From 14c13854d3cae9d93c3d148be30fb72f1eaffe55 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 18 Mar 2024 18:56:33 +0000 Subject: [PATCH] [Rework] Further types conversion (no functional changes) --- clang-plugin/printf_check.cc | 1296 ++++++++--------- contrib/aho-corasick/acism.c | 191 +-- contrib/cdb/cdb_init.c | 54 +- contrib/lc-btrie/btrie.c | 1251 ++++++++++------ contrib/lc-btrie/btrie.h | 17 +- contrib/librdns/resolver.c | 780 +++++----- contrib/libucl/lua_ucl.c | 907 ++++++------ contrib/libucl/ucl_hash.c | 236 +-- src/client/rspamc.cxx | 32 +- src/client/rspamdclient.c | 36 +- src/client/rspamdclient.h | 32 +- src/controller.c | 142 +- src/fuzzy_storage.c | 176 +-- src/hs_helper.c | 28 +- src/libcryptobox/base64/base64.c | 16 +- src/libcryptobox/catena/catena.c | 38 +- src/libcryptobox/chacha20/chacha.c | 2 +- src/libcryptobox/cryptobox.c | 136 +- src/libcryptobox/cryptobox.h | 88 +- src/libcryptobox/keypair.c | 112 +- src/libcryptobox/keypair.h | 44 +- src/libcryptobox/keypair_private.h | 30 +- src/libcryptobox/keypairs_cache.c | 6 +- src/libcryptobox/keypairs_cache.h | 2 +- src/libmime/archives.c | 256 ++-- src/libmime/archives.h | 2 +- src/libmime/content_type.c | 46 +- src/libmime/content_type.h | 18 +- src/libmime/email_addr.c | 32 +- src/libmime/email_addr.h | 26 +- src/libmime/images.c | 86 +- src/libmime/images.h | 4 +- src/libmime/lang_detection.c | 244 ++-- src/libmime/lang_detection.h | 8 +- src/libmime/lang_detection_fasttext.cxx | 4 +- src/libmime/lang_detection_fasttext.h | 2 +- src/libmime/message.c | 128 +- src/libmime/message.h | 56 +- src/libmime/mime_encoding.c | 58 +- src/libmime/mime_encoding.h | 20 +- src/libmime/mime_expressions.c | 162 +-- src/libmime/mime_expressions.h | 4 +- src/libmime/mime_headers.c | 92 +- src/libmime/mime_headers.h | 32 +- src/libmime/mime_parser.c | 100 +- src/libmime/received.cxx | 4 +- src/libmime/scan_result.c | 70 +- src/libmime/scan_result.h | 52 +- src/libmime/smtp_parsers.h | 6 +- src/libserver/async_session.c | 18 +- src/libserver/async_session.h | 8 +- src/libserver/cfg_file.h | 272 ++-- src/libserver/cfg_file_private.h | 6 +- src/libserver/cfg_rcl.cxx | 178 +-- src/libserver/cfg_rcl.h | 44 +- src/libserver/cfg_utils.cxx | 120 +- src/libserver/composites/composites.cxx | 28 +- .../composites/composites_internal.hxx | 2 +- src/libserver/css/css_util.cxx | 8 +- src/libserver/dkim.c | 360 ++--- src/libserver/dkim.h | 48 +- src/libserver/dns.c | 54 +- src/libserver/dns.h | 14 +- src/libserver/dynamic_cfg.c | 68 +- src/libserver/dynamic_cfg.h | 20 +- src/libserver/fuzzy_backend/fuzzy_backend.c | 52 +- src/libserver/fuzzy_backend/fuzzy_backend.h | 18 +- .../fuzzy_backend/fuzzy_backend_redis.c | 126 +- .../fuzzy_backend/fuzzy_backend_redis.h | 8 +- .../fuzzy_backend/fuzzy_backend_sqlite.c | 78 +- .../fuzzy_backend/fuzzy_backend_sqlite.h | 10 +- src/libserver/fuzzy_wire.h | 36 +- src/libserver/html/html.cxx | 48 +- src/libserver/html/html.h | 18 +- src/libserver/html/html.hxx | 2 +- src/libserver/html/html_entities.cxx | 2 +- src/libserver/html/html_tag_defs.hxx | 2 +- src/libserver/html/html_tests.cxx | 12 +- src/libserver/html/html_url.cxx | 18 +- src/libserver/http/http_connection.c | 158 +- src/libserver/http/http_connection.h | 24 +- src/libserver/http/http_context.c | 32 +- src/libserver/http/http_context.h | 22 +- src/libserver/http/http_message.c | 60 +- src/libserver/http/http_message.h | 38 +- src/libserver/http/http_private.h | 12 +- src/libserver/http/http_router.c | 30 +- src/libserver/http/http_router.h | 8 +- src/libserver/http/http_util.c | 18 +- src/libserver/http/http_util.h | 4 +- src/libserver/logger.h | 82 +- src/libserver/logger/logger.c | 166 +-- src/libserver/logger/logger_console.c | 22 +- src/libserver/logger/logger_file.c | 52 +- src/libserver/logger/logger_private.h | 68 +- src/libserver/logger/logger_syslog.c | 26 +- src/libserver/maps/map.c | 150 +- src/libserver/maps/map.h | 18 +- src/libserver/maps/map_helpers.c | 136 +- src/libserver/maps/map_helpers.h | 60 +- src/libserver/maps/map_private.h | 38 +- src/libserver/milter.c | 118 +- src/libserver/milter.h | 14 +- src/libserver/milter_internal.h | 4 +- src/libserver/monitored.c | 92 +- src/libserver/monitored.h | 14 +- src/libserver/protocol.c | 68 +- src/libserver/protocol.h | 4 +- src/libserver/re_cache.c | 344 ++--- src/libserver/re_cache.h | 42 +- src/libserver/redis_pool.cxx | 30 +- src/libserver/redis_pool.h | 4 +- src/libserver/roll_history.c | 26 +- src/libserver/roll_history.h | 28 +- src/libserver/rspamd_control.c | 80 +- src/libserver/rspamd_control.h | 94 +- src/libserver/rspamd_symcache.h | 126 +- src/libserver/spf.c | 164 +-- src/libserver/spf.h | 54 +- src/libserver/ssl_util.c | 50 +- src/libserver/ssl_util.h | 8 +- src/libserver/symcache/symcache_c.cxx | 110 +- src/libserver/symcache/symcache_impl.cxx | 6 +- src/libserver/symcache/symcache_runtime.cxx | 2 +- src/libserver/task.c | 116 +- src/libserver/task.h | 48 +- src/libserver/url.c | 468 +++--- src/libserver/url.h | 56 +- src/libserver/worker_util.c | 78 +- src/libserver/worker_util.h | 30 +- src/libstat/backends/backends.h | 12 +- src/libstat/backends/cdb_backend.cxx | 6 +- src/libstat/backends/http_backend.cxx | 10 +- src/libstat/backends/mmaped_file.c | 92 +- src/libstat/backends/redis_backend.cxx | 56 +- src/libstat/backends/sqlite3_backend.c | 38 +- src/libstat/classifiers/bayes.c | 38 +- src/libstat/classifiers/classifiers.h | 2 +- src/libstat/classifiers/lua_classifier.c | 12 +- src/libstat/learn_cache/learn_cache.h | 24 +- src/libstat/learn_cache/redis_cache.cxx | 20 +- src/libstat/learn_cache/sqlite3_cache.c | 28 +- src/libstat/stat_api.h | 12 +- src/libstat/stat_config.c | 34 +- src/libstat/stat_internal.h | 26 +- src/libstat/stat_process.c | 86 +- src/libstat/tokenizers/osb.c | 28 +- src/libstat/tokenizers/tokenizers.c | 64 +- src/libstat/tokenizers/tokenizers.h | 32 +- src/libutil/addr.c | 160 +- src/libutil/addr.h | 48 +- src/libutil/cxx/utf8_util.cxx | 6 +- src/libutil/cxx/utf8_util.h | 4 +- src/libutil/expression.c | 118 +- src/libutil/expression.h | 42 +- src/libutil/fstring.c | 36 +- src/libutil/fstring.h | 30 +- src/libutil/hash.c | 64 +- src/libutil/hash.h | 10 +- src/libutil/heap.c | 6 +- src/libutil/heap.h | 8 +- src/libutil/mem_pool.c | 144 +- src/libutil/mem_pool.h | 62 +- src/libutil/mem_pool_internal.h | 22 +- src/libutil/multipattern.c | 132 +- src/libutil/multipattern.h | 38 +- src/libutil/printf.c | 114 +- src/libutil/printf.h | 28 +- src/libutil/radix.c | 56 +- src/libutil/radix.h | 26 +- src/libutil/regexp.c | 116 +- src/libutil/regexp.h | 32 +- src/libutil/rrd.c | 144 +- src/libutil/rrd.h | 66 +- src/libutil/shingles.c | 58 +- src/libutil/shingles.h | 14 +- src/libutil/sqlite_utils.c | 32 +- src/libutil/sqlite_utils.h | 22 +- src/libutil/str_util.c | 510 +++---- src/libutil/str_util.h | 144 +- src/libutil/upstream.c | 182 +-- src/libutil/upstream.h | 44 +- src/libutil/util.c | 304 ++-- src/libutil/util.h | 122 +- src/lua/lua_cdb.c | 24 +- src/lua/lua_cfg_file.c | 12 +- src/lua/lua_classifier.c | 24 +- src/lua/lua_classnames.c | 2 +- src/lua/lua_classnames.h | 2 +- src/lua/lua_common.c | 296 ++-- src/lua/lua_common.h | 136 +- src/lua/lua_compress.c | 52 +- src/lua/lua_compress.h | 8 +- src/lua/lua_config.c | 402 ++--- src/lua/lua_cryptobox.c | 330 ++--- src/lua/lua_dns.c | 12 +- src/lua/lua_dns_resolver.c | 30 +- src/lua/lua_expression.c | 50 +- src/lua/lua_html.cxx | 46 +- src/lua/lua_http.c | 50 +- src/lua/lua_ip.c | 68 +- src/lua/lua_kann.c | 56 +- src/lua/lua_logger.c | 120 +- src/lua/lua_map.c | 88 +- src/lua/lua_mempool.c | 68 +- src/lua/lua_mimepart.c | 158 +- src/lua/lua_parsers.c | 26 +- src/lua/lua_redis.c | 122 +- src/lua/lua_regexp.c | 42 +- src/lua/lua_rsa.c | 94 +- src/lua/lua_spf.c | 56 +- src/lua/lua_sqlite3.c | 46 +- src/lua/lua_task.c | 572 ++++---- src/lua/lua_tcp.c | 128 +- src/lua/lua_tensor.c | 90 +- src/lua/lua_text.c | 196 +-- src/lua/lua_thread_pool.cxx | 42 +- src/lua/lua_thread_pool.h | 20 +- src/lua/lua_trie.c | 64 +- src/lua/lua_udp.c | 38 +- src/lua/lua_upstream.c | 62 +- src/lua/lua_url.c | 142 +- src/lua/lua_url.h | 20 +- src/lua/lua_util.c | 276 ++-- src/lua/lua_worker.c | 66 +- src/lua/lua_xmlrpc.c | 50 +- src/plugins/chartable.cxx | 66 +- src/plugins/dkim_check.c | 144 +- src/plugins/fuzzy_check.c | 440 +++--- src/plugins/regexp.c | 40 +- src/ragel/rfc2047_parser.rl | 8 +- src/ragel/smtp_date_parser.rl | 2 +- src/ragel/smtp_ip_parser.rl | 2 +- src/rspamadm/commands.c | 26 +- src/rspamadm/configdump.c | 20 +- src/rspamadm/confighelp.c | 16 +- src/rspamadm/configtest.c | 10 +- src/rspamadm/control.c | 20 +- src/rspamadm/fuzzy_convert.c | 14 +- src/rspamadm/lua_repl.c | 100 +- src/rspamadm/pw.c | 42 +- src/rspamadm/rspamadm.c | 56 +- src/rspamadm/rspamadm.h | 26 +- src/rspamadm/signtool.c | 58 +- src/rspamadm/stat_convert.c | 26 +- src/rspamd.c | 110 +- src/rspamd.h | 56 +- src/rspamd_proxy.c | 124 +- src/worker.c | 10 +- test/rspamd_cryptobox_test.c | 22 +- test/rspamd_dkim_test.c | 14 +- test/rspamd_dns_test.c | 2 +- test/rspamd_heap_test.c | 20 +- test/rspamd_lua_pcall_vs_resume_test.c | 48 +- test/rspamd_lua_test.c | 20 +- test/rspamd_radix_test.c | 36 +- test/rspamd_rrd_test.c | 8 +- test/rspamd_shingles_test.c | 20 +- test/rspamd_test_suite.c | 6 +- test/rspamd_upstream_test.c | 10 +- utils/base64.c | 18 +- utils/rspamd_http_bench.c | 54 +- utils/rspamd_http_server.c | 34 +- 263 files changed, 11092 insertions(+), 10730 deletions(-) diff --git a/clang-plugin/printf_check.cc b/clang-plugin/printf_check.cc index e39cec8e3..24d7de0ee 100644 --- a/clang-plugin/printf_check.cc +++ b/clang-plugin/printf_check.cc @@ -31,792 +31,788 @@ using namespace clang; namespace rspamd { - struct PrintfArgChecker; +struct PrintfArgChecker; - static bool cstring_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool cstring_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool int_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool int_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool long_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool long_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool size_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool size_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool char_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool char_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool double_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool double_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool long_double_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool long_double_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool pointer_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool pointer_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool pid_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool pid_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool time_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool time_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool int64_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool int64_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool int32_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool int32_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool tok_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool tok_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool fstring_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool fstring_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool gstring_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool gstring_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - static bool gerr_arg_handler (const Expr *arg, - struct PrintfArgChecker *ctx); +static bool gerr_arg_handler(const Expr *arg, + struct PrintfArgChecker *ctx); - using arg_parser_t = bool (*) (const Expr *, struct PrintfArgChecker *); +using arg_parser_t = bool (*)(const Expr *, struct PrintfArgChecker *); - static void - print_error (const char *err, const Expr *e, const ASTContext *ast, +static void +print_error(const char *err, const Expr *e, const ASTContext *ast, CompilerInstance *ci) +{ + auto loc = e->getExprLoc(); + auto &diag = ci->getDiagnostics(); + auto id = diag.getCustomDiagID(DiagnosticsEngine::Error, + "format query error: %0"); + diag.Report(loc, id) << err; +} + +static void +print_warning(const char *err, const Expr *e, const ASTContext *ast, + CompilerInstance *ci) +{ + auto loc = e->getExprLoc(); + auto &diag = ci->getDiagnostics(); + auto id = diag.getCustomDiagID(DiagnosticsEngine::Warning, + "format query warning: %0"); + diag.Report(loc, id) << err; +} + +static void +print_remark(const char *err, const Expr *e, const ASTContext *ast, + CompilerInstance *ci) +{ + auto loc = e->getExprLoc(); + auto &diag = ci->getDiagnostics(); + auto id = diag.getCustomDiagID(DiagnosticsEngine::Remark, + "format query warning: %0"); + diag.Report(loc, id) << err; +} + +struct PrintfArgChecker { +private: + arg_parser_t parser; + +public: + int width; + int precision; + bool is_unsigned; + ASTContext *past; + CompilerInstance *pci; + + PrintfArgChecker(arg_parser_t _p, ASTContext *_ast, CompilerInstance *_ci) + : parser(_p), past(_ast), pci(_ci) { - auto loc = e->getExprLoc (); - auto &diag = ci->getDiagnostics (); - auto id = diag.getCustomDiagID (DiagnosticsEngine::Error, - "format query error: %0"); - diag.Report (loc, id) << err; + width = 0; + precision = 0; + is_unsigned = false; } - static void - print_warning (const char *err, const Expr *e, const ASTContext *ast, - CompilerInstance *ci) + virtual ~PrintfArgChecker() { - auto loc = e->getExprLoc (); - auto &diag = ci->getDiagnostics (); - auto id = diag.getCustomDiagID (DiagnosticsEngine::Warning, - "format query warning: %0"); - diag.Report (loc, id) << err; } - static void - print_remark (const char *err, const Expr *e, const ASTContext *ast, - CompilerInstance *ci) + bool operator()(const Expr *e) { - auto loc = e->getExprLoc (); - auto &diag = ci->getDiagnostics (); - auto id = diag.getCustomDiagID (DiagnosticsEngine::Remark, - "format query warning: %0"); - diag.Report (loc, id) << err; + return parser(e, this); } +}; - struct PrintfArgChecker { - private: - arg_parser_t parser; - public: - int width; - int precision; - bool is_unsigned; - ASTContext *past; - CompilerInstance *pci; - - PrintfArgChecker (arg_parser_t _p, ASTContext *_ast, CompilerInstance *_ci) : - parser (_p), past (_ast), pci(_ci) - { - width = 0; - precision = 0; - is_unsigned = false; - } +class PrintfCheckVisitor::impl { + std::unordered_map printf_functions; + std::unordered_set format_specs; + ASTContext *pcontext; + CompilerInstance *ci; - virtual ~PrintfArgChecker () - { + std::unique_ptr parseFlags(const std::string &flags, + const Expr *e) + { + auto type = flags.back(); + + switch (type) { + case 's': + return std::make_unique(cstring_arg_handler, + this->pcontext, this->ci); + case 'd': + return std::make_unique(int_arg_handler, + this->pcontext, this->ci); + case 'z': + return std::make_unique(size_arg_handler, + this->pcontext, this->ci); + case 'l': + return std::make_unique(long_arg_handler, + this->pcontext, this->ci); + case 'f': + case 'g': + return std::make_unique(double_arg_handler, + this->pcontext, this->ci); + case 'F': + case 'G': + return std::make_unique( + long_double_arg_handler, + this->pcontext, this->ci); + case 'c': + return std::make_unique(char_arg_handler, + this->pcontext, this->ci); + case 'p': + return std::make_unique(pointer_arg_handler, + this->pcontext, this->ci); + case 'P': + return std::make_unique(pid_arg_handler, + this->pcontext, this->ci); + case 't': + return std::make_unique(time_arg_handler, + this->pcontext, this->ci); + case 'L': + return std::make_unique(int64_arg_handler, + this->pcontext, this->ci); + case 'D': + return std::make_unique(int32_arg_handler, + this->pcontext, this->ci); + case 'T': + return std::make_unique(tok_arg_handler, + this->pcontext, this->ci); + case 'V': + return std::make_unique(fstring_arg_handler, + this->pcontext, this->ci); + case 'v': + return std::make_unique(gstring_arg_handler, + this->pcontext, this->ci); + case 'e': + return std::make_unique(gerr_arg_handler, + this->pcontext, this->ci); + default: { + auto err_msg = std::string("unknown parser flag: ") + type; + print_warning(err_msg.c_str(), + e, this->pcontext, this->ci); + break; } - - bool operator() (const Expr *e) - { - return parser (e, this); } - }; - class PrintfCheckVisitor::impl { - std::unordered_map printf_functions; - std::unordered_set format_specs; - ASTContext *pcontext; - CompilerInstance *ci; - - std::unique_ptr parseFlags (const std::string &flags, - const Expr *e) - { - auto type = flags.back (); - - switch (type) { - case 's': - return std::make_unique (cstring_arg_handler, - this->pcontext, this->ci); - case 'd': - return std::make_unique (int_arg_handler, - this->pcontext, this->ci); - case 'z': - return std::make_unique (size_arg_handler, - this->pcontext, this->ci); - case 'l': - return std::make_unique (long_arg_handler, - this->pcontext, this->ci); - case 'f': - case 'g': - return std::make_unique (double_arg_handler, - this->pcontext, this->ci); - case 'F': - case 'G': - return std::make_unique ( - long_double_arg_handler, - this->pcontext, this->ci); - case 'c': - return std::make_unique (char_arg_handler, - this->pcontext, this->ci); - case 'p': - return std::make_unique (pointer_arg_handler, - this->pcontext, this->ci); - case 'P': - return std::make_unique (pid_arg_handler, - this->pcontext, this->ci); - case 't': - return std::make_unique (time_arg_handler, - this->pcontext, this->ci); - case 'L': - return std::make_unique (int64_arg_handler, - this->pcontext, this->ci); - case 'D': - return std::make_unique (int32_arg_handler, - this->pcontext, this->ci); - case 'T': - return std::make_unique (tok_arg_handler, - this->pcontext, this->ci); - case 'V': - return std::make_unique (fstring_arg_handler, - this->pcontext, this->ci); - case 'v': - return std::make_unique (gstring_arg_handler, - this->pcontext, this->ci); - case 'e': - return std::make_unique (gerr_arg_handler, - this->pcontext, this->ci); - default: { - auto err_msg = std::string ("unknown parser flag: ") + type; - print_warning (err_msg.c_str(), - e, this->pcontext, this->ci); + return nullptr; + } + + std::shared_ptr> + genParsers(const StringRef query, const Expr *e) + { + enum { + ignore_chars = 0, + read_percent, + read_width, + read_precision, + read_arg + } state = ignore_chars; + int width, precision; + std::string flags; + + auto res = std::make_shared>(); + + for (auto citer = query.begin(); citer != query.end(); ++citer) { + auto c = *citer; + + switch (state) { + case ignore_chars: + if (c == '%') { + state = read_percent; + flags.clear(); + width = precision = 0; + } break; + case read_percent: + if (isdigit(c)) { + state = read_width; + width = c - '0'; } - } - - return nullptr; - } + else if (c == '.') { + state = read_precision; + precision = c - '0'; + } + else if (c == '*') { + /* %*s - need integer argument */ + res->emplace_back(int_arg_handler, this->pcontext, + this->ci); - std::shared_ptr > - genParsers (const StringRef query, const Expr *e) - { - enum { - ignore_chars = 0, - read_percent, - read_width, - read_precision, - read_arg - } state = ignore_chars; - int width, precision; - std::string flags; - - auto res = std::make_shared > (); - - for (auto citer = query.begin(); citer != query.end(); ++citer) { - auto c = *citer; - - switch (state) { - case ignore_chars: - if (c == '%') { - state = read_percent; - flags.clear (); - width = precision = 0; - } - break; - case read_percent: - if (isdigit (c)) { - state = read_width; - width = c - '0'; - } - else if (c == '.') { - state = read_precision; - precision = c - '0'; - } - else if (c == '*') { - /* %*s - need integer argument */ - res->emplace_back (int_arg_handler, this->pcontext, - this->ci); - - if (*std::next (citer) == '.') { - ++citer; - state = read_precision; - } - else { - state = read_arg; - } - } - else if (c == '%') { - /* Percent character, ignore */ - state = ignore_chars; - } - else { - // Rewind iter - --citer; - state = read_arg; - } - break; - case read_width: - if (isdigit (c)) { - width *= 10; - width += c - '0'; - } - else if (c == '.') { + if (*std::next(citer) == '.') { + ++citer; state = read_precision; - precision = c - '0'; } else { - // Rewind iter - --citer; state = read_arg; } - break; - case read_precision: - if (isdigit (c)) { - precision *= 10; - precision += c - '0'; + } + else if (c == '%') { + /* Percent character, ignore */ + state = ignore_chars; + } + else { + // Rewind iter + --citer; + state = read_arg; + } + break; + case read_width: + if (isdigit(c)) { + width *= 10; + width += c - '0'; + } + else if (c == '.') { + state = read_precision; + precision = c - '0'; + } + else { + // Rewind iter + --citer; + state = read_arg; + } + break; + case read_precision: + if (isdigit(c)) { + precision *= 10; + precision += c - '0'; + } + else if (c == '*') { + res->emplace_back(int_arg_handler, this->pcontext, + this->ci); + state = read_arg; + } + else { + // Rewind iter + --citer; + state = read_arg; + } + break; + case read_arg: + auto found = format_specs.find(c); + if (found != format_specs.end() || !isalpha(c)) { + + if (isalpha(c)) { + flags.push_back(c); } - else if (c == '*') { - res->emplace_back (int_arg_handler, this->pcontext, - this->ci); - state = read_arg; + + auto handler = parseFlags(flags, e); + + if (handler) { + auto handler_copy = *handler; + handler_copy.precision = precision; + handler_copy.width = width; + res->emplace_back(std::move(handler_copy)); } else { - // Rewind iter - --citer; - state = read_arg; + return nullptr; } - break; - case read_arg: - auto found = format_specs.find (c); - if (found != format_specs.end () || !isalpha (c)) { - - if (isalpha (c)) { - flags.push_back (c); - } - auto handler = parseFlags (flags, e); - - if (handler) { - auto handler_copy = *handler; - handler_copy.precision = precision; - handler_copy.width = width; - res->emplace_back (std::move (handler_copy)); - } - else { - return nullptr; - } - - if (c == '%') { - state = read_percent; - } - else { - state = ignore_chars; - } - flags.clear (); - width = precision = 0; + if (c == '%') { + state = read_percent; } else { - flags.push_back (c); + state = ignore_chars; } - break; - } - } - - if (state == read_arg) { - auto handler = parseFlags (flags, e); - - if (handler) { - auto handler_copy = *handler; - handler_copy.precision = precision; - handler_copy.width = width; - res->emplace_back (std::move (handler_copy)); + flags.clear(); + width = precision = 0; } else { - return nullptr; + flags.push_back(c); } + break; } + } - return res; + if (state == read_arg) { + auto handler = parseFlags(flags, e); + + if (handler) { + auto handler_copy = *handler; + handler_copy.precision = precision; + handler_copy.width = width; + res->emplace_back(std::move(handler_copy)); + } + else { + return nullptr; + } } - public: - impl (ASTContext *_ctx, clang::CompilerInstance &_ci) - : pcontext (_ctx), ci(&_ci) - { - /* name -> format string position */ - printf_functions = { - {"rspamd_printf", 0}, - {"rspamd_default_log_function", 4}, - {"rspamd_snprintf", 2}, - {"rspamd_fprintf", 1}, - {"rspamd_printf_gstring", 1}, - {"rspamd_printf_fstring", 1}, - {"rspamd_conditional_debug_fast", 6}, - }; - - format_specs = { - 's', 'd', 'l', 'L', 'v', 'V', 'f', 'F', 'g', 'G', - 'T', 'z', 'D', 'c', 'p', 'P', 'e' - }; + return res; + } + +public: + impl(ASTContext *_ctx, clang::CompilerInstance &_ci) + : pcontext(_ctx), ci(&_ci) + { + /* name -> format string position */ + printf_functions = { + {"rspamd_printf", 0}, + {"rspamd_default_log_function", 4}, + {"rspamd_snprintf", 2}, + {"rspamd_fprintf", 1}, + {"rspamd_printf_gstring", 1}, + {"rspamd_printf_fstring", 1}, + {"rspamd_conditional_debug_fast", 6}, }; - bool VisitCallExpr (CallExpr *E) - { - if (E->getCalleeDecl () == nullptr) { - print_remark ("cannot get callee decl", - E, this->pcontext, this->ci); - return true; - } - auto callee = dyn_cast (E->getCalleeDecl ()); - if (callee == NULL) { - print_remark ("cannot get named callee decl", - E, this->pcontext, this->ci); + format_specs = { + 's', 'd', 'l', 'L', 'v', 'V', 'f', 'F', 'g', 'G', + 'T', 'z', 'D', 'c', 'p', 'P', 'e'}; + }; + + bool VisitCallExpr(CallExpr *E) + { + if (E->getCalleeDecl() == nullptr) { + print_remark("cannot get callee decl", + E, this->pcontext, this->ci); + return true; + } + auto callee = dyn_cast(E->getCalleeDecl()); + if (callee == NULL) { + print_remark("cannot get named callee decl", + E, this->pcontext, this->ci); + return true; + } + + auto fname = callee->getNameAsString(); + + auto pos_it = printf_functions.find(fname); + + if (pos_it != printf_functions.end()) { + const auto args = E->getArgs(); + auto pos = pos_it->second; + auto query = args[pos]; + + if (!query->isEvaluatable(*pcontext)) { + print_remark("cannot evaluate query", + E, this->pcontext, this->ci); + /* It is not assumed to be an error */ return true; } - auto fname = callee->getNameAsString (); + clang::Expr::EvalResult r; - auto pos_it = printf_functions.find (fname); - - if (pos_it != printf_functions.end ()) { - const auto args = E->getArgs (); - auto pos = pos_it->second; - auto query = args[pos]; + if (!query->EvaluateAsRValue(r, *pcontext)) { + print_warning("cannot evaluate rvalue of query", + E, this->pcontext, this->ci); + return false; + } - if (!query->isEvaluatable (*pcontext)) { - print_remark ("cannot evaluate query", - E, this->pcontext, this->ci); - /* It is not assumed to be an error */ - return true; - } + auto qval = dyn_cast( + r.Val.getLValueBase().get()); + if (!qval) { + print_warning("bad or absent query string", + E, this->pcontext, this->ci); + return false; + } - clang::Expr::EvalResult r; + auto parsers = genParsers(qval->getString(), E); - if (!query->EvaluateAsRValue (r, *pcontext)) { - print_warning ("cannot evaluate rvalue of query", - E, this->pcontext, this->ci); - return false; - } + if (parsers) { + if (parsers->size() != E->getNumArgs() - (pos + 1)) { + std::ostringstream err_buf; + err_buf << "number of arguments for " << fname + << " mismatches query string '" << qval->getString().str() + << "', expected " << parsers->size() << " args" + << ", got " << (E->getNumArgs() - (pos + 1)) + << " args"; + print_error(err_buf.str().c_str(), E, this->pcontext, this->ci); - auto qval = dyn_cast ( - r.Val.getLValueBase ().get ()); - if (!qval) { - print_warning ("bad or absent query string", - E, this->pcontext, this->ci); return false; } + else { + for (auto i = pos + 1; i < E->getNumArgs(); i++) { + auto arg = args[i]; - auto parsers = genParsers (qval->getString (), E); - - if (parsers) { - if (parsers->size () != E->getNumArgs () - (pos + 1)) { - std::ostringstream err_buf; - err_buf << "number of arguments for " << fname - << " mismatches query string '" << - qval->getString ().str () - << "', expected " << parsers->size () << - " args" - << ", got " << - (E->getNumArgs () - (pos + 1)) - << " args"; - print_error (err_buf.str().c_str(), E, this->pcontext, this->ci); - - return false; - } - else { - for (auto i = pos + 1; i < E->getNumArgs (); i++) { - auto arg = args[i]; - - if (arg) { - if (!parsers->at (i - (pos + 1)) (arg)) { - return false; - } + if (arg) { + if (!parsers->at(i - (pos + 1))(arg)) { + return false; } } } } } - - return true; } - }; - PrintfCheckVisitor::PrintfCheckVisitor (ASTContext *ctx, - clang::CompilerInstance &ci) : - pimpl{new impl (ctx, ci)} - { + return true; } +}; - PrintfCheckVisitor::~PrintfCheckVisitor () - { - } +PrintfCheckVisitor::PrintfCheckVisitor(ASTContext *ctx, + clang::CompilerInstance &ci) + : pimpl{new impl(ctx, ci)} +{ +} - bool PrintfCheckVisitor::VisitCallExpr (clang::CallExpr *E) - { - return pimpl->VisitCallExpr (E); - } +PrintfCheckVisitor::~PrintfCheckVisitor() +{ +} - /* Type handlers */ - static bool - cstring_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - auto type = arg->getType ().split ().Ty; +bool PrintfCheckVisitor::VisitCallExpr(clang::CallExpr *E) +{ + return pimpl->VisitCallExpr(E); +} - if (!type->isPointerType ()) { - auto err_msg = std::string ("bad string argument for %s: ") + - arg->getType ().getAsString (); - print_error (err_msg.c_str(), +/* Type handlers */ +static bool +cstring_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + auto type = arg->getType().split().Ty; + + if (!type->isPointerType()) { + auto err_msg = std::string("bad string argument for %s: ") + + arg->getType().getAsString(); + print_error(err_msg.c_str(), arg, ctx->past, ctx->pci); - return false; - } + return false; + } - auto ptr_type = type->getPointeeType ().split ().Ty; + auto ptr_type = type->getPointeeType().split().Ty; - if (!ptr_type->isCharType ()) { - /* We might have gchar * here */ - auto desugared_type = ptr_type->getUnqualifiedDesugaredType (); - auto desugared_ptr_type = type->getUnqualifiedDesugaredType (); + if (!ptr_type->isCharType()) { + /* We might have char * here */ + auto desugared_type = ptr_type->getUnqualifiedDesugaredType(); + auto desugared_ptr_type = type->getUnqualifiedDesugaredType(); - if (!desugared_type || (!desugared_type->isCharType () && - !desugared_ptr_type->isVoidPointerType ())) { - if (desugared_type) { - desugared_type->dump (); - } - auto err_msg = std::string ("bad string argument for %s: ") + - arg->getType ().getAsString (); - print_error (err_msg.c_str(), - arg, ctx->past, ctx->pci); - return false; + if (!desugared_type || (!desugared_type->isCharType() && + !desugared_ptr_type->isVoidPointerType())) { + if (desugared_type) { + desugared_type->dump(); } + auto err_msg = std::string("bad string argument for %s: ") + + arg->getType().getAsString(); + print_error(err_msg.c_str(), + arg, ctx->past, ctx->pci); + return false; } - - return true; } - static bool - check_builtin_type (const Expr *arg, struct PrintfArgChecker *ctx, - const std::vector &k, const std::string &fmt) - { - auto type = arg->getType ().split ().Ty; + return true; +} - auto desugared_type = type->getUnqualifiedDesugaredType (); +static bool +check_builtin_type(const Expr *arg, struct PrintfArgChecker *ctx, + const std::vector &k, const std::string &fmt) +{ + auto type = arg->getType().split().Ty; - if (!desugared_type->isBuiltinType ()) { - auto err_msg = std::string ("not a builtin type for ") + fmt + " arg: " + - arg->getType ().getAsString (); - print_error (err_msg.c_str(), + auto desugared_type = type->getUnqualifiedDesugaredType(); + + if (!desugared_type->isBuiltinType()) { + auto err_msg = std::string("not a builtin type for ") + fmt + " arg: " + + arg->getType().getAsString(); + print_error(err_msg.c_str(), arg, ctx->past, ctx->pci); - return false; - } + return false; + } - auto builtin_type = dyn_cast (desugared_type); - auto kind = builtin_type->getKind (); - auto found = false; + auto builtin_type = dyn_cast(desugared_type); + auto kind = builtin_type->getKind(); + auto found = false; - for (auto kk : k) { - if (kind == kk) { - found = true; - break; - } + for (auto kk: k) { + if (kind == kk) { + found = true; + break; } + } - if (!found) { - auto err_msg = std::string ("bad argument for ") + - fmt + " arg: " + - arg->getType ().getAsString () + - ", resolved as: " + - builtin_type->getNameAsCString (ctx->past->getPrintingPolicy ()); - print_error (err_msg.c_str(), + if (!found) { + auto err_msg = std::string("bad argument for ") + + fmt + " arg: " + + arg->getType().getAsString() + + ", resolved as: " + + builtin_type->getNameAsCString(ctx->past->getPrintingPolicy()); + print_error(err_msg.c_str(), arg, ctx->past, ctx->pci); - return false; - } - - return true; + return false; } - static bool - int_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::UInt, - BuiltinType::Kind::Int}, - "%d or *"); - } + return true; +} - static bool - long_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::ULong, - BuiltinType::Kind::Long}, - "%l"); - } +static bool +int_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::UInt, + BuiltinType::Kind::Int}, + "%d or *"); +} - static bool - char_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::UChar, - BuiltinType::Kind::SChar, - BuiltinType::Kind::Int}, // Because of char -> int propagation - "%c"); - } +static bool +long_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::ULong, + BuiltinType::Kind::Long}, + "%l"); +} - static bool - size_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - if (sizeof (size_t) == sizeof (long)) { - if (sizeof (long long) == sizeof (long)) { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::ULong, - BuiltinType::Kind::Long, - BuiltinType::Kind::LongLong, - BuiltinType::Kind::ULongLong}, - "%z"); - } - else { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::ULong, - BuiltinType::Kind::Long}, - "%z"); - } - } - else if (sizeof (size_t) == sizeof (int)) { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::UInt, - BuiltinType::Kind::Int}, - "%z"); +static bool +char_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::UChar, + BuiltinType::Kind::SChar, + BuiltinType::Kind::Int},// Because of char -> int propagation + "%c"); +} + +static bool +size_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + if (sizeof(size_t) == sizeof(long)) { + if (sizeof(long long) == sizeof(long)) { + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::ULong, + BuiltinType::Kind::Long, + BuiltinType::Kind::LongLong, + BuiltinType::Kind::ULongLong}, + "%z"); } else { - assert (0); + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::ULong, + BuiltinType::Kind::Long}, + "%z"); } - - return true; } - - static bool - double_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::Double}, - "%f or %g"); + else if (sizeof(size_t) == sizeof(int)) { + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::UInt, + BuiltinType::Kind::Int}, + "%z"); } - - static bool - long_double_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::LongDouble}, - "%F or %G"); + else { + assert(0); } - static bool - pid_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - if (sizeof (pid_t) == sizeof (long)) { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::ULong, - BuiltinType::Kind::Long}, - "%P"); - } - else if (sizeof (pid_t) == sizeof (int)) { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::UInt, - BuiltinType::Kind::Int}, - "%P"); - } - else { - assert (0); - } + return true; +} + +static bool +double_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::Double}, + "%f or %g"); +} + +static bool +long_double_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::LongDouble}, + "%F or %G"); +} + +static bool +pid_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + if (sizeof(pid_t) == sizeof(long)) { + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::ULong, + BuiltinType::Kind::Long}, + "%P"); + } + else if (sizeof(pid_t) == sizeof(int)) { + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::UInt, + BuiltinType::Kind::Int}, + "%P"); } + else { + assert(0); + } +} - static bool - time_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - if (sizeof (time_t) == sizeof (long)) { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::ULong, - BuiltinType::Kind::Long}, - "%t"); - } - else if (sizeof (time_t) == sizeof (int)) { - return check_builtin_type (arg, - ctx, - {BuiltinType::Kind::UInt, - BuiltinType::Kind::Int}, - "%t"); - } - else { - assert (0); - } +static bool +time_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + if (sizeof(time_t) == sizeof(long)) { + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::ULong, + BuiltinType::Kind::Long}, + "%t"); + } + else if (sizeof(time_t) == sizeof(int)) { + return check_builtin_type(arg, + ctx, + {BuiltinType::Kind::UInt, + BuiltinType::Kind::Int}, + "%t"); } + else { + assert(0); + } +} - static bool - pointer_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - auto type = arg->getType ().split ().Ty; +static bool +pointer_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + auto type = arg->getType().split().Ty; - if (!type->isPointerType ()) { - auto err_msg = std::string ("bad pointer argument for %p: ") + - arg->getType ().getAsString (); - print_error (err_msg.c_str(), + if (!type->isPointerType()) { + auto err_msg = std::string("bad pointer argument for %p: ") + + arg->getType().getAsString(); + print_error(err_msg.c_str(), arg, ctx->past, ctx->pci); - return false; - } - - return true; + return false; } - static bool - int64_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - std::vector check; - - if (sizeof (int64_t) == sizeof (long long)) { - check.push_back (BuiltinType::Kind::ULongLong); - check.push_back (BuiltinType::Kind::LongLong); - } - if (sizeof (int64_t) == sizeof (long)) { - check.push_back (BuiltinType::Kind::ULong); - check.push_back (BuiltinType::Kind::Long); - } + return true; +} - return check_builtin_type (arg, - ctx, - check, - "%L"); +static bool +int64_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + std::vector check; - return true; + if (sizeof(int64_t) == sizeof(long long)) { + check.push_back(BuiltinType::Kind::ULongLong); + check.push_back(BuiltinType::Kind::LongLong); + } + if (sizeof(int64_t) == sizeof(long)) { + check.push_back(BuiltinType::Kind::ULong); + check.push_back(BuiltinType::Kind::Long); } - static bool - int32_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - std::vector < BuiltinType::Kind> check; + return check_builtin_type(arg, + ctx, + check, + "%L"); - if (sizeof (int32_t) == sizeof (long)) { - check.push_back (BuiltinType::Kind::ULong); - check.push_back (BuiltinType::Kind::Long); - } - if (sizeof (int32_t) == sizeof (int)) { - check.push_back (BuiltinType::Kind::UInt); - check.push_back (BuiltinType::Kind::Int); - } + return true; +} - return check_builtin_type (arg, - ctx, - check, - "%D"); +static bool +int32_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + std::vector check; - return true; + if (sizeof(int32_t) == sizeof(long)) { + check.push_back(BuiltinType::Kind::ULong); + check.push_back(BuiltinType::Kind::Long); + } + if (sizeof(int32_t) == sizeof(int)) { + check.push_back(BuiltinType::Kind::UInt); + check.push_back(BuiltinType::Kind::Int); } - static bool - check_struct_type (const Expr *arg, struct PrintfArgChecker *ctx, - const std::string &sname, const std::string &fmt) - { - auto type = arg->getType ().split ().Ty; + return check_builtin_type(arg, + ctx, + check, + "%D"); - if (!type->isPointerType ()) { - auto err_msg = std::string ("non pointer argument for %s: ") + - arg->getType ().getAsString (); - print_error (err_msg.c_str(), - arg, ctx->past, ctx->pci); - return false; - } + return true; +} - auto ptr_type = type->getPointeeType ().split ().Ty; - auto desugared_type = ptr_type->getUnqualifiedDesugaredType (); +static bool +check_struct_type(const Expr *arg, struct PrintfArgChecker *ctx, + const std::string &sname, const std::string &fmt) +{ + auto type = arg->getType().split().Ty; - if (!desugared_type->isRecordType ()) { - auto err_msg = std::string ("not a record type for ") + fmt + " arg: " + - arg->getType ().getAsString (); - print_error (err_msg.c_str(), + if (!type->isPointerType()) { + auto err_msg = std::string("non pointer argument for %s: ") + + arg->getType().getAsString(); + print_error(err_msg.c_str(), arg, ctx->past, ctx->pci); - return false; - } + return false; + } - auto struct_type = desugared_type->getAsStructureType (); - auto struct_decl = struct_type->getDecl (); - auto struct_def = struct_decl->getNameAsString (); + auto ptr_type = type->getPointeeType().split().Ty; + auto desugared_type = ptr_type->getUnqualifiedDesugaredType(); - if (struct_def != sname) { - auto err_msg = std::string ("bad argument '") + struct_def + "' for " - + fmt + " arg: " + - arg->getType ().getAsString (); - print_error (err_msg.c_str(), + if (!desugared_type->isRecordType()) { + auto err_msg = std::string("not a record type for ") + fmt + " arg: " + + arg->getType().getAsString(); + print_error(err_msg.c_str(), arg, ctx->past, ctx->pci); - return false; - } - - return true; + return false; } - static bool - tok_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - return check_struct_type (arg, - ctx, - "f_str_tok", - "%T"); - } + auto struct_type = desugared_type->getAsStructureType(); + auto struct_decl = struct_type->getDecl(); + auto struct_def = struct_decl->getNameAsString(); - static bool - fstring_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - return check_struct_type (arg, - ctx, - "f_str_s", - "%V"); + if (struct_def != sname) { + auto err_msg = std::string("bad argument '") + struct_def + "' for " + fmt + " arg: " + + arg->getType().getAsString(); + print_error(err_msg.c_str(), + arg, ctx->past, ctx->pci); + return false; } - static bool - gstring_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - return check_struct_type (arg, - ctx, - "_GString", - "%v"); - } + return true; +} - static bool - gerr_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) - { - return check_struct_type (arg, - ctx, - "_GError", - "%e"); - } +static bool +tok_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + return check_struct_type(arg, + ctx, + "f_str_tok", + "%T"); +} + +static bool +fstring_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + return check_struct_type(arg, + ctx, + "f_str_s", + "%V"); +} + +static bool +gstring_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + return check_struct_type(arg, + ctx, + "_GString", + "%v"); +} + +static bool +gerr_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx) +{ + return check_struct_type(arg, + ctx, + "_GError", + "%e"); } +}// namespace rspamd diff --git a/contrib/aho-corasick/acism.c b/contrib/aho-corasick/acism.c index e2b48a590..b0cee0d66 100644 --- a/contrib/aho-corasick/acism.c +++ b/contrib/aho-corasick/acism.c @@ -1,3 +1,19 @@ +/* + * Copyright 2024 Vsevolod Stakhov + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* ** Copyright (C) 2009-2014 Mischa Sandberg ** @@ -22,103 +38,104 @@ #include "_acism.h" #include "unix-std.h" -#define BACK ((SYMBOL)0) +#define BACK ((SYMBOL) 0) #define ROOT ((STATE) 0) -extern const guchar lc_map[256]; +extern const unsigned char lc_map[256]; -int -acism_lookup(ac_trie_t const *psp, const char *text, size_t len, - ACISM_ACTION *cb, void *context, int *statep, bool caseless) +int acism_lookup(ac_trie_t const *psp, const char *text, size_t len, + ACISM_ACTION *cb, void *context, int *statep, bool caseless) { - char const *cp = text, *endp = cp + len; - uint8_t s; - STATE state = *statep; - int ret = 0; - - while (cp < endp) { - s = caseless ? lc_map[(guint8)*cp++] : *cp++; - _SYMBOL sym = psp->symv[s]; - if (!sym) { - // Input byte is not in any pattern string. - state = ROOT; - continue; - } - - // Search for a valid transition from this (state, sym), - // following the backref chain. - - TRAN next; - while (!t_valid(psp, next = p_tran(psp, state, sym)) && state != ROOT) { - TRAN back = p_tran(psp, state, BACK); - state = t_valid(psp, back) ? t_next(psp, back) : ROOT; - } - - if (!t_valid(psp, next)) - continue; - - if (!(next & (IS_MATCH | IS_SUFFIX))) { - // No complete match yet; keep going. - state = t_next(psp, next); - continue; - } - - // At this point, one or more patterns have matched. - // Find all matches by following the backref chain. - // A valid node for (sym) with no SUFFIX flag marks the - // end of the suffix chain. - // In the same backref traversal, find a new (state), - // if the original transition is to a leaf. - - STATE s = state; - - // Initially state is ROOT. The chain search saves the - // first state from which the next char has a transition. - state = t_isleaf(psp, next) ? 0 : t_next(psp, next); - - while (1) { - - if (t_valid(psp, next)) { - - if (next & IS_MATCH) { - unsigned strno, ss = s + sym, i; - if (t_isleaf(psp, psp->tranv[ss])) { - strno = t_strno(psp, psp->tranv[ss]); - } else { - for (i = p_hash(psp, ss); psp->hashv[i].state != ss; ++i); - strno = psp->hashv[i].strno; - } - - if ((ret = cb(strno, cp - text, context))) - goto EXIT; - } - - if (!state && !t_isleaf(psp, next)) - state = t_next(psp, next); - if ( state && !(next & IS_SUFFIX)) - break; - } - - if (s == ROOT) - break; - - TRAN b = p_tran(psp, s, BACK); - s = t_valid(psp, b) ? t_next(psp, b) : ROOT; - next = p_tran(psp, s, sym); - } - } + char const *cp = text, *endp = cp + len; + uint8_t s; + STATE state = *statep; + int ret = 0; + + while (cp < endp) { + s = caseless ? lc_map[(uint8_t) *cp++] : *cp++; + _SYMBOL sym = psp->symv[s]; + if (!sym) { + // Input byte is not in any pattern string. + state = ROOT; + continue; + } + + // Search for a valid transition from this (state, sym), + // following the backref chain. + + TRAN next; + while (!t_valid(psp, next = p_tran(psp, state, sym)) && state != ROOT) { + TRAN back = p_tran(psp, state, BACK); + state = t_valid(psp, back) ? t_next(psp, back) : ROOT; + } + + if (!t_valid(psp, next)) + continue; + + if (!(next & (IS_MATCH | IS_SUFFIX))) { + // No complete match yet; keep going. + state = t_next(psp, next); + continue; + } + + // At this point, one or more patterns have matched. + // Find all matches by following the backref chain. + // A valid node for (sym) with no SUFFIX flag marks the + // end of the suffix chain. + // In the same backref traversal, find a new (state), + // if the original transition is to a leaf. + + STATE s = state; + + // Initially state is ROOT. The chain search saves the + // first state from which the next char has a transition. + state = t_isleaf(psp, next) ? 0 : t_next(psp, next); + + while (1) { + + if (t_valid(psp, next)) { + + if (next & IS_MATCH) { + unsigned strno, ss = s + sym, i; + if (t_isleaf(psp, psp->tranv[ss])) { + strno = t_strno(psp, psp->tranv[ss]); + } + else { + for (i = p_hash(psp, ss); psp->hashv[i].state != ss; ++i) + ; + strno = psp->hashv[i].strno; + } + + if ((ret = cb(strno, cp - text, context))) + goto EXIT; + } + + if (!state && !t_isleaf(psp, next)) + state = t_next(psp, next); + if (state && !(next & IS_SUFFIX)) + break; + } + + if (s == ROOT) + break; + + TRAN b = p_tran(psp, s, BACK); + s = t_valid(psp, b) ? t_next(psp, b) : ROOT; + next = p_tran(psp, s, sym); + } + } EXIT: *statep = state; - return ret; + return ret; } -void -acism_destroy(ac_trie_t *psp) +void acism_destroy(ac_trie_t *psp) { if (!psp) return; if (psp->flags & IS_MMAP) - munmap((char*)psp->tranv - sizeof(ac_trie_t), - sizeof(ac_trie_t) + p_size(psp)); - else g_free(psp->tranv); + munmap((char *) psp->tranv - sizeof(ac_trie_t), + sizeof(ac_trie_t) + p_size(psp)); + else + g_free(psp->tranv); g_free(psp); } //EOF diff --git a/contrib/cdb/cdb_init.c b/contrib/cdb/cdb_init.c index bfc6dd0c2..278506d21 100644 --- a/contrib/cdb/cdb_init.c +++ b/contrib/cdb/cdb_init.c @@ -18,8 +18,7 @@ cdb_hash(const void *buf, unsigned len) return hash; } -int -cdb_init(struct cdb *cdbp, int fd) +int cdb_init(struct cdb *cdbp, int fd) { struct stat st; unsigned char *mem; @@ -29,7 +28,7 @@ cdb_init(struct cdb *cdbp, int fd) #endif /* get file size */ - if (fstat (fd, &st) < 0) + if (fstat(fd, &st) < 0) return -1; /* trivial sanity check: at least toc should be here */ if (st.st_size < 2048) @@ -39,16 +38,16 @@ cdb_init(struct cdb *cdbp, int fd) #ifdef _WIN32 hFile = (HANDLE) _get_osfhandle(fd); if (hFile == (HANDLE) -1) - return -1; + return -1; hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); if (!hMapping) - return -1; - mem = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); + return -1; + mem = (unsigned char *) MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); CloseHandle(hMapping); if (!mem) - return -1; + return -1; #else - mem = (unsigned char*) mmap (NULL, fsize, PROT_READ, MAP_SHARED, fd, 0); + mem = (unsigned char *) mmap(NULL, fsize, PROT_READ, MAP_SHARED, fd, 0); if (mem == MAP_FAILED) return -1; #endif /* _WIN32 */ @@ -60,7 +59,7 @@ cdb_init(struct cdb *cdbp, int fd) cdbp->cdb_vpos = cdbp->cdb_vlen = 0; cdbp->cdb_kpos = cdbp->cdb_klen = 0; - dend = cdb_unpack (mem); + dend = cdb_unpack(mem); if (dend < 2048) dend = 2048; else if (dend >= fsize) @@ -70,21 +69,20 @@ cdb_init(struct cdb *cdbp, int fd) return 0; } -void -cdb_free(struct cdb *cdbp) +void cdb_free(struct cdb *cdbp) { if (cdbp->cdb_mem) { #ifdef _WIN32 - UnmapViewOfFile((void*) cdbp->cdb_mem); + UnmapViewOfFile((void *) cdbp->cdb_mem); #else - munmap ((void*) cdbp->cdb_mem, cdbp->cdb_fsize); + munmap((void *) cdbp->cdb_mem, cdbp->cdb_fsize); #endif /* _WIN32 */ cdbp->cdb_mem = NULL; } cdbp->cdb_fsize = 0; if (cdbp->loop) { - ev_stat_stop (cdbp->loop, &cdbp->stat_ev); + ev_stat_stop(cdbp->loop, &cdbp->stat_ev); } } @@ -98,43 +96,41 @@ cdb_get(const struct cdb *cdbp, unsigned len, unsigned pos) return cdbp->cdb_mem + pos; } -int -cdb_read(const struct cdb *cdbp, void *buf, unsigned len, unsigned pos) +int cdb_read(const struct cdb *cdbp, void *buf, unsigned len, unsigned pos) { - const void *data = cdb_get (cdbp, len, pos); + const void *data = cdb_get(cdbp, len, pos); if (!data) return -1; - memcpy (buf, data, len); + memcpy(buf, data, len); return 0; } static void -cdb_timer_callback (EV_P_ ev_stat *w, int revents) +cdb_timer_callback(EV_P_ ev_stat *w, int revents) { struct cdb *cdbp = w->data; - gint nfd; + int nfd; /* Check cdb file for modifications */ - if ((nfd = open (cdbp->filename, O_RDONLY)) != -1) { + if ((nfd = open(cdbp->filename, O_RDONLY)) != -1) { if (cdbp->cdb_mem) { #ifdef _WIN32 - UnmapViewOfFile((void*) cdbp->cdb_mem); + UnmapViewOfFile((void *) cdbp->cdb_mem); #else - munmap ((void*) cdbp->cdb_mem, cdbp->cdb_fsize); + munmap((void *) cdbp->cdb_mem, cdbp->cdb_fsize); #endif /* _WIN32 */ cdbp->cdb_mem = NULL; } - (void)close (cdbp->cdb_fd); + (void) close(cdbp->cdb_fd); cdbp->cdb_fsize = 0; - (void)cdb_init (cdbp, nfd); + (void) cdb_init(cdbp, nfd); } } -void -cdb_add_timer (struct cdb *cdbp, EV_P_ ev_tstamp seconds) +void cdb_add_timer(struct cdb *cdbp, EV_P_ ev_tstamp seconds) { cdbp->loop = loop; - ev_stat_init (&cdbp->stat_ev, cdb_timer_callback, cdbp->filename, seconds); + ev_stat_init(&cdbp->stat_ev, cdb_timer_callback, cdbp->filename, seconds); cdbp->stat_ev.data = cdbp; - ev_stat_start (EV_A_ &cdbp->stat_ev); + ev_stat_start(EV_A_ & cdbp->stat_ev); } diff --git a/contrib/lc-btrie/btrie.c b/contrib/lc-btrie/btrie.c index 81b69b2b9..c7272ec20 100644 --- a/contrib/lc-btrie/btrie.c +++ b/contrib/lc-btrie/btrie.c @@ -302,8 +302,8 @@ #include #include #if defined(TEST) && defined(NDEBUG) -# warning undefining NDEBUG for TEST build -# undef NDEBUG +#warning undefining NDEBUG for TEST build +#undef NDEBUG #endif #include @@ -314,54 +314,54 @@ #define SIZEOF_VOID_P __SIZEOF_POINTER__ #else #if defined(__ILP32__) || defined(__ILP32) || defined(_ILP32) -# define SIZEOF_VOID_P 4 +#define SIZEOF_VOID_P 4 #elif defined(__ILP64__) || defined(__ILP64) || defined(_ILP64) -# define SIZEOF_VOID_P 8 +#define SIZEOF_VOID_P 8 #elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) -# define SIZEOF_VOID_P 8 +#define SIZEOF_VOID_P 8 #elif defined(__LP64__) || defined(__LP64) || defined(_LP64) -# define SIZEOF_VOID_P 8 +#define SIZEOF_VOID_P 8 #elif defined(UINTPTR_MAX) && defined(UINT64_MAX) && (UINTPTR_MAX == UINT64_MAX) -# define SIZEOF_VOID_P 8 +#define SIZEOF_VOID_P 8 #else -# define SIZEOF_VOID_P 4 +#define SIZEOF_VOID_P 4 #endif #endif #if SIZEOF_VOID_P == 4 -# define TBM_STRIDE 4 +#define TBM_STRIDE 4 #elif SIZEOF_VOID_P == 8 -# define TBM_STRIDE 5 +#define TBM_STRIDE 5 #else -# error "Unsupported word size" +#error "Unsupported word size" #endif #ifndef NO_STDINT_H -# if TBM_STRIDE == 4 +#if TBM_STRIDE == 4 typedef uint16_t tbm_bitmap_t; -# else +#else typedef uint32_t tbm_bitmap_t; -# endif +#endif #else /* NO_STDINT_H */ -# if TBM_STRIDE == 4 -# if SIZEOF_SHORT == 2 +#if TBM_STRIDE == 4 +#if SIZEOF_SHORT == 2 typedef short unsigned tbm_bitmap_t; -# else -# error "can not determine type for 16 bit unsigned int" -# endif -# else /* TBM_STRIDE == 5 */ -# if SIZEOF_INT == 4 +#else +#error "can not determine type for 16 bit unsigned int" +#endif +#else /* TBM_STRIDE == 5 */ +#if SIZEOF_INT == 4 typedef unsigned tbm_bitmap_t; -# elif SIZEOF_LONG == 4 +#elif SIZEOF_LONG == 4 typedef long unsigned tbm_bitmap_t; -# else -# error "can not determine type for 32 bit unsigned int" -# endif -# endif +#else +#error "can not determine type for 32 bit unsigned int" +#endif +#endif #endif -#define TBM_FANOUT (1U << TBM_STRIDE) -#define LC_BYTES_PER_NODE (SIZEOF_VOID_P - 1) +#define TBM_FANOUT (1U << TBM_STRIDE) +#define LC_BYTES_PER_NODE (SIZEOF_VOID_P - 1) typedef union node_u node_t; @@ -373,8 +373,7 @@ typedef union node_u node_t; * lc_node.) */ -struct tbm_node -{ +struct tbm_node { #ifdef WORDS_BIGENDIAN tbm_bitmap_t int_bm; /* the internal bitmap */ tbm_bitmap_t ext_bm; /* extending path ("external") bitmap */ @@ -382,21 +381,19 @@ struct tbm_node tbm_bitmap_t ext_bm; /* extending path ("external") bitmap */ tbm_bitmap_t int_bm; /* the internal bitmap */ #endif - union - { - node_t *children; /* pointer to array of children */ + union { + node_t *children; /* pointer to array of children */ const void **data_end; /* one past end of internal prefix data array */ } ptr; }; -struct lc_node -{ +struct lc_node { /* lc_flags contains the LC prefix length and a couple of bit flags * (apparently char-sized bit fields are a gcc extension) */ -# define LC_FLAGS_IS_LC 0x80 -# define LC_FLAGS_IS_TERMINAL 0x40 -# define LC_FLAGS_LEN_MASK 0x3f +#define LC_FLAGS_IS_LC 0x80 +#define LC_FLAGS_IS_TERMINAL 0x40 +#define LC_FLAGS_LEN_MASK 0x3f #ifdef WORDS_BIGENDIAN btrie_oct_t lc_flags; btrie_oct_t prefix[LC_BYTES_PER_NODE]; @@ -404,28 +401,24 @@ struct lc_node btrie_oct_t prefix[LC_BYTES_PER_NODE]; btrie_oct_t lc_flags; #endif - union - { - node_t *child; /* pointer to child (if !is_terminal) */ + union { + node_t *child; /* pointer to child (if !is_terminal) */ const void *data; /* the prefix data (if is_terminal) */ } ptr; }; -union node_u -{ +union node_u { struct tbm_node tbm_node; struct lc_node lc_node; }; -struct free_hunk -{ +struct free_hunk { struct free_hunk *next; }; #define MAX_CHILD_ARRAY_LEN (TBM_FANOUT + TBM_FANOUT / 2) -struct btrie -{ +struct btrie { node_t root; rspamd_mempool_t *mp; @@ -433,16 +426,16 @@ struct btrie jmp_buf exception; /* mem mgmt stats */ size_t alloc_total; /* total bytes allocated from mempool */ - size_t alloc_data; /* bytes allocated for TBM node int. prefix data */ + size_t alloc_data; /* bytes allocated for TBM node int. prefix data */ size_t alloc_waste; /* bytes wasted by rounding of data array size */ #ifdef BTRIE_DEBUG_ALLOC size_t alloc_hist[MAX_CHILD_ARRAY_LEN * 2]; /* histogram of alloc sizes */ #endif /* trie stats */ - size_t n_entries; /* number of entries */ + size_t n_entries; /* number of entries */ size_t n_tbm_nodes; /* total number of TBM nodes in tree */ - size_t n_lc_nodes; /* total number of LC nodes in tree */ + size_t n_lc_nodes; /* total number of LC nodes in tree */ }; /**************************************************************** @@ -487,7 +480,7 @@ alloc_nodes(struct btrie *btrie, unsigned nchildren, unsigned ndata) assert(n_nodes > 0 && n_nodes <= MAX_CHILD_ARRAY_LEN); - hunk = _get_hunk (btrie, n_nodes); + hunk = _get_hunk(btrie, n_nodes); if (hunk == NULL) { /* Do not have free hunk of exactly the requested size, look for a * larger hunk. (The funny order in which we scan the buckets is @@ -496,27 +489,28 @@ alloc_nodes(struct btrie *btrie, unsigned nchildren, unsigned ndata) */ size_t n, skip = n_nodes > 4 ? 4 : n_nodes; for (n = n_nodes + skip; n <= MAX_CHILD_ARRAY_LEN; n++) { - if ((hunk = _get_hunk (btrie, n)) != NULL) { - _free_hunk (btrie, hunk + n_nodes, n - n_nodes); + if ((hunk = _get_hunk(btrie, n)) != NULL) { + _free_hunk(btrie, hunk + n_nodes, n - n_nodes); goto DONE; } } for (n = n_nodes + 1; n < n_nodes + skip && n <= MAX_CHILD_ARRAY_LEN; - n++) { - if ((hunk = _get_hunk (btrie, n)) != NULL) { - _free_hunk (btrie, hunk + n_nodes, n - n_nodes); + n++) { + if ((hunk = _get_hunk(btrie, n)) != NULL) { + _free_hunk(btrie, hunk + n_nodes, n - n_nodes); goto DONE; } } /* failed to find free hunk, allocate a fresh one */ - hunk = rspamd_mempool_alloc0 (btrie->mp, n_nodes * sizeof(node_t)); + hunk = rspamd_mempool_alloc0(btrie->mp, n_nodes * sizeof(node_t)); if (hunk == NULL) - longjmp (btrie->exception, BTRIE_ALLOC_FAILED); + longjmp(btrie->exception, BTRIE_ALLOC_FAILED); btrie->alloc_total += n_nodes * sizeof(node_t); } - DONE: btrie->alloc_data += ndata * sizeof(void *); +DONE: + btrie->alloc_data += ndata * sizeof(void *); btrie->alloc_waste += (ndata % 2) * sizeof(void *); #ifdef BTRIE_DEBUG_ALLOC btrie->alloc_hist[2 * nchildren + ndata]++; @@ -528,13 +522,13 @@ alloc_nodes(struct btrie *btrie, unsigned nchildren, unsigned ndata) /* Free memory allocated by alloc_nodes */ static void free_nodes(struct btrie *btrie, node_t *buf, unsigned nchildren, - unsigned ndata) + unsigned ndata) { size_t n_nodes = nchildren + (ndata + 1) / 2; assert(n_nodes > 0 && n_nodes <= MAX_CHILD_ARRAY_LEN); - _free_hunk (btrie, buf - (ndata + 1) / 2, n_nodes); + _free_hunk(btrie, buf - (ndata + 1) / 2, n_nodes); btrie->alloc_data -= ndata * sizeof(void *); btrie->alloc_waste -= (ndata % 2) * sizeof(void *); @@ -567,12 +561,12 @@ dump_alloc_hist(const struct btrie *btrie) if (bin % 2 == 0) { const struct free_hunk *hunk; for (hunk = btrie->free_list[bin / 2 - 1]; hunk; hunk = hunk->next) - n_free++; + n_free++; } free_bytes = n_free * bin * sizeof(void *); printf("%3zu: %6zu %6zu %8zu %8zu %8zu\n", bin * sizeof(void *), - n_alloc, n_free, bytes, waste_bytes, free_bytes); + n_alloc, n_free, bytes, waste_bytes, free_bytes); total_alloc += n_alloc; total_free += n_free; @@ -582,7 +576,7 @@ dump_alloc_hist(const struct btrie *btrie) } puts("---- ------ ------ -------- -------- --------"); printf("SUM: %6zu %6zu %8zu %8zu %8zu\n", - total_alloc, total_free, total_bytes, total_waste, total_free_bytes); + total_alloc, total_free, total_bytes, total_waste, total_free_bytes); } #endif @@ -622,17 +616,17 @@ static inline unsigned count_bits(tbm_bitmap_t v) static inline unsigned count_bits_before(tbm_bitmap_t bm, int b) { - return b ? count_bits (bm >> ((1 << TBM_STRIDE) - b)) : 0; + return b ? count_bits(bm >> ((1 << TBM_STRIDE) - b)) : 0; } static inline unsigned count_bits_from(tbm_bitmap_t bm, int b) { - return count_bits (bm << b); + return count_bits(bm << b); } /* extracts a few bits from bitstring, returning them as an integer */ static inline btrie_oct_t RSPAMD_NO_SANITIZE extract_bits(const btrie_oct_t *prefix, unsigned pos, - unsigned nbits) + unsigned nbits) { if (nbits == 0) return 0; @@ -650,38 +644,283 @@ static inline unsigned extract_bit(const btrie_oct_t *prefix, int pos) /* get mask for high n bits of a byte */ static inline btrie_oct_t high_bits(unsigned n) { - return (btrie_oct_t) -(1U << (8 - n)); + return (btrie_oct_t) - (1U << (8 - n)); } /* determine whether two prefixes are equal */ static inline int prefixes_equal(const btrie_oct_t *pfx1, - const btrie_oct_t *pfx2, unsigned len) + const btrie_oct_t *pfx2, unsigned len) { - return (memcmp (pfx1, pfx2, len / 8) == 0 - && (len % 8 == 0 || - ((pfx1[len / 8] ^ pfx2[len / 8]) & high_bits (len % 8)) == 0)); + return (memcmp(pfx1, pfx2, len / 8) == 0 && (len % 8 == 0 || + ((pfx1[len / 8] ^ pfx2[len / 8]) & high_bits(len % 8)) == 0)); } /* determine length of longest common subprefix */ static inline unsigned common_prefix(const btrie_oct_t *pfx1, - const btrie_oct_t *pfx2, unsigned len) + const btrie_oct_t *pfx2, unsigned len) { /* algorithm adapted from * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup */ static btrie_oct_t leading_zeros[] = - { 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, }; + { + 8, + 7, + 6, + 6, + 5, + 5, + 5, + 5, + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + }; unsigned nb; for (nb = 0; nb < len / 8; nb++) { @@ -712,13 +951,13 @@ static inline int is_lc_node(const node_t *node) static inline int is_tbm_node(const node_t *node) { - return !is_lc_node (node); + return !is_lc_node(node); } /* is node a TBM node with internal data? */ static inline int has_data(const node_t *node) { - return is_tbm_node (node) && node->tbm_node.int_bm != 0; + return is_tbm_node(node) && node->tbm_node.int_bm != 0; } static inline unsigned base_index(unsigned pfx, unsigned plen) @@ -739,108 +978,136 @@ static inline void init_empty_node(struct btrie *btrie, node_t *node) static inline const void ** tbm_data_p(const struct tbm_node *node, unsigned pfx, unsigned plen) { - unsigned bi = base_index (pfx, plen); + unsigned bi = base_index(pfx, plen); - if ((node->int_bm & bit (bi)) == 0) + if ((node->int_bm & bit(bi)) == 0) return NULL; /* no data */ else { - return &node->ptr.data_end[-(int) count_bits_from (node->int_bm, bi)]; + return &node->ptr.data_end[-(int) count_bits_from(node->int_bm, bi)]; } } /* add an element to the internal data array */ static void tbm_insert_data(struct btrie *btrie, struct tbm_node *node, - unsigned pfx, unsigned plen, const void *data) + unsigned pfx, unsigned plen, const void *data) { /* XXX: don't realloc if already big enough? */ - unsigned bi = base_index (pfx, plen); - unsigned nchildren = count_bits (node->ext_bm); - int ndata = count_bits (node->int_bm); - unsigned di = count_bits_before (node->int_bm, bi); + unsigned bi = base_index(pfx, plen); + unsigned nchildren = count_bits(node->ext_bm); + int ndata = count_bits(node->int_bm); + unsigned di = count_bits_before(node->int_bm, bi); node_t *old_children = node->ptr.children; const void **old_data_beg = node->ptr.data_end - ndata; const void **data_beg; - assert((node->int_bm & bit (bi)) == 0); + assert((node->int_bm & bit(bi)) == 0); - node->ptr.children = alloc_nodes (btrie, nchildren, ndata + 1); + node->ptr.children = alloc_nodes(btrie, nchildren, ndata + 1); data_beg = node->ptr.data_end - (ndata + 1); data_beg[di] = data; - node->int_bm |= bit (bi); + node->int_bm |= bit(bi); if (nchildren != 0 || ndata != 0) { memcpy(data_beg, old_data_beg, di * sizeof(data_beg[0])); memcpy(&data_beg[di + 1], &old_data_beg[di], - (ndata - di) * sizeof(data_beg[0]) - + nchildren * sizeof(node_t)); - free_nodes (btrie, old_children, nchildren, ndata); + (ndata - di) * sizeof(data_beg[0]) + nchildren * sizeof(node_t)); + free_nodes(btrie, old_children, nchildren, ndata); } } /* determine whether TBM has internal prefix data for pfx/plen or ancestors */ static inline int has_internal_data(const struct tbm_node *node, unsigned pfx, - unsigned plen) + unsigned plen) { -# define BIT(n) (1U << ((1 << TBM_STRIDE) - 1 - (n))) -# define B0() BIT(1) /* the bit for 0/0 */ -# define B1(n) (BIT((n) + 2) | B0()) /* the bits for n/1 and its ancestors */ -# define B2(n) (BIT((n) + 4) | B1(n >> 1)) /* the bits for n/2 and ancestors */ -# define B3(n) (BIT((n) + 8) | B2(n >> 1)) /* the bits for n/3 and ancestors */ -# define B4(n) (BIT((n) + 16) | B3(n >> 1)) /* the bits for n/4 and ancestors */ +#define BIT(n) (1U << ((1 << TBM_STRIDE) - 1 - (n))) +#define B0() BIT(1) /* the bit for 0/0 */ +#define B1(n) (BIT((n) + 2) | B0()) /* the bits for n/1 and its ancestors */ +#define B2(n) (BIT((n) + 4) | B1(n >> 1)) /* the bits for n/2 and ancestors */ +#define B3(n) (BIT((n) + 8) | B2(n >> 1)) /* the bits for n/3 and ancestors */ +#define B4(n) (BIT((n) + 16) | B3(n >> 1)) /* the bits for n/4 and ancestors */ static tbm_bitmap_t ancestors[] = - { 0, B0(), B1(0), B1(1), B2(0), B2(1), B2(2), B2(3), B3(0), B3(1), B3(2), - B3(3), B3(4), B3(5), B3(6), B3(7), -# if TBM_STRIDE == 5 - B4(0), B4(1), B4(2), B4(3), B4(4), B4(5), B4(6), B4(7), B4(8), B4( - 9), B4(10), B4(11), B4(12), B4(13), B4(14), B4(15), -# elif TBM_STRIDE != 4 -# error "unsupported TBM_STRIDE" -# endif - }; -# undef B4 -# undef B3 -# undef B2 -# undef B1 -# undef B0 -# undef BIT - - return (node->int_bm & ancestors[base_index (pfx, plen)]) != 0; + { 0, + B0(), + B1(0), + B1(1), + B2(0), + B2(1), + B2(2), + B2(3), + B3(0), + B3(1), + B3(2), + B3(3), + B3(4), + B3(5), + B3(6), + B3(7), +#if TBM_STRIDE == 5 + B4(0), + B4(1), + B4(2), + B4(3), + B4(4), + B4(5), + B4(6), + B4(7), + B4(8), + B4( + 9), + B4(10), + B4(11), + B4(12), + B4(13), + B4(14), + B4(15), +#elif TBM_STRIDE != 4 +#error "unsupported TBM_STRIDE" +#endif + }; +#undef B4 +#undef B3 +#undef B2 +#undef B1 +#undef B0 +#undef BIT + + return (node->int_bm & ancestors[base_index(pfx, plen)]) != 0; } /* get pointer to TBM extending path */ static inline node_t * tbm_ext_path(const struct tbm_node *node, unsigned pfx) { - if ((node->ext_bm & bit (pfx)) == 0) + if ((node->ext_bm & bit(pfx)) == 0) return NULL; else - return &node->ptr.children[count_bits_before (node->ext_bm, pfx)]; + return &node->ptr.children[count_bits_before(node->ext_bm, pfx)]; } /* resize TBM node child array to make space for new child node */ static node_t * tbm_insert_ext_path(struct btrie *btrie, struct tbm_node *node, unsigned pfx) { - unsigned nchildren = count_bits (node->ext_bm); - unsigned ci = count_bits_before (node->ext_bm, pfx); - int ndata = count_bits (node->int_bm); + unsigned nchildren = count_bits(node->ext_bm); + unsigned ci = count_bits_before(node->ext_bm, pfx); + int ndata = count_bits(node->int_bm); node_t *old_children = node->ptr.children; const void **old_data_beg = node->ptr.data_end - ndata; - assert((node->ext_bm & bit (pfx)) == 0); + assert((node->ext_bm & bit(pfx)) == 0); - node->ptr.children = alloc_nodes (btrie, nchildren + 1, ndata); - init_empty_node (btrie, &node->ptr.children[ci]); - node->ext_bm |= bit (pfx); + node->ptr.children = alloc_nodes(btrie, nchildren + 1, ndata); + init_empty_node(btrie, &node->ptr.children[ci]); + node->ext_bm |= bit(pfx); if (nchildren != 0 || ndata != 0) { const void **data_beg = node->ptr.data_end - ndata; memcpy(data_beg, old_data_beg, - ndata * sizeof(data_beg[0]) + ci * sizeof(node_t)); + ndata * sizeof(data_beg[0]) + ci * sizeof(node_t)); memcpy(&node->ptr.children[ci + 1], &old_children[ci], - (nchildren - ci) * sizeof(old_children[0])); - free_nodes (btrie, old_children, nchildren, ndata); + (nchildren - ci) * sizeof(old_children[0])); + free_nodes(btrie, old_children, nchildren, ndata); } return &node->ptr.children[ci]; @@ -857,7 +1124,7 @@ static inline unsigned lc_len(const struct lc_node *node) } static inline void lc_init_flags(struct lc_node *node, int is_terminal, - unsigned len) + unsigned len) { assert((len & ~LC_FLAGS_LEN_MASK) == 0); node->lc_flags = LC_FLAGS_IS_LC | len; @@ -867,7 +1134,7 @@ static inline void lc_init_flags(struct lc_node *node, int is_terminal, static inline void lc_add_to_len(struct lc_node *node, int increment) { - unsigned new_len = lc_len (node) + increment; + unsigned new_len = lc_len(node) + increment; assert((new_len & ~LC_FLAGS_LEN_MASK) == 0); node->lc_flags = (node->lc_flags & ~LC_FLAGS_LEN_MASK) | new_len; } @@ -879,23 +1146,23 @@ static inline unsigned lc_shift(unsigned pos) static inline unsigned lc_base(unsigned pos) { - return 8 * lc_shift (pos); + return 8 * lc_shift(pos); } static inline unsigned lc_bits(const struct lc_node *node, unsigned pos) { - return pos % 8 + lc_len (node); + return pos % 8 + lc_len(node); } static inline unsigned lc_bytes(const struct lc_node *node, unsigned pos) { - return (lc_bits (node, pos) + 7) / 8; + return (lc_bits(node, pos) + 7) / 8; } static inline unsigned lc_leading_bits(const struct lc_node *node, unsigned pos, - unsigned nbits) + unsigned nbits) { - return extract_bits (node->prefix, pos % 8, nbits); + return extract_bits(node->prefix, pos % 8, nbits); } /* Initialize a new terminal LC node @@ -904,22 +1171,22 @@ static inline unsigned lc_leading_bits(const struct lc_node *node, unsigned pos, * of LC nodes will be created. */ static void init_terminal_node(struct btrie *btrie, node_t *dst, unsigned pos, - const btrie_oct_t *prefix, unsigned len, const void *data) + const btrie_oct_t *prefix, unsigned len, const void *data) { struct lc_node *node = &dst->lc_node; unsigned nbytes = (len + 7) / 8; - while (nbytes - lc_shift (pos) > LC_BYTES_PER_NODE) { - memcpy(node->prefix, prefix + lc_shift (pos), LC_BYTES_PER_NODE); - lc_init_flags (node, 0, 8 * LC_BYTES_PER_NODE - pos % 8); - node->ptr.child = alloc_nodes (btrie, 1, 0); - pos += lc_len (node); + while (nbytes - lc_shift(pos) > LC_BYTES_PER_NODE) { + memcpy(node->prefix, prefix + lc_shift(pos), LC_BYTES_PER_NODE); + lc_init_flags(node, 0, 8 * LC_BYTES_PER_NODE - pos % 8); + node->ptr.child = alloc_nodes(btrie, 1, 0); + pos += lc_len(node); node = &node->ptr.child->lc_node; btrie->n_lc_nodes++; } - memcpy(node->prefix, prefix + lc_shift (pos), nbytes - lc_shift (pos)); - lc_init_flags (node, 1, len - pos); + memcpy(node->prefix, prefix + lc_shift(pos), nbytes - lc_shift(pos)); + lc_init_flags(node, 1, len - pos); node->ptr.data = data; btrie->n_lc_nodes++; } @@ -929,75 +1196,74 @@ static void init_terminal_node(struct btrie *btrie, node_t *dst, unsigned pos, * also ensure that the leading nodes in the LC chain have maximum length. */ static void coalesce_lc_node(struct btrie *btrie, struct lc_node *node, - unsigned pos) + unsigned pos) { - while (!lc_is_terminal (node) && lc_bits (node, pos) < 8 * LC_BYTES_PER_NODE - && is_lc_node (node->ptr.child)) { + while (!lc_is_terminal(node) && lc_bits(node, pos) < 8 * LC_BYTES_PER_NODE && is_lc_node(node->ptr.child)) { struct lc_node *child = &node->ptr.child->lc_node; - unsigned spare_bits = 8 * LC_BYTES_PER_NODE - lc_bits (node, pos); - unsigned end = pos + lc_len (node); - unsigned shift = lc_shift (end) - lc_shift (pos); - if (lc_len (child) <= spare_bits) { + unsigned spare_bits = 8 * LC_BYTES_PER_NODE - lc_bits(node, pos); + unsigned end = pos + lc_len(node); + unsigned shift = lc_shift(end) - lc_shift(pos); + if (lc_len(child) <= spare_bits) { /* node plus child will fit in single node - merge */ - memcpy(node->prefix + shift, child->prefix, lc_bytes (child, end)); - lc_init_flags (node, lc_is_terminal (child), - lc_len (node) + lc_len (child)); + memcpy(node->prefix + shift, child->prefix, lc_bytes(child, end)); + lc_init_flags(node, lc_is_terminal(child), + lc_len(node) + lc_len(child)); node->ptr = child->ptr; - free_nodes (btrie, (node_t *) child, 1, 0); + free_nodes(btrie, (node_t *) child, 1, 0); btrie->n_lc_nodes--; } else { /* can't merge, but can take some of children bits */ - unsigned cshift = lc_shift (end + spare_bits) - lc_shift (end); + unsigned cshift = lc_shift(end + spare_bits) - lc_shift(end); memcpy(node->prefix + shift, child->prefix, - LC_BYTES_PER_NODE - shift); - lc_add_to_len (node, spare_bits); + LC_BYTES_PER_NODE - shift); + lc_add_to_len(node, spare_bits); if (cshift) memmove(child->prefix, child->prefix + cshift, - lc_bytes (child, end) - cshift); - assert(lc_len (child) > spare_bits); - lc_add_to_len (child, -spare_bits); + lc_bytes(child, end) - cshift); + assert(lc_len(child) > spare_bits); + lc_add_to_len(child, -spare_bits); - pos += lc_len (node); + pos += lc_len(node); node = child; } } } static void init_tbm_node(struct btrie *btrie, node_t *node, unsigned pos, - const btrie_oct_t pbyte, const void **root_data_p, node_t *left, - node_t *right); + const btrie_oct_t pbyte, const void **root_data_p, node_t *left, + node_t *right); /* given an LC node at orig_pos, create a new (shorter) node at pos */ static void shorten_lc_node(struct btrie *btrie, node_t *dst, unsigned pos, - struct lc_node *src, unsigned orig_pos) + struct lc_node *src, unsigned orig_pos) { assert(orig_pos < pos); - assert(lc_len (src) >= pos - orig_pos); - assert(dst != (node_t * )src); + assert(lc_len(src) >= pos - orig_pos); + assert(dst != (node_t *) src); - if (lc_len (src) == pos - orig_pos && !lc_is_terminal (src)) { + if (lc_len(src) == pos - orig_pos && !lc_is_terminal(src)) { /* just steal the child */ node_t *child = src->ptr.child; *dst = *child; - free_nodes (btrie, child, 1, 0); + free_nodes(btrie, child, 1, 0); btrie->n_lc_nodes--; } else { struct lc_node *node = &dst->lc_node; - unsigned shift = lc_shift (pos) - lc_shift (orig_pos); + unsigned shift = lc_shift(pos) - lc_shift(orig_pos); if (shift) { memmove(node->prefix, src->prefix + shift, - lc_bytes (src, orig_pos) - shift); + lc_bytes(src, orig_pos) - shift); node->lc_flags = src->lc_flags; node->ptr = src->ptr; } else { *node = *src; } - lc_add_to_len (node, -(pos - orig_pos)); - coalesce_lc_node (btrie, node, pos); + lc_add_to_len(node, -(pos - orig_pos)); + coalesce_lc_node(btrie, node, pos); } } @@ -1006,101 +1272,101 @@ static void shorten_lc_node(struct btrie *btrie, node_t *dst, unsigned pos, * on entry, node must have length at least len */ static void split_lc_node(struct btrie *btrie, struct lc_node *node, - unsigned pos, unsigned len) + unsigned pos, unsigned len) { - node_t *child = alloc_nodes (btrie, 1, 0); + node_t *child = alloc_nodes(btrie, 1, 0); - assert(lc_len (node) >= len); - shorten_lc_node (btrie, child, pos + len, node, pos); + assert(lc_len(node) >= len); + shorten_lc_node(btrie, child, pos + len, node, pos); - lc_init_flags (node, 0, len); + lc_init_flags(node, 0, len); node->ptr.child = child; btrie->n_lc_nodes++; } /* convert non-terminal LC node of length one to a TBM node *in place* */ static void convert_lc_node_1(struct btrie *btrie, struct lc_node *node, - unsigned pos) + unsigned pos) { btrie_oct_t pbyte = node->prefix[0]; node_t *child = node->ptr.child; node_t *left, *right; - assert(lc_len (node) == 1); - assert(!lc_is_terminal (node)); + assert(lc_len(node) == 1); + assert(!lc_is_terminal(node)); - if (extract_bit (node->prefix, pos % 8)) + if (extract_bit(node->prefix, pos % 8)) left = NULL, right = child; else left = child, right = NULL; - init_tbm_node (btrie, (node_t *) node, pos, pbyte, NULL, left, right); - free_nodes (btrie, child, 1, 0); + init_tbm_node(btrie, (node_t *) node, pos, pbyte, NULL, left, right); + free_nodes(btrie, child, 1, 0); btrie->n_lc_nodes--; } /* convert an LC node to TBM node *in place* */ static void convert_lc_node(struct btrie *btrie, struct lc_node *node, - unsigned pos) + unsigned pos) { - unsigned len = lc_len (node); + unsigned len = lc_len(node); if (len >= TBM_STRIDE) { - unsigned pfx = lc_leading_bits (node, pos, TBM_STRIDE); + unsigned pfx = lc_leading_bits(node, pos, TBM_STRIDE); struct tbm_node *result = (struct tbm_node *) node; /* split to LC of len TBM_STRIDE followed by child (extending path) */ - split_lc_node (btrie, node, pos, TBM_STRIDE); + split_lc_node(btrie, node, pos, TBM_STRIDE); /* then convert leading LC node to TBM node */ result->int_bm = 0; - result->ext_bm = bit (pfx); + result->ext_bm = bit(pfx); btrie->n_lc_nodes--; btrie->n_tbm_nodes++; } - else if (lc_is_terminal (node)) { + else if (lc_is_terminal(node)) { /* convert short terminal LC to TBM (with internal data) */ - unsigned pfx = lc_leading_bits (node, pos, len); + unsigned pfx = lc_leading_bits(node, pos, len); const void *data = node->ptr.data; node_t *result = (node_t *) node; - init_empty_node (btrie, result); - tbm_insert_data (btrie, &result->tbm_node, pfx, len, data); + init_empty_node(btrie, result); + tbm_insert_data(btrie, &result->tbm_node, pfx, len, data); btrie->n_lc_nodes--; } else { assert(len > 0); for (; len > 1; len--) { - split_lc_node (btrie, node, pos, len - 1); - convert_lc_node_1 (btrie, &node->ptr.child->lc_node, pos + len - 1); + split_lc_node(btrie, node, pos, len - 1); + convert_lc_node_1(btrie, &node->ptr.child->lc_node, pos + len - 1); } - convert_lc_node_1 (btrie, node, pos); + convert_lc_node_1(btrie, node, pos); } } static void insert_lc_node(struct btrie *btrie, node_t *dst, unsigned pos, - btrie_oct_t pbyte, unsigned last_bit, node_t *tail) + btrie_oct_t pbyte, unsigned last_bit, node_t *tail) { struct lc_node *node = &dst->lc_node; btrie_oct_t mask = 1 << (7 - (pos % 8)); btrie_oct_t bit = last_bit ? mask : 0; - if (mask != 0x01 && is_lc_node (tail)) { + if (mask != 0x01 && is_lc_node(tail)) { /* optimization: LC tail has room for the extra bit (without shifting) */ assert((tail->lc_node.prefix[0] & mask) == bit); *node = tail->lc_node; - lc_add_to_len (node, 1); + lc_add_to_len(node, 1); return; } /* add new leading LC node of len 1 */ node->prefix[0] = pbyte | bit; - lc_init_flags (node, 0, 1); - node->ptr.child = alloc_nodes (btrie, 1, 0); + lc_init_flags(node, 0, 1); + node->ptr.child = alloc_nodes(btrie, 1, 0); node->ptr.child[0] = *tail; btrie->n_lc_nodes++; - if (is_lc_node (tail)) - coalesce_lc_node (btrie, node, pos); + if (is_lc_node(tail)) + coalesce_lc_node(btrie, node, pos); } /* given: @@ -1110,14 +1376,14 @@ static void insert_lc_node(struct btrie *btrie, node_t *dst, unsigned pos, * the bits in the prefix between lc_base(pos + plen) and pos + plen */ static inline btrie_oct_t next_pbyte(btrie_oct_t pbyte, unsigned pos, - unsigned pfx) + unsigned pfx) { unsigned end = pos + TBM_STRIDE; if (end % 8 != 0) { btrie_oct_t nbyte = (btrie_oct_t) pfx << (8 - end % 8); if (end % 8 > TBM_STRIDE) - nbyte |= pbyte & high_bits (pos % 8); + nbyte |= pbyte & high_bits(pos % 8); return nbyte; } return 0; @@ -1127,8 +1393,8 @@ static inline btrie_oct_t next_pbyte(btrie_oct_t pbyte, unsigned pos, * root prefix of the new node. */ static void init_tbm_node(struct btrie *btrie, node_t *dst, unsigned pos, - const btrie_oct_t pbyte, const void **root_data_p, node_t *left, - node_t *right) + const btrie_oct_t pbyte, const void **root_data_p, node_t *left, + node_t *right) { struct tbm_node *node = &dst->tbm_node; unsigned nchildren = 0; @@ -1139,33 +1405,33 @@ static void init_tbm_node(struct btrie *btrie, node_t *dst, unsigned pos, tbm_bitmap_t int_bm = 0; unsigned i, d, pfx_base; - if (left && is_lc_node (left) && lc_len (&left->lc_node) < TBM_STRIDE) - convert_lc_node (btrie, &left->lc_node, pos + 1); - if (right && is_lc_node (right) && lc_len (&right->lc_node) < TBM_STRIDE) - convert_lc_node (btrie, &right->lc_node, pos + 1); + if (left && is_lc_node(left) && lc_len(&left->lc_node) < TBM_STRIDE) + convert_lc_node(btrie, &left->lc_node, pos + 1); + if (right && is_lc_node(right) && lc_len(&right->lc_node) < TBM_STRIDE) + convert_lc_node(btrie, &right->lc_node, pos + 1); /* set internal data for root prefix */ if (root_data_p) { data[ndata++] = *root_data_p; - int_bm |= bit (base_index (0, 0)); + int_bm |= bit(base_index(0, 0)); } /* copy internal data from children */ for (d = 0; d < TBM_STRIDE - 1; d++) { - if (left && has_data (left)) { + if (left && has_data(left)) { for (i = 0; i < 1U << d; i++) { - const void **data_p = tbm_data_p (&left->tbm_node, i, d); + const void **data_p = tbm_data_p(&left->tbm_node, i, d); if (data_p) { data[ndata++] = *data_p; - int_bm |= bit (base_index (i, d + 1)); + int_bm |= bit(base_index(i, d + 1)); } } } - if (right && has_data (right)) { + if (right && has_data(right)) { for (i = 0; i < 1U << d; i++) { - const void **data_p = tbm_data_p (&right->tbm_node, i, d); + const void **data_p = tbm_data_p(&right->tbm_node, i, d); if (data_p) { data[ndata++] = *data_p; - int_bm |= bit (base_index (i + (1 << d), d + 1)); + int_bm |= bit(base_index(i + (1 << d), d + 1)); } } } @@ -1177,32 +1443,32 @@ static void init_tbm_node(struct btrie *btrie, node_t *dst, unsigned pos, if (child == NULL) { continue; } - else if (is_lc_node (child)) { - unsigned pfx = pfx_base + lc_leading_bits (&child->lc_node, pos + 1, - TBM_STRIDE - 1); + else if (is_lc_node(child)) { + unsigned pfx = pfx_base + lc_leading_bits(&child->lc_node, pos + 1, + TBM_STRIDE - 1); /* child is LC node, just shorten it by TBM_STRIDE - 1 */ - shorten_lc_node (btrie, &children[nchildren++], pos + TBM_STRIDE, - &child->lc_node, pos + 1); - ext_bm |= bit (pfx); + shorten_lc_node(btrie, &children[nchildren++], pos + TBM_STRIDE, + &child->lc_node, pos + 1); + ext_bm |= bit(pfx); } - else if (!is_empty_node (child)) { + else if (!is_empty_node(child)) { /* convert deepest internal prefixes of child to extending paths * of the new node */ for (i = 0; i < TBM_FANOUT / 2; i++) { - const void **data_p = tbm_data_p (&child->tbm_node, i, - TBM_STRIDE - 1); - node_t *left_ext = tbm_ext_path (&child->tbm_node, 2 * i); - node_t *right_ext = tbm_ext_path (&child->tbm_node, 2 * i + 1); + const void **data_p = tbm_data_p(&child->tbm_node, i, + TBM_STRIDE - 1); + node_t *left_ext = tbm_ext_path(&child->tbm_node, 2 * i); + node_t *right_ext = tbm_ext_path(&child->tbm_node, 2 * i + 1); if (data_p || left_ext || right_ext) { node_t *ext_path = &children[nchildren++]; unsigned pfx = pfx_base + i; - btrie_oct_t npbyte = next_pbyte (pbyte, pos, pfx); + btrie_oct_t npbyte = next_pbyte(pbyte, pos, pfx); - ext_bm |= bit (pfx); + ext_bm |= bit(pfx); if (left_ext == NULL && right_ext == NULL) { /* only have data - set ext_path to zero-length terminal LC node */ - lc_init_flags (&ext_path->lc_node, 1, 0); + lc_init_flags(&ext_path->lc_node, 1, 0); ext_path->lc_node.prefix[0] = npbyte; ext_path->lc_node.ptr.data = *data_p; btrie->n_lc_nodes++; @@ -1210,33 +1476,33 @@ static void init_tbm_node(struct btrie *btrie, node_t *dst, unsigned pos, else if (data_p || (left_ext && right_ext)) { /* have at least two of data, left_ext, right_ext * ext_path must be a full TBM node */ - init_tbm_node (btrie, ext_path, pos + TBM_STRIDE, - npbyte, data_p, left_ext, right_ext); + init_tbm_node(btrie, ext_path, pos + TBM_STRIDE, + npbyte, data_p, left_ext, right_ext); } else if (left_ext) { /* have only left_ext, insert length-one LC node */ - insert_lc_node (btrie, ext_path, pos + TBM_STRIDE, - npbyte, 0, left_ext); + insert_lc_node(btrie, ext_path, pos + TBM_STRIDE, + npbyte, 0, left_ext); } else { /* have only right_ext, insert length-one LC node */ - insert_lc_node (btrie, ext_path, pos + TBM_STRIDE, - npbyte, 1, right_ext); + insert_lc_node(btrie, ext_path, pos + TBM_STRIDE, + npbyte, 1, right_ext); } } } btrie->n_tbm_nodes--; - free_nodes (btrie, child->tbm_node.ptr.children, - count_bits (child->tbm_node.ext_bm), - count_bits (child->tbm_node.int_bm)); + free_nodes(btrie, child->tbm_node.ptr.children, + count_bits(child->tbm_node.ext_bm), + count_bits(child->tbm_node.int_bm)); } } - assert(count_bits (int_bm) == ndata); - assert(count_bits (ext_bm) == nchildren); + assert(count_bits(int_bm) == ndata); + assert(count_bits(ext_bm) == nchildren); - node->ptr.children = alloc_nodes (btrie, nchildren, ndata); - memcpy(node->ptr.data_end - (int )ndata, data, ndata * sizeof(data[0])); + node->ptr.children = alloc_nodes(btrie, nchildren, ndata); + memcpy(node->ptr.data_end - (int) ndata, data, ndata * sizeof(data[0])); memcpy(node->ptr.children, children, nchildren * sizeof(children[0])); node->ext_bm = ext_bm; node->int_bm = int_bm; @@ -1244,41 +1510,41 @@ static void init_tbm_node(struct btrie *btrie, node_t *dst, unsigned pos, } static enum btrie_result add_to_trie(struct btrie *btrie, node_t *node, - unsigned pos, const btrie_oct_t *prefix, unsigned len, const void *data) + unsigned pos, const btrie_oct_t *prefix, unsigned len, const void *data) { for (;;) { - if (is_lc_node (node)) { + if (is_lc_node(node)) { struct lc_node *lc_node = &node->lc_node; - unsigned end = pos + lc_len (lc_node); - unsigned cbits = common_prefix (prefix + lc_shift (pos), - lc_node->prefix, (len < end ? len : end) - lc_base (pos)); - unsigned clen = lc_base (pos) + cbits; /* position of first mismatch */ + unsigned end = pos + lc_len(lc_node); + unsigned cbits = common_prefix(prefix + lc_shift(pos), + lc_node->prefix, (len < end ? len : end) - lc_base(pos)); + unsigned clen = lc_base(pos) + cbits; /* position of first mismatch */ - if (clen == end && !lc_is_terminal (lc_node)) { + if (clen == end && !lc_is_terminal(lc_node)) { /* matched entire prefix of LC node, proceed to child */ - assert(lc_len (lc_node) > 0); + assert(lc_len(lc_node) > 0); node = lc_node->ptr.child; pos = end; } - else if (clen == end && len == end && lc_is_terminal (lc_node)) { + else if (clen == end && len == end && lc_is_terminal(lc_node)) { /* exact match for terminal node - already have data for prefix */ return BTRIE_DUPLICATE_PREFIX; } else { - assert(clen < end || (lc_is_terminal (lc_node) && len > end)); + assert(clen < end || (lc_is_terminal(lc_node) && len > end)); /* Need to insert new TBM node at clen */ if (clen > pos) { - split_lc_node (btrie, lc_node, pos, clen - pos); + split_lc_node(btrie, lc_node, pos, clen - pos); node = lc_node->ptr.child; - assert(is_lc_node (node)); + assert(is_lc_node(node)); pos = clen; } - convert_lc_node (btrie, &node->lc_node, pos); + convert_lc_node(btrie, &node->lc_node, pos); } } - else if (is_empty_node (node)) { + else if (is_empty_node(node)) { /* at empty TBM node - just replace with terminal LC node */ - init_terminal_node (btrie, node, pos, prefix, len, data); + init_terminal_node(btrie, node, pos, prefix, len, data); btrie->n_entries++; btrie->n_tbm_nodes--; return BTRIE_OKAY; @@ -1289,23 +1555,23 @@ static enum btrie_result add_to_trie(struct btrie *btrie, node_t *node, if (len < end) { unsigned plen = len - pos; - unsigned pfx = extract_bits (prefix, pos, plen); + unsigned pfx = extract_bits(prefix, pos, plen); - if (tbm_data_p (tbm_node, pfx, plen) != NULL) + if (tbm_data_p(tbm_node, pfx, plen) != NULL) return BTRIE_DUPLICATE_PREFIX; /* prefix already has data */ else { - tbm_insert_data (btrie, tbm_node, pfx, plen, data); + tbm_insert_data(btrie, tbm_node, pfx, plen, data); btrie->n_entries++; return BTRIE_OKAY; } } else { - unsigned pfx = extract_bits (prefix, pos, TBM_STRIDE); + unsigned pfx = extract_bits(prefix, pos, TBM_STRIDE); /* follow extending path */ - node = tbm_ext_path (tbm_node, pfx); + node = tbm_ext_path(tbm_node, pfx); if (node == NULL) - node = tbm_insert_ext_path (btrie, tbm_node, pfx); + node = tbm_insert_ext_path(btrie, tbm_node, pfx); pos = end; } } @@ -1314,23 +1580,23 @@ static enum btrie_result add_to_trie(struct btrie *btrie, node_t *node, static const void * search_trie(const node_t *node, unsigned pos, const btrie_oct_t *prefix, - unsigned len) + unsigned len) { /* remember last TBM node seen with internal data */ const struct tbm_node *int_node = 0; unsigned int_pfx = 0, int_plen = 0; while (node) { - if (is_lc_node (node)) { + if (is_lc_node(node)) { const struct lc_node *lc_node = &node->lc_node; - unsigned end = pos + lc_len (lc_node); + unsigned end = pos + lc_len(lc_node); if (len < end) break; - if (!prefixes_equal (prefix + lc_shift (pos), lc_node->prefix, - end - lc_base (pos))) + if (!prefixes_equal(prefix + lc_shift(pos), lc_node->prefix, + end - lc_base(pos))) break; - if (lc_is_terminal (lc_node)) + if (lc_is_terminal(lc_node)) return lc_node->ptr.data; /* found terminal node */ pos = end; @@ -1341,8 +1607,8 @@ search_trie(const node_t *node, unsigned pos, const btrie_oct_t *prefix, unsigned end = pos + TBM_STRIDE; if (len < end) { unsigned plen = len - pos; - unsigned pfx = extract_bits (prefix, pos, plen); - if (has_internal_data (tbm_node, pfx, plen)) { + unsigned pfx = extract_bits(prefix, pos, plen); + if (has_internal_data(tbm_node, pfx, plen)) { int_node = tbm_node; int_pfx = pfx; int_plen = plen; @@ -1350,25 +1616,25 @@ search_trie(const node_t *node, unsigned pos, const btrie_oct_t *prefix, break; } else { - unsigned pfx = extract_bits (prefix, pos, TBM_STRIDE); - if (has_internal_data (tbm_node, pfx >> 1, TBM_STRIDE - 1)) { + unsigned pfx = extract_bits(prefix, pos, TBM_STRIDE); + if (has_internal_data(tbm_node, pfx >> 1, TBM_STRIDE - 1)) { int_node = tbm_node; int_pfx = pfx >> 1; int_plen = TBM_STRIDE - 1; } pos = end; - node = tbm_ext_path (tbm_node, pfx); + node = tbm_ext_path(tbm_node, pfx); } } } if (int_node) { - const void **data_p = tbm_data_p (int_node, int_pfx, int_plen); + const void **data_p = tbm_data_p(int_node, int_pfx, int_plen); while (data_p == NULL) { assert(int_plen > 0); int_pfx >>= 1; int_plen--; - data_p = tbm_data_p (int_node, int_pfx, int_plen); + data_p = tbm_data_p(int_node, int_pfx, int_plen); } return *data_p; } @@ -1381,7 +1647,7 @@ btrie_init(rspamd_mempool_t *mp) { struct btrie *btrie; - if (!(btrie = rspamd_mempool_alloc0 (mp, sizeof(*btrie)))) { + if (!(btrie = rspamd_mempool_alloc0(mp, sizeof(*btrie)))) { return NULL; } @@ -1395,19 +1661,19 @@ btrie_init(rspamd_mempool_t *mp) } enum btrie_result btrie_add_prefix(struct btrie *btrie, - const btrie_oct_t *prefix, unsigned len, const void *data) + const btrie_oct_t *prefix, unsigned len, const void *data) { enum btrie_result rv; - if ((rv = setjmp (btrie->exception)) != 0) + if ((rv = setjmp(btrie->exception)) != 0) return rv; /* out of memory */ - return add_to_trie (btrie, &btrie->root, 0, prefix, len, data); + return add_to_trie(btrie, &btrie->root, 0, prefix, len, data); } const void * btrie_lookup(const struct btrie *btrie, const btrie_oct_t *prefix, unsigned len) { - return search_trie (&btrie->root, 0, prefix, len); + return search_trie(&btrie->root, 0, prefix, len); } /**************************************************************** @@ -1438,7 +1704,7 @@ static void node_stats(const node_t *node, size_t depth, struct stats *stats) { if (depth > stats->max_depth) - stats->max_depth = depth; + stats->max_depth = depth; stats->total_depth += depth; if (is_lc_node(node)) { @@ -1446,10 +1712,10 @@ node_stats(const node_t *node, size_t depth, struct stats *stats) stats->n_lc_nodes++; #endif if (!lc_is_terminal(&node->lc_node)) - node_stats(node->lc_node.ptr.child, depth + 1, stats); + node_stats(node->lc_node.ptr.child, depth + 1, stats); #ifndef NDEBUG else - stats->n_entries++; + stats->n_entries++; #endif } else { @@ -1464,7 +1730,7 @@ node_stats(const node_t *node, size_t depth, struct stats *stats) stats->alloc_waste += (ndata % 2) * sizeof(void *); #endif for (i = 0; i < nchildren; i++) - node_stats(&node->tbm_node.ptr.children[i], depth + 1, stats); + node_stats(&node->tbm_node.ptr.children[i], depth + 1, stats); } } #endif /* BTRIE_EXTENDED_STATS */ @@ -1486,20 +1752,19 @@ static size_t count_free(const struct btrie *btrie) #endif /* not NDEBUG */ const char * -btrie_stats(const struct btrie *btrie, guint duplicates) +btrie_stats(const struct btrie *btrie, unsigned int duplicates) { static char buf[128]; size_t n_nodes = btrie->n_lc_nodes + btrie->n_tbm_nodes; size_t alloc_free = (btrie->alloc_total + sizeof(node_t) /* do not double-count the root node */ - - n_nodes * sizeof(node_t) - btrie->alloc_data - btrie->alloc_waste - - sizeof(*btrie)); + - n_nodes * sizeof(node_t) - btrie->alloc_data - btrie->alloc_waste - sizeof(*btrie)); #ifdef BTRIE_EXTENDED_STATS struct stats stats; double average_depth; memset(&stats, 0, sizeof(stats)); node_stats(&btrie->root, 0, &stats); - average_depth = (double)stats.total_depth / n_nodes; + average_depth = (double) stats.total_depth / n_nodes; #ifndef NDEBUG /* check the node counts */ @@ -1513,7 +1778,7 @@ btrie_stats(const struct btrie *btrie, guint duplicates) #ifndef NDEBUG /* check that we haven't lost any memory */ - assert(alloc_free == count_free (btrie)); + assert(alloc_free == count_free(btrie)); #endif #ifdef BTRIE_DEBUG_ALLOC @@ -1523,21 +1788,19 @@ btrie_stats(const struct btrie *btrie, guint duplicates) #ifdef BTRIE_EXTENDED_STATS snprintf(buf, sizeof(buf), - "ents=%lu tbm=%lu lc=%lu mem=%.0fk free=%lu waste=%lu" - " depth=%.1f/%lu" - ,(long unsigned)btrie->n_entries, (long unsigned)btrie->n_tbm_nodes, - (long unsigned)btrie->n_lc_nodes, (double)btrie->alloc_total / 1024, - (long unsigned)alloc_free, (long unsigned)btrie->alloc_waste - , average_depth, (long unsigned)stats.max_depth); + "ents=%lu tbm=%lu lc=%lu mem=%.0fk free=%lu waste=%lu" + " depth=%.1f/%lu", + (long unsigned) btrie->n_entries, (long unsigned) btrie->n_tbm_nodes, + (long unsigned) btrie->n_lc_nodes, (double) btrie->alloc_total / 1024, + (long unsigned) alloc_free, (long unsigned) btrie->alloc_waste, average_depth, (long unsigned) stats.max_depth); #else snprintf(buf, sizeof(buf), - "ents=%lu dup=%u tbm=%lu lc=%lu mem=%.0fk free=%lu waste=%lu", - (long unsigned)btrie->n_entries, - duplicates, - (long unsigned)btrie->n_tbm_nodes, - (long unsigned)btrie->n_lc_nodes, (double)btrie->alloc_total / 1024, - (long unsigned)alloc_free, (long unsigned)btrie->alloc_waste - ); + "ents=%lu dup=%u tbm=%lu lc=%lu mem=%.0fk free=%lu waste=%lu", + (long unsigned) btrie->n_entries, + duplicates, + (long unsigned) btrie->n_tbm_nodes, + (long unsigned) btrie->n_lc_nodes, (double) btrie->alloc_total / 1024, + (long unsigned) alloc_free, (long unsigned) btrie->alloc_waste); #endif buf[sizeof(buf) - 1] = '\0'; return buf; @@ -1547,8 +1810,7 @@ btrie_stats(const struct btrie *btrie, guint duplicates) #ifndef NO_MASTER_DUMP -struct walk_context -{ +struct walk_context { btrie_walk_cb_t *callback; void *user_data; @@ -1559,12 +1821,12 @@ static void walk_node(const node_t *node, unsigned pos, struct walk_context *ctx); static void walk_tbm_node(const struct tbm_node *node, unsigned pos, - unsigned pfx, unsigned plen, struct walk_context *ctx) + unsigned pfx, unsigned plen, struct walk_context *ctx) { btrie_oct_t *prefix = ctx->prefix; int pbyte = pos / 8; btrie_oct_t pbit = 0x80 >> (pos % 8); - const void **data_p = tbm_data_p (node, pfx, plen); + const void **data_p = tbm_data_p(node, pfx, plen); if (pos >= BTRIE_MAX_PREFIX) { /* This can/should not happen, but don't overwrite buffers if it does. */ @@ -1572,38 +1834,38 @@ static void walk_tbm_node(const struct tbm_node *node, unsigned pos, } if (data_p) - ctx->callback (prefix, pos, *data_p, 0, ctx->user_data); + ctx->callback(prefix, pos, *data_p, 0, ctx->user_data); /* walk children */ if (plen < TBM_STRIDE - 1) { /* children are internal prefixes in same node */ - walk_tbm_node (node, pos + 1, pfx << 1, plen + 1, ctx); + walk_tbm_node(node, pos + 1, pfx << 1, plen + 1, ctx); prefix[pbyte] |= pbit; - walk_tbm_node (node, pos + 1, (pfx << 1) + 1, plen + 1, ctx); + walk_tbm_node(node, pos + 1, (pfx << 1) + 1, plen + 1, ctx); prefix[pbyte] &= ~pbit; } else { /* children are extending paths */ const node_t *ext_path; - if ((ext_path = tbm_ext_path (node, pfx << 1)) != NULL) - walk_node (ext_path, pos + 1, ctx); - if ((ext_path = tbm_ext_path (node, (pfx << 1) + 1)) != NULL) { + if ((ext_path = tbm_ext_path(node, pfx << 1)) != NULL) + walk_node(ext_path, pos + 1, ctx); + if ((ext_path = tbm_ext_path(node, (pfx << 1) + 1)) != NULL) { prefix[pbyte] |= pbit; - walk_node (ext_path, pos + 1, ctx); + walk_node(ext_path, pos + 1, ctx); prefix[pbyte] &= ~pbit; } } if (data_p) - ctx->callback (prefix, pos, *data_p, 1, ctx->user_data); + ctx->callback(prefix, pos, *data_p, 1, ctx->user_data); } static void walk_lc_node(const struct lc_node *node, unsigned pos, - struct walk_context *ctx) + struct walk_context *ctx) { btrie_oct_t *prefix = ctx->prefix; - unsigned end = pos + lc_len (node); - btrie_oct_t save_prefix = prefix[lc_shift (pos)]; + unsigned end = pos + lc_len(node); + btrie_oct_t save_prefix = prefix[lc_shift(pos)]; if (end > BTRIE_MAX_PREFIX) { /* This can/should not happen, but don't overwrite buffers if it does. */ @@ -1611,29 +1873,29 @@ static void walk_lc_node(const struct lc_node *node, unsigned pos, } /* construct full prefix to node */ - memcpy(&prefix[lc_shift (pos)], node->prefix, lc_bytes (node, pos)); + memcpy(&prefix[lc_shift(pos)], node->prefix, lc_bytes(node, pos)); if (end % 8) - prefix[end / 8] &= high_bits (end % 8); + prefix[end / 8] &= high_bits(end % 8); - if (lc_is_terminal (node)) { - ctx->callback (prefix, end, node->ptr.data, 0, ctx->user_data); - ctx->callback (prefix, end, node->ptr.data, 1, ctx->user_data); + if (lc_is_terminal(node)) { + ctx->callback(prefix, end, node->ptr.data, 0, ctx->user_data); + ctx->callback(prefix, end, node->ptr.data, 1, ctx->user_data); } else - walk_node (node->ptr.child, end, ctx); + walk_node(node->ptr.child, end, ctx); - prefix[lc_shift (pos)] = save_prefix; /* restore parents prefix */ - if (lc_bytes (node, pos) > 1) - memset(&prefix[lc_shift (pos) + 1], 0, lc_bytes (node, pos) - 1); + prefix[lc_shift(pos)] = save_prefix; /* restore parents prefix */ + if (lc_bytes(node, pos) > 1) + memset(&prefix[lc_shift(pos) + 1], 0, lc_bytes(node, pos) - 1); } static void walk_node(const node_t *node, unsigned pos, - struct walk_context *ctx) + struct walk_context *ctx) { - if (is_lc_node (node)) - walk_lc_node (&node->lc_node, pos, ctx); + if (is_lc_node(node)) + walk_lc_node(&node->lc_node, pos, ctx); else - walk_tbm_node (&node->tbm_node, pos, 0, 0, ctx); + walk_tbm_node(&node->tbm_node, pos, 0, 0, ctx); } /* walk trie in lexicographical order @@ -1641,7 +1903,7 @@ static void walk_node(const node_t *node, unsigned pos, * calls callback twice (once preorder, once postorder) at each prefix */ void btrie_walk(const struct btrie *btrie, btrie_walk_cb_t *callback, - void *user_data) + void *user_data) { struct walk_context ctx; @@ -1649,7 +1911,7 @@ void btrie_walk(const struct btrie *btrie, btrie_walk_cb_t *callback, ctx.callback = callback; ctx.user_data = user_data; - walk_node (&btrie->root, 0, &ctx); + walk_node(&btrie->root, 0, &ctx); } #endif /* not NO_MASTER_DUMP */ @@ -1664,7 +1926,7 @@ void btrie_walk(const struct btrie *btrie, btrie_walk_cb_t *callback, #include #ifndef UNUSED -# define UNUSED __attribute__((unused)) +#define UNUSED __attribute__((unused)) #endif /* bogus replacements mp_alloc for running self-tests */ @@ -1675,12 +1937,14 @@ mp_alloc(UNUSED struct mempool *mp, unsigned sz, UNUSED int align) } #if 0 -# define PASS(name) puts("OK " name) +#define PASS(name) puts("OK " name) #else -# define PASS(name) fputs(".", stdout); fflush(stdout) +#define PASS(name) \ + fputs(".", stdout); \ + fflush(stdout) #endif -const char * pgm_name = "???"; +const char *pgm_name = "???"; static void test_struct_node_packing() @@ -1705,7 +1969,7 @@ test_struct_node_packing() static void test_bit() { - tbm_bitmap_t ones = ~(tbm_bitmap_t)0; + tbm_bitmap_t ones = ~(tbm_bitmap_t) 0; tbm_bitmap_t high_bit = ones ^ (ones >> 1); assert(bit(0) == high_bit); @@ -1718,7 +1982,7 @@ static void test_count_bits() { unsigned max_bits = sizeof(tbm_bitmap_t) * 8; - tbm_bitmap_t ones = ~(tbm_bitmap_t)0; + tbm_bitmap_t ones = ~(tbm_bitmap_t) 0; assert(count_bits(0) == 0); assert(count_bits(1) == 1); @@ -1743,7 +2007,7 @@ static void test_count_bits_before() { unsigned max_bits = sizeof(tbm_bitmap_t) * 8; - tbm_bitmap_t ones = ~(tbm_bitmap_t)0; + tbm_bitmap_t ones = ~(tbm_bitmap_t) 0; unsigned i; for (i = 0; i < max_bits; i++) { @@ -1758,7 +2022,7 @@ static void test_count_bits_from() { unsigned max_bits = sizeof(tbm_bitmap_t) * 8; - tbm_bitmap_t ones = ~(tbm_bitmap_t)0; + tbm_bitmap_t ones = ~(tbm_bitmap_t) 0; unsigned i; for (i = 0; i < max_bits; i++) { @@ -1776,16 +2040,16 @@ test_extract_bits() unsigned i; for (i = 0; i < 32; i++) - assert(extract_bits(prefix, i, 0) == 0); + assert(extract_bits(prefix, i, 0) == 0); for (i = 0; i < 8; i++) - assert(extract_bits(prefix, i, 1) == 1); + assert(extract_bits(prefix, i, 1) == 1); for (i = 8; i < 16; i++) - assert(extract_bits(prefix, i, 1) == i % 2); + assert(extract_bits(prefix, i, 1) == i % 2); for (i = 16; i < 24; i++) - assert(extract_bits(prefix, i, 1) == (i + 1) % 2); + assert(extract_bits(prefix, i, 1) == (i + 1) % 2); for (i = 24; i < 32; i++) - assert(extract_bits(prefix, i, 1) == 0); + assert(extract_bits(prefix, i, 1) == 0); assert(extract_bits(prefix, 2, 6) == 0x3f); assert(extract_bits(prefix, 3, 6) == 0x3e); @@ -1828,7 +2092,7 @@ test_prefixes_equal() assert(!prefixes_equal(prefix1, prefix2, 8 * LC_BYTES_PER_NODE)); assert(prefixes_equal(prefix1, prefix2, i)); if (i + 1 < 8 * LC_BYTES_PER_NODE) - assert(!prefixes_equal(prefix1, prefix2, i + 1)); + assert(!prefixes_equal(prefix1, prefix2, i + 1)); prefix1[i / 8] ^= 1 << (7 - i % 8); } PASS("test_prefixes_equal"); @@ -1848,7 +2112,7 @@ test_common_prefix() prefix1[i / 8] ^= 1 << (7 - i % 8); assert(common_prefix(prefix1, prefix2, 8 * LC_BYTES_PER_NODE) == i); if (i + 1 < 8 * LC_BYTES_PER_NODE) - assert(common_prefix(prefix1, prefix2, i+1) == i); + assert(common_prefix(prefix1, prefix2, i + 1) == i); prefix1[i / 8] ^= 1 << (7 - i % 8); } PASS("test_common_prefix"); @@ -1857,13 +2121,13 @@ test_common_prefix() static void test_base_index() { - assert(base_index(0,0) == 1); - assert(base_index(0,1) == 2); - assert(base_index(1,1) == 3); - assert(base_index(0,2) == 4); - assert(base_index(1,2) == 5); - assert(base_index(2,2) == 6); - assert(base_index(3,2) == 7); + assert(base_index(0, 0) == 1); + assert(base_index(0, 1) == 2); + assert(base_index(1, 1) == 3); + assert(base_index(0, 2) == 4); + assert(base_index(1, 2) == 5); + assert(base_index(2, 2) == 6); + assert(base_index(3, 2) == 7); PASS("test_base_index"); } @@ -1889,20 +2153,76 @@ test_has_internal_data() /****************************************************************/ static const btrie_oct_t numbered_bytes[] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x00, + 0x01, + 0x02, + 0x03, + 0x04, + 0x05, + 0x06, + 0x07, + 0x08, + 0x09, + 0x0a, + 0x0b, + 0x0c, + 0x0d, + 0x0e, + 0x0f, + 0x10, + 0x11, + 0x12, + 0x13, + 0x14, + 0x15, + 0x16, + 0x17, + 0x18, + 0x19, + 0x1a, + 0x1b, + 0x1c, + 0x1d, + 0x1e, + 0x1f, + 0x20, + 0x21, + 0x22, + 0x23, + 0x24, + 0x25, + 0x26, + 0x27, + 0x28, + 0x29, + 0x2a, + 0x2b, + 0x2c, + 0x2d, + 0x2e, + 0x2f, + 0x30, + 0x31, + 0x32, + 0x33, + 0x34, + 0x35, + 0x36, + 0x37, + 0x38, + 0x39, + 0x3a, + 0x3b, + 0x3c, + 0x3d, + 0x3e, + 0x3f, }; static void check_non_terminal_lc_node(struct lc_node *node, unsigned len) { - assert(is_lc_node((node_t *)node)); + assert(is_lc_node((node_t *) node)); assert(!lc_is_terminal(node)); assert(lc_len(node) == len); } @@ -1910,7 +2230,7 @@ check_non_terminal_lc_node(struct lc_node *node, unsigned len) static void check_terminal_lc_node(struct lc_node *node, unsigned len, const void *data) { - assert(is_lc_node((node_t *)node)); + assert(is_lc_node((node_t *) node)); assert(lc_is_terminal(node)); assert(lc_len(node) == len); assert(node->ptr.data == data); @@ -1920,33 +2240,33 @@ static void test_init_terminal_node() { struct btrie *btrie = btrie_init(NULL); - const void *data = (void *)0xdeadbeef; + const void *data = (void *) 0xdeadbeef; node_t node; struct lc_node *head = &node.lc_node; init_terminal_node(btrie, &node, 0, - numbered_bytes, 8 * LC_BYTES_PER_NODE, data); + numbered_bytes, 8 * LC_BYTES_PER_NODE, data); check_terminal_lc_node(head, 8 * LC_BYTES_PER_NODE, data); assert(memcmp(head->prefix, numbered_bytes, LC_BYTES_PER_NODE) == 0); init_terminal_node(btrie, &node, 7, - numbered_bytes, 8 * LC_BYTES_PER_NODE, data); + numbered_bytes, 8 * LC_BYTES_PER_NODE, data); check_terminal_lc_node(head, 8 * LC_BYTES_PER_NODE - 7, data); assert(memcmp(head->prefix, numbered_bytes, LC_BYTES_PER_NODE) == 0); init_terminal_node(btrie, &node, 0, - numbered_bytes, 2 * 8 * LC_BYTES_PER_NODE, data); + numbered_bytes, 2 * 8 * LC_BYTES_PER_NODE, data); check_non_terminal_lc_node(head, 8 * LC_BYTES_PER_NODE); assert(memcmp(head->prefix, numbered_bytes, LC_BYTES_PER_NODE) == 0); { struct lc_node *child = &head->ptr.child->lc_node; check_terminal_lc_node(child, 8 * LC_BYTES_PER_NODE, data); assert(memcmp(child->prefix, &numbered_bytes[LC_BYTES_PER_NODE], - LC_BYTES_PER_NODE) == 0); + LC_BYTES_PER_NODE) == 0); } init_terminal_node(btrie, &node, 15, - numbered_bytes, 8 * LC_BYTES_PER_NODE + 15, data); + numbered_bytes, 8 * LC_BYTES_PER_NODE + 15, data); check_non_terminal_lc_node(head, 8 * LC_BYTES_PER_NODE - 7); assert(memcmp(head->prefix, &numbered_bytes[1], LC_BYTES_PER_NODE) == 0); { @@ -1962,35 +2282,33 @@ static void test_coalesce_lc_node() { struct btrie *btrie = btrie_init(NULL); - const void *data = (void *)0xdeadbeef; + const void *data = (void *) 0xdeadbeef; node_t node; struct lc_node *head = &node.lc_node; /* test merging */ init_terminal_node(btrie, &node, 0, - numbered_bytes, 8 * (LC_BYTES_PER_NODE + 1), data); + numbered_bytes, 8 * (LC_BYTES_PER_NODE + 1), data); check_non_terminal_lc_node(head, LC_BYTES_PER_NODE * 8); lc_add_to_len(head, -8); coalesce_lc_node(btrie, head, 8); check_terminal_lc_node(head, LC_BYTES_PER_NODE * 8, data); - assert(head->prefix[LC_BYTES_PER_NODE - 1] - == numbered_bytes[LC_BYTES_PER_NODE]); + assert(head->prefix[LC_BYTES_PER_NODE - 1] == numbered_bytes[LC_BYTES_PER_NODE]); /* test bit stealing */ init_terminal_node(btrie, &node, 0, - numbered_bytes, 8 * (2 * LC_BYTES_PER_NODE), data); + numbered_bytes, 8 * (2 * LC_BYTES_PER_NODE), data); check_non_terminal_lc_node(head, LC_BYTES_PER_NODE * 8); lc_add_to_len(head, -15); coalesce_lc_node(btrie, head, 15); check_non_terminal_lc_node(head, LC_BYTES_PER_NODE * 8 - 7); assert(memcmp(head->prefix, numbered_bytes, LC_BYTES_PER_NODE - 1) == 0); - assert(head->prefix[LC_BYTES_PER_NODE - 1] - == numbered_bytes[LC_BYTES_PER_NODE]); + assert(head->prefix[LC_BYTES_PER_NODE - 1] == numbered_bytes[LC_BYTES_PER_NODE]); { struct lc_node *child = &head->ptr.child->lc_node; check_terminal_lc_node(child, 8 * (LC_BYTES_PER_NODE - 1), data); assert(memcmp(child->prefix, &numbered_bytes[LC_BYTES_PER_NODE + 1], - LC_BYTES_PER_NODE - 1) == 0); + LC_BYTES_PER_NODE - 1) == 0); } PASS("test_coalesce_lc_node"); @@ -2000,26 +2318,25 @@ static void test_shorten_lc_node() { struct btrie *btrie = btrie_init(NULL); - const void *data = (void *)0xdeadbeef; + const void *data = (void *) 0xdeadbeef; node_t node, shorter; /* test shorten without shift */ init_terminal_node(btrie, &node, 0, - numbered_bytes, 8 * LC_BYTES_PER_NODE, data); + numbered_bytes, 8 * LC_BYTES_PER_NODE, data); memset(shorter.lc_node.prefix, 0xff, LC_BYTES_PER_NODE); shorten_lc_node(btrie, &shorter, 7, &node.lc_node, 0); check_terminal_lc_node(&shorter.lc_node, LC_BYTES_PER_NODE * 8 - 7, data); - assert(memcmp(shorter.lc_node.prefix, numbered_bytes, LC_BYTES_PER_NODE) - == 0); + assert(memcmp(shorter.lc_node.prefix, numbered_bytes, LC_BYTES_PER_NODE) == 0); /* test shorten with shift */ init_terminal_node(btrie, &node, 7, - numbered_bytes, 8 * LC_BYTES_PER_NODE, data); + numbered_bytes, 8 * LC_BYTES_PER_NODE, data); memset(shorter.lc_node.prefix, 0xff, LC_BYTES_PER_NODE); shorten_lc_node(btrie, &shorter, 9, &node.lc_node, 7); check_terminal_lc_node(&shorter.lc_node, LC_BYTES_PER_NODE * 8 - 9, data); assert(memcmp(shorter.lc_node.prefix, &numbered_bytes[1], - LC_BYTES_PER_NODE - 1) == 0); + LC_BYTES_PER_NODE - 1) == 0); { /* test child stealing */ @@ -2041,16 +2358,16 @@ static void test_split_lc_node() { struct btrie *btrie = btrie_init(NULL); - const void *data = (void *)0xdeadbeef; + const void *data = (void *) 0xdeadbeef; struct lc_node node; - init_terminal_node(btrie, (node_t *)&node, 1, numbered_bytes, 25, data); + init_terminal_node(btrie, (node_t *) &node, 1, numbered_bytes, 25, data); split_lc_node(btrie, &node, 1, 8); check_non_terminal_lc_node(&node, 8); check_terminal_lc_node(&node.ptr.child->lc_node, 16, data); /* test conversion of terminal to non-terminal */ - init_terminal_node(btrie, (node_t *)&node, 7, numbered_bytes, 10, data); + init_terminal_node(btrie, (node_t *) &node, 7, numbered_bytes, 10, data); split_lc_node(btrie, &node, 7, 3); check_non_terminal_lc_node(&node, 3); check_terminal_lc_node(&node.ptr.child->lc_node, 0, data); @@ -2062,7 +2379,7 @@ static void test_convert_lc_node_1() { struct btrie *btrie = btrie_init(NULL); - const void *data = (void *)0xdeadbeef; + const void *data = (void *) 0xdeadbeef; struct lc_node head; /* test tail is left */ @@ -2072,7 +2389,7 @@ test_convert_lc_node_1() init_terminal_node(btrie, head.ptr.child, 1, numbered_bytes, 1, data); convert_lc_node_1(btrie, &head, 0); { - node_t *result = (node_t *)&head; + node_t *result = (node_t *) &head; assert(is_tbm_node(result)); assert(result->tbm_node.ext_bm == 0); assert(result->tbm_node.int_bm == bit(base_index(0, 1))); @@ -2086,7 +2403,7 @@ test_convert_lc_node_1() init_terminal_node(btrie, head.ptr.child, 8, numbered_bytes, 10, data); convert_lc_node_1(btrie, &head, 7); { - node_t *result = (node_t *)&head; + node_t *result = (node_t *) &head; assert(is_tbm_node(result)); assert(result->tbm_node.ext_bm == 0); assert(result->tbm_node.int_bm == bit(base_index(4, 3))); @@ -2100,7 +2417,7 @@ static void test_convert_lc_node() { struct btrie *btrie = btrie_init(NULL); - const void *data = (void *)0xdeadbeef; + const void *data = (void *) 0xdeadbeef; node_t node; /* if (len >= TBM_STRIDE) */ @@ -2139,7 +2456,7 @@ static void test_insert_lc_node() { struct btrie *btrie = btrie_init(NULL); - const void *data = (void *)0xdeadbeef; + const void *data = (void *) 0xdeadbeef; node_t node, tail; /* test optimized case, last_bit == 0 */ @@ -2187,7 +2504,7 @@ static void test_init_tbm_node() { struct btrie *btrie = btrie_init(NULL); - const void *data = (void *)0xdeadbeef; + const void *data = (void *) 0xdeadbeef; unsigned lr; node_t node; @@ -2212,35 +2529,35 @@ test_init_tbm_node() assert(node.tbm_node.ext_bm == bit(base)); assert(node.tbm_node.int_bm == 0); check_terminal_lc_node(&tbm_ext_path(&node.tbm_node, base)->lc_node, - 1, data); + 1, data); /* test with short LC node children */ init_terminal_node(btrie, &child, 1, numbered_bytes, TBM_STRIDE - 1, data); init_tbm_node(btrie, &node, 0, 0, NULL, left, right); assert(is_tbm_node(&node)); assert(node.tbm_node.ext_bm == 0); - assert(node.tbm_node.int_bm == bit(base_index(base >> 1, TBM_STRIDE-1))); - assert(*tbm_data_p(&node.tbm_node, base >> 1, TBM_STRIDE-1) == data); + assert(node.tbm_node.int_bm == bit(base_index(base >> 1, TBM_STRIDE - 1))); + assert(*tbm_data_p(&node.tbm_node, base >> 1, TBM_STRIDE - 1) == data); /* construct TBM node with all eight combinations of having data, * left_ext and/or right_ext in its extending paths */ init_empty_node(btrie, &child); for (pfx = 0; pfx < 8; pfx++) { if (pfx & 1) - tbm_insert_data(btrie, &child.tbm_node, pfx, TBM_STRIDE - 1, data); + tbm_insert_data(btrie, &child.tbm_node, pfx, TBM_STRIDE - 1, data); if (pfx & 2) { btrie_oct_t prefix0 = 0; init_terminal_node(btrie, - tbm_insert_ext_path(btrie, &child.tbm_node, 2*pfx), - TBM_STRIDE + 1, - &prefix0, TBM_STRIDE + 2, data); + tbm_insert_ext_path(btrie, &child.tbm_node, 2 * pfx), + TBM_STRIDE + 1, + &prefix0, TBM_STRIDE + 2, data); } if (pfx & 4) { btrie_oct_t prefix0 = 0x80 >> TBM_STRIDE; init_terminal_node(btrie, - tbm_insert_ext_path(btrie, &child.tbm_node, 2*pfx+1), - TBM_STRIDE + 1, - &prefix0, TBM_STRIDE + 3, data); + tbm_insert_ext_path(btrie, &child.tbm_node, 2 * pfx + 1), + TBM_STRIDE + 1, + &prefix0, TBM_STRIDE + 3, data); } } init_tbm_node(btrie, &node, 0, 0, NULL, left, right); @@ -2248,9 +2565,9 @@ test_init_tbm_node() unsigned base = lr ? (1U << (TBM_STRIDE - 1)) : 0; node_t *ext_path = tbm_ext_path(&node.tbm_node, base + pfx); if (pfx == 0) - assert(ext_path == NULL); + assert(ext_path == NULL); else if (pfx == 1) - check_terminal_lc_node(&ext_path->lc_node, 0, data); + check_terminal_lc_node(&ext_path->lc_node, 0, data); else if (pfx == 2) { check_terminal_lc_node(&ext_path->lc_node, 2, data); assert(ext_path->lc_node.prefix[0] == 0); @@ -2286,7 +2603,7 @@ static void test_add_to_trie() { struct btrie *btrie = btrie_init(NULL); - const void *data = (void *)0xdeadbeef; + const void *data = (void *) 0xdeadbeef; enum btrie_result result; unsigned pfx, plen; node_t root; @@ -2294,20 +2611,20 @@ test_add_to_trie() /* test initial insertion */ init_empty_node(btrie, &root); result = add_to_trie(btrie, &root, 0, - numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data); + numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data); assert(result == BTRIE_OKAY); check_non_terminal_lc_node(&root.lc_node, 8 * LC_BYTES_PER_NODE); check_terminal_lc_node(&root.lc_node.ptr.child->lc_node, - 8 * LC_BYTES_PER_NODE, data); + 8 * LC_BYTES_PER_NODE, data); /* test can follow LC node to tail, and then detect duplicate prefix */ result = add_to_trie(btrie, &root, 0, - numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data); + numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data); assert(result == BTRIE_DUPLICATE_PREFIX); /* test can insert new TBM node within existing LC node */ result = add_to_trie(btrie, &root, 0, - &numbered_bytes[1], 16, data); + &numbered_bytes[1], 16, data); assert(result == BTRIE_OKAY); check_non_terminal_lc_node(&root.lc_node, 7); assert(is_tbm_node(root.lc_node.ptr.child)); @@ -2325,8 +2642,8 @@ test_add_to_trie() btrie_oct_t prefix0 = plen ? pfx << (8 - plen) : 0; init_empty_node(btrie, &root); init_terminal_node(btrie, tbm_insert_ext_path(btrie, &root.tbm_node, 0), - TBM_STRIDE, - numbered_bytes, 8, data); + TBM_STRIDE, + numbered_bytes, 8, data); result = add_to_trie(btrie, &root, 0, &prefix0, plen, data); assert(result == BTRIE_OKAY); assert(is_tbm_node(&root)); @@ -2350,7 +2667,7 @@ test_add_to_trie() assert(root.tbm_node.ext_bm == bit(pfx)); assert(root.tbm_node.int_bm == bit(base_index(0, 0))); check_terminal_lc_node(&tbm_ext_path(&root.tbm_node, pfx)->lc_node, - 8 - TBM_STRIDE, data); + 8 - TBM_STRIDE, data); result = add_to_trie(btrie, &root, 0, &prefix0, 8, data); assert(result == BTRIE_DUPLICATE_PREFIX); @@ -2359,14 +2676,14 @@ test_add_to_trie() /* test can follow extending path */ init_empty_node(btrie, &root); init_terminal_node(btrie, - tbm_insert_ext_path(btrie, &root.tbm_node, 0), TBM_STRIDE, - numbered_bytes, 8, data); + tbm_insert_ext_path(btrie, &root.tbm_node, 0), TBM_STRIDE, + numbered_bytes, 8, data); result = add_to_trie(btrie, &root, 0, numbered_bytes, 7, data); assert(result == BTRIE_OKAY); assert(root.tbm_node.ext_bm == bit(0)); assert(root.tbm_node.int_bm == 0); check_non_terminal_lc_node(&root.tbm_node.ptr.children[0].lc_node, - 7 - TBM_STRIDE); + 7 - TBM_STRIDE); PASS("test_add_to_trie"); } @@ -2375,25 +2692,21 @@ static void test_search_trie() { struct btrie *btrie = btrie_init(NULL); - const void *data01 = (void *)0xdead0001; - const void *data11 = (void *)0xdead0101; - const void *data = (void *)0xdeadbeef; + const void *data01 = (void *) 0xdead0001; + const void *data11 = (void *) 0xdead0101; + const void *data = (void *) 0xdeadbeef; unsigned plen, pfx; node_t root; /* test can follow chain of LC nodes to an exact match */ init_empty_node(btrie, &root); add_to_trie(btrie, &root, 0, - numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data); + numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data); - assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE) - == data); - assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE + 1) - == data); - assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE - 1) - == NULL); - assert(search_trie(&root, 0, &numbered_bytes[1], 8 * 2 * LC_BYTES_PER_NODE) - == NULL); + assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE) == data); + assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE + 1) == data); + assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE - 1) == NULL); + assert(search_trie(&root, 0, &numbered_bytes[1], 8 * 2 * LC_BYTES_PER_NODE) == NULL); /* test can follow extending path to an exact match */ for (pfx = 0; pfx < (1U << TBM_STRIDE); pfx++) { @@ -2405,14 +2718,14 @@ test_search_trie() assert(search_trie(&root, 0, &prefix0, 8) == data); /* test that last matching TBM internal prefix gets picked up */ if (prefix0 & 0x80) - assert(search_trie(&root, 0, &prefix0, 7) == data11); + assert(search_trie(&root, 0, &prefix0, 7) == data11); else - assert(search_trie(&root, 0, &prefix0, 7) == data01); + assert(search_trie(&root, 0, &prefix0, 7) == data01); prefix0 ^= 1 << (8 - TBM_STRIDE); if (prefix0 & 0x80) - assert(search_trie(&root, 0, &prefix0, 8) == data11); + assert(search_trie(&root, 0, &prefix0, 8) == data11); else - assert(search_trie(&root, 0, &prefix0, 8) == data01); + assert(search_trie(&root, 0, &prefix0, 8) == data01); } /* test finding of TBM internal prefixes */ @@ -2425,9 +2738,9 @@ test_search_trie() for (pfx = 0; pfx < (1U << TBM_STRIDE); pfx++) { btrie_oct_t prefix0 = pfx << (8 - plen); if (prefix0 & 0x80) - assert(search_trie(&root, 0, &prefix0, plen) == data11); + assert(search_trie(&root, 0, &prefix0, plen) == data11); else - assert(search_trie(&root, 0, &prefix0, plen) == data01); + assert(search_trie(&root, 0, &prefix0, plen) == data01); } } @@ -2473,7 +2786,7 @@ unit_tests() #define INDENT_FILL "....:....|....:....|....:....|....:....|" static void dump_node(const node_t *node, unsigned pos, btrie_oct_t *prefix, - int indent); + int indent); static void dump_prefix(btrie_oct_t *prefix, unsigned len, int indent, const char *tail) @@ -2482,9 +2795,9 @@ dump_prefix(btrie_oct_t *prefix, unsigned len, int indent, const char *tail) printf("%*.*s0x", indent, indent, INDENT_FILL); for (i = 0; i < len / 8; i++) - printf("%02x", prefix[i]); + printf("%02x", prefix[i]); if (len % 8) - printf("%02x", prefix[len / 8] & high_bits(len % 8)); + printf("%02x", prefix[len / 8] & high_bits(len % 8)); printf("/%u%s", len, tail); } @@ -2498,13 +2811,13 @@ insert_bits(btrie_oct_t *prefix, unsigned pos, btrie_oct_t pfx, unsigned nbits) unsigned shift = 16 - (pos % 8) - nbits; v = (v & ~(mask << shift)) | (pfx << shift); prefix[pos / 8] = v >> 8; - prefix[pos / 8 + 1] = (btrie_oct_t)v; + prefix[pos / 8 + 1] = (btrie_oct_t) v; } } static void dump_tbm_node(const struct tbm_node *node, unsigned pos, - btrie_oct_t *prefix, int indent) + btrie_oct_t *prefix, int indent) { unsigned pfx = 0, plen = 0; @@ -2516,7 +2829,7 @@ dump_tbm_node(const struct tbm_node *node, unsigned pos, if (data_p) { insert_bits(prefix, pos, pfx, plen); dump_prefix(prefix, pos + plen, indent, ""); - printf(" [%u/%u] (%s)\n", pfx, plen, (const char *)*data_p); + printf(" [%u/%u] (%s)\n", pfx, plen, (const char *) *data_p); } plen++; pfx <<= 1; @@ -2529,7 +2842,7 @@ dump_tbm_node(const struct tbm_node *node, unsigned pos, } while (pfx & 1) { if (--plen == 0) - return; + return; pfx >>= 1; } pfx++; @@ -2539,7 +2852,7 @@ dump_tbm_node(const struct tbm_node *node, unsigned pos, static void dump_lc_node(const struct lc_node *node, unsigned pos, - btrie_oct_t *prefix, int indent) + btrie_oct_t *prefix, int indent) { unsigned end = pos + lc_len(node); btrie_oct_t save_prefix = prefix[lc_shift(pos)]; @@ -2548,7 +2861,7 @@ dump_lc_node(const struct lc_node *node, unsigned pos, if (lc_is_terminal(node)) { dump_prefix(prefix, end, indent, ""); - printf(" (%s)\n", (const char *)node->ptr.data); + printf(" (%s)\n", (const char *) node->ptr.data); } else { dump_prefix(prefix, end, indent, "\n"); @@ -2557,16 +2870,16 @@ dump_lc_node(const struct lc_node *node, unsigned pos, prefix[lc_shift(pos)] = save_prefix; if (lc_bytes(node, pos) > 1) - memset(&prefix[lc_shift(pos) + 1], 0, lc_bytes(node, pos) - 1); + memset(&prefix[lc_shift(pos) + 1], 0, lc_bytes(node, pos) - 1); } static void dump_node(const node_t *node, unsigned pos, btrie_oct_t *prefix, int indent) { if (is_lc_node(node)) - dump_lc_node(&node->lc_node, pos, prefix, indent); + dump_lc_node(&node->lc_node, pos, prefix, indent); else - dump_tbm_node(&node->tbm_node, pos, prefix, indent); + dump_tbm_node(&node->tbm_node, pos, prefix, indent); } static void @@ -2591,8 +2904,7 @@ static int parse_prefix(const char *arg, btrie_oct_t prefix[16], unsigned *len) { char addrbuf[128]; - return sscanf(arg, "%127[0-9a-fA-F:]/%u", addrbuf, len) == 2 - && inet_pton(AF_INET6, addrbuf, prefix) == 1; + return sscanf(arg, "%127[0-9a-fA-F:]/%u", addrbuf, len) == 2 && inet_pton(AF_INET6, addrbuf, prefix) == 1; } static int @@ -2603,7 +2915,7 @@ test_btrie(int argc, char *argv[]) btrie_oct_t prefix[16]; unsigned len; - for (i = 1; i < argc-1; i++) { + for (i = 1; i < argc - 1; i++) { if (!parse_prefix(argv[i], prefix, &len)) { fprintf(stderr, "Can not parse arg '%s'\n", argv[i]); return 1; @@ -2616,29 +2928,28 @@ test_btrie(int argc, char *argv[]) if (argc > 1) { const void *data; - if (!parse_prefix(argv[argc-1], prefix, &len)) { - fprintf(stderr, "Can not parse arg '%s'\n", argv[argc-1]); + if (!parse_prefix(argv[argc - 1], prefix, &len)) { + fprintf(stderr, "Can not parse arg '%s'\n", argv[argc - 1]); return 1; } data = btrie_lookup(btrie, prefix, 128); - printf("lookup(%s) => %s\n", argv[argc-1], (const char *)data); + printf("lookup(%s) => %s\n", argv[argc - 1], (const char *) data); } return 0; } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { if ((pgm_name = strrchr(argv[0], '/')) != NULL) - pgm_name++; + pgm_name++; else - pgm_name = argv[0]; + pgm_name = argv[0]; if (argc > 1) - return test_btrie(argc, argv); + return test_btrie(argc, argv); else - return unit_tests(); + return unit_tests(); } #endif /* TEST */ diff --git a/contrib/lc-btrie/btrie.h b/contrib/lc-btrie/btrie.h index 370a03e51..4f147aa4a 100644 --- a/contrib/lc-btrie/btrie.h +++ b/contrib/lc-btrie/btrie.h @@ -50,34 +50,33 @@ typedef uint8_t btrie_oct_t; * in btrie_walk() --- btrie_add_prefix() and btrie_lookup() impose no * limit on the length of bitstrings */ -#define BTRIE_MAX_PREFIX 128 +#define BTRIE_MAX_PREFIX 128 struct btrie; struct memory_pool_s; -struct btrie * btrie_init(struct memory_pool_s *mp); +struct btrie *btrie_init(struct memory_pool_s *mp); -enum btrie_result -{ +enum btrie_result { BTRIE_OKAY = 0, BTRIE_ALLOC_FAILED = -1, BTRIE_DUPLICATE_PREFIX = 1 }; enum btrie_result btrie_add_prefix(struct btrie *btrie, - const btrie_oct_t *prefix, unsigned len, const void *data); + const btrie_oct_t *prefix, unsigned len, const void *data); const void *btrie_lookup(const struct btrie *btrie, const btrie_oct_t *pfx, - unsigned len); + unsigned len); -const char *btrie_stats(const struct btrie *btrie, guint duplicates); +const char *btrie_stats(const struct btrie *btrie, unsigned int duplicates); #ifndef NO_MASTER_DUMP typedef void btrie_walk_cb_t(const btrie_oct_t *prefix, unsigned len, - const void *data, int post, void *user_data); + const void *data, int post, void *user_data); void btrie_walk(const struct btrie *btrie, btrie_walk_cb_t *callback, - void *user_data); + void *user_data); #endif /* not NO_MASTER_DUMP */ #endif /* _BTRIE_H_INCLUDED */ diff --git a/contrib/librdns/resolver.c b/contrib/librdns/resolver.c index bfcfd0ae2..29624ef2a 100644 --- a/contrib/librdns/resolver.c +++ b/contrib/librdns/resolver.c @@ -1,3 +1,19 @@ +/* + * Copyright 2024 Vsevolod Stakhov + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Copyright (c) 2014, Vsevolod Stakhov * @@ -43,10 +59,10 @@ #include "compression.h" __KHASH_IMPL(rdns_requests_hash, kh_inline, int, struct rdns_request *, true, - kh_int_hash_func, kh_int_hash_equal); + kh_int_hash_func, kh_int_hash_equal); static int -rdns_send_request (struct rdns_request *req, int fd, bool new_req) +rdns_send_request(struct rdns_request *req, int fd, bool new_req) { ssize_t r; struct rdns_server *serv = req->io->srv; @@ -78,26 +94,26 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req) if (resolver->curve_plugin == NULL) { if (!IS_CHANNEL_CONNECTED(req->io)) { - r = sendto (fd, req->packet, req->pos, 0, - req->io->saddr, - req->io->slen); + r = sendto(fd, req->packet, req->pos, 0, + req->io->saddr, + req->io->slen); } else { - r = send (fd, req->packet, req->pos, 0); + r = send(fd, req->packet, req->pos, 0); } } else { if (!IS_CHANNEL_CONNECTED(req->io)) { - r = resolver->curve_plugin->cb.curve_plugin.send_cb (req, - resolver->curve_plugin->data, - req->io->saddr, - req->io->slen); + r = resolver->curve_plugin->cb.curve_plugin.send_cb(req, + resolver->curve_plugin->data, + req->io->saddr, + req->io->slen); } else { - r = resolver->curve_plugin->cb.curve_plugin.send_cb (req, - resolver->curve_plugin->data, - NULL, - 0); + r = resolver->curve_plugin->cb.curve_plugin.send_cb(req, + resolver->curve_plugin->data, + NULL, + 0); } } if (r == -1) { @@ -108,8 +124,8 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req) k = kh_put(rdns_requests_hash, req->io->requests, req->id, &pr); kh_value(req->io->requests, k) = req; - req->async_event = resolver->async->add_write (resolver->async->data, - fd, req); + req->async_event = resolver->async->add_write(resolver->async->data, + fd, req); req->state = RDNS_REQUEST_WAIT_SEND; } /* @@ -119,17 +135,17 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req) return 0; } else { - rdns_debug ("send failed: %s for server %s", strerror (errno), serv->name); + rdns_debug("send failed: %s for server %s", strerror(errno), serv->name); return -1; } } else if (!IS_CHANNEL_CONNECTED(req->io)) { /* Connect socket */ - r = connect (fd, req->io->saddr, req->io->slen); + r = connect(fd, req->io->saddr, req->io->slen); if (r == -1) { - rdns_err ("cannot connect after sending request: %s for server %s", - strerror (errno), serv->name); + rdns_err("cannot connect after sending request: %s for server %s", + strerror(errno), serv->name); } else { req->io->flags |= RDNS_CHANNEL_CONNECTED; @@ -142,8 +158,8 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req) k = kh_put(rdns_requests_hash, req->io->requests, req->id, &pr); kh_value(req->io->requests, k) = req; /* Fill timeout */ - req->async_event = resolver->async->add_timer (resolver->async->data, - req->timeout, req); + req->async_event = resolver->async->add_timer(resolver->async->data, + req->timeout, req); req->state = RDNS_REQUEST_WAIT_REPLY; } @@ -152,19 +168,19 @@ rdns_send_request (struct rdns_request *req, int fd, bool new_req) static struct rdns_request * -rdns_find_dns_request (uint8_t *in, struct rdns_io_channel *ioc) +rdns_find_dns_request(uint8_t *in, struct rdns_io_channel *ioc) { struct dns_header header; int id; struct rdns_resolver *resolver = ioc->resolver; - memcpy (&header, in, sizeof(header)); + memcpy(&header, in, sizeof(header)); id = header.qid; khiter_t k = kh_get(rdns_requests_hash, ioc->requests, id); if (k == kh_end(ioc->requests)) { /* No such requests found */ - rdns_debug ("DNS request with id %d has not been found for IO channel", id); + rdns_debug("DNS request with id %d has not been found for IO channel", id); return NULL; } @@ -173,10 +189,10 @@ rdns_find_dns_request (uint8_t *in, struct rdns_io_channel *ioc) } static bool -rdns_parse_reply (uint8_t *in, int r, struct rdns_request *req, - struct rdns_reply **_rep) +rdns_parse_reply(uint8_t *in, int r, struct rdns_request *req, + struct rdns_reply **_rep) { - struct dns_header *header = (struct dns_header *)in; + struct dns_header *header = (struct dns_header *) in; struct rdns_reply *rep; struct rdns_reply_entry *elt; uint8_t *pos, *npos; @@ -189,14 +205,14 @@ rdns_parse_reply (uint8_t *in, int r, struct rdns_request *req, /* First check header fields */ if (header->qr == 0) { - rdns_info ("got request while waiting for reply"); + rdns_info("got request while waiting for reply"); return false; } - qdcount = ntohs (header->qdcount); + qdcount = ntohs(header->qdcount); if (qdcount != req->qcount) { - rdns_info ("request has %d queries, reply has %d queries", (int)req->qcount, (int)header->qdcount); + rdns_info("request has %d queries, reply has %d queries", (int) req->qcount, (int) header->qdcount); return false; } @@ -204,12 +220,12 @@ rdns_parse_reply (uint8_t *in, int r, struct rdns_request *req, * Now we have request and query data is now at the end of header, so compare * request QR section and reply QR section */ - req->pos = sizeof (struct dns_header); - pos = in + sizeof (struct dns_header); - t = r - sizeof (struct dns_header); - for (i = 0; i < (int)qdcount; i ++) { - if ((npos = rdns_request_reply_cmp (req, pos,t)) == NULL) { - rdns_info ("DNS request with id %d is for different query, ignoring", (int)req->id); + req->pos = sizeof(struct dns_header); + pos = in + sizeof(struct dns_header); + t = r - sizeof(struct dns_header); + for (i = 0; i < (int) qdcount; i++) { + if ((npos = rdns_request_reply_cmp(req, pos, t)) == NULL) { + rdns_info("DNS request with id %d is for different query, ignoring", (int) req->id); return false; } t -= npos - pos; @@ -218,7 +234,7 @@ rdns_parse_reply (uint8_t *in, int r, struct rdns_request *req, /* * Now pos is in answer section, so we should extract data and form reply */ - rep = rdns_make_reply (req, header->rcode); + rep = rdns_make_reply(req, header->rcode); if (header->ad) { rep->flags |= RDNS_AUTH; @@ -229,7 +245,7 @@ rdns_parse_reply (uint8_t *in, int r, struct rdns_request *req, } if (rep == NULL) { - rdns_warn ("Cannot allocate memory for reply"); + rdns_warn("Cannot allocate memory for reply"); return false; } @@ -238,24 +254,24 @@ rdns_parse_reply (uint8_t *in, int r, struct rdns_request *req, if (rep->code == RDNS_RC_NOERROR) { r -= pos - in; /* Extract RR records */ - for (i = 0; i < ntohs (header->ancount); i ++) { - elt = malloc (sizeof (struct rdns_reply_entry)); - t = rdns_parse_rr (resolver, in, elt, &pos, rep, &r); + for (i = 0; i < ntohs(header->ancount); i++) { + elt = malloc(sizeof(struct rdns_reply_entry)); + t = rdns_parse_rr(resolver, in, elt, &pos, rep, &r); if (t == -1) { - free (elt); - rdns_debug ("incomplete reply"); + free(elt); + rdns_debug("incomplete reply"); break; } else if (t == 1) { - DL_APPEND (rep->entries, elt); + DL_APPEND(rep->entries, elt); if (elt->type == type) { found = true; } } else { - rdns_debug ("no matching reply for %s", - req->requested_names[0].name); - free (elt); + rdns_debug("no matching reply for %s", + req->requested_names[0].name); + free(elt); } } } @@ -272,7 +288,7 @@ rdns_parse_reply (uint8_t *in, int r, struct rdns_request *req, } static bool -rdns_tcp_maybe_realloc_read_buf (struct rdns_io_channel *ioc) +rdns_tcp_maybe_realloc_read_buf(struct rdns_io_channel *ioc) { if (ioc->tcp->read_buf_allocated == 0 && ioc->tcp->next_read_size > 0) { ioc->tcp->cur_read_buf = malloc(ioc->tcp->next_read_size); @@ -294,7 +310,7 @@ rdns_tcp_maybe_realloc_read_buf (struct rdns_io_channel *ioc) void *next_buf = realloc(ioc->tcp->cur_read_buf, next_shift); if (next_buf == NULL) { - free (ioc->tcp->cur_read_buf); + free(ioc->tcp->cur_read_buf); ioc->tcp->cur_read_buf = NULL; return false; } @@ -306,7 +322,7 @@ rdns_tcp_maybe_realloc_read_buf (struct rdns_io_channel *ioc) } static void -rdns_process_tcp_read (int fd, struct rdns_io_channel *ioc) +rdns_process_tcp_read(int fd, struct rdns_io_channel *ioc) { ssize_t r; struct rdns_resolver *resolver = ioc->resolver; @@ -327,7 +343,7 @@ rdns_process_tcp_read (int fd, struct rdns_io_channel *ioc) /* We have read the size, so we can try read one more time */ if (!rdns_tcp_maybe_realloc_read_buf(ioc)) { rdns_err("failed to allocate %d bytes: %s", - (int)ioc->tcp->next_read_size, strerror(errno)); + (int) ioc->tcp->next_read_size, strerror(errno)); r = -1; goto err; } @@ -338,7 +354,7 @@ rdns_process_tcp_read (int fd, struct rdns_io_channel *ioc) } } else if (ioc->tcp->cur_read == 1) { - r = read(fd, ((unsigned char *)&ioc->tcp->next_read_size) + 1, 1); + r = read(fd, ((unsigned char *) &ioc->tcp->next_read_size) + 1, 1); if (r == -1 || r == 0) { goto err; @@ -350,7 +366,7 @@ rdns_process_tcp_read (int fd, struct rdns_io_channel *ioc) /* We have read the size, so we can try read one more time */ if (!rdns_tcp_maybe_realloc_read_buf(ioc)) { rdns_err("failed to allocate %d bytes: %s", - (int)ioc->tcp->next_read_size, strerror(errno)); + (int) ioc->tcp->next_read_size, strerror(errno)); r = -1; goto err; } @@ -380,22 +396,22 @@ rdns_process_tcp_read (int fd, struct rdns_io_channel *ioc) if ((ioc->tcp->cur_read - 2) == ioc->tcp->next_read_size) { /* We have a full packet ready, process it */ - struct rdns_request *req = rdns_find_dns_request (ioc->tcp->cur_read_buf, ioc); + struct rdns_request *req = rdns_find_dns_request(ioc->tcp->cur_read_buf, ioc); if (req != NULL) { struct rdns_reply *rep; - if (rdns_parse_reply (ioc->tcp->cur_read_buf, - ioc->tcp->next_read_size, req, &rep)) { - UPSTREAM_OK (req->io->srv); + if (rdns_parse_reply(ioc->tcp->cur_read_buf, + ioc->tcp->next_read_size, req, &rep)) { + UPSTREAM_OK(req->io->srv); if (req->resolver->ups && req->io->srv->ups_elt) { - req->resolver->ups->ok (req->io->srv->ups_elt, - req->resolver->ups->data); + req->resolver->ups->ok(req->io->srv->ups_elt, + req->resolver->ups->data); } - req->func (rep, req->arg); - REF_RELEASE (req); + req->func(rep, req->arg); + REF_RELEASE(req); } } else { @@ -406,7 +422,7 @@ rdns_process_tcp_read (int fd, struct rdns_io_channel *ioc) ioc->tcp->cur_read = 0; /* Retry read the next packet to avoid unnecessary polling */ - rdns_process_tcp_read (fd, ioc); + rdns_process_tcp_read(fd, ioc); } return; @@ -414,37 +430,37 @@ rdns_process_tcp_read (int fd, struct rdns_io_channel *ioc) err: if (r == 0) { /* Got EOF, just close the socket */ - rdns_debug ("closing TCP channel due to EOF"); - rdns_ioc_tcp_reset (ioc); + rdns_debug("closing TCP channel due to EOF"); + rdns_ioc_tcp_reset(ioc); } else if (errno == EINTR || errno == EAGAIN) { /* We just retry later as there is no real error */ return; } else { - rdns_debug ("closing TCP channel due to IO error: %s", strerror(errno)); - rdns_ioc_tcp_reset (ioc); + rdns_debug("closing TCP channel due to IO error: %s", strerror(errno)); + rdns_ioc_tcp_reset(ioc); } } static void -rdns_process_tcp_connect (int fd, struct rdns_io_channel *ioc) +rdns_process_tcp_connect(int fd, struct rdns_io_channel *ioc) { - ioc->flags |= RDNS_CHANNEL_CONNECTED|RDNS_CHANNEL_ACTIVE; + ioc->flags |= RDNS_CHANNEL_CONNECTED | RDNS_CHANNEL_ACTIVE; ioc->flags &= ~RDNS_CHANNEL_TCP_CONNECTING; if (ioc->tcp->async_read == NULL) { ioc->tcp->async_read = ioc->resolver->async->add_read(ioc->resolver->async->data, - ioc->sock, ioc); + ioc->sock, ioc); } } static bool -rdns_reschedule_req_over_tcp (struct rdns_request *req, struct rdns_server *serv) +rdns_reschedule_req_over_tcp(struct rdns_request *req, struct rdns_server *serv) { struct rdns_resolver *resolver; struct rdns_io_channel *old_ioc = req->io, - *ioc = serv->tcp_io_channels[ottery_rand_uint32 () % serv->tcp_io_cnt]; + *ioc = serv->tcp_io_channels[ottery_rand_uint32() % serv->tcp_io_cnt]; resolver = req->resolver; @@ -461,25 +477,25 @@ rdns_reschedule_req_over_tcp (struct rdns_request *req, struct rdns_server *serv if (oc == NULL) { rdns_err("failed to allocate output buffer for TCP ioc: %s", - strerror(errno)); + strerror(errno)); return false; } - oc->write_buf = ((unsigned char *)oc) + sizeof(*oc); + oc->write_buf = ((unsigned char *) oc) + sizeof(*oc); memcpy(oc->write_buf, req->packet, req->packet_len); oc->next_write_size = htons(req->packet_len); DL_APPEND(ioc->tcp->output_chain, oc); if (ioc->tcp->async_write == NULL) { - ioc->tcp->async_write = resolver->async->add_write ( - resolver->async->data, - ioc->sock, ioc); + ioc->tcp->async_write = resolver->async->add_write( + resolver->async->data, + ioc->sock, ioc); } req->state = RDNS_REQUEST_TCP; /* Switch IO channel from UDP to TCP */ - rdns_request_remove_from_hash (req); + rdns_request_remove_from_hash(req); req->io = ioc; khiter_t k; @@ -489,7 +505,7 @@ rdns_reschedule_req_over_tcp (struct rdns_request *req, struct rdns_server *serv if (pr == 0) { /* We have already a request with this id, so we have to regenerate ID */ - req->id = rdns_permutor_generate_id (); + req->id = rdns_permutor_generate_id(); /* Update packet as well */ uint16_t raw_id = req->id; memcpy(req->packet, &raw_id, sizeof(raw_id)); @@ -499,8 +515,8 @@ rdns_reschedule_req_over_tcp (struct rdns_request *req, struct rdns_server *serv } } - req->async_event = resolver->async->add_timer (resolver->async->data, - req->timeout, req); + req->async_event = resolver->async->add_timer(resolver->async->data, + req->timeout, req); kh_value(req->io->requests, k) = req; REF_RELEASE(old_ioc); @@ -513,7 +529,7 @@ rdns_reschedule_req_over_tcp (struct rdns_request *req, struct rdns_server *serv } static void -rdns_process_udp_read (int fd, struct rdns_io_channel *ioc) +rdns_process_udp_read(int fd, struct rdns_io_channel *ioc) { struct rdns_resolver *resolver; struct rdns_request *req = NULL; @@ -525,47 +541,47 @@ rdns_process_udp_read (int fd, struct rdns_io_channel *ioc) /* First read packet from socket */ if (resolver->curve_plugin == NULL) { - r = recv (fd, in, sizeof (in), 0); - if (r > (int)(sizeof (struct dns_header) + sizeof (struct dns_query))) { - req = rdns_find_dns_request (in, ioc); + r = recv(fd, in, sizeof(in), 0); + if (r > (int) (sizeof(struct dns_header) + sizeof(struct dns_query))) { + req = rdns_find_dns_request(in, ioc); } } else { - r = resolver->curve_plugin->cb.curve_plugin.recv_cb (ioc, in, - sizeof (in), resolver->curve_plugin->data, &req, - ioc->saddr, ioc->slen); + r = resolver->curve_plugin->cb.curve_plugin.recv_cb(ioc, in, + sizeof(in), resolver->curve_plugin->data, &req, + ioc->saddr, ioc->slen); if (req == NULL && - r > (int)(sizeof (struct dns_header) + sizeof (struct dns_query))) { - req = rdns_find_dns_request (in, ioc); + r > (int) (sizeof(struct dns_header) + sizeof(struct dns_query))) { + req = rdns_find_dns_request(in, ioc); } } if (req != NULL) { - if (rdns_parse_reply (in, r, req, &rep)) { - UPSTREAM_OK (req->io->srv); + if (rdns_parse_reply(in, r, req, &rep)) { + UPSTREAM_OK(req->io->srv); if (req->resolver->ups && req->io->srv->ups_elt) { - req->resolver->ups->ok (req->io->srv->ups_elt, - req->resolver->ups->data); + req->resolver->ups->ok(req->io->srv->ups_elt, + req->resolver->ups->data); } - rdns_request_unschedule (req, true); + rdns_request_unschedule(req, true); if (!(rep->flags & RDNS_TRUNCATED)) { req->state = RDNS_REQUEST_REPLIED; req->func(rep, req->arg); /* This will free reply as well */ - REF_RELEASE (req); + REF_RELEASE(req); } else { if (req->io->srv->tcp_io_cnt > 0) { rdns_debug("truncated UDP reply for %s; schedule over TCP", req->requested_names[0].name); /* Reschedule via TCP */ - if (!rdns_reschedule_req_over_tcp (req, req->io->srv)) { + if (!rdns_reschedule_req_over_tcp(req, req->io->srv)) { /* Use truncated reply as we have no other options */ req->state = RDNS_REQUEST_REPLIED; req->func(rep, req->arg); - REF_RELEASE (req); + REF_RELEASE(req); } else { /* Remove and free the truncated reply, as we have rescheduled the reply */ @@ -578,42 +594,40 @@ rdns_process_udp_read (int fd, struct rdns_io_channel *ioc) req->state = RDNS_REQUEST_REPLIED; req->func(rep, req->arg); /* This will free reply as well */ - REF_RELEASE (req); + REF_RELEASE(req); } } } } else { /* Still want to increase uses */ - ioc->uses ++; + ioc->uses++; } } -void -rdns_process_read (int fd, void *arg) +void rdns_process_read(int fd, void *arg) { - struct rdns_io_channel *ioc = (struct rdns_io_channel *)arg; + struct rdns_io_channel *ioc = (struct rdns_io_channel *) arg; struct rdns_resolver *resolver; resolver = ioc->resolver; if (IS_CHANNEL_TCP(ioc)) { if (IS_CHANNEL_CONNECTED(ioc)) { - rdns_process_tcp_read (fd, ioc); + rdns_process_tcp_read(fd, ioc); } else { - rdns_err ("read readiness on non connected TCP channel!"); + rdns_err("read readiness on non connected TCP channel!"); } } else { - rdns_process_udp_read (fd, ioc); + rdns_process_udp_read(fd, ioc); } } -void -rdns_process_timer (void *arg) +void rdns_process_timer(void *arg) { - struct rdns_request *req = (struct rdns_request *)arg; + struct rdns_request *req = (struct rdns_request *) arg; struct rdns_reply *rep; int r; bool renew = false; @@ -621,34 +635,34 @@ rdns_process_timer (void *arg) struct rdns_server *serv = NULL; unsigned cnt; - req->retransmits --; + req->retransmits--; resolver = req->resolver; if (req->resolver->ups && req->io->srv->ups_elt) { - req->resolver->ups->fail (req->io->srv->ups_elt, - req->resolver->ups->data, "timeout waiting reply"); + req->resolver->ups->fail(req->io->srv->ups_elt, + req->resolver->ups->data, "timeout waiting reply"); } else { - UPSTREAM_FAIL (req->io->srv, time (NULL)); + UPSTREAM_FAIL(req->io->srv, time(NULL)); } if (req->state == RDNS_REQUEST_TCP) { - rep = rdns_make_reply (req, RDNS_RC_TIMEOUT); - rdns_request_unschedule (req, true); + rep = rdns_make_reply(req, RDNS_RC_TIMEOUT); + rdns_request_unschedule(req, true); req->state = RDNS_REQUEST_REPLIED; - req->func (rep, req->arg); - REF_RELEASE (req); + req->func(rep, req->arg); + REF_RELEASE(req); return; } if (req->retransmits == 0) { - rep = rdns_make_reply (req, RDNS_RC_TIMEOUT); - rdns_request_unschedule (req, true); + rep = rdns_make_reply(req, RDNS_RC_TIMEOUT); + rdns_request_unschedule(req, true); req->state = RDNS_REQUEST_REPLIED; - req->func (rep, req->arg); - REF_RELEASE (req); + req->func(rep, req->arg); + REF_RELEASE(req); return; } @@ -656,56 +670,57 @@ rdns_process_timer (void *arg) if (!IS_CHANNEL_ACTIVE(req->io) || req->retransmits == 1) { if (resolver->ups) { - cnt = resolver->ups->count (resolver->ups->data); + cnt = resolver->ups->count(resolver->ups->data); } else { cnt = 0; - UPSTREAM_FOREACH (resolver->servers, serv) { - cnt ++; + UPSTREAM_FOREACH(resolver->servers, serv) + { + cnt++; } } if (!IS_CHANNEL_ACTIVE(req->io) || cnt > 1) { /* Do not reschedule IO requests on inactive sockets */ - rdns_debug ("reschedule request with id: %d", (int)req->id); - rdns_request_unschedule (req, true); - REF_RELEASE (req->io); + rdns_debug("reschedule request with id: %d", (int) req->id); + rdns_request_unschedule(req, true); + REF_RELEASE(req->io); if (resolver->ups) { struct rdns_upstream_elt *elt; - elt = resolver->ups->select_retransmit ( - req->requested_names[0].name, - req->requested_names[0].len, - req->io->srv->ups_elt, - resolver->ups->data); + elt = resolver->ups->select_retransmit( + req->requested_names[0].name, + req->requested_names[0].len, + req->io->srv->ups_elt, + resolver->ups->data); if (elt) { serv = elt->server; serv->ups_elt = elt; } else { - UPSTREAM_SELECT_ROUND_ROBIN (resolver->servers, serv); + UPSTREAM_SELECT_ROUND_ROBIN(resolver->servers, serv); } } else { - UPSTREAM_SELECT_ROUND_ROBIN (resolver->servers, serv); + UPSTREAM_SELECT_ROUND_ROBIN(resolver->servers, serv); } if (serv == NULL) { - rdns_warn ("cannot find suitable server for request"); - rep = rdns_make_reply (req, RDNS_RC_SERVFAIL); + rdns_warn("cannot find suitable server for request"); + rep = rdns_make_reply(req, RDNS_RC_SERVFAIL); req->state = RDNS_REQUEST_REPLIED; - req->func (rep, req->arg); - REF_RELEASE (req); + req->func(rep, req->arg); + REF_RELEASE(req); return; } /* Select random IO channel */ - req->io = serv->io_channels[ottery_rand_uint32 () % serv->io_cnt]; - req->io->uses ++; - REF_RETAIN (req->io); + req->io = serv->io_channels[ottery_rand_uint32() % serv->io_cnt]; + req->io->uses++; + REF_RETAIN(req->io); renew = true; } } @@ -714,61 +729,62 @@ rdns_process_timer (void *arg) * Note: when `renew` is true, then send_request deals with the * timers and events itself */ - r = rdns_send_request (req, req->io->sock, renew); + r = rdns_send_request(req, req->io->sock, renew); if (r == 0) { /* Retransmit one more time */ if (!renew) { - req->async->del_timer (req->async->data, - req->async_event); - req->async_event = req->async->add_write (req->async->data, - req->io->sock, req); + req->async->del_timer(req->async->data, + req->async_event); + req->async_event = req->async->add_write(req->async->data, + req->io->sock, req); } req->state = RDNS_REQUEST_WAIT_SEND; } else if (r == -1) { if (req->resolver->ups && req->io->srv->ups_elt) { - req->resolver->ups->fail (req->io->srv->ups_elt, - req->resolver->ups->data, "cannot send retransmit after timeout"); + req->resolver->ups->fail(req->io->srv->ups_elt, + req->resolver->ups->data, "cannot send retransmit after timeout"); } else { - UPSTREAM_FAIL (req->io->srv, time (NULL)); + UPSTREAM_FAIL(req->io->srv, time(NULL)); } if (!renew) { - req->async->del_timer (req->async->data, - req->async_event); + req->async->del_timer(req->async->data, + req->async_event); req->async_event = NULL; rdns_request_remove_from_hash(req); } /* We have not scheduled timeout actually due to send error */ - rep = rdns_make_reply (req, RDNS_RC_NETERR); + rep = rdns_make_reply(req, RDNS_RC_NETERR); req->state = RDNS_REQUEST_REPLIED; - req->func (rep, req->arg); - REF_RELEASE (req); + req->func(rep, req->arg); + REF_RELEASE(req); } else { - req->async->repeat_timer (req->async->data, req->async_event); + req->async->repeat_timer(req->async->data, req->async_event); req->state = RDNS_REQUEST_WAIT_REPLY; } } static void -rdns_process_periodic (void *arg) +rdns_process_periodic(void *arg) { - struct rdns_resolver *resolver = (struct rdns_resolver*)arg; + struct rdns_resolver *resolver = (struct rdns_resolver *) arg; struct rdns_server *serv; - UPSTREAM_RESCAN (resolver->servers, time (NULL)); + UPSTREAM_RESCAN(resolver->servers, time(NULL)); - UPSTREAM_FOREACH (resolver->servers, serv) { - for (int i = 0; i < serv->tcp_io_cnt; i ++) { + UPSTREAM_FOREACH(resolver->servers, serv) + { + for (int i = 0; i < serv->tcp_io_cnt; i++) { if (IS_CHANNEL_CONNECTED(serv->tcp_io_channels[i])) { /* Disconnect channels with no requests in flight */ if (kh_size(serv->tcp_io_channels[i]->requests) == 0) { - rdns_debug ("reset inactive TCP connection to %s", serv->name); - rdns_ioc_tcp_reset (serv->tcp_io_channels[i]); + rdns_debug("reset inactive TCP connection to %s", serv->name); + rdns_ioc_tcp_reset(serv->tcp_io_channels[i]); } } } @@ -776,31 +792,33 @@ rdns_process_periodic (void *arg) } static void -rdns_process_ioc_refresh (void *arg) +rdns_process_ioc_refresh(void *arg) { - struct rdns_resolver *resolver = (struct rdns_resolver*)arg; + struct rdns_resolver *resolver = (struct rdns_resolver *) arg; struct rdns_server *serv; struct rdns_io_channel *ioc, *nioc; unsigned int i; if (resolver->max_ioc_uses > 0) { - UPSTREAM_FOREACH (resolver->servers, serv) { - for (i = 0; i < serv->io_cnt; i ++) { + UPSTREAM_FOREACH(resolver->servers, serv) + { + for (i = 0; i < serv->io_cnt; i++) { ioc = serv->io_channels[i]; if (ioc->uses > resolver->max_ioc_uses) { /* Schedule IOC removing */ - nioc = rdns_ioc_new (serv, resolver, false); + nioc = rdns_ioc_new(serv, resolver, false); if (nioc == NULL) { - rdns_err ("calloc fails to allocate rdns_io_channel"); + rdns_err("calloc fails to allocate rdns_io_channel"); continue; } serv->io_channels[i] = nioc; - rdns_debug ("scheduled io channel for server %s to be refreshed after " - "%lu usages", serv->name, (unsigned long)ioc->uses); + rdns_debug("scheduled io channel for server %s to be refreshed after " + "%lu usages", + serv->name, (unsigned long) ioc->uses); ioc->flags &= ~RDNS_CHANNEL_ACTIVE; - REF_RELEASE (ioc); + REF_RELEASE(ioc); } } } @@ -808,7 +826,7 @@ rdns_process_ioc_refresh (void *arg) } static void -rdns_process_udp_retransmit (int fd, struct rdns_request *req) +rdns_process_udp_retransmit(int fd, struct rdns_request *req) { struct rdns_resolver *resolver; struct rdns_reply *rep; @@ -816,67 +834,67 @@ rdns_process_udp_retransmit (int fd, struct rdns_request *req) resolver = req->resolver; - resolver->async->del_write (resolver->async->data, - req->async_event); + resolver->async->del_write(resolver->async->data, + req->async_event); req->async_event = NULL; if (req->state == RDNS_REQUEST_FAKE) { /* Reply is ready */ - req->func (req->reply, req->arg); - REF_RELEASE (req); + req->func(req->reply, req->arg); + REF_RELEASE(req); return; } - r = rdns_send_request (req, fd, false); + r = rdns_send_request(req, fd, false); if (r == 0) { /* Retransmit one more time */ - req->async_event = req->async->add_write (req->async->data, - fd, req); + req->async_event = req->async->add_write(req->async->data, + fd, req); req->state = RDNS_REQUEST_WAIT_SEND; } else if (r == -1) { if (req->resolver->ups && req->io->srv->ups_elt) { - req->resolver->ups->fail (req->io->srv->ups_elt, - req->resolver->ups->data, "retransmit send failed"); + req->resolver->ups->fail(req->io->srv->ups_elt, + req->resolver->ups->data, "retransmit send failed"); } else { - UPSTREAM_FAIL (req->io->srv, time (NULL)); + UPSTREAM_FAIL(req->io->srv, time(NULL)); } - rep = rdns_make_reply (req, RDNS_RC_NETERR); + rep = rdns_make_reply(req, RDNS_RC_NETERR); req->state = RDNS_REQUEST_REPLIED; - req->func (rep, req->arg); - REF_RELEASE (req); + req->func(rep, req->arg); + REF_RELEASE(req); } else { - req->async_event = req->async->add_timer (req->async->data, - req->timeout, req); + req->async_event = req->async->add_timer(req->async->data, + req->timeout, req); req->state = RDNS_REQUEST_WAIT_REPLY; } } static ssize_t -rdns_write_output_chain (struct rdns_io_channel *ioc, struct rdns_tcp_output_chain *oc) +rdns_write_output_chain(struct rdns_io_channel *ioc, struct rdns_tcp_output_chain *oc) { ssize_t r; struct iovec iov[2]; int niov, already_written; - int packet_len = ntohs (oc->next_write_size); + int packet_len = ntohs(oc->next_write_size); switch (oc->cur_write) { case 0: /* Size + DNS request in full */ iov[0].iov_base = &oc->next_write_size; - iov[0].iov_len = sizeof (oc->next_write_size); + iov[0].iov_len = sizeof(oc->next_write_size); iov[1].iov_base = oc->write_buf; iov[1].iov_len = packet_len; niov = 2; break; case 1: /* Partial Size + DNS request in full */ - iov[0].iov_base = ((unsigned char *)&oc->next_write_size) + 1; + iov[0].iov_base = ((unsigned char *) &oc->next_write_size) + 1; iov[0].iov_len = 1; iov[1].iov_base = oc->write_buf; iov[1].iov_len = packet_len; @@ -905,15 +923,16 @@ rdns_write_output_chain (struct rdns_io_channel *ioc, struct rdns_tcp_output_cha } static void -rdns_process_tcp_write (int fd, struct rdns_io_channel *ioc) +rdns_process_tcp_write(int fd, struct rdns_io_channel *ioc) { struct rdns_resolver *resolver = ioc->resolver; /* Try to write as much as we can */ struct rdns_tcp_output_chain *oc, *tmp; - DL_FOREACH_SAFE(ioc->tcp->output_chain, oc, tmp) { - ssize_t r = rdns_write_output_chain (ioc, oc); + DL_FOREACH_SAFE(ioc->tcp->output_chain, oc, tmp) + { + ssize_t r = rdns_write_output_chain(ioc, oc); if (r == -1) { if (errno == EAGAIN || errno == EINTR) { @@ -921,17 +940,17 @@ rdns_process_tcp_write (int fd, struct rdns_io_channel *ioc) return; } else { - rdns_err ("error when trying to write request to %s: %s", - ioc->srv->name, strerror (errno)); - rdns_ioc_tcp_reset (ioc); + rdns_err("error when trying to write request to %s: %s", + ioc->srv->name, strerror(errno)); + rdns_ioc_tcp_reset(ioc); return; } } else if (ntohs(oc->next_write_size) < oc->cur_write) { /* Packet has been fully written, remove it */ DL_DELETE(ioc->tcp->output_chain, oc); - free (oc); /* It also frees write buf */ - ioc->tcp->cur_output_chains --; + free(oc); /* It also frees write buf */ + ioc->tcp->cur_output_chains--; } else { /* Buffer is not yet processed, stop unless we can continue */ @@ -941,14 +960,13 @@ rdns_process_tcp_write (int fd, struct rdns_io_channel *ioc) if (ioc->tcp->cur_output_chains == 0) { /* Unregister write event */ - ioc->resolver->async->del_write (ioc->resolver->async->data, - ioc->tcp->async_write); + ioc->resolver->async->del_write(ioc->resolver->async->data, + ioc->tcp->async_write); ioc->tcp->async_write = NULL; } } -void -rdns_process_write (int fd, void *arg) +void rdns_process_write(int fd, void *arg) { /* * We first need to dispatch *arg to understand what has caused the write @@ -962,7 +980,7 @@ rdns_process_write (int fd, void *arg) */ uint64_t tag; - memcpy (&tag, arg, sizeof(tag)); + memcpy(&tag, arg, sizeof(tag)); if (tag == RDNS_IO_CHANNEL_TAG) { struct rdns_io_channel *ioc = (struct rdns_io_channel *) arg; @@ -982,10 +1000,10 @@ rdns_process_write (int fd, void *arg) } struct rdns_server * -rdns_select_request_upstream (struct rdns_resolver *resolver, - struct rdns_request *req, - bool is_retransmit, - struct rdns_server *prev_serv) +rdns_select_request_upstream(struct rdns_resolver *resolver, + struct rdns_request *req, + bool is_retransmit, + struct rdns_server *prev_serv) { struct rdns_server *serv = NULL; @@ -993,14 +1011,14 @@ rdns_select_request_upstream (struct rdns_resolver *resolver, struct rdns_upstream_elt *elt; if (is_retransmit && prev_serv) { - elt = resolver->ups->select_retransmit (req->requested_names[0].name, - req->requested_names[0].len, - prev_serv->ups_elt, - resolver->ups->data); + elt = resolver->ups->select_retransmit(req->requested_names[0].name, + req->requested_names[0].len, + prev_serv->ups_elt, + resolver->ups->data); } else { - elt = resolver->ups->select (req->requested_names[0].name, - req->requested_names[0].len, resolver->ups->data); + elt = resolver->ups->select(req->requested_names[0].name, + req->requested_names[0].len, resolver->ups->data); } if (elt) { @@ -1008,29 +1026,28 @@ rdns_select_request_upstream (struct rdns_resolver *resolver, serv->ups_elt = elt; } else { - UPSTREAM_SELECT_ROUND_ROBIN (resolver->servers, serv); + UPSTREAM_SELECT_ROUND_ROBIN(resolver->servers, serv); } } else { - UPSTREAM_SELECT_ROUND_ROBIN (resolver->servers, serv); + UPSTREAM_SELECT_ROUND_ROBIN(resolver->servers, serv); } return serv; } -#define align_ptr(p, a) \ - (guint8 *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1)) - -struct rdns_request* -rdns_make_request_full ( - struct rdns_resolver *resolver, - dns_callback_type cb, - void *cbdata, - double timeout, - unsigned int repeats, - unsigned int queries, - ... - ) +#define align_ptr(p, a) \ + (uint8_t *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1)) + +struct rdns_request * +rdns_make_request_full( + struct rdns_resolver *resolver, + dns_callback_type cb, + void *cbdata, + double timeout, + unsigned int repeats, + unsigned int queries, + ...) { va_list args; struct rdns_request *req; @@ -1041,7 +1058,7 @@ rdns_make_request_full ( const char *cur_name, *last_name = NULL; khash_t(rdns_compression_hash) *comp = NULL; struct rdns_fake_reply *fake_rep = NULL; - char fake_buf[MAX_FAKE_NAME + sizeof (struct rdns_fake_reply_idx) + 16]; + char fake_buf[MAX_FAKE_NAME + sizeof(struct rdns_fake_reply_idx) + 16]; struct rdns_fake_reply_idx *idx; if (resolver == NULL || !resolver->initialized) { @@ -1049,15 +1066,15 @@ rdns_make_request_full ( return NULL; } - rdns_err ("resolver is uninitialized"); + rdns_err("resolver is uninitialized"); return NULL; } - req = malloc (sizeof (struct rdns_request)); + req = malloc(sizeof(struct rdns_request)); if (req == NULL) { - rdns_err ("failed to allocate memory for request: %s", - strerror (errno)); + rdns_err("failed to allocate memory for request: %s", + strerror(errno)); return NULL; } @@ -1069,13 +1086,13 @@ rdns_make_request_full ( req->io = NULL; req->state = RDNS_REQUEST_NEW; req->packet = NULL; - req->requested_names = calloc (queries, sizeof (struct rdns_request_name)); + req->requested_names = calloc(queries, sizeof(struct rdns_request_name)); req->async_event = NULL; if (req->requested_names == NULL) { - free (req); - rdns_err ("failed to allocate memory for request data: %s", - strerror (errno)); + free(req); + rdns_err("failed to allocate memory for request data: %s", + strerror(errno)); return NULL; } @@ -1084,34 +1101,34 @@ rdns_make_request_full ( #ifdef TWEETNACL req->curve_plugin_data = NULL; #endif - REF_INIT_RETAIN (req, rdns_request_free); + REF_INIT_RETAIN(req, rdns_request_free); /* Calculate packet's total length based on records count */ - va_start (args, queries); + va_start(args, queries); for (i = 0; i < queries * 2; i += 2) { cur = i / 2; - cur_name = va_arg (args, const char *); - type = va_arg (args, int); + cur_name = va_arg(args, const char *); + type = va_arg(args, int); if (cur_name != NULL) { - clen = strlen (cur_name); + clen = strlen(cur_name); if (clen == 0) { - rdns_warn ("got empty name to resolve"); - rdns_request_free (req); + rdns_warn("got empty name to resolve"); + rdns_request_free(req); return NULL; } if (cur_name[0] == '.') { /* Skip dots at the begin */ - unsigned int ndots = strspn (cur_name, "."); + unsigned int ndots = strspn(cur_name, "."); cur_name += ndots; clen -= ndots; if (clen == 0) { - rdns_warn ("got empty name to resolve"); - rdns_request_free (req); + rdns_warn("got empty name to resolve"); + rdns_request_free(req); return NULL; } } @@ -1119,28 +1136,28 @@ rdns_make_request_full ( if (cur_name[clen - 1] == '.') { /* Skip trailing dots */ while (clen >= 1 && cur_name[clen - 1] == '.') { - clen --; + clen--; } if (clen == 0) { - rdns_warn ("got empty name to resolve"); - rdns_request_free (req); + rdns_warn("got empty name to resolve"); + rdns_request_free(req); return NULL; } } if (last_name == NULL && queries == 1 && clen < MAX_FAKE_NAME) { /* We allocate structure in the static space */ - idx = (struct rdns_fake_reply_idx *)align_ptr (fake_buf, 16); + idx = (struct rdns_fake_reply_idx *) align_ptr(fake_buf, 16); idx->type = type; idx->len = clen; - memcpy (idx->request, cur_name, clen); - HASH_FIND (hh, resolver->fake_elts, idx, sizeof (*idx) + clen, - fake_rep); + memcpy(idx->request, cur_name, clen); + HASH_FIND(hh, resolver->fake_elts, idx, sizeof(*idx) + clen, + fake_rep); if (fake_rep) { /* We actually treat it as a short-circuit */ - req->reply = rdns_make_reply (req, fake_rep->rcode); + req->reply = rdns_make_reply(req, fake_rep->rcode); req->reply->entries = fake_rep->result; req->state = RDNS_REQUEST_FAKE; } @@ -1150,16 +1167,16 @@ rdns_make_request_full ( tlen += clen; } else if (last_name == NULL) { - rdns_err ("got NULL as the first name to resolve"); - rdns_request_free (req); + rdns_err("got NULL as the first name to resolve"); + rdns_request_free(req); return NULL; } if (req->state != RDNS_REQUEST_FAKE) { - if (!rdns_format_dns_name (resolver, last_name, clen, - &req->requested_names[cur].name, &olen)) { - rdns_err ("cannot format %s", last_name); - rdns_request_free (req); + if (!rdns_format_dns_name(resolver, last_name, clen, + &req->requested_names[cur].name, &olen)) { + rdns_err("cannot format %s", last_name); + rdns_request_free(req); return NULL; } @@ -1172,27 +1189,28 @@ rdns_make_request_full ( req->requested_names[cur].type = type; } - va_end (args); + va_end(args); if (req->state != RDNS_REQUEST_FAKE) { - rdns_allocate_packet (req, tlen); - rdns_make_dns_header (req, queries); + rdns_allocate_packet(req, tlen); + rdns_make_dns_header(req, queries); for (i = 0; i < queries; i++) { cur_name = req->requested_names[i].name; clen = req->requested_names[i].len; type = req->requested_names[i].type; if (queries > 1) { - if (!rdns_add_rr (req, cur_name, clen, type, &comp)) { - rdns_err ("cannot add rr"); - REF_RELEASE (req); + if (!rdns_add_rr(req, cur_name, clen, type, &comp)) { + rdns_err("cannot add rr"); + REF_RELEASE(req); rdns_compression_free(comp); return NULL; } - } else { - if (!rdns_add_rr (req, cur_name, clen, type, NULL)) { - rdns_err ("cannot add rr"); - REF_RELEASE (req); + } + else { + if (!rdns_add_rr(req, cur_name, clen, type, NULL)) { + rdns_err("cannot add rr"); + REF_RELEASE(req); rdns_compression_free(comp); return NULL; } @@ -1202,7 +1220,7 @@ rdns_make_request_full ( rdns_compression_free(comp); /* Add EDNS RR */ - rdns_add_edns0 (req); + rdns_add_edns0(req); req->retransmits = repeats ? repeats : 1; req->timeout = timeout; @@ -1211,59 +1229,59 @@ rdns_make_request_full ( req->async = resolver->async; - serv = rdns_select_request_upstream (resolver, req, false, NULL); + serv = rdns_select_request_upstream(resolver, req, false, NULL); if (serv == NULL) { - rdns_warn ("cannot find suitable server for request"); - REF_RELEASE (req); + rdns_warn("cannot find suitable server for request"); + REF_RELEASE(req); return NULL; } /* Select random IO channel */ - req->io = serv->io_channels[ottery_rand_uint32 () % serv->io_cnt]; + req->io = serv->io_channels[ottery_rand_uint32() % serv->io_cnt]; if (req->state == RDNS_REQUEST_FAKE) { - req->async_event = resolver->async->add_write (resolver->async->data, - req->io->sock, req); + req->async_event = resolver->async->add_write(resolver->async->data, + req->io->sock, req); } else { /* Now send request to server */ do { - r = rdns_send_request (req, req->io->sock, true); + r = rdns_send_request(req, req->io->sock, true); if (r == -1) { - req->retransmits --; /* It must be > 0 */ + req->retransmits--; /* It must be > 0 */ if (req->retransmits > 0) { if (resolver->ups && serv->ups_elt) { - resolver->ups->fail (serv->ups_elt, resolver->ups->data, - "send IO error"); + resolver->ups->fail(serv->ups_elt, resolver->ups->data, + "send IO error"); } else { - UPSTREAM_FAIL (serv, time (NULL)); + UPSTREAM_FAIL(serv, time(NULL)); } - serv = rdns_select_request_upstream (resolver, req, - true, serv); + serv = rdns_select_request_upstream(resolver, req, + true, serv); if (serv == NULL) { - rdns_warn ("cannot find suitable server for request"); - REF_RELEASE (req); + rdns_warn("cannot find suitable server for request"); + REF_RELEASE(req); return NULL; } - req->io = serv->io_channels[ottery_rand_uint32 () % serv->io_cnt]; + req->io = serv->io_channels[ottery_rand_uint32() % serv->io_cnt]; } else { - rdns_info ("cannot send DNS request: %s", strerror (errno)); - REF_RELEASE (req); + rdns_info("cannot send DNS request: %s", strerror(errno)); + REF_RELEASE(req); if (resolver->ups && serv->ups_elt) { - resolver->ups->fail (serv->ups_elt, resolver->ups->data, - "send IO error"); + resolver->ups->fail(serv->ups_elt, resolver->ups->data, + "send IO error"); } else { - UPSTREAM_FAIL (serv, time (NULL)); + UPSTREAM_FAIL(serv, time(NULL)); } return NULL; @@ -1277,43 +1295,43 @@ rdns_make_request_full ( } while (req->retransmits > 0); } - REF_RETAIN (req->io); - REF_RETAIN (req->resolver); + REF_RETAIN(req->io); + REF_RETAIN(req->resolver); return req; } -bool -rdns_resolver_init (struct rdns_resolver *resolver) +bool rdns_resolver_init(struct rdns_resolver *resolver) { unsigned int i; struct rdns_server *serv; struct rdns_io_channel *ioc; if (!resolver->async_binded) { - rdns_err ("no async backend specified"); + rdns_err("no async backend specified"); return false; } if (resolver->servers == NULL) { - rdns_err ("no DNS servers defined"); + rdns_err("no DNS servers defined"); return false; } /* Now init io channels to all servers */ - UPSTREAM_FOREACH (resolver->servers, serv) { - serv->io_channels = calloc (serv->io_cnt, sizeof (struct rdns_io_channel *)); + UPSTREAM_FOREACH(resolver->servers, serv) + { + serv->io_channels = calloc(serv->io_cnt, sizeof(struct rdns_io_channel *)); if (serv->io_channels == NULL) { - rdns_err ("cannot allocate memory for the resolver IO channels"); + rdns_err("cannot allocate memory for the resolver IO channels"); return false; } - for (i = 0; i < serv->io_cnt; i ++) { + for (i = 0; i < serv->io_cnt; i++) { ioc = rdns_ioc_new(serv, resolver, false); if (ioc == NULL) { - rdns_err ("cannot allocate memory or init the IO channel"); + rdns_err("cannot allocate memory or init the IO channel"); return false; } @@ -1326,16 +1344,16 @@ rdns_resolver_init (struct rdns_resolver *resolver) * We are more forgiving for TCP IO channels: we can have zero of them * if DNS is misconfigured and still be able to resolve stuff */ - serv->tcp_io_channels = calloc (serv->tcp_io_cnt, sizeof (struct rdns_io_channel *)); + serv->tcp_io_channels = calloc(serv->tcp_io_cnt, sizeof(struct rdns_io_channel *)); if (serv->tcp_io_channels == NULL) { - rdns_err ("cannot allocate memory for the resolver TCP IO channels"); + rdns_err("cannot allocate memory for the resolver TCP IO channels"); return false; } - for (i = 0; i < serv->tcp_io_cnt; i ++) { - ioc = rdns_ioc_new (serv, resolver, true); + for (i = 0; i < serv->tcp_io_cnt; i++) { + ioc = rdns_ioc_new(serv, resolver, true); if (ioc == NULL) { - rdns_err ("cannot allocate memory or init the TCP IO channel"); + rdns_err("cannot allocate memory or init the TCP IO channel"); continue; } @@ -1346,8 +1364,8 @@ rdns_resolver_init (struct rdns_resolver *resolver) } if (resolver->async->add_periodic) { - resolver->periodic = resolver->async->add_periodic (resolver->async->data, - UPSTREAM_REVIVE_TIME, rdns_process_periodic, resolver); + resolver->periodic = resolver->async->add_periodic(resolver->async->data, + UPSTREAM_REVIVE_TIME, rdns_process_periodic, resolver); } resolver->initialized = true; @@ -1355,9 +1373,8 @@ rdns_resolver_init (struct rdns_resolver *resolver) return true; } -void -rdns_resolver_register_plugin (struct rdns_resolver *resolver, - struct rdns_plugin *plugin) +void rdns_resolver_register_plugin(struct rdns_resolver *resolver, + struct rdns_plugin *plugin) { if (resolver != NULL && plugin != NULL) { /* XXX: support only network plugin now, and only a single one */ @@ -1368,9 +1385,9 @@ rdns_resolver_register_plugin (struct rdns_resolver *resolver, } void * -rdns_resolver_add_server (struct rdns_resolver *resolver, - const char *name, unsigned int port, - int priority, unsigned int io_cnt) +rdns_resolver_add_server(struct rdns_resolver *resolver, + const char *name, unsigned int port, + int priority, unsigned int io_cnt) { struct rdns_server *serv; union { @@ -1378,8 +1395,8 @@ rdns_resolver_add_server (struct rdns_resolver *resolver, struct in6_addr v6; } addr; - if (inet_pton (AF_INET, name, &addr) == 0 && - inet_pton (AF_INET6, name, &addr) == 0) { + if (inet_pton(AF_INET, name, &addr) == 0 && + inet_pton(AF_INET6, name, &addr) == 0) { /* Invalid IP */ return NULL; } @@ -1391,13 +1408,13 @@ rdns_resolver_add_server (struct rdns_resolver *resolver, return NULL; } - serv = calloc (1, sizeof (struct rdns_server)); + serv = calloc(1, sizeof(struct rdns_server)); if (serv == NULL) { return NULL; } - serv->name = strdup (name); + serv->name = strdup(name); if (serv->name == NULL) { - free (serv); + free(serv); return NULL; } @@ -1406,56 +1423,52 @@ rdns_resolver_add_server (struct rdns_resolver *resolver, serv->tcp_io_cnt = default_tcp_io_cnt; serv->port = port; - UPSTREAM_ADD (resolver->servers, serv, priority); + UPSTREAM_ADD(resolver->servers, serv, priority); return serv; } -void -rdns_resolver_set_logger (struct rdns_resolver *resolver, - rdns_log_function logger, void *log_data) +void rdns_resolver_set_logger(struct rdns_resolver *resolver, + rdns_log_function logger, void *log_data) { resolver->logger = logger; resolver->log_data = log_data; } -void -rdns_resolver_set_log_level (struct rdns_resolver *resolver, - enum rdns_log_level level) +void rdns_resolver_set_log_level(struct rdns_resolver *resolver, + enum rdns_log_level level) { resolver->log_level = level; } -void -rdns_resolver_set_upstream_lib (struct rdns_resolver *resolver, - struct rdns_upstream_context *ups_ctx, - void *ups_data) +void rdns_resolver_set_upstream_lib(struct rdns_resolver *resolver, + struct rdns_upstream_context *ups_ctx, + void *ups_data) { resolver->ups = ups_ctx; resolver->ups->data = ups_data; } -void -rdns_resolver_set_max_io_uses (struct rdns_resolver *resolver, - uint64_t max_ioc_uses, double check_time) +void rdns_resolver_set_max_io_uses(struct rdns_resolver *resolver, + uint64_t max_ioc_uses, double check_time) { if (resolver->refresh_ioc_periodic != NULL) { - resolver->async->del_periodic (resolver->async->data, - resolver->refresh_ioc_periodic); + resolver->async->del_periodic(resolver->async->data, + resolver->refresh_ioc_periodic); resolver->refresh_ioc_periodic = NULL; } resolver->max_ioc_uses = max_ioc_uses; if (check_time > 0.0 && resolver->async->add_periodic) { resolver->refresh_ioc_periodic = - resolver->async->add_periodic (resolver->async->data, - check_time, rdns_process_ioc_refresh, resolver); + resolver->async->add_periodic(resolver->async->data, + check_time, rdns_process_ioc_refresh, resolver); } } static void -rdns_resolver_free (struct rdns_resolver *resolver) +rdns_resolver_free(struct rdns_resolver *resolver) { struct rdns_server *serv, *stmp; struct rdns_io_channel *ioc; @@ -1463,45 +1476,46 @@ rdns_resolver_free (struct rdns_resolver *resolver) if (resolver->initialized) { if (resolver->periodic != NULL) { - resolver->async->del_periodic (resolver->async->data, resolver->periodic); + resolver->async->del_periodic(resolver->async->data, resolver->periodic); } if (resolver->refresh_ioc_periodic != NULL) { - resolver->async->del_periodic (resolver->async->data, - resolver->refresh_ioc_periodic); + resolver->async->del_periodic(resolver->async->data, + resolver->refresh_ioc_periodic); } if (resolver->curve_plugin != NULL && resolver->curve_plugin->dtor != NULL) { - resolver->curve_plugin->dtor (resolver, resolver->curve_plugin->data); + resolver->curve_plugin->dtor(resolver, resolver->curve_plugin->data); } /* Stop IO watch on all IO channels */ - UPSTREAM_FOREACH_SAFE (resolver->servers, serv, stmp) { - for (i = 0; i < serv->io_cnt; i ++) { + UPSTREAM_FOREACH_SAFE(resolver->servers, serv, stmp) + { + for (i = 0; i < serv->io_cnt; i++) { ioc = serv->io_channels[i]; - REF_RELEASE (ioc); + REF_RELEASE(ioc); } - for (i = 0; i < serv->tcp_io_cnt; i ++) { + for (i = 0; i < serv->tcp_io_cnt; i++) { ioc = serv->tcp_io_channels[i]; - REF_RELEASE (ioc); + REF_RELEASE(ioc); } - UPSTREAM_DEL (resolver->servers, serv); - free (serv->io_channels); - free (serv->tcp_io_channels); - free (serv->name); - free (serv); + UPSTREAM_DEL(resolver->servers, serv); + free(serv->io_channels); + free(serv->tcp_io_channels); + free(serv->name); + free(serv); } } - free (resolver->async); - free (resolver); + free(resolver->async); + free(resolver); } struct rdns_resolver * -rdns_resolver_new (int flags) +rdns_resolver_new(int flags) { - struct rdns_resolver *new_resolver; + struct rdns_resolver *new_resolver; - new_resolver = calloc (1, sizeof (struct rdns_resolver)); + new_resolver = calloc(1, sizeof(struct rdns_resolver)); - REF_INIT_RETAIN (new_resolver, rdns_resolver_free); + REF_INIT_RETAIN(new_resolver, rdns_resolver_free); new_resolver->logger = rdns_logger_internal; new_resolver->log_data = new_resolver; @@ -1510,9 +1524,8 @@ rdns_resolver_new (int flags) return new_resolver; } -void -rdns_resolver_async_bind (struct rdns_resolver *resolver, - struct rdns_async_context *ctx) +void rdns_resolver_async_bind(struct rdns_resolver *resolver, + struct rdns_async_context *ctx) { if (resolver != NULL && ctx != NULL) { resolver->async = ctx; @@ -1520,8 +1533,7 @@ rdns_resolver_async_bind (struct rdns_resolver *resolver, } } -void -rdns_resolver_set_dnssec (struct rdns_resolver *resolver, bool enabled) +void rdns_resolver_set_dnssec(struct rdns_resolver *resolver, bool enabled) { if (resolver) { resolver->enable_dnssec = enabled; @@ -1529,49 +1541,49 @@ rdns_resolver_set_dnssec (struct rdns_resolver *resolver, bool enabled) } -void rdns_resolver_set_fake_reply (struct rdns_resolver *resolver, - const char *name, - enum rdns_request_type type, - enum dns_rcode rcode, - struct rdns_reply_entry *reply) +void rdns_resolver_set_fake_reply(struct rdns_resolver *resolver, + const char *name, + enum rdns_request_type type, + enum dns_rcode rcode, + struct rdns_reply_entry *reply) { struct rdns_fake_reply *fake_rep; struct rdns_fake_reply_idx *srch; - unsigned len = strlen (name); + unsigned len = strlen(name); - assert (len < MAX_FAKE_NAME); - srch = malloc (sizeof (*srch) + len); + assert(len < MAX_FAKE_NAME); + srch = malloc(sizeof(*srch) + len); srch->len = len; srch->type = type; - memcpy (srch->request, name, len); + memcpy(srch->request, name, len); - HASH_FIND (hh, resolver->fake_elts, srch, len + sizeof (*srch), fake_rep); + HASH_FIND(hh, resolver->fake_elts, srch, len + sizeof(*srch), fake_rep); if (fake_rep) { /* Append reply to the existing list */ fake_rep->rcode = rcode; if (reply) { - DL_CONCAT (fake_rep->result, reply); + DL_CONCAT(fake_rep->result, reply); } } else { - fake_rep = calloc (1, sizeof (*fake_rep) + len); + fake_rep = calloc(1, sizeof(*fake_rep) + len); if (fake_rep == NULL) { - abort (); + abort(); } fake_rep->rcode = rcode; - memcpy (&fake_rep->key, srch, sizeof (*srch) + len); + memcpy(&fake_rep->key, srch, sizeof(*srch) + len); if (reply) { - DL_CONCAT (fake_rep->result, reply); + DL_CONCAT(fake_rep->result, reply); } - HASH_ADD (hh, resolver->fake_elts, key, sizeof (*srch) + len, fake_rep); + HASH_ADD(hh, resolver->fake_elts, key, sizeof(*srch) + len, fake_rep); } - free (srch); + free(srch); } diff --git a/contrib/libucl/lua_ucl.c b/contrib/libucl/lua_ucl.c index c2e39c462..a9edb3e4d 100644 --- a/contrib/libucl/lua_ucl.c +++ b/contrib/libucl/lua_ucl.c @@ -74,11 +74,11 @@ func = "huh"; #define UCL_ARRAY_TYPE_META "ucl.type.array" #define UCL_IMPL_ARRAY_TYPE_META "ucl.type.impl_array" -static int ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj, int flags); -static int ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj, int flags); -static int ucl_object_push_lua_common (lua_State *L, const ucl_object_t *obj, int flags); -static ucl_object_t* ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags); -static ucl_object_t* ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags); +static int ucl_object_lua_push_array(lua_State *L, const ucl_object_t *obj, int flags); +static int ucl_object_lua_push_scalar(lua_State *L, const ucl_object_t *obj, int flags); +static int ucl_object_push_lua_common(lua_State *L, const ucl_object_t *obj, int flags); +static ucl_object_t *ucl_object_lua_fromtable(lua_State *L, int idx, ucl_string_flags_t flags); +static ucl_object_t *ucl_object_lua_fromelt(lua_State *L, int idx, ucl_string_flags_t flags); static void *ucl_null; @@ -101,46 +101,46 @@ enum lua_ucl_push_flags { * @param obj */ static void -ucl_object_lua_push_element (lua_State *L, const char *key, - const ucl_object_t *obj, int flags) +ucl_object_lua_push_element(lua_State *L, const char *key, + const ucl_object_t *obj, int flags) { - lua_pushstring (L, key); - ucl_object_push_lua_common (L, obj, flags|LUA_UCL_ALLOW_ARRAY); - lua_settable (L, -3); + lua_pushstring(L, key); + ucl_object_push_lua_common(L, obj, flags | LUA_UCL_ALLOW_ARRAY); + lua_settable(L, -3); } static void -lua_ucl_userdata_dtor (void *ud) +lua_ucl_userdata_dtor(void *ud) { - struct ucl_lua_funcdata *fd = (struct ucl_lua_funcdata *)ud; + struct ucl_lua_funcdata *fd = (struct ucl_lua_funcdata *) ud; - luaL_unref (fd->L, LUA_REGISTRYINDEX, fd->idx); + luaL_unref(fd->L, LUA_REGISTRYINDEX, fd->idx); if (fd->ret != NULL) { - free (fd->ret); + free(fd->ret); } - free (fd); + free(fd); } static const char * -lua_ucl_userdata_emitter (void *ud) +lua_ucl_userdata_emitter(void *ud) { - struct ucl_lua_funcdata *fd = (struct ucl_lua_funcdata *)ud; + struct ucl_lua_funcdata *fd = (struct ucl_lua_funcdata *) ud; const char *out = ""; - lua_rawgeti (fd->L, LUA_REGISTRYINDEX, fd->idx); + lua_rawgeti(fd->L, LUA_REGISTRYINDEX, fd->idx); - lua_pcall (fd->L, 0, 1, 0); - out = lua_tostring (fd->L, -1); + lua_pcall(fd->L, 0, 1, 0); + out = lua_tostring(fd->L, -1); if (out != NULL) { /* We need to store temporary string in a more appropriate place */ if (fd->ret) { - free (fd->ret); + free(fd->ret); } - fd->ret = strdup (out); + fd->ret = strdup(out); } - lua_settop (fd->L, 0); + lua_settop(fd->L, 0); return fd->ret; } @@ -152,26 +152,26 @@ lua_ucl_userdata_emitter (void *ud) * @return */ static int -ucl_object_lua_push_object (lua_State *L, const ucl_object_t *obj, - int flags) +ucl_object_lua_push_object(lua_State *L, const ucl_object_t *obj, + int flags) { const ucl_object_t *cur; ucl_object_iter_t it = NULL; if ((flags & LUA_UCL_ALLOW_ARRAY) && obj->next != NULL) { /* Actually we need to push this as an array */ - return ucl_object_lua_push_array (L, obj, flags); + return ucl_object_lua_push_array(L, obj, flags); } - lua_createtable (L, 0, obj->len); + lua_createtable(L, 0, obj->len); it = NULL; - while ((cur = ucl_object_iterate (obj, &it, true)) != NULL) { - ucl_object_lua_push_element (L, ucl_object_key (cur), cur, flags); + while ((cur = ucl_object_iterate(obj, &it, true)) != NULL) { + ucl_object_lua_push_element(L, ucl_object_key(cur), cur, flags); } - luaL_getmetatable (L, UCL_OBJECT_TYPE_META); - lua_setmetatable (L, -2); + luaL_getmetatable(L, UCL_OBJECT_TYPE_META); + lua_setmetatable(L, -2); return 1; } @@ -183,7 +183,7 @@ ucl_object_lua_push_object (lua_State *L, const ucl_object_t *obj, * @return */ static int -ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj, int flags) +ucl_object_lua_push_array(lua_State *L, const ucl_object_t *obj, int flags) { const ucl_object_t *cur; ucl_object_iter_t it; @@ -191,36 +191,38 @@ ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj, int flags) if (obj->type == UCL_ARRAY) { nelt = obj->len; - it = ucl_object_iterate_new (obj); - lua_createtable (L, nelt, 0); + it = ucl_object_iterate_new(obj); + lua_createtable(L, nelt, 0); - while ((cur = ucl_object_iterate_safe (it, true))) { - ucl_object_push_lua (L, cur, (flags & ~LUA_UCL_ALLOW_ARRAY)); - lua_rawseti (L, -2, i); - i ++; + while ((cur = ucl_object_iterate_safe(it, true))) { + ucl_object_push_lua(L, cur, (flags & ~LUA_UCL_ALLOW_ARRAY)); + lua_rawseti(L, -2, i); + i++; } - luaL_getmetatable (L, UCL_ARRAY_TYPE_META); - lua_setmetatable (L, -2); + luaL_getmetatable(L, UCL_ARRAY_TYPE_META); + lua_setmetatable(L, -2); - ucl_object_iterate_free (it); + ucl_object_iterate_free(it); } else { /* Optimize allocation by preallocation of table */ - LL_FOREACH (obj, cur) { - nelt ++; + LL_FOREACH(obj, cur) + { + nelt++; } - lua_createtable (L, nelt, 0); + lua_createtable(L, nelt, 0); - LL_FOREACH (obj, cur) { - ucl_object_push_lua (L, cur, (flags & ~LUA_UCL_ALLOW_ARRAY)); - lua_rawseti (L, -2, i); - i ++; + LL_FOREACH(obj, cur) + { + ucl_object_push_lua(L, cur, (flags & ~LUA_UCL_ALLOW_ARRAY)); + lua_rawseti(L, -2, i); + i++; } - luaL_getmetatable (L, UCL_IMPL_ARRAY_TYPE_META); - lua_setmetatable (L, -2); + luaL_getmetatable(L, UCL_IMPL_ARRAY_TYPE_META); + lua_setmetatable(L, -2); } return 1; @@ -230,48 +232,48 @@ ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj, int flags) * Push a simple object to lua depending on its actual type */ static int -ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj, - int flags) +ucl_object_lua_push_scalar(lua_State *L, const ucl_object_t *obj, + int flags) { struct ucl_lua_funcdata *fd; if ((flags & LUA_UCL_ALLOW_ARRAY) && obj->next != NULL) { /* Actually we need to push this as an array */ - return ucl_object_lua_push_array (L, obj, flags); + return ucl_object_lua_push_array(L, obj, flags); } switch (obj->type) { case UCL_BOOLEAN: - lua_pushboolean (L, ucl_obj_toboolean (obj)); + lua_pushboolean(L, ucl_obj_toboolean(obj)); break; case UCL_STRING: - lua_pushlstring (L, ucl_obj_tostring (obj), obj->len); + lua_pushlstring(L, ucl_obj_tostring(obj), obj->len); break; case UCL_INT: #if LUA_VERSION_NUM >= 501 - lua_pushinteger (L, ucl_obj_toint (obj)); + lua_pushinteger(L, ucl_obj_toint(obj)); #else - lua_pushnumber (L, ucl_obj_toint (obj)); + lua_pushnumber(L, ucl_obj_toint(obj)); #endif break; case UCL_FLOAT: case UCL_TIME: - lua_pushnumber (L, ucl_obj_todouble (obj)); + lua_pushnumber(L, ucl_obj_todouble(obj)); break; case UCL_NULL: if (flags & LUA_UCL_CONVERT_NIL) { - lua_pushboolean (L, false); + lua_pushboolean(L, false); } else { - lua_getfield (L, LUA_REGISTRYINDEX, "ucl.null"); + lua_getfield(L, LUA_REGISTRYINDEX, "ucl.null"); } break; case UCL_USERDATA: - fd = (struct ucl_lua_funcdata *)obj->value.ud; - lua_rawgeti (L, LUA_REGISTRYINDEX, fd->idx); + fd = (struct ucl_lua_funcdata *) obj->value.ud; + lua_rawgeti(L, LUA_REGISTRYINDEX, fd->idx); break; default: - lua_pushnil (L); + lua_pushnil(L); break; } @@ -279,15 +281,15 @@ ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj, } static int -ucl_object_push_lua_common (lua_State *L, const ucl_object_t *obj, int flags) +ucl_object_push_lua_common(lua_State *L, const ucl_object_t *obj, int flags) { switch (obj->type) { case UCL_OBJECT: - return ucl_object_lua_push_object (L, obj, flags); + return ucl_object_lua_push_object(L, obj, flags); case UCL_ARRAY: - return ucl_object_lua_push_array (L, obj, flags); + return ucl_object_lua_push_array(L, obj, flags); default: - return ucl_object_lua_push_scalar (L, obj, flags); + return ucl_object_lua_push_scalar(L, obj, flags); } } @@ -306,19 +308,16 @@ ucl_object_push_lua_common (lua_State *L, const ucl_object_t *obj, int flags) * @param {bool} allow_array expand implicit arrays (should be true for all but partial arrays) * @return {int} `1` if an object is pushed to lua */ -int -ucl_object_push_lua (lua_State *L, const ucl_object_t *obj, bool allow_array) +int ucl_object_push_lua(lua_State *L, const ucl_object_t *obj, bool allow_array) { - return ucl_object_push_lua_common (L, obj, - allow_array ? LUA_UCL_ALLOW_ARRAY : LUA_UCL_DEFAULT_FLAGS); + return ucl_object_push_lua_common(L, obj, + allow_array ? LUA_UCL_ALLOW_ARRAY : LUA_UCL_DEFAULT_FLAGS); } -int -ucl_object_push_lua_filter_nil (lua_State *L, const ucl_object_t *obj, bool allow_array) +int ucl_object_push_lua_filter_nil(lua_State *L, const ucl_object_t *obj, bool allow_array) { - return ucl_object_push_lua_common (L, obj, - allow_array ? (LUA_UCL_ALLOW_ARRAY|LUA_UCL_CONVERT_NIL) : - (LUA_UCL_DEFAULT_FLAGS|LUA_UCL_CONVERT_NIL)); + return ucl_object_push_lua_common(L, obj, + allow_array ? (LUA_UCL_ALLOW_ARRAY | LUA_UCL_CONVERT_NIL) : (LUA_UCL_DEFAULT_FLAGS | LUA_UCL_CONVERT_NIL)); } /** @@ -328,7 +327,7 @@ ucl_object_push_lua_filter_nil (lua_State *L, const ucl_object_t *obj, bool allo * @param idx */ static ucl_object_t * -ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags) +ucl_object_lua_fromtable(lua_State *L, int idx, ucl_string_flags_t flags) { ucl_object_t *obj, *top = NULL, *cur; size_t keylen; @@ -338,52 +337,54 @@ ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags) if (idx < 0) { /* For negative indicies we want to invert them */ - idx = lua_gettop (L) + idx + 1; + idx = lua_gettop(L) + idx + 1; } /* First, we check from metatable */ - if (luaL_getmetafield (L, idx, "class") != 0) { + if (luaL_getmetafield(L, idx, "class") != 0) { - if (lua_type (L, -1) == LUA_TSTRING) { - const char *classname = lua_tostring (L, -1); + if (lua_type(L, -1) == LUA_TSTRING) { + const char *classname = lua_tostring(L, -1); - if (strcmp (classname, UCL_OBJECT_TYPE_META) == 0) { + if (strcmp(classname, UCL_OBJECT_TYPE_META) == 0) { is_array = false; found_mt = true; - } else if (strcmp (classname, UCL_ARRAY_TYPE_META) == 0) { + } + else if (strcmp(classname, UCL_ARRAY_TYPE_META) == 0) { is_array = true; found_mt = true; #if LUA_VERSION_NUM >= 502 - max = lua_rawlen (L, idx); + max = lua_rawlen(L, idx); #else - max = lua_objlen (L, idx); + max = lua_objlen(L, idx); #endif nelts = max; - } else if (strcmp (classname, UCL_IMPL_ARRAY_TYPE_META) == 0) { + } + else if (strcmp(classname, UCL_IMPL_ARRAY_TYPE_META) == 0) { is_array = true; is_implicit = true; found_mt = true; #if LUA_VERSION_NUM >= 502 - max = lua_rawlen (L, idx); + max = lua_rawlen(L, idx); #else - max = lua_objlen (L, idx); + max = lua_objlen(L, idx); #endif nelts = max; } } - lua_pop (L, 1); + lua_pop(L, 1); } if (!found_mt) { /* Check for array (it is all inefficient) */ - lua_pushnil (L); + lua_pushnil(L); - while (lua_next (L, idx) != 0) { - lua_pushvalue (L, -2); + while (lua_next(L, idx) != 0) { + lua_pushvalue(L, -2); - if (lua_type (L, -1) == LUA_TNUMBER) { - double num = lua_tonumber (L, -1); + if (lua_type(L, -1) == LUA_TNUMBER) { + double num = lua_tonumber(L, -1); if (num == (int) num) { if (num > max) { max = num; @@ -399,8 +400,8 @@ ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags) is_array = false; } - lua_pop (L, 2); - nelts ++; + lua_pop(L, 2); + nelts++; } } @@ -409,52 +410,53 @@ ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags) int i; if (!is_implicit) { - top = ucl_object_typed_new (UCL_ARRAY); - ucl_object_reserve (top, nelts); + top = ucl_object_typed_new(UCL_ARRAY); + ucl_object_reserve(top, nelts); } else { top = NULL; } - for (i = 1; i <= max; i ++) { - lua_pushinteger (L, i); - lua_gettable (L, idx); + for (i = 1; i <= max; i++) { + lua_pushinteger(L, i); + lua_gettable(L, idx); - obj = ucl_object_lua_fromelt (L, lua_gettop (L), flags); + obj = ucl_object_lua_fromelt(L, lua_gettop(L), flags); if (obj != NULL) { if (is_implicit) { - DL_APPEND (top, obj); + DL_APPEND(top, obj); } else { - ucl_array_append (top, obj); + ucl_array_append(top, obj); } } - lua_pop (L, 1); + lua_pop(L, 1); } } else { - lua_pushnil (L); - top = ucl_object_typed_new (UCL_OBJECT); - ucl_object_reserve (top, nelts); + lua_pushnil(L); + top = ucl_object_typed_new(UCL_OBJECT); + ucl_object_reserve(top, nelts); - while (lua_next (L, idx) != 0) { + while (lua_next(L, idx) != 0) { /* copy key to avoid modifications */ - lua_pushvalue (L, -2); - k = lua_tolstring (L, -1, &keylen); - obj = ucl_object_lua_fromelt (L, lua_gettop (L) - 1, flags); + lua_pushvalue(L, -2); + k = lua_tolstring(L, -1, &keylen); + obj = ucl_object_lua_fromelt(L, lua_gettop(L) - 1, flags); if (obj != NULL) { - ucl_object_insert_key (top, obj, k, keylen, true); + ucl_object_insert_key(top, obj, k, keylen, true); - DL_FOREACH (obj, cur) { + DL_FOREACH(obj, cur) + { if (cur->keylen == 0) { cur->keylen = obj->keylen; cur->key = obj->key; } } } - lua_pop (L, 2); + lua_pop(L, 2); } } @@ -468,7 +470,7 @@ ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags) * @param idx */ static ucl_object_t * -ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags) +ucl_object_lua_fromelt(lua_State *L, int idx, ucl_string_flags_t flags) { int type; double num; @@ -477,11 +479,11 @@ ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags) const char *str; size_t sz; - type = lua_type (L, idx); + type = lua_type(L, idx); switch (type) { case LUA_TSTRING: - str = lua_tolstring (L, idx, &sz); + str = lua_tolstring(L, idx, &sz); if (str) { /* @@ -496,31 +498,31 @@ ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags) } } else { - obj = ucl_object_typed_new (UCL_NULL); + obj = ucl_object_typed_new(UCL_NULL); } break; case LUA_TNUMBER: - num = lua_tonumber (L, idx); - if (num == (int64_t)num) { - obj = ucl_object_fromint (num); + num = lua_tonumber(L, idx); + if (num == (int64_t) num) { + obj = ucl_object_fromint(num); } else { - obj = ucl_object_fromdouble (num); + obj = ucl_object_fromdouble(num); } break; case LUA_TBOOLEAN: - obj = ucl_object_frombool (lua_toboolean (L, idx)); + obj = ucl_object_frombool(lua_toboolean(L, idx)); break; case LUA_TUSERDATA: - if (lua_topointer (L, idx) == ucl_null) { - obj = ucl_object_typed_new (UCL_NULL); + if (lua_topointer(L, idx) == ucl_null) { + obj = ucl_object_typed_new(UCL_NULL); } else { /* Assume it is a text like object */ - struct _rspamd_lua_text *t = lua_touserdata (L, idx); + struct _rspamd_lua_text *t = lua_touserdata(L, idx); if (t) { - if (t->len >0) { + if (t->len > 0) { obj = ucl_object_fromstring_common(t->start, t->len, 0); } else { @@ -537,30 +539,30 @@ ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags) case LUA_TTABLE: case LUA_TFUNCTION: case LUA_TTHREAD: - if (luaL_getmetafield (L, idx, "__gen_ucl")) { - if (lua_isfunction (L, -1)) { - lua_settop (L, 3); /* gen, obj, func */ - lua_insert (L, 1); /* func, gen, obj */ - lua_insert (L, 2); /* func, obj, gen */ + if (luaL_getmetafield(L, idx, "__gen_ucl")) { + if (lua_isfunction(L, -1)) { + lua_settop(L, 3); /* gen, obj, func */ + lua_insert(L, 1); /* func, gen, obj */ + lua_insert(L, 2); /* func, obj, gen */ lua_call(L, 2, 1); - obj = ucl_object_lua_fromelt (L, 1, flags); + obj = ucl_object_lua_fromelt(L, 1, flags); } - lua_pop (L, 2); + lua_pop(L, 2); } else { if (type == LUA_TTABLE) { - obj = ucl_object_lua_fromtable (L, idx, flags); + obj = ucl_object_lua_fromtable(L, idx, flags); } else if (type == LUA_TFUNCTION) { - fd = malloc (sizeof (*fd)); + fd = malloc(sizeof(*fd)); if (fd != NULL) { - lua_pushvalue (L, idx); + lua_pushvalue(L, idx); fd->L = L; fd->ret = NULL; - fd->idx = luaL_ref (L, LUA_REGISTRYINDEX); + fd->idx = luaL_ref(L, LUA_REGISTRYINDEX); - obj = ucl_object_new_userdata (lua_ucl_userdata_dtor, - lua_ucl_userdata_emitter, (void *)fd); + obj = ucl_object_new_userdata(lua_ucl_userdata_dtor, + lua_ucl_userdata_emitter, (void *) fd); } } } @@ -580,18 +582,18 @@ ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags) * this object thus needs to be unref'ed after usage. */ ucl_object_t * -ucl_object_lua_import (lua_State *L, int idx) +ucl_object_lua_import(lua_State *L, int idx) { ucl_object_t *obj; int t; - t = lua_type (L, idx); + t = lua_type(L, idx); switch (t) { case LUA_TTABLE: - obj = ucl_object_lua_fromtable (L, idx, UCL_STRING_RAW); + obj = ucl_object_lua_fromtable(L, idx, UCL_STRING_RAW); break; default: - obj = ucl_object_lua_fromelt (L, idx, UCL_STRING_RAW); + obj = ucl_object_lua_fromelt(L, idx, UCL_STRING_RAW); break; } @@ -608,18 +610,18 @@ ucl_object_lua_import (lua_State *L, int idx) * this object thus needs to be unref'ed after usage. */ ucl_object_t * -ucl_object_lua_import_escape (lua_State *L, int idx) +ucl_object_lua_import_escape(lua_State *L, int idx) { ucl_object_t *obj; int t; - t = lua_type (L, idx); + t = lua_type(L, idx); switch (t) { case LUA_TTABLE: - obj = ucl_object_lua_fromtable (L, idx, UCL_STRING_ESCAPE); + obj = ucl_object_lua_fromtable(L, idx, UCL_STRING_ESCAPE); break; default: - obj = ucl_object_lua_fromelt (L, idx, UCL_STRING_ESCAPE); + obj = ucl_object_lua_fromelt(L, idx, UCL_STRING_ESCAPE); break; } @@ -627,84 +629,84 @@ ucl_object_lua_import_escape (lua_State *L, int idx) } static int -lua_ucl_to_string (lua_State *L, const ucl_object_t *obj, enum ucl_emitter type) +lua_ucl_to_string(lua_State *L, const ucl_object_t *obj, enum ucl_emitter type) { unsigned char *result; size_t outlen; - result = ucl_object_emit_len (obj, type, &outlen); + result = ucl_object_emit_len(obj, type, &outlen); if (result != NULL) { - lua_pushlstring (L, (const char *)result, outlen); - free (result); + lua_pushlstring(L, (const char *) result, outlen); + free(result); } else { - lua_pushnil (L); + lua_pushnil(L); } return 1; } static int -lua_ucl_parser_init (lua_State *L) +lua_ucl_parser_init(lua_State *L) { struct ucl_parser *parser, **pparser; int flags = UCL_PARSER_NO_FILEVARS; - if (lua_gettop (L) >= 1) { - flags = lua_tonumber (L, 1); + if (lua_gettop(L) >= 1) { + flags = lua_tonumber(L, 1); } - parser = ucl_parser_new (flags); + parser = ucl_parser_new(flags); if (parser == NULL) { - lua_pushnil (L); + lua_pushnil(L); } - pparser = lua_newuserdata (L, sizeof (parser)); + pparser = lua_newuserdata(L, sizeof(parser)); *pparser = parser; - luaL_getmetatable (L, PARSER_META); - lua_setmetatable (L, -2); + luaL_getmetatable(L, PARSER_META); + lua_setmetatable(L, -2); return 1; } static struct ucl_parser * -lua_ucl_parser_get (lua_State *L, int index) +lua_ucl_parser_get(lua_State *L, int index) { return *((struct ucl_parser **) luaL_checkudata(L, index, PARSER_META)); } static ucl_object_t * -lua_ucl_object_get (lua_State *L, int index) +lua_ucl_object_get(lua_State *L, int index) { return *((ucl_object_t **) luaL_checkudata(L, index, OBJECT_META)); } static void -lua_ucl_push_opaque (lua_State *L, ucl_object_t *obj) +lua_ucl_push_opaque(lua_State *L, ucl_object_t *obj) { ucl_object_t **pobj; - pobj = lua_newuserdata (L, sizeof (*pobj)); + pobj = lua_newuserdata(L, sizeof(*pobj)); *pobj = obj; - luaL_getmetatable (L, OBJECT_META); - lua_setmetatable (L, -2); + luaL_getmetatable(L, OBJECT_META); + lua_setmetatable(L, -2); } static inline enum ucl_parse_type -lua_ucl_str_to_parse_type (const char *str) +lua_ucl_str_to_parse_type(const char *str) { enum ucl_parse_type type = UCL_PARSE_UCL; if (str != NULL) { - if (strcasecmp (str, "msgpack") == 0) { + if (strcasecmp(str, "msgpack") == 0) { type = UCL_PARSE_MSGPACK; } - else if (strcasecmp (str, "sexp") == 0 || - strcasecmp (str, "csexp") == 0) { + else if (strcasecmp(str, "sexp") == 0 || + strcasecmp(str, "csexp") == 0) { type = UCL_PARSE_CSEXP; } - else if (strcasecmp (str, "auto") == 0) { + else if (strcasecmp(str, "auto") == 0) { type = UCL_PARSE_AUTO; } } @@ -728,28 +730,28 @@ else end */ static int -lua_ucl_parser_parse_file (lua_State *L) +lua_ucl_parser_parse_file(lua_State *L) { struct ucl_parser *parser; const char *file; int ret = 2; - parser = lua_ucl_parser_get (L, 1); - file = luaL_checkstring (L, 2); + parser = lua_ucl_parser_get(L, 1); + file = luaL_checkstring(L, 2); if (parser != NULL && file != NULL) { - if (ucl_parser_add_file (parser, file)) { - lua_pushboolean (L, true); + if (ucl_parser_add_file(parser, file)) { + lua_pushboolean(L, true); ret = 1; } else { - lua_pushboolean (L, false); - lua_pushstring (L, ucl_parser_get_error (parser)); + lua_pushboolean(L, false); + lua_pushstring(L, ucl_parser_get_error(parser)); } } else { - lua_pushboolean (L, false); - lua_pushstring (L, "invalid arguments"); + lua_pushboolean(L, false); + lua_pushstring(L, "invalid arguments"); } return ret; @@ -766,23 +768,23 @@ local parser = ucl.parser() local res = parser:register_variable('CONFDIR', '/etc/foo') */ static int -lua_ucl_parser_register_variable (lua_State *L) +lua_ucl_parser_register_variable(lua_State *L) { struct ucl_parser *parser; const char *name, *value; int ret = 2; - parser = lua_ucl_parser_get (L, 1); - name = luaL_checkstring (L, 2); - value = luaL_checkstring (L, 3); + parser = lua_ucl_parser_get(L, 1); + name = luaL_checkstring(L, 2); + value = luaL_checkstring(L, 3); if (parser != NULL && name != NULL && value != NULL) { - ucl_parser_register_variable (parser, name, value); - lua_pushboolean (L, true); + ucl_parser_register_variable(parser, name, value); + lua_pushboolean(L, true); ret = 1; } else { - return luaL_error (L, "invalid arguments"); + return luaL_error(L, "invalid arguments"); } return ret; @@ -798,28 +800,28 @@ local parser = ucl.parser() local res = parser:register_variables({CONFDIR = '/etc/foo', VARDIR = '/var'}) */ static int -lua_ucl_parser_register_variables (lua_State *L) +lua_ucl_parser_register_variables(lua_State *L) { struct ucl_parser *parser; const char *name, *value; int ret = 2; - parser = lua_ucl_parser_get (L, 1); + parser = lua_ucl_parser_get(L, 1); - if (parser != NULL && lua_type (L, 2) == LUA_TTABLE) { - for (lua_pushnil (L); lua_next (L, 2); lua_pop (L, 1)) { - lua_pushvalue (L, -2); - name = luaL_checkstring (L, -1); - value = luaL_checkstring (L, -2); - ucl_parser_register_variable (parser, name, value); - lua_pop (L, 1); + if (parser != NULL && lua_type(L, 2) == LUA_TTABLE) { + for (lua_pushnil(L); lua_next(L, 2); lua_pop(L, 1)) { + lua_pushvalue(L, -2); + name = luaL_checkstring(L, -1); + value = luaL_checkstring(L, -2); + ucl_parser_register_variable(parser, name, value); + lua_pop(L, 1); } - lua_pushboolean (L, true); + lua_pushboolean(L, true); ret = 1; } else { - return luaL_error (L, "invalid arguments"); + return luaL_error(L, "invalid arguments"); } return ret; @@ -832,7 +834,7 @@ lua_ucl_parser_register_variables (lua_State *L) * @return {bool[, string]} if res is `true` then file has been parsed successfully, otherwise an error string is also returned */ static int -lua_ucl_parser_parse_string (lua_State *L) +lua_ucl_parser_parse_string(lua_State *L) { struct ucl_parser *parser; const char *string; @@ -840,27 +842,27 @@ lua_ucl_parser_parse_string (lua_State *L) enum ucl_parse_type type = UCL_PARSE_UCL; int ret = 2; - parser = lua_ucl_parser_get (L, 1); - string = luaL_checklstring (L, 2, &llen); + parser = lua_ucl_parser_get(L, 1); + string = luaL_checklstring(L, 2, &llen); - if (lua_type (L, 3) == LUA_TSTRING) { - type = lua_ucl_str_to_parse_type (lua_tostring (L, 3)); + if (lua_type(L, 3) == LUA_TSTRING) { + type = lua_ucl_str_to_parse_type(lua_tostring(L, 3)); } if (parser != NULL && string != NULL) { - if (ucl_parser_add_chunk_full (parser, (const unsigned char *)string, - llen, 0, UCL_DUPLICATE_APPEND, type)) { - lua_pushboolean (L, true); + if (ucl_parser_add_chunk_full(parser, (const unsigned char *) string, + llen, 0, UCL_DUPLICATE_APPEND, type)) { + lua_pushboolean(L, true); ret = 1; } else { - lua_pushboolean (L, false); - lua_pushstring (L, ucl_parser_get_error (parser)); + lua_pushboolean(L, false); + lua_pushstring(L, ucl_parser_get_error(parser)); } } else { - lua_pushboolean (L, false); - lua_pushstring (L, "invalid arguments"); + lua_pushboolean(L, false); + lua_pushstring(L, "invalid arguments"); } return ret; @@ -873,24 +875,24 @@ lua_ucl_parser_parse_string (lua_State *L) * @return {bool[, string]} if res is `true` then file has been parsed successfully, otherwise an error string is also returned */ static int -lua_ucl_parser_parse_text (lua_State *L) +lua_ucl_parser_parse_text(lua_State *L) { struct ucl_parser *parser; struct _rspamd_lua_text *t; enum ucl_parse_type type = UCL_PARSE_UCL; int ret = 2; - parser = lua_ucl_parser_get (L, 1); + parser = lua_ucl_parser_get(L, 1); - if (lua_type (L, 2) == LUA_TUSERDATA) { - t = lua_touserdata (L, 2); + if (lua_type(L, 2) == LUA_TUSERDATA) { + t = lua_touserdata(L, 2); } - else if (lua_type (L, 2) == LUA_TSTRING) { - const gchar *s; + else if (lua_type(L, 2) == LUA_TSTRING) { + const char *s; gsize len; static struct _rspamd_lua_text st_t; - s = lua_tolstring (L, 2, &len); + s = lua_tolstring(L, 2, &len); st_t.start = s; st_t.len = len; @@ -900,24 +902,24 @@ lua_ucl_parser_parse_text (lua_State *L) return luaL_error(L, "invalid argument as input, expected userdata or a string"); } - if (lua_type (L, 3) == LUA_TSTRING) { - type = lua_ucl_str_to_parse_type (lua_tostring (L, 3)); + if (lua_type(L, 3) == LUA_TSTRING) { + type = lua_ucl_str_to_parse_type(lua_tostring(L, 3)); } if (parser != NULL && t != NULL) { - if (ucl_parser_add_chunk_full (parser, (const unsigned char *)t->start, - t->len, 0, UCL_DUPLICATE_APPEND, type)) { - lua_pushboolean (L, true); + if (ucl_parser_add_chunk_full(parser, (const unsigned char *) t->start, + t->len, 0, UCL_DUPLICATE_APPEND, type)) { + lua_pushboolean(L, true); ret = 1; } else { - lua_pushboolean (L, false); - lua_pushstring (L, ucl_parser_get_error (parser)); + lua_pushboolean(L, false); + lua_pushstring(L, ucl_parser_get_error(parser)); } } else { - lua_pushboolean (L, false); - lua_pushstring (L, "invalid arguments"); + lua_pushboolean(L, false); + lua_pushstring(L, "invalid arguments"); } return ret; @@ -929,22 +931,22 @@ lua_ucl_parser_parse_text (lua_State *L) * @return {variant or nil} ucl object as lua native variable */ static int -lua_ucl_parser_get_object (lua_State *L) +lua_ucl_parser_get_object(lua_State *L) { struct ucl_parser *parser; ucl_object_t *obj; int ret = 1; - parser = lua_ucl_parser_get (L, 1); - obj = ucl_parser_get_object (parser); + parser = lua_ucl_parser_get(L, 1); + obj = ucl_parser_get_object(parser); if (obj != NULL) { - ret = ucl_object_push_lua (L, obj, false); + ret = ucl_object_push_lua(L, obj, false); /* no need to keep reference */ - ucl_object_unref (obj); + ucl_object_unref(obj); } else { - lua_pushnil (L); + lua_pushnil(L); } return ret; @@ -957,20 +959,20 @@ lua_ucl_parser_get_object (lua_State *L) * @return {ucl.object or nil} ucl object wrapped variable */ static int -lua_ucl_parser_get_object_wrapped (lua_State *L) +lua_ucl_parser_get_object_wrapped(lua_State *L) { struct ucl_parser *parser; ucl_object_t *obj; int ret = 1; - parser = lua_ucl_parser_get (L, 1); - obj = ucl_parser_get_object (parser); + parser = lua_ucl_parser_get(L, 1); + obj = ucl_parser_get_object(parser); if (obj != NULL) { - lua_ucl_push_opaque (L, obj); + lua_ucl_push_opaque(L, obj); } else { - lua_pushnil (L); + lua_pushnil(L); } return ret; @@ -986,76 +988,78 @@ lua_ucl_parser_get_object_wrapped (lua_State *L) * */ static int -lua_ucl_parser_validate (lua_State *L) +lua_ucl_parser_validate(lua_State *L) { struct ucl_parser *parser, *schema_parser; ucl_object_t *schema; const char *schema_file; struct ucl_schema_error err; - parser = lua_ucl_parser_get (L, 1); + parser = lua_ucl_parser_get(L, 1); if (parser && parser->top_obj) { - if (lua_type (L, 2) == LUA_TTABLE) { - schema = ucl_object_lua_import (L, 2); + if (lua_type(L, 2) == LUA_TTABLE) { + schema = ucl_object_lua_import(L, 2); if (schema == NULL) { - lua_pushboolean (L, false); - lua_pushstring (L, "cannot load schema from lua table"); + lua_pushboolean(L, false); + lua_pushstring(L, "cannot load schema from lua table"); return 2; } } - else if (lua_type (L, 2) == LUA_TSTRING) { - schema_parser = ucl_parser_new (0); - schema_file = luaL_checkstring (L, 2); + else if (lua_type(L, 2) == LUA_TSTRING) { + schema_parser = ucl_parser_new(0); + schema_file = luaL_checkstring(L, 2); - if (!ucl_parser_add_file (schema_parser, schema_file)) { - lua_pushboolean (L, false); - lua_pushfstring (L, "cannot parse schema file \"%s\": " - "%s", schema_file, ucl_parser_get_error (parser)); - ucl_parser_free (schema_parser); + if (!ucl_parser_add_file(schema_parser, schema_file)) { + lua_pushboolean(L, false); + lua_pushfstring(L, "cannot parse schema file \"%s\": " + "%s", + schema_file, ucl_parser_get_error(parser)); + ucl_parser_free(schema_parser); return 2; } - schema = ucl_parser_get_object (schema_parser); - ucl_parser_free (schema_parser); + schema = ucl_parser_get_object(schema_parser); + ucl_parser_free(schema_parser); } else { - lua_pushboolean (L, false); - lua_pushstring (L, "invalid schema argument"); + lua_pushboolean(L, false); + lua_pushstring(L, "invalid schema argument"); return 2; } - if (!ucl_object_validate (schema, parser->top_obj, &err)) { - lua_pushboolean (L, false); - lua_pushfstring (L, "validation error: " - "%s", err.msg); + if (!ucl_object_validate(schema, parser->top_obj, &err)) { + lua_pushboolean(L, false); + lua_pushfstring(L, "validation error: " + "%s", + err.msg); } else { - lua_pushboolean (L, true); - lua_pushnil (L); + lua_pushboolean(L, true); + lua_pushnil(L); } - ucl_object_unref (schema); + ucl_object_unref(schema); } else { - lua_pushboolean (L, false); - lua_pushstring (L, "invalid parser or empty top object"); + lua_pushboolean(L, false); + lua_pushstring(L, "invalid parser or empty top object"); } return 2; } static int -lua_ucl_parser_gc (lua_State *L) +lua_ucl_parser_gc(lua_State *L) { struct ucl_parser *parser; - parser = lua_ucl_parser_get (L, 1); - ucl_parser_free (parser); + parser = lua_ucl_parser_get(L, 1); + ucl_parser_free(parser); return 0; } @@ -1066,38 +1070,38 @@ lua_ucl_parser_gc (lua_State *L) * @return {variant} any lua object */ static int -lua_ucl_object_unwrap (lua_State *L) +lua_ucl_object_unwrap(lua_State *L) { ucl_object_t *obj; - obj = lua_ucl_object_get (L, 1); + obj = lua_ucl_object_get(L, 1); if (obj) { - ucl_object_push_lua (L, obj, true); + ucl_object_push_lua(L, obj, true); } else { - lua_pushnil (L); + lua_pushnil(L); } return 1; } static inline enum ucl_emitter -lua_ucl_str_to_emit_type (const char *strtype) +lua_ucl_str_to_emit_type(const char *strtype) { enum ucl_emitter format = UCL_EMIT_JSON_COMPACT; - if (strcasecmp (strtype, "json") == 0) { + if (strcasecmp(strtype, "json") == 0) { format = UCL_EMIT_JSON; } - else if (strcasecmp (strtype, "json-compact") == 0) { + else if (strcasecmp(strtype, "json-compact") == 0) { format = UCL_EMIT_JSON_COMPACT; } - else if (strcasecmp (strtype, "yaml") == 0) { + else if (strcasecmp(strtype, "yaml") == 0) { format = UCL_EMIT_YAML; } - else if (strcasecmp (strtype, "config") == 0 || - strcasecmp (strtype, "ucl") == 0) { + else if (strcasecmp(strtype, "config") == 0 || + strcasecmp(strtype, "ucl") == 0) { format = UCL_EMIT_CONFIG; } @@ -1118,26 +1122,26 @@ lua_ucl_str_to_emit_type (const char *strtype) * @return {string} string representation of the opaque ucl object */ static int -lua_ucl_object_tostring (lua_State *L) +lua_ucl_object_tostring(lua_State *L) { ucl_object_t *obj; enum ucl_emitter format = UCL_EMIT_JSON_COMPACT; - obj = lua_ucl_object_get (L, 1); + obj = lua_ucl_object_get(L, 1); if (obj) { - if (lua_gettop (L) > 1) { - if (lua_type (L, 2) == LUA_TSTRING) { - const char *strtype = lua_tostring (L, 2); + if (lua_gettop(L) > 1) { + if (lua_type(L, 2) == LUA_TSTRING) { + const char *strtype = lua_tostring(L, 2); - format = lua_ucl_str_to_emit_type (strtype); + format = lua_ucl_str_to_emit_type(strtype); } } - return lua_ucl_to_string (L, obj, format); + return lua_ucl_to_string(L, obj, format); } else { - lua_pushnil (L); + lua_pushnil(L); } return 1; @@ -1156,7 +1160,7 @@ lua_ucl_object_tostring (lua_State *L) * ucl object as {result,err,ext_refs} */ static int -lua_ucl_object_validate (lua_State *L) +lua_ucl_object_validate(lua_State *L) { ucl_object_t *obj, *schema, *ext_refs = NULL; const ucl_object_t *schema_elt; @@ -1164,34 +1168,34 @@ lua_ucl_object_validate (lua_State *L) struct ucl_schema_error err; const char *path = NULL; - obj = lua_ucl_object_get (L, 1); - schema = lua_ucl_object_get (L, 2); + obj = lua_ucl_object_get(L, 1); + schema = lua_ucl_object_get(L, 2); - if (schema && obj && ucl_object_type (schema) == UCL_OBJECT) { - if (lua_gettop (L) > 2) { - if (lua_type (L, 3) == LUA_TSTRING) { - path = lua_tostring (L, 3); + if (schema && obj && ucl_object_type(schema) == UCL_OBJECT) { + if (lua_gettop(L) > 2) { + if (lua_type(L, 3) == LUA_TSTRING) { + path = lua_tostring(L, 3); if (path[0] == '#') { path++; } } - else if (lua_type (L, 3) == LUA_TUSERDATA || lua_type (L, 3) == - LUA_TTABLE) { + else if (lua_type(L, 3) == LUA_TUSERDATA || lua_type(L, 3) == + LUA_TTABLE) { /* External refs */ - ext_refs = lua_ucl_object_get (L, 3); + ext_refs = lua_ucl_object_get(L, 3); } - if (lua_gettop (L) > 3) { - if (lua_type (L, 4) == LUA_TUSERDATA || lua_type (L, 4) == - LUA_TTABLE) { + if (lua_gettop(L) > 3) { + if (lua_type(L, 4) == LUA_TUSERDATA || lua_type(L, 4) == + LUA_TTABLE) { /* External refs */ - ext_refs = lua_ucl_object_get (L, 4); + ext_refs = lua_ucl_object_get(L, 4); } } } if (path) { - schema_elt = ucl_object_lookup_path_char (schema, path, '/'); + schema_elt = ucl_object_lookup_path_char(schema, path, '/'); } else { /* Use the top object */ @@ -1199,39 +1203,39 @@ lua_ucl_object_validate (lua_State *L) } if (schema_elt) { - res = ucl_object_validate_root_ext (schema_elt, obj, schema, - ext_refs, &err); + res = ucl_object_validate_root_ext(schema_elt, obj, schema, + ext_refs, &err); if (res) { - lua_pushboolean (L, res); - lua_pushnil (L); + lua_pushboolean(L, res); + lua_pushnil(L); if (ext_refs) { - lua_ucl_push_opaque (L, ext_refs); + lua_ucl_push_opaque(L, ext_refs); } } else { - lua_pushboolean (L, res); - lua_pushfstring (L, "validation error: %s", err.msg); + lua_pushboolean(L, res); + lua_pushfstring(L, "validation error: %s", err.msg); if (ext_refs) { - lua_ucl_push_opaque (L, ext_refs); + lua_ucl_push_opaque(L, ext_refs); } } } else { - lua_pushboolean (L, res); + lua_pushboolean(L, res); - lua_pushfstring (L, "cannot find the requested path: %s", path); + lua_pushfstring(L, "cannot find the requested path: %s", path); if (ext_refs) { - lua_ucl_push_opaque (L, ext_refs); + lua_ucl_push_opaque(L, ext_refs); } } } else { - lua_pushboolean (L, res); - lua_pushstring (L, "invalid object or schema"); + lua_pushboolean(L, res); + lua_pushstring(L, "invalid object or schema"); } if (ext_refs) { @@ -1242,166 +1246,166 @@ lua_ucl_object_validate (lua_State *L) } static int -lua_ucl_object_gc (lua_State *L) +lua_ucl_object_gc(lua_State *L) { ucl_object_t *obj; - obj = lua_ucl_object_get (L, 1); + obj = lua_ucl_object_get(L, 1); - ucl_object_unref (obj); + ucl_object_unref(obj); return 0; } static void -lua_ucl_parser_mt (lua_State *L) +lua_ucl_parser_mt(lua_State *L) { - luaL_newmetatable (L, PARSER_META); + luaL_newmetatable(L, PARSER_META); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - lua_pushcfunction (L, lua_ucl_parser_gc); - lua_setfield (L, -2, "__gc"); + lua_pushcfunction(L, lua_ucl_parser_gc); + lua_setfield(L, -2, "__gc"); - lua_pushcfunction (L, lua_ucl_parser_parse_file); - lua_setfield (L, -2, "parse_file"); + lua_pushcfunction(L, lua_ucl_parser_parse_file); + lua_setfield(L, -2, "parse_file"); - lua_pushcfunction (L, lua_ucl_parser_parse_string); - lua_setfield (L, -2, "parse_string"); + lua_pushcfunction(L, lua_ucl_parser_parse_string); + lua_setfield(L, -2, "parse_string"); - lua_pushcfunction (L, lua_ucl_parser_parse_text); - lua_setfield (L, -2, "parse_text"); + lua_pushcfunction(L, lua_ucl_parser_parse_text); + lua_setfield(L, -2, "parse_text"); - lua_pushcfunction (L, lua_ucl_parser_register_variable); - lua_setfield (L, -2, "register_variable"); + lua_pushcfunction(L, lua_ucl_parser_register_variable); + lua_setfield(L, -2, "register_variable"); - lua_pushcfunction (L, lua_ucl_parser_register_variables); - lua_setfield (L, -2, "register_variables"); + lua_pushcfunction(L, lua_ucl_parser_register_variables); + lua_setfield(L, -2, "register_variables"); - lua_pushcfunction (L, lua_ucl_parser_get_object); - lua_setfield (L, -2, "get_object"); + lua_pushcfunction(L, lua_ucl_parser_get_object); + lua_setfield(L, -2, "get_object"); - lua_pushcfunction (L, lua_ucl_parser_get_object_wrapped); - lua_setfield (L, -2, "get_object_wrapped"); + lua_pushcfunction(L, lua_ucl_parser_get_object_wrapped); + lua_setfield(L, -2, "get_object_wrapped"); - lua_pushcfunction (L, lua_ucl_parser_validate); - lua_setfield (L, -2, "validate"); + lua_pushcfunction(L, lua_ucl_parser_validate); + lua_setfield(L, -2, "validate"); - lua_pop (L, 1); + lua_pop(L, 1); } static void -lua_ucl_object_mt (lua_State *L) +lua_ucl_object_mt(lua_State *L) { - luaL_newmetatable (L, OBJECT_META); + luaL_newmetatable(L, OBJECT_META); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - lua_pushcfunction (L, lua_ucl_object_gc); - lua_setfield (L, -2, "__gc"); + lua_pushcfunction(L, lua_ucl_object_gc); + lua_setfield(L, -2, "__gc"); - lua_pushcfunction (L, lua_ucl_object_tostring); - lua_setfield (L, -2, "__tostring"); + lua_pushcfunction(L, lua_ucl_object_tostring); + lua_setfield(L, -2, "__tostring"); - lua_pushcfunction (L, lua_ucl_object_tostring); - lua_setfield (L, -2, "tostring"); + lua_pushcfunction(L, lua_ucl_object_tostring); + lua_setfield(L, -2, "tostring"); - lua_pushcfunction (L, lua_ucl_object_unwrap); - lua_setfield (L, -2, "unwrap"); + lua_pushcfunction(L, lua_ucl_object_unwrap); + lua_setfield(L, -2, "unwrap"); - lua_pushcfunction (L, lua_ucl_object_unwrap); - lua_setfield (L, -2, "tolua"); + lua_pushcfunction(L, lua_ucl_object_unwrap); + lua_setfield(L, -2, "tolua"); - lua_pushcfunction (L, lua_ucl_object_validate); - lua_setfield (L, -2, "validate"); + lua_pushcfunction(L, lua_ucl_object_validate); + lua_setfield(L, -2, "validate"); - lua_pushstring (L, OBJECT_META); - lua_setfield (L, -2, "class"); + lua_pushstring(L, OBJECT_META); + lua_setfield(L, -2, "class"); - lua_pop (L, 1); + lua_pop(L, 1); } static void -lua_ucl_types_mt (lua_State *L) +lua_ucl_types_mt(lua_State *L) { - luaL_newmetatable (L, UCL_OBJECT_TYPE_META); + luaL_newmetatable(L, UCL_OBJECT_TYPE_META); - lua_pushcfunction (L, lua_ucl_object_tostring); - lua_setfield (L, -2, "__tostring"); + lua_pushcfunction(L, lua_ucl_object_tostring); + lua_setfield(L, -2, "__tostring"); - lua_pushcfunction (L, lua_ucl_object_tostring); - lua_setfield (L, -2, "tostring"); + lua_pushcfunction(L, lua_ucl_object_tostring); + lua_setfield(L, -2, "tostring"); - lua_pushstring (L, UCL_OBJECT_TYPE_META); - lua_setfield (L, -2, "class"); + lua_pushstring(L, UCL_OBJECT_TYPE_META); + lua_setfield(L, -2, "class"); - lua_pop (L, 1); + lua_pop(L, 1); - luaL_newmetatable (L, UCL_ARRAY_TYPE_META); + luaL_newmetatable(L, UCL_ARRAY_TYPE_META); - lua_pushcfunction (L, lua_ucl_object_tostring); - lua_setfield (L, -2, "__tostring"); + lua_pushcfunction(L, lua_ucl_object_tostring); + lua_setfield(L, -2, "__tostring"); - lua_pushcfunction (L, lua_ucl_object_tostring); - lua_setfield (L, -2, "tostring"); + lua_pushcfunction(L, lua_ucl_object_tostring); + lua_setfield(L, -2, "tostring"); - lua_pushstring (L, UCL_ARRAY_TYPE_META); - lua_setfield (L, -2, "class"); + lua_pushstring(L, UCL_ARRAY_TYPE_META); + lua_setfield(L, -2, "class"); - lua_pop (L, 1); + lua_pop(L, 1); - luaL_newmetatable (L, UCL_IMPL_ARRAY_TYPE_META); + luaL_newmetatable(L, UCL_IMPL_ARRAY_TYPE_META); - lua_pushcfunction (L, lua_ucl_object_tostring); - lua_setfield (L, -2, "__tostring"); + lua_pushcfunction(L, lua_ucl_object_tostring); + lua_setfield(L, -2, "__tostring"); - lua_pushcfunction (L, lua_ucl_object_tostring); - lua_setfield (L, -2, "tostring"); + lua_pushcfunction(L, lua_ucl_object_tostring); + lua_setfield(L, -2, "tostring"); - lua_pushstring (L, UCL_IMPL_ARRAY_TYPE_META); - lua_setfield (L, -2, "class"); + lua_pushstring(L, UCL_IMPL_ARRAY_TYPE_META); + lua_setfield(L, -2, "class"); - lua_pop (L, 1); + lua_pop(L, 1); } static int -lua_ucl_to_json (lua_State *L) +lua_ucl_to_json(lua_State *L) { ucl_object_t *obj; int format = UCL_EMIT_JSON; - if (lua_gettop (L) > 1) { - if (lua_toboolean (L, 2)) { + if (lua_gettop(L) > 1) { + if (lua_toboolean(L, 2)) { format = UCL_EMIT_JSON_COMPACT; } } - obj = ucl_object_lua_import (L, 1); + obj = ucl_object_lua_import(L, 1); if (obj != NULL) { - lua_ucl_to_string (L, obj, format); - ucl_object_unref (obj); + lua_ucl_to_string(L, obj, format); + ucl_object_unref(obj); } else { - lua_pushnil (L); + lua_pushnil(L); } return 1; } static int -lua_ucl_to_config (lua_State *L) +lua_ucl_to_config(lua_State *L) { ucl_object_t *obj; - obj = ucl_object_lua_import (L, 1); + obj = ucl_object_lua_import(L, 1); if (obj != NULL) { - lua_ucl_to_string (L, obj, UCL_EMIT_CONFIG); - ucl_object_unref (obj); + lua_ucl_to_string(L, obj, UCL_EMIT_CONFIG); + ucl_object_unref(obj); } else { - lua_pushnil (L); + lua_pushnil(L); } return 1; @@ -1442,133 +1446,132 @@ func = "huh"; --]] */ static int -lua_ucl_to_format (lua_State *L) +lua_ucl_to_format(lua_State *L) { ucl_object_t *obj; int format = UCL_EMIT_JSON; bool sort = false; - if (lua_gettop (L) > 1) { - if (lua_type (L, 2) == LUA_TNUMBER) { - format = lua_tonumber (L, 2); + if (lua_gettop(L) > 1) { + if (lua_type(L, 2) == LUA_TNUMBER) { + format = lua_tonumber(L, 2); if (format < 0 || format >= UCL_EMIT_YAML) { - lua_pushnil (L); + lua_pushnil(L); return 1; } } - else if (lua_type (L, 2) == LUA_TSTRING) { - const char *strtype = lua_tostring (L, 2); + else if (lua_type(L, 2) == LUA_TSTRING) { + const char *strtype = lua_tostring(L, 2); - if (strcasecmp (strtype, "json") == 0) { + if (strcasecmp(strtype, "json") == 0) { format = UCL_EMIT_JSON; } - else if (strcasecmp (strtype, "json-compact") == 0) { + else if (strcasecmp(strtype, "json-compact") == 0) { format = UCL_EMIT_JSON_COMPACT; } - else if (strcasecmp (strtype, "yaml") == 0) { + else if (strcasecmp(strtype, "yaml") == 0) { format = UCL_EMIT_YAML; } - else if (strcasecmp (strtype, "config") == 0 || - strcasecmp (strtype, "ucl") == 0) { + else if (strcasecmp(strtype, "config") == 0 || + strcasecmp(strtype, "ucl") == 0) { format = UCL_EMIT_CONFIG; } - else if (strcasecmp (strtype, "msgpack") == 0 || - strcasecmp (strtype, "messagepack") == 0) { + else if (strcasecmp(strtype, "msgpack") == 0 || + strcasecmp(strtype, "messagepack") == 0) { format = UCL_EMIT_MSGPACK; } } - if (lua_isboolean (L, 3)) { - sort = lua_toboolean (L, 3); + if (lua_isboolean(L, 3)) { + sort = lua_toboolean(L, 3); } } - obj = ucl_object_lua_import (L, 1); + obj = ucl_object_lua_import(L, 1); if (obj != NULL) { if (sort) { - if (ucl_object_type (obj) == UCL_OBJECT) { - ucl_object_sort_keys (obj, UCL_SORT_KEYS_RECURSIVE); + if (ucl_object_type(obj) == UCL_OBJECT) { + ucl_object_sort_keys(obj, UCL_SORT_KEYS_RECURSIVE); } } - lua_ucl_to_string (L, obj, format); - ucl_object_unref (obj); + lua_ucl_to_string(L, obj, format); + ucl_object_unref(obj); } else { - lua_pushnil (L); + lua_pushnil(L); } return 1; } static int -lua_ucl_null_tostring (lua_State* L) +lua_ucl_null_tostring(lua_State *L) { - lua_pushstring (L, "null"); + lua_pushstring(L, "null"); return 1; } static void -lua_ucl_null_mt (lua_State *L) +lua_ucl_null_mt(lua_State *L) { - luaL_newmetatable (L, NULL_META); + luaL_newmetatable(L, NULL_META); - lua_pushcfunction (L, lua_ucl_null_tostring); - lua_setfield (L, -2, "__tostring"); + lua_pushcfunction(L, lua_ucl_null_tostring); + lua_setfield(L, -2, "__tostring"); - lua_pop (L, 1); + lua_pop(L, 1); } -int -luaopen_ucl (lua_State *L) +int luaopen_ucl(lua_State *L) { - lua_ucl_parser_mt (L); - lua_ucl_null_mt (L); - lua_ucl_object_mt (L); - lua_ucl_types_mt (L); + lua_ucl_parser_mt(L); + lua_ucl_null_mt(L); + lua_ucl_object_mt(L); + lua_ucl_types_mt(L); /* Create the refs weak table: */ - lua_createtable (L, 0, 2); - lua_pushliteral (L, "v"); /* tbl, "v" */ - lua_setfield (L, -2, "__mode"); - lua_pushvalue (L, -1); /* tbl, tbl */ - lua_setmetatable (L, -2); /* tbl */ - lua_setfield (L, LUA_REGISTRYINDEX, "ucl.refs"); + lua_createtable(L, 0, 2); + lua_pushliteral(L, "v"); /* tbl, "v" */ + lua_setfield(L, -2, "__mode"); + lua_pushvalue(L, -1); /* tbl, tbl */ + lua_setmetatable(L, -2); /* tbl */ + lua_setfield(L, LUA_REGISTRYINDEX, "ucl.refs"); - lua_newtable (L); + lua_newtable(L); - lua_pushcfunction (L, lua_ucl_parser_init); - lua_setfield (L, -2, "parser"); + lua_pushcfunction(L, lua_ucl_parser_init); + lua_setfield(L, -2, "parser"); - lua_pushcfunction (L, lua_ucl_to_json); - lua_setfield (L, -2, "to_json"); + lua_pushcfunction(L, lua_ucl_to_json); + lua_setfield(L, -2, "to_json"); - lua_pushcfunction (L, lua_ucl_to_config); - lua_setfield (L, -2, "to_config"); + lua_pushcfunction(L, lua_ucl_to_config); + lua_setfield(L, -2, "to_config"); - lua_pushcfunction (L, lua_ucl_to_format); - lua_setfield (L, -2, "to_format"); + lua_pushcfunction(L, lua_ucl_to_format); + lua_setfield(L, -2, "to_format"); - ucl_null = lua_newuserdata (L, 0); - luaL_getmetatable (L, NULL_META); - lua_setmetatable (L, -2); + ucl_null = lua_newuserdata(L, 0); + luaL_getmetatable(L, NULL_META); + lua_setmetatable(L, -2); - lua_pushvalue (L, -1); - lua_setfield (L, LUA_REGISTRYINDEX, "ucl.null"); + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, "ucl.null"); - lua_setfield (L, -2, "null"); + lua_setfield(L, -2, "null"); return 1; } -struct ucl_lua_funcdata* -ucl_object_toclosure (const ucl_object_t *obj) +struct ucl_lua_funcdata * +ucl_object_toclosure(const ucl_object_t *obj) { if (obj == NULL || obj->type != UCL_USERDATA) { return NULL; } - return (struct ucl_lua_funcdata*)obj->value.ud; + return (struct ucl_lua_funcdata *) obj->value.ud; } diff --git a/contrib/libucl/ucl_hash.c b/contrib/libucl/ucl_hash.c index a26c26f9f..eb2053ba1 100644 --- a/contrib/libucl/ucl_hash.c +++ b/contrib/libucl/ucl_hash.c @@ -45,7 +45,7 @@ struct ucl_hash_struct { }; static uint64_t -ucl_hash_seed (void) +ucl_hash_seed(void) { static uint64_t seed; if (seed == 0) { @@ -53,41 +53,41 @@ ucl_hash_seed (void) seed = UCL_RANDOM_FUNCTION; #else /* Not very random but can be useful for our purposes */ - seed = time (NULL); + seed = time(NULL); #endif } return seed; } -extern const guchar lc_map[256]; +extern const unsigned char lc_map[256]; static inline uint32_t -ucl_hash_func (const ucl_object_t *o) +ucl_hash_func(const ucl_object_t *o) { - return (uint32_t)rspamd_cryptobox_fast_hash (o->key, o->keylen, 0xb9a1ef83c4561c95ULL); + return (uint32_t) rspamd_cryptobox_fast_hash(o->key, o->keylen, 0xb9a1ef83c4561c95ULL); } static inline int -ucl_hash_equal (const ucl_object_t *k1, const ucl_object_t *k2) +ucl_hash_equal(const ucl_object_t *k1, const ucl_object_t *k2) { if (k1->keylen == k2->keylen) { - return memcmp (k1->key, k2->key, k1->keylen) == 0; + return memcmp(k1->key, k2->key, k1->keylen) == 0; } return 0; } -KHASH_INIT (ucl_hash_node, const ucl_object_t *, struct ucl_hash_elt *, 1, - ucl_hash_func, ucl_hash_equal) +KHASH_INIT(ucl_hash_node, const ucl_object_t *, struct ucl_hash_elt *, 1, + ucl_hash_func, ucl_hash_equal) static inline uint32_t -ucl_hash_caseless_func (const ucl_object_t *o) +ucl_hash_caseless_func(const ucl_object_t *o) { unsigned len = o->keylen; unsigned leftover = o->keylen % 4; unsigned fp, i; - const uint8_t* s = (const uint8_t*)o->key; + const uint8_t *s = (const uint8_t *) o->key; union { struct { unsigned char c1, c2, c3, c4; @@ -98,7 +98,7 @@ ucl_hash_caseless_func (const ucl_object_t *o) rspamd_cryptobox_fast_hash_state_t hst; fp = len - leftover; - rspamd_cryptobox_fast_hash_init (&hst, h); + rspamd_cryptobox_fast_hash_init(&hst, h); for (i = 0; i != fp; i += 4) { u.c.c1 = s[i], u.c.c2 = s[i + 1], u.c.c3 = s[i + 2], u.c.c4 = s[i + 3]; @@ -106,58 +106,58 @@ ucl_hash_caseless_func (const ucl_object_t *o) u.c.c2 = lc_map[u.c.c2]; u.c.c3 = lc_map[u.c.c3]; u.c.c4 = lc_map[u.c.c4]; - rspamd_cryptobox_fast_hash_update (&hst, &u, sizeof (u)); + rspamd_cryptobox_fast_hash_update(&hst, &u, sizeof(u)); } u.pp = 0; switch (leftover) { case 3: - u.c.c3 = lc_map[(unsigned char)s[i++]]; + u.c.c3 = lc_map[(unsigned char) s[i++]]; case 2: /* fallthrough */ - u.c.c2 = lc_map[(unsigned char)s[i++]]; + u.c.c2 = lc_map[(unsigned char) s[i++]]; case 1: /* fallthrough */ - u.c.c1 = lc_map[(unsigned char)s[i]]; - rspamd_cryptobox_fast_hash_update (&hst, &u, sizeof (u)); + u.c.c1 = lc_map[(unsigned char) s[i]]; + rspamd_cryptobox_fast_hash_update(&hst, &u, sizeof(u)); break; } - return (uint32_t)rspamd_cryptobox_fast_hash_final (&hst); + return (uint32_t) rspamd_cryptobox_fast_hash_final(&hst); } static inline bool -ucl_hash_caseless_equal (const ucl_object_t *k1, const ucl_object_t *k2) +ucl_hash_caseless_equal(const ucl_object_t *k1, const ucl_object_t *k2) { if (k1->keylen == k2->keylen) { - return rspamd_lc_cmp (k1->key, k2->key, k1->keylen) == 0; + return rspamd_lc_cmp(k1->key, k2->key, k1->keylen) == 0; } return false; } -KHASH_INIT (ucl_hash_caseless_node, const ucl_object_t *, struct ucl_hash_elt *, 1, - ucl_hash_caseless_func, ucl_hash_caseless_equal) +KHASH_INIT(ucl_hash_caseless_node, const ucl_object_t *, struct ucl_hash_elt *, 1, + ucl_hash_caseless_func, ucl_hash_caseless_equal) -ucl_hash_t* -ucl_hash_create (bool ignore_case) +ucl_hash_t * +ucl_hash_create(bool ignore_case) { ucl_hash_t *new; - new = UCL_ALLOC (sizeof (ucl_hash_t)); + new = UCL_ALLOC(sizeof(ucl_hash_t)); if (new != NULL) { void *h; new->head = NULL; new->caseless = ignore_case; if (ignore_case) { - h = (void *)kh_init (ucl_hash_caseless_node); + h = (void *) kh_init(ucl_hash_caseless_node); } else { - h = (void *)kh_init (ucl_hash_node); + h = (void *) kh_init(ucl_hash_node); } if (h == NULL) { - UCL_FREE (sizeof (ucl_hash_t), new); + UCL_FREE(sizeof(ucl_hash_t), new); return NULL; } new->hash = h; @@ -165,7 +165,7 @@ ucl_hash_create (bool ignore_case) return new; } -void ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func func) +void ucl_hash_destroy(ucl_hash_t *hashlin, ucl_hash_free_func func) { if (hashlin == NULL) { @@ -175,16 +175,16 @@ void ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func func) if (func != NULL) { /* Iterate over the hash first */ khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) - hashlin->hash; + hashlin->hash; khiter_t k; const ucl_object_t *cur, *tmp; - for (k = kh_begin (h); k != kh_end (h); ++k) { - if (kh_exist (h, k)) { - cur = (kh_value (h, k))->obj; + for (k = kh_begin(h); k != kh_end(h); ++k) { + if (kh_exist(h, k)) { + cur = (kh_value(h, k))->obj; while (cur != NULL) { tmp = cur->next; - func (__DECONST (ucl_object_t *, cur)); + func(__DECONST(ucl_object_t *, cur)); cur = tmp; } } @@ -193,27 +193,27 @@ void ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func func) if (hashlin->caseless) { khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *) - hashlin->hash; - kh_destroy (ucl_hash_caseless_node, h); + hashlin->hash; + kh_destroy(ucl_hash_caseless_node, h); } else { khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) - hashlin->hash; - kh_destroy (ucl_hash_node, h); + hashlin->hash; + kh_destroy(ucl_hash_node, h); } struct ucl_hash_elt *cur, *tmp; - DL_FOREACH_SAFE(hashlin->head, cur, tmp) { + DL_FOREACH_SAFE(hashlin->head, cur, tmp) + { UCL_FREE(sizeof(*cur), cur); } - UCL_FREE (sizeof (*hashlin), hashlin); + UCL_FREE(sizeof(*hashlin), hashlin); } -bool -ucl_hash_insert (ucl_hash_t* hashlin, const ucl_object_t *obj, - const char *key, unsigned keylen) +bool ucl_hash_insert(ucl_hash_t *hashlin, const ucl_object_t *obj, + const char *key, unsigned keylen) { khiter_t k; int ret; @@ -225,11 +225,11 @@ ucl_hash_insert (ucl_hash_t* hashlin, const ucl_object_t *obj, if (hashlin->caseless) { khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *) - hashlin->hash; - k = kh_put (ucl_hash_caseless_node, h, obj, &ret); + hashlin->hash; + k = kh_put(ucl_hash_caseless_node, h, obj, &ret); if (ret > 0) { elt = UCL_ALLOC(sizeof(*elt)); - pelt = &kh_value (h, k); + pelt = &kh_value(h, k); *pelt = elt; DL_APPEND(hashlin->head, elt); elt->obj = obj; @@ -240,25 +240,26 @@ ucl_hash_insert (ucl_hash_t* hashlin, const ucl_object_t *obj, } else { khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) - hashlin->hash; - k = kh_put (ucl_hash_node, h, obj, &ret); + hashlin->hash; + k = kh_put(ucl_hash_node, h, obj, &ret); if (ret > 0) { elt = UCL_ALLOC(sizeof(*elt)); - pelt = &kh_value (h, k); + pelt = &kh_value(h, k); *pelt = elt; DL_APPEND(hashlin->head, elt); elt->obj = obj; - } else if (ret < 0) { + } + else if (ret < 0) { goto e0; } } return true; - e0: +e0: return false; } -void ucl_hash_replace (ucl_hash_t* hashlin, const ucl_object_t *old, - const ucl_object_t *new) +void ucl_hash_replace(ucl_hash_t *hashlin, const ucl_object_t *old, + const ucl_object_t *new) { khiter_t k; int ret; @@ -270,12 +271,12 @@ void ucl_hash_replace (ucl_hash_t* hashlin, const ucl_object_t *old, if (hashlin->caseless) { khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *) - hashlin->hash; - k = kh_put (ucl_hash_caseless_node, h, old, &ret); + hashlin->hash; + k = kh_put(ucl_hash_caseless_node, h, old, &ret); if (ret == 0) { elt = kh_value(h, k); - kh_del (ucl_hash_caseless_node, h, k); - k = kh_put (ucl_hash_caseless_node, h, new, &ret); + kh_del(ucl_hash_caseless_node, h, k); + k = kh_put(ucl_hash_caseless_node, h, new, &ret); nelt = UCL_ALLOC(sizeof(*nelt)); nelt->obj = new; kh_value(h, k) = nelt; @@ -285,12 +286,12 @@ void ucl_hash_replace (ucl_hash_t* hashlin, const ucl_object_t *old, } else { khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) - hashlin->hash; - k = kh_put (ucl_hash_node, h, old, &ret); + hashlin->hash; + k = kh_put(ucl_hash_node, h, old, &ret); if (ret == 0) { - elt = kh_value (h, k); - kh_del (ucl_hash_node, h, k); - k = kh_put (ucl_hash_node, h, new, &ret); + elt = kh_value(h, k); + kh_del(ucl_hash_node, h, k); + k = kh_put(ucl_hash_node, h, new, &ret); nelt = UCL_ALLOC(sizeof(*nelt)); nelt->obj = new; kh_value(h, k) = nelt; @@ -304,12 +305,15 @@ struct ucl_hash_real_iter { const struct ucl_hash_elt *cur; }; -#define UHI_SETERR(ep, ern) {if (ep != NULL) *ep = (ern);} +#define UHI_SETERR(ep, ern) \ + { \ + if (ep != NULL) *ep = (ern); \ + } -const void* -ucl_hash_iterate2 (ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep) +const void * +ucl_hash_iterate2(ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep) { - struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *)(*iter); + struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *) (*iter); const ucl_object_t *ret = NULL; if (hashlin == NULL) { @@ -318,7 +322,7 @@ ucl_hash_iterate2 (ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep) } if (it == NULL) { - it = UCL_ALLOC (sizeof (*it)); + it = UCL_ALLOC(sizeof(*it)); if (it == NULL) { UHI_SETERR(ep, ENOMEM); @@ -334,7 +338,7 @@ ucl_hash_iterate2 (ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep) it->cur = it->cur->next; } else { - UCL_FREE (sizeof (*it), it); + UCL_FREE(sizeof(*it), it); *iter = NULL; return NULL; } @@ -344,17 +348,16 @@ ucl_hash_iterate2 (ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep) return ret; } -bool -ucl_hash_iter_has_next (ucl_hash_t *hashlin, ucl_hash_iter_t iter) +bool ucl_hash_iter_has_next(ucl_hash_t *hashlin, ucl_hash_iter_t iter) { - struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *)(iter); + struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *) (iter); return it->cur != NULL; } -const ucl_object_t* -ucl_hash_search (ucl_hash_t* hashlin, const char *key, unsigned keylen) +const ucl_object_t * +ucl_hash_search(ucl_hash_t *hashlin, const char *key, unsigned keylen) { khiter_t k; const ucl_object_t *ret = NULL; @@ -370,20 +373,20 @@ ucl_hash_search (ucl_hash_t* hashlin, const char *key, unsigned keylen) if (hashlin->caseless) { khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *) - hashlin->hash; + hashlin->hash; - k = kh_get (ucl_hash_caseless_node, h, &search); - if (k != kh_end (h)) { - elt = kh_value (h, k); + k = kh_get(ucl_hash_caseless_node, h, &search); + if (k != kh_end(h)) { + elt = kh_value(h, k); ret = elt->obj; } } else { khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) - hashlin->hash; - k = kh_get (ucl_hash_node, h, &search); - if (k != kh_end (h)) { - elt = kh_value (h, k); + hashlin->hash; + k = kh_get(ucl_hash_node, h, &search); + if (k != kh_end(h)) { + elt = kh_value(h, k); ret = elt->obj; } } @@ -391,8 +394,7 @@ ucl_hash_search (ucl_hash_t* hashlin, const char *key, unsigned keylen) return ret; } -void -ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj) +void ucl_hash_delete(ucl_hash_t *hashlin, const ucl_object_t *obj) { khiter_t k; struct ucl_hash_elt *elt; @@ -403,46 +405,46 @@ ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj) if (hashlin->caseless) { khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *) - hashlin->hash; + hashlin->hash; - k = kh_get (ucl_hash_caseless_node, h, obj); - if (k != kh_end (h)) { - elt = kh_value (h, k); + k = kh_get(ucl_hash_caseless_node, h, obj); + if (k != kh_end(h)) { + elt = kh_value(h, k); DL_DELETE(hashlin->head, elt); - kh_del (ucl_hash_caseless_node, h, k); + kh_del(ucl_hash_caseless_node, h, k); UCL_FREE(sizeof(*elt), elt); } } else { khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) - hashlin->hash; - k = kh_get (ucl_hash_node, h, obj); - if (k != kh_end (h)) { - elt = kh_value (h, k); + hashlin->hash; + k = kh_get(ucl_hash_node, h, obj); + if (k != kh_end(h)) { + elt = kh_value(h, k); DL_DELETE(hashlin->head, elt); - kh_del (ucl_hash_node, h, k); + kh_del(ucl_hash_node, h, k); UCL_FREE(sizeof(*elt), elt); } } } -bool -ucl_hash_reserve (ucl_hash_t *hashlin, size_t sz) +bool ucl_hash_reserve(ucl_hash_t *hashlin, size_t sz) { if (hashlin == NULL) { return false; } - if (sz > kh_size((khash_t(ucl_hash_node) *)hashlin->hash)) { + if (sz > kh_size((khash_t(ucl_hash_node) *) hashlin->hash)) { if (hashlin->caseless) { khash_t(ucl_hash_caseless_node) *h = (khash_t( - ucl_hash_caseless_node) *) - hashlin->hash; - kh_resize (ucl_hash_caseless_node, h, sz * 2); - } else { + ucl_hash_caseless_node) *) + hashlin->hash; + kh_resize(ucl_hash_caseless_node, h, sz * 2); + } + else { khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) - hashlin->hash; - kh_resize (ucl_hash_node, h, sz * 2); + hashlin->hash; + kh_resize(ucl_hash_node, h, sz * 2); } } @@ -450,33 +452,32 @@ ucl_hash_reserve (ucl_hash_t *hashlin, size_t sz) } static int -ucl_hash_cmp_icase (const void *a, const void *b) +ucl_hash_cmp_icase(const void *a, const void *b) { - const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *)a, - *ob = (const struct ucl_hash_elt *)b; + const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *) a, + *ob = (const struct ucl_hash_elt *) b; if (oa->obj->keylen == ob->obj->keylen) { - return rspamd_lc_cmp (oa->obj->key, ob->obj->key, oa->obj->keylen); + return rspamd_lc_cmp(oa->obj->key, ob->obj->key, oa->obj->keylen); } - return ((int)(oa->obj->keylen)) - ob->obj->keylen; + return ((int) (oa->obj->keylen)) - ob->obj->keylen; } static int -ucl_hash_cmp_case_sens (const void *a, const void *b) +ucl_hash_cmp_case_sens(const void *a, const void *b) { - const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *)a, - *ob = (const struct ucl_hash_elt *)b; + const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *) a, + *ob = (const struct ucl_hash_elt *) b; if (oa->obj->keylen == ob->obj->keylen) { - return memcmp (oa->obj->key, ob->obj->key, oa->obj->keylen); + return memcmp(oa->obj->key, ob->obj->key, oa->obj->keylen); } - return ((int)(oa->obj->keylen)) - ob->obj->keylen; + return ((int) (oa->obj->keylen)) - ob->obj->keylen; } -void -ucl_hash_sort (ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl) +void ucl_hash_sort(ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl) { if (fl & UCL_SORT_KEYS_ICASE) { @@ -489,9 +490,10 @@ ucl_hash_sort (ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl) if (fl & UCL_SORT_KEYS_RECURSIVE) { struct ucl_hash_elt *elt; - DL_FOREACH(hashlin->head, elt) { - if (ucl_object_type (elt->obj) == UCL_OBJECT) { - ucl_hash_sort (elt->obj->value.ov, fl); + DL_FOREACH(hashlin->head, elt) + { + if (ucl_object_type(elt->obj) == UCL_OBJECT) { + ucl_hash_sort(elt->obj->value.ov, fl); } } } diff --git a/src/client/rspamc.cxx b/src/client/rspamc.cxx index d1b6a8ed0..af3276ede 100644 --- a/src/client/rspamc.cxx +++ b/src/client/rspamc.cxx @@ -91,10 +91,10 @@ std::vector children; static GPatternSpec **exclude_compiled = nullptr; static struct rspamd_http_context *http_ctx; -static gint retcode = EXIT_SUCCESS; +static int retcode = EXIT_SUCCESS; -static gboolean rspamc_password_callback(const gchar *option_name, - const gchar *value, +static gboolean rspamc_password_callback(const char *option_name, + const char *value, gpointer data, GError **error); @@ -496,8 +496,8 @@ auto sort_ucl_container_with_default(T &cont, const char *default_sort, static gboolean -rspamc_password_callback(const gchar *option_name, - const gchar *value, +rspamc_password_callback(const char *option_name, + const char *value, gpointer data, GError **error) { @@ -558,7 +558,7 @@ rspamc_password_callback(const gchar *option_name, * Parse command line */ static void -read_cmd_line(gint *argc, gchar ***argv) +read_cmd_line(int *argc, char ***argv) { GError *error = nullptr; GOptionContext *context; @@ -672,7 +672,7 @@ check_rspamc_command(const char *cmd) -> std::optional static void print_commands_list() { - guint cmd_len = 0; + unsigned int cmd_len = 0; rspamc_print(stdout, "Rspamc commands summary:\n"); @@ -1584,10 +1584,10 @@ rspamc_output_headers(FILE *out, struct rspamd_http_message *msg) static void rspamc_mime_output(FILE *out, ucl_object_t *result, GString *input, - gdouble time, GError *err) + double time, GError *err) { - const gchar *action = "no action", *line_end = "\r\n", *p; - gdouble score = 0.0, required_score = 0.0; + const char *action = "no action", *line_end = "\r\n", *p; + double score = 0.0, required_score = 0.0; gboolean is_spam = FALSE; auto nl_type = RSPAMD_TASK_NEWLINES_CRLF; @@ -1748,10 +1748,10 @@ rspamc_mime_output(FILE *out, ucl_object_t *result, GString *input, static void rspamc_client_execute_cmd(const struct rspamc_command &cmd, ucl_object_t *result, - GString *input, gdouble time, GError *err) + GString *input, double time, GError *err) { - gchar **eargv; - gint eargc, infd, outfd, errfd; + char **eargv; + int eargc, infd, outfd, errfd; GError *exec_err = nullptr; GPid cld; @@ -1814,13 +1814,13 @@ static void rspamc_client_cb(struct rspamd_client_connection *conn, struct rspamd_http_message *msg, const char *name, ucl_object_t *result, GString *input, - gpointer ud, gdouble start_time, gdouble send_time, + gpointer ud, double start_time, double send_time, const char *body, gsize bodylen, GError *err) { struct rspamc_callback_data *cbdata = (struct rspamc_callback_data *) ud; FILE *out = stdout; - gdouble finish = rspamd_get_ticks(FALSE), diff; + double finish = rspamd_get_ticks(FALSE), diff; auto &cmd = cbdata->cmd; @@ -1939,7 +1939,7 @@ rspamc_process_input(struct ev_loop *ev_base, const struct rspamc_command &cmd, { struct rspamd_client_connection *conn; const char *p; - guint16 port; + uint16_t port; GError *err = nullptr; std::string hostbuf; diff --git a/src/client/rspamdclient.c b/src/client/rspamdclient.c index e77f662eb..2b8d0e9bb 100644 --- a/src/client/rspamdclient.c +++ b/src/client/rspamdclient.c @@ -38,7 +38,7 @@ struct rspamd_client_request; * Since rspamd uses untagged HTTP we can pass a single message per socket */ struct rspamd_client_connection { - gint fd; + int fd; GString *server_name; struct rspamd_cryptobox_pubkey *key; struct rspamd_cryptobox_keypair *keypair; @@ -46,8 +46,8 @@ struct rspamd_client_connection { ev_tstamp timeout; struct rspamd_http_connection *http_conn; gboolean req_sent; - gdouble start_time; - gdouble send_time; + double start_time; + double send_time; struct rspamd_client_request *req; struct rspamd_keypair_cache *keys_cache; }; @@ -82,10 +82,10 @@ rspamd_client_request_free(struct rspamd_client_request *req) } } -static gint +static int rspamd_client_body_handler(struct rspamd_http_connection *conn, struct rspamd_http_message *msg, - const gchar *chunk, gsize len) + const char *chunk, gsize len) { /* Do nothing here */ return 0; @@ -104,7 +104,7 @@ rspamd_client_error_handler(struct rspamd_http_connection *conn, GError *err) c->start_time, c->send_time, NULL, 0, err); } -static gint +static int rspamd_client_finish_handler(struct rspamd_http_connection *conn, struct rspamd_http_message *msg) { @@ -114,8 +114,8 @@ rspamd_client_finish_handler(struct rspamd_http_connection *conn, struct ucl_parser *parser; GError *err; const rspamd_ftok_t *tok; - const gchar *start, *body = NULL; - guchar *out = NULL; + const char *start, *body = NULL; + unsigned char *out = NULL; gsize len, bodylen = 0; c = req->conn; @@ -134,7 +134,7 @@ rspamd_client_finish_handler(struct rspamd_http_connection *conn, if (rspamd_http_message_get_body(msg, NULL) == NULL || msg->code / 100 != 2) { err = g_error_new(RCLIENT_ERROR, msg->code, "HTTP error: %d, %.*s", msg->code, - (gint) msg->status->len, msg->status->str); + (int) msg->status->len, msg->status->str); req->cb(c, msg, c->server_name->str, NULL, req->input, req->ud, c->start_time, c->send_time, body, bodylen, err); g_error_free(err); @@ -263,11 +263,11 @@ end: struct rspamd_client_connection * rspamd_client_init(struct rspamd_http_context *http_ctx, - struct ev_loop *ev_base, const gchar *name, - guint16 port, gdouble timeout, const gchar *key) + struct ev_loop *ev_base, const char *name, + uint16_t port, double timeout, const char *key) { struct rspamd_client_connection *conn; - gint fd; + int fd; fd = rspamd_socket(name, port, SOCK_STREAM, TRUE, FALSE, TRUE); @@ -321,21 +321,21 @@ rspamd_client_init(struct rspamd_http_context *http_ctx, gboolean rspamd_client_command(struct rspamd_client_connection *conn, - const gchar *command, GQueue *attrs, + const char *command, GQueue *attrs, FILE *in, rspamd_client_callback cb, gpointer ud, gboolean compressed, - const gchar *comp_dictionary, - const gchar *filename, + const char *comp_dictionary, + const char *filename, GError **err) { struct rspamd_client_request *req; struct rspamd_http_client_header *nh; - gchar *p; + char *p; gsize remain, old_len; GList *cur; GString *input = NULL; rspamd_fstring_t *body; - guint dict_id = 0; + unsigned int dict_id = 0; gsize dict_len = 0; void *dict = NULL; ZSTD_CCtx *zctx; @@ -445,7 +445,7 @@ rspamd_client_command(struct rspamd_client_connection *conn, rspamd_http_message_add_header(req->msg, COMPRESSION_HEADER, "zstd"); if (dict_id != 0) { - gchar dict_str[32]; + char dict_str[32]; rspamd_snprintf(dict_str, sizeof(dict_str), "%ud", dict_id); rspamd_http_message_add_header(req->msg, "Dictionary", dict_str); diff --git a/src/client/rspamdclient.h b/src/client/rspamdclient.h index 27597dfb2..094676cfb 100644 --- a/src/client/rspamdclient.h +++ b/src/client/rspamdclient.h @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,8 +28,8 @@ struct rspamd_client_connection; struct rspamd_http_message; struct rspamd_http_client_header { - gchar *name; - gchar *value; + char *name; + char *value; }; /** @@ -43,13 +43,13 @@ struct rspamd_http_client_header { typedef void (*rspamd_client_callback)( struct rspamd_client_connection *conn, struct rspamd_http_message *msg, - const gchar *name, + const char *name, ucl_object_t *result, GString *input, gpointer ud, - gdouble start_time, - gdouble send_time, - const gchar *body, + double start_time, + double send_time, + const char *body, gsize body_len, GError *err); @@ -66,10 +66,10 @@ struct rspamd_http_context; struct rspamd_client_connection *rspamd_client_init( struct rspamd_http_context *http_ctx, struct ev_loop *ev_base, - const gchar *name, - guint16 port, - gdouble timeout, - const gchar *key); + const char *name, + uint16_t port, + double timeout, + const char *key); /** * @@ -83,14 +83,14 @@ struct rspamd_client_connection *rspamd_client_init( */ gboolean rspamd_client_command( struct rspamd_client_connection *conn, - const gchar *command, + const char *command, GQueue *attrs, FILE *in, rspamd_client_callback cb, gpointer ud, gboolean compressed, - const gchar *comp_dictionary, - const gchar *filename, + const char *comp_dictionary, + const char *filename, GError **err); /** diff --git a/src/controller.c b/src/controller.c index 9e61ad4d1..b287f89d8 100644 --- a/src/controller.c +++ b/src/controller.c @@ -140,9 +140,9 @@ struct rspamd_controller_worker_ctx { /* Whether we use ssl for this server */ gboolean use_ssl; /* Webui password */ - gchar *password; + char *password; /* Privileged password */ - gchar *enable_password; + char *enable_password; /* Cached versions of the passwords */ rspamd_ftok_t cached_password; rspamd_ftok_t cached_enable_password; @@ -154,15 +154,15 @@ struct rspamd_controller_worker_ctx { /* Main server */ struct rspamd_main *srv; /* SSL cert */ - gchar *ssl_cert; + char *ssl_cert; /* SSL private key */ - gchar *ssl_key; + char *ssl_key; /* A map of secure IP */ const ucl_object_t *secure_ip; struct rspamd_radix_map_helper *secure_map; /* Static files dir */ - gchar *static_files_dir; + char *static_files_dir; /* Custom commands registered by plugins */ GHashTable *custom_commands; @@ -178,31 +178,31 @@ struct rspamd_controller_worker_ctx { struct rspamd_rrd_file *rrd; struct rspamd_lang_detector *lang_det; - gdouble task_timeout; + double task_timeout; /* Health check stuff */ - guint workers_count; - guint scanners_count; - guint workers_hb_lost; + unsigned int workers_count; + unsigned int scanners_count; + unsigned int workers_hb_lost; ev_timer health_check_timer; }; struct rspamd_controller_plugin_cbdata { lua_State *L; struct rspamd_controller_worker_ctx *ctx; - gchar *plugin; + char *plugin; struct ucl_lua_funcdata *handler; ucl_object_t *obj; gboolean is_enable; gboolean need_task; - guint version; + unsigned int version; }; static gboolean -rspamd_is_encrypted_password(const gchar *password, +rspamd_is_encrypted_password(const char *password, struct rspamd_controller_pbkdf const **pbkdf) { - const gchar *start, *end; + const char *start, *end; int64_t id; gsize size, i; gboolean ret = FALSE; @@ -220,7 +220,7 @@ rspamd_is_encrypted_password(const gchar *password, } if (size > 0) { - gchar *endptr; + char *endptr; id = strtoul(start, &endptr, 10); if ((endptr == NULL || *endptr == *end)) { @@ -243,11 +243,11 @@ rspamd_is_encrypted_password(const gchar *password, return ret; } -static const gchar * -rspamd_encrypted_password_get_str(const gchar *password, gsize skip, +static const char * +rspamd_encrypted_password_get_str(const char *password, gsize skip, gsize *length) { - const gchar *str, *start, *end; + const char *str, *start, *end; gsize size; start = password + skip; @@ -272,15 +272,15 @@ rspamd_encrypted_password_get_str(const gchar *password, gsize skip, static gboolean rspamd_check_encrypted_password(struct rspamd_controller_worker_ctx *ctx, - const rspamd_ftok_t *password, const gchar *check, + const rspamd_ftok_t *password, const char *check, const struct rspamd_controller_pbkdf *pbkdf, gboolean is_enable) { - const gchar *salt, *hash; - gchar *salt_decoded, *key_decoded; + const char *salt, *hash; + char *salt_decoded, *key_decoded; gsize salt_len = 0, key_len = 0; gboolean ret = TRUE; - guchar *local_key; + unsigned char *local_key; rspamd_ftok_t *cache; gpointer m; @@ -412,17 +412,17 @@ check_uncached: * @return 0 if no forwarded found, 1 if forwarded found and it is yet trusted * and -1 if forwarded is denied */ -static gint +static int rspamd_controller_check_forwarded(struct rspamd_controller_session *session, struct rspamd_http_message *msg, struct rspamd_controller_worker_ctx *ctx) { const rspamd_ftok_t *hdr; - const gchar *comma; + const char *comma; const char *hdr_name = "X-Forwarded-For", *alt_hdr_name = "X-Real-IP"; char ip_buf[INET6_ADDRSTRLEN + 1]; rspamd_inet_addr_t *addr = NULL; - gint ret = 0; + int ret = 0; hdr = rspamd_http_message_find_header(msg, hdr_name); @@ -508,7 +508,7 @@ rspamd_controller_check_password(struct rspamd_http_connection_entry *entry, struct rspamd_controller_session *session, struct rspamd_http_message *msg, gboolean is_enable) { - const gchar *check; + const char *check; const rspamd_ftok_t *password; rspamd_ftok_t lookup; GHashTable *query_args = NULL; @@ -562,7 +562,7 @@ rspamd_controller_check_password(struct rspamd_http_connection_entry *entry, /* Try to get password from query args */ query_args = rspamd_http_message_parse_query(msg); - lookup.begin = (gchar *) "password"; + lookup.begin = (char *) "password"; lookup.len = sizeof("password") - 1; password = g_hash_table_lookup(query_args, &lookup); @@ -830,7 +830,7 @@ rspamd_controller_handle_symbols(struct rspamd_http_connection_entry *conn_ent, group_symbols = ucl_object_typed_new(UCL_ARRAY); while (g_hash_table_iter_next(&sit, &k, &v)) { - gdouble tm = 0.0, freq = 0, freq_dev = 0; + double tm = 0.0, freq = 0, freq_dev = 0; sym = v; sym_obj = ucl_object_typed_new(UCL_OBJECT); @@ -918,7 +918,7 @@ rspamd_controller_handle_actions(struct rspamd_http_connection_entry *conn_ent, static gboolean rspamd_controller_can_edit_map(struct rspamd_map_backend *bk) { - gchar *fpath; + char *fpath; if (access(bk->uri, W_OK) == 0) { return TRUE; @@ -961,7 +961,7 @@ rspamd_controller_handle_maps(struct rspamd_http_connection_entry *conn_ent, GList *cur; struct rspamd_map *map; struct rspamd_map_backend *bk; - guint i; + unsigned int i; gboolean editable; ucl_object_t *obj, *top; @@ -1026,7 +1026,7 @@ rspamd_controller_handle_get_map(struct rspamd_http_connection_entry *conn_ent, struct rspamd_map_backend *bk = NULL; const rspamd_ftok_t *idstr; struct stat st; - gint fd; + int fd; gulong id, i; gboolean found = FALSE; struct rspamd_http_message *reply; @@ -1111,7 +1111,7 @@ rspamd_controller_handle_get_map(struct rspamd_http_connection_entry *conn_ent, static ucl_object_t * rspamd_controller_pie_element(enum rspamd_action_type action, - const char *label, gdouble data) + const char *label, double data) { ucl_object_t *res = ucl_object_typed_new(UCL_OBJECT); const char *colors[METRIC_ACTION_MAX] = { @@ -1148,7 +1148,7 @@ rspamd_controller_handle_pie_chart( { struct rspamd_controller_session *session = conn_ent->ud; struct rspamd_controller_worker_ctx *ctx; - gdouble data[5], total; + double data[5], total; ucl_object_t *top; ctx = session->ctx; @@ -1190,13 +1190,13 @@ rspamd_controller_handle_pie_chart( void rspamd_controller_graph_point(gulong t, gulong step, struct rspamd_rrd_query_result *rrd_result, - gdouble *acc, + double *acc, ucl_object_t **elt) { - guint nan_cnt; - gdouble sum = 0.0, yval; + unsigned int nan_cnt; + double sum = 0.0, yval; ucl_object_t *data_elt; - guint i, j; + unsigned int i, j; for (i = 0; i < rrd_result->ds_count; i++) { sum = 0.0; @@ -1219,7 +1219,7 @@ void rspamd_controller_graph_point(gulong t, gulong step, } else { ucl_object_insert_key(data_elt, - ucl_object_fromdouble(sum / (gdouble) step), "y", 1, + ucl_object_fromdouble(sum / (double) step), "y", 1, false); } ucl_array_append(elt[i], data_elt); @@ -1247,7 +1247,7 @@ rspamd_controller_handle_graph( rspamd_ftok_t srch, *value; struct rspamd_rrd_query_result *rrd_result; gulong i, k, start_row, cnt, t, ts, step; - gdouble *acc; + double *acc; ucl_object_t *res, *elt[METRIC_ACTION_MAX]; enum { rra_day = 0, @@ -1257,7 +1257,7 @@ rspamd_controller_handle_graph( rra_invalid } rra_num = rra_invalid; /* How many points are we going to send to display */ - static const guint desired_points = 500; + static const unsigned int desired_points = 500; ctx = session->ctx; @@ -1273,7 +1273,7 @@ rspamd_controller_handle_graph( } query = rspamd_http_message_parse_query(msg); - srch.begin = (gchar *) "type"; + srch.begin = (char *) "type"; srch.len = 4; if (query == NULL || (value = g_hash_table_lookup(query, &srch)) == NULL) { @@ -1333,7 +1333,7 @@ rspamd_controller_handle_graph( k = 0; /* Create window */ - step = ceil(((gdouble) rrd_result->rra_rows) / desired_points); + step = ceil(((double) rrd_result->rra_rows) / desired_points); g_assert(step >= 1); acc = g_malloc0(sizeof(double) * rrd_result->ds_count * step); @@ -1342,7 +1342,7 @@ rspamd_controller_handle_graph( memcpy(&acc[k * rrd_result->ds_count], &rrd_result->data[i * rrd_result->ds_count], - sizeof(gdouble) * rrd_result->ds_count); + sizeof(double) * rrd_result->ds_count); if (k < step - 1) { k++; @@ -1389,9 +1389,9 @@ rspamd_controller_handle_legacy_history( struct rspamd_http_message *msg) { struct roll_history_row *row, *copied_rows; - guint i, rows_proc, row_num; + unsigned int i, rows_proc, row_num; struct tm tm; - gchar timebuf[32], **syms; + char timebuf[32], **syms; ucl_object_t *top, *obj; top = ucl_object_typed_new(UCL_ARRAY); @@ -1446,11 +1446,11 @@ rspamd_controller_handle_legacy_history( syms = g_strsplit_set(row->symbols, ", ", -1); if (syms) { - guint nelts = g_strv_length(syms); + unsigned int nelts = g_strv_length(syms); ucl_object_t *syms_obj = ucl_object_typed_new(UCL_OBJECT); ucl_object_reserve(syms_obj, nelts); - for (guint j = 0; j < nelts; j++) { + for (unsigned int j = 0; j < nelts; j++) { g_strstrip(syms[j]); if (strlen(syms[j]) == 0) { @@ -1755,7 +1755,7 @@ rspamd_controller_handle_history_reset(struct rspamd_http_connection_entry *conn struct rspamd_controller_session *session = conn_ent->ud; struct rspamd_controller_worker_ctx *ctx; struct roll_history_row *row; - guint completed_rows, i, t; + unsigned int completed_rows, i, t; lua_State *L; ctx = session->ctx; @@ -1820,7 +1820,7 @@ rspamd_controller_handle_lua(struct rspamd_http_connection_entry *conn_ent, struct rspamd_task *task, **ptask; struct rspamd_http_connection_entry **pconn; struct rspamd_controller_worker_ctx *ctx; - gchar filebuf[PATH_MAX], realbuf[PATH_MAX]; + char filebuf[PATH_MAX], realbuf[PATH_MAX]; struct http_parser_url u; rspamd_ftok_t lookup; struct stat st; @@ -2237,9 +2237,9 @@ rspamd_controller_handle_saveactions( ucl_object_t *obj; const ucl_object_t *cur; struct rspamd_controller_worker_ctx *ctx; - const gchar *error; - gdouble score; - gint i, added = 0; + const char *error; + double score; + int i, added = 0; enum rspamd_action_type act; ucl_object_iter_t it = NULL; @@ -2361,8 +2361,8 @@ rspamd_controller_handle_savesymbols( const ucl_object_t *cur, *jname, *jvalue; ucl_object_iter_t iter = NULL; struct rspamd_controller_worker_ctx *ctx; - const gchar *error; - gdouble val; + const char *error; + double val; struct rspamd_symbol *sym; int added = 0; @@ -2492,8 +2492,8 @@ rspamd_controller_handle_savemap(struct rspamd_http_connection_entry *conn_ent, const rspamd_ftok_t *idstr; gulong id, i; gboolean found = FALSE; - gchar tempname[PATH_MAX]; - gint fd; + char tempname[PATH_MAX]; + int fd; ctx = session->ctx; @@ -2658,7 +2658,7 @@ rspamd_controller_handle_stat_common( { struct rspamd_controller_session *session = conn_ent->ud; ucl_object_t *top, *sub; - gint i; + int i; int64_t uptime; uint64_t spam = 0, ham = 0; rspamd_mempool_stat_t mem_st; @@ -2839,7 +2839,7 @@ rspamd_controller_metrics_fin_task(void *ud) ucl_object_t *top; struct rspamd_fuzzy_stat_entry *entry; rspamd_fstring_t *output; - gint i; + int i; conn_ent = cbdata->conn_ent; top = cbdata->top; @@ -3095,7 +3095,7 @@ rspamd_controller_handle_metrics_common( { struct rspamd_controller_session *session = conn_ent->ud; ucl_object_t *top, *sub; - gint i; + int i; int64_t uptime; uint64_t spam = 0, ham = 0; rspamd_mempool_stat_t mem_st; @@ -3270,7 +3270,7 @@ rspamd_controller_handle_custom(struct rspamd_http_connection_entry *conn_ent, { struct rspamd_controller_session *session = conn_ent->ud; struct rspamd_custom_controller_command *cmd; - gchar *url_str; + char *url_str; struct http_parser_url u; rspamd_ftok_t lookup; @@ -3281,7 +3281,7 @@ rspamd_controller_handle_custom(struct rspamd_http_connection_entry *conn_ent, lookup.begin = msg->url->str + u.field_data[UF_PATH].off; lookup.len = u.field_data[UF_PATH].len; - rspamd_normalize_path_inplace((gchar *) lookup.begin, + rspamd_normalize_path_inplace((char *) lookup.begin, lookup.len, &unnorm_len); lookup.len = unnorm_len; @@ -3488,7 +3488,7 @@ rspamd_controller_handle_lua_plugin(struct rspamd_http_connection_entry *conn_en lookup.begin = msg->url->str + u.field_data[UF_PATH].off; lookup.len = u.field_data[UF_PATH].len; - rspamd_normalize_path_inplace((gchar *) lookup.begin, + rspamd_normalize_path_inplace((char *) lookup.begin, lookup.len, &unnorm_len); lookup.len = unnorm_len; @@ -3631,7 +3631,7 @@ rspamd_controller_accept_socket(EV_P_ ev_io *w, int revents) struct rspamd_controller_worker_ctx *ctx; struct rspamd_controller_session *session; rspamd_inet_addr_t *addr = NULL; - gint nfd; + int nfd; ctx = worker->ctx; @@ -3664,7 +3664,7 @@ rspamd_controller_accept_socket(EV_P_ ev_io *w, int revents) static void rspamd_controller_password_sane(struct rspamd_controller_worker_ctx *ctx, - const gchar *password, const gchar *type) + const char *password, const char *type) { const struct rspamd_controller_pbkdf *pbkdf = &pbkdf_list[0]; @@ -3833,7 +3833,7 @@ luaopen_controller(lua_State *L) } struct rspamd_http_connection_entry * -lua_check_controller_entry(lua_State *L, gint pos) +lua_check_controller_entry(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_csession_classname); luaL_argcheck(L, ud != NULL, pos, "'csession' expected"); @@ -3903,8 +3903,8 @@ static int lua_csession_send_error(lua_State *L) { struct rspamd_http_connection_entry *c = lua_check_controller_entry(L, 1); - guint err_code = lua_tonumber(L, 2); - const gchar *err_str = lua_tostring(L, 3); + unsigned int err_code = lua_tonumber(L, 2); + const char *err_str = lua_tostring(L, 3); if (c) { rspamd_controller_send_error(c, err_code, "%s", err_str); @@ -3920,7 +3920,7 @@ static int lua_csession_send_string(lua_State *L) { struct rspamd_http_connection_entry *c = lua_check_controller_entry(L, 1); - const gchar *str = lua_tostring(L, 2); + const char *str = lua_tostring(L, 2); if (c) { rspamd_controller_send_string(c, str); @@ -3947,8 +3947,8 @@ rspamd_controller_register_plugin_path(lua_State *L, struct rspamd_controller_worker_ctx *ctx, const ucl_object_t *webui_data, const ucl_object_t *handler, - const gchar *path, - const gchar *plugin_name) + const char *path, + const char *plugin_name) { struct rspamd_controller_plugin_cbdata *cbd; const ucl_object_t *elt; @@ -4040,7 +4040,7 @@ rspamd_controller_register_plugins_paths(struct rspamd_controller_worker_ctx *ct static void rspamd_controller_health_rep(struct rspamd_worker *worker, - struct rspamd_srv_reply *rep, gint rep_fd, + struct rspamd_srv_reply *rep, int rep_fd, gpointer ud) { struct rspamd_controller_worker_ctx *ctx = (struct rspamd_controller_worker_ctx *) ud; @@ -4075,7 +4075,7 @@ start_controller_worker(struct rspamd_worker *worker) struct module_ctx *mctx; GHashTableIter iter; gpointer key, value; - guint i; + unsigned int i; gpointer m; g_assert(rspamd_worker_check_context(worker->ctx, rspamd_controller_ctx_magic)); diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 05749d899..445289511 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -51,7 +51,7 @@ /* Update stats on keys each 1 hour */ #define KEY_STAT_INTERVAL 3600.0 -static const gchar *local_db_name = "local"; +static const char *local_db_name = "local"; /* Init functions */ gpointer init_fuzzy(struct rspamd_config *cfg); @@ -91,7 +91,7 @@ struct fuzzy_key_stat { /* Store averages for checked/matched per minute */ struct rspamd_counter_data checked_ctr; struct rspamd_counter_data matched_ctr; - gdouble last_checked_time; + double last_checked_time; uint64_t last_checked_count; uint64_t last_matched_count; struct rspamd_cryptobox_keypair *keypair; @@ -102,8 +102,8 @@ struct fuzzy_key_stat { struct rspamd_leaky_bucket_elt { rspamd_inet_addr_t *addr; - gdouble last; - gdouble cur; + double last; + double cur; }; static const uint64_t rspamd_fuzzy_storage_magic = 0x291a3253eb1b3ea5ULL; @@ -119,7 +119,7 @@ fuzzy_kp_hash(const unsigned char *p) static bool fuzzy_kp_equal(gconstpointer a, gconstpointer b) { - const guchar *pa = a, *pb = b; + const unsigned char *pa = a, *pb = b; return (memcmp(pa, pb, RSPAMD_FUZZY_KEYLEN) == 0); } @@ -150,9 +150,9 @@ struct rspamd_fuzzy_storage_ctx { struct rspamd_config *cfg; /* END OF COMMON PART */ struct fuzzy_global_stat stat; - gdouble expire; - gdouble sync_timeout; - gdouble delay; + double expire; + double sync_timeout; + double delay; struct rspamd_radix_map_helper *update_ips; struct rspamd_hash_map_helper *update_keys; struct rspamd_radix_map_helper *blocked_ips; @@ -166,7 +166,7 @@ struct rspamd_fuzzy_storage_ctx { const ucl_object_t *ratelimit_whitelist_map; const ucl_object_t *dynamic_keys_map; - guint keypair_cache_size; + unsigned int keypair_cache_size; ev_timer stat_ev; ev_io peer_ev; @@ -186,25 +186,25 @@ struct rspamd_fuzzy_storage_ctx { rspamd_lru_hash_t *ratelimit_buckets; struct rspamd_fuzzy_backend *backend; GArray *updates_pending; - guint updates_failed; - guint updates_maxfail; + unsigned int updates_failed; + unsigned int updates_maxfail; /* Used to send data between workers */ - gint peer_fd; + int peer_fd; /* Ratelimits */ - guint leaky_bucket_ttl; - guint leaky_bucket_mask; - guint max_buckets; + unsigned int leaky_bucket_ttl; + unsigned int leaky_bucket_mask; + unsigned int max_buckets; gboolean ratelimit_log_only; - gdouble leaky_bucket_burst; - gdouble leaky_bucket_rate; + double leaky_bucket_burst; + double leaky_bucket_rate; struct rspamd_worker *worker; const ucl_object_t *skip_map; struct rspamd_hash_map_helper *skip_hashes; - gint lua_pre_handler_cbref; - gint lua_post_handler_cbref; - gint lua_blacklist_cbref; + int lua_pre_handler_cbref; + int lua_post_handler_cbref; + int lua_blacklist_cbref; khash_t(fuzzy_key_ids_set) * default_forbidden_ids; /* Ids that should not override other ids */ khash_t(fuzzy_key_ids_set) * weak_ids; @@ -228,13 +228,13 @@ struct fuzzy_session { enum rspamd_fuzzy_epoch epoch; enum fuzzy_cmd_type cmd_type; - gint fd; + int fd; ev_tstamp timestamp; struct ev_io io; ref_entry_t ref; struct fuzzy_key *key; struct rspamd_fuzzy_cmd_extension *extensions; - guchar nm[rspamd_cryptobox_MAX_NMBYTES]; + unsigned char nm[rspamd_cryptobox_MAX_NMBYTES]; }; struct fuzzy_peer_request { @@ -245,19 +245,19 @@ struct fuzzy_peer_request { struct rspamd_updates_cbdata { GArray *updates_pending; struct rspamd_fuzzy_storage_ctx *ctx; - gchar *source; + char *source; gboolean final; }; static void rspamd_fuzzy_write_reply(struct fuzzy_session *session); static gboolean rspamd_fuzzy_process_updates_queue(struct rspamd_fuzzy_storage_ctx *ctx, - const gchar *source, gboolean final); + const char *source, gboolean final); static gboolean rspamd_fuzzy_check_client(struct rspamd_fuzzy_storage_ctx *ctx, rspamd_inet_addr_t *addr); static void rspamd_fuzzy_maybe_call_blacklisted(struct rspamd_fuzzy_storage_ctx *ctx, rspamd_inet_addr_t *addr, - const gchar *reason); + const char *reason); static struct fuzzy_key *fuzzy_add_keypair_from_ucl(const ucl_object_t *obj, khash_t(rspamd_fuzzy_keys_hash) * target); @@ -267,9 +267,9 @@ struct fuzzy_keymap_ucl_buf { }; /* Callbacks for reading json dynamic rules */ -static gchar * -ucl_keymap_read_cb(gchar *chunk, - gint len, +static char * +ucl_keymap_read_cb(char *chunk, + int len, struct map_cb_data *data, gboolean final) { @@ -540,11 +540,11 @@ rspamd_fuzzy_check_ratelimit(struct fuzzy_session *session) static void rspamd_fuzzy_maybe_call_blacklisted(struct rspamd_fuzzy_storage_ctx *ctx, rspamd_inet_addr_t *addr, - const gchar *reason) + const char *reason) { if (ctx->lua_blacklist_cbref != -1) { lua_State *L = ctx->cfg->lua_state; - gint err_idx, ret; + int err_idx, ret; lua_pushcfunction(L, &rspamd_lua_traceback); err_idx = lua_gettop(L); @@ -601,13 +601,13 @@ rspamd_fuzzy_check_write(struct fuzzy_session *session) } if (session->ctx->update_keys != NULL && session->key->stat && session->key->key) { - static gchar base32_buf[rspamd_cryptobox_HASHBYTES * 2 + 1]; - guint raw_len; - const guchar *pk_raw = rspamd_keypair_component(session->key->key, - RSPAMD_KEYPAIR_COMPONENT_ID, &raw_len); - gint encoded_len = rspamd_encode_base32_buf(pk_raw, raw_len, - base32_buf, sizeof(base32_buf), - RSPAMD_BASE32_DEFAULT); + static char base32_buf[rspamd_cryptobox_HASHBYTES * 2 + 1]; + unsigned int raw_len; + const unsigned char *pk_raw = rspamd_keypair_component(session->key->key, + RSPAMD_KEYPAIR_COMPONENT_ID, &raw_len); + int encoded_len = rspamd_encode_base32_buf(pk_raw, raw_len, + base32_buf, sizeof(base32_buf), + RSPAMD_BASE32_DEFAULT); if (rspamd_match_hash_map(session->ctx->update_keys, base32_buf, encoded_len)) { return TRUE; @@ -715,15 +715,15 @@ fuzzy_update_version_callback(uint64_t ver, void *ud) static void rspamd_fuzzy_updates_cb(gboolean success, - guint nadded, - guint ndeleted, - guint nextended, - guint nignored, + unsigned int nadded, + unsigned int ndeleted, + unsigned int nextended, + unsigned int nignored, void *ud) { struct rspamd_updates_cbdata *cbdata = ud; struct rspamd_fuzzy_storage_ctx *ctx; - const gchar *source; + const char *source; ctx = cbdata->ctx; source = cbdata->source; @@ -798,7 +798,7 @@ rspamd_fuzzy_updates_cb(gboolean success, static gboolean rspamd_fuzzy_process_updates_queue(struct rspamd_fuzzy_storage_ctx *ctx, - const gchar *source, gboolean final) + const char *source, gboolean final) { struct rspamd_updates_cbdata *cbdata; @@ -886,7 +886,7 @@ rspamd_fuzzy_write_reply(struct fuzzy_session *session) static void rspamd_fuzzy_update_key_stat(gboolean matched, struct fuzzy_key_stat *key_stat, - guint cmd, + unsigned int cmd, struct rspamd_fuzzy_reply *res, ev_tstamp timestamp) { @@ -934,7 +934,7 @@ rspamd_fuzzy_update_stats(struct rspamd_fuzzy_storage_ctx *ctx, gboolean is_delayed, struct fuzzy_key *key, struct fuzzy_key_stat *ip_stat, - guint cmd, + unsigned int cmd, struct rspamd_fuzzy_reply *res, ev_tstamp timestamp) { @@ -1003,7 +1003,7 @@ static void rspamd_fuzzy_make_reply(struct rspamd_fuzzy_cmd *cmd, struct rspamd_fuzzy_reply *result, struct fuzzy_session *session, - gint flags) + int flags) { gsize len; @@ -1084,7 +1084,7 @@ rspamd_fuzzy_make_reply(struct rspamd_fuzzy_cmd *cmd, session->timestamp); } - rspamd_cryptobox_encrypt_nm_inplace((guchar *) &session->reply.rep, + rspamd_cryptobox_encrypt_nm_inplace((unsigned char *) &session->reply.rep, len, session->reply.hdr.nonce, session->nm, @@ -1118,7 +1118,7 @@ rspamd_fuzzy_make_reply(struct rspamd_fuzzy_cmd *cmd, } static gboolean -fuzzy_peer_try_send(gint fd, struct fuzzy_peer_request *up_req) +fuzzy_peer_try_send(int fd, struct fuzzy_peer_request *up_req) { gssize r; @@ -1184,7 +1184,7 @@ rspamd_fuzzy_check_callback(struct rspamd_fuzzy_reply *result, void *ud) struct rspamd_fuzzy_cmd *cmd = NULL; const struct rspamd_shingle *shingle = NULL; struct rspamd_shingle sgl_cpy; - gint send_flags = 0; + int send_flags = 0; switch (session->cmd_type) { case CMD_ENCRYPTED_NORMAL: @@ -1211,7 +1211,7 @@ rspamd_fuzzy_check_callback(struct rspamd_fuzzy_reply *result, void *ud) if (session->ctx->lua_post_handler_cbref != -1) { /* Start lua post handler */ lua_State *L = session->ctx->cfg->lua_state; - gint err_idx, ret; + int err_idx, ret; lua_pushcfunction(L, &rspamd_lua_traceback); err_idx = lua_gettop(L); @@ -1287,9 +1287,9 @@ rspamd_fuzzy_check_callback(struct rspamd_fuzzy_reply *result, void *ud) if (!isnan(session->ctx->delay) && rspamd_match_radix_map_addr(session->ctx->delay_whitelist, session->addr) == NULL) { - gdouble hash_age = rspamd_get_calendar_ticks() - result->ts; - gdouble jittered_age = rspamd_time_jitter(session->ctx->delay, - session->ctx->delay / 2.0); + double hash_age = rspamd_get_calendar_ticks() - result->ts; + double jittered_age = rspamd_time_jitter(session->ctx->delay, + session->ctx->delay / 2.0); if (hash_age < jittered_age) { send_flags |= RSPAMD_FUZZY_REPLY_DELAY; @@ -1360,11 +1360,11 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session) struct fuzzy_peer_cmd up_cmd; struct fuzzy_peer_request *up_req; struct fuzzy_key_stat *ip_stat = NULL; - gchar hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; + char hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; rspamd_inet_addr_t *naddr; gpointer ptr; gsize up_len = 0; - gint send_flags = 0; + int send_flags = 0; cmd = &session->cmd.basic; @@ -1401,7 +1401,7 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session) if (session->ctx->lua_pre_handler_cbref != -1) { /* Start lua pre handler */ lua_State *L = session->ctx->cfg->lua_state; - gint err_idx, ret; + int err_idx, ret; lua_pushcfunction(L, &rspamd_lua_traceback); err_idx = lua_gettop(L); @@ -1585,7 +1585,7 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session) static enum rspamd_fuzzy_epoch -rspamd_fuzzy_command_valid(struct rspamd_fuzzy_cmd *cmd, gint r) +rspamd_fuzzy_command_valid(struct rspamd_fuzzy_cmd *cmd, int r) { enum rspamd_fuzzy_epoch ret = RSPAMD_FUZZY_EPOCH_MAX; @@ -1622,7 +1622,7 @@ rspamd_fuzzy_command_valid(struct rspamd_fuzzy_cmd *cmd, gint r) } static gboolean -rspamd_fuzzy_decrypt_command(struct fuzzy_session *s, guchar *buf, gsize buflen) +rspamd_fuzzy_decrypt_command(struct fuzzy_session *s, unsigned char *buf, gsize buflen) { struct rspamd_fuzzy_encrypted_req_hdr hdr; struct rspamd_cryptobox_pubkey *rk; @@ -1702,20 +1702,20 @@ rspamd_fuzzy_decrypt_command(struct fuzzy_session *s, guchar *buf, gsize buflen) static gboolean -rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize buflen) +rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, unsigned char *buf, gsize buflen) { struct rspamd_fuzzy_cmd_extension *ext, *prev_ext; - guchar *storage, *p = buf, *end = buf + buflen; + unsigned char *storage, *p = buf, *end = buf + buflen; gsize st_len = 0, n_ext = 0; /* Read number of extensions to allocate array */ while (p < end) { - guchar cmd = *p++; + unsigned char cmd = *p++; if (p < end) { if (cmd == RSPAMD_FUZZY_EXT_SOURCE_DOMAIN) { /* Next byte is buf length */ - guchar dom_len = *p++; + unsigned char dom_len = *p++; if (dom_len <= (end - p)) { st_len += dom_len; @@ -1772,19 +1772,19 @@ rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize bu storage = g_malloc(n_ext * sizeof(struct rspamd_fuzzy_cmd_extension) + st_len); - guchar *data_buf = storage + - n_ext * sizeof(struct rspamd_fuzzy_cmd_extension); + unsigned char *data_buf = storage + + n_ext * sizeof(struct rspamd_fuzzy_cmd_extension); ext = (struct rspamd_fuzzy_cmd_extension *) storage; /* All validation has been done, so we can just go further */ while (p < end) { prev_ext = ext; - guchar cmd = *p++; + unsigned char cmd = *p++; if (cmd == RSPAMD_FUZZY_EXT_SOURCE_DOMAIN) { /* Next byte is buf length */ - guchar dom_len = *p++; - guchar *dest = data_buf; + unsigned char dom_len = *p++; + unsigned char *dest = data_buf; ext->ext = RSPAMD_FUZZY_EXT_SOURCE_DOMAIN; ext->next = ext + 1; @@ -1796,7 +1796,7 @@ rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize bu ext = ext->next; } else if (cmd == RSPAMD_FUZZY_EXT_SOURCE_IP4) { - guchar *dest = data_buf; + unsigned char *dest = data_buf; ext->ext = RSPAMD_FUZZY_EXT_SOURCE_IP4; ext->next = ext + 1; @@ -1808,7 +1808,7 @@ rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize bu ext = ext->next; } else if (cmd == RSPAMD_FUZZY_EXT_SOURCE_IP6) { - guchar *dest = data_buf; + unsigned char *dest = data_buf; ext->ext = RSPAMD_FUZZY_EXT_SOURCE_IP6; ext->next = ext + 1; @@ -1836,7 +1836,7 @@ rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize bu } static gboolean -rspamd_fuzzy_cmd_from_wire(guchar *buf, guint buflen, struct fuzzy_session *s) +rspamd_fuzzy_cmd_from_wire(unsigned char *buf, unsigned int buflen, struct fuzzy_session *s) { enum rspamd_fuzzy_epoch epoch; gboolean encrypted = FALSE; @@ -1982,7 +1982,7 @@ accept_fuzzy_socket(EV_P_ ev_io *w, int revents) gssize r, msg_len; uint64_t *nerrors; struct iovec iovs[MSGVEC_LEN]; - guint8 bufs[MSGVEC_LEN][FUZZY_INPUT_BUFLEN]; + uint8_t bufs[MSGVEC_LEN][FUZZY_INPUT_BUFLEN]; union sa_union peer_sa[MSGVEC_LEN]; socklen_t salen = sizeof(peer_sa[0]); #ifdef HAVE_RECVMMSG @@ -2120,8 +2120,8 @@ rspamd_fuzzy_storage_periodic_callback(void *ud) static gboolean rspamd_fuzzy_storage_sync(struct rspamd_main *rspamd_main, - struct rspamd_worker *worker, gint fd, - gint attached_fd, + struct rspamd_worker *worker, int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud) { @@ -2147,8 +2147,8 @@ rspamd_fuzzy_storage_sync(struct rspamd_main *rspamd_main, static gboolean rspamd_fuzzy_control_blocked(struct rspamd_main *rspamd_main, - struct rspamd_worker *worker, gint fd, - gint attached_fd, + struct rspamd_worker *worker, int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud) { @@ -2223,8 +2223,8 @@ rspamd_fuzzy_control_blocked(struct rspamd_main *rspamd_main, static gboolean rspamd_fuzzy_storage_reload(struct rspamd_main *rspamd_main, - struct rspamd_worker *worker, gint fd, - gint attached_fd, + struct rspamd_worker *worker, int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud) { @@ -2295,7 +2295,7 @@ static void rspamd_fuzzy_key_stat_iter(const unsigned char *pk_iter, struct fuzzy_key *fuzzy_key, ucl_object_t *keys_obj, gboolean ip_stat) { struct fuzzy_key_stat *key_stat = fuzzy_key->stat; - gchar keyname[17]; + char keyname[17]; if (key_stat) { rspamd_snprintf(keyname, sizeof(keyname), "%8bs", pk_iter); @@ -2447,7 +2447,7 @@ rspamd_fuzzy_maybe_load_ratelimits(struct rspamd_fuzzy_storage_ctx *ctx) while ((cur = ucl_object_iterate(obj, &it, true)) != NULL) { const ucl_object_t *ip, *value, *last; - const gchar *ip_str; + const char *ip_str; double limit_val, last_val; ip = ucl_object_find_key(cur, "ip"); @@ -2642,8 +2642,8 @@ lua_fuzzy_add_blacklist_handler(lua_State *L) static gboolean rspamd_fuzzy_storage_stat(struct rspamd_main *rspamd_main, - struct rspamd_worker *worker, gint fd, - gint attached_fd, + struct rspamd_worker *worker, int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud) { @@ -2651,13 +2651,13 @@ rspamd_fuzzy_storage_stat(struct rspamd_main *rspamd_main, struct rspamd_control_reply rep; ucl_object_t *obj; struct ucl_emitter_functions *emit_subr; - guchar fdspace[CMSG_SPACE(sizeof(int))]; + unsigned char fdspace[CMSG_SPACE(sizeof(int))]; struct iovec iov; struct msghdr msg; struct cmsghdr *cmsg; - gint outfd = -1; - gchar tmppath[PATH_MAX]; + int outfd = -1; + char tmppath[PATH_MAX]; memset(&rep, 0, sizeof(rep)); rep.type = RSPAMD_CONTROL_FUZZY_STAT; @@ -2732,7 +2732,7 @@ fuzzy_parse_ids(rspamd_mempool_t *pool, struct rspamd_rcl_struct_parser *pd = (struct rspamd_rcl_struct_parser *) ud; khash_t(fuzzy_key_ids_set) * target; - target = *(khash_t(fuzzy_key_ids_set) **) ((gchar *) pd->user_struct + pd->offset); + target = *(khash_t(fuzzy_key_ids_set) **) ((char *) pd->user_struct + pd->offset); if (ucl_object_type(obj) == UCL_ARRAY) { const ucl_object_t *cur; @@ -2790,8 +2790,8 @@ fuzzy_add_keypair_from_ucl(const ucl_object_t *obj, khash_t(rspamd_fuzzy_keys_ha key->flags_stat = kh_init(fuzzy_key_flag_stat); /* Preallocate some space for flags */ kh_resize(fuzzy_key_flag_stat, key->flags_stat, 8); - const guchar *pk = rspamd_keypair_component(kp, RSPAMD_KEYPAIR_COMPONENT_PK, - NULL); + const unsigned char *pk = rspamd_keypair_component(kp, RSPAMD_KEYPAIR_COMPONENT_PK, + NULL); keystat->keypair = rspamd_keypair_ref(kp); /* We map entries by pubkey in binary form for faster lookup */ khiter_t k; @@ -3174,7 +3174,7 @@ rspamd_fuzzy_peer_io(EV_P_ ev_io *w, int revents) static void fuzzy_peer_rep(struct rspamd_worker *worker, - struct rspamd_srv_reply *rep, gint rep_fd, + struct rspamd_srv_reply *rep, int rep_fd, gpointer ud) { struct rspamd_fuzzy_storage_ctx *ctx = ud; diff --git a/src/hs_helper.c b/src/hs_helper.c index 8b40c8932..26d57528f 100644 --- a/src/hs_helper.c +++ b/src/hs_helper.c @@ -37,8 +37,8 @@ worker_t hs_helper_worker = { RSPAMD_WORKER_VER /* Version info */ }; -static const gdouble default_max_time = 1.0; -static const gdouble default_recompile_time = 60.0; +static const double default_max_time = 1.0; +static const double default_recompile_time = 60.0; static const uint64_t rspamd_hs_helper_magic = 0x22d310157a2288a0ULL; /* @@ -53,10 +53,10 @@ struct hs_helper_ctx { /* Config */ struct rspamd_config *cfg; /* END OF COMMON PART */ - gchar *hs_dir; + char *hs_dir; gboolean loaded; - gdouble max_time; - gdouble recompile_time; + double max_time; + double recompile_time; ev_timer recompile_timer; }; @@ -119,9 +119,9 @@ rspamd_hs_helper_cleanup_dir(struct hs_helper_ctx *ctx, gboolean forced) { struct stat st; glob_t globbuf; - guint len, i; - gint rc; - gchar *pattern; + unsigned int len, i; + int rc; + char *pattern; gboolean ret = TRUE; pid_t our_pid = getpid(); @@ -186,9 +186,9 @@ rspamd_hs_helper_cleanup_dir(struct hs_helper_ctx *ctx, gboolean forced) if ((rc = glob(pattern, 0, NULL, &globbuf)) == 0) { for (i = 0; i < globbuf.gl_pathc; i++) { /* Check if we have a pid in the filename */ - const gchar *end_num = globbuf.gl_pathv[i] + - strlen(globbuf.gl_pathv[i]) - (sizeof(".hs.new") - 1); - const gchar *p = end_num - 1; + const char *end_num = globbuf.gl_pathv[i] + + strlen(globbuf.gl_pathv[i]) - (sizeof(".hs.new") - 1); + const char *p = end_num - 1; pid_t foreign_pid = -1; while (p > globbuf.gl_pathv[i]) { @@ -270,7 +270,7 @@ rspamd_rs_delayed_cb(EV_P_ ev_timer *w, int revents) } static void -rspamd_rs_compile_cb(guint ncompiled, GError *err, void *cbd) +rspamd_rs_compile_cb(unsigned int ncompiled, GError *err, void *cbd) { struct rspamd_worker *worker = (struct rspamd_worker *) cbd; ev_timer *tm; @@ -343,8 +343,8 @@ rspamd_rs_compile(struct hs_helper_ctx *ctx, struct rspamd_worker *worker, static gboolean rspamd_hs_helper_reload(struct rspamd_main *rspamd_main, - struct rspamd_worker *worker, gint fd, - gint attached_fd, + struct rspamd_worker *worker, int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud) { diff --git a/src/libcryptobox/base64/base64.c b/src/libcryptobox/base64/base64.c index e86892443..1d3f3d123 100644 --- a/src/libcryptobox/base64/base64.c +++ b/src/libcryptobox/base64/base64.c @@ -340,7 +340,7 @@ static const base64_impl_t *base64_ref = &base64_list[0]; const char * base64_load(void) { - guint i; + unsigned int i; const base64_impl_t *opt_impl = base64_ref; /* Enable reference */ @@ -360,12 +360,12 @@ base64_load(void) } gboolean -rspamd_cryptobox_base64_decode(const gchar *in, gsize inlen, - guchar *out, gsize *outlen) +rspamd_cryptobox_base64_decode(const char *in, gsize inlen, + unsigned char *out, gsize *outlen) { const base64_impl_t *opt_impl = base64_ref; - for (gint i = G_N_ELEMENTS(base64_list) - 1; i > 0; i--) { + for (int i = G_N_ELEMENTS(base64_list) - 1; i > 0; i--) { if (base64_list[i].enabled && base64_list[i].min_len <= inlen) { opt_impl = &base64_list[i]; break; @@ -379,8 +379,8 @@ double base64_test(bool generic, size_t niters, size_t len, size_t str_len) { size_t cycles; - guchar *in, *out, *tmp; - gdouble t1, t2, total = 0; + unsigned char *in, *out, *tmp; + double t1, t2, total = 0; gsize outlen; g_assert(len > 0); @@ -421,9 +421,9 @@ base64_test(bool generic, size_t niters, size_t len, size_t str_len) gboolean -rspamd_cryptobox_base64_is_valid(const gchar *in, gsize inlen) +rspamd_cryptobox_base64_is_valid(const char *in, gsize inlen) { - const guchar *p, *end; + const unsigned char *p, *end; if (inlen == 0) { return FALSE; diff --git a/src/libcryptobox/catena/catena.c b/src/libcryptobox/catena/catena.c index 7e066dd7d..ced2de882 100644 --- a/src/libcryptobox/catena/catena.c +++ b/src/libcryptobox/catena/catena.c @@ -1,23 +1,17 @@ -/*- - * Copyright 2016 Vsevolod Stakhov - * Copyright (c) 2014 cforler +/* + * Copyright 2024 Vsevolod Stakhov * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: + * 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 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "config.h" @@ -424,16 +418,16 @@ int simple_catena(const uint8_t *pwd, const uint32_t pwdlen, int catena_test(void) { /* From catena-v3.1 spec */ - guint8 pw[] = {0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64}; - guint8 salt[] = {0x73, 0x61, 0x6c, 0x74}; - guint8 ad[] = {0x64, 0x61, 0x74, 0x61}; - guint8 expected[] = { + uint8_t pw[] = {0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64}; + uint8_t salt[] = {0x73, 0x61, 0x6c, 0x74}; + uint8_t ad[] = {0x64, 0x61, 0x74, 0x61}; + uint8_t expected[] = { 0x20, 0xc5, 0x91, 0x93, 0x8f, 0xc3, 0xaf, 0xcc, 0x3b, 0xba, 0x91, 0xd2, 0xfb, 0x84, 0xbf, 0x7b, 0x44, 0x04, 0xf9, 0x4c, 0x45, 0xed, 0x4d, 0x11, 0xa7, 0xe2, 0xb4, 0x12, 0x3e, 0xab, 0x0b, 0x77, 0x4a, 0x12, 0xb4, 0x22, 0xd0, 0xda, 0xb5, 0x25, 0x29, 0x02, 0xfc, 0x54, 0x47, 0xea, 0x82, 0x63, 0x8c, 0x1a, 0xfb, 0xa7, 0xa9, 0x94, 0x24, 0x13, 0x0e, 0x44, 0x36, 0x3b, 0x9d, 0x9f, 0xc9, 0x60}; - guint8 real[H_LEN]; + uint8_t real[H_LEN]; if (catena(pw, sizeof(pw), salt, sizeof(salt), ad, sizeof(ad), 4, 10, 10, H_LEN, real) != 0) { diff --git a/src/libcryptobox/chacha20/chacha.c b/src/libcryptobox/chacha20/chacha.c index 0b471c80a..3dda743a0 100644 --- a/src/libcryptobox/chacha20/chacha.c +++ b/src/libcryptobox/chacha20/chacha.c @@ -94,7 +94,7 @@ chacha_is_aligned(const void *p) const char * chacha_load(void) { - guint i; + unsigned int i; if (cpu_config != 0) { for (i = 0; i < G_N_ELEMENTS(chacha_list); i++) { diff --git a/src/libcryptobox/cryptobox.c b/src/libcryptobox/cryptobox.c index 4d3c1b43c..aa093d01e 100644 --- a/src/libcryptobox/cryptobox.c +++ b/src/libcryptobox/cryptobox.c @@ -63,14 +63,14 @@ unsigned cpu_config = 0; static gboolean cryptobox_loaded = FALSE; -static const guchar n0[16] = {0}; +static const unsigned char n0[16] = {0}; #define CRYPTOBOX_ALIGNMENT 16 #define cryptobox_align_ptr(p, a) \ (void *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1)) static void -rspamd_cryptobox_cpuid(gint cpu[4], gint info) +rspamd_cryptobox_cpuid(int cpu[4], int info) { uint32_t __attribute__((unused)) eax, __attribute__((unused)) ecx = 0, __attribute__((unused)) ebx = 0, __attribute__((unused)) edx = 0; @@ -93,7 +93,7 @@ rspamd_cryptobox_cpuid(gint cpu[4], gint info) cpu[2] = ecx; cpu[3] = edx; #else - memset(cpu, 0, sizeof(gint) * 4); + memset(cpu, 0, sizeof(int) * 4); #endif } @@ -108,7 +108,7 @@ rspamd_cryptobox_ill_handler(int signo) } static gboolean -rspamd_cryptobox_test_instr(gint instr) +rspamd_cryptobox_test_instr(int instr) { void (*old_handler)(int); uint32_t rd; @@ -186,7 +186,7 @@ rspamd_cryptobox_test_instr(gint instr) struct rspamd_cryptobox_library_ctx * rspamd_cryptobox_init(void) { - gint cpu[4], nid; + int cpu[4], nid; const uint32_t osxsave_mask = (1 << 27); const uint32_t fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27)); const uint32_t avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8); @@ -357,7 +357,7 @@ void rspamd_cryptobox_keypair(rspamd_pk_t pk, rspamd_sk_t sk, unsigned char *buf = NULL; /* Thanks openssl for this API (no) */ len = EC_POINT_point2buf(EC_KEY_get0_group(ec_sec), ec_pub, POINT_CONVERSION_UNCOMPRESSED, &buf, NULL); - g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode)); + g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode)); memcpy(pk, buf, len); OPENSSL_free(buf); #else @@ -365,13 +365,13 @@ void rspamd_cryptobox_keypair(rspamd_pk_t pk, rspamd_sk_t sk, bn_pub = EC_POINT_point2bn(EC_KEY_get0_group(ec_sec), ec_pub, POINT_CONVERSION_UNCOMPRESSED, NULL, NULL); len = BN_num_bytes(bn_pub); - g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode)); + g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode)); BN_bn2bin(bn_pub, pk); BN_free(bn_pub); #endif len = BN_num_bytes(bn_sec); - g_assert(len <= (gint) sizeof(rspamd_sk_t)); + g_assert(len <= (int) sizeof(rspamd_sk_t)); BN_bn2bin(bn_sec, sk); EC_KEY_free(ec_sec); @@ -407,7 +407,7 @@ void rspamd_cryptobox_keypair_sig(rspamd_sig_pk_t pk, rspamd_sig_sk_t sk, unsigned char *buf = NULL; /* Thanks openssl for this API (no) */ len = EC_POINT_point2buf(EC_KEY_get0_group(ec_sec), ec_pub, POINT_CONVERSION_UNCOMPRESSED, &buf, NULL); - g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode)); + g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode)); memcpy(pk, buf, len); OPENSSL_free(buf); #else @@ -415,13 +415,13 @@ void rspamd_cryptobox_keypair_sig(rspamd_sig_pk_t pk, rspamd_sig_sk_t sk, bn_pub = EC_POINT_point2bn(EC_KEY_get0_group(ec_sec), ec_pub, POINT_CONVERSION_UNCOMPRESSED, NULL, NULL); len = BN_num_bytes(bn_pub); - g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode)); + g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode)); BN_bn2bin(bn_pub, pk); BN_free(bn_pub); #endif len = BN_num_bytes(bn_sec); - g_assert(len <= (gint) sizeof(rspamd_sk_t)); + g_assert(len <= (int) sizeof(rspamd_sk_t)); BN_bn2bin(bn_sec, sk); EC_KEY_free(ec_sec); #endif @@ -476,8 +476,8 @@ void rspamd_cryptobox_nm(rspamd_nm_t nm, enum rspamd_cryptobox_mode mode) { if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { - guchar s[32]; - guchar e[32]; + unsigned char s[32]; + unsigned char e[32]; memcpy(e, sk, 32); e[0] &= 248; @@ -497,8 +497,8 @@ void rspamd_cryptobox_nm(rspamd_nm_t nm, EC_KEY *lk; EC_POINT *ec_pub; BIGNUM *bn_pub, *bn_sec; - gint len; - guchar s[32]; + int len; + unsigned char s[32]; lk = EC_KEY_new_by_curve_name(CRYPTOBOX_CURVE_NID); g_assert(lk != NULL); @@ -525,8 +525,8 @@ void rspamd_cryptobox_nm(rspamd_nm_t nm, } } -void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p, - const guchar *m, gsize mlen, +void rspamd_cryptobox_sign(unsigned char *sig, unsigned long long *siglen_p, + const unsigned char *m, gsize mlen, const rspamd_sk_t sk, enum rspamd_cryptobox_mode mode) { @@ -541,7 +541,7 @@ void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p, BIGNUM *bn_sec; EVP_MD_CTX *sha_ctx; unsigned char h[64]; - guint diglen = rspamd_cryptobox_signature_bytes(mode); + unsigned int diglen = rspamd_cryptobox_signature_bytes(mode); /* Prehash */ sha_ctx = EVP_MD_CTX_create(); @@ -571,9 +571,9 @@ void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p, } } -bool rspamd_cryptobox_verify(const guchar *sig, +bool rspamd_cryptobox_verify(const unsigned char *sig, gsize siglen, - const guchar *m, + const unsigned char *m, gsize mlen, const rspamd_pk_t pk, enum rspamd_cryptobox_mode mode) @@ -700,7 +700,7 @@ rspamd_cryptobox_auth_init(void *auth_ctx, void *enc_ctx, { if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { crypto_onetimeauth_state *mac_ctx; - guchar RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; + unsigned char RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; mac_ctx = cryptobox_align_ptr(auth_ctx, CRYPTOBOX_ALIGNMENT); memset(subkey, 0, sizeof(subkey)); @@ -724,8 +724,8 @@ rspamd_cryptobox_auth_init(void *auth_ctx, void *enc_ctx, } static gboolean -rspamd_cryptobox_encrypt_update(void *enc_ctx, const guchar *in, gsize inlen, - guchar *out, gsize *outlen, +rspamd_cryptobox_encrypt_update(void *enc_ctx, const unsigned char *in, gsize inlen, + unsigned char *out, gsize *outlen, enum rspamd_cryptobox_mode mode) { if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { @@ -747,7 +747,7 @@ rspamd_cryptobox_encrypt_update(void *enc_ctx, const guchar *in, gsize inlen, g_assert(0); #else EVP_CIPHER_CTX **s = enc_ctx; - gint r; + int r; r = inlen; g_assert(EVP_EncryptUpdate(*s, out, &r, in, inlen) == 1); @@ -764,7 +764,7 @@ rspamd_cryptobox_encrypt_update(void *enc_ctx, const guchar *in, gsize inlen, } static gboolean -rspamd_cryptobox_auth_update(void *auth_ctx, const guchar *in, gsize inlen, +rspamd_cryptobox_auth_update(void *auth_ctx, const unsigned char *in, gsize inlen, enum rspamd_cryptobox_mode mode) { if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { @@ -787,7 +787,7 @@ rspamd_cryptobox_auth_update(void *auth_ctx, const guchar *in, gsize inlen, } static gsize -rspamd_cryptobox_encrypt_final(void *enc_ctx, guchar *out, gsize remain, +rspamd_cryptobox_encrypt_final(void *enc_ctx, unsigned char *out, gsize remain, enum rspamd_cryptobox_mode mode) { if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { @@ -801,7 +801,7 @@ rspamd_cryptobox_encrypt_final(void *enc_ctx, guchar *out, gsize remain, g_assert(0); #else EVP_CIPHER_CTX **s = enc_ctx; - gint r = remain; + int r = remain; g_assert(EVP_EncryptFinal_ex(*s, out, &r) == 1); @@ -884,7 +884,7 @@ rspamd_cryptobox_auth_verify_init(void *auth_ctx, void *enc_ctx, { if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { crypto_onetimeauth_state *mac_ctx; - guchar RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; + unsigned char RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; mac_ctx = cryptobox_align_ptr(auth_ctx, CRYPTOBOX_ALIGNMENT); memset(subkey, 0, sizeof(subkey)); @@ -908,8 +908,8 @@ rspamd_cryptobox_auth_verify_init(void *auth_ctx, void *enc_ctx, } static gboolean -rspamd_cryptobox_decrypt_update(void *enc_ctx, const guchar *in, gsize inlen, - guchar *out, gsize *outlen, +rspamd_cryptobox_decrypt_update(void *enc_ctx, const unsigned char *in, gsize inlen, + unsigned char *out, gsize *outlen, enum rspamd_cryptobox_mode mode) { if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { @@ -930,7 +930,7 @@ rspamd_cryptobox_decrypt_update(void *enc_ctx, const guchar *in, gsize inlen, g_assert(0); #else EVP_CIPHER_CTX **s = enc_ctx; - gint r; + int r; r = outlen ? *outlen : inlen; g_assert(EVP_DecryptUpdate(*s, out, &r, in, inlen) == 1); @@ -946,7 +946,7 @@ rspamd_cryptobox_decrypt_update(void *enc_ctx, const guchar *in, gsize inlen, static gboolean rspamd_cryptobox_auth_verify_update(void *auth_ctx, - const guchar *in, gsize inlen, + const unsigned char *in, gsize inlen, enum rspamd_cryptobox_mode mode) { if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { @@ -969,7 +969,7 @@ rspamd_cryptobox_auth_verify_update(void *auth_ctx, } static gboolean -rspamd_cryptobox_decrypt_final(void *enc_ctx, guchar *out, gsize remain, +rspamd_cryptobox_decrypt_final(void *enc_ctx, unsigned char *out, gsize remain, enum rspamd_cryptobox_mode mode) { if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { @@ -985,7 +985,7 @@ rspamd_cryptobox_decrypt_final(void *enc_ctx, guchar *out, gsize remain, g_assert(0); #else EVP_CIPHER_CTX **s = enc_ctx; - gint r = remain; + int r = remain; if (EVP_DecryptFinal_ex(*s, out, &r) < 0) { return FALSE; @@ -1021,7 +1021,7 @@ rspamd_cryptobox_auth_verify_final(void *auth_ctx, const rspamd_mac_t sig, #else EVP_CIPHER_CTX **s = auth_ctx; - if (EVP_CIPHER_CTX_ctrl(*s, EVP_CTRL_GCM_SET_TAG, 16, (guchar *) sig) != 1) { + if (EVP_CIPHER_CTX_ctrl(*s, EVP_CTRL_GCM_SET_TAG, 16, (unsigned char *) sig) != 1) { return FALSE; } @@ -1055,7 +1055,7 @@ rspamd_cryptobox_cleanup(void *enc_ctx, void *auth_ctx, } } -void rspamd_cryptobox_encrypt_nm_inplace(guchar *data, gsize len, +void rspamd_cryptobox_encrypt_nm_inplace(unsigned char *data, gsize len, const rspamd_nonce_t nonce, const rspamd_nm_t nm, rspamd_mac_t sig, @@ -1081,7 +1081,7 @@ void rspamd_cryptobox_encrypt_nm_inplace(guchar *data, gsize len, static void rspamd_cryptobox_flush_outbuf(struct rspamd_cryptobox_segment *st, - const guchar *buf, gsize len, gsize offset) + const unsigned char *buf, gsize len, gsize offset) { gsize cpy_len; @@ -1102,9 +1102,9 @@ void rspamd_cryptobox_encryptv_nm_inplace(struct rspamd_cryptobox_segment *segme enum rspamd_cryptobox_mode mode) { struct rspamd_cryptobox_segment *cur = segments, *start_seg = segments; - guchar outbuf[CHACHA_BLOCKBYTES * 16]; + unsigned char outbuf[CHACHA_BLOCKBYTES * 16]; void *enc_ctx, *auth_ctx; - guchar *out, *in; + unsigned char *out, *in; gsize r, remain, inremain, seg_offset; enc_ctx = g_alloca(rspamd_cryptobox_encrypt_ctx_len(mode)); @@ -1119,7 +1119,7 @@ void rspamd_cryptobox_encryptv_nm_inplace(struct rspamd_cryptobox_segment *segme seg_offset = 0; for (;;) { - if (cur - segments == (gint) cnt) { + if (cur - segments == (int) cnt) { break; } @@ -1205,7 +1205,7 @@ void rspamd_cryptobox_encryptv_nm_inplace(struct rspamd_cryptobox_segment *segme } gboolean -rspamd_cryptobox_decrypt_nm_inplace(guchar *data, gsize len, +rspamd_cryptobox_decrypt_nm_inplace(unsigned char *data, gsize len, const rspamd_nonce_t nonce, const rspamd_nm_t nm, const rspamd_mac_t sig, enum rspamd_cryptobox_mode mode) { @@ -1235,13 +1235,13 @@ rspamd_cryptobox_decrypt_nm_inplace(guchar *data, gsize len, } gboolean -rspamd_cryptobox_decrypt_inplace(guchar *data, gsize len, +rspamd_cryptobox_decrypt_inplace(unsigned char *data, gsize len, const rspamd_nonce_t nonce, const rspamd_pk_t pk, const rspamd_sk_t sk, const rspamd_mac_t sig, enum rspamd_cryptobox_mode mode) { - guchar nm[rspamd_cryptobox_MAX_NMBYTES]; + unsigned char nm[rspamd_cryptobox_MAX_NMBYTES]; gboolean ret; rspamd_cryptobox_nm(nm, pk, sk, mode); @@ -1252,13 +1252,13 @@ rspamd_cryptobox_decrypt_inplace(guchar *data, gsize len, return ret; } -void rspamd_cryptobox_encrypt_inplace(guchar *data, gsize len, +void rspamd_cryptobox_encrypt_inplace(unsigned char *data, gsize len, const rspamd_nonce_t nonce, const rspamd_pk_t pk, const rspamd_sk_t sk, rspamd_mac_t sig, enum rspamd_cryptobox_mode mode) { - guchar nm[rspamd_cryptobox_MAX_NMBYTES]; + unsigned char nm[rspamd_cryptobox_MAX_NMBYTES]; rspamd_cryptobox_nm(nm, pk, sk, mode); rspamd_cryptobox_encrypt_nm_inplace(data, len, nonce, nm, sig, mode); @@ -1272,7 +1272,7 @@ void rspamd_cryptobox_encryptv_inplace(struct rspamd_cryptobox_segment *segments rspamd_mac_t sig, enum rspamd_cryptobox_mode mode) { - guchar nm[rspamd_cryptobox_MAX_NMBYTES]; + unsigned char nm[rspamd_cryptobox_MAX_NMBYTES]; rspamd_cryptobox_nm(nm, pk, sk, mode); rspamd_cryptobox_encryptv_nm_inplace(segments, cnt, nonce, nm, sig, mode); @@ -1293,11 +1293,11 @@ void rspamd_cryptobox_siphash(unsigned char *out, const unsigned char *in, */ static gboolean rspamd_cryptobox_pbkdf2(const char *pass, gsize pass_len, - const guint8 *salt, gsize salt_len, guint8 *key, gsize key_len, + const uint8_t *salt, gsize salt_len, uint8_t *key, gsize key_len, unsigned int rounds) { - guint8 *asalt, obuf[crypto_generichash_blake2b_BYTES_MAX]; - guint8 d1[crypto_generichash_blake2b_BYTES_MAX], + uint8_t *asalt, obuf[crypto_generichash_blake2b_BYTES_MAX]; + uint8_t d1[crypto_generichash_blake2b_BYTES_MAX], d2[crypto_generichash_blake2b_BYTES_MAX]; unsigned int i, j; unsigned int count; @@ -1324,7 +1324,7 @@ rspamd_cryptobox_pbkdf2(const char *pass, gsize pass_len, pass, pass_len); } else { - guint8 k[crypto_generichash_blake2b_BYTES_MAX]; + uint8_t k[crypto_generichash_blake2b_BYTES_MAX]; /* * We use additional blake2 iteration to store large key @@ -1344,7 +1344,7 @@ rspamd_cryptobox_pbkdf2(const char *pass, gsize pass_len, pass, pass_len); } else { - guint8 k[crypto_generichash_blake2b_BYTES_MAX]; + uint8_t k[crypto_generichash_blake2b_BYTES_MAX]; /* * We use additional blake2 iteration to store large key @@ -1380,7 +1380,7 @@ rspamd_cryptobox_pbkdf2(const char *pass, gsize pass_len, gboolean rspamd_cryptobox_pbkdf(const char *pass, gsize pass_len, - const guint8 *salt, gsize salt_len, guint8 *key, gsize key_len, + const uint8_t *salt, gsize salt_len, uint8_t *key, gsize key_len, unsigned int complexity, enum rspamd_cryptobox_pbkdf_type type) { gboolean ret = FALSE; @@ -1402,7 +1402,7 @@ rspamd_cryptobox_pbkdf(const char *pass, gsize pass_len, return ret; } -guint rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode) +unsigned int rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode) { if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { return 32; @@ -1412,7 +1412,7 @@ guint rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode) } } -guint rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode) +unsigned int rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode) { if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { return 32; @@ -1422,7 +1422,7 @@ guint rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode) } } -guint rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode) +unsigned int rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode) { if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { return 24; @@ -1433,12 +1433,12 @@ guint rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode) } -guint rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode) +unsigned int rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode) { return 32; } -guint rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode) +unsigned int rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode) { if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { return 64; @@ -1448,9 +1448,9 @@ guint rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode) } } -guint rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode) +unsigned int rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode) { - static guint ssl_keylen; + static unsigned int ssl_keylen; if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { return 64; @@ -1470,17 +1470,17 @@ guint rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode) } } -guint rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode) +unsigned int rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode) { return 32; } -guint rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode) +unsigned int rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode) { return 16; } -void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *p, const guchar *key, gsize keylen) +void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *p, const unsigned char *key, gsize keylen) { crypto_generichash_blake2b_state *st = cryptobox_align_ptr(p, RSPAMD_ALIGNOF(crypto_generichash_blake2b_state)); @@ -1491,7 +1491,7 @@ void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *p, const guchar * /** * Update hash with data portion */ -void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *p, const guchar *data, gsize len) +void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *p, const unsigned char *data, gsize len) { crypto_generichash_blake2b_state *st = cryptobox_align_ptr(p, RSPAMD_ALIGNOF(crypto_generichash_blake2b_state)); @@ -1501,7 +1501,7 @@ void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *p, const guchar /** * Output hash to the buffer of rspamd_cryptobox_HASHBYTES length */ -void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *p, guchar *out) +void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *p, unsigned char *out) { crypto_generichash_blake2b_state *st = cryptobox_align_ptr(p, RSPAMD_ALIGNOF(crypto_generichash_blake2b_state)); @@ -1511,10 +1511,10 @@ void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *p, guchar *out) /** * One in all function */ -void rspamd_cryptobox_hash(guchar *out, - const guchar *data, +void rspamd_cryptobox_hash(unsigned char *out, + const unsigned char *data, gsize len, - const guchar *key, + const unsigned char *key, gsize keylen) { crypto_generichash_blake2b(out, crypto_generichash_blake2b_BYTES_MAX, @@ -1636,7 +1636,7 @@ void rspamd_cryptobox_fast_hash_update(rspamd_cryptobox_fast_hash_state_t *st, case RSPAMD_CRYPTOBOX_MUMHASH: { struct _mum_iuf *iuf = (struct _mum_iuf *) st->opaque; gsize drem = len; - const guchar *p = data; + const unsigned char *p = data; if (iuf->rem > 0) { /* Process remainder */ diff --git a/src/libcryptobox/cryptobox.h b/src/libcryptobox/cryptobox.h index 635fffefc..8382c8f68 100644 --- a/src/libcryptobox/cryptobox.h +++ b/src/libcryptobox/cryptobox.h @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,7 +25,7 @@ extern "C" { #endif struct rspamd_cryptobox_segment { - guchar *data; + unsigned char *data; gsize len; }; @@ -57,15 +57,15 @@ struct rspamd_cryptobox_segment { #define CPUID_SSE42 0x40 #define CPUID_RDRAND 0x80 -typedef guchar rspamd_pk_t[rspamd_cryptobox_MAX_PKBYTES]; -typedef guchar rspamd_sk_t[rspamd_cryptobox_MAX_SKBYTES]; -typedef guchar rspamd_mac_t[rspamd_cryptobox_MAX_MACBYTES]; -typedef guchar rspamd_nm_t[rspamd_cryptobox_MAX_NMBYTES]; -typedef guchar rspamd_nonce_t[rspamd_cryptobox_MAX_NONCEBYTES]; -typedef guchar rspamd_sipkey_t[rspamd_cryptobox_SIPKEYBYTES]; -typedef guchar rspamd_signature_t[rspamd_cryptobox_MAX_SIGBYTES]; -typedef guchar rspamd_sig_pk_t[rspamd_cryptobox_MAX_SIGPKBYTES]; -typedef guchar rspamd_sig_sk_t[rspamd_cryptobox_MAX_SIGSKBYTES]; +typedef unsigned char rspamd_pk_t[rspamd_cryptobox_MAX_PKBYTES]; +typedef unsigned char rspamd_sk_t[rspamd_cryptobox_MAX_SKBYTES]; +typedef unsigned char rspamd_mac_t[rspamd_cryptobox_MAX_MACBYTES]; +typedef unsigned char rspamd_nm_t[rspamd_cryptobox_MAX_NMBYTES]; +typedef unsigned char rspamd_nonce_t[rspamd_cryptobox_MAX_NONCEBYTES]; +typedef unsigned char rspamd_sipkey_t[rspamd_cryptobox_SIPKEYBYTES]; +typedef unsigned char rspamd_signature_t[rspamd_cryptobox_MAX_SIGBYTES]; +typedef unsigned char rspamd_sig_pk_t[rspamd_cryptobox_MAX_SIGPKBYTES]; +typedef unsigned char rspamd_sig_sk_t[rspamd_cryptobox_MAX_SIGSKBYTES]; enum rspamd_cryptobox_mode { RSPAMD_CRYPTOBOX_MODE_25519 = 0, @@ -73,9 +73,9 @@ enum rspamd_cryptobox_mode { }; struct rspamd_cryptobox_library_ctx { - gchar *cpu_extensions; - const gchar *chacha20_impl; - const gchar *base64_impl; + char *cpu_extensions; + const char *chacha20_impl; + const char *base64_impl; unsigned long cpu_config; }; @@ -108,7 +108,7 @@ void rspamd_cryptobox_keypair_sig(rspamd_sig_pk_t pk, rspamd_sig_sk_t sk, * @param sk local secret key * @param sig output signature */ -void rspamd_cryptobox_encrypt_inplace(guchar *data, gsize len, +void rspamd_cryptobox_encrypt_inplace(unsigned char *data, gsize len, const rspamd_nonce_t nonce, const rspamd_pk_t pk, const rspamd_sk_t sk, rspamd_mac_t sig, enum rspamd_cryptobox_mode mode); @@ -137,7 +137,7 @@ void rspamd_cryptobox_encryptv_inplace(struct rspamd_cryptobox_segment *segments * @param sig signature input * @return TRUE if input has been verified successfully */ -gboolean rspamd_cryptobox_decrypt_inplace(guchar *data, gsize len, +gboolean rspamd_cryptobox_decrypt_inplace(unsigned char *data, gsize len, const rspamd_nonce_t nonce, const rspamd_pk_t pk, const rspamd_sk_t sk, const rspamd_mac_t sig, enum rspamd_cryptobox_mode mode); @@ -150,7 +150,7 @@ gboolean rspamd_cryptobox_decrypt_inplace(guchar *data, gsize len, * @param sk local secret key * @param sig output signature */ -void rspamd_cryptobox_encrypt_nm_inplace(guchar *data, gsize len, +void rspamd_cryptobox_encrypt_nm_inplace(unsigned char *data, gsize len, const rspamd_nonce_t nonce, const rspamd_nm_t nm, rspamd_mac_t sig, enum rspamd_cryptobox_mode mode); @@ -179,7 +179,7 @@ void rspamd_cryptobox_encryptv_nm_inplace(struct rspamd_cryptobox_segment *segme * @param sig signature input * @return TRUE if input has been verified successfully */ -gboolean rspamd_cryptobox_decrypt_nm_inplace(guchar *data, gsize len, +gboolean rspamd_cryptobox_decrypt_nm_inplace(unsigned char *data, gsize len, const rspamd_nonce_t nonce, const rspamd_nm_t nm, const rspamd_mac_t sig, enum rspamd_cryptobox_mode mode); @@ -201,8 +201,8 @@ void rspamd_cryptobox_nm(rspamd_nm_t nm, const rspamd_pk_t pk, * @param mlen input length * @param sk secret key */ -void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p, - const guchar *m, gsize mlen, +void rspamd_cryptobox_sign(unsigned char *sig, unsigned long long *siglen_p, + const unsigned char *m, gsize mlen, const rspamd_sk_t sk, enum rspamd_cryptobox_mode mode); @@ -215,9 +215,9 @@ void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p, * @param pk public key for verification * @return true if signature is valid, false otherwise */ -bool rspamd_cryptobox_verify(const guchar *sig, +bool rspamd_cryptobox_verify(const unsigned char *sig, gsize siglen, - const guchar *m, + const unsigned char *m, gsize mlen, const rspamd_pk_t pk, enum rspamd_cryptobox_mode mode); @@ -268,8 +268,8 @@ enum rspamd_cryptobox_pbkdf_type { * @return TRUE in case of success and FALSE if failed */ gboolean rspamd_cryptobox_pbkdf(const char *pass, gsize pass_len, - const guint8 *salt, gsize salt_len, - guint8 *key, gsize key_len, + const uint8_t *salt, gsize salt_len, + uint8_t *key, gsize key_len, unsigned int complexity, enum rspamd_cryptobox_pbkdf_type type); @@ -277,42 +277,42 @@ gboolean rspamd_cryptobox_pbkdf(const char *pass, gsize pass_len, /** * Real size of rspamd cryptobox public key */ -guint rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode); +unsigned int rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode); /** * Real size of rspamd cryptobox signing public key */ -guint rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode); +unsigned int rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode); /** * Real size of crypto nonce */ -guint rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode); +unsigned int rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode); /** * Real size of rspamd cryptobox secret key */ -guint rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode); +unsigned int rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode); /** * Real size of rspamd cryptobox signing secret key */ -guint rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode); +unsigned int rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode); /** * Real size of rspamd cryptobox shared key */ -guint rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode); +unsigned int rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode); /** * Real size of rspamd cryptobox MAC signature */ -guint rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode); +unsigned int rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode); /** * Real size of rspamd cryptobox digital signature */ -guint rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode); +unsigned int rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode); /* Hash IUF interface */ typedef crypto_generichash_blake2b_state rspamd_cryptobox_hash_state_t; @@ -323,26 +323,26 @@ typedef crypto_generichash_blake2b_state rspamd_cryptobox_hash_state_t; * non-keyed hash is generated */ void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *st, - const guchar *key, gsize keylen); + const unsigned char *key, gsize keylen); /** * Update hash with data portion */ void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *st, - const guchar *data, gsize len); + const unsigned char *data, gsize len); /** * Output hash to the buffer of rspamd_cryptobox_HASHBYTES length */ -void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *st, guchar *out); +void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *st, unsigned char *out); /** * One in all function */ -void rspamd_cryptobox_hash(guchar *out, - const guchar *data, +void rspamd_cryptobox_hash(unsigned char *out, + const unsigned char *data, gsize len, - const guchar *key, + const unsigned char *key, gsize keylen); enum rspamd_cryptobox_fast_hash_type { @@ -357,7 +357,7 @@ enum rspamd_cryptobox_fast_hash_type { /* Non crypto hash IUF interface */ typedef struct CRYPTO_ALIGN(64) rspamd_cryptobox_fast_hash_state_s { - guchar opaque[576]; /* Required for xxhash3 */ + unsigned char opaque[576]; /* Required for xxhash3 */ enum rspamd_cryptobox_fast_hash_type type; } rspamd_cryptobox_fast_hash_state_t; @@ -419,8 +419,8 @@ uint64_t rspamd_cryptobox_fast_hash_specific( * @param outlen * @return */ -gboolean rspamd_cryptobox_base64_decode(const gchar *in, gsize inlen, - guchar *out, gsize *outlen); +gboolean rspamd_cryptobox_base64_decode(const char *in, gsize inlen, + unsigned char *out, gsize *outlen); /** * Returns TRUE if data looks like a valid base64 string @@ -428,7 +428,7 @@ gboolean rspamd_cryptobox_base64_decode(const gchar *in, gsize inlen, * @param inlen * @return */ -gboolean rspamd_cryptobox_base64_is_valid(const gchar *in, gsize inlen); +gboolean rspamd_cryptobox_base64_is_valid(const char *in, gsize inlen); #ifdef __cplusplus } diff --git a/src/libcryptobox/keypair.c b/src/libcryptobox/keypair.c index 671b752af..02070bb46 100644 --- a/src/libcryptobox/keypair.c +++ b/src/libcryptobox/keypair.c @@ -21,7 +21,7 @@ #include "libutil/printf.h" #include "contrib/libottery/ottery.h" -const guchar encrypted_magic[7] = {'r', 'u', 'c', 'l', 'e', 'v', '1'}; +const unsigned char encrypted_magic[7] = {'r', 'u', 'c', 'l', 'e', 'v', '1'}; static GQuark rspamd_keypair_quark(void) @@ -34,7 +34,7 @@ rspamd_keypair_quark(void) */ static void * rspamd_cryptobox_keypair_sk(struct rspamd_cryptobox_keypair *kp, - guint *len) + unsigned int *len) { g_assert(kp != NULL); @@ -65,7 +65,7 @@ rspamd_cryptobox_keypair_sk(struct rspamd_cryptobox_keypair *kp, static void * rspamd_cryptobox_keypair_pk(struct rspamd_cryptobox_keypair *kp, - guint *len) + unsigned int *len) { g_assert(kp != NULL); @@ -96,7 +96,7 @@ rspamd_cryptobox_keypair_pk(struct rspamd_cryptobox_keypair *kp, static void * rspamd_cryptobox_pubkey_pk(const struct rspamd_cryptobox_pubkey *kp, - guint *len) + unsigned int *len) { g_assert(kp != NULL); @@ -130,7 +130,7 @@ rspamd_cryptobox_keypair_alloc(enum rspamd_cryptobox_keypair_type type, enum rspamd_cryptobox_mode alg) { struct rspamd_cryptobox_keypair *kp; - guint size = 0; + unsigned int size = 0; if (alg == RSPAMD_CRYPTOBOX_MODE_25519) { if (type == RSPAMD_KEYPAIR_KEX) { @@ -165,7 +165,7 @@ rspamd_cryptobox_pubkey_alloc(enum rspamd_cryptobox_keypair_type type, enum rspamd_cryptobox_mode alg) { struct rspamd_cryptobox_pubkey *pk; - guint size = 0; + unsigned int size = 0; if (alg == RSPAMD_CRYPTOBOX_MODE_25519) { if (type == RSPAMD_KEYPAIR_KEX) { @@ -205,7 +205,7 @@ void rspamd_cryptobox_nm_dtor(struct rspamd_cryptobox_nm *nm) void rspamd_cryptobox_keypair_dtor(struct rspamd_cryptobox_keypair *kp) { void *sk; - guint len = 0; + unsigned int len = 0; sk = rspamd_cryptobox_keypair_sk(kp, &len); g_assert(sk != NULL && len > 0); @@ -235,7 +235,7 @@ rspamd_keypair_new(enum rspamd_cryptobox_keypair_type type, { struct rspamd_cryptobox_keypair *kp; void *pk, *sk; - guint size; + unsigned int size; kp = rspamd_cryptobox_keypair_alloc(type, alg); kp->alg = alg; @@ -319,16 +319,16 @@ rspamd_pubkey_alg(struct rspamd_cryptobox_pubkey *p) } struct rspamd_cryptobox_pubkey * -rspamd_pubkey_from_base32(const gchar *b32, +rspamd_pubkey_from_base32(const char *b32, gsize len, enum rspamd_cryptobox_keypair_type type, enum rspamd_cryptobox_mode alg) { - guchar *decoded; + unsigned char *decoded; gsize dlen, expected_len; - guint pklen; + unsigned int pklen; struct rspamd_cryptobox_pubkey *pk; - guchar *pk_data; + unsigned char *pk_data; g_assert(b32 != NULL); @@ -363,16 +363,16 @@ rspamd_pubkey_from_base32(const gchar *b32, } struct rspamd_cryptobox_pubkey * -rspamd_pubkey_from_hex(const gchar *hex, +rspamd_pubkey_from_hex(const char *hex, gsize len, enum rspamd_cryptobox_keypair_type type, enum rspamd_cryptobox_mode alg) { - guchar *decoded; + unsigned char *decoded; gsize dlen, expected_len; - guint pklen; + unsigned int pklen; struct rspamd_cryptobox_pubkey *pk; - guchar *pk_data; + unsigned char *pk_data; g_assert(hex != NULL); @@ -409,15 +409,15 @@ rspamd_pubkey_from_hex(const gchar *hex, } struct rspamd_cryptobox_pubkey * -rspamd_pubkey_from_bin(const guchar *raw, +rspamd_pubkey_from_bin(const unsigned char *raw, gsize len, enum rspamd_cryptobox_keypair_type type, enum rspamd_cryptobox_mode alg) { gsize expected_len; - guint pklen; + unsigned int pklen; struct rspamd_cryptobox_pubkey *pk; - guchar *pk_data; + unsigned char *pk_data; g_assert(raw != NULL && len > 0); @@ -440,14 +440,14 @@ rspamd_pubkey_from_bin(const guchar *raw, } -const guchar * +const unsigned char * rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p, struct rspamd_cryptobox_keypair *kp) { g_assert(p != NULL); if (p->nm) { - if (memcmp(kp->id, (const guchar *) &p->nm->sk_id, sizeof(uint64_t)) == 0) { + if (memcmp(kp->id, (const unsigned char *) &p->nm->sk_id, sizeof(uint64_t)) == 0) { return p->nm->nm; } @@ -459,7 +459,7 @@ rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p, return NULL; } -const guchar * +const unsigned char * rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p, struct rspamd_cryptobox_keypair *kp) { @@ -496,7 +496,7 @@ rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p, return p->nm->nm; } -const guchar * +const unsigned char * rspamd_keypair_get_id(struct rspamd_cryptobox_keypair *kp) { g_assert(kp != NULL); @@ -512,7 +512,7 @@ rspamd_keypair_get_extensions(struct rspamd_cryptobox_keypair *kp) return kp->extensions; } -const guchar * +const unsigned char * rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk) { g_assert(pk != NULL); @@ -520,12 +520,12 @@ rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk) return pk->id; } -const guchar * +const unsigned char * rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk, - guint *len) + unsigned int *len) { - guchar *ret = NULL; - guint rlen; + unsigned char *ret = NULL; + unsigned int rlen; ret = rspamd_cryptobox_pubkey_pk(pk, &rlen); @@ -537,10 +537,10 @@ rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk, } static void -rspamd_keypair_print_component(guchar *data, gsize datalen, - GString *res, guint how, const gchar *description) +rspamd_keypair_print_component(unsigned char *data, gsize datalen, + GString *res, unsigned int how, const char *description) { - gint olen, b32_len; + int olen, b32_len; if (how & RSPAMD_KEYPAIR_HUMAN) { rspamd_printf_gstring(res, "%s: ", description); @@ -559,7 +559,7 @@ rspamd_keypair_print_component(guchar *data, gsize datalen, } } else if (how & RSPAMD_KEYPAIR_HEX) { - rspamd_printf_gstring(res, "%*xs", (gint) datalen, data); + rspamd_printf_gstring(res, "%*xs", (int) datalen, data); } else { g_string_append_len(res, data, datalen); @@ -571,10 +571,10 @@ rspamd_keypair_print_component(guchar *data, gsize datalen, } GString * -rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, guint how) +rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, unsigned int how) { GString *res; - guint len; + unsigned int len; gpointer p; g_assert(kp != NULL); @@ -601,10 +601,10 @@ rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, guint how) } GString * -rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, guint how) +rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, unsigned int how) { GString *res; - guint len; + unsigned int len; gpointer p; g_assert(pk != NULL); @@ -627,12 +627,12 @@ rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, guint how) return res; } -const guchar * +const unsigned char * rspamd_keypair_component(struct rspamd_cryptobox_keypair *kp, - guint ncomp, guint *len) + unsigned int ncomp, unsigned int *len) { - guint rlen = 0; - const guchar *ret = NULL; + unsigned int rlen = 0; + const unsigned char *ret = NULL; g_assert(kp != NULL); @@ -660,14 +660,14 @@ struct rspamd_cryptobox_keypair * rspamd_keypair_from_ucl(const ucl_object_t *obj) { const ucl_object_t *privkey, *pubkey, *elt; - const gchar *str; + const char *str; enum rspamd_cryptobox_keypair_type type = RSPAMD_KEYPAIR_KEX; enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519; gboolean is_hex = FALSE; struct rspamd_cryptobox_keypair *kp; - guint len; + unsigned int len; gsize ucl_len; - gint dec_len; + int dec_len; gpointer target; if (ucl_object_type(obj) != UCL_OBJECT) { @@ -744,7 +744,7 @@ rspamd_keypair_from_ucl(const ucl_object_t *obj) dec_len = rspamd_decode_base32_buf(str, ucl_len, target, len, RSPAMD_BASE32_DEFAULT); } - if (dec_len != (gint) len) { + if (dec_len != (int) len) { rspamd_keypair_unref(kp); return NULL; @@ -760,7 +760,7 @@ rspamd_keypair_from_ucl(const ucl_object_t *obj) dec_len = rspamd_decode_base32_buf(str, ucl_len, target, len, RSPAMD_BASE32_DEFAULT); } - if (dec_len != (gint) len) { + if (dec_len != (int) len) { rspamd_keypair_unref(kp); return NULL; @@ -782,9 +782,9 @@ rspamd_keypair_to_ucl(struct rspamd_cryptobox_keypair *kp, enum rspamd_keypair_dump_flags flags) { ucl_object_t *ucl_out, *elt; - gint how = 0; + int how = 0; GString *keypair_out; - const gchar *encoding; + const char *encoding; g_assert(kp != NULL); @@ -857,11 +857,11 @@ rspamd_keypair_to_ucl(struct rspamd_cryptobox_keypair *kp, gboolean rspamd_keypair_decrypt(struct rspamd_cryptobox_keypair *kp, - const guchar *in, gsize inlen, - guchar **out, gsize *outlen, + const unsigned char *in, gsize inlen, + unsigned char **out, gsize *outlen, GError **err) { - const guchar *nonce, *mac, *data, *pubkey; + const unsigned char *nonce, *mac, *data, *pubkey; g_assert(kp != NULL); g_assert(in != NULL); @@ -924,11 +924,11 @@ rspamd_keypair_decrypt(struct rspamd_cryptobox_keypair *kp, gboolean rspamd_keypair_encrypt(struct rspamd_cryptobox_keypair *kp, - const guchar *in, gsize inlen, - guchar **out, gsize *outlen, + const unsigned char *in, gsize inlen, + unsigned char **out, gsize *outlen, GError **err) { - guchar *nonce, *mac, *data, *pubkey; + unsigned char *nonce, *mac, *data, *pubkey; struct rspamd_cryptobox_keypair *local; gsize olen; @@ -973,11 +973,11 @@ rspamd_keypair_encrypt(struct rspamd_cryptobox_keypair *kp, gboolean rspamd_pubkey_encrypt(struct rspamd_cryptobox_pubkey *pk, - const guchar *in, gsize inlen, - guchar **out, gsize *outlen, + const unsigned char *in, gsize inlen, + unsigned char **out, gsize *outlen, GError **err) { - guchar *nonce, *mac, *data, *pubkey; + unsigned char *nonce, *mac, *data, *pubkey; struct rspamd_cryptobox_keypair *local; gsize olen; diff --git a/src/libcryptobox/keypair.h b/src/libcryptobox/keypair.h index 64461b7d4..849246255 100644 --- a/src/libcryptobox/keypair.h +++ b/src/libcryptobox/keypair.h @@ -32,7 +32,7 @@ enum rspamd_cryptobox_keypair_type { RSPAMD_KEYPAIR_SIGN }; -extern const guchar encrypted_magic[7]; +extern const unsigned char encrypted_magic[7]; /** * Opaque structure for the full (public + private) keypair @@ -82,7 +82,7 @@ struct rspamd_cryptobox_pubkey *rspamd_pubkey_ref( * @param alg algorithm of the key (nist or curve25519) * @return new pubkey or NULL in case of error */ -struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_base32(const gchar *b32, +struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_base32(const char *b32, gsize len, enum rspamd_cryptobox_keypair_type type, enum rspamd_cryptobox_mode alg); @@ -94,7 +94,7 @@ struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_base32(const gchar *b32, * @param alg algorithm of the key (nist or curve25519) * @return new pubkey or NULL in case of error */ -struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_hex(const gchar *hex, +struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_hex(const char *hex, gsize len, enum rspamd_cryptobox_keypair_type type, enum rspamd_cryptobox_mode alg); @@ -106,7 +106,7 @@ struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_hex(const gchar *hex, * @param alg algorithm of the key (nist or curve25519) * @return new pubkey or NULL in case of error */ -struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_bin(const guchar *raw, +struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_bin(const unsigned char *raw, gsize len, enum rspamd_cryptobox_keypair_type type, enum rspamd_cryptobox_mode alg); @@ -145,23 +145,23 @@ enum rspamd_cryptobox_mode rspamd_pubkey_alg(struct rspamd_cryptobox_pubkey *p); * @param p * @return */ -const guchar *rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p, - struct rspamd_cryptobox_keypair *kp); +const unsigned char *rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p, + struct rspamd_cryptobox_keypair *kp); /** * Calculate and store nm value for the specified local key (performs ECDH) * @param p * @return */ -const guchar *rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p, - struct rspamd_cryptobox_keypair *kp); +const unsigned char *rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p, + struct rspamd_cryptobox_keypair *kp); /** * Get raw public key id for a specified keypair (rspamd_cryptobox_HASHBYTES) * @param kp * @return */ -const guchar *rspamd_keypair_get_id(struct rspamd_cryptobox_keypair *kp); +const unsigned char *rspamd_keypair_get_id(struct rspamd_cryptobox_keypair *kp); /** * Returns keypair extensions if any @@ -175,7 +175,7 @@ const ucl_object_t *rspamd_keypair_get_extensions(struct rspamd_cryptobox_keypai * @param kp * @return */ -const guchar *rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk); +const unsigned char *rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk); /** * Get raw public key from pubkey opaque structure @@ -183,8 +183,8 @@ const guchar *rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk); * @param len * @return */ -const guchar *rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk, - guint *len); +const unsigned char *rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk, + unsigned int *len); /** Short ID characters count */ #define RSPAMD_KEYPAIR_SHORT_ID_LEN 5 @@ -209,7 +209,7 @@ const guchar *rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk, * @return newly allocated string with keypair */ GString *rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, - guint how); + unsigned int how); /** * Print pubkey encoding it if needed @@ -218,7 +218,7 @@ GString *rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, * @return newly allocated string with keypair */ GString *rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, - guint how); + unsigned int how); /** Get keypair pubkey ID */ #define RSPAMD_KEYPAIR_COMPONENT_ID 0 @@ -234,8 +234,8 @@ GString *rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, * @param len length of input * @return raw content of the component */ -const guchar *rspamd_keypair_component(struct rspamd_cryptobox_keypair *kp, - guint ncomp, guint *len); +const unsigned char *rspamd_keypair_component(struct rspamd_cryptobox_keypair *kp, + unsigned int ncomp, unsigned int *len); /** * Create a new keypair from ucl object @@ -272,8 +272,8 @@ ucl_object_t *rspamd_keypair_to_ucl(struct rspamd_cryptobox_keypair *kp, * @return TRUE if decryption is completed, out must be freed in this case */ gboolean rspamd_keypair_decrypt(struct rspamd_cryptobox_keypair *kp, - const guchar *in, gsize inlen, - guchar **out, gsize *outlen, + const unsigned char *in, gsize inlen, + unsigned char **out, gsize *outlen, GError **err); /** @@ -289,8 +289,8 @@ gboolean rspamd_keypair_decrypt(struct rspamd_cryptobox_keypair *kp, * @return TRUE if encryption has been completed, out must be freed in this case */ gboolean rspamd_keypair_encrypt(struct rspamd_cryptobox_keypair *kp, - const guchar *in, gsize inlen, - guchar **out, gsize *outlen, + const unsigned char *in, gsize inlen, + unsigned char **out, gsize *outlen, GError **err); /** @@ -306,8 +306,8 @@ gboolean rspamd_keypair_encrypt(struct rspamd_cryptobox_keypair *kp, * @return TRUE if encryption has been completed, out must be freed in this case */ gboolean rspamd_pubkey_encrypt(struct rspamd_cryptobox_pubkey *pk, - const guchar *in, gsize inlen, - guchar **out, gsize *outlen, + const unsigned char *in, gsize inlen, + unsigned char **out, gsize *outlen, GError **err); #ifdef __cplusplus diff --git a/src/libcryptobox/keypair_private.h b/src/libcryptobox/keypair_private.h index 89e3f0996..793231701 100644 --- a/src/libcryptobox/keypair_private.h +++ b/src/libcryptobox/keypair_private.h @@ -27,7 +27,7 @@ extern "C" { * KEX cached data */ struct rspamd_cryptobox_nm { - guchar nm[rspamd_cryptobox_MAX_NMBYTES]; + unsigned char nm[rspamd_cryptobox_MAX_NMBYTES]; uint64_t sk_id; /* Used to store secret key id */ ref_entry_t ref; }; @@ -36,7 +36,7 @@ struct rspamd_cryptobox_nm { * Generic keypair */ struct rspamd_cryptobox_keypair { - guchar id[rspamd_cryptobox_HASHBYTES]; + unsigned char id[rspamd_cryptobox_HASHBYTES]; enum rspamd_cryptobox_keypair_type type; enum rspamd_cryptobox_mode alg; ucl_object_t *extensions; @@ -49,8 +49,8 @@ struct rspamd_cryptobox_keypair { #define RSPAMD_CRYPTOBOX_KEYPAIR_NIST(x) ((struct rspamd_cryptobox_keypair_nist *) (x)) struct rspamd_cryptobox_keypair_nist { struct rspamd_cryptobox_keypair parent; - guchar sk[32]; - guchar pk[65]; + unsigned char sk[32]; + unsigned char pk[65]; }; /* @@ -59,8 +59,8 @@ struct rspamd_cryptobox_keypair_nist { #define RSPAMD_CRYPTOBOX_KEYPAIR_25519(x) ((struct rspamd_cryptobox_keypair_25519 *) (x)) struct rspamd_cryptobox_keypair_25519 { struct rspamd_cryptobox_keypair parent; - guchar sk[32]; - guchar pk[32]; + unsigned char sk[32]; + unsigned char pk[32]; }; /* @@ -69,8 +69,8 @@ struct rspamd_cryptobox_keypair_25519 { #define RSPAMD_CRYPTOBOX_KEYPAIR_SIG_NIST(x) ((struct rspamd_cryptobox_keypair_sig_nist *) (x)) struct rspamd_cryptobox_keypair_sig_nist { struct rspamd_cryptobox_keypair parent; - guchar sk[32]; - guchar pk[65]; + unsigned char sk[32]; + unsigned char pk[65]; }; /* @@ -79,15 +79,15 @@ struct rspamd_cryptobox_keypair_sig_nist { #define RSPAMD_CRYPTOBOX_KEYPAIR_SIG_25519(x) ((struct rspamd_cryptobox_keypair_sig_25519 *) (x)) struct rspamd_cryptobox_keypair_sig_25519 { struct rspamd_cryptobox_keypair parent; - guchar sk[64]; - guchar pk[32]; + unsigned char sk[64]; + unsigned char pk[32]; }; /* * Public component of the keypair */ struct rspamd_cryptobox_pubkey { - guchar id[rspamd_cryptobox_HASHBYTES]; + unsigned char id[rspamd_cryptobox_HASHBYTES]; struct rspamd_cryptobox_nm *nm; enum rspamd_cryptobox_keypair_type type; enum rspamd_cryptobox_mode alg; @@ -100,7 +100,7 @@ struct rspamd_cryptobox_pubkey { #define RSPAMD_CRYPTOBOX_PUBKEY_NIST(x) ((struct rspamd_cryptobox_pubkey_nist *) (x)) struct rspamd_cryptobox_pubkey_nist { struct rspamd_cryptobox_pubkey parent; - guchar pk[65]; + unsigned char pk[65]; }; /* @@ -109,7 +109,7 @@ struct rspamd_cryptobox_pubkey_nist { #define RSPAMD_CRYPTOBOX_PUBKEY_25519(x) ((struct rspamd_cryptobox_pubkey_25519 *) (x)) struct rspamd_cryptobox_pubkey_25519 { struct rspamd_cryptobox_pubkey parent; - guchar pk[32]; + unsigned char pk[32]; }; /* @@ -118,7 +118,7 @@ struct rspamd_cryptobox_pubkey_25519 { #define RSPAMD_CRYPTOBOX_PUBKEY_SIG_NIST(x) ((struct rspamd_cryptobox_pubkey_sig_nist *) (x)) struct rspamd_cryptobox_pubkey_sig_nist { struct rspamd_cryptobox_pubkey parent; - guchar pk[65]; + unsigned char pk[65]; }; /* @@ -127,7 +127,7 @@ struct rspamd_cryptobox_pubkey_sig_nist { #define RSPAMD_CRYPTOBOX_PUBKEY_SIG_25519(x) ((struct rspamd_cryptobox_pubkey_sig_25519 *) (x)) struct rspamd_cryptobox_pubkey_sig_25519 { struct rspamd_cryptobox_pubkey parent; - guchar pk[32]; + unsigned char pk[32]; }; void rspamd_cryptobox_nm_dtor(struct rspamd_cryptobox_nm *nm); diff --git a/src/libcryptobox/keypairs_cache.c b/src/libcryptobox/keypairs_cache.c index 05712b25c..6003d9923 100644 --- a/src/libcryptobox/keypairs_cache.c +++ b/src/libcryptobox/keypairs_cache.c @@ -21,7 +21,7 @@ struct rspamd_keypair_elt { struct rspamd_cryptobox_nm *nm; - guchar pair[rspamd_cryptobox_HASHBYTES * 2]; + unsigned char pair[rspamd_cryptobox_HASHBYTES * 2]; }; struct rspamd_keypair_cache { @@ -37,7 +37,7 @@ rspamd_keypair_destroy(gpointer ptr) g_free(elt); } -static guint +static unsigned int rspamd_keypair_hash(gconstpointer ptr) { struct rspamd_keypair_elt *elt = (struct rspamd_keypair_elt *) ptr; @@ -56,7 +56,7 @@ rspamd_keypair_equal(gconstpointer p1, gconstpointer p2) } struct rspamd_keypair_cache * -rspamd_keypair_cache_new(guint max_items) +rspamd_keypair_cache_new(unsigned int max_items) { struct rspamd_keypair_cache *c; diff --git a/src/libcryptobox/keypairs_cache.h b/src/libcryptobox/keypairs_cache.h index 96e356a80..a3a717fa1 100644 --- a/src/libcryptobox/keypairs_cache.h +++ b/src/libcryptobox/keypairs_cache.h @@ -31,7 +31,7 @@ struct rspamd_keypair_cache; * @param max_items defines maximum count of elements in the cache * @return new cache */ -struct rspamd_keypair_cache *rspamd_keypair_cache_new(guint max_items); +struct rspamd_keypair_cache *rspamd_keypair_cache_new(unsigned int max_items); /** diff --git a/src/libmime/archives.c b/src/libmime/archives.c index 7f77cf591..c40c0e88a 100644 --- a/src/libmime/archives.c +++ b/src/libmime/archives.c @@ -39,7 +39,7 @@ rspamd_archive_dtor(gpointer p) { struct rspamd_archive *arch = p; struct rspamd_archive_file *f; - guint i; + unsigned int i; for (i = 0; i < arch->files->len; i++) { f = g_ptr_array_index(arch->files, i); @@ -58,9 +58,9 @@ static bool rspamd_archive_file_try_utf(struct rspamd_task *task, struct rspamd_archive *arch, struct rspamd_archive_file *fentry, - const gchar *in, gsize inlen) + const char *in, gsize inlen) { - const gchar *charset = NULL, *p, *end; + const char *charset = NULL, *p, *end; GString *res; charset = rspamd_mime_charset_find_by_content(in, inlen, TRUE); @@ -173,12 +173,12 @@ static void rspamd_archive_process_zip(struct rspamd_task *task, struct rspamd_mime_part *part) { - const guchar *p, *start, *end, *eocd = NULL, *cd; + const unsigned char *p, *start, *end, *eocd = NULL, *cd; const uint32_t eocd_magic = 0x06054b50, cd_basic_len = 46; - const guchar cd_magic[] = {0x50, 0x4b, 0x01, 0x02}; - const guint max_processed = 1024; + const unsigned char cd_magic[] = {0x50, 0x4b, 0x01, 0x02}; + const unsigned int max_processed = 1024; uint32_t cd_offset, cd_size, comp_size, uncomp_size, processed = 0; - guint16 extra_len, fname_len, comment_len; + uint16_t extra_len, fname_len, comment_len; struct rspamd_archive *arch; struct rspamd_archive_file *f = NULL; @@ -233,7 +233,7 @@ rspamd_archive_process_zip(struct rspamd_task *task, cd_offset = GUINT32_FROM_LE(cd_offset); /* We need to check sanity as well */ - if (cd_offset + cd_size > (guint) (eocd - start)) { + if (cd_offset + cd_size > (unsigned int) (eocd - start)) { msg_info_task("zip archive is invalid (bad size/offset for CD)"); return; @@ -251,7 +251,7 @@ rspamd_archive_process_zip(struct rspamd_task *task, arch); while (cd < start + cd_offset + cd_size) { - guint16 flags; + uint16_t flags; /* Read central directory record */ if (eocd - cd < cd_basic_len || @@ -261,7 +261,7 @@ rspamd_archive_process_zip(struct rspamd_task *task, return; } - memcpy(&flags, cd + 8, sizeof(guint16)); + memcpy(&flags, cd + 8, sizeof(uint16_t)); flags = GUINT16_FROM_LE(flags); memcpy(&comp_size, cd + 20, sizeof(uint32_t)); comp_size = GUINT32_FROM_LE(comp_size); @@ -305,22 +305,22 @@ rspamd_archive_process_zip(struct rspamd_task *task, } /* Process extra fields */ - const guchar *extra = cd + fname_len + cd_basic_len; + const unsigned char *extra = cd + fname_len + cd_basic_len; p = extra; - while (p + sizeof(guint16) * 2 < extra + extra_len) { - guint16 hid, hlen; + while (p + sizeof(uint16_t) * 2 < extra + extra_len) { + uint16_t hid, hlen; - memcpy(&hid, p, sizeof(guint16)); + memcpy(&hid, p, sizeof(uint16_t)); hid = GUINT16_FROM_LE(hid); - memcpy(&hlen, p + sizeof(guint16), sizeof(guint16)); + memcpy(&hlen, p + sizeof(uint16_t), sizeof(uint16_t)); hlen = GUINT16_FROM_LE(hlen); if (hid == 0x0017) { f->flags |= RSPAMD_ARCHIVE_FILE_ENCRYPTED; } - p += hlen + sizeof(guint16) * 2; + p += hlen + sizeof(uint16_t) * 2; } cd += fname_len + comment_len + extra_len + cd_basic_len; @@ -332,8 +332,8 @@ rspamd_archive_process_zip(struct rspamd_task *task, arch->size = part->parsed_data.len; } -static inline gint -rspamd_archive_rar_read_vint(const guchar *start, gsize remain, uint64_t *res) +static inline int +rspamd_archive_rar_read_vint(const unsigned char *start, gsize remain, uint64_t *res) { /* * From http://www.rarlab.com/technote.htm: @@ -345,8 +345,8 @@ rspamd_archive_rar_read_vint(const guchar *start, gsize remain, uint64_t *res) * continuation flag. Second byte, if present, contains next 7 bits and so on. */ uint64_t t = 0; - guint shift = 0; - const guchar *p = start; + unsigned int shift = 0; + const unsigned char *p = start; while (remain > 0 && shift <= 57) { if (*p & 0x80) { @@ -410,31 +410,31 @@ rspamd_archive_rar_read_vint(const guchar *start, gsize remain, uint64_t *res) #define RAR_READ_UINT16(n) \ do { \ - if (end - p < (glong) sizeof(guint16)) { \ + if (end - p < (glong) sizeof(uint16_t)) { \ msg_debug_archive("rar archive is invalid (bad int16)"); \ return; \ } \ n = p[0] + (p[1] << 8); \ - p += sizeof(guint16); \ + p += sizeof(uint16_t); \ } while (0) -#define RAR_READ_UINT32(n) \ - do { \ - if (end - p < (glong) sizeof(uint32_t)) { \ - msg_debug_archive("rar archive is invalid (bad int32)"); \ - return; \ - } \ - n = (guint) p[0] + ((guint) p[1] << 8) + ((guint) p[2] << 16) + ((guint) p[3] << 24); \ - p += sizeof(uint32_t); \ +#define RAR_READ_UINT32(n) \ + do { \ + if (end - p < (glong) sizeof(uint32_t)) { \ + msg_debug_archive("rar archive is invalid (bad int32)"); \ + return; \ + } \ + n = (unsigned int) p[0] + ((unsigned int) p[1] << 8) + ((unsigned int) p[2] << 16) + ((unsigned int) p[3] << 24); \ + p += sizeof(uint32_t); \ } while (0) static void -rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, - const guchar *end, struct rspamd_mime_part *part) +rspamd_archive_process_rar_v4(struct rspamd_task *task, const unsigned char *start, + const unsigned char *end, struct rspamd_mime_part *part) { - const guchar *p = start, *start_section; - guint8 type; - guint flags; + const unsigned char *p = start, *start_section; + uint8_t type; + unsigned int flags; uint64_t sz, comp_sz = 0, uncomp_sz = 0; struct rspamd_archive *arch; struct rspamd_archive_file *f; @@ -451,7 +451,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, while (p < end) { /* Crc16 */ start_section = p; - RAR_SKIP_BYTES(sizeof(guint16)); + RAR_SKIP_BYTES(sizeof(uint16_t)); type = *p; p++; RAR_READ_UINT16(flags); @@ -484,7 +484,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, } if (type == 0x74) { - guint fname_len; + unsigned int fname_len; /* File header */ /* Uncompressed size */ @@ -519,7 +519,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, if (flags & 0x200) { /* We have unicode + normal version */ - guchar *tmp; + unsigned char *tmp; tmp = memchr(p, '\0', fname_len); @@ -574,16 +574,16 @@ static void rspamd_archive_process_rar(struct rspamd_task *task, struct rspamd_mime_part *part) { - const guchar *p, *end, *section_start; - const guchar rar_v5_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00}, - rar_v4_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00}; - const guint rar_encrypted_header = 4, rar_main_header = 1, - rar_file_header = 2; + const unsigned char *p, *end, *section_start; + const unsigned char rar_v5_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00}, + rar_v4_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00}; + const unsigned int rar_encrypted_header = 4, rar_main_header = 1, + rar_file_header = 2; uint64_t vint, sz, comp_sz = 0, uncomp_sz = 0, flags = 0, type = 0, extra_sz = 0; struct rspamd_archive *arch; struct rspamd_archive_file *f; - gint r; + int r; p = part->parsed_data.begin; end = p + part->parsed_data.len; @@ -764,10 +764,10 @@ rspamd_archive_process_rar(struct rspamd_task *task, if (f && has_extra && extra_sz > 0 && p + fname_len + extra_sz < end) { /* Try to find encryption record in extra field */ - const guchar *ex = p + fname_len; + const unsigned char *ex = p + fname_len; while (ex < p + extra_sz) { - const guchar *t; + const unsigned char *t; int64_t cur_sz = 0, sec_type = 0; r = rspamd_archive_rar_read_vint(ex, extra_sz, &cur_sz); @@ -807,8 +807,8 @@ end: arch->size = part->parsed_data.len; } -static inline gint -rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, uint64_t *res) +static inline int +rspamd_archive_7zip_read_vint(const unsigned char *start, gsize remain, uint64_t *res) { /* * REAL_UINT64 means real UINT64. @@ -825,7 +825,7 @@ rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, uint64_t *res) * 11111110 BYTE y[7] : y * 11111111 BYTE y[8] : y */ - guchar t; + unsigned char t; if (remain == 0) { return -1; @@ -847,8 +847,8 @@ rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, uint64_t *res) } } else { - gint cur_bit = 6, intlen = 1; - const guchar bmask = 0xFF; + int cur_bit = 6, intlen = 1; + const unsigned char bmask = 0xFF; uint64_t tgt; while (cur_bit > 0) { @@ -904,15 +904,15 @@ rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, uint64_t *res) n = GUINT64_FROM_LE(n); \ p += sizeof(uint64_t); \ } while (0) -#define SZ_SKIP_BYTES(n) \ - do { \ - if (end - p >= (n)) { \ - p += (n); \ - } \ - else { \ - msg_debug_archive("7zip archive is invalid (truncated); wanted to read %d bytes, %d avail: %s", (gint) (n), (gint) (end - p), G_STRLOC); \ - return NULL; \ - } \ +#define SZ_SKIP_BYTES(n) \ + do { \ + if (end - p >= (n)) { \ + p += (n); \ + } \ + else { \ + msg_debug_archive("7zip archive is invalid (truncated); wanted to read %d bytes, %d avail: %s", (int) (n), (int) (end - p), G_STRLOC); \ + return NULL; \ + } \ } while (0) enum rspamd_7zip_header_mark { @@ -953,11 +953,11 @@ enum rspamd_7zip_header_mark { ((codec_id) == _7Z_CRYPTO_RAR_29) || \ ((codec_id) == _7Z_CRYPTO_AES_256_SHA_256)) -static const guchar * +static const unsigned char * rspamd_7zip_read_bits(struct rspamd_task *task, - const guchar *p, const guchar *end, - struct rspamd_archive *arch, guint nbits, - guint *pbits_set) + const unsigned char *p, const unsigned char *end, + struct rspamd_archive *arch, unsigned int nbits, + unsigned int *pbits_set) { unsigned mask = 0, avail = 0, i; gboolean bit_set = 0; @@ -981,16 +981,16 @@ rspamd_7zip_read_bits(struct rspamd_task *task, return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_digest(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch, uint64_t num_streams, - guint *pdigest_read) + unsigned int *pdigest_read) { - guchar all_defined = *p; + unsigned char all_defined = *p; uint64_t i; - guint num_defined = 0; + unsigned int num_defined = 0; /* * BYTE AllAreDefined * if (AllAreDefined == 0) @@ -1029,14 +1029,14 @@ rspamd_7zip_read_digest(struct rspamd_task *task, return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_pack_info(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch) { uint64_t pack_pos = 0, pack_streams = 0, i, cur_sz; - guint num_digests = 0; - guchar t; + unsigned int num_digests = 0; + unsigned char t; /* * UINT64 PackPos * UINT64 NumPackStreams @@ -1089,10 +1089,10 @@ end: return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_folder(struct rspamd_task *task, - const guchar *p, const guchar *end, - struct rspamd_archive *arch, guint *pnstreams, guint *ndigests) + const unsigned char *p, const unsigned char *end, + struct rspamd_archive *arch, unsigned int *pnstreams, unsigned int *ndigests) { uint64_t ncoders = 0, i, j, noutstreams = 0, ninstreams = 0; @@ -1100,7 +1100,7 @@ rspamd_7zip_read_folder(struct rspamd_task *task, for (i = 0; i < ncoders && p != NULL && p < end; i++) { uint64_t sz, tmp; - guchar t; + unsigned char t; /* * BYTE * { @@ -1189,15 +1189,15 @@ rspamd_7zip_read_folder(struct rspamd_task *task, return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_coders_info(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch, - guint *pnum_folders, guint *pnum_nodigest) + unsigned int *pnum_folders, unsigned int *pnum_nodigest) { uint64_t num_folders = 0, i, tmp; - guchar t; - guint *folder_nstreams = NULL, num_digests = 0, digests_read = 0; + unsigned char t; + unsigned int *folder_nstreams = NULL, num_digests = 0, digests_read = 0; while (p != NULL && p < end) { /* @@ -1259,11 +1259,11 @@ rspamd_7zip_read_coders_info(struct rspamd_task *task, case kCodersUnPackSize: for (i = 0; i < num_folders && p != NULL && p < end; i++) { if (folder_nstreams) { - for (guint j = 0; j < folder_nstreams[i]; j++) { + for (unsigned int j = 0; j < folder_nstreams[i]; j++) { SZ_READ_VINT(tmp); /* Unpacked size */ msg_debug_archive("7zip: unpacked size " "(folder=%d, stream=%d) = %L", - (gint) i, j, tmp); + (int) i, j, tmp); } } else { @@ -1315,14 +1315,14 @@ end: return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_substreams_info(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch, - guint num_folders, guint num_nodigest) + unsigned int num_folders, unsigned int num_nodigest) { - guchar t; - guint i; + unsigned char t; + unsigned int i; uint64_t *folder_nstreams; if (num_folders > 8192) { @@ -1380,7 +1380,7 @@ rspamd_7zip_read_substreams_info(struct rspamd_task *task, * In fact, it is just absent in the real life... */ for (i = 0; i < num_folders; i++) { - for (guint j = 0; j < folder_nstreams[i]; j++) { + for (unsigned int j = 0; j < folder_nstreams[i]; j++) { uint64_t tmp; SZ_READ_VINT(tmp); /* Who cares indeed */ @@ -1402,13 +1402,13 @@ end: return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_main_streams_info(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch) { - guchar t; - guint num_folders = 0, unknown_digests = 0; + unsigned char t; + unsigned int num_folders = 0, unknown_digests = 0; while (p != NULL && p < end) { t = *p; @@ -1459,12 +1459,12 @@ end: return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_archive_props(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch) { - guchar proptype; + unsigned char proptype; uint64_t proplen; /* @@ -1501,18 +1501,18 @@ rspamd_7zip_read_archive_props(struct rspamd_task *task, } static GString * -rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const guchar *p, - const guchar *end) +rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const unsigned char *p, + const unsigned char *end) { GString *res; goffset dest_pos = 0, src_pos = 0; - const gsize len = (end - p) / sizeof(guint16); - guint16 *up; + const gsize len = (end - p) / sizeof(uint16_t); + uint16_t *up; UChar32 wc; UBool is_error = 0; res = g_string_sized_new((end - p) * 3 / 2 + sizeof(wc) + 1); - up = (guint16 *) p; + up = (uint16_t *) p; while (src_pos < len) { U16_NEXT(up, src_pos, len, wc); @@ -1538,13 +1538,13 @@ rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const guchar *p, return res; } -static const guchar * +static const unsigned char * rspamd_7zip_read_files_info(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch) { uint64_t nfiles = 0, sz, i; - guchar t, b; + unsigned char t, b; struct rspamd_archive_file *fentry; SZ_READ_VINT(nfiles); @@ -1592,7 +1592,7 @@ rspamd_7zip_read_files_info(struct rspamd_task *task, for (i = 0; i < nfiles; i++) { /* Zero terminated wchar_t: happy converting... */ /* First, find terminator */ - const guchar *fend = NULL, *tp = p; + const unsigned char *fend = NULL, *tp = p; GString *res; while (tp < end - 1) { @@ -1644,13 +1644,13 @@ end: return p; } -static const guchar * +static const unsigned char * rspamd_7zip_read_next_section(struct rspamd_task *task, - const guchar *p, const guchar *end, + const unsigned char *p, const unsigned char *end, struct rspamd_archive *arch, struct rspamd_mime_part *part) { - guchar t = *p; + unsigned char t = *p; SZ_SKIP_BYTES(1); @@ -1732,8 +1732,8 @@ rspamd_archive_process_7zip(struct rspamd_task *task, struct rspamd_mime_part *part) { struct rspamd_archive *arch; - const guchar *start, *p, *end; - const guchar sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; + const unsigned char *start, *p, *end; + const unsigned char sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; uint64_t section_offset = 0, section_length = 0; start = part->parsed_data.begin; @@ -1793,9 +1793,9 @@ rspamd_archive_process_gzip(struct rspamd_task *task, struct rspamd_mime_part *part) { struct rspamd_archive *arch; - const guchar *start, *p, *end; - const guchar gz_magic[] = {0x1F, 0x8B}; - guchar flags; + const unsigned char *start, *p, *end; + const unsigned char gz_magic[] = {0x1F, 0x8B}; + unsigned char flags; start = part->parsed_data.begin; p = start; @@ -1834,7 +1834,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, if (flags & (1u << 2)) { /* Optional section */ - guint16 optlen = 0; + uint16_t optlen = 0; RAR_READ_UINT16(optlen); @@ -1849,7 +1849,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, } /* Read file name */ - const guchar *fname_start = p; + const unsigned char *fname_start = p; while (p < end) { if (*p == '\0') { @@ -1889,7 +1889,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, /* Fallback, we need to extract file name from archive name if possible */ if (part->cd && part->cd->filename.len > 0) { - const gchar *dot_pos, *slash_pos; + const char *dot_pos, *slash_pos; dot_pos = rspamd_memrchr(part->cd->filename.begin, '.', part->cd->filename.len); @@ -1914,7 +1914,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, goto set; } else { - const gchar *fname_start = part->cd->filename.begin; + const char *fname_start = part->cd->filename.begin; f = g_malloc0(sizeof(*f)); @@ -1951,11 +1951,11 @@ set: } static gboolean -rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const gchar *str, - const guchar *magic_start, gsize magic_len) +rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const char *str, + const unsigned char *magic_start, gsize magic_len) { struct rspamd_content_type *ct; - const gchar *p; + const char *p; rspamd_ftok_t srch, *fname; ct = part->ct; @@ -2024,12 +2024,12 @@ rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const gchar *str, void rspamd_archives_process(struct rspamd_task *task) { - guint i; + unsigned int i; struct rspamd_mime_part *part; - const guchar rar_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07}; - const guchar zip_magic[] = {0x50, 0x4b, 0x03, 0x04}; - const guchar sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; - const guchar gz_magic[] = {0x1F, 0x8B, 0x08}; + const unsigned char rar_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07}; + const unsigned char zip_magic[] = {0x50, 0x4b, 0x03, 0x04}; + const unsigned char sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; + const unsigned char gz_magic[] = {0x1F, 0x8B, 0x08}; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) { @@ -2071,10 +2071,10 @@ void rspamd_archives_process(struct rspamd_task *task) } -const gchar * +const char * rspamd_archive_type_str(enum rspamd_archive_type type) { - const gchar *ret = "unknown"; + const char *ret = "unknown"; switch (type) { case RSPAMD_ARCHIVE_ZIP: diff --git a/src/libmime/archives.h b/src/libmime/archives.h index 56beb6227..cafa06047 100644 --- a/src/libmime/archives.h +++ b/src/libmime/archives.h @@ -63,7 +63,7 @@ void rspamd_archives_process(struct rspamd_task *task); /** * Get textual representation of an archive's type */ -const gchar *rspamd_archive_type_str(enum rspamd_archive_type type); +const char *rspamd_archive_type_str(enum rspamd_archive_type type); #ifdef __cplusplus } diff --git a/src/libmime/content_type.c b/src/libmime/content_type.c index 1b5c77987..07c61b671 100644 --- a/src/libmime/content_type.c +++ b/src/libmime/content_type.c @@ -23,9 +23,9 @@ static gboolean rspamd_rfc2231_decode(rspamd_mempool_t *pool, struct rspamd_content_type_param *param, - gchar *value_start, gchar *value_end) + char *value_start, char *value_end) { - gchar *quote_pos; + char *quote_pos; quote_pos = memchr(value_start, '\'', value_end - value_start); @@ -42,7 +42,7 @@ rspamd_rfc2231_decode(rspamd_mempool_t *pool, * encoding'data (in theory). * Try to handle both... */ - const gchar *charset = NULL; + const char *charset = NULL; rspamd_ftok_t ctok; ctok.begin = value_start; @@ -102,10 +102,10 @@ rspamd_rfc2231_decode(rspamd_mempool_t *pool, static gboolean rspamd_param_maybe_rfc2231_process(rspamd_mempool_t *pool, struct rspamd_content_type_param *param, - gchar *name_start, gchar *name_end, - gchar *value_start, gchar *value_end) + char *name_start, char *name_end, + char *value_start, char *value_end) { - const gchar *star_pos; + const char *star_pos; star_pos = memchr(name_start, '*', name_end - name_start); @@ -191,7 +191,7 @@ rspamd_postprocess_ct_attributes(rspamd_mempool_t *pool, if (param->flags & RSPAMD_CONTENT_PARAM_PIECEWISE) { /* Reconstruct param */ gsize tlen = 0; - gchar *ndata, *pos; + char *ndata, *pos; sorted = param; DL_SORT(sorted, rspamd_cmp_pieces); @@ -267,7 +267,7 @@ rspamd_content_type_postprocess(rspamd_mempool_t *pool, if (rspamd_ftok_icase_equal(¶m->name, &srch)) { found = param; - gchar *lc_boundary; + char *lc_boundary; /* Adjust boundary */ lc_boundary = rspamd_mempool_alloc(pool, param->value.len); memcpy(lc_boundary, param->value.begin, param->value.len); @@ -283,7 +283,7 @@ rspamd_content_type_postprocess(rspamd_mempool_t *pool, RSPAMD_FTOK_ASSIGN(&srch, "name"); if (!rspamd_ftok_icase_equal(¶m->name, &srch)) { /* Just lowercase */ - rspamd_str_lc_utf8((gchar *) param->value.begin, param->value.len); + rspamd_str_lc_utf8((char *) param->value.begin, param->value.len); } } } @@ -308,8 +308,8 @@ rspamd_content_disposition_postprocess(rspamd_mempool_t *pool, void rspamd_content_type_add_param(rspamd_mempool_t *pool, struct rspamd_content_type *ct, - gchar *name_start, gchar *name_end, - gchar *value_start, gchar *value_end) + char *name_start, char *name_end, + char *value_start, char *value_end) { struct rspamd_content_type_param *nparam; rspamd_ftok_t srch; @@ -349,10 +349,10 @@ void rspamd_content_type_add_param(rspamd_mempool_t *pool, } static struct rspamd_content_type * -rspamd_content_type_parser(gchar *in, gsize len, rspamd_mempool_t *pool) +rspamd_content_type_parser(char *in, gsize len, rspamd_mempool_t *pool) { - guint obraces = 0, ebraces = 0, qlen = 0; - gchar *p, *c, *end, *pname_start = NULL, *pname_end = NULL; + unsigned int obraces = 0, ebraces = 0, qlen = 0; + char *p, *c, *end, *pname_start = NULL, *pname_end = NULL; struct rspamd_content_type *res = NULL, val; gboolean eqsign_seen = FALSE; enum { @@ -662,7 +662,7 @@ rspamd_content_type_parser(gchar *in, gsize len, rspamd_mempool_t *pool) } if (val.type.len > 0) { - gchar *tmp; + char *tmp; res = rspamd_mempool_alloc(pool, sizeof(val)); memcpy(res, &val, sizeof(val)); @@ -688,12 +688,12 @@ rspamd_content_type_parser(gchar *in, gsize len, rspamd_mempool_t *pool) } struct rspamd_content_type * -rspamd_content_type_parse(const gchar *in, +rspamd_content_type_parse(const char *in, gsize len, rspamd_mempool_t *pool) { struct rspamd_content_type *res = NULL; rspamd_ftok_t srch; - gchar *cpy; + char *cpy; cpy = rspamd_mempool_alloc(pool, len + 1); rspamd_strlcpy(cpy, in, len + 1); @@ -793,7 +793,7 @@ rspamd_content_type_parse(const gchar *in, } } else { - msg_warn_pool("cannot parse content type: %*s", (gint) len, cpy); + msg_warn_pool("cannot parse content type: %*s", (int) len, cpy); } return res; @@ -801,11 +801,11 @@ rspamd_content_type_parse(const gchar *in, void rspamd_content_disposition_add_param(rspamd_mempool_t *pool, struct rspamd_content_disposition *cd, - const gchar *name_start, const gchar *name_end, - const gchar *value_start, const gchar *value_end) + const char *name_start, const char *name_end, + const char *value_start, const char *value_end) { rspamd_ftok_t srch; - gchar *name_cpy, *value_cpy, *name_cpy_end, *value_cpy_end; + char *name_cpy, *value_cpy, *name_cpy_end, *value_cpy_end; struct rspamd_content_type_param *found = NULL, *nparam; g_assert(cd != NULL); @@ -850,7 +850,7 @@ void rspamd_content_disposition_add_param(rspamd_mempool_t *pool, } struct rspamd_content_disposition * -rspamd_content_disposition_parse(const gchar *in, +rspamd_content_disposition_parse(const char *in, gsize len, rspamd_mempool_t *pool) { struct rspamd_content_disposition *res = NULL, val; @@ -877,7 +877,7 @@ rspamd_content_disposition_parse(const gchar *in, } else { msg_warn_pool("cannot parse content disposition: %*s", - (gint) len, in); + (int) len, in); } return res; diff --git a/src/libmime/content_type.h b/src/libmime/content_type.h index ac49bdc35..2177cdf2d 100644 --- a/src/libmime/content_type.h +++ b/src/libmime/content_type.h @@ -46,13 +46,13 @@ enum rspamd_content_param_flags { struct rspamd_content_type_param { rspamd_ftok_t name; rspamd_ftok_t value; - guint rfc2231_id; + unsigned int rfc2231_id; enum rspamd_content_param_flags flags; struct rspamd_content_type_param *prev, *next; }; struct rspamd_content_type { - gchar *cpy; + char *cpy; rspamd_ftok_t type; rspamd_ftok_t subtype; rspamd_ftok_t charset; @@ -69,7 +69,7 @@ enum rspamd_content_disposition_type { }; struct rspamd_content_disposition { - gchar *lc_data; + char *lc_data; enum rspamd_content_disposition_type type; rspamd_ftok_t filename; GHashTable *attrs; /* Can be empty */ @@ -85,8 +85,8 @@ struct rspamd_content_disposition { */ void rspamd_content_type_add_param(rspamd_mempool_t *pool, struct rspamd_content_type *ct, - gchar *name_start, gchar *name_end, - gchar *value_start, gchar *value_end); + char *name_start, char *name_end, + char *value_start, char *value_end); /** * Parse content type from the header (performs copy + lowercase) @@ -95,7 +95,7 @@ void rspamd_content_type_add_param(rspamd_mempool_t *pool, * @param pool * @return */ -struct rspamd_content_type *rspamd_content_type_parse(const gchar *in, +struct rspamd_content_type *rspamd_content_type_parse(const char *in, gsize len, rspamd_mempool_t *pool); /** @@ -109,8 +109,8 @@ struct rspamd_content_type *rspamd_content_type_parse(const gchar *in, */ void rspamd_content_disposition_add_param(rspamd_mempool_t *pool, struct rspamd_content_disposition *cd, - const gchar *name_start, const gchar *name_end, - const gchar *value_start, const gchar *value_end); + const char *name_start, const char *name_end, + const char *value_start, const char *value_end); /** * Parse content-disposition header @@ -119,7 +119,7 @@ void rspamd_content_disposition_add_param(rspamd_mempool_t *pool, * @param pool * @return */ -struct rspamd_content_disposition *rspamd_content_disposition_parse(const gchar *in, +struct rspamd_content_disposition *rspamd_content_disposition_parse(const char *in, gsize len, rspamd_mempool_t *pool); diff --git a/src/libmime/email_addr.c b/src/libmime/email_addr.c index 0af7388a8..da1453050 100644 --- a/src/libmime/email_addr.c +++ b/src/libmime/email_addr.c @@ -48,7 +48,7 @@ rspamd_email_address_unescape(struct rspamd_email_address *addr) } struct rspamd_email_address * -rspamd_email_address_from_smtp(const gchar *str, guint len) +rspamd_email_address_from_smtp(const char *str, unsigned int len) { struct rspamd_email_address addr, *ret; gsize nlen; @@ -73,8 +73,8 @@ rspamd_email_address_from_smtp(const gchar *str, guint len) nlen = ret->domain_len + ret->user_len + 2; ret->addr = g_malloc(nlen + 1); ret->addr_len = rspamd_snprintf((char *) ret->addr, nlen, "%*s@%*s", - (gint) ret->user_len, ret->user, - (gint) ret->domain_len, ret->domain); + (int) ret->user_len, ret->user, + (int) ret->domain_len, ret->domain); ret->flags |= RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED; } @@ -106,7 +106,7 @@ rspamd_email_address_add(rspamd_mempool_t *pool, GString *name) { struct rspamd_email_address *elt; - guint nlen; + unsigned int nlen; elt = g_malloc0(sizeof(*elt)); rspamd_mempool_notify_alloc(pool, sizeof(*elt)); @@ -134,8 +134,8 @@ rspamd_email_address_add(rspamd_mempool_t *pool, elt->addr = g_malloc(nlen + 1); rspamd_mempool_notify_alloc(pool, nlen + 1); elt->addr_len = rspamd_snprintf((char *) elt->addr, nlen, "%*s@%*s", - (gint) elt->user_len, elt->user, - (gint) elt->domain_len, elt->domain); + (int) elt->user_len, elt->user, + (int) elt->domain_len, elt->domain); elt->flags |= RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED; } @@ -155,7 +155,7 @@ static gboolean rspamd_email_address_parse_heuristic(const char *data, size_t len, struct rspamd_email_address *addr) { - const gchar *p = data, *at = NULL, *end = data + len; + const char *p = data, *at = NULL, *end = data + len; gboolean ret = FALSE; memset(addr, 0, sizeof(*addr)); @@ -199,11 +199,11 @@ rspamd_email_address_parse_heuristic(const char *data, size_t len, } static inline int -rspamd_email_address_check_and_add(const gchar *start, gsize len, +rspamd_email_address_check_and_add(const char *start, gsize len, GPtrArray *res, rspamd_mempool_t *pool, GString *ns, - gint max_elements) + int max_elements) { struct rspamd_email_address addr; @@ -241,17 +241,17 @@ rspamd_email_address_check_and_add(const gchar *start, gsize len, } GPtrArray * -rspamd_email_address_from_mime(rspamd_mempool_t *pool, const gchar *hdr, - guint len, +rspamd_email_address_from_mime(rspamd_mempool_t *pool, const char *hdr, + unsigned int len, GPtrArray *src, - gint max_elements) + int max_elements) { GPtrArray *res = src; gboolean seen_at = FALSE, seen_obrace = FALSE; - const gchar *p = hdr, *end = hdr + len, *c = hdr, *t; + const char *p = hdr, *end = hdr + len, *c = hdr, *t; GString *ns, *cpy; - gint obraces, ebraces; + int obraces, ebraces; enum { parse_name = 0, parse_quoted, @@ -343,7 +343,7 @@ rspamd_email_address_from_mime(rspamd_mempool_t *pool, const gchar *hdr, if (*p == '"') { /* We need to strip last spaces and update `ns` */ if (p > c) { - guint nspaces = 0; + unsigned int nspaces = 0; t = p - 1; @@ -551,7 +551,7 @@ end: void rspamd_email_address_list_destroy(gpointer ptr) { GPtrArray *ar = ptr; - guint i; + unsigned int i; struct rspamd_email_address *addr; PTR_ARRAY_FOREACH(ar, i, addr) diff --git a/src/libmime/email_addr.h b/src/libmime/email_addr.h index ed00722f9..280e4a503 100644 --- a/src/libmime/email_addr.h +++ b/src/libmime/email_addr.h @@ -45,17 +45,17 @@ enum rspamd_email_address_flags { * Structure that represents email address in a convenient way */ struct rspamd_email_address { - const gchar *raw; - const gchar *addr; - const gchar *user; - const gchar *domain; - const gchar *name; + const char *raw; + const char *addr; + const char *user; + const char *domain; + const char *name; - guint raw_len; - guint addr_len; - guint domain_len; - guint user_len; - guint flags; + unsigned int raw_len; + unsigned int addr_len; + unsigned int domain_len; + unsigned int user_len; + unsigned int flags; }; struct rspamd_task; @@ -66,7 +66,7 @@ struct rspamd_task; * @param len length of string * @return */ -struct rspamd_email_address *rspamd_email_address_from_smtp(const gchar *str, guint len); +struct rspamd_email_address *rspamd_email_address_from_smtp(const char *str, unsigned int len); /** * Parses email address from the mime header, decodes names and return the array @@ -78,8 +78,8 @@ struct rspamd_email_address *rspamd_email_address_from_smtp(const gchar *str, gu * @return */ GPtrArray * -rspamd_email_address_from_mime(rspamd_mempool_t *pool, const gchar *hdr, guint len, - GPtrArray *src, gint max_elements); +rspamd_email_address_from_mime(rspamd_mempool_t *pool, const char *hdr, unsigned int len, + GPtrArray *src, int max_elements); /** * Destroys list of email addresses diff --git a/src/libmime/images.c b/src/libmime/images.c index be4d02f06..1078baba6 100644 --- a/src/libmime/images.c +++ b/src/libmime/images.c @@ -36,12 +36,12 @@ INIT_LOG_MODULE(images) static rspamd_lru_hash_t *images_hash = NULL; #endif -static const guint8 png_signature[] = {137, 80, 78, 71, 13, 10, 26, 10}; -static const guint8 jpg_sig1[] = {0xff, 0xd8}; -static const guint8 jpg_sig_jfif[] = {0xff, 0xe0}; -static const guint8 jpg_sig_exif[] = {0xff, 0xe1}; -static const guint8 gif_signature[] = {'G', 'I', 'F', '8'}; -static const guint8 bmp_signature[] = {'B', 'M'}; +static const uint8_t png_signature[] = {137, 80, 78, 71, 13, 10, 26, 10}; +static const uint8_t jpg_sig1[] = {0xff, 0xd8}; +static const uint8_t jpg_sig_jfif[] = {0xff, 0xe0}; +static const uint8_t jpg_sig_exif[] = {0xff, 0xe1}; +static const uint8_t gif_signature[] = {'G', 'I', 'F', '8'}; +static const uint8_t bmp_signature[] = {'B', 'M'}; static bool process_image(struct rspamd_task *task, struct rspamd_mime_part *part); @@ -63,7 +63,7 @@ bool rspamd_images_process_mime_part_maybe(struct rspamd_task *task, void rspamd_images_process(struct rspamd_task *task) { - guint i; + unsigned int i; struct rspamd_mime_part *part; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) @@ -108,7 +108,7 @@ process_png_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) { struct rspamd_image *img; uint32_t t; - const guint8 *p; + const uint8_t *p; if (data->len < 24) { msg_info_pool("bad png detected (maybe striped)"); @@ -140,8 +140,8 @@ process_png_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) static struct rspamd_image * process_jpg_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) { - const guint8 *p, *end; - guint16 h, w; + const uint8_t *p, *end; + uint16_t h, w; struct rspamd_image *img; img = rspamd_mempool_alloc0(pool, sizeof(struct rspamd_image)); @@ -154,13 +154,13 @@ process_jpg_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) while (p < end) { if (p[0] == 0xFF && p[1] != 0xFF) { - guint len = p[2] * 256 + p[3]; + unsigned int len = p[2] * 256 + p[3]; p++; if (*p == 0xc0 || *p == 0xc1 || *p == 0xc2 || *p == 0xc3 || *p == 0xc9 || *p == 0xca || *p == 0xcb) { - memcpy(&h, p + 4, sizeof(guint16)); + memcpy(&h, p + 4, sizeof(uint16_t)); h = p[4] * 0xff + p[5]; img->height = h; w = p[6] * 0xff + p[7]; @@ -184,8 +184,8 @@ static struct rspamd_image * process_gif_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) { struct rspamd_image *img; - const guint8 *p; - guint16 t; + const uint8_t *p; + uint16_t t; if (data->len < 10) { msg_info_pool("bad gif detected (maybe striped)"); @@ -197,9 +197,9 @@ process_gif_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) img->data = data; p = data->begin + 6; - memcpy(&t, p, sizeof(guint16)); + memcpy(&t, p, sizeof(uint16_t)); img->width = GUINT16_FROM_LE(t); - memcpy(&t, p + 2, sizeof(guint16)); + memcpy(&t, p + 2, sizeof(uint16_t)); img->height = GUINT16_FROM_LE(t); return img; @@ -210,7 +210,7 @@ process_bmp_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) { struct rspamd_image *img; int32_t t; - const guint8 *p; + const uint8_t *p; if (data->len < 28) { msg_info_pool("bad bmp detected (maybe striped)"); @@ -235,20 +235,20 @@ process_bmp_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) * http://unix4lyfe.org/dct/ */ static void -rspamd_image_dct_block(gint pixels[8][8], gdouble *out) +rspamd_image_dct_block(int pixels[8][8], double *out) { - gint i; - gint rows[8][8]; + int i; + int rows[8][8]; - static const gint c1 = 1004 /* cos(pi/16) << 10 */, - s1 = 200 /* sin(pi/16) */, - c3 = 851 /* cos(3pi/16) << 10 */, - s3 = 569 /* sin(3pi/16) << 10 */, - r2c6 = 554 /* sqrt(2)*cos(6pi/16) << 10 */, - r2s6 = 1337 /* sqrt(2)*sin(6pi/16) << 10 */, - r2 = 181; /* sqrt(2) << 7*/ + static const int c1 = 1004 /* cos(pi/16) << 10 */, + s1 = 200 /* sin(pi/16) */, + c3 = 851 /* cos(3pi/16) << 10 */, + s3 = 569 /* sin(3pi/16) << 10 */, + r2c6 = 554 /* sqrt(2)*cos(6pi/16) << 10 */, + r2s6 = 1337 /* sqrt(2)*sin(6pi/16) << 10 */, + r2 = 181; /* sqrt(2) << 7*/ - gint x0, x1, x2, x3, x4, x5, x6, x7, x8; + int x0, x1, x2, x3, x4, x5, x6, x7, x8; /* transform rows */ for (i = 0; i < 8; i++) { @@ -362,8 +362,8 @@ rspamd_image_dct_block(gint pixels[8][8], gdouble *out) } struct rspamd_image_cache_entry { - guchar digest[64]; - guchar dct[RSPAMD_DCT_LEN / NBBY]; + unsigned char digest[64]; + unsigned char dct[RSPAMD_DCT_LEN / NBBY]; }; static void @@ -447,8 +447,8 @@ void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img) { #ifdef USABLE_GD gdImagePtr src = NULL, dst = NULL; - guint i, j, k, l; - gdouble *dct; + unsigned int i, j, k, l; + double *dct; if (img->data->len == 0 || img->data->len > G_MAXINT32) { return; @@ -496,7 +496,7 @@ void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img) gdImageDestroy(src); img->is_normalized = TRUE; - dct = g_malloc0(sizeof(gdouble) * RSPAMD_DCT_LEN); + dct = g_malloc0(sizeof(double) * RSPAMD_DCT_LEN); img->dct = g_malloc0(RSPAMD_DCT_LEN / NBBY); rspamd_mempool_add_destructor(task->task_pool, g_free, img->dct); @@ -520,7 +520,7 @@ void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img) */ for (i = 0; i < RSPAMD_NORMALIZED_DIM; i += 8) { for (j = 0; j < RSPAMD_NORMALIZED_DIM; j += 8) { - gint p[8][8]; + int p[8][8]; for (k = 0; k < 8; k++) { p[k][0] = gdImageGetPixel(dst, i + k, j); @@ -536,20 +536,20 @@ void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img) rspamd_image_dct_block(p, dct + i * RSPAMD_NORMALIZED_DIM + j); - gdouble avg = 0.0; + double avg = 0.0; for (k = 0; k < 8; k++) { for (l = 0; l < 8; l++) { - gdouble x = *(dct + - i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l); - avg += (x - avg) / (gdouble) (k * 8 + l + 1); + double x = *(dct + + i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l); + avg += (x - avg) / (double) (k * 8 + l + 1); } } for (k = 0; k < 8; k++) { for (l = 0; l < 8; l++) { - guint idx = i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l; + unsigned int idx = i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l; if (dct[idx] >= avg) { setbit(img->dct, idx); @@ -623,7 +623,7 @@ process_image(struct rspamd_task *task, struct rspamd_mime_part *part) return false; } -const gchar * +const char * rspamd_image_type_str(enum rspamd_image_type type) { switch (type) { @@ -652,8 +652,8 @@ rspamd_image_process_part(struct rspamd_task *task, struct rspamd_mime_part *par struct rspamd_mime_header *rh; struct rspamd_mime_text_part *tp; struct html_image *himg; - const gchar *cid; - guint cid_len, i; + const char *cid; + unsigned int cid_len, i; struct rspamd_image *img; img = (struct rspamd_image *) part->specific.img; @@ -707,7 +707,7 @@ rspamd_image_process_part(struct rspamd_task *task, struct rspamd_mime_part *par void rspamd_images_link(struct rspamd_task *task) { struct rspamd_mime_part *part; - guint i; + unsigned int i; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) { diff --git a/src/libmime/images.h b/src/libmime/images.h index a70fb7eab..d55034e2d 100644 --- a/src/libmime/images.h +++ b/src/libmime/images.h @@ -31,7 +31,7 @@ struct rspamd_image { uint32_t width; uint32_t height; gboolean is_normalized; - guchar *dct; + unsigned char *dct; }; /* @@ -65,7 +65,7 @@ struct rspamd_image *rspamd_maybe_process_image(rspamd_mempool_t *pool, /* * Get textual representation of an image's type */ -const gchar *rspamd_image_type_str(enum rspamd_image_type type); +const char *rspamd_image_type_str(enum rspamd_image_type type); void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img); diff --git a/src/libmime/lang_detection.c b/src/libmime/lang_detection.c index 0321ee7df..c3a647507 100644 --- a/src/libmime/lang_detection.c +++ b/src/libmime/lang_detection.c @@ -33,14 +33,14 @@ static const gsize default_short_text_limit = 10; static const gsize default_words = 80; -static const gdouble update_prob = 0.6; -static const gchar *default_languages_path = RSPAMD_SHAREDIR "/languages"; +static const double update_prob = 0.6; +static const char *default_languages_path = RSPAMD_SHAREDIR "/languages"; #undef EXTRA_LANGDET_DEBUG struct rspamd_language_unicode_match { - const gchar *lang; - gint unicode_code; + const char *lang; + int unicode_code; }; /* @@ -63,10 +63,10 @@ static const struct rspamd_language_unicode_match unicode_langs[] = { /* * Top languages */ -static const gchar *tier0_langs[] = { +static const char *tier0_langs[] = { "en", }; -static const gchar *tier1_langs[] = { +static const char *tier1_langs[] = { "fr", "it", "de", "es", "nl", "pt", "ru", "pl", "tk", "th", "ar"}; @@ -79,31 +79,31 @@ enum rspamd_language_category { }; struct rspamd_language_elt { - const gchar *name; /* e.g. "en" or "ru" */ - gint flags; /* enum rspamd_language_elt_flags */ + const char *name; /* e.g. "en" or "ru" */ + int flags; /* enum rspamd_language_elt_flags */ enum rspamd_language_category category; - guint trigrams_words; - guint stop_words; - gdouble mean; - gdouble std; - guint occurrences; /* total number of parts with this language */ + unsigned int trigrams_words; + unsigned int stop_words; + double mean; + double std; + unsigned int occurrences; /* total number of parts with this language */ }; struct rspamd_ngramm_elt { struct rspamd_language_elt *elt; - gdouble prob; + double prob; }; struct rspamd_ngramm_chain { GPtrArray *languages; - gdouble mean; - gdouble std; - gchar *utf; + double mean; + double std; + char *utf; }; struct rspamd_stop_word_range { - guint start; - guint stop; + unsigned int start; + unsigned int stop; struct rspamd_language_elt *elt; }; @@ -124,7 +124,7 @@ struct rspamd_stop_word_elt { INIT_LOG_MODULE_PUBLIC(langdet) static const struct rspamd_language_unicode_match * -rspamd_language_search_unicode_match(const gchar *key, +rspamd_language_search_unicode_match(const char *key, const struct rspamd_language_unicode_match *elts, size_t nelts) { size_t i; @@ -139,7 +139,7 @@ rspamd_language_search_unicode_match(const gchar *key, } static gboolean -rspamd_language_search_str(const gchar *key, const gchar *elts[], size_t nelts) +rspamd_language_search_str(const char *key, const char *elts[], size_t nelts) { size_t i; @@ -151,7 +151,7 @@ rspamd_language_search_str(const gchar *key, const gchar *elts[], size_t nelts) return FALSE; } -static guint +static unsigned int rspamd_trigram_hash_func(gconstpointer key) { return rspamd_cryptobox_fast_hash(key, 3 * sizeof(UChar32), @@ -166,14 +166,14 @@ rspamd_trigram_equal_func(gconstpointer v, gconstpointer v2) KHASH_INIT(rspamd_trigram_hash, const UChar32 *, struct rspamd_ngramm_chain, true, rspamd_trigram_hash_func, rspamd_trigram_equal_func); -KHASH_INIT(rspamd_candidates_hash, const gchar *, +KHASH_INIT(rspamd_candidates_hash, const char *, struct rspamd_lang_detector_res *, true, rspamd_str_hash, rspamd_str_equal); KHASH_INIT(rspamd_stopwords_hash, rspamd_ftok_t *, char, false, rspamd_ftok_hash, rspamd_ftok_equal); -KHASH_INIT(rspamd_languages_hash, const gchar *, struct rspamd_language_elt *, true, +KHASH_INIT(rspamd_languages_hash, const char *, struct rspamd_language_elt *, true, rspamd_str_hash, rspamd_str_equal); struct rspamd_lang_detector { khash_t(rspamd_languages_hash) * languages; @@ -215,8 +215,8 @@ rspamd_language_detector_ucs_is_latin(const UChar32 *s, gsize len) } struct rspamd_language_ucs_elt { - guint freq; - const gchar *utf; + unsigned int freq; + const char *utf; UChar32 s[0]; }; @@ -225,15 +225,15 @@ rspamd_language_detector_init_ngramm(struct rspamd_config *cfg, struct rspamd_lang_detector *d, struct rspamd_language_elt *lelt, struct rspamd_language_ucs_elt *ucs, - guint len, - guint freq, - guint total, + unsigned int len, + unsigned int freq, + unsigned int total, khash_t(rspamd_trigram_hash) * htb) { struct rspamd_ngramm_chain *chain = NULL, st_chain; struct rspamd_ngramm_elt *elt; khiter_t k; - guint i; + unsigned int i; gboolean found; switch (len) { @@ -262,7 +262,7 @@ rspamd_language_detector_init_ngramm(struct rspamd_config *cfg, chain->utf = rspamd_mempool_strdup(cfg->cfg_pool, ucs->utf); elt = rspamd_mempool_alloc(cfg->cfg_pool, sizeof(*elt)); elt->elt = lelt; - elt->prob = ((gdouble) freq) / ((gdouble) total); + elt->prob = ((double) freq) / ((double) total); g_ptr_array_add(chain->languages, elt); k = kh_put(rspamd_trigram_hash, htb, ucs->s, &i); @@ -276,7 +276,7 @@ rspamd_language_detector_init_ngramm(struct rspamd_config *cfg, { if (strcmp(elt->elt->name, lelt->name) == 0) { found = TRUE; - elt->prob += ((gdouble) freq) / ((gdouble) total); + elt->prob += ((double) freq) / ((double) total); break; } } @@ -284,14 +284,14 @@ rspamd_language_detector_init_ngramm(struct rspamd_config *cfg, if (!found) { elt = rspamd_mempool_alloc(cfg->cfg_pool, sizeof(*elt)); elt->elt = lelt; - elt->prob = ((gdouble) freq) / ((gdouble) total); + elt->prob = ((double) freq) / ((double) total); g_ptr_array_add(chain->languages, elt); } } } static inline enum rspamd_language_category -rspamd_language_detector_get_category(guint uflags) +rspamd_language_detector_get_category(unsigned int uflags) { enum rspamd_language_category cat = RSPAMD_LANGUAGE_LATIN; @@ -308,10 +308,10 @@ rspamd_language_detector_get_category(guint uflags) return cat; } -static const gchar * +static const char * rspamd_language_detector_print_flags(struct rspamd_language_elt *elt) { - static gchar flags_buf[256]; + static char flags_buf[256]; goffset r = 0; if (elt->flags & RS_LANGUAGE_TIER1) { @@ -334,19 +334,19 @@ rspamd_language_detector_print_flags(struct rspamd_language_elt *elt) return flags_buf; } -static gint +static int rspamd_language_detector_cmp_ngramm(gconstpointer a, gconstpointer b) { struct rspamd_language_ucs_elt *e1 = *(struct rspamd_language_ucs_elt **) a; struct rspamd_language_ucs_elt *e2 = *(struct rspamd_language_ucs_elt **) b; - return (gint) e2->freq - (gint) e1->freq; + return (int) e2->freq - (int) e1->freq; } static void rspamd_language_detector_read_file(struct rspamd_config *cfg, struct rspamd_lang_detector *d, - const gchar *path, + const char *path, const ucl_object_t *stop_words) { struct ucl_parser *parser; @@ -357,10 +357,10 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, struct rspamd_language_elt *nelt; struct rspamd_language_ucs_elt *ucs_elt; khash_t(rspamd_trigram_hash) *htb = NULL; - gchar *pos; - guint total = 0, total_latin = 0, total_ngramms = 0, i, skipped, - loaded; - gdouble mean = 0, std = 0, delta = 0, delta2 = 0, m2 = 0; + char *pos; + unsigned int total = 0, total_latin = 0, total_ngramms = 0, i, skipped, + loaded; + double mean = 0, std = 0, delta = 0, delta2 = 0, m2 = 0; enum rspamd_language_category cat = RSPAMD_LANGUAGE_MAX; parser = ucl_parser_new(UCL_PARSER_NO_FILEVARS); @@ -416,7 +416,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, return; } else { - const gchar *stype = ucl_object_tostring(type); + const char *stype = ucl_object_tostring(type); if (strcmp(stype, "latin") == 0) { cat = RSPAMD_LANGUAGE_LATIN; @@ -445,7 +445,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, const ucl_object_t *cur; while ((cur = ucl_object_iterate(flags, &it, true)) != NULL) { - const gchar *fl = ucl_object_tostring(cur); + const char *fl = ucl_object_tostring(cur); if (cur) { if (strcmp(fl, "diacritics") == 0) { @@ -473,7 +473,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, struct sb_stemmer *stem = NULL; it = NULL; const ucl_object_t *w; - guint start, stop; + unsigned int start, stop; stem = sb_stemmer_new(nelt->name, "UTF_8"); start = rspamd_multipattern_get_npatterns(d->stop_words[cat].mp); @@ -482,7 +482,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, gsize wlen; const char *word = ucl_object_tolstring(w, &wlen); const char *saved; - guint mp_flags = RSPAMD_MULTIPATTERN_ICASE | RSPAMD_MULTIPATTERN_UTF8; + unsigned int mp_flags = RSPAMD_MULTIPATTERN_ICASE | RSPAMD_MULTIPATTERN_UTF8; if (rspamd_multipattern_has_hyperscan()) { mp_flags |= RSPAMD_MULTIPATTERN_RE; @@ -511,13 +511,13 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, } if (saved) { - gint rc; + int rc; rspamd_ftok_t *tok; - gchar *dst; + char *dst; tok = rspamd_mempool_alloc(cfg->cfg_pool, sizeof(*tok) + wlen + 1); - dst = ((gchar *) tok) + sizeof(*tok); + dst = ((char *) tok) + sizeof(*tok); rspamd_strlcpy(dst, saved, wlen + 1); tok->begin = dst; tok->len = wlen; @@ -548,7 +548,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, htb = d->trigrams[cat]; GPtrArray *ngramms; - guint nsym; + unsigned int nsym; if (rspamd_language_search_str(nelt->name, tier1_langs, G_N_ELEMENTS(tier1_langs))) { @@ -567,9 +567,9 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, loaded = 0; while ((cur = ucl_object_iterate(freqs, &it, true)) != NULL) { - const gchar *key; + const char *key; gsize keylen; - guint freq; + unsigned int freq; key = ucl_object_keyl(cur, &keylen); freq = ucl_object_toint(cur); @@ -603,7 +603,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, if (!U_SUCCESS(uc_err)) { msg_warn_config("cannot convert key %*s to unicode: %s", - (gint) keylen, key, u_errorName(uc_err)); + (int) keylen, key, u_errorName(uc_err)); continue; } @@ -684,7 +684,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, "std=%.2f, mean=%.2f, skipped=%d, loaded=%d, stop_words=%d; " "(%s)", nelt->name, - (gint) nelt->trigrams_words, + (int) nelt->trigrams_words, total, std, mean, skipped, loaded, nelt->stop_words, @@ -698,7 +698,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, } static gboolean -rspamd_ucl_array_find_str(const gchar *str, const ucl_object_t *ar) +rspamd_ucl_array_find_str(const char *str, const ucl_object_t *ar) { ucl_object_iter_t it = NULL; const ucl_object_t *cur; @@ -722,8 +722,8 @@ rspamd_language_detector_process_chain(struct rspamd_config *cfg, struct rspamd_ngramm_chain *chain) { struct rspamd_ngramm_elt *elt; - guint i; - gdouble delta, mean = 0, delta2, m2 = 0, std; + unsigned int i; + double delta, mean = 0, delta2, m2 = 0, std; if (chain->languages->len > 3) { PTR_ARRAY_FOREACH(chain->languages, i, elt) @@ -767,7 +767,7 @@ static void rspamd_language_detector_dtor(struct rspamd_lang_detector *d) { if (d) { - for (guint i = 0; i < RSPAMD_LANGUAGE_MAX; i++) { + for (unsigned int i = 0; i < RSPAMD_LANGUAGE_MAX; i++) { kh_destroy(rspamd_trigram_hash, d->trigrams[i]); rspamd_multipattern_destroy(d->stop_words[i].mp); g_array_free(d->stop_words[i].ranges, TRUE); @@ -787,13 +787,13 @@ rspamd_language_detector_init(struct rspamd_config *cfg) { const ucl_object_t *section, *elt, *languages_enable = NULL, *languages_disable = NULL; - const gchar *languages_path = default_languages_path; + const char *languages_path = default_languages_path; glob_t gl; size_t i, short_text_limit = default_short_text_limit, total = 0; UErrorCode uc_err = U_ZERO_ERROR; GString *languages_pattern; struct rspamd_ngramm_chain *chain, schain; - gchar *fname; + char *fname; struct rspamd_lang_detector *ret = NULL; struct ucl_parser *parser; ucl_object_t *stop_words; @@ -912,8 +912,8 @@ rspamd_language_detector_init(struct rspamd_config *cfg) msg_info_config("loaded %d languages, " "%d trigrams; %s", - (gint) kh_size(ret->languages), - (gint) total, fasttext_status); + (int) kh_size(ret->languages), + (int) total, fasttext_status); g_free(fasttext_status); if (stop_words) { @@ -936,11 +936,11 @@ end: } static void -rspamd_language_detector_random_select(GArray *ucs_tokens, guint nwords, +rspamd_language_detector_random_select(GArray *ucs_tokens, unsigned int nwords, goffset *offsets_out, uint64_t *seed) { - guint step_len, remainder, i, out_idx; + unsigned int step_len, remainder, i, out_idx; uint64_t coin, sel; rspamd_stat_token_t *tok; @@ -973,7 +973,7 @@ rspamd_language_detector_random_select(GArray *ucs_tokens, guint nwords, for (i = step_len + remainder; i < ucs_tokens->len; i += step_len, out_idx++) { - guint ntries = 0; + unsigned int ntries = 0; coin = rspamd_random_uint64_fast_seed(seed); sel = (coin % step_len) + i; @@ -1028,9 +1028,9 @@ rspamd_language_detector_random_select(GArray *ucs_tokens, guint nwords, static goffset rspamd_language_detector_next_ngramm(rspamd_stat_token_t *tok, UChar32 *window, - guint wlen, goffset cur_off) + unsigned int wlen, goffset cur_off) { - guint i; + unsigned int i; if (wlen > 1) { /* Deal with spaces at the beginning and ending */ @@ -1081,13 +1081,13 @@ rspamd_language_detector_process_ngramm_full(struct rspamd_task *task, khash_t(rspamd_candidates_hash) * candidates, khash_t(rspamd_trigram_hash) * trigrams) { - guint i; - gint ret; + unsigned int i; + int ret; struct rspamd_ngramm_chain *chain = NULL; struct rspamd_ngramm_elt *elt; struct rspamd_lang_detector_res *cand; khiter_t k; - gdouble prob; + double prob; k = kh_get(rspamd_trigram_hash, trigrams, window); if (k != kh_end(trigrams)) { @@ -1140,7 +1140,7 @@ rspamd_language_detector_detect_word(struct rspamd_task *task, khash_t(rspamd_candidates_hash) * candidates, khash_t(rspamd_trigram_hash) * trigrams) { - const guint wlen = 3; + const unsigned int wlen = 3; UChar32 window[3]; goffset cur = 0; @@ -1151,7 +1151,7 @@ rspamd_language_detector_detect_word(struct rspamd_task *task, } } -static const gdouble cutoff_limit = -8.0; +static const double cutoff_limit = -8.0; /* * Converts frequencies to log probabilities, filter those candidates who * has the lowest probabilities @@ -1160,7 +1160,7 @@ static const gdouble cutoff_limit = -8.0; static inline void rspamd_language_detector_filter_step1(struct rspamd_task *task, struct rspamd_lang_detector_res *cand, - gdouble *max_prob, guint *filtered) + double *max_prob, unsigned int *filtered) { if (!isnan(cand->prob)) { if (cand->prob == 0) { @@ -1189,7 +1189,7 @@ rspamd_language_detector_filter_step1(struct rspamd_task *task, static inline void rspamd_language_detector_filter_step2(struct rspamd_task *task, struct rspamd_lang_detector_res *cand, - gdouble max_prob, guint *filtered) + double max_prob, unsigned int *filtered) { /* * Probabilities are logarithmic, so if prob1 - prob2 > 4, it means that @@ -1208,8 +1208,8 @@ rspamd_language_detector_filter_negligible(struct rspamd_task *task, khash_t(rspamd_candidates_hash) * candidates) { struct rspamd_lang_detector_res *cand; - guint filtered = 0; - gdouble max_prob = -(G_MAXDOUBLE); + unsigned int filtered = 0; + double max_prob = -(G_MAXDOUBLE); kh_foreach_value(candidates, cand, rspamd_language_detector_filter_step1(task, cand, &max_prob, &filtered)); @@ -1221,17 +1221,17 @@ rspamd_language_detector_filter_negligible(struct rspamd_task *task, static void rspamd_language_detector_detect_type(struct rspamd_task *task, - guint nwords, + unsigned int nwords, struct rspamd_lang_detector *d, GArray *words, enum rspamd_language_category cat, khash_t(rspamd_candidates_hash) * candidates, struct rspamd_mime_text_part *part) { - guint nparts = MIN(words->len, nwords); + unsigned int nparts = MIN(words->len, nwords); goffset *selected_words; rspamd_stat_token_t *tok; - guint i; + unsigned int i; uint64_t seed; /* Seed PRNG with part digest to provide some sort of determinism */ @@ -1255,7 +1255,7 @@ rspamd_language_detector_detect_type(struct rspamd_task *task, g_free(selected_words); } -static gint +static int rspamd_language_detector_cmp(gconstpointer a, gconstpointer b) { const struct rspamd_lang_detector_res @@ -1280,14 +1280,14 @@ enum rspamd_language_detected_type { static enum rspamd_language_detected_type rspamd_language_detector_try_ngramm(struct rspamd_task *task, - guint nwords, + unsigned int nwords, struct rspamd_lang_detector *d, GArray *ucs_tokens, enum rspamd_language_category cat, khash_t(rspamd_candidates_hash) * candidates, struct rspamd_mime_text_part *part) { - guint cand_len = 0; + unsigned int cand_len = 0; struct rspamd_lang_detector_res *cand; rspamd_language_detector_detect_type(task, @@ -1322,15 +1322,15 @@ enum rspamd_language_sort_flags { struct rspamd_frequency_sort_cbdata { struct rspamd_lang_detector *d; enum rspamd_language_sort_flags flags; - gdouble std; - gdouble mean; + double std; + double mean; }; -static const gdouble tier0_adjustment = 1.2; -static const gdouble tier1_adjustment = 0.8; -static const gdouble frequency_adjustment = 0.8; +static const double tier0_adjustment = 1.2; +static const double tier1_adjustment = 0.8; +static const double frequency_adjustment = 0.8; -static gint +static int rspamd_language_detector_cmp_heuristic(gconstpointer a, gconstpointer b, gpointer ud) { @@ -1338,18 +1338,18 @@ rspamd_language_detector_cmp_heuristic(gconstpointer a, gconstpointer b, struct rspamd_lang_detector_res *canda = *(struct rspamd_lang_detector_res **) a, *candb = *(struct rspamd_lang_detector_res **) b; - gdouble adj; - gdouble proba_adjusted, probb_adjusted, freqa, freqb; + double adj; + double proba_adjusted, probb_adjusted, freqa, freqb; if (cbd->d->total_occurrences == 0) { /* Not enough data, compare directly */ return rspamd_language_detector_cmp(a, b); } - freqa = ((gdouble) canda->elt->occurrences) / - (gdouble) cbd->d->total_occurrences; - freqb = ((gdouble) candb->elt->occurrences) / - (gdouble) cbd->d->total_occurrences; + freqa = ((double) canda->elt->occurrences) / + (double) cbd->d->total_occurrences; + freqb = ((double) candb->elt->occurrences) / + (double) cbd->d->total_occurrences; proba_adjusted = canda->prob; probb_adjusted = candb->prob; @@ -1405,15 +1405,15 @@ rspamd_language_detector_cmp_heuristic(gconstpointer a, gconstpointer b, static void rspamd_language_detector_unicode_scripts(struct rspamd_task *task, struct rspamd_mime_text_part *part, - guint *pchinese, - guint *pspecial) + unsigned int *pchinese, + unsigned int *pspecial) { - const gchar *p = part->utf_stripped_content->data, *end; - guint i = 0, cnt = 0; + const char *p = part->utf_stripped_content->data, *end; + unsigned int i = 0, cnt = 0; end = p + part->utf_stripped_content->len; int32_t uc, sc; - guint nlatin = 0, nchinese = 0, nspecial = 0; - const guint cutoff_limit = 32; + unsigned int nlatin = 0, nchinese = 0, nspecial = 0; + const unsigned int cutoff_limit = 32; while (p + i < end) { U8_NEXT(p, i, part->utf_stripped_content->len, uc); @@ -1527,7 +1527,7 @@ rspamd_language_detector_unicode_scripts(struct rspamd_task *task, static inline void rspamd_language_detector_set_language(struct rspamd_task *task, struct rspamd_mime_text_part *part, - const gchar *code, + const char *code, struct rspamd_language_elt *elt) { struct rspamd_lang_detector_res *r; @@ -1548,10 +1548,10 @@ rspamd_language_detector_set_language(struct rspamd_task *task, static gboolean rspamd_language_detector_try_uniscript(struct rspamd_task *task, struct rspamd_mime_text_part *part, - guint nchinese, - guint nspecial) + unsigned int nchinese, + unsigned int nspecial) { - guint i; + unsigned int i; for (i = 0; i < G_N_ELEMENTS(unicode_langs); i++) { if (unicode_langs[i].unicode_code & part->unicode_scripts) { @@ -1598,7 +1598,7 @@ rspamd_language_detector_try_uniscript(struct rspamd_task *task, return FALSE; } -static guint +static unsigned int rspamd_langelt_hash_func(gconstpointer key) { const struct rspamd_language_elt *elt = (const struct rspamd_language_elt *) key; @@ -1626,10 +1626,10 @@ struct rspamd_sw_cbdata { GArray *ranges; }; -static gint +static int rspamd_ranges_cmp(const void *k, const void *memb) { - gint pos = GPOINTER_TO_INT(k); + int pos = GPOINTER_TO_INT(k); const struct rspamd_stop_word_range *r = (struct rspamd_stop_word_range *) memb; if (pos >= r->start && pos < r->stop) { @@ -1642,17 +1642,17 @@ rspamd_ranges_cmp(const void *k, const void *memb) return 1; } -static gint +static int rspamd_language_detector_sw_cb(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, + unsigned int strnum, + int match_start, + int match_pos, + const char *text, gsize len, void *context) { /* Check if boundary */ - const gchar *prev = text, *next = text + len; + const char *prev = text, *next = text + len; struct rspamd_stop_word_range *r; struct rspamd_sw_cbdata *cbdata = (struct rspamd_sw_cbdata *) context; khiter_t k; @@ -1683,7 +1683,7 @@ rspamd_language_detector_sw_cb(struct rspamd_multipattern *mp, g_assert(r != NULL); k = kh_get(rspamd_sw_hash, cbdata->res, r->elt); - gint nwords = 1; + int nwords = 1; if (k != kh_end(cbdata->res)) { khiter_t set_k; @@ -1704,7 +1704,7 @@ rspamd_language_detector_sw_cb(struct rspamd_multipattern *mp, } } else { - gint tt; + int tt; k = kh_put(rspamd_sw_hash, cbdata->res, r->elt, &tt); kh_value(cbdata->res, k) = kh_init(rspamd_sw_res_set); @@ -1824,8 +1824,8 @@ rspamd_language_detector_detect(struct rspamd_task *task, { khash_t(rspamd_candidates_hash) * candidates; GPtrArray *result; - gdouble mean, std, start_ticks, end_ticks; - guint cand_len; + double mean, std, start_ticks, end_ticks; + unsigned int cand_len; enum rspamd_language_category cat; struct rspamd_lang_detector_res *cand; enum rspamd_language_detected_type r; @@ -1839,7 +1839,7 @@ rspamd_language_detector_detect(struct rspamd_task *task, start_ticks = rspamd_get_ticks(TRUE); - guint nchinese = 0, nspecial = 0; + unsigned int nchinese = 0, nspecial = 0; rspamd_language_detector_unicode_scripts(task, part, &nchinese, &nspecial); /* Disable internal language detection heuristics if we have fasttext */ @@ -1968,7 +1968,7 @@ rspamd_language_detector_detect(struct rspamd_task *task, mean /= cand_len; kh_foreach_value(candidates, cand, { - gdouble err; + double err; if (!isnan(cand->prob)) { err = cand->prob - mean; std += fabs(err); @@ -2076,7 +2076,7 @@ void rspamd_language_detector_unref(struct rspamd_lang_detector *d) gboolean rspamd_language_detector_is_stop_word(struct rspamd_lang_detector *d, - const gchar *word, gsize wlen) + const char *word, gsize wlen) { khiter_t k; rspamd_ftok_t search; @@ -2093,7 +2093,7 @@ rspamd_language_detector_is_stop_word(struct rspamd_lang_detector *d, return FALSE; } -gint rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt) +int rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt) { if (elt) { return elt->flags; diff --git a/src/libmime/lang_detection.h b/src/libmime/lang_detection.h index 5423c13b7..45d3b24b6 100644 --- a/src/libmime/lang_detection.h +++ b/src/libmime/lang_detection.h @@ -60,8 +60,8 @@ enum rspamd_language_elt_flags { }; struct rspamd_lang_detector_res { - gdouble prob; - const gchar *lang; + double prob; + const char *lang; struct rspamd_language_elt *elt; }; @@ -95,14 +95,14 @@ gboolean rspamd_language_detector_detect(struct rspamd_task *task, * @return */ gboolean rspamd_language_detector_is_stop_word(struct rspamd_lang_detector *d, - const gchar *word, gsize wlen); + const char *word, gsize wlen); /** * Return language flags for a specific language elt * @param elt * @return */ -gint rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt); +int rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt); #ifdef __cplusplus } #endif diff --git a/src/libmime/lang_detection_fasttext.cxx b/src/libmime/lang_detection_fasttext.cxx index c973ed710..faa97b0fc 100644 --- a/src/libmime/lang_detection_fasttext.cxx +++ b/src/libmime/lang_detection_fasttext.cxx @@ -187,7 +187,7 @@ rspamd_fasttext_predict_result_t rspamd_lang_detection_fasttext_detect(void *ud, return nullptr; #else /* Avoid too long inputs */ - static const guint max_fasttext_input_len = 1024 * 1024; + static const unsigned int max_fasttext_input_len = 1024 * 1024; auto *real_model = FASTTEXT_MODEL_TO_C_API(ud); std::vector words_vec; words_vec.reserve(utf_words->len); @@ -215,7 +215,7 @@ void rspamd_lang_detection_fasttext_destroy(void *ud) } -guint rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t res) +unsigned int rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t res) { #ifdef WITH_FASTTEXT auto *real_res = FASTTEXT_RESULT_TO_C_API(res); diff --git a/src/libmime/lang_detection_fasttext.h b/src/libmime/lang_detection_fasttext.h index c8710d3c4..2a2756968 100644 --- a/src/libmime/lang_detection_fasttext.h +++ b/src/libmime/lang_detection_fasttext.h @@ -60,7 +60,7 @@ rspamd_fasttext_predict_result_t rspamd_lang_detection_fasttext_detect(void *ud, * @param ud * @return */ -guint rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t ud); +unsigned int rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t ud); /** * Get language from fasttext result * @param res diff --git a/src/libmime/message.c b/src/libmime/message.c index f74ca0dca..f2cabf399 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -46,14 +46,14 @@ #define SET_PART_RAW(part) ((part)->flags &= ~RSPAMD_MIME_TEXT_PART_FLAG_UTF) #define SET_PART_UTF(part) ((part)->flags |= RSPAMD_MIME_TEXT_PART_FLAG_UTF) -static const gchar gtube_pattern_reject[] = "XJS*C4JDBQADN1.NSBN3*2IDNEN*" - "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; -static const gchar gtube_pattern_add_header[] = "YJS*C4JDBQADN1.NSBN3*2IDNEN*" - "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; -static const gchar gtube_pattern_rewrite_subject[] = "ZJS*C4JDBQADN1.NSBN3*2IDNEN*" - "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; -static const gchar gtube_pattern_no_action[] = "AJS*C4JDBQADN1.NSBN3*2IDNEN*" +static const char gtube_pattern_reject[] = "XJS*C4JDBQADN1.NSBN3*2IDNEN*" + "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; +static const char gtube_pattern_add_header[] = "YJS*C4JDBQADN1.NSBN3*2IDNEN*" "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; +static const char gtube_pattern_rewrite_subject[] = "ZJS*C4JDBQADN1.NSBN3*2IDNEN*" + "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; +static const char gtube_pattern_no_action[] = "AJS*C4JDBQADN1.NSBN3*2IDNEN*" + "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; struct rspamd_multipattern *gtube_matcher = NULL; static const uint64_t words_hash_seed = 0xdeadbabe; @@ -69,7 +69,7 @@ rspamd_mime_part_extract_words(struct rspamd_task *task, struct rspamd_mime_text_part *part) { rspamd_stat_token_t *w; - guint i, total_len = 0, short_len = 0; + unsigned int i, total_len = 0, short_len = 0; if (part->utf_words) { rspamd_stem_words(part->utf_words, task->task_pool, part->language, @@ -109,7 +109,7 @@ rspamd_mime_part_extract_words(struct rspamd_task *task, } if (part->utf_words->len) { - gdouble *avg_len_p, *short_len_p; + double *avg_len_p, *short_len_p; avg_len_p = rspamd_mempool_get_variable(task->task_pool, RSPAMD_MEMPOOL_AVG_WORDS_LEN); @@ -152,8 +152,8 @@ rspamd_mime_part_create_words(struct rspamd_task *task, #if U_ICU_VERSION_MAJOR_NUM < 50 /* Hack to prevent hang with Thai in old libicu */ - const gchar *p = part->utf_stripped_content->data, *end; - guint i = 0; + const char *p = part->utf_stripped_content->data, *end; + unsigned int i = 0; end = p + part->utf_stripped_content->len; int32_t uc, sc; @@ -225,10 +225,10 @@ rspamd_mime_part_detect_language(struct rspamd_task *task, static void rspamd_strip_newlines_parse(struct rspamd_task *task, - const gchar *begin, const gchar *pe, + const char *begin, const char *pe, struct rspamd_mime_text_part *part) { - const gchar *p = begin, *c = begin; + const char *p = begin, *c = begin; gboolean crlf_added = FALSE, is_utf = IS_TEXT_PART_UTF(part); gboolean url_open_bracket = FALSE; UChar32 uc; @@ -253,7 +253,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, if (p > c) { g_byte_array_append(part->utf_stripped_content, - (const guint8 *) c, p - c); + (const uint8_t *) c, p - c); c = begin + off; p = c; } @@ -290,7 +290,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, state = seen_cr; if (p > c) { g_byte_array_append(part->utf_stripped_content, - (const guint8 *) c, p - c); + (const uint8_t *) c, p - c); } crlf_added = FALSE; @@ -300,7 +300,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, /* Double \r\r */ if (!crlf_added) { g_byte_array_append(part->utf_stripped_content, - (const guint8 *) " ", 1); + (const uint8_t *) " ", 1); crlf_added = TRUE; g_ptr_array_add(part->newlines, (((gpointer) (goffset) (part->utf_stripped_content->len)))); @@ -328,14 +328,14 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, if (p > c) { g_byte_array_append(part->utf_stripped_content, - (const guint8 *) c, p - c); + (const uint8_t *) c, p - c); } c = p + 1; if (IS_TEXT_PART_HTML(part) || !url_open_bracket) { g_byte_array_append(part->utf_stripped_content, - (const guint8 *) " ", 1); + (const uint8_t *) " ", 1); g_ptr_array_add(part->newlines, (((gpointer) (goffset) (part->utf_stripped_content->len)))); crlf_added = TRUE; @@ -350,7 +350,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, if (!crlf_added) { if (IS_TEXT_PART_HTML(part) || !url_open_bracket) { g_byte_array_append(part->utf_stripped_content, - (const guint8 *) " ", 1); + (const uint8_t *) " ", 1); crlf_added = TRUE; } @@ -366,7 +366,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, /* Double \n\n */ if (!crlf_added) { g_byte_array_append(part->utf_stripped_content, - (const guint8 *) " ", 1); + (const uint8_t *) " ", 1); crlf_added = TRUE; g_ptr_array_add(part->newlines, (((gpointer) (goffset) (part->utf_stripped_content->len)))); @@ -430,7 +430,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, if (*p == ' ') { if (!crlf_added) { g_byte_array_append(part->utf_stripped_content, - (const guint8 *) " ", 1); + (const uint8_t *) " ", 1); } while (p < pe && *p == ' ') { @@ -461,7 +461,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, switch (state) { case normal_char: g_byte_array_append(part->utf_stripped_content, - (const guint8 *) c, p - c); + (const uint8_t *) c, p - c); while (c < p) { if (*c == ' ') { @@ -489,7 +489,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, if (!crlf_added) { g_byte_array_append(part->utf_stripped_content, - (const guint8 *) " ", 1); + (const uint8_t *) " ", 1); g_ptr_array_add(part->newlines, (((gpointer) (goffset) (part->utf_stripped_content->len)))); } @@ -510,8 +510,8 @@ static void rspamd_normalize_text_part(struct rspamd_task *task, struct rspamd_mime_text_part *part) { - const gchar *p, *end; - guint i; + const char *p, *end; + unsigned int i; goffset off; struct rspamd_process_exception *ex; UErrorCode uc_err = U_ZERO_ERROR; @@ -524,7 +524,7 @@ rspamd_normalize_text_part(struct rspamd_task *task, else { part->utf_stripped_content = g_byte_array_sized_new(part->utf_content.len); - p = (const gchar *) part->utf_content.begin; + p = (const char *) part->utf_content.begin; end = p + part->utf_content.len; rspamd_strip_newlines_parse(task, p, end, part); @@ -569,15 +569,15 @@ rspamd_normalize_text_part(struct rspamd_task *task, #define MIN3(a, b, c) ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c))) -static guint +static unsigned int rspamd_words_levenshtein_distance(struct rspamd_task *task, GArray *w1, GArray *w2) { - guint s1len, s2len, x, y, lastdiag, olddiag; - guint *column, ret; + unsigned int s1len, s2len, x, y, lastdiag, olddiag; + unsigned int *column, ret; uint64_t h1, h2; - gint eq; - static const guint max_words = 8192; + int eq; + static const unsigned int max_words = 8192; s1len = w1->len; s2len = w2->len; @@ -596,7 +596,7 @@ rspamd_words_levenshtein_distance(struct rspamd_task *task, } } - column = g_malloc0((s1len + 1) * sizeof(guint)); + column = g_malloc0((s1len + 1) * sizeof(unsigned int)); for (y = 1; y <= s1len; y++) { column[y] = y; @@ -626,12 +626,12 @@ rspamd_words_levenshtein_distance(struct rspamd_task *task, return ret; } -static gint +static int rspamd_multipattern_gtube_cb(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, + unsigned int strnum, + int match_start, + int match_pos, + const char *text, gsize len, void *context) { @@ -652,7 +652,7 @@ static enum rspamd_action_type rspamd_check_gtube(struct rspamd_task *task, struct rspamd_mime_text_part *part) { static const gsize max_check_size = 8 * 1024; - gint ret; + int ret; enum rspamd_action_type act = METRIC_ACTION_NOACTION; enum rspamd_gtube_patterns_policy policy = task->cfg ? task->cfg->gtube_patterns_policy : RSPAMD_GTUBE_REJECT; g_assert(part != NULL); @@ -719,7 +719,7 @@ rspamd_check_gtube(struct rspamd_task *task, struct rspamd_mime_text_part *part) return act; } -static gint +static int exceptions_compare_func(gconstpointer a, gconstpointer b) { const struct rspamd_process_exception *ea = a, *eb = b; @@ -741,7 +741,7 @@ rspamd_message_process_plain_text_part(struct rspamd_task *task, if (text_part->utf_raw_content != NULL) { /* Just have the same content */ - text_part->utf_content.begin = (const gchar *) text_part->utf_raw_content->data; + text_part->utf_content.begin = (const char *) text_part->utf_raw_content->data; text_part->utf_content.len = text_part->utf_raw_content->len; } else { @@ -845,7 +845,7 @@ rspamd_message_process_text_part_maybe(struct rspamd_task *task, uint16_t *cur_url_order) { struct rspamd_mime_text_part *text_part; - guint flags = 0; + unsigned int flags = 0; enum rspamd_action_type act; /* Skip attachments */ @@ -881,7 +881,7 @@ rspamd_message_process_text_part_maybe(struct rspamd_task *task, act = rspamd_check_gtube(task, text_part); if (act != METRIC_ACTION_NOACTION) { struct rspamd_action *action; - gdouble score = NAN; + double score = NAN; action = rspamd_config_get_action_by_type(task->cfg, act); @@ -950,15 +950,15 @@ rspamd_message_process_text_part_maybe(struct rspamd_task *task, /* Creates message from various data using libmagic to detect type */ static void -rspamd_message_from_data(struct rspamd_task *task, const guchar *start, +rspamd_message_from_data(struct rspamd_task *task, const unsigned char *start, gsize len) { struct rspamd_content_type *ct = NULL; struct rspamd_mime_part *part; const char *mb = "application/octet-stream"; - gchar *mid; + char *mid; rspamd_ftok_t srch, *tok; - gchar cdbuf[1024]; + char cdbuf[1024]; g_assert(start != NULL); @@ -1075,7 +1075,7 @@ rspamd_message_from_data(struct rspamd_task *task, const guchar *start, static void rspamd_message_dtor(struct rspamd_message *msg) { - guint i; + unsigned int i; struct rspamd_mime_part *p; struct rspamd_mime_text_part *tp; @@ -1146,9 +1146,9 @@ rspamd_message_new(struct rspamd_task *task) gboolean rspamd_message_parse(struct rspamd_task *task) { - const gchar *p; + const char *p; gsize len; - guint i; + unsigned int i; GError *err = NULL; uint64_t n[2], seed; @@ -1205,7 +1205,7 @@ rspamd_message_parse(struct rspamd_task *task) enum rspamd_mime_parse_error ret; debug_task("construct mime parser from string length %d", - (gint) task->msg.len); + (int) task->msg.len); ret = rspamd_mime_parse_task(task, &err); switch (ret) { @@ -1257,7 +1257,7 @@ rspamd_message_parse(struct rspamd_task *task) struct rspamd_mime_part *part; /* Blake2b applied to string 'rspamd' */ - static const guchar RSPAMD_ALIGNED(32) hash_key[] = { + static const unsigned char RSPAMD_ALIGNED(32) hash_key[] = { 0xef, 0x43, 0xae, @@ -1350,13 +1350,13 @@ rspamd_message_parse(struct rspamd_task *task) msg_info_task("loaded message; id: <%s>; queue-id: <%s>; size: %z; " "checksum: <%*xs>", MESSAGE_FIELD(task, message_id), task->queue_id, task->msg.len, - (gint) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest)); + (int) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest)); } else { msg_info_task("loaded message; id: <%s>; size: %z; " "checksum: <%*xs>", MESSAGE_FIELD(task, message_id), task->msg.len, - (gint) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest)); + (int) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest)); } return TRUE; @@ -1394,13 +1394,13 @@ rspamd_mime_text_part_position_compare_func(const void *v1, const void *v2) void rspamd_message_process(struct rspamd_task *task) { - guint i; + unsigned int i; struct rspamd_mime_text_part *p1, *p2; - gdouble diff, *pdiff; - guint tw, *ptw, dw; + double diff, *pdiff; + unsigned int tw, *ptw, dw; struct rspamd_mime_part *part; lua_State *L = NULL; - gint magic_func_pos = -1, content_func_pos = -1, old_top = -1, funcs_top = -1; + int magic_func_pos = -1, content_func_pos = -1, old_top = -1, funcs_top = -1; if (task->cfg) { L = task->cfg->lua_state; @@ -1441,7 +1441,7 @@ void rspamd_message_process(struct rspamd_task *task) struct rspamd_task **ptask; lua_pushcfunction(L, &rspamd_lua_traceback); - gint err_idx = lua_gettop(L); + int err_idx = lua_gettop(L); lua_pushvalue(L, magic_func_pos); pmime = lua_newuserdata(L, sizeof(struct rspamd_mime_part *)); rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); @@ -1455,7 +1455,7 @@ void rspamd_message_process(struct rspamd_task *task) } else { if (lua_istable(L, -1)) { - const gchar *mb; + const char *mb; /* First returned value */ part->detected_ext = rspamd_mempool_strdup(task->task_pool, @@ -1513,7 +1513,7 @@ void rspamd_message_process(struct rspamd_task *task) struct rspamd_task **ptask; lua_pushcfunction(L, &rspamd_lua_traceback); - gint err_idx = lua_gettop(L); + int err_idx = lua_gettop(L); lua_pushvalue(L, content_func_pos); pmime = lua_newuserdata(L, sizeof(struct rspamd_mime_part *)); rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); @@ -1572,8 +1572,8 @@ void rspamd_message_process(struct rspamd_task *task) /* Calculate average words length and number of short words */ struct rspamd_mime_text_part *text_part; - gdouble *var; - guint total_words = 0; + double *var; + unsigned int total_words = 0; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, text_part) { @@ -1651,7 +1651,7 @@ void rspamd_message_process(struct rspamd_task *task) dw = rspamd_words_levenshtein_distance(task, p1->normalized_hashes, p2->normalized_hashes); - diff = dw / (gdouble) tw; + diff = dw / (double) tw; msg_debug_task( "different words: %d, total words: %d, " @@ -1660,14 +1660,14 @@ void rspamd_message_process(struct rspamd_task *task) diff); pdiff = rspamd_mempool_alloc(task->task_pool, - sizeof(gdouble)); + sizeof(double)); *pdiff = diff; rspamd_mempool_set_variable(task->task_pool, "parts_distance", pdiff, NULL); ptw = rspamd_mempool_alloc(task->task_pool, - sizeof(gint)); + sizeof(int)); *ptw = tw; rspamd_mempool_set_variable(task->task_pool, "total_words", diff --git a/src/libmime/message.h b/src/libmime/message.h index 12761bf91..cb695773e 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -75,15 +75,15 @@ enum rspamd_lua_specific_type { }; struct rspamd_lua_specific_part { - gint cbref; + int cbref; enum rspamd_lua_specific_type type; }; struct rspamd_mime_part { struct rspamd_content_type *ct; struct rspamd_content_type *detected_ct; - gchar *detected_type; - gchar *detected_ext; + char *detected_type; + char *detected_ext; struct rspamd_content_disposition *cd; rspamd_ftok_t raw_data; rspamd_ftok_t parsed_data; @@ -93,13 +93,13 @@ struct rspamd_mime_part { struct rspamd_mime_headers_table *raw_headers; GPtrArray *urls; - gchar *raw_headers_str; + char *raw_headers_str; gsize raw_headers_len; enum rspamd_cte cte; - guint flags; + unsigned int flags; enum rspamd_mime_part_type part_type; - guint part_number; + unsigned int part_number; union { struct rspamd_mime_multipart *mp; @@ -109,7 +109,7 @@ struct rspamd_mime_part { struct rspamd_lua_specific_part lua_specific; } specific; - guchar digest[rspamd_cryptobox_HASHBYTES]; + unsigned char digest[rspamd_cryptobox_HASHBYTES]; }; #define RSPAMD_MIME_TEXT_PART_FLAG_UTF (1 << 0) @@ -126,9 +126,9 @@ struct rspamd_mime_part { struct rspamd_mime_text_part { - const gchar *language; + const char *language; GPtrArray *languages; - const gchar *real_charset; + const char *real_charset; /* Raw data in native encoding */ rspamd_ftok_t raw; @@ -147,29 +147,29 @@ struct rspamd_mime_text_part { GList *exceptions; /**< list of offsets of urls */ struct rspamd_mime_part *mime_part; - guint flags; - guint nlines; - guint spaces; - guint nwords; - guint non_ascii_chars; - guint ascii_chars; - guint double_spaces; - guint non_spaces; - guint empty_lines; - guint capital_letters; - guint numeric_characters; - guint unicode_scripts; + unsigned int flags; + unsigned int nlines; + unsigned int spaces; + unsigned int nwords; + unsigned int non_ascii_chars; + unsigned int ascii_chars; + unsigned int double_spaces; + unsigned int non_spaces; + unsigned int empty_lines; + unsigned int capital_letters; + unsigned int numeric_characters; + unsigned int unicode_scripts; }; struct rspamd_message_raw_headers_content { - const gchar *begin; + const char *begin; gsize len; - const gchar *body_start; + const char *body_start; }; struct rspamd_message { - const gchar *message_id; - gchar *subject; + const char *message_id; + char *subject; GPtrArray *parts; /**< list of parsed parts */ GPtrArray *text_parts; /**< list of text parts */ @@ -181,7 +181,7 @@ struct rspamd_message { struct rspamd_task *task; GPtrArray *rcpt_mime; GPtrArray *from_mime; - guchar digest[16]; + unsigned char digest[16]; enum rspamd_newlines_type nlines_type; /**< type of newlines (detected on most of headers */ ref_entry_t ref; }; @@ -208,14 +208,14 @@ void rspamd_message_process(struct rspamd_task *task); * @param str * @return */ -enum rspamd_cte rspamd_cte_from_string(const gchar *str); +enum rspamd_cte rspamd_cte_from_string(const char *str); /** * Converts cte to string * @param ct * @return */ -const gchar *rspamd_cte_to_string(enum rspamd_cte ct); +const char *rspamd_cte_to_string(enum rspamd_cte ct); struct rspamd_message *rspamd_message_new(struct rspamd_task *task); diff --git a/src/libmime/mime_encoding.c b/src/libmime/mime_encoding.c index 90d81b125..8b4c45436 100644 --- a/src/libmime/mime_encoding.c +++ b/src/libmime/mime_encoding.c @@ -44,9 +44,9 @@ static rspamd_regexp_t *utf_compatible_re = NULL; struct rspamd_charset_substitution { - const gchar *input; - const gchar *canon; - gint flags; + const char *input; + const char *canon; + int flags; }; #include "mime_encoding_list.h" @@ -72,7 +72,7 @@ static const UChar iso_8859_16_map[] = { 0x0171, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0119, 0x021B, 0x00FF}; struct rspamd_charset_converter { - gchar *canon_name; + char *canon_name; union { UConverter *conv; const UChar *cnv_table; @@ -115,7 +115,7 @@ rspamd_converter_to_uchars(struct rspamd_charset_converter *cnv, } else { UChar *d = dest, *dend = dest + destCapacity; - const guchar *p = src, *end = src + srcLength; + const unsigned char *p = src, *end = src + srcLength; while (p < end && d < dend) { if (*p <= 127) { @@ -134,12 +134,12 @@ rspamd_converter_to_uchars(struct rspamd_charset_converter *cnv, struct rspamd_charset_converter * -rspamd_mime_get_converter_cached(const gchar *enc, +rspamd_mime_get_converter_cached(const char *enc, rspamd_mempool_t *pool, gboolean is_canon, UErrorCode *err) { - const gchar *canon_name; + const char *canon_name; static rspamd_lru_hash_t *cache; struct rspamd_charset_converter *conv; @@ -208,7 +208,7 @@ rspamd_mime_get_converter_cached(const gchar *enc, static void rspamd_mime_encoding_substitute_init(void) { - guint i; + unsigned int i; sub_hash = g_hash_table_new(rspamd_strcase_hash, rspamd_strcase_equal); @@ -218,14 +218,14 @@ rspamd_mime_encoding_substitute_init(void) } static void -rspamd_charset_normalize(gchar *in) +rspamd_charset_normalize(char *in) { /* * This is a simple routine to validate input charset * we just check that charset starts with alphanumeric and ends * with alphanumeric */ - gchar *begin, *end; + char *begin, *end; gboolean changed = FALSE; begin = in; @@ -248,12 +248,12 @@ rspamd_charset_normalize(gchar *in) } } -const gchar * +const char * rspamd_mime_detect_charset(const rspamd_ftok_t *in, rspamd_mempool_t *pool) { - gchar *ret = NULL, *h, *t; + char *ret = NULL, *h, *t; struct rspamd_charset_substitution *s; - const gchar *cset; + const char *cset; rspamd_ftok_t utf8_tok; UErrorCode uc_err = U_ZERO_ERROR; @@ -321,12 +321,12 @@ rspamd_mime_detect_charset(const rspamd_ftok_t *in, rspamd_mempool_t *pool) return cset; } -gchar * +char * rspamd_mime_text_to_utf8(rspamd_mempool_t *pool, - gchar *input, gsize len, const gchar *in_enc, + char *input, gsize len, const char *in_enc, gsize *olen, GError **err) { - gchar *d; + char *d; int32_t r, clen, dlen; UChar *tmp_buf; @@ -403,10 +403,10 @@ static gboolean rspamd_mime_text_part_utf8_convert(struct rspamd_task *task, struct rspamd_mime_text_part *text_part, GByteArray *input, - const gchar *charset, + const char *charset, GError **err) { - gchar *d; + char *d; int32_t r, clen, dlen, uc_len; UChar *tmp_buf; UErrorCode uc_err = U_ZERO_ERROR; @@ -482,7 +482,7 @@ gboolean rspamd_mime_to_utf8_byte_array(GByteArray *in, GByteArray *out, rspamd_mempool_t *pool, - const gchar *enc) + const char *enc) { int32_t r, clen, dlen; UChar *tmp_buf; @@ -511,7 +511,7 @@ rspamd_mime_to_utf8_byte_array(GByteArray *in, RSPAMD_FTOK_FROM_STR(&charset_tok, enc); - if (rspamd_mime_charset_utf_check(&charset_tok, (gchar *) in->data, in->len, + if (rspamd_mime_charset_utf_check(&charset_tok, (char *) in->data, in->len, FALSE)) { g_byte_array_set_size(out, in->len); memcpy(out->data, in->data, out->len); @@ -556,9 +556,9 @@ rspamd_mime_to_utf8_byte_array(GByteArray *in, return TRUE; } -void rspamd_mime_charset_utf_enforce(gchar *in, gsize len) +void rspamd_mime_charset_utf_enforce(char *in, gsize len) { - gchar *p, *end; + char *p, *end; goffset err_offset; UChar32 uc = 0; @@ -594,12 +594,12 @@ void rspamd_mime_charset_utf_enforce(gchar *in, gsize len) } const char * -rspamd_mime_charset_find_by_content(const gchar *in, gsize inlen, +rspamd_mime_charset_find_by_content(const char *in, gsize inlen, bool check_utf8) { int nconsumed; bool is_reliable; - const gchar *ced_name; + const char *ced_name; if (check_utf8) { if (rspamd_fast_utf8_validate(in, inlen) == 0) { @@ -621,13 +621,13 @@ rspamd_mime_charset_find_by_content(const gchar *in, gsize inlen, } static const char * -rspamd_mime_charset_find_by_content_maybe_split(const gchar *in, gsize inlen) +rspamd_mime_charset_find_by_content_maybe_split(const char *in, gsize inlen) { if (inlen < RSPAMD_CHARSET_MAX_CONTENT * 3) { return rspamd_mime_charset_find_by_content(in, inlen, false); } else { - const gchar *c1, *c2, *c3; + const char *c1, *c2, *c3; c1 = rspamd_mime_charset_find_by_content(in, RSPAMD_CHARSET_MAX_CONTENT, false); c2 = rspamd_mime_charset_find_by_content(in + inlen / 2, @@ -678,9 +678,9 @@ rspamd_mime_charset_find_by_content_maybe_split(const gchar *in, gsize inlen) gboolean rspamd_mime_charset_utf_check(rspamd_ftok_t *charset, - gchar *in, gsize len, gboolean content_check) + char *in, gsize len, gboolean content_check) { - const gchar *real_charset; + const char *real_charset; if (utf_compatible_re == NULL) { utf_compatible_re = rspamd_regexp_new( @@ -729,7 +729,7 @@ void rspamd_mime_text_part_maybe_convert(struct rspamd_task *task, struct rspamd_mime_text_part *text_part) { GError *err = NULL; - const gchar *charset = NULL; + const char *charset = NULL; gboolean checked = FALSE, need_charset_heuristic = TRUE, valid_utf8 = FALSE; GByteArray *part_content; rspamd_ftok_t charset_tok; diff --git a/src/libmime/mime_encoding.h b/src/libmime/mime_encoding.h index 88e25efa6..f03ac36f4 100644 --- a/src/libmime/mime_encoding.h +++ b/src/libmime/mime_encoding.h @@ -36,8 +36,8 @@ struct rspamd_charset_converter; * @param in * @return */ -const gchar *rspamd_mime_detect_charset(const rspamd_ftok_t *in, - rspamd_mempool_t *pool); +const char *rspamd_mime_detect_charset(const rspamd_ftok_t *in, + rspamd_mempool_t *pool); /** * Convert text chunk to utf-8. Input encoding is substituted using @@ -52,9 +52,9 @@ const gchar *rspamd_mime_detect_charset(const rspamd_ftok_t *in, * @param err * @return */ -gchar *rspamd_mime_text_to_utf8(rspamd_mempool_t *pool, - gchar *input, gsize len, const gchar *in_enc, - gsize *olen, GError **err); +char *rspamd_mime_text_to_utf8(rspamd_mempool_t *pool, + char *input, gsize len, const char *in_enc, + gsize *olen, GError **err); /** * Converts data from `in` to `out`, @@ -70,7 +70,7 @@ gchar *rspamd_mime_text_to_utf8(rspamd_mempool_t *pool, gboolean rspamd_mime_to_utf8_byte_array(GByteArray *in, GByteArray *out, rspamd_mempool_t *pool, - const gchar *enc); + const char *enc); /** * Maybe convert part to utf-8 @@ -89,7 +89,7 @@ void rspamd_mime_text_part_maybe_convert(struct rspamd_task *task, * @return */ gboolean rspamd_mime_charset_utf_check(rspamd_ftok_t *charset, - gchar *in, gsize len, + char *in, gsize len, gboolean content_check); /** @@ -98,7 +98,7 @@ gboolean rspamd_mime_charset_utf_check(rspamd_ftok_t *charset, * @param in * @param len */ -void rspamd_mime_charset_utf_enforce(gchar *in, gsize len); +void rspamd_mime_charset_utf_enforce(char *in, gsize len); /** * Gets cached converter @@ -109,7 +109,7 @@ void rspamd_mime_charset_utf_enforce(gchar *in, gsize len); * @return converter */ struct rspamd_charset_converter *rspamd_mime_get_converter_cached( - const gchar *enc, + const char *enc, rspamd_mempool_t *pool, gboolean is_canon, UErrorCode *err); @@ -138,7 +138,7 @@ rspamd_converter_to_uchars(struct rspamd_charset_converter *cnv, * @param inlen * @return detected charset name or NULL */ -const char *rspamd_mime_charset_find_by_content(const gchar *in, gsize inlen, +const char *rspamd_mime_charset_find_by_content(const char *in, gsize inlen, bool check_utf8); #ifdef __cplusplus diff --git a/src/libmime/mime_expressions.c b/src/libmime/mime_expressions.c index 9ff01c3b0..f77017ff2 100644 --- a/src/libmime/mime_expressions.c +++ b/src/libmime/mime_expressions.c @@ -88,10 +88,10 @@ static gboolean rspamd_has_symbol_expr(struct rspamd_task *task, GArray *args, void *unused); -static rspamd_expression_atom_t *rspamd_mime_expr_parse(const gchar *line, gsize len, +static rspamd_expression_atom_t *rspamd_mime_expr_parse(const char *line, gsize len, rspamd_mempool_t *pool, gpointer ud, GError **err); -static gdouble rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom); -static gint rspamd_mime_expr_priority(rspamd_expression_atom_t *atom); +static double rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom); +static int rspamd_mime_expr_priority(rspamd_expression_atom_t *atom); static void rspamd_mime_expr_destroy(rspamd_expression_atom_t *atom); /** @@ -99,11 +99,11 @@ static void rspamd_mime_expr_destroy(rspamd_expression_atom_t *atom); */ struct rspamd_regexp_atom { enum rspamd_re_type type; /**< regexp type */ - gchar *regexp_text; /**< regexp text representation */ + char *regexp_text; /**< regexp text representation */ rspamd_regexp_t *regexp; /**< regexp structure */ union { - const gchar *header; /**< header name for header regexps */ - const gchar *selector; /**< selector name for lua selector regexp */ + const char *header; /**< header name for header regexps */ + const char *selector; /**< selector name for lua selector regexp */ } extra; gboolean is_test; /**< true if this expression must be tested */ gboolean is_strong; /**< true if headers search must be case sensitive */ @@ -114,7 +114,7 @@ struct rspamd_regexp_atom { * Rspamd expression function */ struct rspamd_function_atom { - gchar *name; /**< name of function */ + char *name; /**< name of function */ GArray *args; /**< its args */ }; @@ -126,12 +126,12 @@ enum rspamd_mime_atom_type { }; struct rspamd_mime_atom { - gchar *str; + char *str; union { struct rspamd_regexp_atom *re; struct rspamd_function_atom *func; - const gchar *lua_function; - gint lua_cbref; + const char *lua_function; + int lua_cbref; } d; enum rspamd_mime_atom_type type; }; @@ -141,7 +141,7 @@ struct rspamd_mime_atom { * Sorted by name to use bsearch */ static struct _fl { - const gchar *name; + const char *name; rspamd_internal_func_t func; void *user_data; } rspamd_functions_list[] = { @@ -180,7 +180,7 @@ static uint32_t functions_number = sizeof(rspamd_functions_list) / static gboolean list_allocated = FALSE; /* Bsearch routine */ -static gint +static int fl_cmp(const void *s1, const void *s2) { struct _fl *fl1 = (struct _fl *) s1; @@ -196,7 +196,7 @@ rspamd_mime_expr_quark(void) #define TYPE_CHECK(str, type, len) (sizeof(type) - 1 == (len) && rspamd_lc_cmp((str), (type), (len)) == 0) static gboolean -rspamd_parse_long_option(const gchar *start, gsize len, +rspamd_parse_long_option(const char *start, gsize len, struct rspamd_regexp_atom *a) { gboolean ret = FALSE; @@ -277,11 +277,11 @@ rspamd_parse_long_option(const gchar *start, gsize len, * Rspamd regexp utility functions */ static struct rspamd_regexp_atom * -rspamd_mime_expr_parse_regexp_atom(rspamd_mempool_t *pool, const gchar *line, +rspamd_mime_expr_parse_regexp_atom(rspamd_mempool_t *pool, const char *line, struct rspamd_config *cfg) { - const gchar *begin, *end, *p, *src, *start, *brace; - gchar *dbegin, *dend, *extra = NULL; + const char *begin, *end, *p, *src, *start, *brace; + char *dbegin, *dend, *extra = NULL; struct rspamd_regexp_atom *result; GError *err = NULL; GString *re_flags; @@ -531,11 +531,11 @@ rspamd_mime_expr_parse_regexp_atom(rspamd_mempool_t *pool, const gchar *line, } struct rspamd_function_atom * -rspamd_mime_expr_parse_function_atom(rspamd_mempool_t *pool, const gchar *input) +rspamd_mime_expr_parse_function_atom(rspamd_mempool_t *pool, const char *input) { - const gchar *obrace, *ebrace, *p, *c; - gchar t, *databuf; - guint len; + const char *obrace, *ebrace, *p, *c; + char t, *databuf; + unsigned int len; struct rspamd_function_atom *res; struct expression_argument arg; GError *err = NULL; @@ -645,17 +645,17 @@ rspamd_mime_expr_parse_function_atom(rspamd_mempool_t *pool, const gchar *input) } static rspamd_expression_atom_t * -rspamd_mime_expr_parse(const gchar *line, gsize len, +rspamd_mime_expr_parse(const char *line, gsize len, rspamd_mempool_t *pool, gpointer ud, GError **err) { rspamd_expression_atom_t *a = NULL; struct rspamd_mime_atom *mime_atom = NULL; - const gchar *p, *end, *c = NULL; + const char *p, *end, *c = NULL; struct rspamd_mime_expr_ud *real_ud = (struct rspamd_mime_expr_ud *) ud; struct rspamd_config *cfg; rspamd_regexp_t *own_re; - gchar t; - gint type = MIME_ATOM_REGEXP, obraces = 0, ebraces = 0; + char t; + int type = MIME_ATOM_REGEXP, obraces = 0, ebraces = 0; enum { in_header = 0, got_slash, @@ -786,8 +786,8 @@ rspamd_mime_expr_parse(const gchar *line, gsize len, g_set_error(err, rspamd_mime_expr_quark(), 100, "cannot parse" " mime atom '%s' when reading symbol '%c' at offset %d, " "near %.*s", - line, t, (gint) (p - line), - (gint) MIN(end - p, 10), p); + line, t, (int) (p - line), + (int) MIN(end - p, 10), p); return NULL; case end_atom: goto set; @@ -817,7 +817,7 @@ set: goto err; } else { - gint lua_cbref = -1; + int lua_cbref = -1; /* Check regexp condition */ if (real_ud->conf_obj != NULL) { @@ -1011,11 +1011,11 @@ err: return NULL; } -static gint +static int rspamd_mime_expr_process_regexp(struct rspamd_regexp_atom *re, struct rspamd_task *task) { - gint ret; + int ret; if (re == NULL) { msg_info_task("invalid regexp passed"); @@ -1057,11 +1057,11 @@ rspamd_mime_expr_process_regexp(struct rspamd_regexp_atom *re, } -static gint +static int rspamd_mime_expr_priority(rspamd_expression_atom_t *atom) { struct rspamd_mime_atom *mime_atom = atom->data; - gint ret = 0; + int ret = 0; switch (mime_atom->type) { case MIME_ATOM_INTERNAL_FUNCTION: @@ -1137,13 +1137,13 @@ rspamd_mime_expr_process_function(struct rspamd_function_atom *func, return selected->func(task, func->args, selected->user_data); } -static gdouble +static double rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom) { struct rspamd_task *task = (struct rspamd_task *) ud; struct rspamd_mime_atom *mime_atom; lua_State *L; - gdouble ret = 0; + double ret = 0; g_assert(task != NULL); g_assert(atom != NULL); @@ -1181,7 +1181,7 @@ rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom) } } else if (mime_atom->type == MIME_ATOM_LOCAL_LUA_FUNCTION) { - gint err_idx; + int err_idx; L = task->cfg->lua_state; lua_pushcfunction(L, &rspamd_lua_traceback); @@ -1218,7 +1218,7 @@ rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom) return ret; } -void register_expression_function(const gchar *name, +void register_expression_function(const char *name, rspamd_internal_func_t func, void *user_data) { @@ -1276,9 +1276,9 @@ rspamd_header_exists(struct rspamd_task *task, GArray *args, void *unused) } rh = rspamd_message_get_header_array(task, - (gchar *) arg->data, FALSE); + (char *) arg->data, FALSE); - debug_task("try to get header %s: %d", (gchar *) arg->data, + debug_task("try to get header %s: %d", (char *) arg->data, (rh != NULL)); if (rh) { @@ -1298,9 +1298,9 @@ rspamd_header_exists(struct rspamd_task *task, GArray *args, void *unused) gboolean rspamd_parts_distance(struct rspamd_task *task, GArray *args, void *unused) { - gint threshold, threshold2 = -1; + int threshold, threshold2 = -1; struct expression_argument *arg; - gdouble *pdiff, diff; + double *pdiff, diff; if (args == NULL || args->len == 0) { debug_task("no threshold is specified, assume it 100"); @@ -1314,10 +1314,10 @@ rspamd_parts_distance(struct rspamd_task *task, GArray *args, void *unused) return FALSE; } - threshold = strtoul((gchar *) arg->data, NULL, 10); + threshold = strtoul((char *) arg->data, NULL, 10); if (errno != 0) { msg_info_task("bad numeric value for threshold \"%s\", assume it 100", - (gchar *) arg->data); + (char *) arg->data); threshold = 100; } if (args->len >= 2) { @@ -1328,10 +1328,10 @@ rspamd_parts_distance(struct rspamd_task *task, GArray *args, void *unused) } errno = 0; - threshold2 = strtoul((gchar *) arg->data, NULL, 10); + threshold2 = strtoul((char *) arg->data, NULL, 10); if (errno != 0) { msg_info_task("bad numeric value for threshold \"%s\", ignore it", - (gchar *) arg->data); + (char *) arg->data); threshold2 = -1; } } @@ -1366,13 +1366,13 @@ rspamd_parts_distance(struct rspamd_task *task, GArray *args, void *unused) } struct addr_list { - const gchar *name; - guint namelen; - const gchar *addr; - guint addrlen; + const char *name; + unsigned int namelen; + const char *addr; + unsigned int addrlen; }; -static gint +static int addr_list_cmp_func(const void *a, const void *b) { const struct addr_list *addra = (struct addr_list *) a, @@ -1396,7 +1396,7 @@ rspamd_recipients_distance(struct rspamd_task *task, GArray *args, struct rspamd_email_address *cur; double threshold; struct addr_list *ar; - gint num, i, hits = 0; + int num, i, hits = 0; if (args == NULL) { msg_warn_task("no parameters to function"); @@ -1410,11 +1410,11 @@ rspamd_recipients_distance(struct rspamd_task *task, GArray *args, } errno = 0; - threshold = strtod((gchar *) arg->data, NULL); + threshold = strtod((char *) arg->data, NULL); if (errno != 0) { msg_warn_task("invalid numeric value '%s': %s", - (gchar *) arg->data, + (char *) arg->data, strerror(errno)); return FALSE; } @@ -1469,7 +1469,7 @@ rspamd_has_only_html_part(struct rspamd_task *task, GArray *args, void *unused) { struct rspamd_mime_text_part *p; - guint i, cnt_html = 0, cnt_txt = 0; + unsigned int i, cnt_html = 0, cnt_txt = 0; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, p) { @@ -1492,7 +1492,7 @@ is_recipient_list_sorted(GPtrArray *ar) struct rspamd_email_address *addr; gboolean res = TRUE; rspamd_ftok_t cur, prev; - gint i; + int i; /* Do not check to short address lists */ if (ar == NULL || ar->len < MIN_RCPT_TO_COMPARE) { @@ -1540,7 +1540,7 @@ rspamd_compare_transfer_encoding(struct rspamd_task *task, void *unused) { struct expression_argument *arg; - guint i; + unsigned int i; struct rspamd_mime_part *part; enum rspamd_cte cte; @@ -1586,7 +1586,7 @@ rspamd_has_html_tag(struct rspamd_task *task, GArray *args, void *unused) { struct rspamd_mime_text_part *p; struct expression_argument *arg; - guint i; + unsigned int i; gboolean res = FALSE; if (args == NULL) { @@ -1618,7 +1618,7 @@ gboolean rspamd_has_fake_html(struct rspamd_task *task, GArray *args, void *unused) { struct rspamd_mime_text_part *p; - guint i; + unsigned int i; gboolean res = FALSE; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, p) @@ -1656,10 +1656,10 @@ rspamd_raw_header_exists(struct rspamd_task *task, GArray *args, void *unused) static gboolean match_smtp_data(struct rspamd_task *task, struct expression_argument *arg, - const gchar *what, gsize len) + const char *what, gsize len) { rspamd_regexp_t *re; - gint r = 0; + int r = 0; if (arg->type == EXPRESSION_ARGUMENT_REGEXP) { /* This is a regexp */ @@ -1690,8 +1690,8 @@ rspamd_check_smtp_data(struct rspamd_task *task, GArray *args, void *unused) struct expression_argument *arg; struct rspamd_email_address *addr = NULL; GPtrArray *rcpts = NULL; - const gchar *type, *str = NULL; - guint i; + const char *type, *str = NULL; + unsigned int i; if (args == NULL) { msg_warn_task("no parameters to function"); @@ -1799,7 +1799,7 @@ rspamd_check_smtp_data(struct rspamd_task *task, GArray *args, void *unused) } static inline gboolean -rspamd_check_ct_attr(const gchar *begin, gsize len, +rspamd_check_ct_attr(const char *begin, gsize len, struct expression_argument *arg_pattern) { rspamd_regexp_t *re; @@ -1840,10 +1840,10 @@ rspamd_content_type_compare_param(struct rspamd_task *task, struct expression_argument *arg, *arg1, *arg_pattern; gboolean recursive = FALSE; struct rspamd_mime_part *cur_part; - guint i; + unsigned int i; rspamd_ftok_t srch; struct rspamd_content_type_param *found = NULL, *cur; - const gchar *param_name; + const char *param_name; if (args == NULL || args->len < 2) { msg_warn_task("no parameters to function"); @@ -1923,10 +1923,10 @@ rspamd_content_type_has_param(struct rspamd_task *task, struct expression_argument *arg, *arg1; gboolean recursive = FALSE; struct rspamd_mime_part *cur_part; - guint i; + unsigned int i; rspamd_ftok_t srch; struct rspamd_content_type_param *found = NULL; - const gchar *param_name; + const char *param_name; if (args == NULL || args->len < 1) { msg_warn_task("no parameters to function"); @@ -1999,8 +1999,8 @@ rspamd_content_type_check(struct rspamd_task *task, rspamd_regexp_t *re; struct expression_argument *arg1, *arg_pattern; struct rspamd_content_type *ct; - gint r = 0; - guint i; + int r = 0; + unsigned int i; gboolean recursive = FALSE; struct rspamd_mime_part *cur_part; @@ -2092,7 +2092,7 @@ compare_subtype(struct rspamd_task *task, struct rspamd_content_type *ct, { rspamd_regexp_t *re; rspamd_ftok_t srch; - gint r = 0; + int r = 0; if (subtype == NULL || ct == NULL) { msg_warn_task("invalid parameters passed"); @@ -2120,7 +2120,7 @@ compare_subtype(struct rspamd_task *task, struct rspamd_content_type *ct, } static gboolean -compare_len(struct rspamd_mime_part *part, guint min, guint max) +compare_len(struct rspamd_mime_part *part, unsigned int min, unsigned int max) { if (min == 0 && max == 0) { return TRUE; @@ -2141,15 +2141,15 @@ static gboolean common_has_content_part(struct rspamd_task *task, struct expression_argument *param_type, struct expression_argument *param_subtype, - gint min_len, - gint max_len) + int min_len, + int max_len) { rspamd_regexp_t *re; struct rspamd_mime_part *part; struct rspamd_content_type *ct; rspamd_ftok_t srch; - gint r = 0; - guint i; + int r = 0; + unsigned int i; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) { @@ -2224,7 +2224,7 @@ rspamd_has_content_part_len(struct rspamd_task *task, void *unused) { struct expression_argument *param_type = NULL, *param_subtype = NULL; - gint min = 0, max = 0; + int min = 0, max = 0; struct expression_argument *arg; if (args == NULL) { @@ -2245,7 +2245,7 @@ rspamd_has_content_part_len(struct rspamd_task *task, if (errno != 0) { msg_warn_task("invalid numeric value '%s': %s", - (gchar *) arg->data, + (char *) arg->data, strerror(errno)); return FALSE; } @@ -2257,7 +2257,7 @@ rspamd_has_content_part_len(struct rspamd_task *task, if (errno != 0) { msg_warn_task("invalid numeric value '%s': %s", - (gchar *) arg->data, + (char *) arg->data, strerror(errno)); return FALSE; } @@ -2274,7 +2274,7 @@ rspamd_is_empty_body(struct rspamd_task *task, void *unused) { struct rspamd_mime_part *part; - guint i; + unsigned int i; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) { @@ -2320,7 +2320,7 @@ rspamd_has_flag_expr(struct rspamd_task *task, { gboolean found = FALSE, result = FALSE; struct expression_argument *flag_arg; - const gchar *flag_str; + const char *flag_str; if (args == NULL) { msg_warn_task("no parameters to function"); @@ -2334,7 +2334,7 @@ rspamd_has_flag_expr(struct rspamd_task *task, return FALSE; } - flag_str = (const gchar *) flag_arg->data; + flag_str = (const char *) flag_arg->data; TASK_GET_FLAG(flag_str, "pass_all", RSPAMD_TASK_FLAG_PASS_ALL); TASK_GET_FLAG(flag_str, "no_log", RSPAMD_TASK_FLAG_NO_LOG); @@ -2368,7 +2368,7 @@ rspamd_has_symbol_expr(struct rspamd_task *task, void *unused) { struct expression_argument *sym_arg; - const gchar *symbol_str; + const char *symbol_str; if (args == NULL) { msg_warn_task("no parameters to function"); @@ -2382,7 +2382,7 @@ rspamd_has_symbol_expr(struct rspamd_task *task, return FALSE; } - symbol_str = (const gchar *) sym_arg->data; + symbol_str = (const char *) sym_arg->data; if (rspamd_task_find_symbol_result(task, symbol_str, NULL)) { return TRUE; diff --git a/src/libmime/mime_expressions.h b/src/libmime/mime_expressions.h index a2ea3fea4..106099803 100644 --- a/src/libmime/mime_expressions.h +++ b/src/libmime/mime_expressions.h @@ -47,7 +47,7 @@ typedef gboolean (*rspamd_internal_func_t)(struct rspamd_task *, * @param name name of function * @param func pointer to function */ -void register_expression_function(const gchar *name, +void register_expression_function(const char *name, rspamd_internal_func_t func, void *user_data); @@ -56,7 +56,7 @@ void register_expression_function(const gchar *name, * @param limit new limit in bytes * @return old limit value */ -guint rspamd_mime_expression_set_re_limit(guint limit); +unsigned int rspamd_mime_expression_set_re_limit(unsigned int limit); #ifdef __cplusplus } diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c index 2bdab38c2..e4bf4db06 100644 --- a/src/libmime/mime_headers.c +++ b/src/libmime/mime_headers.c @@ -24,7 +24,7 @@ #include "libutil/util.h" #include -KHASH_INIT(rspamd_mime_headers_htb, gchar *, +KHASH_INIT(rspamd_mime_headers_htb, char *, struct rspamd_mime_header *, 1, rspamd_strcase_hash, rspamd_strcase_equal); @@ -38,9 +38,9 @@ rspamd_mime_header_check_special(struct rspamd_task *task, struct rspamd_mime_header *rh) { uint64_t h; - const gchar *p, *end; - gchar *id; - gint max_recipients = -1, len; + const char *p, *end; + char *id; + int max_recipients = -1, len; if (task->cfg) { max_recipients = task->cfg->max_recipients; @@ -93,7 +93,7 @@ rspamd_mime_header_check_special(struct rspamd_task *task, } if (end > p) { - gchar *d; + char *d; if (*(end - 1) == '>') { end--; @@ -186,16 +186,16 @@ rspamd_mime_header_add(struct rspamd_task *task, void rspamd_mime_headers_process(struct rspamd_task *task, struct rspamd_mime_headers_table *target, struct rspamd_mime_header **order_ptr, - const gchar *in, gsize len, + const char *in, gsize len, gboolean check_newlines) { struct rspamd_mime_header *nh = NULL; - const gchar *p, *c, *end; - gchar *tmp, *tp; - gint state = 0, l, next_state = 100, err_state = 100, t_state; + const char *p, *c, *end; + char *tmp, *tp; + int state = 0, l, next_state = 100, err_state = 100, t_state; gboolean valid_folding = FALSE, shift_by_one = FALSE; - guint nlines_count[RSPAMD_TASK_NEWLINES_MAX]; - guint norder = 0; + unsigned int nlines_count[RSPAMD_TASK_NEWLINES_MAX]; + unsigned int norder = 0; p = in; end = p + len; @@ -485,12 +485,12 @@ void rspamd_mime_headers_process(struct rspamd_task *task, LL_REVERSE(*order_ptr); if (check_newlines) { - guint max_cnt = 0; - gint sel = 0; + unsigned int max_cnt = 0; + int sel = 0; rspamd_cryptobox_hash_state_t hs; - guchar hout[rspamd_cryptobox_HASHBYTES], *hexout; + unsigned char hout[rspamd_cryptobox_HASHBYTES], *hexout; - for (gint i = RSPAMD_TASK_NEWLINES_CR; i < RSPAMD_TASK_NEWLINES_MAX; i++) { + for (int i = RSPAMD_TASK_NEWLINES_CR; i < RSPAMD_TASK_NEWLINES_MAX; i++) { if (nlines_count[i] > max_cnt) { max_cnt = nlines_count[i]; sel = i; @@ -572,7 +572,7 @@ static void rspamd_mime_header_sanity_check(GString *str) { gsize i; - gchar t; + char t; for (i = 0; i < str->len; i++) { t = str->str[i]; @@ -588,20 +588,20 @@ rspamd_mime_header_sanity_check(GString *str) } } -gchar * -rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in, +char * +rspamd_mime_header_decode(rspamd_mempool_t *pool, const char *in, gsize inlen, gboolean *invalid_utf) { GString *out; - const guchar *c, *p, *end; - const gchar *tok_start = NULL; + const unsigned char *c, *p, *end; + const char *tok_start = NULL; gsize tok_len = 0, pos; GByteArray *token = NULL, *decoded; rspamd_ftok_t cur_charset = {0, NULL}, old_charset = {0, NULL}; - gint encoding; + int encoding; gssize r; - guint qmarks = 0; - gchar *ret; + unsigned int qmarks = 0; + char *ret; enum { parse_normal = 0, got_eqsign, @@ -628,7 +628,7 @@ rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in, state = got_eqsign; } else if (*p >= 128) { - gint off = 0; + int off = 0; UChar32 uc; /* Unencoded character */ g_string_append_len(out, c, p - c); @@ -815,17 +815,17 @@ rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in, return ret; } -gchar * -rspamd_mime_header_encode(const gchar *in, gsize len) +char * +rspamd_mime_header_encode(const char *in, gsize len) { - const gchar *p = in, *end = in + len; - gchar *out, encode_buf[80 * sizeof(uint32_t)]; + const char *p = in, *end = in + len; + char *out, encode_buf[80 * sizeof(uint32_t)]; GString *res; gboolean need_encoding = FALSE; /* Check if we need to encode */ while (p < end) { - if ((((guchar) *p) & 0x80) != 0) { + if ((((unsigned char) *p) & 0x80) != 0) { need_encoding = TRUE; break; } @@ -839,17 +839,17 @@ rspamd_mime_header_encode(const gchar *in, gsize len) else { /* Need encode */ gsize ulen, pos; - gint r; - const gchar *prev; + int r; + const char *prev; /* Choose step: =?UTF-8?Q??= should be less than 76 chars */ - guint step = (76 - 12) / 3 + 1; + unsigned int step = (76 - 12) / 3 + 1; ulen = g_utf8_strlen(in, len); res = g_string_sized_new(len * 2 + 1); pos = 0; prev = in; /* Adjust chunk size for unicode average length */ - step *= 1.0 * ulen / (gdouble) len; + step *= 1.0 * ulen / (double) len; while (pos < ulen) { p = g_utf8_offset_to_pointer(in, pos); @@ -898,8 +898,8 @@ rspamd_mime_header_encode(const gchar *in, gsize len) return out; } -gchar * -rspamd_mime_message_id_generate(const gchar *fqdn) +char * +rspamd_mime_message_id_generate(const char *fqdn) { GString *out; uint64_t rnd, clk; @@ -909,8 +909,8 @@ rspamd_mime_message_id_generate(const gchar *fqdn) clk = rspamd_get_calendar_ticks() * 1e6; rspamd_printf_gstring(out, "%*bs.%*bs@%s", - (gint) sizeof(uint64_t) - 3, (guchar *) &clk, - (gint) sizeof(uint64_t), (gchar *) &rnd, + (int) sizeof(uint64_t) - 3, (unsigned char *) &clk, + (int) sizeof(uint64_t), (char *) &rnd, fqdn); return g_string_free(out, FALSE); @@ -918,7 +918,7 @@ rspamd_mime_message_id_generate(const gchar *fqdn) struct rspamd_mime_header * rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs, - const gchar *field, + const char *field, gboolean need_modified) { if (hdrs == NULL) { @@ -930,7 +930,7 @@ rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs, struct rspamd_mime_header *hdr; if (htb) { - k = kh_get(rspamd_mime_headers_htb, htb, (gchar *) field); + k = kh_get(rspamd_mime_headers_htb, htb, (char *) field); if (k == kh_end(htb)) { return NULL; @@ -958,7 +958,7 @@ rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs, } struct rspamd_mime_header * -rspamd_message_get_header_array(struct rspamd_task *task, const gchar *field, +rspamd_message_get_header_array(struct rspamd_task *task, const char *field, gboolean need_modified) { return rspamd_message_get_header_from_hash( @@ -978,7 +978,7 @@ gsize rspamd_mime_headers_count(struct rspamd_mime_headers_table *hdrs) bool rspamd_mime_headers_foreach(const struct rspamd_mime_headers_table *hdrs, rspamd_hdr_traverse_func_t func, void *ud) { - const gchar *name; + const char *name; struct rspamd_mime_header *hdr; kh_foreach(&hdrs->htb, name, hdr, { @@ -1097,7 +1097,7 @@ gsize rspamd_message_header_unfold_inplace(char *hdr, gsize len) void rspamd_message_set_modified_header(struct rspamd_task *task, struct rspamd_mime_headers_table *hdrs, - const gchar *hdr_name, + const char *hdr_name, const ucl_object_t *obj, struct rspamd_mime_header **order_ptr) { @@ -1107,7 +1107,7 @@ void rspamd_message_set_modified_header(struct rspamd_task *task, int i; if (htb) { - k = kh_get(rspamd_mime_headers_htb, htb, (gchar *) hdr_name); + k = kh_get(rspamd_mime_headers_htb, htb, (char *) hdr_name); if (k == kh_end(htb)) { hdr_elt = rspamd_mempool_alloc0(task->task_pool, sizeof(*hdr_elt)); @@ -1353,7 +1353,7 @@ void rspamd_message_set_modified_header(struct rspamd_task *task, } } -gsize rspamd_strip_smtp_comments_inplace(gchar *input, gsize len) +gsize rspamd_strip_smtp_comments_inplace(char *input, gsize len) { enum parser_state { parse_normal, @@ -1363,8 +1363,8 @@ gsize rspamd_strip_smtp_comments_inplace(gchar *input, gsize len) parse_quoted_ignore, } state = parse_normal, next_state = parse_normal; - gchar *d = input, *end = input + len, *start = input; - gchar t; + char *d = input, *end = input + len, *start = input; + char t; int obraces = 0, ebraces = 0; while (input < end) { diff --git a/src/libmime/mime_headers.h b/src/libmime/mime_headers.h index 60015a20e..9f89daece 100644 --- a/src/libmime/mime_headers.h +++ b/src/libmime/mime_headers.h @@ -56,15 +56,15 @@ enum rspamd_mime_header_flags { }; struct rspamd_mime_header { - const gchar *raw_value; /* As it is in the message (unfolded and unparsed) */ + const char *raw_value; /* As it is in the message (unfolded and unparsed) */ gsize raw_len; - guint order; + unsigned int order; int flags; /* see enum rspamd_mime_header_flags */ /* These are zero terminated (historically) */ - gchar *name; /* Also used for key */ - gchar *value; - gchar *separator; - gchar *decoded; + char *name; /* Also used for key */ + char *value; + char *separator; + char *decoded; struct rspamd_mime_header *modified_chain; /* Headers modified during transform */ struct rspamd_mime_header *prev, *next; /* Headers with the same name */ struct rspamd_mime_header *ord_next; /* Overall order of headers, slist */ @@ -83,7 +83,7 @@ struct rspamd_mime_headers_table; void rspamd_mime_headers_process(struct rspamd_task *task, struct rspamd_mime_headers_table *target, struct rspamd_mime_header **order_ptr, - const gchar *in, gsize len, + const char *in, gsize len, gboolean check_newlines); /** @@ -93,8 +93,8 @@ void rspamd_mime_headers_process(struct rspamd_task *task, * @param inlen * @return */ -gchar *rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in, - gsize inlen, gboolean *invalid_utf); +char *rspamd_mime_header_decode(rspamd_mempool_t *pool, const char *in, + gsize inlen, gboolean *invalid_utf); /** * Encode mime header if needed @@ -102,14 +102,14 @@ gchar *rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in, * @param len * @return newly allocated encoded header */ -gchar *rspamd_mime_header_encode(const gchar *in, gsize len); +char *rspamd_mime_header_encode(const char *in, gsize len); /** * Generate new unique message id * @param fqdn * @return */ -gchar *rspamd_mime_message_id_generate(const gchar *fqdn); +char *rspamd_mime_message_id_generate(const char *fqdn); /** * Get an array of header's values with specified header's name using raw headers @@ -119,7 +119,7 @@ gchar *rspamd_mime_message_id_generate(const gchar *fqdn); */ struct rspamd_mime_header * rspamd_message_get_header_array(struct rspamd_task *task, - const gchar *field, + const char *field, gboolean need_modified); /** @@ -130,7 +130,7 @@ rspamd_message_get_header_array(struct rspamd_task *task, */ struct rspamd_mime_header * rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs, - const gchar *field, + const char *field, gboolean need_modified); /** @@ -142,7 +142,7 @@ rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs, */ void rspamd_message_set_modified_header(struct rspamd_task *task, struct rspamd_mime_headers_table *hdrs, - const gchar *hdr_name, + const char *hdr_name, const ucl_object_t *obj, struct rspamd_mime_header **order_ptr); @@ -167,7 +167,7 @@ struct rspamd_mime_headers_table *rspamd_message_headers_new(void); */ gsize rspamd_mime_headers_count(struct rspamd_mime_headers_table *hdrs); -typedef bool(rspamd_hdr_traverse_func_t)(const gchar *, const struct rspamd_mime_header *, void *); +typedef bool(rspamd_hdr_traverse_func_t)(const char *, const struct rspamd_mime_header *, void *); /** * Traverse all headers in a table * @param func @@ -183,7 +183,7 @@ bool rspamd_mime_headers_foreach(const struct rspamd_mime_headers_table *, * @param len length of the input * @return new length of the input */ -gsize rspamd_strip_smtp_comments_inplace(gchar *input, gsize len); +gsize rspamd_strip_smtp_comments_inplace(char *input, gsize len); /** * Unfold header in place diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c index 64a8a2242..e753f6377 100644 --- a/src/libmime/mime_parser.c +++ b/src/libmime/mime_parser.c @@ -29,14 +29,14 @@ struct rspamd_mime_parser_lib_ctx { struct rspamd_multipattern *mp_boundary; - guchar hkey[rspamd_cryptobox_SIPKEYBYTES]; /* Key for hashing */ - guint key_usages; + unsigned char hkey[rspamd_cryptobox_SIPKEYBYTES]; /* Key for hashing */ + unsigned int key_usages; }; struct rspamd_mime_parser_lib_ctx *lib_ctx = NULL; -static const guint max_nested = 64; -static const guint max_key_usages = 10000; +static const unsigned int max_nested = 64; +static const unsigned int max_key_usages = 10000; #define msg_debug_mime(...) rspamd_conditional_debug_fast(NULL, task->from_addr, \ rspamd_mime_log_id, "mime", task->task_pool->tag.uid, \ @@ -53,17 +53,17 @@ struct rspamd_mime_boundary { goffset start; uint64_t hash; uint64_t closed_hash; - gint flags; + int flags; }; struct rspamd_mime_parser_ctx { GPtrArray *stack; /* Stack of parts */ GArray *boundaries; /* Boundaries found in the whole message */ - const gchar *start; - const gchar *pos; - const gchar *end; + const char *start; + const char *pos; + const char *end; struct rspamd_task *task; - guint nesting; + unsigned int nesting; }; static enum rspamd_mime_parse_error @@ -87,7 +87,7 @@ static enum rspamd_mime_parse_error rspamd_mime_process_multipart_node(struct rspamd_task *task, struct rspamd_mime_parser_ctx *st, struct rspamd_mime_part *multipart, - const gchar *start, const gchar *end, + const char *start, const char *end, gboolean is_finished, GError **err); @@ -99,10 +99,10 @@ rspamd_mime_parser_quark(void) return g_quark_from_static_string("mime-parser"); } -const gchar * +const char * rspamd_cte_to_string(enum rspamd_cte ct) { - const gchar *ret = "unknown"; + const char *ret = "unknown"; switch (ct) { case RSPAMD_CTE_7BIT: @@ -128,7 +128,7 @@ rspamd_cte_to_string(enum rspamd_cte ct) } enum rspamd_cte -rspamd_cte_from_string(const gchar *str) +rspamd_cte_from_string(const char *str) { enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN; @@ -178,7 +178,7 @@ rspamd_mime_parser_init_lib(void) } static enum rspamd_cte -rspamd_mime_parse_cte(const gchar *in, gsize len) +rspamd_mime_parse_cte(const char *in, gsize len) { uint64_t h; enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN; @@ -216,15 +216,15 @@ static enum rspamd_cte rspamd_mime_part_get_cte_heuristic(struct rspamd_task *task, struct rspamd_mime_part *part) { - const guint check_len = 128; - guint real_len, nspaces = 0, neqsign = 0, n8bit = 0, nqpencoded = 0, - padeqsign = 0, nupper = 0, nlower = 0; + const unsigned int check_len = 128; + unsigned int real_len, nspaces = 0, neqsign = 0, n8bit = 0, nqpencoded = 0, + padeqsign = 0, nupper = 0, nlower = 0; gboolean b64_chars = TRUE; - const guchar *p, *end; + const unsigned char *p, *end; enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN; real_len = MIN(check_len, part->raw_data.len); - p = (const guchar *) part->raw_data.begin; + p = (const unsigned char *) part->raw_data.begin; end = p + part->raw_data.len; while (p < end && g_ascii_isspace(*p)) { @@ -232,7 +232,7 @@ rspamd_mime_part_get_cte_heuristic(struct rspamd_task *task, } if (end - p > sizeof("begin-base64 ")) { - const guchar *uue_start; + const unsigned char *uue_start; if (memcmp(p, "begin ", sizeof("begin ") - 1) == 0) { uue_start = p + sizeof("begin ") - 1; @@ -342,7 +342,7 @@ rspamd_mime_part_get_cte_heuristic(struct rspamd_task *task, } else { - if (((end - (const guchar *) part->raw_data.begin) + padeqsign) % 4 == 0) { + if (((end - (const unsigned char *) part->raw_data.begin) + padeqsign) % 4 == 0) { if (padeqsign == 0) { /* * It can be either base64 or plain text, hard to say @@ -421,7 +421,7 @@ rspamd_mime_part_get_cte(struct rspamd_task *task, DL_FOREACH(hdr, cur) { gsize hlen; - gchar lc_buf[128]; + char lc_buf[128]; hlen = rspamd_snprintf(lc_buf, sizeof(lc_buf), "%s", cur->value); rspamd_str_lc(lc_buf, hlen); @@ -571,7 +571,7 @@ rspamd_mime_part_get_cd(struct rspamd_task *task, struct rspamd_mime_part *part) void rspamd_mime_parser_calc_digest(struct rspamd_mime_part *part) { /* Blake2b applied to string 'rspamd' */ - static const guchar hash_key[] = { + static const unsigned char hash_key[] = { 0xef, 0x43, 0xae, @@ -815,8 +815,8 @@ rspamd_mime_parse_normal_part(struct rspamd_task *task, * Since ASN.1 structures are freed, we need to copy * the content */ - gchar *cpy = rspamd_mempool_alloc(task->task_pool, - p7_signed_content->d.data->length); + char *cpy = rspamd_mempool_alloc(task->task_pool, + p7_signed_content->d.data->length); memcpy(cpy, p7_signed_content->d.data->data, p7_signed_content->d.data->length); ret = rspamd_mime_process_multipart_node(task, @@ -849,7 +849,7 @@ struct rspamd_mime_multipart_cbdata { struct rspamd_task *task; struct rspamd_mime_part *multipart; struct rspamd_mime_parser_ctx *st; - const gchar *part_start; + const char *part_start; rspamd_ftok_t *cur_boundary; uint64_t bhash; GError **err; @@ -859,7 +859,7 @@ static enum rspamd_mime_parse_error rspamd_mime_process_multipart_node(struct rspamd_task *task, struct rspamd_mime_parser_ctx *st, struct rspamd_mime_part *multipart, - const gchar *start, const gchar *end, + const char *start, const char *end, gboolean is_finished, GError **err) { @@ -871,7 +871,7 @@ rspamd_mime_process_multipart_node(struct rspamd_task *task, enum rspamd_mime_parse_error ret = RSPAMD_MIME_PARSE_FATAL; - str.str = (gchar *) start; + str.str = (char *) start; str.len = end - start; if (*start == '\n' || *start == '\r') { @@ -885,7 +885,7 @@ rspamd_mime_process_multipart_node(struct rspamd_task *task, if (!is_finished) { /* Ignore garbage */ - const gchar *p = start; + const char *p = start; gboolean seen_something = FALSE; while (p < end) { @@ -1009,7 +1009,7 @@ rspamd_mime_parse_multipart_cb(struct rspamd_task *task, struct rspamd_mime_multipart_cbdata *cb, struct rspamd_mime_boundary *b) { - const gchar *pos = st->start + b->boundary; + const char *pos = st->start + b->boundary; enum rspamd_mime_parse_error ret; task = cb->task; @@ -1053,7 +1053,7 @@ rspamd_multipart_boundaries_filter(struct rspamd_task *task, { struct rspamd_mime_boundary *cur; goffset last_offset; - guint i, sel = 0; + unsigned int i, sel = 0; enum rspamd_mime_parse_error ret; last_offset = (multipart->raw_data.begin - st->start) + @@ -1183,7 +1183,7 @@ rspamd_mime_parse_multipart_part(struct rspamd_task *task, if (part->ct->boundary.len > 0) { /* We know our boundary */ cbdata.cur_boundary = &part->ct->boundary; - rspamd_cryptobox_siphash((guchar *) &cbdata.bhash, + rspamd_cryptobox_siphash((unsigned char *) &cbdata.bhash, cbdata.cur_boundary->begin, cbdata.cur_boundary->len, lib_ctx->hkey); msg_debug_mime("hash: %T -> %L", cbdata.cur_boundary, cbdata.bhash); @@ -1203,16 +1203,16 @@ rspamd_mime_parse_multipart_part(struct rspamd_task *task, } /* Process boundary like structures in a message */ -static gint +static int rspamd_mime_preprocess_cb(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, + unsigned int strnum, + int match_start, + int match_pos, + const char *text, gsize len, void *context) { - const gchar *end = text + len, *p = text + match_pos, *bend; + const char *end = text + len, *p = text + match_pos, *bend; gsize blen; gboolean closing = FALSE; struct rspamd_mime_boundary b; @@ -1281,7 +1281,7 @@ rspamd_mime_preprocess_cb(struct rspamd_multipattern *mp, b.start = bend - st->start; /* Small optimisation as boundaries are usually short strings */ - gchar *lc_copy, lc_copy_buf[128]; + char *lc_copy, lc_copy_buf[128]; if (blen + 2 < sizeof(lc_copy_buf)) { lc_copy = lc_copy_buf; @@ -1299,18 +1299,18 @@ rspamd_mime_preprocess_cb(struct rspamd_multipattern *mp, rspamd_str_lc(lc_copy, blen); } - rspamd_cryptobox_siphash((guchar *) &b.hash, lc_copy, blen, + rspamd_cryptobox_siphash((unsigned char *) &b.hash, lc_copy, blen, lib_ctx->hkey); msg_debug_mime("normal hash: %*s -> %L, %d boffset, %d data offset", - (gint) blen, lc_copy, b.hash, (int) b.boundary, (int) b.start); + (int) blen, lc_copy, b.hash, (int) b.boundary, (int) b.start); if (closing) { b.flags = RSPAMD_MIME_BOUNDARY_FLAG_CLOSED; - rspamd_cryptobox_siphash((guchar *) &b.closed_hash, lc_copy, + rspamd_cryptobox_siphash((unsigned char *) &b.closed_hash, lc_copy, blen + 2, lib_ctx->hkey); msg_debug_mime("closing hash: %*s -> %L, %d boffset, %d data offset", - (gint) blen + 2, lc_copy, + (int) blen + 2, lc_copy, b.closed_hash, (int) b.boundary, (int) b.start); } @@ -1335,7 +1335,7 @@ rspamd_mime_parser_headers_heuristic(GString *input, goffset *body_start) { const gsize default_max_len = 76; gsize max_len = MIN(input->len, default_max_len); - const gchar *p, *end; + const char *p, *end; enum { st_before_colon = 0, st_colon, @@ -1434,11 +1434,11 @@ rspamd_mime_parse_message(struct rspamd_task *task, { struct rspamd_content_type *ct, *sel = NULL; struct rspamd_mime_header *hdr = NULL, *cur; - const gchar *pbegin, *p; + const char *pbegin, *p; gsize plen, len; struct rspamd_mime_part *npart; goffset hdr_pos, body_pos; - guint i; + unsigned int i; enum rspamd_mime_parse_error ret = RSPAMD_MIME_PARSE_OK; GString str; struct rspamd_mime_parser_ctx *nst = st; @@ -1458,7 +1458,7 @@ rspamd_mime_parse_message(struct rspamd_task *task, p = task->msg.begin; len = task->msg.len; - str.str = (gchar *) p; + str.str = (char *) p; str.len = len; hdr_pos = rspamd_string_find_eoh(&str, &body_pos); @@ -1545,7 +1545,7 @@ rspamd_mime_parse_message(struct rspamd_task *task, nst->nesting = st->nesting; st->nesting++; - str.str = (gchar *) part->parsed_data.begin; + str.str = (char *) part->parsed_data.begin; str.len = part->parsed_data.len; hdr_pos = rspamd_string_find_eoh(&str, &body_pos); @@ -1660,7 +1660,7 @@ rspamd_mime_parse_message(struct rspamd_task *task, *end_boundary = NULL; goffset cur_offset = nst->pos - nst->start, end_offset = st->end - st->start; - guint sel_idx = 0; + unsigned int sel_idx = 0; for (;;) { start_boundary = NULL; @@ -1679,7 +1679,7 @@ rspamd_mime_parse_message(struct rspamd_task *task, } if (start_boundary) { - const gchar *start, *end; + const char *start, *end; if (nst->boundaries->len > sel_idx + 1) { end_boundary = &g_array_index(nst->boundaries, diff --git a/src/libmime/received.cxx b/src/libmime/received.cxx index dc16d9b09..ab0a65a69 100644 --- a/src/libmime/received.cxx +++ b/src/libmime/received.cxx @@ -50,7 +50,7 @@ struct received_part { }; static inline auto -received_part_set_or_append(const gchar *begin, +received_part_set_or_append(const char *begin, gsize len, mime_string &dest) -> void { @@ -427,7 +427,7 @@ received_process_rdns(rspamd_mempool_t *pool, RSPAMD_INET_ADDRESS_PARSE_RECEIVED); if (addr) { - const gchar *addr_str; + const char *addr_str; if (rspamd_inet_address_get_port(addr) != 0) { addr_str = rspamd_inet_address_to_string_pretty(addr); diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c index 5c89b6560..b9660071b 100644 --- a/src/libmime/scan_result.c +++ b/src/libmime/scan_result.c @@ -73,7 +73,7 @@ rspamd_metric_actions_foreach_cb(int i, struct rspamd_action *act, void *cbd) struct rspamd_scan_result * rspamd_create_metric_result(struct rspamd_task *task, - const gchar *name, gint lua_sym_cbref) + const char *name, int lua_sym_cbref) { struct rspamd_scan_result *metric_res; @@ -127,10 +127,10 @@ rspamd_pr_sort(const struct rspamd_passthrough_result *pra, bool rspamd_add_passthrough_result(struct rspamd_task *task, struct rspamd_action *action, - guint priority, + unsigned int priority, double target_score, - const gchar *message, - const gchar *module, + const char *message, + const char *module, uint flags, struct rspamd_scan_result *scan_result) { @@ -194,12 +194,12 @@ bool rspamd_add_passthrough_result(struct rspamd_task *task, return true; } -static inline gdouble +static inline double rspamd_check_group_score(struct rspamd_task *task, - const gchar *symbol, + const char *symbol, struct rspamd_symbols_group *gr, - gdouble *group_score, - gdouble w) + double *group_score, + double w) { if (gr != NULL && group_score && gr->max_score > 0.0 && w > 0.0) { if (*group_score >= gr->max_score && w > 0) { @@ -223,23 +223,23 @@ rspamd_check_group_score(struct rspamd_task *task, static struct rspamd_symbol_result * insert_metric_result(struct rspamd_task *task, - const gchar *symbol, + const char *symbol, double weight, - const gchar *opt, + const char *opt, struct rspamd_scan_result *metric_res, enum rspamd_symbol_insert_flags flags, bool *new_sym) { struct rspamd_symbol_result *symbol_result = NULL; - gdouble final_score, *gr_score = NULL, next_gf = 1.0, diff; + double final_score, *gr_score = NULL, next_gf = 1.0, diff; struct rspamd_symbol *sdef; struct rspamd_symbols_group *gr = NULL; const ucl_object_t *mobj, *sobj; - gint max_shots = G_MAXINT, ret; - guint i; + int max_shots = G_MAXINT, ret; + unsigned int i; khiter_t k; gboolean single = !!(flags & RSPAMD_SYMBOL_INSERT_SINGLE); - gchar *sym_cpy; + char *sym_cpy; if (!isfinite(weight)) { msg_warn_task("detected %s score for symbol %s, replace it with zero", @@ -290,7 +290,7 @@ insert_metric_result(struct rspamd_task *task, } if (task->settings) { - gdouble corr; + double corr; mobj = ucl_object_lookup(task->settings, "scores"); if (!mobj) { @@ -383,7 +383,7 @@ insert_metric_result(struct rspamd_task *task, if (sdef) { PTR_ARRAY_FOREACH(sdef->groups, i, gr) { - gdouble cur_diff; + double cur_diff; k = kh_get(rspamd_symbols_group_hash, metric_res->sym_groups, gr); @@ -467,7 +467,7 @@ insert_metric_result(struct rspamd_task *task, /* Check group limits */ PTR_ARRAY_FOREACH(sdef->groups, i, gr) { - gdouble cur_score; + double cur_score; k = kh_get(rspamd_symbols_group_hash, metric_res->sym_groups, gr); g_assert(k != kh_end(metric_res->sym_groups)); @@ -535,9 +535,9 @@ insert_metric_result(struct rspamd_task *task, struct rspamd_symbol_result * rspamd_task_insert_result_full(struct rspamd_task *task, - const gchar *symbol, + const char *symbol, double weight, - const gchar *opt, + const char *opt, enum rspamd_symbol_insert_flags flags, struct rspamd_scan_result *result) { @@ -638,13 +638,13 @@ rspamd_task_insert_result_full(struct rspamd_task *task, return ret; } -static gchar * +static char * rspamd_task_option_safe_copy(struct rspamd_task *task, - const gchar *val, + const char *val, gsize vlen, gsize *outlen) { - const gchar *p, *end; + const char *p, *end; p = val; end = val + vlen; @@ -653,7 +653,7 @@ rspamd_task_option_safe_copy(struct rspamd_task *task, while (p < end) { if (*p & 0x80) { UChar32 uc; - gint off = 0; + int off = 0; U8_NEXT(p, off, end - p, uc); @@ -683,7 +683,7 @@ rspamd_task_option_safe_copy(struct rspamd_task *task, } } - gchar *dest, *d; + char *dest, *d; dest = rspamd_mempool_alloc(task->task_pool, vlen + 1); d = dest; @@ -692,7 +692,7 @@ rspamd_task_option_safe_copy(struct rspamd_task *task, while (p < end) { if (*p & 0x80) { UChar32 uc; - gint off = 0; + int off = 0; U8_NEXT(p, off, end - p, uc); @@ -737,15 +737,15 @@ rspamd_task_option_safe_copy(struct rspamd_task *task, gboolean rspamd_task_add_result_option(struct rspamd_task *task, struct rspamd_symbol_result *s, - const gchar *val, + const char *val, gsize vlen) { struct rspamd_symbol_option *opt, srch; gboolean ret = FALSE; - gchar *opt_cpy = NULL; + char *opt_cpy = NULL; gsize cpy_len; khiter_t k; - gint r; + int r; struct rspamd_symbol_result *cur; if (s && val) { @@ -779,14 +779,14 @@ rspamd_task_add_result_option(struct rspamd_task *task, if (!(cur->sym && (cur->sym->flags & RSPAMD_SYMBOL_FLAG_ONEPARAM))) { - srch.option = (gchar *) val; + srch.option = (char *) val; srch.optlen = vlen; k = kh_get(rspamd_options_hash, cur->options, &srch); if (k == kh_end(cur->options)) { opt_cpy = rspamd_task_option_safe_copy(task, val, vlen, &cpy_len); if (cpy_len != vlen) { - srch.option = (gchar *) opt_cpy; + srch.option = (char *) opt_cpy; srch.optlen = cpy_len; k = kh_get(rspamd_options_hash, cur->options, &srch); } @@ -1013,7 +1013,7 @@ rspamd_task_find_symbol_result(struct rspamd_task *task, const char *sym, struct rspamd_symbol_result *rspamd_task_remove_symbol_result( struct rspamd_task *task, - const gchar *symbol, + const char *symbol, struct rspamd_scan_result *result) { struct rspamd_symbol_result *res = NULL; @@ -1036,12 +1036,12 @@ struct rspamd_symbol_result *rspamd_task_remove_symbol_result( /* Also check the group limit */ if (result->sym_groups && res->sym) { struct rspamd_symbol_group *gr; - gint i; + int i; khiter_t k_groups; PTR_ARRAY_FOREACH(res->sym->groups, i, gr) { - gdouble *gr_score; + double *gr_score; k_groups = kh_get(rspamd_symbols_group_hash, result->sym_groups, gr); @@ -1070,7 +1070,7 @@ void rspamd_task_symbol_result_foreach(struct rspamd_task *task, struct rspamd_scan_result *result, GHFunc func, gpointer ud) { - const gchar *kk; + const char *kk; struct rspamd_symbol_result *res; if (result == NULL) { @@ -1087,7 +1087,7 @@ void rspamd_task_symbol_result_foreach(struct rspamd_task *task, struct rspamd_scan_result * rspamd_find_metric_result(struct rspamd_task *task, - const gchar *name) + const char *name) { struct rspamd_scan_result *res; diff --git a/src/libmime/scan_result.h b/src/libmime/scan_result.h index 46c2de8fa..d4572e1d8 100644 --- a/src/libmime/scan_result.h +++ b/src/libmime/scan_result.h @@ -35,7 +35,7 @@ struct rspamd_settings; struct rspamd_classifier_config; struct rspamd_symbol_option { - gchar *option; + char *option; gsize optlen; struct rspamd_symbol_option *prev, *next; }; @@ -54,10 +54,10 @@ struct rspamd_symbol_result { double score; /**< symbol's score */ struct kh_rspamd_options_hash_s *options; /**< list of symbol's options */ struct rspamd_symbol_option *opts_head; /**< head of linked list of options */ - const gchar *name; + const char *name; struct rspamd_symbol *sym; /**< symbol configuration */ gssize opts_len; /**< total size of all options (negative if truncated option is added) */ - guint nshots; + unsigned int nshots; int flags; struct rspamd_symbol_result *next; /**< for shadow results */ }; @@ -74,11 +74,11 @@ struct rspamd_symbol_result { struct rspamd_passthrough_result { struct rspamd_action *action; - guint priority; - guint flags; + unsigned int priority; + unsigned int flags; double target_score; - const gchar *message; - const gchar *module; + const char *message; + const char *module; struct rspamd_passthrough_result *prev, *next; }; @@ -89,7 +89,7 @@ enum rspamd_action_config_flags { RSPAMD_ACTION_RESULT_DISABLED = (1u << 1u), }; struct rspamd_action_config { - gdouble cur_limit; + double cur_limit; int flags; struct rspamd_action *action; }; @@ -107,14 +107,14 @@ struct rspamd_scan_result { struct kh_rspamd_symbols_hash_s *symbols; /**< symbols of metric */ struct kh_rspamd_symbols_group_hash_s *sym_groups; /**< groups of symbols */ struct rspamd_action_config *actions_config; - const gchar *name; /**< for named results, NULL is the default result */ + const char *name; /**< for named results, NULL is the default result */ struct rspamd_task *task; /**< back reference */ - gint symbol_cbref; /**< lua function that defines if a symbol can be inserted, -1 if unused */ - guint nactions; - guint npositive; - guint nnegative; - guint nresults; /**< all results: positive, negative, passthrough etc */ - guint nresults_postfilters; /**< how many results are there before postfilters stage */ + int symbol_cbref; /**< lua function that defines if a symbol can be inserted, -1 if unused */ + unsigned int nactions; + unsigned int npositive; + unsigned int nnegative; + unsigned int nresults; /**< all results: positive, negative, passthrough etc */ + unsigned int nresults_postfilters; /**< how many results are there before postfilters stage */ struct rspamd_scan_result *prev, *next; /**< double linked list of results */ }; @@ -124,7 +124,7 @@ struct rspamd_scan_result { * @return metric result or NULL if metric `name` has not been found */ struct rspamd_scan_result *rspamd_create_metric_result(struct rspamd_task *task, - const gchar *name, gint lua_sym_cbref); + const char *name, int lua_sym_cbref); /** * Find result with a specific name (NULL means the default result) @@ -133,7 +133,7 @@ struct rspamd_scan_result *rspamd_create_metric_result(struct rspamd_task *task, * @return */ struct rspamd_scan_result *rspamd_find_metric_result(struct rspamd_task *task, - const gchar *name); + const char *name); /** * Adds a new passthrough result to a task @@ -145,9 +145,9 @@ struct rspamd_scan_result *rspamd_find_metric_result(struct rspamd_task *task, * @param module */ bool rspamd_add_passthrough_result(struct rspamd_task *task, - struct rspamd_action *action, guint priority, - double target_score, const gchar *message, - const gchar *module, guint flags, + struct rspamd_action *action, unsigned int priority, + double target_score, const char *message, + const char *module, unsigned int flags, struct rspamd_scan_result *scan_result); enum rspamd_symbol_insert_flags { @@ -165,9 +165,9 @@ enum rspamd_symbol_insert_flags { * @param opts list of symbol's options */ struct rspamd_symbol_result *rspamd_task_insert_result_full(struct rspamd_task *task, - const gchar *symbol, + const char *symbol, double weight, - const gchar *opts, + const char *opts, enum rspamd_symbol_insert_flags flags, struct rspamd_scan_result *result); @@ -185,7 +185,7 @@ struct rspamd_symbol_result *rspamd_task_insert_result_full(struct rspamd_task * */ struct rspamd_symbol_result *rspamd_task_remove_symbol_result( struct rspamd_task *task, - const gchar *symbol, + const char *symbol, struct rspamd_scan_result *result); /** * Adds new option to symbol @@ -195,7 +195,7 @@ struct rspamd_symbol_result *rspamd_task_remove_symbol_result( */ gboolean rspamd_task_add_result_option(struct rspamd_task *task, struct rspamd_symbol_result *s, - const gchar *opt, + const char *opt, gsize vlen); /** @@ -227,8 +227,8 @@ void rspamd_task_symbol_result_foreach(struct rspamd_task *task, * @return result metric weight */ double rspamd_factor_consolidation_func(struct rspamd_task *task, - const gchar *metric_name, - const gchar *unused); + const char *metric_name, + const char *unused); /** diff --git a/src/libmime/smtp_parsers.h b/src/libmime/smtp_parsers.h index e88c2bf54..79d15903a 100644 --- a/src/libmime/smtp_parsers.h +++ b/src/libmime/smtp_parsers.h @@ -35,9 +35,9 @@ gboolean rspamd_content_disposition_parser(const char *data, size_t len, rspamd_mempool_t *pool); gboolean -rspamd_rfc2047_parser(const gchar *in, gsize len, gint *pencoding, - const gchar **charset, gsize *charset_len, - const gchar **encoded, gsize *encoded_len); +rspamd_rfc2047_parser(const char *in, gsize len, int *pencoding, + const char **charset, gsize *charset_len, + const char **encoded, gsize *encoded_len); rspamd_inet_addr_t *rspamd_parse_smtp_ip(const char *data, size_t len, rspamd_mempool_t *pool); diff --git a/src/libserver/async_session.c b/src/libserver/async_session.c index d12f95550..9f87ffd33 100644 --- a/src/libserver/async_session.c +++ b/src/libserver/async_session.c @@ -49,8 +49,8 @@ static struct rspamd_counter_data events_count; struct rspamd_async_event { - const gchar *subsystem; - const gchar *event_source; + const char *subsystem; + const char *event_source; event_finalizer_t fin; void *user_data; }; @@ -94,7 +94,7 @@ struct rspamd_async_session { khash_t(rspamd_events_hash) * events; void *user_data; rspamd_mempool_t *pool; - guint flags; + unsigned int flags; }; static void @@ -134,11 +134,11 @@ struct rspamd_async_event * rspamd_session_add_event_full(struct rspamd_async_session *session, event_finalizer_t fin, gpointer user_data, - const gchar *subsystem, - const gchar *event_source) + const char *subsystem, + const char *event_source) { struct rspamd_async_event *new_event; - gint ret; + int ret; if (session == NULL) { msg_err("session is NULL"); @@ -176,7 +176,7 @@ rspamd_session_add_event_full(struct rspamd_async_session *session, void rspamd_session_remove_event_full(struct rspamd_async_session *session, event_finalizer_t fin, void *ud, - const gchar *event_source) + const char *event_source) { struct rspamd_async_event search_ev, *found_ev; khiter_t k; @@ -335,9 +335,9 @@ rspamd_session_pending(struct rspamd_async_session *session) return ret; } -guint rspamd_session_events_pending(struct rspamd_async_session *session) +unsigned int rspamd_session_events_pending(struct rspamd_async_session *session) { - guint npending; + unsigned int npending; g_assert(session != NULL); diff --git a/src/libserver/async_session.h b/src/libserver/async_session.h index 4573545f1..e4b9feb08 100644 --- a/src/libserver/async_session.h +++ b/src/libserver/async_session.h @@ -54,8 +54,8 @@ struct rspamd_async_event * rspamd_session_add_event_full(struct rspamd_async_session *session, event_finalizer_t fin, gpointer user_data, - const gchar *subsystem, - const gchar *event_source); + const char *subsystem, + const char *event_source); #define rspamd_session_add_event(session, fin, user_data, subsystem) \ rspamd_session_add_event_full(session, fin, user_data, subsystem, G_STRLOC) @@ -69,7 +69,7 @@ rspamd_session_add_event_full(struct rspamd_async_session *session, void rspamd_session_remove_event_full(struct rspamd_async_session *session, event_finalizer_t fin, gpointer ud, - const gchar *event_source); + const char *event_source); #define rspamd_session_remove_event(session, fin, user_data) \ rspamd_session_remove_event_full(session, fin, user_data, G_STRLOC) @@ -104,7 +104,7 @@ gboolean rspamd_session_pending(struct rspamd_async_session *session); * @param session * @return */ -guint rspamd_session_events_pending(struct rspamd_async_session *session); +unsigned int rspamd_session_events_pending(struct rspamd_async_session *session); /** diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 3e9feaced..a1ede5669 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -71,8 +71,8 @@ enum rspamd_log_cfg_flags { }; struct rspamd_worker_log_pipe { - gint fd; - gint type; + int fd; + int type; struct rspamd_worker_log_pipe *prev, *next; }; @@ -80,9 +80,9 @@ struct rspamd_worker_log_pipe { * script module list item */ struct script_module { - gchar *name; /**< name of module */ - gchar *path; /**< path to module */ - gchar *digest; + char *name; /**< name of module */ + char *path; /**< path to module */ + char *digest; }; enum rspamd_symbol_group_flags { @@ -98,11 +98,11 @@ enum rspamd_symbol_group_flags { */ struct rspamd_symbol; struct rspamd_symbols_group { - gchar *name; - gchar *description; + char *name; + char *description; GHashTable *symbols; - gdouble max_score; - guint flags; + double max_score; + unsigned int flags; }; enum rspamd_symbol_flags { @@ -118,24 +118,24 @@ enum rspamd_symbol_flags { * Symbol config definition */ struct rspamd_symbol { - gchar *name; - gchar *description; - gdouble *weight_ptr; - gdouble score; - guint priority; + char *name; + char *description; + double *weight_ptr; + double score; + unsigned int priority; struct rspamd_symbols_group *gr; /* Main group */ GPtrArray *groups; /* Other groups */ - guint flags; + unsigned int flags; void *cache_item; - gint nshots; + int nshots; }; /** * Statfile config definition */ struct rspamd_statfile_config { - gchar *symbol; /**< symbol of statfile */ - gchar *label; /**< label of this statfile */ + char *symbol; /**< symbol of statfile */ + char *label; /**< label of this statfile */ ucl_object_t *opts; /**< other options */ gboolean is_spam; /**< spam flag */ struct rspamd_classifier_config *clcf; /**< parent pointer of classifier configuration */ @@ -144,7 +144,7 @@ struct rspamd_statfile_config { struct rspamd_tokenizer_config { const ucl_object_t *opts; /**< other options */ - const gchar *name; /**< name of tokenizer */ + const char *name; /**< name of tokenizer */ }; @@ -166,33 +166,33 @@ struct rspamd_tokenizer_config { struct rspamd_classifier_config { GList *statfiles; /**< statfiles list */ GHashTable *labels; /**< statfiles with labels */ - gchar *metric; /**< metric of this classifier */ - gchar *classifier; /**< classifier interface */ + char *metric; /**< metric of this classifier */ + char *classifier; /**< classifier interface */ struct rspamd_tokenizer_config *tokenizer; /**< tokenizer used for classifier */ - const gchar *backend; /**< name of statfile's backend */ + const char *backend; /**< name of statfile's backend */ ucl_object_t *opts; /**< other options */ GList *learn_conditions; /**< list of learn condition callbacks */ GList *classify_conditions; /**< list of classify condition callbacks */ - gchar *name; /**< unique name of classifier */ + char *name; /**< unique name of classifier */ uint32_t min_tokens; /**< minimal number of tokens to process classifier */ uint32_t max_tokens; /**< maximum number of tokens */ - guint min_token_hits; /**< minimum number of hits for a token to be considered */ - gdouble min_prob_strength; /**< use only tokens with probability in [0.5 - MPS, 0.5 + MPS] */ - guint min_learns; /**< minimum number of learns for each statfile */ - guint flags; + unsigned int min_token_hits; /**< minimum number of hits for a token to be considered */ + double min_prob_strength; /**< use only tokens with probability in [0.5 - MPS, 0.5 + MPS] */ + unsigned int min_learns; /**< minimum number of learns for each statfile */ + unsigned int flags; }; struct rspamd_worker_bind_conf { GPtrArray *addrs; - guint cnt; - gchar *name; - gchar *bind_line; + unsigned int cnt; + char *name; + char *bind_line; gboolean is_systemd; struct rspamd_worker_bind_conf *next; }; struct rspamd_worker_lua_script { - gint cbref; + int cbref; struct rspamd_worker_lua_script *prev, *next; }; @@ -203,7 +203,7 @@ struct rspamd_worker_conf { struct worker_s *worker; /**< pointer to worker type */ GQuark type; /**< type of worker */ struct rspamd_worker_bind_conf *bind_conf; /**< bind configuration */ - gint16 count; /**< number of workers */ + int16_t count; /**< number of workers */ GList *listen_socks; /**< listening sockets descriptors */ uint64_t rlimit_nofile; /**< max files limit */ uint64_t rlimit_maxcore; /**< maximum core file size */ @@ -258,7 +258,7 @@ enum rspamd_log_format_flags { struct rspamd_log_format { enum rspamd_log_format_type type; - guint flags; + unsigned int flags; gsize len; gpointer data; struct rspamd_log_format *prev, *next; @@ -292,14 +292,14 @@ enum rspamd_action_flags { struct rspamd_action; struct rspamd_config_cfg_lua_script { - gint cbref; - gint priority; - gchar *lua_src_pos; + int cbref; + int priority; + char *lua_src_pos; struct rspamd_config_cfg_lua_script *prev, *next; }; struct rspamd_config_post_init_script { - gint cbref; + int cbref; struct rspamd_config_post_init_script *prev, *next; }; @@ -321,7 +321,7 @@ enum rspamd_gtube_patterns_policy { struct rspamd_config_settings_elt { uint32_t id; enum rspamd_config_settings_policy policy; - const gchar *name; + const char *name; ucl_object_t *symbols_enabled; ucl_object_t *symbols_disabled; struct rspamd_config_settings_elt *prev, *next; @@ -332,23 +332,23 @@ struct rspamd_config_settings_elt { * Structure that stores all config data */ struct rspamd_config { - gchar *rspamd_user; /**< user to run as */ - gchar *rspamd_group; /**< group to run as */ + char *rspamd_user; /**< user to run as */ + char *rspamd_group; /**< group to run as */ rspamd_mempool_t *cfg_pool; /**< memory pool for config */ - gchar *cfg_name; /**< name of config file */ - gchar *pid_file; /**< name of pid file */ - gchar *temp_dir; /**< dir for temp files */ - gchar *control_socket_path; /**< path to the control socket */ + char *cfg_name; /**< name of config file */ + char *pid_file; /**< name of pid file */ + char *temp_dir; /**< dir for temp files */ + char *control_socket_path; /**< path to the control socket */ const ucl_object_t *local_addrs; /**< tree of local addresses */ #ifdef WITH_GPERF_TOOLS - gchar *profile_path; + char *profile_path; #endif - gdouble unknown_weight; /**< weight of unknown symbols */ - gdouble grow_factor; /**< grow factor for metric */ - GHashTable *symbols; /**< weights of symbols in metric */ - const gchar *subject; /**< subject rewrite string */ - GHashTable *groups; /**< groups of symbols */ - void *actions; /**< all actions of the metric (opaque type) */ + double unknown_weight; /**< weight of unknown symbols */ + double grow_factor; /**< grow factor for metric */ + GHashTable *symbols; /**< weights of symbols in metric */ + const char *subject; /**< subject rewrite string */ + GHashTable *groups; /**< groups of symbols */ + void *actions; /**< all actions of the metric (opaque type) */ gboolean one_shot_mode; /**< rules add only one symbol */ gboolean check_text_attachements; /**< check text attachements as text */ @@ -369,19 +369,19 @@ struct rspamd_config { gsize max_cores_size; /**< maximum size occupied by rspamd core files */ gsize max_cores_count; /**< maximum number of core files */ - gchar *cores_dir; /**< directory for core files */ + char *cores_dir; /**< directory for core files */ gsize max_message; /**< maximum size for messages */ gsize max_pic_size; /**< maximum size for a picture to process */ gsize images_cache_size; /**< size of LRU cache for DCT data from images */ - gdouble task_timeout; /**< maximum message processing time */ - gint default_max_shots; /**< default maximum count of symbols hits permitted (-1 for unlimited) */ + double task_timeout; /**< maximum message processing time */ + int default_max_shots; /**< default maximum count of symbols hits permitted (-1 for unlimited) */ int32_t heartbeats_loss_max; /**< number of heartbeats lost to consider worker's termination */ - gdouble heartbeat_interval; /**< interval for heartbeats for workers */ + double heartbeat_interval; /**< interval for heartbeats for workers */ enum rspamd_log_type log_type; /**< log type */ - gint log_facility; /**< log facility in case of syslog */ - gint log_level; /**< log level trigger */ - gchar *log_file; /**< path to logfile in case of file logging */ + int log_facility; /**< log facility in case of syslog */ + int log_level; /**< log level trigger */ + char *log_file; /**< path to logfile in case of file logging */ gboolean log_buffered; /**< whether logging is buffered */ gboolean log_silent_workers; /**< silence info messages from workers */ uint32_t log_buf_size; /**< length of log buffer */ @@ -389,10 +389,10 @@ struct rspamd_config { gboolean log_urls; /**< whether we should log URLs */ GHashTable *debug_modules; /**< logging modules to debug */ struct rspamd_cryptobox_pubkey *log_encryption_key; /**< encryption key for logs */ - guint log_flags; /**< logging flags */ - guint log_error_elts; /**< number of elements in error logbuf */ - guint log_error_elt_maxlen; /**< maximum size of error log element */ - guint log_task_max_elts; /**< maximum number of elements in task logging */ + unsigned int log_flags; /**< logging flags */ + unsigned int log_error_elts; /**< number of elements in error logbuf */ + unsigned int log_error_elt_maxlen; /**< maximum size of error log element */ + unsigned int log_task_max_elts; /**< maximum number of elements in task logging */ struct rspamd_worker_log_pipe *log_pipes; gboolean compat_messages; /**< use old messages in the protocol (array) */ @@ -412,66 +412,66 @@ struct rspamd_config { GList *statfiles; /**< list of all statfiles in config file order */ GHashTable *classifiers_symbols; /**< hashtable indexed by symbol name of classifiers */ GHashTable *cfg_params; /**< all cfg params indexed by its name in this structure */ - gchar *dynamic_conf; /**< path to dynamic configuration */ + char *dynamic_conf; /**< path to dynamic configuration */ ucl_object_t *current_dynamic_conf; /**< currently loaded dynamic configuration */ - gint clock_res; /**< resolution of clock used */ + int clock_res; /**< resolution of clock used */ - GList *maps; /**< maps active */ - gdouble map_timeout; /**< maps watch timeout */ - gdouble map_file_watch_multiplier; /**< multiplier for watch timeout when maps are files */ - gchar *maps_cache_dir; /**< where to save HTTP cached data */ + GList *maps; /**< maps active */ + double map_timeout; /**< maps watch timeout */ + double map_file_watch_multiplier; /**< multiplier for watch timeout when maps are files */ + char *maps_cache_dir; /**< where to save HTTP cached data */ - gdouble monitored_interval; /**< interval between monitored checks */ + double monitored_interval; /**< interval between monitored checks */ gboolean disable_monitored; /**< disable monitoring completely */ gboolean fips_mode; /**< turn on fips mode for openssl */ struct rspamd_symcache *cache; /**< symbols cache object */ - gchar *cache_filename; /**< filename of cache file */ - gdouble cache_reload_time; /**< how often cache reload should be performed */ - gchar *checksum; /**< real checksum of config file */ + char *cache_filename; /**< filename of cache file */ + double cache_reload_time; /**< how often cache reload should be performed */ + char *checksum; /**< real checksum of config file */ gpointer lua_state; /**< pointer to lua state */ gpointer lua_thread_pool; /**< pointer to lua thread (coroutine) pool */ - gchar *rrd_file; /**< rrd file to store statistics */ - gchar *history_file; /**< file to save rolling history */ - gchar *stats_file; /**< file to save stats */ - gchar *tld_file; /**< file to load effective tld list from */ - gchar *hs_cache_dir; /**< directory to save hyperscan databases */ - gchar *events_backend; /**< string representation of the events backend used */ + char *rrd_file; /**< rrd file to store statistics */ + char *history_file; /**< file to save rolling history */ + char *stats_file; /**< file to save stats */ + char *tld_file; /**< file to load effective tld list from */ + char *hs_cache_dir; /**< directory to save hyperscan databases */ + char *events_backend; /**< string representation of the events backend used */ - gdouble dns_timeout; /**< timeout in milliseconds for waiting for dns reply */ + double dns_timeout; /**< timeout in milliseconds for waiting for dns reply */ uint32_t dns_retransmits; /**< maximum retransmits count */ uint32_t dns_io_per_server; /**< number of sockets per DNS server */ const ucl_object_t *nameservers; /**< list of nameservers or NULL to parse resolv.conf */ uint32_t dns_max_requests; /**< limit of DNS requests per task */ gboolean enable_dnssec; /**< enable dnssec stub resolver */ - guint upstream_max_errors; /**< upstream max errors before shutting off */ - gdouble upstream_error_time; /**< rate of upstream errors */ - gdouble upstream_revive_time; /**< revive timeout for upstreams */ - gdouble upstream_lazy_resolve_time; /**< lazy resolve time for upstreams */ + unsigned int upstream_max_errors; /**< upstream max errors before shutting off */ + double upstream_error_time; /**< rate of upstream errors */ + double upstream_revive_time; /**< revive timeout for upstreams */ + double upstream_lazy_resolve_time; /**< lazy resolve time for upstreams */ struct upstream_ctx *ups_ctx; /**< upstream context */ struct rspamd_dns_resolver *dns_resolver; /**< dns resolver if loaded */ - guint min_word_len; /**< minimum length of the word to be considered */ - guint max_word_len; /**< maximum length of the word to be considered */ - guint words_decay; /**< limit for words for starting adaptive ignoring */ - guint history_rows; /**< number of history rows stored */ - guint max_sessions_cache; /**< maximum number of sessions cache elts */ - guint lua_gc_step; /**< lua gc step */ - guint lua_gc_pause; /**< lua gc pause */ - guint full_gc_iters; /**< iterations between full gc cycle */ - guint max_lua_urls; /**< maximum number of urls to be passed to Lua */ - guint max_urls; /**< maximum number of urls to be processed in general */ - gint max_recipients; /**< maximum number of recipients to be processed */ - guint max_blas_threads; /**< maximum threads for openblas when learning ANN */ - guint max_opts_len; /**< maximum length for all options for a symbol */ - gsize max_html_len; /**< maximum length of HTML document */ + unsigned int min_word_len; /**< minimum length of the word to be considered */ + unsigned int max_word_len; /**< maximum length of the word to be considered */ + unsigned int words_decay; /**< limit for words for starting adaptive ignoring */ + unsigned int history_rows; /**< number of history rows stored */ + unsigned int max_sessions_cache; /**< maximum number of sessions cache elts */ + unsigned int lua_gc_step; /**< lua gc step */ + unsigned int lua_gc_pause; /**< lua gc pause */ + unsigned int full_gc_iters; /**< iterations between full gc cycle */ + unsigned int max_lua_urls; /**< maximum number of urls to be passed to Lua */ + unsigned int max_urls; /**< maximum number of urls to be processed in general */ + int max_recipients; /**< maximum number of recipients to be processed */ + unsigned int max_blas_threads; /**< maximum threads for openblas when learning ANN */ + unsigned int max_opts_len; /**< maximum length for all options for a symbol */ + gsize max_html_len; /**< maximum length of HTML document */ struct module_s **compiled_modules; /**< list of compiled C modules */ struct worker_s **compiled_workers; /**< list of compiled C modules */ struct rspamd_log_format *log_format; /**< parsed log format */ - gchar *log_format_str; /**< raw log format string */ + char *log_format_str; /**< raw log format string */ struct rspamd_external_libs_ctx *libs_ctx; /**< context for external libraries */ struct rspamd_monitored_ctx *monitored_ctx; /**< context for monitored resources */ @@ -486,11 +486,11 @@ struct rspamd_config { struct rspamd_config_cfg_lua_script *on_term_scripts; /**< list of callbacks called on worker's termination */ struct rspamd_config_cfg_lua_script *config_unload_scripts; /**< list of scripts executed on config unload */ - gchar *ssl_ca_path; /**< path to CA certs */ - gchar *ssl_ciphers; /**< set of preferred ciphers */ - gchar *zstd_input_dictionary; /**< path to zstd input dictionary */ - gchar *zstd_output_dictionary; /**< path to zstd output dictionary */ - ucl_object_t *neighbours; /**< other servers in the cluster */ + char *ssl_ca_path; /**< path to CA certs */ + char *ssl_ciphers; /**< set of preferred ciphers */ + char *zstd_input_dictionary; /**< path to zstd input dictionary */ + char *zstd_output_dictionary; /**< path to zstd output dictionary */ + ucl_object_t *neighbours; /**< other servers in the cluster */ struct rspamd_config_settings_elt *setting_ids; /**< preprocessed settings ids */ struct rspamd_lang_detector *lang_det; /**< language detector */ @@ -508,7 +508,7 @@ struct rspamd_config { * @return 1 if line was successfully parsed and 0 in case of error */ gboolean rspamd_parse_bind_line(struct rspamd_config *cfg, - struct rspamd_worker_conf *cf, const gchar *str); + struct rspamd_worker_conf *cf, const char *str); enum rspamd_config_init_flags { @@ -537,8 +537,8 @@ void rspamd_config_free(struct rspamd_config *cfg); * @return module value or NULL if option does not defined */ const ucl_object_t *rspamd_config_get_module_opt(struct rspamd_config *cfg, - const gchar *module_name, - const gchar *opt_name) G_GNUC_WARN_UNUSED_RESULT; + const char *module_name, + const char *opt_name) G_GNUC_WARN_UNUSED_RESULT; /** @@ -546,7 +546,7 @@ const ucl_object_t *rspamd_config_get_module_opt(struct rspamd_config *cfg, * @param str string representation of flag (eg. 'on') * @return numeric value of flag (0 or 1) */ -gint rspamd_config_parse_flag(const gchar *str, guint len); +int rspamd_config_parse_flag(const char *str, unsigned int len); enum rspamd_post_load_options { RSPAMD_CONFIG_INIT_URL = 1 << 0, @@ -595,7 +595,7 @@ void rspamd_config_init_metric(struct rspamd_config *cfg); */ struct rspamd_symbols_group *rspamd_config_new_group( struct rspamd_config *cfg, - const gchar *name); + const char *name); /* * Return a new statfile structure, setting default and non-conflicting attributes @@ -619,7 +619,7 @@ gboolean rspamd_config_check_statfiles(struct rspamd_classifier_config *cf); */ struct rspamd_classifier_config *rspamd_config_find_classifier( struct rspamd_config *cfg, - const gchar *name); + const char *name); void rspamd_ucl_add_conf_macros(struct ucl_parser *parser, struct rspamd_config *cfg); @@ -649,13 +649,13 @@ gboolean rspamd_init_filters(struct rspamd_config *cfg, bool reconfig, bool stri * @return TRUE if symbol has been inserted or FALSE if symbol already exists with higher priority */ gboolean rspamd_config_add_symbol(struct rspamd_config *cfg, - const gchar *symbol, - gdouble score, - const gchar *description, - const gchar *group, - guint flags, - guint priority, - gint nshots); + const char *symbol, + double score, + const char *description, + const char *group, + unsigned int flags, + unsigned int priority, + int nshots); /** * Adds new group for a symbol @@ -665,8 +665,8 @@ gboolean rspamd_config_add_symbol(struct rspamd_config *cfg, * @return */ gboolean rspamd_config_add_symbol_group(struct rspamd_config *cfg, - const gchar *symbol, - const gchar *group); + const char *symbol, + const char *group); /** * Sets action score for a specified metric with the specified priority @@ -677,7 +677,7 @@ gboolean rspamd_config_add_symbol_group(struct rspamd_config *cfg, * @return TRUE if symbol has been inserted or FALSE if action already exists with higher priority */ gboolean rspamd_config_set_action_score(struct rspamd_config *cfg, - const gchar *action_name, + const char *action_name, const ucl_object_t *obj); /** @@ -688,8 +688,8 @@ gboolean rspamd_config_set_action_score(struct rspamd_config *cfg, * @return */ gboolean rspamd_config_maybe_disable_action(struct rspamd_config *cfg, - const gchar *action_name, - guint priority); + const char *action_name, + unsigned int priority); /** * Checks if a specified C or lua module is enabled or disabled in the config. @@ -705,7 +705,7 @@ gboolean rspamd_config_maybe_disable_action(struct rspamd_config *cfg, * @return TRUE if a module is enabled */ gboolean rspamd_config_is_module_enabled(struct rspamd_config *cfg, - const gchar *module_name); + const char *module_name); /** * Verifies enabled/disabled combination in the specified object @@ -718,14 +718,14 @@ gboolean rspamd_config_is_enabled_from_ucl(rspamd_mempool_t *pool, /* * Get action from a string */ -gboolean rspamd_action_from_str(const gchar *data, enum rspamd_action_type *result); +gboolean rspamd_action_from_str(const char *data, enum rspamd_action_type *result); /* * Return textual representation of action enumeration */ -const gchar *rspamd_action_to_str(enum rspamd_action_type action); +const char *rspamd_action_to_str(enum rspamd_action_type action); -const gchar *rspamd_action_to_str_alt(enum rspamd_action_type action); +const char *rspamd_action_to_str_alt(enum rspamd_action_type action); /** * Parse radix tree or radix map from ucl object @@ -737,9 +737,9 @@ const gchar *rspamd_action_to_str_alt(enum rspamd_action_type action); */ struct rspamd_radix_map_helper; -gboolean rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const gchar *description, +gboolean rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const char *description, struct rspamd_radix_map_helper **target, GError **err, - struct rspamd_worker *worker, const gchar *map_name); + struct rspamd_worker *worker, const char *map_name); /** * Adds new settings id to be preprocessed @@ -749,7 +749,7 @@ gboolean rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_objec * @param symbols_disabled (ownership is transferred to callee) */ void rspamd_config_register_settings_id(struct rspamd_config *cfg, - const gchar *name, + const char *name, ucl_object_t *symbols_enabled, ucl_object_t *symbols_disabled, enum rspamd_config_settings_policy policy); @@ -760,7 +760,7 @@ void rspamd_config_register_settings_id(struct rspamd_config *cfg, * @param namelen * @return */ -uint32_t rspamd_config_name_to_id(const gchar *name, gsize namelen); +uint32_t rspamd_config_name_to_id(const char *name, gsize namelen); /** * Finds settings id element and obtain reference count (must be unrefed by caller) @@ -780,7 +780,7 @@ struct rspamd_config_settings_elt *rspamd_config_find_settings_id_ref( */ struct rspamd_config_settings_elt *rspamd_config_find_settings_name_ref( struct rspamd_config *cfg, - const gchar *name, gsize namelen); + const char *name, gsize namelen); /** * Returns action object by name @@ -789,7 +789,7 @@ struct rspamd_config_settings_elt *rspamd_config_find_settings_name_ref( * @return */ struct rspamd_action *rspamd_config_get_action(struct rspamd_config *cfg, - const gchar *name); + const char *name); struct rspamd_action *rspamd_config_get_action_by_type(struct rspamd_config *cfg, enum rspamd_action_type type); @@ -821,7 +821,7 @@ void rspamd_config_actions_foreach_enumerate(struct rspamd_config *cfg, gsize rspamd_config_actions_size(struct rspamd_config *cfg); int rspamd_config_ev_backend_get(struct rspamd_config *cfg); -const gchar *rspamd_config_ev_backend_to_string(int ev_backend, gboolean *effective); +const char *rspamd_config_ev_backend_to_string(int ev_backend, gboolean *effective); struct rspamd_external_libs_ctx; @@ -864,9 +864,9 @@ gboolean rspamd_config_libs(struct rspamd_external_libs_ctx *ctx, cfg->cfg_pool->tag.tagname, cfg->checksum, \ RSPAMD_LOG_FUNC, \ __VA_ARGS__) -#define msg_err_config_forced(...) rspamd_default_log_function((gint) G_LOG_LEVEL_CRITICAL | (gint) RSPAMD_LOG_FORCED, \ - cfg->cfg_pool->tag.tagname, cfg->checksum, \ - RSPAMD_LOG_FUNC, \ +#define msg_err_config_forced(...) rspamd_default_log_function((int) G_LOG_LEVEL_CRITICAL | (int) RSPAMD_LOG_FORCED, \ + cfg->cfg_pool->tag.tagname, cfg->checksum, \ + RSPAMD_LOG_FUNC, \ __VA_ARGS__) #define msg_warn_config(...) rspamd_default_log_function(G_LOG_LEVEL_WARNING, \ cfg->cfg_pool->tag.tagname, cfg->checksum, \ @@ -876,7 +876,7 @@ gboolean rspamd_config_libs(struct rspamd_external_libs_ctx *ctx, cfg->cfg_pool->tag.tagname, cfg->checksum, \ RSPAMD_LOG_FUNC, \ __VA_ARGS__) -extern guint rspamd_config_log_id; +extern unsigned int rspamd_config_log_id; #define msg_debug_config(...) rspamd_conditional_debug_fast(NULL, NULL, \ rspamd_config_log_id, "config", cfg->checksum, \ RSPAMD_LOG_FUNC, \ diff --git a/src/libserver/cfg_file_private.h b/src/libserver/cfg_file_private.h index 8c9fc6539..f190c73f9 100644 --- a/src/libserver/cfg_file_private.h +++ b/src/libserver/cfg_file_private.h @@ -29,9 +29,9 @@ extern "C" { struct rspamd_action { enum rspamd_action_type action_type; int flags; /* enum rspamd_action_flags */ - guint priority; - gdouble threshold; - gchar *name; + unsigned int priority; + double threshold; + char *name; }; #ifdef __cplusplus diff --git a/src/libserver/cfg_rcl.cxx b/src/libserver/cfg_rcl.cxx index 6addd6020..4feb55de0 100644 --- a/src/libserver/cfg_rcl.cxx +++ b/src/libserver/cfg_rcl.cxx @@ -95,7 +95,7 @@ struct rspamd_worker_cfg_parser { ankerl::unordered_dense::map, rspamd_worker_param_parser, pair_hash> parsers; /**< parsers hash */ - gint type; /**< workers quark */ + int type; /**< workers quark */ gboolean (*def_obj_parser)(ucl_object_t *obj, gpointer ud); /**< default object parser */ gpointer def_ud; }; @@ -122,11 +122,11 @@ rspamd_rcl_section_parse_defaults(struct rspamd_config *cfg, */ static gboolean rspamd_rcl_logging_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, gpointer ud, struct rspamd_rcl_section *section, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) { const ucl_object_t *val; - const gchar *facility = nullptr, *log_type = nullptr, *log_level = nullptr; + const char *facility = nullptr, *log_type = nullptr, *log_level = nullptr; auto *cfg = (struct rspamd_config *) ud; val = ucl_object_lookup(obj, "type"); @@ -305,7 +305,7 @@ rspamd_rcl_logging_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, static gboolean rspamd_rcl_options_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, gpointer ud, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) { const ucl_object_t *dns, *upstream, *neighbours; @@ -402,7 +402,7 @@ struct rspamd_rcl_symbol_data { static gboolean rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, gpointer ud, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) { auto *cfg = static_cast(ud); @@ -523,16 +523,16 @@ rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, static gboolean rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, gpointer ud, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) { auto *sd = static_cast(ud); struct rspamd_config *cfg; const ucl_object_t *elt; - const gchar *description = nullptr; - gdouble score = NAN; - guint priority = 1, flags = 0; - gint nshots = 0; + const char *description = nullptr; + double score = NAN; + unsigned int priority = 1, flags = 0; + int nshots = 0; g_assert(key != nullptr); cfg = sd->cfg; @@ -697,7 +697,7 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, static gboolean rspamd_rcl_actions_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, gpointer ud, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) { auto *cfg = static_cast(ud); @@ -707,7 +707,7 @@ rspamd_rcl_actions_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, it = ucl_object_iterate_new(obj); while ((cur = ucl_object_iterate_safe(it, true)) != nullptr) { - gint type = ucl_object_type(cur); + int type = ucl_object_type(cur); if (type == UCL_NULL) { rspamd_config_maybe_disable_action(cfg, ucl_object_key(cur), @@ -759,7 +759,7 @@ constexpr const auto known_worker_attributes = frozen::make_unordered_set(ud); @@ -883,7 +883,7 @@ rspamd_rcl_worker_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, static gboolean rspamd_rcl_lua_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, gpointer ud, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) { namespace fs = std::filesystem; @@ -973,7 +973,7 @@ rspamd_lua_mod_sort_fn(gconstpointer a, gconstpointer b) gboolean rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections, struct rspamd_config *cfg, - const gchar *path, + const char *path, gboolean main_path, GError **err) { @@ -1040,7 +1040,7 @@ rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections, static gboolean rspamd_rcl_modules_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, gpointer ud, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) { auto *cfg = static_cast(ud); @@ -1134,7 +1134,7 @@ struct statfile_parser_data { static gboolean rspamd_rcl_statfile_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, gpointer ud, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) { auto *stud = (struct statfile_parser_data *) ud; @@ -1211,7 +1211,7 @@ rspamd_rcl_statfile_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, static gboolean rspamd_rcl_classifier_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) @@ -1305,9 +1305,9 @@ rspamd_rcl_classifier_handler(rspamd_mempool_t *pool, LL_FOREACH(val, cur) { if (ucl_object_type(cur) == UCL_STRING) { - const gchar *lua_script; + const char *lua_script; gsize slen; - gint ref_idx; + int ref_idx; lua_script = ucl_object_tolstring(cur, &slen); ref_idx = rspamd_lua_function_ref_from_str(RSPAMD_LUA_CFG_STATE(cfg), @@ -1333,9 +1333,9 @@ rspamd_rcl_classifier_handler(rspamd_mempool_t *pool, LL_FOREACH(val, cur) { if (ucl_object_type(cur) == UCL_STRING) { - const gchar *lua_script; + const char *lua_script; gsize slen; - gint ref_idx; + int ref_idx; lua_script = ucl_object_tolstring(cur, &slen); ref_idx = rspamd_lua_function_ref_from_str(RSPAMD_LUA_CFG_STATE(cfg), @@ -1363,14 +1363,14 @@ rspamd_rcl_classifier_handler(rspamd_mempool_t *pool, static gboolean rspamd_rcl_composite_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) { auto *cfg = static_cast(ud); void *composite; - const gchar *composite_name; + const char *composite_name; g_assert(key != nullptr); @@ -1394,7 +1394,7 @@ rspamd_rcl_composite_handler(rspamd_mempool_t *pool, static gboolean rspamd_rcl_composites_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) @@ -1420,14 +1420,14 @@ rspamd_rcl_composites_handler(rspamd_mempool_t *pool, static gboolean rspamd_rcl_neighbours_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err) { auto *cfg = static_cast(ud); auto has_port = FALSE, has_proto = FALSE; - const gchar *p; + const char *p; if (key == nullptr) { g_set_error(err, @@ -1493,7 +1493,7 @@ rspamd_rcl_neighbours_handler(rspamd_mempool_t *pool, struct rspamd_rcl_section * rspamd_rcl_add_section(struct rspamd_rcl_sections_map **top, struct rspamd_rcl_section *parent_section, - const gchar *name, const gchar *key_attr, rspamd_rcl_handler_t handler, + const char *name, const char *key_attr, rspamd_rcl_handler_t handler, enum ucl_type type, gboolean required, gboolean strict_type) { return rspamd_rcl_add_section_doc(top, parent_section, name, key_attr, handler, @@ -1503,10 +1503,10 @@ rspamd_rcl_add_section(struct rspamd_rcl_sections_map **top, struct rspamd_rcl_section * rspamd_rcl_add_section_doc(struct rspamd_rcl_sections_map **top, struct rspamd_rcl_section *parent_section, - const gchar *name, const gchar *key_attr, rspamd_rcl_handler_t handler, + const char *name, const char *key_attr, rspamd_rcl_handler_t handler, enum ucl_type type, gboolean required, gboolean strict_type, ucl_object_t *doc_target, - const gchar *doc_string) + const char *doc_string) { if (top == nullptr) { g_error("invalid arguments to rspamd_rcl_add_section"); @@ -1581,11 +1581,11 @@ rspamd_rcl_add_section_doc(struct rspamd_rcl_sections_map **top, struct rspamd_rcl_default_handler_data * rspamd_rcl_add_default_handler(struct rspamd_rcl_section *section, - const gchar *name, + const char *name, rspamd_rcl_default_handler_t handler, goffset offset, - gint flags, - const gchar *doc_string) + int flags, + const char *doc_string) { auto it = section->default_parser.emplace(std::make_pair(std::string{name}, rspamd_rcl_default_handler_data{})); @@ -2529,7 +2529,7 @@ rspamd_rcl_process_section(struct rspamd_config *cfg, ucl_object_iter_t it; const ucl_object_t *cur; auto is_nested = true; - const gchar *key = nullptr; + const char *key = nullptr; if (sec.processed) { /* Section has been already processed */ @@ -2746,22 +2746,22 @@ rspamd_rcl_parse_struct_string(rspamd_mempool_t *pool, auto *pd = (struct rspamd_rcl_struct_parser *) ud; const gsize num_str_len = 32; - auto target = (gchar **) (((gchar *) pd->user_struct) + pd->offset); + auto target = (char **) (((char *) pd->user_struct) + pd->offset); switch (obj->type) { case UCL_STRING: *target = rspamd_mempool_strdup(pool, ucl_copy_value_trash(obj)); break; case UCL_INT: - *target = (gchar *) rspamd_mempool_alloc(pool, num_str_len); + *target = (char *) rspamd_mempool_alloc(pool, num_str_len); rspamd_snprintf(*target, num_str_len, "%L", obj->value.iv); break; case UCL_FLOAT: - *target = (gchar *) rspamd_mempool_alloc(pool, num_str_len); + *target = (char *) rspamd_mempool_alloc(pool, num_str_len); rspamd_snprintf(*target, num_str_len, "%f", obj->value.dv); break; case UCL_BOOLEAN: - *target = (gchar *) rspamd_mempool_alloc(pool, num_str_len); + *target = (char *) rspamd_mempool_alloc(pool, num_str_len); rspamd_snprintf(*target, num_str_len, "%s", ((gboolean) obj->value.iv) ? "true" : "false"); break; @@ -2791,17 +2791,17 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, { auto *pd = (struct rspamd_rcl_struct_parser *) ud; union { - gint *ip; + int *ip; int32_t *i32p; - gint16 *i16p; + int16_t *i16p; int64_t *i64p; - guint *up; + unsigned int *up; gsize *sp; } target; int64_t val; if (pd->flags == RSPAMD_CL_FLAG_INT_32) { - target.i32p = (int32_t *) (((gchar *) pd->user_struct) + pd->offset); + target.i32p = (int32_t *) (((char *) pd->user_struct) + pd->offset); if (!ucl_object_toint_safe(obj, &val)) { g_set_error(err, CFG_RCL_ERROR, @@ -2814,7 +2814,7 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, *target.i32p = val; } else if (pd->flags == RSPAMD_CL_FLAG_INT_64) { - target.i64p = (int64_t *) (((gchar *) pd->user_struct) + pd->offset); + target.i64p = (int64_t *) (((char *) pd->user_struct) + pd->offset); if (!ucl_object_toint_safe(obj, &val)) { g_set_error(err, CFG_RCL_ERROR, @@ -2827,7 +2827,7 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, *target.i64p = val; } else if (pd->flags == RSPAMD_CL_FLAG_INT_SIZE) { - target.sp = (gsize *) (((gchar *) pd->user_struct) + pd->offset); + target.sp = (gsize *) (((char *) pd->user_struct) + pd->offset); if (!ucl_object_toint_safe(obj, &val)) { g_set_error(err, CFG_RCL_ERROR, @@ -2840,7 +2840,7 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, *target.sp = val; } else if (pd->flags == RSPAMD_CL_FLAG_INT_16) { - target.i16p = (gint16 *) (((gchar *) pd->user_struct) + pd->offset); + target.i16p = (int16_t *) (((char *) pd->user_struct) + pd->offset); if (!ucl_object_toint_safe(obj, &val)) { g_set_error(err, CFG_RCL_ERROR, @@ -2853,7 +2853,7 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, *target.i16p = val; } else if (pd->flags == RSPAMD_CL_FLAG_UINT) { - target.up = (guint *) (((gchar *) pd->user_struct) + pd->offset); + target.up = (unsigned int *) (((char *) pd->user_struct) + pd->offset); if (!ucl_object_toint_safe(obj, &val)) { g_set_error(err, CFG_RCL_ERROR, @@ -2866,7 +2866,7 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, *target.up = val; } else { - target.ip = (gint *) (((gchar *) pd->user_struct) + pd->offset); + target.ip = (int *) (((char *) pd->user_struct) + pd->offset); if (!ucl_object_toint_safe(obj, &val)) { g_set_error(err, CFG_RCL_ERROR, @@ -2890,9 +2890,9 @@ rspamd_rcl_parse_struct_double(rspamd_mempool_t *pool, GError **err) { auto *pd = (struct rspamd_rcl_struct_parser *) ud; - gdouble *target; + double *target; - target = (gdouble *) (((gchar *) pd->user_struct) + pd->offset); + target = (double *) (((char *) pd->user_struct) + pd->offset); if (!ucl_object_todouble_safe(obj, target)) { g_set_error(err, @@ -2916,13 +2916,13 @@ rspamd_rcl_parse_struct_time(rspamd_mempool_t *pool, { auto *pd = (struct rspamd_rcl_struct_parser *) ud; union { - gint *psec; + int *psec; uint32_t *pu32; - gdouble *pdv; + double *pdv; struct timeval *ptv; struct timespec *pts; } target; - gdouble val; + double val; if (!ucl_object_todouble_safe(obj, &val)) { g_set_error(err, @@ -2936,26 +2936,26 @@ rspamd_rcl_parse_struct_time(rspamd_mempool_t *pool, if (pd->flags == RSPAMD_CL_FLAG_TIME_TIMEVAL) { target.ptv = - (struct timeval *) (((gchar *) pd->user_struct) + pd->offset); + (struct timeval *) (((char *) pd->user_struct) + pd->offset); target.ptv->tv_sec = (glong) val; target.ptv->tv_usec = (val - (glong) val) * 1000000; } else if (pd->flags == RSPAMD_CL_FLAG_TIME_TIMESPEC) { target.pts = - (struct timespec *) (((gchar *) pd->user_struct) + pd->offset); + (struct timespec *) (((char *) pd->user_struct) + pd->offset); target.pts->tv_sec = (glong) val; target.pts->tv_nsec = (val - (glong) val) * 1000000000000LL; } else if (pd->flags == RSPAMD_CL_FLAG_TIME_FLOAT) { - target.pdv = (double *) (((gchar *) pd->user_struct) + pd->offset); + target.pdv = (double *) (((char *) pd->user_struct) + pd->offset); *target.pdv = val; } else if (pd->flags == RSPAMD_CL_FLAG_TIME_INTEGER) { - target.psec = (gint *) (((gchar *) pd->user_struct) + pd->offset); + target.psec = (int *) (((char *) pd->user_struct) + pd->offset); *target.psec = val * 1000; } else if (pd->flags == RSPAMD_CL_FLAG_TIME_UINT_32) { - target.pu32 = (uint32_t *) (((gchar *) pd->user_struct) + pd->offset); + target.pu32 = (uint32_t *) (((char *) pd->user_struct) + pd->offset); *target.pu32 = val * 1000; } else { @@ -2981,7 +2981,7 @@ rspamd_rcl_parse_struct_keypair(rspamd_mempool_t *pool, auto *pd = (struct rspamd_rcl_struct_parser *) ud; struct rspamd_cryptobox_keypair **target, *kp; - target = (struct rspamd_cryptobox_keypair **) (((gchar *) pd->user_struct) + + target = (struct rspamd_cryptobox_keypair **) (((char *) pd->user_struct) + pd->offset); if (obj->type == UCL_OBJECT) { kp = rspamd_keypair_from_ucl(obj); @@ -2992,7 +2992,7 @@ rspamd_rcl_parse_struct_keypair(rspamd_mempool_t *pool, *target = kp; } else { - gchar *dump = (char *) ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT); + char *dump = (char *) ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT); g_set_error(err, CFG_RCL_ERROR, EINVAL, @@ -3025,7 +3025,7 @@ rspamd_rcl_parse_struct_pubkey(rspamd_mempool_t *pool, auto *pd = (struct rspamd_rcl_struct_parser *) ud; struct rspamd_cryptobox_pubkey **target, *pk; gsize len; - const gchar *str; + const char *str; rspamd_cryptobox_keypair_type keypair_type = RSPAMD_KEYPAIR_KEX; rspamd_cryptobox_mode keypair_mode = RSPAMD_CRYPTOBOX_MODE_25519; @@ -3036,7 +3036,7 @@ rspamd_rcl_parse_struct_pubkey(rspamd_mempool_t *pool, keypair_mode = RSPAMD_CRYPTOBOX_MODE_NIST; } - target = (struct rspamd_cryptobox_pubkey **) (((gchar *) pd->user_struct) + + target = (struct rspamd_cryptobox_pubkey **) (((char *) pd->user_struct) + pd->offset); if (obj->type == UCL_STRING) { str = ucl_object_tolstring(obj, &len); @@ -3079,7 +3079,7 @@ rspamd_rcl_insert_string_list_item(gpointer *target, rspamd_mempool_t *pool, GList *lv; gpointer p; } d; - gchar *val; + char *val; d.p = *target; @@ -3114,7 +3114,7 @@ rspamd_rcl_parse_struct_string_list(rspamd_mempool_t *pool, auto is_hash = pd->flags & RSPAMD_CL_FLAG_STRING_LIST_HASH; - auto *target = (gpointer *) (((gchar *) pd->user_struct) + pd->offset); + auto *target = (gpointer *) (((char *) pd->user_struct) + pd->offset); if (!is_hash && *target != nullptr) { need_destructor = FALSE; @@ -3134,19 +3134,19 @@ rspamd_rcl_parse_struct_string_list(rspamd_mempool_t *pool, continue; } case UCL_INT: { - auto *val = (gchar *) rspamd_mempool_alloc(pool, num_str_len); + auto *val = (char *) rspamd_mempool_alloc(pool, num_str_len); rspamd_snprintf(val, num_str_len, "%L", cur->value.iv); rspamd_rcl_insert_string_list_item(target, pool, val, is_hash); break; } case UCL_FLOAT: { - auto *val = (gchar *) rspamd_mempool_alloc(pool, num_str_len); + auto *val = (char *) rspamd_mempool_alloc(pool, num_str_len); rspamd_snprintf(val, num_str_len, "%f", cur->value.dv); rspamd_rcl_insert_string_list_item(target, pool, val, is_hash); break; } case UCL_BOOLEAN: { - auto *val = (gchar *) rspamd_mempool_alloc(pool, num_str_len); + auto *val = (char *) rspamd_mempool_alloc(pool, num_str_len); rspamd_snprintf(val, num_str_len, "%s", ((gboolean) cur->value.iv) ? "true" : "false"); rspamd_rcl_insert_string_list_item(target, pool, val, is_hash); @@ -3204,7 +3204,7 @@ rspamd_rcl_parse_struct_ucl(rspamd_mempool_t *pool, auto *pd = (struct rspamd_rcl_struct_parser *) ud; const ucl_object_t **target; - target = (const ucl_object_t **) (((gchar *) pd->user_struct) + pd->offset); + target = (const ucl_object_t **) (((char *) pd->user_struct) + pd->offset); *target = obj; @@ -3222,7 +3222,7 @@ rspamd_rcl_parse_struct_boolean(rspamd_mempool_t *pool, auto *pd = (struct rspamd_rcl_struct_parser *) ud; gboolean *target; - target = (gboolean *) (((gchar *) pd->user_struct) + pd->offset); + target = (gboolean *) (((char *) pd->user_struct) + pd->offset); if (obj->type == UCL_BOOLEAN) { *target = obj->value.iv; @@ -3256,10 +3256,10 @@ rspamd_rcl_parse_struct_addr(rspamd_mempool_t *pool, { auto *pd = (struct rspamd_rcl_struct_parser *) ud; rspamd_inet_addr_t **target; - const gchar *val; + const char *val; gsize size; - target = (rspamd_inet_addr_t **) (((gchar *) pd->user_struct) + pd->offset); + target = (rspamd_inet_addr_t **) (((char *) pd->user_struct) + pd->offset); if (ucl_object_type(obj) == UCL_STRING) { val = ucl_object_tolstring(obj, &size); @@ -3295,11 +3295,11 @@ rspamd_rcl_parse_struct_mime_addr(rspamd_mempool_t *pool, { auto *pd = (struct rspamd_rcl_struct_parser *) ud; GPtrArray **target, *tmp_addr = nullptr; - const gchar *val; + const char *val; ucl_object_iter_t it; const ucl_object_t *cur; - target = (GPtrArray **) (((gchar *) pd->user_struct) + pd->offset); + target = (GPtrArray **) (((char *) pd->user_struct) + pd->offset); it = ucl_object_iterate_new(obj); while ((cur = ucl_object_iterate_safe(it, true)) != nullptr) { @@ -3328,12 +3328,12 @@ rspamd_rcl_parse_struct_mime_addr(rspamd_mempool_t *pool, void rspamd_rcl_register_worker_option(struct rspamd_config *cfg, GQuark type, - const gchar *name, + const char *name, rspamd_rcl_default_handler_t handler, gpointer target, glong offset, - gint flags, - const gchar *doc_string) + int flags, + const char *doc_string) { auto parser_it = cfg->rcl_top_section->workers_parser.try_emplace(type, rspamd_worker_cfg_parser{}); auto &parser = parser_it.first->second; @@ -3390,7 +3390,7 @@ rspamd_rcl_emitter_append_c(unsigned char c, size_t nchars, void *ud) d[0] = nchars; d[1] = c; - rspamd_cryptobox_hash_update(hs, (const guchar *) d, sizeof(d)); + rspamd_cryptobox_hash_update(hs, (const unsigned char *) d, sizeof(d)); return 0; } @@ -3409,7 +3409,7 @@ rspamd_rcl_emitter_append_int(int64_t elt, void *ud) { auto *hs = (rspamd_cryptobox_hash_state_t *) ud; - rspamd_cryptobox_hash_update(hs, (const guchar *) &elt, sizeof(elt)); + rspamd_cryptobox_hash_update(hs, (const unsigned char *) &elt, sizeof(elt)); return 0; } @@ -3419,7 +3419,7 @@ rspamd_rcl_emitter_append_double(double elt, void *ud) { auto *hs = (rspamd_cryptobox_hash_state_t *) ud; - rspamd_cryptobox_hash_update(hs, (const guchar *) &elt, sizeof(elt)); + rspamd_cryptobox_hash_update(hs, (const unsigned char *) &elt, sizeof(elt)); return 0; } @@ -3597,7 +3597,7 @@ void rspamd_config_calculate_cksum(struct rspamd_config *cfg) gboolean rspamd_config_parse_ucl(struct rspamd_config *cfg, - const gchar *filename, + const char *filename, GHashTable *vars, ucl_include_trace_func_t inc_trace, void *trace_data, @@ -3691,12 +3691,12 @@ rspamd_config_parse_ucl(struct rspamd_config *cfg, gboolean rspamd_config_read(struct rspamd_config *cfg, - const gchar *filename, + const char *filename, rspamd_rcl_section_fin_t logger_fin, gpointer logger_ud, GHashTable *vars, gboolean skip_jinja, - gchar **lua_env) + char **lua_env) { GError *err = nullptr; @@ -3802,7 +3802,7 @@ rspamd_config_read(struct rspamd_config *cfg, static void rspamd_rcl_doc_obj_from_handler(ucl_object_t *doc_obj, rspamd_rcl_default_handler_t handler, - gint flags) + int flags) { auto has_example = ucl_object_lookup(doc_obj, "example") != nullptr; auto has_type = ucl_object_lookup(doc_obj, "type") != nullptr; @@ -3920,7 +3920,7 @@ rspamd_rcl_add_doc_obj(ucl_object_t *doc_target, const char *doc_name, ucl_type_t type, rspamd_rcl_default_handler_t handler, - gint flags, + int flags, const char *default_value, gboolean required) { @@ -3968,12 +3968,12 @@ rspamd_rcl_add_doc_obj(ucl_object_t *doc_target, ucl_object_t * rspamd_rcl_add_doc_by_path(struct rspamd_config *cfg, - const gchar *doc_path, + const char *doc_path, const char *doc_string, const char *doc_name, ucl_type_t type, rspamd_rcl_default_handler_t handler, - gint flags, + int flags, const char *default_value, gboolean required) { @@ -4080,10 +4080,10 @@ rspamd_rcl_add_doc_from_comments(struct rspamd_config *cfg, ucl_object_t * rspamd_rcl_add_doc_by_example(struct rspamd_config *cfg, - const gchar *root_path, - const gchar *doc_string, - const gchar *doc_name, - const gchar *example_data, gsize example_len) + const char *root_path, + const char *doc_string, + const char *doc_name, + const char *example_data, gsize example_len) { auto parser = std::shared_ptr(ucl_parser_new(UCL_PARSER_NO_FILEVARS | UCL_PARSER_SAVE_COMMENTS), ucl_parser_free); diff --git a/src/libserver/cfg_rcl.h b/src/libserver/cfg_rcl.h index 766c55e83..e33656b72 100644 --- a/src/libserver/cfg_rcl.h +++ b/src/libserver/cfg_rcl.h @@ -74,7 +74,7 @@ struct rspamd_rcl_struct_parser { */ typedef gboolean (*rspamd_rcl_handler_t)(rspamd_mempool_t *pool, const ucl_object_t *obj, - const gchar *key, + const char *key, gpointer ud, struct rspamd_rcl_section *section, GError **err); @@ -103,11 +103,11 @@ typedef void (*rspamd_rcl_section_fin_t)(rspamd_mempool_t *pool, gpointer ud); */ struct rspamd_rcl_default_handler_data *rspamd_rcl_add_default_handler( struct rspamd_rcl_section *section, - const gchar *name, + const char *name, rspamd_rcl_default_handler_t handler, goffset offset, - gint flags, - const gchar *doc_string); + int flags, + const char *doc_string); /** * Add new section to the configuration @@ -123,8 +123,8 @@ struct rspamd_rcl_default_handler_data *rspamd_rcl_add_default_handler( struct rspamd_rcl_section *rspamd_rcl_add_section( struct rspamd_rcl_sections_map **top, struct rspamd_rcl_section *parent_section, - const gchar *name, - const gchar *key_attr, + const char *name, + const char *key_attr, rspamd_rcl_handler_t handler, enum ucl_type type, gboolean required, @@ -133,12 +133,12 @@ struct rspamd_rcl_section *rspamd_rcl_add_section( struct rspamd_rcl_section *rspamd_rcl_add_section_doc( struct rspamd_rcl_sections_map **top, struct rspamd_rcl_section *parent_section, - const gchar *name, const gchar *key_attr, + const char *name, const char *key_attr, rspamd_rcl_handler_t handler, enum ucl_type type, gboolean required, gboolean strict_type, ucl_object_t *doc_target, - const gchar *doc_string); + const char *doc_string); /** * Init common sections known to rspamd @@ -350,12 +350,12 @@ gboolean rspamd_rcl_parse_struct_ucl(rspamd_mempool_t *pool, */ void rspamd_rcl_register_worker_option(struct rspamd_config *cfg, GQuark type, - const gchar *name, + const char *name, rspamd_rcl_default_handler_t handler, gpointer target, glong offset, - gint flags, - const gchar *doc_string); + int flags, + const char *doc_string); /** * Adds new documentation object to the configuration @@ -367,7 +367,7 @@ ucl_object_t *rspamd_rcl_add_doc_obj(ucl_object_t *doc_target, const char *doc_name, ucl_type_t type, rspamd_rcl_default_handler_t handler, - gint flags, + int flags, const char *default_value, gboolean required); @@ -376,12 +376,12 @@ ucl_object_t *rspamd_rcl_add_doc_obj(ucl_object_t *doc_target, * split by dots */ ucl_object_t *rspamd_rcl_add_doc_by_path(struct rspamd_config *cfg, - const gchar *doc_path, + const char *doc_path, const char *doc_string, const char *doc_name, ucl_type_t type, rspamd_rcl_default_handler_t handler, - gint flags, + int flags, const char *default_value, gboolean required); @@ -408,10 +408,10 @@ ucl_object_t *rspamd_rcl_add_doc_by_path(struct rspamd_config *cfg, * @return */ ucl_object_t *rspamd_rcl_add_doc_by_example(struct rspamd_config *cfg, - const gchar *root_path, - const gchar *doc_string, - const gchar *doc_name, - const gchar *example_data, gsize example_len); + const char *root_path, + const char *doc_string, + const char *doc_name, + const char *example_data, gsize example_len); /** * Add lua modules path @@ -422,7 +422,7 @@ ucl_object_t *rspamd_rcl_add_doc_by_example(struct rspamd_config *cfg, */ gboolean rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections, struct rspamd_config *cfg, - const gchar *path, + const char *path, gboolean main_path, GError **err); @@ -455,19 +455,19 @@ void rspamd_config_calculate_cksum(struct rspamd_config *cfg); * Read configuration file */ gboolean rspamd_config_parse_ucl(struct rspamd_config *cfg, - const gchar *filename, + const char *filename, GHashTable *vars, ucl_include_trace_func_t inc_trace, void *trace_data, gboolean skip_jinja, GError **err); gboolean rspamd_config_read(struct rspamd_config *cfg, - const gchar *filename, + const char *filename, rspamd_rcl_section_fin_t logger_fin, gpointer logger_ud, GHashTable *vars, gboolean skip_jinja, - gchar **lua_env); + char **lua_env); #ifdef __cplusplus } diff --git a/src/libserver/cfg_utils.cxx b/src/libserver/cfg_utils.cxx index ec9ce0bcf..ff432ec4a 100644 --- a/src/libserver/cfg_utils.cxx +++ b/src/libserver/cfg_utils.cxx @@ -101,14 +101,14 @@ struct rspamd_ucl_map_cbdata { { } }; -static gchar *rspamd_ucl_read_cb(gchar *chunk, - gint len, - struct map_cb_data *data, - gboolean final); +static char *rspamd_ucl_read_cb(char *chunk, + int len, + struct map_cb_data *data, + gboolean final); static void rspamd_ucl_fin_cb(struct map_cb_data *data, void **target); static void rspamd_ucl_dtor_cb(struct map_cb_data *data); -guint rspamd_config_log_id = (guint) -1; +unsigned int rspamd_config_log_id = (unsigned int) -1; RSPAMD_CONSTRUCTOR(rspamd_config_log_init) { rspamd_config_log_id = rspamd_logger_add_debug_module("config"); @@ -162,10 +162,10 @@ struct rspamd_actions_list { gboolean rspamd_parse_bind_line(struct rspamd_config *cfg, struct rspamd_worker_conf *cf, - const gchar *str) + const char *str) { struct rspamd_worker_bind_conf *cnf; - const gchar *fdname; + const char *fdname; gboolean ret = TRUE; if (str == nullptr) { @@ -437,8 +437,8 @@ void rspamd_config_free(struct rspamd_config *cfg) const ucl_object_t * rspamd_config_get_module_opt(struct rspamd_config *cfg, - const gchar *module_name, - const gchar *opt_name) + const char *module_name, + const char *opt_name) { const ucl_object_t *res = nullptr, *sec; @@ -450,9 +450,9 @@ rspamd_config_get_module_opt(struct rspamd_config *cfg, return res; } -gint rspamd_config_parse_flag(const gchar *str, guint len) +int rspamd_config_parse_flag(const char *str, unsigned int len) { - gint c; + int c; if (!str || !*str) { return -1; @@ -627,8 +627,8 @@ rspamd_config_process_var(struct rspamd_config *cfg, const rspamd_ftok_t *var, static gboolean rspamd_config_parse_log_format(struct rspamd_config *cfg) { - const gchar *p, *c, *end, *s; - gchar *d; + const char *p, *c, *end, *s; + char *d; struct rspamd_log_format *lf = nullptr; rspamd_ftok_t var, var_content; enum { @@ -637,7 +637,7 @@ rspamd_config_parse_log_format(struct rspamd_config *cfg) parse_var_name, parse_var_content, } state = parse_str; - gint braces = 0; + int braces = 0; g_assert(cfg != nullptr); c = cfg->log_format_str; @@ -1026,7 +1026,7 @@ void rspamd_config_init_metric(struct rspamd_config *cfg) } struct rspamd_symbols_group * -rspamd_config_new_group(struct rspamd_config *cfg, const gchar *name) +rspamd_config_new_group(struct rspamd_config *cfg, const char *name) { struct rspamd_symbols_group *gr; @@ -1093,7 +1093,7 @@ rspamd_config_new_worker(struct rspamd_config *cfg, static bool -rspamd_include_map_handler(const guchar *data, gsize len, +rspamd_include_map_handler(const unsigned char *data, gsize len, const ucl_object_t *args, void *ud) { auto *cfg = (struct rspamd_config *) ud; @@ -1236,7 +1236,7 @@ void rspamd_config_insert_classify_symbols(struct rspamd_config *cfg) } struct rspamd_classifier_config * -rspamd_config_find_classifier(struct rspamd_config *cfg, const gchar *name) +rspamd_config_find_classifier(struct rspamd_config *cfg, const char *name) { if (name == nullptr) { return nullptr; @@ -1312,9 +1312,9 @@ rspamd_config_check_statfiles(struct rspamd_classifier_config *cf) return res; } -static gchar * -rspamd_ucl_read_cb(gchar *chunk, - gint len, +static char * +rspamd_ucl_read_cb(char *chunk, + int len, struct map_cb_data *data, gboolean final) { @@ -1388,7 +1388,7 @@ rspamd_check_module(struct rspamd_config *cfg, module_t *mod) if (mod != nullptr) { if (mod->module_version != RSPAMD_CUR_MODULE_VERSION) { msg_err_config("module %s has incorrect version %xd (%xd expected)", - mod->name, (gint) mod->module_version, RSPAMD_CUR_MODULE_VERSION); + mod->name, (int) mod->module_version, RSPAMD_CUR_MODULE_VERSION); ret = FALSE; } if (ret && mod->rspamd_version != RSPAMD_VERSION_NUM) { @@ -1443,7 +1443,7 @@ rspamd_init_filters(struct rspamd_config *cfg, bool reconfig, bool strict) { GList *cur; module_t *mod, **pmod; - guint i = 0; + unsigned int i = 0; struct module_ctx *mod_ctx, *cur_ctx; gboolean ret = TRUE; @@ -1470,7 +1470,7 @@ rspamd_init_filters(struct rspamd_config *cfg, bool reconfig, bool strict) PTR_ARRAY_FOREACH(cfg->c_modules, i, cur_ctx) { if (g_ascii_strcasecmp(cur_ctx->mod->name, - (const gchar *) cur->data) == 0) { + (const char *) cur->data) == 0) { mod_ctx = cur_ctx; break; } @@ -1513,9 +1513,9 @@ rspamd_init_filters(struct rspamd_config *cfg, bool reconfig, bool strict) } static void -rspamd_config_new_symbol(struct rspamd_config *cfg, const gchar *symbol, - gdouble score, const gchar *description, const gchar *group, - guint flags, guint priority, gint nshots) +rspamd_config_new_symbol(struct rspamd_config *cfg, const char *symbol, + double score, const char *description, const char *group, + unsigned int flags, unsigned int priority, int nshots) { struct rspamd_symbols_group *sym_group; struct rspamd_symbol *sym_def; @@ -1585,17 +1585,17 @@ rspamd_config_new_symbol(struct rspamd_config *cfg, const gchar *symbol, gboolean rspamd_config_add_symbol(struct rspamd_config *cfg, - const gchar *symbol, - gdouble score, - const gchar *description, - const gchar *group, - guint flags, - guint priority, - gint nshots) + const char *symbol, + double score, + const char *description, + const char *group, + unsigned int flags, + unsigned int priority, + int nshots) { struct rspamd_symbol *sym_def; struct rspamd_symbols_group *sym_group; - guint i; + unsigned int i; g_assert(cfg != nullptr); g_assert(symbol != nullptr); @@ -1724,12 +1724,12 @@ rspamd_config_add_symbol(struct rspamd_config *cfg, gboolean rspamd_config_add_symbol_group(struct rspamd_config *cfg, - const gchar *symbol, - const gchar *group) + const char *symbol, + const char *group) { struct rspamd_symbol *sym_def; struct rspamd_symbols_group *sym_group; - guint i; + unsigned int i; g_assert(cfg != nullptr); g_assert(symbol != nullptr); @@ -1787,7 +1787,7 @@ rspamd_config_is_enabled_from_ucl(rspamd_mempool_t *pool, return ucl_object_toboolean(enabled); } else if (ucl_object_type(enabled) == UCL_STRING) { - gint ret = rspamd_config_parse_flag(ucl_object_tostring(enabled), 0); + int ret = rspamd_config_parse_flag(ucl_object_tostring(enabled), 0); if (ret == 0) { return FALSE; @@ -1811,7 +1811,7 @@ rspamd_config_is_enabled_from_ucl(rspamd_mempool_t *pool, return !ucl_object_toboolean(disabled); } else if (ucl_object_type(disabled) == UCL_STRING) { - gint ret = rspamd_config_parse_flag(ucl_object_tostring(disabled), 0); + int ret = rspamd_config_parse_flag(ucl_object_tostring(disabled), 0); if (ret == 0) { return TRUE; @@ -1831,7 +1831,7 @@ rspamd_config_is_enabled_from_ucl(rspamd_mempool_t *pool, gboolean rspamd_config_is_module_enabled(struct rspamd_config *cfg, - const gchar *module_name) + const char *module_name) { gboolean is_c = FALSE, enabled; const ucl_object_t *conf; @@ -1839,7 +1839,7 @@ rspamd_config_is_module_enabled(struct rspamd_config *cfg, struct rspamd_symbols_group *gr; lua_State *L = RSPAMD_LUA_CFG_STATE(cfg); struct module_ctx *cur_ctx; - guint i; + unsigned int i; PTR_ARRAY_FOREACH(cfg->c_modules, i, cur_ctx) { @@ -1931,7 +1931,7 @@ static gboolean rspamd_config_action_from_ucl(struct rspamd_config *cfg, struct rspamd_action *act, const ucl_object_t *obj, - guint priority) + unsigned int priority) { auto threshold = NAN; int flags = 0; @@ -1955,7 +1955,7 @@ rspamd_config_action_from_ucl(struct rspamd_config *cfg, while ((cur = ucl_object_iterate(elt, &it, true)) != nullptr) { if (ucl_object_type(cur) == UCL_STRING) { - const gchar *fl_str = ucl_object_tostring(cur); + const char *fl_str = ucl_object_tostring(cur); if (g_ascii_strcasecmp(fl_str, "no_threshold") == 0) { flags |= RSPAMD_ACTION_NO_THRESHOLD; @@ -1976,7 +1976,7 @@ rspamd_config_action_from_ucl(struct rspamd_config *cfg, elt = ucl_object_lookup(obj, "milter"); if (elt) { - const gchar *milter_action = ucl_object_tostring(elt); + const char *milter_action = ucl_object_tostring(elt); if (strcmp(milter_action, "discard") == 0) { flags |= RSPAMD_ACTION_MILTER; @@ -2024,12 +2024,12 @@ rspamd_config_action_from_ucl(struct rspamd_config *cfg, gboolean rspamd_config_set_action_score(struct rspamd_config *cfg, - const gchar *action_name, + const char *action_name, const ucl_object_t *obj) { enum rspamd_action_type std_act; const ucl_object_t *elt; - guint priority = ucl_object_get_priority(obj), obj_type; + unsigned int priority = ucl_object_get_priority(obj), obj_type; g_assert(cfg != nullptr); g_assert(action_name != nullptr); @@ -2107,8 +2107,8 @@ rspamd_config_set_action_score(struct rspamd_config *cfg, gboolean rspamd_config_maybe_disable_action(struct rspamd_config *cfg, - const gchar *action_name, - guint priority) + const char *action_name, + unsigned int priority) { auto actions = RSPAMD_CFG_ACTIONS(cfg); auto maybe_act = rspamd::find_map(actions->actions_by_name, action_name); @@ -2140,7 +2140,7 @@ rspamd_config_maybe_disable_action(struct rspamd_config *cfg, } struct rspamd_action * -rspamd_config_get_action(struct rspamd_config *cfg, const gchar *name) +rspamd_config_get_action(struct rspamd_config *cfg, const char *name) { auto actions = RSPAMD_CFG_ACTIONS(cfg); auto maybe_act = rspamd::find_map(actions->actions_by_name, name); @@ -2189,14 +2189,14 @@ gsize rspamd_config_actions_size(struct rspamd_config *cfg) } gboolean -rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const gchar *description, +rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const char *description, struct rspamd_radix_map_helper **target, GError **err, - struct rspamd_worker *worker, const gchar *map_name) + struct rspamd_worker *worker, const char *map_name) { ucl_type_t type; ucl_object_iter_t it = nullptr; const ucl_object_t *cur, *cur_elt; - const gchar *str; + const char *str; /* Cleanup */ *target = nullptr; @@ -2317,7 +2317,7 @@ constexpr const auto action_types = frozen::make_unordered_mapcrypto_ctx->cpu_config & CPUID_SSE41)) { utf8_flags |= RSPAMD_FAST_UTF8_FLAG_SSE41; diff --git a/src/libserver/composites/composites.cxx b/src/libserver/composites/composites.cxx index aa231a315..64f8f2daf 100644 --- a/src/libserver/composites/composites.cxx +++ b/src/libserver/composites/composites.cxx @@ -51,11 +51,11 @@ INIT_LOG_MODULE(composites) namespace rspamd::composites { -static rspamd_expression_atom_t *rspamd_composite_expr_parse(const gchar *line, gsize len, +static rspamd_expression_atom_t *rspamd_composite_expr_parse(const char *line, gsize len, rspamd_mempool_t *pool, gpointer ud, GError **err); -static gdouble rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom); -static gint rspamd_composite_expr_priority(rspamd_expression_atom_t *atom); +static double rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom); +static int rspamd_composite_expr_priority(rspamd_expression_atom_t *atom); static void rspamd_composite_expr_destroy(rspamd_expression_atom_t *atom); static void composites_foreach_callback(gpointer key, gpointer value, void *data); @@ -234,12 +234,12 @@ rspamd_composite_atom_dtor(void *ptr) } static rspamd_expression_atom_t * -rspamd_composite_expr_parse(const gchar *line, gsize len, +rspamd_composite_expr_parse(const char *line, gsize len, rspamd_mempool_t *pool, gpointer ud, GError **err) { gsize clen = 0; - const gchar *p, *end; + const char *p, *end; enum composite_expr_state { comp_state_read_symbol = 0, comp_state_read_obrace, @@ -350,7 +350,7 @@ rspamd_composite_expr_parse(const gchar *line, gsize len, res->str = line; /* Full state machine to fill a composite atom */ - const gchar *opt_start = nullptr; + const char *opt_start = nullptr; while (p < end) { if (state == comp_state_read_end) { @@ -406,7 +406,7 @@ rspamd_composite_expr_parse(const gchar *line, gsize len, case comp_state_read_option: if (*p == ',' || *p == ']') { /* Plain match, copy option to ensure string_view validity */ - gint opt_len = p - opt_start; + int opt_len = p - opt_start; auto *opt_buf = rspamd_mempool_alloc_buffer(pool, opt_len + 1); rspamd_strlcpy(opt_buf, opt_start, opt_len + 1); opt_buf = g_strstrip(opt_buf); @@ -573,7 +573,7 @@ process_single_symbol(struct composites_data *cd, struct rspamd_composite_atom *atom) -> double { struct rspamd_symbol_result *ms = nullptr; - gdouble rc = 0; + double rc = 0; struct rspamd_task *task = cd->task; if ((ms = rspamd_task_find_symbol_result(cd->task, sym.data(), cd->metric_res)) == nullptr) { @@ -674,7 +674,7 @@ rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom) -> doubl struct rspamd_symbol_result *ms = NULL; struct rspamd_task *task = cd->task; - gdouble rc = 0; + double rc = 0; if (cd->checked[cd->composite->id * 2]) { /* We have already checked this composite, so just return its value */ @@ -784,7 +784,7 @@ rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom) -> doubl /* * We don't have preferences for composites */ -static gint +static int rspamd_composite_expr_priority(rspamd_expression_atom_t *atom) { return 0; @@ -801,9 +801,9 @@ composites_foreach_callback(gpointer key, gpointer value, void *data) { auto *cd = (struct composites_data *) data; auto *comp = (struct rspamd_composite *) value; - auto *str_key = (const gchar *) key; + auto *str_key = (const char *) key; struct rspamd_task *task; - gdouble rc; + double rc; cd->composite = comp; task = cd->task; @@ -869,8 +869,8 @@ remove_symbols(const composites_data &cd, const std::vector want_remove_score = TRUE, want_remove_symbol = TRUE, want_forced = FALSE; - const gchar *disable_score_reason = "no policy", - *disable_symbol_reason = "no policy"; + const char *disable_score_reason = "no policy", + *disable_symbol_reason = "no policy"; task = cd.task; diff --git a/src/libserver/composites/composites_internal.hxx b/src/libserver/composites/composites_internal.hxx index 038e217a0..55aaa2ee1 100644 --- a/src/libserver/composites/composites_internal.hxx +++ b/src/libserver/composites/composites_internal.hxx @@ -45,7 +45,7 @@ struct rspamd_composite { std::string str_expr; std::string sym; struct rspamd_expression *expr; - gint id; + int id; rspamd_composite_policy policy; }; diff --git a/src/libserver/css/css_util.cxx b/src/libserver/css/css_util.cxx index 07f87229c..5a34250a0 100644 --- a/src/libserver/css/css_util.cxx +++ b/src/libserver/css/css_util.cxx @@ -141,10 +141,10 @@ std::string_view unescape_css(rspamd_mempool_t *pool, }// namespace rspamd::css /* C API */ -const gchar *rspamd_css_unescape(rspamd_mempool_t *pool, - const guchar *begin, - gsize len, - gsize *outlen) +const char *rspamd_css_unescape(rspamd_mempool_t *pool, + const unsigned char *begin, + gsize len, + gsize *outlen) { auto sv = rspamd::css::unescape_css(pool, {(const char *) begin, len}); const auto *v = sv.begin(); diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c index 7bf7b1f30..3134b0ecf 100644 --- a/src/libserver/dkim.c +++ b/src/libserver/dkim.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -94,8 +94,8 @@ INIT_LOG_MODULE(dkim) union rspamd_dkim_header_stat { struct _st { - guint16 count; - guint16 flags; + uint16_t count; + uint16_t flags; } s; uint32_t n; }; @@ -109,11 +109,11 @@ struct rspamd_dkim_common_ctx { EVP_MD_CTX *headers_hash; EVP_MD_CTX *body_hash; enum rspamd_dkim_type type; - guint idx; - gint header_canon_type; - gint body_canon_type; - guint body_canonicalised; - guint headers_canonicalised; + unsigned int idx; + int header_canon_type; + int body_canon_type; + unsigned int body_canonicalised; + unsigned int headers_canonicalised; gboolean is_sign; }; @@ -132,37 +132,37 @@ struct rspamd_dkim_context_s { struct rspamd_dns_resolver *resolver; gsize blen; gsize bhlen; - gint sig_alg; - guint ver; + int sig_alg; + unsigned int ver; time_t timestamp; time_t expiration; - gchar *domain; - gchar *selector; - gint8 *b; - gchar *short_b; - gint8 *bh; - gchar *dns_key; + char *domain; + char *selector; + int8_t *b; + char *short_b; + int8_t *bh; + char *dns_key; enum rspamd_arc_seal_cv cv; - const gchar *dkim_header; + const char *dkim_header; }; #define RSPAMD_DKIM_KEY_ID_LEN 16 struct rspamd_dkim_key_s { - guint8 *keydata; - guint8 *raw_key; + uint8_t *keydata; + uint8_t *raw_key; gsize keylen; gsize decoded_len; - gchar key_id[RSPAMD_DKIM_KEY_ID_LEN]; + char key_id[RSPAMD_DKIM_KEY_ID_LEN]; union { RSA *key_rsa; EC_KEY *key_ecdsa; - guchar *key_eddsa; + unsigned char *key_eddsa; } key; BIO *key_bio; EVP_PKEY *key_evp; time_t mtime; - guint ttl; + unsigned int ttl; enum rspamd_dkim_key_type type; ref_entry_t ref; }; @@ -173,68 +173,68 @@ struct rspamd_dkim_sign_context_s { }; struct rspamd_dkim_header { - const gchar *name; - gint count; + const char *name; + int count; }; /* Parser of dkim params */ typedef gboolean (*dkim_parse_param_f)(rspamd_dkim_context_t *ctx, - const gchar *param, gsize len, GError **err); + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_signature(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_signalg(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_domain(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_canonalg(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_ignore(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_selector(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_hdrlist(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_version(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_timestamp(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_expiration(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_bodyhash(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_bodylength(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_idx(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); static gboolean rspamd_dkim_parse_cv(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err); @@ -269,7 +269,7 @@ dkim_error_quark(void) /* Parsers implementation */ static gboolean rspamd_dkim_parse_signature(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -283,7 +283,7 @@ rspamd_dkim_parse_signature(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_signalg(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -330,7 +330,7 @@ rspamd_dkim_parse_signalg(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_domain(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -358,11 +358,11 @@ rspamd_dkim_parse_domain(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_canonalg(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { - const gchar *p, *slash = NULL, *end = param + len; + const char *p, *slash = NULL, *end = param + len; gsize sl = 0; p = param; @@ -420,7 +420,7 @@ err: static gboolean rspamd_dkim_parse_ignore(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -430,7 +430,7 @@ rspamd_dkim_parse_ignore(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_selector(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -467,15 +467,15 @@ rspamd_dkim_hlist_free(void *ud) static gboolean rspamd_dkim_parse_hdrlist_common(struct rspamd_dkim_common_ctx *ctx, - const gchar *param, + const char *param, gsize len, gboolean sign, GError **err) { - const gchar *c, *p, *end = param + len; - gchar *h; + const char *c, *p, *end = param + len; + char *h; gboolean from_found = FALSE, oversign, existing; - guint count = 0; + unsigned int count = 0; struct rspamd_dkim_header *new; gpointer found; union rspamd_dkim_header_stat u; @@ -602,7 +602,7 @@ rspamd_dkim_parse_hdrlist_common(struct rspamd_dkim_common_ctx *ctx, static gboolean rspamd_dkim_parse_hdrlist(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -611,7 +611,7 @@ rspamd_dkim_parse_hdrlist(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_version(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -629,7 +629,7 @@ rspamd_dkim_parse_version(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_timestamp(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -649,7 +649,7 @@ rspamd_dkim_parse_timestamp(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_expiration(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -669,7 +669,7 @@ rspamd_dkim_parse_expiration(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_bodyhash(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -681,7 +681,7 @@ rspamd_dkim_parse_bodyhash(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_bodylength(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -701,7 +701,7 @@ rspamd_dkim_parse_bodylength(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_idx(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -721,7 +721,7 @@ rspamd_dkim_parse_idx(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_parse_cv(rspamd_dkim_context_t *ctx, - const gchar *param, + const char *param, gsize len, GError **err) { @@ -758,7 +758,7 @@ rspamd_dkim_add_arc_seal_headers(rspamd_mempool_t *pool, struct rspamd_dkim_common_ctx *ctx) { struct rspamd_dkim_header *hdr; - gint count = ctx->idx, i; + int count = ctx->idx, i; ctx->hlist = g_ptr_array_sized_new(count * 3 - 1); @@ -797,16 +797,16 @@ rspamd_dkim_add_arc_seal_headers(rspamd_mempool_t *pool, * @return new context or NULL */ rspamd_dkim_context_t * -rspamd_create_dkim_context(const gchar *sig, +rspamd_create_dkim_context(const char *sig, rspamd_mempool_t *pool, struct rspamd_dns_resolver *resolver, - guint time_jitter, + unsigned int time_jitter, enum rspamd_dkim_type type, GError **err) { - const gchar *p, *c, *tag = NULL, *end; - gint taglen; - gint param = DKIM_PARAM_UNKNOWN; + const char *p, *c, *tag = NULL, *end; + int taglen; + int param = DKIM_PARAM_UNKNOWN; const EVP_MD *md_alg; time_t now; rspamd_dkim_context_t *ctx; @@ -1039,8 +1039,8 @@ rspamd_create_dkim_context(const gchar *sig, } else { /* Cut trailing spaces for value */ - gint tlen = p - c; - const gchar *tmp = p - 1; + int tlen = p - c; + const char *tmp = p - 1; while (tlen > 0) { if (!g_ascii_isspace(*tmp)) { @@ -1074,8 +1074,8 @@ rspamd_create_dkim_context(const gchar *sig, } else if (p == end) { /* Last parameter with no `;` character */ - gint tlen = p - c; - const gchar *tmp = p - 1; + int tlen = p - c; + const char *tmp = p - 1; while (tlen > 0) { if (!g_ascii_isspace(*tmp)) { @@ -1194,7 +1194,7 @@ rspamd_create_dkim_context(const gchar *sig, if (type != RSPAMD_DKIM_ARC_SEAL) { if (ctx->sig_alg == DKIM_SIGN_RSASHA1) { /* Check bh length */ - if (ctx->bhlen != (guint) EVP_MD_size(EVP_sha1())) { + if (ctx->bhlen != (unsigned int) EVP_MD_size(EVP_sha1())) { g_set_error(err, DKIM_ERROR, DKIM_SIGERROR_BADSIG, @@ -1206,7 +1206,7 @@ rspamd_create_dkim_context(const gchar *sig, else if (ctx->sig_alg == DKIM_SIGN_RSASHA256 || ctx->sig_alg == DKIM_SIGN_ECDSASHA256) { if (ctx->bhlen != - (guint) EVP_MD_size(EVP_sha256())) { + (unsigned int) EVP_MD_size(EVP_sha256())) { g_set_error(err, DKIM_ERROR, DKIM_SIGERROR_BADSIG, @@ -1218,7 +1218,7 @@ rspamd_create_dkim_context(const gchar *sig, else if (ctx->sig_alg == DKIM_SIGN_RSASHA512 || ctx->sig_alg == DKIM_SIGN_ECDSASHA512) { if (ctx->bhlen != - (guint) EVP_MD_size(EVP_sha512())) { + (unsigned int) EVP_MD_size(EVP_sha512())) { g_set_error(err, DKIM_ERROR, DKIM_SIGERROR_BADSIG, @@ -1231,7 +1231,7 @@ rspamd_create_dkim_context(const gchar *sig, /* Check expiration */ now = time(NULL); - if (ctx->timestamp && now < ctx->timestamp && ctx->timestamp - now > (gint) time_jitter) { + if (ctx->timestamp && now < ctx->timestamp && ctx->timestamp - now > (int) time_jitter) { g_set_error(err, DKIM_ERROR, DKIM_SIGERROR_FUTURE, @@ -1328,8 +1328,8 @@ struct rspamd_dkim_key_cbdata { }; rspamd_dkim_key_t * -rspamd_dkim_make_key(const gchar *keydata, - guint keylen, enum rspamd_dkim_key_type type, GError **err) +rspamd_dkim_make_key(const char *keydata, + unsigned int keylen, enum rspamd_dkim_key_type type, GError **err) { rspamd_dkim_key_t *key = NULL; @@ -1350,7 +1350,7 @@ rspamd_dkim_make_key(const gchar *keydata, /* Copy key skipping all spaces and newlines */ const char *h = keydata; - guint8 *t = key->raw_key; + uint8_t *t = key->raw_key; while (h - keydata < keylen) { if (!g_ascii_isspace(*h)) { @@ -1382,7 +1382,7 @@ rspamd_dkim_make_key(const gchar *keydata, #endif if (EVP_DigestInit_ex(mdctx, EVP_md5(), NULL) == 1) { - guint dlen = sizeof(key->key_id); + unsigned int dlen = sizeof(key->key_id); EVP_DigestUpdate(mdctx, key->keydata, key->decoded_len); EVP_DigestFinal_ex(mdctx, key->key_id, &dlen); @@ -1399,7 +1399,7 @@ rspamd_dkim_make_key(const gchar *keydata, DKIM_ERROR, DKIM_SIGERROR_KEYFAIL, "DKIM key is has invalid length %d for eddsa; expected %d", - (gint) key->decoded_len, + (int) key->decoded_len, rspamd_cryptobox_pk_sig_bytes(RSPAMD_CRYPTOBOX_MODE_25519)); REF_RELEASE(key); @@ -1462,7 +1462,7 @@ rspamd_dkim_make_key(const gchar *keydata, return key; } -const guchar * +const unsigned char * rspamd_dkim_key_id(rspamd_dkim_key_t *key) { if (key) { @@ -1525,9 +1525,9 @@ void rspamd_dkim_sign_key_free(rspamd_dkim_sign_key_t *key) } rspamd_dkim_key_t * -rspamd_dkim_parse_key(const gchar *txt, gsize *keylen, GError **err) +rspamd_dkim_parse_key(const char *txt, gsize *keylen, GError **err) { - const gchar *c, *p, *end, *key = NULL, *alg = "rsa"; + const char *c, *p, *end, *key = NULL, *alg = "rsa"; enum { read_tag = 0, read_tag_before_eqsign, @@ -1538,7 +1538,7 @@ rspamd_dkim_parse_key(const gchar *txt, gsize *keylen, GError **err) skip_spaces, } state = read_tag, next_state; - gchar tag = '\0'; + char tag = '\0'; gsize klen = 0, alglen = 0; c = txt; @@ -1721,7 +1721,7 @@ rspamd_dkim_dns_cb(struct rdns_reply *reply, gpointer arg) gsize keylen = 0; if (reply->code != RDNS_RC_NOERROR) { - gint err_code = DKIM_SIGERROR_NOKEY; + int err_code = DKIM_SIGERROR_NOKEY; if (reply->code == RDNS_RC_NOREC) { err_code = DKIM_SIGERROR_NOREC; } @@ -1792,15 +1792,15 @@ rspamd_get_dkim_key(rspamd_dkim_context_t *ctx, static gboolean rspamd_dkim_relaxed_body_step(struct rspamd_dkim_common_ctx *ctx, EVP_MD_CTX *ck, - const gchar **start, guint size, + const char **start, unsigned int size, gssize *remain) { - const gchar *h; - gchar *t; - guint len, inlen; + const char *h; + char *t; + unsigned int len, inlen; gssize octets_remain; gboolean got_sp, ret = TRUE; - gchar buf[1024]; + char buf[1024]; len = size; inlen = sizeof(buf) - 1; @@ -1892,14 +1892,14 @@ rspamd_dkim_relaxed_body_step(struct rspamd_dkim_common_ctx *ctx, EVP_MD_CTX *ck static gboolean rspamd_dkim_simple_body_step(struct rspamd_dkim_common_ctx *ctx, - EVP_MD_CTX *ck, const gchar **start, guint size, + EVP_MD_CTX *ck, const char **start, unsigned int size, gssize *remain) { - const gchar *h; - gchar *t; - guint len, inlen; + const char *h; + char *t; + unsigned int len, inlen; gssize octets_remain; - gchar buf[1024]; + char buf[1024]; len = size; inlen = sizeof(buf) - 1; @@ -1959,11 +1959,11 @@ rspamd_dkim_simple_body_step(struct rspamd_dkim_common_ctx *ctx, return ((len != 0) && (octets_remain != 0)); } -static const gchar * -rspamd_dkim_skip_empty_lines(const gchar *start, const gchar *end, - guint type, gboolean sign, gboolean *need_crlf) +static const char * +rspamd_dkim_skip_empty_lines(const char *start, const char *end, + unsigned int type, gboolean sign, gboolean *need_crlf) { - const gchar *p = end - 1, *t; + const char *p = end - 1, *t; enum { init = 0, init_2, @@ -1972,7 +1972,7 @@ rspamd_dkim_skip_empty_lines(const gchar *start, const gchar *end, got_crlf, test_spaces, } state = init; - guint skip = 0; + unsigned int skip = 0; while (p >= start) { switch (state) { @@ -2130,13 +2130,13 @@ end: static gboolean rspamd_dkim_canonize_body(struct rspamd_dkim_common_ctx *ctx, - const gchar *start, - const gchar *end, + const char *start, + const char *end, gboolean sign) { - const gchar *p; + const char *p; gssize remain = ctx->len ? ctx->len : G_MAXSSIZE; - guint total_len = end - start; + unsigned int total_len = end - start; gboolean need_crlf = FALSE; if (start == NULL) { @@ -2224,9 +2224,9 @@ rspamd_dkim_canonize_body(struct rspamd_dkim_common_ctx *ctx, /* Update hash converting all CR and LF to CRLF */ static void -rspamd_dkim_hash_update(EVP_MD_CTX *ck, const gchar *begin, gsize len) +rspamd_dkim_hash_update(EVP_MD_CTX *ck, const char *begin, gsize len) { - const gchar *p, *c, *end; + const char *p, *c, *end; end = begin + len; p = begin; @@ -2262,10 +2262,10 @@ rspamd_dkim_hash_update(EVP_MD_CTX *ck, const gchar *begin, gsize len) /* Update hash by signature value (ignoring b= tag) */ static void rspamd_dkim_signature_update(struct rspamd_dkim_common_ctx *ctx, - const gchar *begin, - guint len) + const char *begin, + unsigned int len) { - const gchar *p, *c, *end; + const char *p, *c, *end; gboolean tag, skip; end = begin + len; @@ -2278,7 +2278,7 @@ rspamd_dkim_signature_update(struct rspamd_dkim_common_ctx *ctx, if (tag && p[0] == 'b' && p[1] == '=') { /* Add to signature */ msg_debug_dkim("initial update hash with signature part: %*s", - (gint) (p - c + 2), + (int) (p - c + 2), c); ctx->headers_canonicalised += p - c + 2; rspamd_dkim_hash_update(ctx->headers_hash, c, p - c + 2); @@ -2305,20 +2305,20 @@ rspamd_dkim_signature_update(struct rspamd_dkim_common_ctx *ctx, if (p - c + 1 > 0) { msg_debug_dkim("final update hash with signature part: %*s", - (gint) (p - c + 1), c); + (int) (p - c + 1), c); ctx->headers_canonicalised += p - c + 1; rspamd_dkim_hash_update(ctx->headers_hash, c, p - c + 1); } } goffset -rspamd_dkim_canonize_header_relaxed_str(const gchar *hname, - const gchar *hvalue, - gchar *out, +rspamd_dkim_canonize_header_relaxed_str(const char *hname, + const char *hvalue, + char *out, gsize outlen) { - gchar *t; - const guchar *h; + char *t; + const unsigned char *h; gboolean got_sp; /* Name part */ @@ -2381,15 +2381,15 @@ rspamd_dkim_canonize_header_relaxed_str(const gchar *hname, static gboolean rspamd_dkim_canonize_header_relaxed(struct rspamd_dkim_common_ctx *ctx, - const gchar *header, - const gchar *header_name, + const char *header, + const char *header_name, gboolean is_sign, - guint count, + unsigned int count, bool is_seal) { - static gchar st_buf[8192]; - gchar *buf; - guint inlen; + static char st_buf[8192]; + char *buf; + unsigned int inlen; goffset r; gboolean allocated = FALSE; @@ -2428,20 +2428,20 @@ rspamd_dkim_canonize_header_relaxed(struct rspamd_dkim_common_ctx *ctx, static gboolean rspamd_dkim_canonize_header(struct rspamd_dkim_common_ctx *ctx, struct rspamd_task *task, - const gchar *header_name, - gint count, - const gchar *dkim_header, - const gchar *dkim_domain) + const char *header_name, + int count, + const char *dkim_header, + const char *dkim_domain) { struct rspamd_mime_header *rh, *cur, *sel = NULL; - gint hdr_cnt = 0; + int hdr_cnt = 0; bool use_idx = false, is_sign = ctx->is_sign; /* * TODO: * Temporary hack to prevent linked list being misused until refactored */ - const guint max_list_iters = 1000; + const unsigned int max_list_iters = 1000; if (count < 0) { use_idx = true; @@ -2477,7 +2477,7 @@ rspamd_dkim_canonize_header(struct rspamd_dkim_common_ctx *ctx, header_name, hdr_cnt); rspamd_dkim_hash_update(ctx->headers_hash, - (const gchar *) &random_cookie, + (const char *) &random_cookie, sizeof(random_cookie)); ctx->headers_canonicalised += sizeof(random_cookie); @@ -2497,8 +2497,8 @@ rspamd_dkim_canonize_header(struct rspamd_dkim_common_ctx *ctx, * This branch is used for ARC headers, and it orders them based on * i= string and not their real order in the list of headers */ - gchar idx_buf[16]; - gint id_len, i; + char idx_buf[16]; + int id_len, i; id_len = rspamd_snprintf(idx_buf, sizeof(idx_buf), "i=%d;", count); @@ -2531,13 +2531,13 @@ rspamd_dkim_canonize_header(struct rspamd_dkim_common_ctx *ctx, ctx->headers_canonicalised += sel->raw_len; msg_debug_dkim("update %s with header (idx=%d): %*s", (use_idx ? "seal" : "signature"), - count, (gint) sel->raw_len, sel->raw_value); + count, (int) sel->raw_len, sel->raw_value); } else { if (is_sign && (sel->flags & RSPAMD_HEADER_FROM)) { /* Special handling of the From handling when rewrite is done */ gboolean has_rewrite = FALSE; - guint i; + unsigned int i; struct rspamd_email_address *addr; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, from_mime), i, addr) @@ -2621,17 +2621,17 @@ rspamd_dkim_canonize_header(struct rspamd_dkim_common_ctx *ctx, } struct rspamd_dkim_cached_hash { - guchar *digest_normal; - guchar *digest_cr; - guchar *digest_crlf; - gchar *type; + unsigned char *digest_normal; + unsigned char *digest_cr; + unsigned char *digest_crlf; + char *type; }; static struct rspamd_dkim_cached_hash * rspamd_dkim_check_bh_cached(struct rspamd_dkim_common_ctx *ctx, struct rspamd_task *task, gsize bhlen, gboolean is_sign) { - gchar typebuf[64]; + char typebuf[64]; struct rspamd_dkim_cached_hash *res; rspamd_snprintf(typebuf, sizeof(typebuf), @@ -2680,15 +2680,15 @@ rspamd_dkim_check(rspamd_dkim_context_t *ctx, rspamd_dkim_key_t *key, struct rspamd_task *task) { - const gchar *body_end, *body_start; - guchar raw_digest[EVP_MAX_MD_SIZE]; + const char *body_end, *body_start; + unsigned char raw_digest[EVP_MAX_MD_SIZE]; struct rspamd_dkim_cached_hash *cached_bh = NULL; EVP_MD_CTX *cpy_ctx = NULL; gsize dlen = 0; struct rspamd_dkim_check_result *res; - guint i; + unsigned int i; struct rspamd_dkim_header *dh; - gint nid; + int nid; g_return_val_if_fail(ctx != NULL, NULL); g_return_val_if_fail(key != NULL, NULL); @@ -2768,8 +2768,8 @@ rspamd_dkim_check(rspamd_dkim_context_t *ctx, if (memcmp(ctx->bh, cached_bh->digest_normal, ctx->bhlen) != 0) { msg_debug_dkim( "bh value mismatch: %*xs versus %*xs, try add LF; try adding CRLF", - (gint) dlen, ctx->bh, - (gint) dlen, raw_digest); + (int) dlen, ctx->bh, + (int) dlen, raw_digest); if (cpy_ctx) { /* Try add CRLF */ @@ -2788,8 +2788,8 @@ rspamd_dkim_check(rspamd_dkim_context_t *ctx, if (memcmp(ctx->bh, raw_digest, ctx->bhlen) != 0) { msg_debug_dkim( "bh value mismatch after added CRLF: %*xs versus %*xs, try add LF", - (gint) dlen, ctx->bh, - (gint) dlen, raw_digest); + (int) dlen, ctx->bh, + (int) dlen, raw_digest); /* Try add LF */ #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) @@ -2806,8 +2806,8 @@ rspamd_dkim_check(rspamd_dkim_context_t *ctx, if (memcmp(ctx->bh, raw_digest, ctx->bhlen) != 0) { msg_debug_dkim("bh value mismatch after added LF: %*xs versus %*xs", - (gint) dlen, ctx->bh, - (gint) dlen, raw_digest); + (int) dlen, ctx->bh, + (int) dlen, raw_digest); res->fail_reason = "body hash did not verify"; res->rcode = DKIM_REJECT; } @@ -2816,15 +2816,15 @@ rspamd_dkim_check(rspamd_dkim_context_t *ctx, else if (cached_bh->digest_crlf) { if (memcmp(ctx->bh, cached_bh->digest_crlf, ctx->bhlen) != 0) { msg_debug_dkim("bh value mismatch after added CRLF: %*xs versus %*xs", - (gint) dlen, ctx->bh, - (gint) dlen, cached_bh->digest_crlf); + (int) dlen, ctx->bh, + (int) dlen, cached_bh->digest_crlf); if (cached_bh->digest_cr) { if (memcmp(ctx->bh, cached_bh->digest_cr, ctx->bhlen) != 0) { msg_debug_dkim( "bh value mismatch after added LF: %*xs versus %*xs", - (gint) dlen, ctx->bh, - (gint) dlen, cached_bh->digest_cr); + (int) dlen, ctx->bh, + (int) dlen, cached_bh->digest_cr); res->fail_reason = "body hash did not verify"; res->rcode = DKIM_REJECT; @@ -2840,8 +2840,8 @@ rspamd_dkim_check(rspamd_dkim_context_t *ctx, else { msg_debug_dkim( "bh value mismatch: %*xs versus %*xs", - (gint) dlen, ctx->bh, - (gint) dlen, cached_bh->digest_normal); + (int) dlen, ctx->bh, + (int) dlen, cached_bh->digest_normal); res->fail_reason = "body hash did not verify"; res->rcode = DKIM_REJECT; } @@ -2861,9 +2861,9 @@ rspamd_dkim_check(rspamd_dkim_context_t *ctx, "%s: bh value mismatch: got %*Bs, expected %*Bs; " "body length %d->%d; d=%s; s=%s", rspamd_dkim_type_to_string(ctx->common.type), - (gint) dlen, cached_bh->digest_normal, - (gint) dlen, ctx->bh, - (gint) (body_end - body_start), ctx->common.body_canonicalised, + (int) dlen, cached_bh->digest_normal, + (int) dlen, ctx->bh, + (int) (body_end - body_start), ctx->common.body_canonicalised, ctx->domain, ctx->selector); return res; @@ -2904,7 +2904,7 @@ rspamd_dkim_check(rspamd_dkim_context_t *ctx, "%s: headers RSA verification failure; " "body length %d->%d; headers length %d; d=%s; s=%s; key_md5=%*xs; orig header: %s", rspamd_dkim_type_to_string(ctx->common.type), - (gint) (body_end - body_start), ctx->common.body_canonicalised, + (int) (body_end - body_start), ctx->common.body_canonicalised, ctx->common.headers_canonicalised, ctx->domain, ctx->selector, RSPAMD_DKIM_KEY_ID_LEN, rspamd_dkim_key_id(key), @@ -2918,7 +2918,7 @@ rspamd_dkim_check(rspamd_dkim_context_t *ctx, "%s: headers ECDSA verification failure; " "body length %d->%d; headers length %d; d=%s; s=%s; key_md5=%*xs; orig header: %s", rspamd_dkim_type_to_string(ctx->common.type), - (gint) (body_end - body_start), ctx->common.body_canonicalised, + (int) (body_end - body_start), ctx->common.body_canonicalised, ctx->common.headers_canonicalised, ctx->domain, ctx->selector, RSPAMD_DKIM_KEY_ID_LEN, rspamd_dkim_key_id(key), @@ -2936,7 +2936,7 @@ rspamd_dkim_check(rspamd_dkim_context_t *ctx, "%s: headers EDDSA verification failure; " "body length %d->%d; headers length %d; d=%s; s=%s; key_md5=%*xs; orig header: %s", rspamd_dkim_type_to_string(ctx->common.type), - (gint) (body_end - body_start), ctx->common.body_canonicalised, + (int) (body_end - body_start), ctx->common.body_canonicalised, ctx->common.headers_canonicalised, ctx->domain, ctx->selector, RSPAMD_DKIM_KEY_ID_LEN, rspamd_dkim_key_id(key), @@ -3013,7 +3013,7 @@ void rspamd_dkim_sign_key_unref(rspamd_dkim_sign_key_t *k) REF_RELEASE(k); } -const gchar * +const char * rspamd_dkim_get_domain(rspamd_dkim_context_t *ctx) { if (ctx) { @@ -3023,7 +3023,7 @@ rspamd_dkim_get_domain(rspamd_dkim_context_t *ctx) return NULL; } -const gchar * +const char * rspamd_dkim_get_selector(rspamd_dkim_context_t *ctx) { if (ctx) { @@ -3033,7 +3033,7 @@ rspamd_dkim_get_selector(rspamd_dkim_context_t *ctx) return NULL; } -guint rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k) +unsigned int rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k) { if (k) { return k->ttl; @@ -3042,7 +3042,7 @@ guint rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k) return 0; } -const gchar * +const char * rspamd_dkim_get_dns_key(rspamd_dkim_context_t *ctx) { if (ctx) { @@ -3055,11 +3055,11 @@ rspamd_dkim_get_dns_key(rspamd_dkim_context_t *ctx) #define PEM_SIG "-----BEGIN" rspamd_dkim_sign_key_t * -rspamd_dkim_sign_key_load(const gchar *key, gsize len, +rspamd_dkim_sign_key_load(const char *key, gsize len, enum rspamd_dkim_key_format type, GError **err) { - guchar *map = NULL, *tmp = NULL; + unsigned char *map = NULL, *tmp = NULL; gsize maplen; rspamd_dkim_sign_key_t *nkey; time_t mtime = time(NULL); @@ -3221,9 +3221,9 @@ rspamd_dkim_sign_key_maybe_invalidate(rspamd_dkim_sign_key_t *key, time_t mtime) rspamd_dkim_sign_context_t * rspamd_create_dkim_sign_context(struct rspamd_task *task, rspamd_dkim_sign_key_t *priv_key, - gint headers_canon, - gint body_canon, - const gchar *headers, + int headers_canon, + int body_canon, + const char *headers, enum rspamd_dkim_type type, GError **err) { @@ -3303,21 +3303,21 @@ rspamd_create_dkim_sign_context(struct rspamd_task *task, GString * -rspamd_dkim_sign(struct rspamd_task *task, const gchar *selector, - const gchar *domain, time_t expire, gsize len, guint idx, - const gchar *arc_cv, rspamd_dkim_sign_context_t *ctx) +rspamd_dkim_sign(struct rspamd_task *task, const char *selector, + const char *domain, time_t expire, gsize len, unsigned int idx, + const char *arc_cv, rspamd_dkim_sign_context_t *ctx) { GString *hdr; struct rspamd_dkim_header *dh; - const gchar *body_end, *body_start, *hname; - guchar raw_digest[EVP_MAX_MD_SIZE]; + const char *body_end, *body_start, *hname; + unsigned char raw_digest[EVP_MAX_MD_SIZE]; struct rspamd_dkim_cached_hash *cached_bh = NULL; gsize dlen = 0; - guint i, j; - gchar *b64_data; - guchar *sig_buf; - guint sig_len; - guint headers_len = 0, cur_len = 0; + unsigned int i, j; + char *b64_data; + unsigned char *sig_buf; + unsigned int sig_len; + unsigned int headers_len = 0, cur_len = 0; union rspamd_dkim_header_stat hstat; g_assert(ctx != NULL); @@ -3399,7 +3399,7 @@ rspamd_dkim_sign(struct rspamd_task *task, const gchar *selector, if (hstat.s.flags & RSPAMD_DKIM_FLAG_OVERSIGN) { /* Do oversigning */ - guint count = 0; + unsigned int count = 0; rh = rspamd_message_get_header_array(task, dh->name, FALSE); @@ -3508,7 +3508,7 @@ rspamd_dkim_sign(struct rspamd_task *task, const gchar *selector, hdr->len); ctx->common.headers_canonicalised += hdr->len; msg_debug_task("update signature with header: %*s", - (gint) hdr->len, hdr->str); + (int) hdr->len, hdr->str); } dlen = EVP_MD_CTX_size(ctx->common.headers_hash); diff --git a/src/libserver/dkim.h b/src/libserver/dkim.h index 50703da1a..6296a656f 100644 --- a/src/libserver/dkim.h +++ b/src/libserver/dkim.h @@ -118,10 +118,10 @@ struct rspamd_dkim_check_result { enum rspamd_dkim_check_rcode rcode; rspamd_dkim_context_t *ctx; /* Processed parts */ - const gchar *selector; - const gchar *domain; - const gchar *short_b; - const gchar *fail_reason; + const char *selector; + const char *domain; + const char *short_b; + const char *fail_reason; }; @@ -137,10 +137,10 @@ typedef void (*dkim_key_handler_f)(rspamd_dkim_key_t *key, gsize keylen, * @param err pointer to error object * @return new context or NULL */ -rspamd_dkim_context_t *rspamd_create_dkim_context(const gchar *sig, +rspamd_dkim_context_t *rspamd_create_dkim_context(const char *sig, rspamd_mempool_t *pool, struct rspamd_dns_resolver *resolver, - guint time_jitter, + unsigned int time_jitter, enum rspamd_dkim_type type, GError **err); @@ -153,9 +153,9 @@ rspamd_dkim_context_t *rspamd_create_dkim_context(const gchar *sig, */ rspamd_dkim_sign_context_t *rspamd_create_dkim_sign_context(struct rspamd_task *task, rspamd_dkim_sign_key_t *priv_key, - gint headers_canon, - gint body_canon, - const gchar *dkim_headers, + int headers_canon, + int body_canon, + const char *dkim_headers, enum rspamd_dkim_type type, GError **err); @@ -165,7 +165,7 @@ rspamd_dkim_sign_context_t *rspamd_create_dkim_sign_context(struct rspamd_task * * @param err * @return */ -rspamd_dkim_sign_key_t *rspamd_dkim_sign_key_load(const gchar *what, gsize len, +rspamd_dkim_sign_key_t *rspamd_dkim_sign_key_load(const char *what, gsize len, enum rspamd_dkim_key_format type, GError **err); @@ -206,12 +206,12 @@ rspamd_dkim_create_result(rspamd_dkim_context_t *ctx, struct rspamd_task *task); GString *rspamd_dkim_sign(struct rspamd_task *task, - const gchar *selector, - const gchar *domain, + const char *selector, + const char *domain, time_t expire, gsize len, - guint idx, - const gchar *arc_cv, + unsigned int idx, + const char *arc_cv, rspamd_dkim_sign_context_t *ctx); rspamd_dkim_key_t *rspamd_dkim_key_ref(rspamd_dkim_key_t *k); @@ -222,13 +222,13 @@ rspamd_dkim_sign_key_t *rspamd_dkim_sign_key_ref(rspamd_dkim_sign_key_t *k); void rspamd_dkim_sign_key_unref(rspamd_dkim_sign_key_t *k); -const gchar *rspamd_dkim_get_domain(rspamd_dkim_context_t *ctx); +const char *rspamd_dkim_get_domain(rspamd_dkim_context_t *ctx); -const gchar *rspamd_dkim_get_selector(rspamd_dkim_context_t *ctx); +const char *rspamd_dkim_get_selector(rspamd_dkim_context_t *ctx); -const gchar *rspamd_dkim_get_dns_key(rspamd_dkim_context_t *ctx); +const char *rspamd_dkim_get_dns_key(rspamd_dkim_context_t *ctx); -guint rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k); +unsigned int rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k); /** * Create DKIM public key from a raw data @@ -238,7 +238,7 @@ guint rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k); * @param err * @return */ -rspamd_dkim_key_t *rspamd_dkim_make_key(const gchar *keydata, guint keylen, +rspamd_dkim_key_t *rspamd_dkim_make_key(const char *keydata, unsigned int keylen, enum rspamd_dkim_key_type type, GError **err); @@ -249,7 +249,7 @@ rspamd_dkim_key_t *rspamd_dkim_make_key(const gchar *keydata, guint keylen, * @param key * @return */ -const guchar *rspamd_dkim_key_id(rspamd_dkim_key_t *key); +const unsigned char *rspamd_dkim_key_id(rspamd_dkim_key_t *key); /** * Parse DKIM public key from a TXT record @@ -258,7 +258,7 @@ const guchar *rspamd_dkim_key_id(rspamd_dkim_key_t *key); * @param err * @return */ -rspamd_dkim_key_t *rspamd_dkim_parse_key(const gchar *txt, gsize *keylen, +rspamd_dkim_key_t *rspamd_dkim_parse_key(const char *txt, gsize *keylen, GError **err); /** @@ -269,9 +269,9 @@ rspamd_dkim_key_t *rspamd_dkim_parse_key(const gchar *txt, gsize *keylen, * @param outlen * @return */ -goffset rspamd_dkim_canonize_header_relaxed_str(const gchar *hname, - const gchar *hvalue, - gchar *out, +goffset rspamd_dkim_canonize_header_relaxed_str(const char *hname, + const char *hvalue, + char *out, gsize outlen); /** diff --git a/src/libserver/dns.c b/src/libserver/dns.c index 980be1dba..ea1c590e6 100644 --- a/src/libserver/dns.c +++ b/src/libserver/dns.c @@ -28,7 +28,7 @@ #include -static const gchar *M = "rspamd dns"; +static const char *M = "rspamd dns"; static struct rdns_upstream_elt *rspamd_dns_select_upstream(const char *name, size_t len, void *ups_data); @@ -40,7 +40,7 @@ static struct rdns_upstream_elt *rspamd_dns_select_upstream_retransmit( static void rspamd_dns_upstream_ok(struct rdns_upstream_elt *elt, void *ups_data); static void rspamd_dns_upstream_fail(struct rdns_upstream_elt *elt, - void *ups_data, const gchar *reason); + void *ups_data, const char *reason); static unsigned int rspamd_dns_upstream_count(void *ups_data); static struct rdns_upstream_context rspamd_ups_ctx = { @@ -68,7 +68,7 @@ struct rspamd_dns_fail_cache_entry { enum rdns_request_type type; }; -static const gint8 ascii_dns_table[128] = { +static const int8_t ascii_dns_table[128] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* HYPHEN-MINUS..FULL STOP */ @@ -83,7 +83,7 @@ static const gint8 ascii_dns_table[128] = { -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1}; -static guint +static unsigned int rspamd_dns_fail_hash(gconstpointer ptr) { struct rspamd_dns_fail_cache_entry *elt = @@ -157,15 +157,15 @@ rspamd_dns_callback(struct rdns_reply *reply, gpointer ud) reqdata->task->resolver->fails_cache) { /* Add to cache... */ - const gchar *name = reqdata->req->requested_names[0].name; - gchar *target; + const char *name = reqdata->req->requested_names[0].name; + char *target; gsize namelen; struct rspamd_dns_fail_cache_entry *nentry; /* Allocate in a single entry to allow further free in a single call */ namelen = strlen(name); nentry = g_malloc(sizeof(nentry) + namelen + 1); - target = ((gchar *) nentry) + sizeof(nentry); + target = ((char *) nentry) + sizeof(nentry); rspamd_strlcpy(target, name, namelen + 1); nentry->type = reqdata->req->requested_names[0].type; nentry->name = target; @@ -206,8 +206,8 @@ rspamd_dns_resolver_request(struct rspamd_dns_resolver *resolver, { struct rdns_request *req; struct rspamd_dns_request_ud *reqdata = NULL; - guint nlen = strlen(name); - gchar *real_name = NULL; + unsigned int nlen = strlen(name); + char *real_name = NULL; g_assert(resolver != NULL); @@ -419,7 +419,7 @@ static void rspamd_rnds_log_bridge( } static void -rspamd_dns_server_init(struct upstream *up, guint idx, gpointer ud) +rspamd_dns_server_init(struct upstream *up, unsigned int idx, gpointer ud) { struct rspamd_dns_resolver *r = ud; rspamd_inet_addr_t *addr; @@ -447,7 +447,7 @@ rspamd_dns_server_init(struct upstream *up, guint idx, gpointer ud) } static void -rspamd_dns_server_reorder(struct upstream *up, guint idx, gpointer ud) +rspamd_dns_server_reorder(struct upstream *up, unsigned int idx, gpointer ud) { struct rspamd_dns_resolver *r = ud; @@ -462,7 +462,7 @@ rspamd_dns_resolv_conf_on_server(struct rdns_resolver *resolver, struct rspamd_dns_resolver *dns_resolver = ud; struct rspamd_config *cfg; rspamd_inet_addr_t *addr; - gint test_fd; + int test_fd; cfg = dns_resolver->cfg; @@ -510,7 +510,7 @@ rspamd_process_fake_reply(struct rspamd_config *cfg, enum rdns_request_type rtype = RDNS_REQUEST_A; enum dns_rcode rcode = RDNS_RC_NOERROR; struct rdns_reply_entry *replies = NULL; - const gchar *name = NULL; + const char *name = NULL; if (ucl_object_type(cur) != UCL_OBJECT) { continue; @@ -560,9 +560,9 @@ rspamd_process_fake_reply(struct rspamd_config *cfg, rep_it = ucl_object_iterate_new(replies_obj); while ((rep_obj = ucl_object_iterate_safe(rep_it, true))) { - const gchar *str_rep = ucl_object_tostring(rep_obj); + const char *str_rep = ucl_object_tostring(rep_obj); struct rdns_reply_entry *rep; - gchar **svec; + char **svec; if (str_rep == NULL) { msg_err_config("invalid reply element for fake DNS record %s", @@ -666,7 +666,7 @@ rspamd_process_fake_reply(struct rspamd_config *cfg, if (replies) { struct rdns_reply_entry *tmp_entry; - guint i = 0; + unsigned int i = 0; DL_COUNT(replies, tmp_entry, i); msg_info_config("added fake record: %s(%s); %d replies", name, @@ -700,13 +700,13 @@ rspamd_process_fake_reply(struct rspamd_config *cfg, static bool rspamd_dns_read_hosts_file(struct rspamd_config *cfg, struct rspamd_dns_resolver *dns_resolver, - const gchar *fname) + const char *fname) { - gchar *linebuf = NULL; + char *linebuf = NULL; gsize buflen = 0; gssize r; FILE *fp; - guint nadded = 0; + unsigned int nadded = 0; fp = fopen(fname, "r"); @@ -732,7 +732,7 @@ rspamd_dns_read_hosts_file(struct rspamd_config *cfg, g_strchomp(linebuf); - gchar **elts = g_strsplit_set(linebuf, " \t\v", -1); + char **elts = g_strsplit_set(linebuf, " \t\v", -1); rspamd_inet_addr_t *addr; if (!rspamd_parse_inet_address(&addr, elts[0], strlen(elts[0]), @@ -741,7 +741,7 @@ rspamd_dns_read_hosts_file(struct rspamd_config *cfg, } else { /* Add all FQDN + aliases if any */ - gchar **cur_name = &elts[1]; + char **cur_name = &elts[1]; while (*cur_name) { if (strlen(*cur_name) == 0) { @@ -1054,7 +1054,7 @@ rspamd_dns_upstream_ok(struct rdns_upstream_elt *elt, static void rspamd_dns_upstream_fail(struct rdns_upstream_elt *elt, - void *ups_data, const gchar *reason) + void *ups_data, const char *reason) { struct upstream *up = elt->lib_data; @@ -1069,18 +1069,18 @@ rspamd_dns_upstream_count(void *ups_data) return rspamd_upstreams_alive(ups); } -gchar * +char * rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver, rspamd_mempool_t *pool, const char *name, - gint namelen, - guint *outlen) + int namelen, + unsigned int *outlen) { if (resolver == NULL || resolver->uidna == NULL || name == NULL || namelen > DNS_D_MAXNAME) { return NULL; } - guint dest_len; + unsigned int dest_len; UErrorCode uc_err = U_ZERO_ERROR; UIDNAInfo info = UIDNA_INFO_INITIALIZER; /* Calculate length required */ @@ -1088,7 +1088,7 @@ rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver, NULL, 0, &info, &uc_err); if (uc_err == U_BUFFER_OVERFLOW_ERROR) { - gchar *dest; + char *dest; if (pool) { dest = rspamd_mempool_alloc(pool, dest_len + 1); diff --git a/src/libserver/dns.h b/src/libserver/dns.h index acf8d0908..8485ee214 100644 --- a/src/libserver/dns.h +++ b/src/libserver/dns.h @@ -41,8 +41,8 @@ struct rspamd_dns_resolver { double fails_cache_time; struct upstream_list *ups; struct rspamd_config *cfg; - gdouble request_timeout; - guint max_retransmits; + double request_timeout; + unsigned int max_retransmits; }; /* Rspamd DNS API */ @@ -97,11 +97,11 @@ gboolean rspamd_dns_resolver_request_task_forced(struct rspamd_task *task, * @param namelen length of input (-1 for zero terminated) * @return encoded string */ -gchar *rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver, - rspamd_mempool_t *pool, - const char *name, - gint namelen, - guint *outlen); +char *rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver, + rspamd_mempool_t *pool, + const char *name, + int namelen, + unsigned int *outlen); #ifdef __cplusplus } diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c index 80121c9cd..984517074 100644 --- a/src/libserver/dynamic_cfg.c +++ b/src/libserver/dynamic_cfg.c @@ -39,9 +39,9 @@ apply_dynamic_conf(const ucl_object_t *top, struct rspamd_config *cfg) enum rspamd_action_type test_act; const ucl_object_t *cur_elt, *cur_nm, *it_val; ucl_object_iter_t it = NULL; - const gchar *name; - gdouble nscore; - static const guint priority = 3; + const char *name; + double nscore; + static const unsigned int priority = 3; while ((cur_elt = ucl_object_iterate(top, &it, true))) { if (ucl_object_type(cur_elt) != UCL_OBJECT) { @@ -143,9 +143,9 @@ apply_dynamic_conf(const ucl_object_t *top, struct rspamd_config *cfg) } /* Callbacks for reading json dynamic rules */ -static gchar * -json_config_read_cb(gchar *chunk, - gint len, +static char * +json_config_read_cb(char *chunk, + int len, struct map_cb_data *data, gboolean final) { @@ -296,8 +296,8 @@ gboolean dump_dynamic_config(struct rspamd_config *cfg) { struct stat st; - gchar *dir, pathbuf[PATH_MAX]; - gint fd; + char *dir, pathbuf[PATH_MAX]; + int fd; if (cfg->dynamic_conf == NULL || cfg->current_dynamic_conf == NULL) { /* No dynamic conf has been specified, so do not try to dump it */ @@ -377,7 +377,7 @@ dump_dynamic_config(struct rspamd_config *cfg) } static ucl_object_t * -new_dynamic_metric(const gchar *metric_name, ucl_object_t *top) +new_dynamic_metric(const char *metric_name, ucl_object_t *top) { ucl_object_t *metric; @@ -396,7 +396,7 @@ new_dynamic_metric(const gchar *metric_name, ucl_object_t *top) } static ucl_object_t * -dynamic_metric_find_elt(const ucl_object_t *arr, const gchar *name) +dynamic_metric_find_elt(const ucl_object_t *arr, const char *name) { ucl_object_iter_t it = NULL; const ucl_object_t *cur, *n; @@ -421,7 +421,7 @@ dynamic_metric_find_elt(const ucl_object_t *arr, const gchar *name) } static ucl_object_t * -dynamic_metric_find_metric(const ucl_object_t *arr, const gchar *metric) +dynamic_metric_find_metric(const ucl_object_t *arr, const char *metric) { ucl_object_iter_t it = NULL; const ucl_object_t *cur, *n; @@ -446,7 +446,7 @@ dynamic_metric_find_metric(const ucl_object_t *arr, const gchar *metric) } static ucl_object_t * -new_dynamic_elt(ucl_object_t *arr, const gchar *name, gdouble value) +new_dynamic_elt(ucl_object_t *arr, const char *name, double value) { ucl_object_t *n; @@ -461,13 +461,13 @@ new_dynamic_elt(ucl_object_t *arr, const gchar *name, gdouble value) return n; } -static gint +static int rspamd_maybe_add_lua_dynsym(struct rspamd_config *cfg, - const gchar *sym, - gdouble score) + const char *sym, + double score) { lua_State *L = cfg->lua_state; - gint ret = -1; + int ret = -1; struct rspamd_config **pcfg; lua_getglobal(L, "rspamd_plugins"); @@ -509,13 +509,13 @@ rspamd_maybe_add_lua_dynsym(struct rspamd_config *cfg, return ret; } -static gint +static int rspamd_maybe_add_lua_dynact(struct rspamd_config *cfg, - const gchar *action, - gdouble score) + const char *action, + double score) { lua_State *L = cfg->lua_state; - gint ret = -1; + int ret = -1; struct rspamd_config **pcfg; lua_getglobal(L, "rspamd_plugins"); @@ -567,12 +567,12 @@ rspamd_maybe_add_lua_dynact(struct rspamd_config *cfg, */ gboolean add_dynamic_symbol(struct rspamd_config *cfg, - const gchar *metric_name, - const gchar *symbol, - gdouble value) + const char *metric_name, + const char *symbol, + double value) { ucl_object_t *metric, *syms; - gint ret; + int ret; if ((ret = rspamd_maybe_add_lua_dynsym(cfg, symbol, value)) != -1) { return ret == 0 ? FALSE : TRUE; @@ -609,8 +609,8 @@ add_dynamic_symbol(struct rspamd_config *cfg, gboolean remove_dynamic_symbol(struct rspamd_config *cfg, - const gchar *metric_name, - const gchar *symbol) + const char *metric_name, + const char *symbol) { ucl_object_t *metric, *syms; gboolean ret = FALSE; @@ -659,13 +659,13 @@ remove_dynamic_symbol(struct rspamd_config *cfg, */ gboolean add_dynamic_action(struct rspamd_config *cfg, - const gchar *metric_name, - guint action, - gdouble value) + const char *metric_name, + unsigned int action, + double value) { ucl_object_t *metric, *acts; - const gchar *action_name = rspamd_action_to_str(action); - gint ret; + const char *action_name = rspamd_action_to_str(action); + int ret; if ((ret = rspamd_maybe_add_lua_dynact(cfg, action_name, value)) != -1) { return ret == 0 ? FALSE : TRUE; @@ -702,11 +702,11 @@ add_dynamic_action(struct rspamd_config *cfg, gboolean remove_dynamic_action(struct rspamd_config *cfg, - const gchar *metric_name, - guint action) + const char *metric_name, + unsigned int action) { ucl_object_t *metric, *acts; - const gchar *action_name = rspamd_action_to_str(action); + const char *action_name = rspamd_action_to_str(action); gboolean ret = FALSE; if (cfg->dynamic_conf == NULL) { diff --git a/src/libserver/dynamic_cfg.h b/src/libserver/dynamic_cfg.h index bb386ca7e..6041ed6e2 100644 --- a/src/libserver/dynamic_cfg.h +++ b/src/libserver/dynamic_cfg.h @@ -46,13 +46,13 @@ gboolean dump_dynamic_config(struct rspamd_config *cfg); * @return */ gboolean add_dynamic_symbol(struct rspamd_config *cfg, - const gchar *metric, - const gchar *symbol, - gdouble value); + const char *metric, + const char *symbol, + double value); gboolean remove_dynamic_symbol(struct rspamd_config *cfg, - const gchar *metric, - const gchar *symbol); + const char *metric, + const char *symbol); /** * Add action for specified metric @@ -63,16 +63,16 @@ gboolean remove_dynamic_symbol(struct rspamd_config *cfg, * @return */ gboolean add_dynamic_action(struct rspamd_config *cfg, - const gchar *metric, - guint action, - gdouble value); + const char *metric, + unsigned int action, + double value); /** * Removes dynamic action */ gboolean remove_dynamic_action(struct rspamd_config *cfg, - const gchar *metric, - guint action); + const char *metric, + unsigned int action); #ifdef __cplusplus } diff --git a/src/libserver/fuzzy_backend/fuzzy_backend.c b/src/libserver/fuzzy_backend/fuzzy_backend.c index 607a92e85..c18463618 100644 --- a/src/libserver/fuzzy_backend/fuzzy_backend.c +++ b/src/libserver/fuzzy_backend/fuzzy_backend.c @@ -35,18 +35,18 @@ static void rspamd_fuzzy_backend_check_sqlite(struct rspamd_fuzzy_backend *bk, rspamd_fuzzy_check_cb cb, void *ud, void *subr_ud); static void rspamd_fuzzy_backend_update_sqlite(struct rspamd_fuzzy_backend *bk, - GArray *updates, const gchar *src, + GArray *updates, const char *src, rspamd_fuzzy_update_cb cb, void *ud, void *subr_ud); static void rspamd_fuzzy_backend_count_sqlite(struct rspamd_fuzzy_backend *bk, rspamd_fuzzy_count_cb cb, void *ud, void *subr_ud); static void rspamd_fuzzy_backend_version_sqlite(struct rspamd_fuzzy_backend *bk, - const gchar *src, + const char *src, rspamd_fuzzy_version_cb cb, void *ud, void *subr_ud); -static const gchar *rspamd_fuzzy_backend_id_sqlite(struct rspamd_fuzzy_backend *bk, - void *subr_ud); +static const char *rspamd_fuzzy_backend_id_sqlite(struct rspamd_fuzzy_backend *bk, + void *subr_ud); static void rspamd_fuzzy_backend_expire_sqlite(struct rspamd_fuzzy_backend *bk, void *subr_ud); static void rspamd_fuzzy_backend_close_sqlite(struct rspamd_fuzzy_backend *bk, @@ -61,17 +61,17 @@ struct rspamd_fuzzy_backend_subr { rspamd_fuzzy_check_cb cb, void *ud, void *subr_ud); void (*update)(struct rspamd_fuzzy_backend *bk, - GArray *updates, const gchar *src, + GArray *updates, const char *src, rspamd_fuzzy_update_cb cb, void *ud, void *subr_ud); void (*count)(struct rspamd_fuzzy_backend *bk, rspamd_fuzzy_count_cb cb, void *ud, void *subr_ud); void (*version)(struct rspamd_fuzzy_backend *bk, - const gchar *src, + const char *src, rspamd_fuzzy_version_cb cb, void *ud, void *subr_ud); - const gchar *(*id)(struct rspamd_fuzzy_backend *bk, void *subr_ud); + const char *(*id)(struct rspamd_fuzzy_backend *bk, void *subr_ud); void (*periodic)(struct rspamd_fuzzy_backend *bk, void *subr_ud); void (*close)(struct rspamd_fuzzy_backend *bk, void *subr_ud); }; @@ -100,8 +100,8 @@ static const struct rspamd_fuzzy_backend_subr fuzzy_subrs[] = { struct rspamd_fuzzy_backend { enum rspamd_fuzzy_backend_type type; - gdouble expire; - gdouble sync; + double expire; + double sync; struct ev_loop *event_loop; rspamd_fuzzy_periodic_cb periodic_cb; void *periodic_ud; @@ -153,17 +153,17 @@ rspamd_fuzzy_backend_check_sqlite(struct rspamd_fuzzy_backend *bk, static void rspamd_fuzzy_backend_update_sqlite(struct rspamd_fuzzy_backend *bk, - GArray *updates, const gchar *src, + GArray *updates, const char *src, rspamd_fuzzy_update_cb cb, void *ud, void *subr_ud) { struct rspamd_fuzzy_backend_sqlite *sq = subr_ud; gboolean success = FALSE; - guint i; + unsigned int i; struct fuzzy_peer_cmd *io_cmd; struct rspamd_fuzzy_cmd *cmd; gpointer ptr; - guint nupdates = 0, nadded = 0, ndeleted = 0, nextended = 0, nignored = 0; + unsigned int nupdates = 0, nadded = 0, ndeleted = 0, nextended = 0, nignored = 0; if (rspamd_fuzzy_backend_sqlite_prepare_update(sq, src)) { for (i = 0; i < updates->len; i++) { @@ -226,7 +226,7 @@ rspamd_fuzzy_backend_count_sqlite(struct rspamd_fuzzy_backend *bk, static void rspamd_fuzzy_backend_version_sqlite(struct rspamd_fuzzy_backend *bk, - const gchar *src, + const char *src, rspamd_fuzzy_version_cb cb, void *ud, void *subr_ud) { @@ -240,7 +240,7 @@ rspamd_fuzzy_backend_version_sqlite(struct rspamd_fuzzy_backend *bk, } } -static const gchar * +static const char * rspamd_fuzzy_backend_id_sqlite(struct rspamd_fuzzy_backend *bk, void *subr_ud) { @@ -276,7 +276,7 @@ rspamd_fuzzy_backend_create(struct ev_loop *ev_base, struct rspamd_fuzzy_backend *bk; enum rspamd_fuzzy_backend_type type = RSPAMD_FUZZY_BACKEND_SQLITE; const ucl_object_t *elt; - gdouble expire = DEFAULT_EXPIRE; + double expire = DEFAULT_EXPIRE; if (config != NULL) { elt = ucl_object_lookup(config, "backend"); @@ -328,10 +328,10 @@ void rspamd_fuzzy_backend_check(struct rspamd_fuzzy_backend *bk, bk->subr->check(bk, cmd, cb, ud, bk->subr_ud); } -static guint +static unsigned int rspamd_fuzzy_digest_hash(gconstpointer key) { - guint ret; + unsigned int ret; /* Distributed uniformly already */ memcpy(&ret, key, sizeof(ret)); @@ -352,8 +352,8 @@ rspamd_fuzzy_backend_deduplicate_queue(GArray *updates) rspamd_fuzzy_digest_equal); struct fuzzy_peer_cmd *io_cmd, *found; struct rspamd_fuzzy_cmd *cmd; - guchar *digest; - guint i; + unsigned char *digest; + unsigned int i; for (i = 0; i < updates->len; i++) { io_cmd = &g_array_index(updates, struct fuzzy_peer_cmd, i); @@ -428,7 +428,7 @@ rspamd_fuzzy_backend_deduplicate_queue(GArray *updates) } void rspamd_fuzzy_backend_process_updates(struct rspamd_fuzzy_backend *bk, - GArray *updates, const gchar *src, rspamd_fuzzy_update_cb cb, + GArray *updates, const char *src, rspamd_fuzzy_update_cb cb, void *ud) { g_assert(bk != NULL); @@ -454,7 +454,7 @@ void rspamd_fuzzy_backend_count(struct rspamd_fuzzy_backend *bk, void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk, - const gchar *src, + const char *src, rspamd_fuzzy_version_cb cb, void *ud) { g_assert(bk != NULL); @@ -462,7 +462,7 @@ void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk, bk->subr->version(bk, src, cb, ud, bk->subr_ud); } -const gchar * +const char * rspamd_fuzzy_backend_id(struct rspamd_fuzzy_backend *bk) { g_assert(bk != NULL); @@ -495,7 +495,7 @@ static void rspamd_fuzzy_backend_periodic_cb(EV_P_ ev_timer *w, int revents) { struct rspamd_fuzzy_backend *bk = (struct rspamd_fuzzy_backend *) w->data; - gdouble jittered; + double jittered; jittered = rspamd_time_jitter(bk->sync, bk->sync / 2.0); w->repeat = jittered; @@ -504,11 +504,11 @@ rspamd_fuzzy_backend_periodic_cb(EV_P_ ev_timer *w, int revents) } void rspamd_fuzzy_backend_start_update(struct rspamd_fuzzy_backend *bk, - gdouble timeout, + double timeout, rspamd_fuzzy_periodic_cb cb, void *ud) { - gdouble jittered; + double jittered; g_assert(bk != NULL); @@ -553,7 +553,7 @@ rspamd_fuzzy_backend_event_base(struct rspamd_fuzzy_backend *backend) return backend->event_loop; } -gdouble +double rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend) { return backend->expire; diff --git a/src/libserver/fuzzy_backend/fuzzy_backend.h b/src/libserver/fuzzy_backend/fuzzy_backend.h index 11b60abb3..fe22d473e 100644 --- a/src/libserver/fuzzy_backend/fuzzy_backend.h +++ b/src/libserver/fuzzy_backend/fuzzy_backend.h @@ -33,10 +33,10 @@ struct rspamd_config; typedef void (*rspamd_fuzzy_check_cb)(struct rspamd_fuzzy_reply *rep, void *ud); typedef void (*rspamd_fuzzy_update_cb)(gboolean success, - guint nadded, - guint ndeleted, - guint nextended, - guint nignored, + unsigned int nadded, + unsigned int ndeleted, + unsigned int nextended, + unsigned int nignored, void *ud); typedef void (*rspamd_fuzzy_version_cb)(uint64_t rev, void *ud); @@ -75,7 +75,7 @@ void rspamd_fuzzy_backend_check(struct rspamd_fuzzy_backend *bk, * @param src */ void rspamd_fuzzy_backend_process_updates(struct rspamd_fuzzy_backend *bk, - GArray *updates, const gchar *src, rspamd_fuzzy_update_cb cb, + GArray *updates, const char *src, rspamd_fuzzy_update_cb cb, void *ud); /** @@ -95,7 +95,7 @@ void rspamd_fuzzy_backend_count(struct rspamd_fuzzy_backend *bk, * @param ud */ void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk, - const gchar *src, + const char *src, rspamd_fuzzy_version_cb cb, void *ud); /** @@ -103,20 +103,20 @@ void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk, * @param backend * @return */ -const gchar *rspamd_fuzzy_backend_id(struct rspamd_fuzzy_backend *backend); +const char *rspamd_fuzzy_backend_id(struct rspamd_fuzzy_backend *backend); /** * Starts expire process for the backend * @param backend */ void rspamd_fuzzy_backend_start_update(struct rspamd_fuzzy_backend *backend, - gdouble timeout, + double timeout, rspamd_fuzzy_periodic_cb cb, void *ud); struct ev_loop *rspamd_fuzzy_backend_event_base(struct rspamd_fuzzy_backend *backend); -gdouble rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend); +double rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend); /** * Closes backend diff --git a/src/libserver/fuzzy_backend/fuzzy_backend_redis.c b/src/libserver/fuzzy_backend/fuzzy_backend_redis.c index e1f24dd1a..27c663070 100644 --- a/src/libserver/fuzzy_backend/fuzzy_backend_redis.c +++ b/src/libserver/fuzzy_backend/fuzzy_backend_redis.c @@ -51,14 +51,14 @@ INIT_LOG_MODULE(fuzzy_redis) struct rspamd_fuzzy_backend_redis { lua_State *L; - const gchar *redis_object; - const gchar *username; - const gchar *password; - const gchar *dbname; - gchar *id; + const char *redis_object; + const char *username; + const char *password; + const char *dbname; + char *id; struct rspamd_redis_pool *pool; - gdouble timeout; - gint conf_ref; + double timeout; + int conf_ref; bool terminated; ref_entry_t ref; }; @@ -80,12 +80,12 @@ struct rspamd_fuzzy_redis_session { gboolean shingles_checked; enum rspamd_fuzzy_redis_command command; - guint nargs; + unsigned int nargs; - guint nadded; - guint ndeleted; - guint nextended; - guint nignored; + unsigned int nadded; + unsigned int ndeleted; + unsigned int nextended; + unsigned int nignored; union { rspamd_fuzzy_check_cb cb_check; @@ -95,15 +95,15 @@ struct rspamd_fuzzy_redis_session { } callback; void *cbdata; - gchar **argv; + char **argv; gsize *argv_lens; struct upstream *up; - guchar found_digest[rspamd_cryptobox_HASHBYTES]; + unsigned char found_digest[rspamd_cryptobox_HASHBYTES]; }; static inline struct upstream_list * rspamd_redis_get_servers(struct rspamd_fuzzy_backend_redis *ctx, - const gchar *what) + const char *what) { lua_State *L = ctx->L; struct upstream_list *res = NULL; @@ -117,7 +117,7 @@ rspamd_redis_get_servers(struct rspamd_fuzzy_backend_redis *ctx, } else { struct lua_logger_trace tr; - gchar outbuf[8192]; + char outbuf[8192]; memset(&tr, 0, sizeof(tr)); lua_logger_out_type(L, -2, outbuf, sizeof(outbuf) - 1, &tr, @@ -135,7 +135,7 @@ rspamd_redis_get_servers(struct rspamd_fuzzy_backend_redis *ctx, static inline void rspamd_fuzzy_redis_session_free_args(struct rspamd_fuzzy_redis_session *session) { - guint i; + unsigned int i; if (session->argv) { for (i = 0; i < session->nargs; i++) { @@ -190,10 +190,10 @@ rspamd_fuzzy_backend_init_redis(struct rspamd_fuzzy_backend *bk, struct rspamd_fuzzy_backend_redis *backend; const ucl_object_t *elt; gboolean ret = FALSE; - guchar id_hash[rspamd_cryptobox_HASHBYTES]; + unsigned char id_hash[rspamd_cryptobox_HASHBYTES]; rspamd_cryptobox_hash_state_t st; lua_State *L = (lua_State *) cfg->lua_state; - gint conf_ref = -1; + int conf_ref = -1; backend = g_malloc0(sizeof(*backend)); @@ -328,11 +328,11 @@ static void rspamd_fuzzy_redis_check_callback(redisAsyncContext *c, gpointer r, gpointer priv); struct _rspamd_fuzzy_shingles_helper { - guchar digest[64]; - guint found; + unsigned char digest[64]; + unsigned int found; }; -static gint +static int rspamd_fuzzy_backend_redis_shingles_cmp(const void *a, const void *b) { const struct _rspamd_fuzzy_shingles_helper *sha = a, @@ -350,7 +350,7 @@ rspamd_fuzzy_redis_shingles_callback(redisAsyncContext *c, gpointer r, struct rspamd_fuzzy_reply rep; GString *key; struct _rspamd_fuzzy_shingles_helper *shingles, *prev = NULL, *sel = NULL; - guint i, found = 0, max_found = 0, cur_found = 0; + unsigned int i, found = 0, max_found = 0, cur_found = 0; ev_timer_stop(session->event_loop, &session->timeout); memset(&rep, 0, sizeof(rep)); @@ -413,7 +413,7 @@ rspamd_fuzzy_redis_shingles_callback(redisAsyncContext *c, gpointer r, /* Prepare new check command */ rspamd_fuzzy_redis_session_free_args(session); session->nargs = 5; - session->argv = g_malloc(sizeof(gchar *) * session->nargs); + session->argv = g_malloc(sizeof(char *) * session->nargs); session->argv_lens = g_malloc(sizeof(gsize) * session->nargs); key = g_string_new(session->backend->redis_object); @@ -436,7 +436,7 @@ rspamd_fuzzy_redis_shingles_callback(redisAsyncContext *c, gpointer r, if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_check_callback, session, session->nargs, - (const gchar **) session->argv, + (const char **) session->argv, session->argv_lens) != REDIS_OK) { if (session->callback.cb_check) { @@ -489,12 +489,12 @@ rspamd_fuzzy_backend_check_shingles(struct rspamd_fuzzy_redis_session *session) struct rspamd_fuzzy_reply rep; const struct rspamd_fuzzy_shingle_cmd *shcmd; GString *key; - guint i, init_len; + unsigned int i, init_len; rspamd_fuzzy_redis_session_free_args(session); /* First of all check digest */ session->nargs = RSPAMD_SHINGLE_SIZE + 1; - session->argv = g_malloc(sizeof(gchar *) * session->nargs); + session->argv = g_malloc(sizeof(char *) * session->nargs); session->argv_lens = g_malloc(sizeof(gsize) * session->nargs); shcmd = (const struct rspamd_fuzzy_shingle_cmd *) session->cmd; @@ -518,7 +518,7 @@ rspamd_fuzzy_backend_check_shingles(struct rspamd_fuzzy_redis_session *session) if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_shingles_callback, session, session->nargs, - (const gchar **) session->argv, session->argv_lens) != REDIS_OK) { + (const char **) session->argv, session->argv_lens) != REDIS_OK) { msg_err("cannot execute redis command on %s: %s", rspamd_inet_address_to_string_pretty(rspamd_upstream_addr_cur(session->up)), session->ctx->errstr); @@ -549,7 +549,7 @@ rspamd_fuzzy_redis_check_callback(redisAsyncContext *c, gpointer r, redisReply *reply = r, *cur; struct rspamd_fuzzy_reply rep; gulong value; - guint found_elts = 0; + unsigned int found_elts = 0; ev_timer_stop(session->event_loop, &session->timeout); memset(&rep, 0, sizeof(rep)); @@ -669,7 +669,7 @@ void rspamd_fuzzy_backend_check_redis(struct rspamd_fuzzy_backend *bk, /* First of all check digest */ session->nargs = 5; - session->argv = g_malloc(sizeof(gchar *) * session->nargs); + session->argv = g_malloc(sizeof(char *) * session->nargs); session->argv_lens = g_malloc(sizeof(gsize) * session->nargs); key = g_string_new(backend->redis_object); @@ -712,7 +712,7 @@ void rspamd_fuzzy_backend_check_redis(struct rspamd_fuzzy_backend *bk, else { if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_check_callback, session, session->nargs, - (const gchar **) session->argv, session->argv_lens) != REDIS_OK) { + (const char **) session->argv, session->argv_lens) != REDIS_OK) { rspamd_fuzzy_redis_session_dtor(session, TRUE); if (cb) { @@ -815,7 +815,7 @@ void rspamd_fuzzy_backend_count_redis(struct rspamd_fuzzy_backend *bk, session->event_loop = rspamd_fuzzy_backend_event_base(bk); session->nargs = 2; - session->argv = g_malloc(sizeof(gchar *) * 2); + session->argv = g_malloc(sizeof(char *) * 2); session->argv_lens = g_malloc(sizeof(gsize) * 2); key = g_string_new(backend->redis_object); g_string_append(key, "_count"); @@ -850,7 +850,7 @@ void rspamd_fuzzy_backend_count_redis(struct rspamd_fuzzy_backend *bk, else { if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_count_callback, session, session->nargs, - (const gchar **) session->argv, session->argv_lens) != REDIS_OK) { + (const char **) session->argv, session->argv_lens) != REDIS_OK) { rspamd_fuzzy_redis_session_dtor(session, TRUE); if (cb) { @@ -921,7 +921,7 @@ rspamd_fuzzy_redis_version_callback(redisAsyncContext *c, gpointer r, } void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk, - const gchar *src, + const char *src, rspamd_fuzzy_version_cb cb, void *ud, void *subr_ud) { @@ -953,7 +953,7 @@ void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk, session->event_loop = rspamd_fuzzy_backend_event_base(bk); session->nargs = 2; - session->argv = g_malloc(sizeof(gchar *) * 2); + session->argv = g_malloc(sizeof(char *) * 2); session->argv_lens = g_malloc(sizeof(gsize) * 2); key = g_string_new(backend->redis_object); g_string_append(key, src); @@ -988,7 +988,7 @@ void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk, else { if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_version_callback, session, session->nargs, - (const gchar **) session->argv, session->argv_lens) != REDIS_OK) { + (const char **) session->argv, session->argv_lens) != REDIS_OK) { rspamd_fuzzy_redis_session_dtor(session, TRUE); if (cb) { @@ -1007,7 +1007,7 @@ void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk, } } -const gchar * +const char * rspamd_fuzzy_backend_id_redis(struct rspamd_fuzzy_backend *bk, void *subr_ud) { @@ -1028,11 +1028,11 @@ void rspamd_fuzzy_backend_expire_redis(struct rspamd_fuzzy_backend *bk, static gboolean rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, struct rspamd_fuzzy_redis_session *session, - struct fuzzy_peer_cmd *io_cmd, guint *shift) + struct fuzzy_peer_cmd *io_cmd, unsigned int *shift) { GString *key, *value; - guint cur_shift = *shift; - guint i, klen; + unsigned int cur_shift = *shift; + unsigned int i, klen; struct rspamd_fuzzy_cmd *cmd; if (io_cmd->is_shingle) { @@ -1081,7 +1081,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 4, - (const gchar **) &session->argv[cur_shift - 4], + (const char **) &session->argv[cur_shift - 4], &session->argv_lens[cur_shift - 4]) != REDIS_OK) { return FALSE; @@ -1108,7 +1108,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 4, - (const gchar **) &session->argv[cur_shift - 4], + (const char **) &session->argv[cur_shift - 4], &session->argv_lens[cur_shift - 4]) != REDIS_OK) { return FALSE; @@ -1133,7 +1133,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 4, - (const gchar **) &session->argv[cur_shift - 4], + (const char **) &session->argv[cur_shift - 4], &session->argv_lens[cur_shift - 4]) != REDIS_OK) { return FALSE; @@ -1145,7 +1145,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, g_string_append_len(key, cmd->digest, sizeof(cmd->digest)); value = g_string_sized_new(sizeof("4294967296")); rspamd_printf_gstring(value, "%d", - (gint) rspamd_fuzzy_backend_get_expire(bk)); + (int) rspamd_fuzzy_backend_get_expire(bk)); session->argv[cur_shift] = g_strdup("EXPIRE"); session->argv_lens[cur_shift++] = sizeof("EXPIRE") - 1; session->argv[cur_shift] = key->str; @@ -1157,7 +1157,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 3, - (const gchar **) &session->argv[cur_shift - 3], + (const char **) &session->argv[cur_shift - 3], &session->argv_lens[cur_shift - 3]) != REDIS_OK) { return FALSE; @@ -1175,7 +1175,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 2, - (const gchar **) &session->argv[cur_shift - 2], + (const char **) &session->argv[cur_shift - 2], &session->argv_lens[cur_shift - 2]) != REDIS_OK) { return FALSE; @@ -1197,7 +1197,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 2, - (const gchar **) &session->argv[cur_shift - 2], + (const char **) &session->argv[cur_shift - 2], &session->argv_lens[cur_shift - 2]) != REDIS_OK) { return FALSE; @@ -1215,7 +1215,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 2, - (const gchar **) &session->argv[cur_shift - 2], + (const char **) &session->argv[cur_shift - 2], &session->argv_lens[cur_shift - 2]) != REDIS_OK) { return FALSE; @@ -1237,7 +1237,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, g_string_append_len(key, cmd->digest, sizeof(cmd->digest)); value = g_string_sized_new(sizeof("4294967296")); rspamd_printf_gstring(value, "%d", - (gint) rspamd_fuzzy_backend_get_expire(bk)); + (int) rspamd_fuzzy_backend_get_expire(bk)); session->argv[cur_shift] = g_strdup("EXPIRE"); session->argv_lens[cur_shift++] = sizeof("EXPIRE") - 1; session->argv[cur_shift] = key->str; @@ -1249,7 +1249,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 3, - (const gchar **) &session->argv[cur_shift - 3], + (const char **) &session->argv[cur_shift - 3], &session->argv_lens[cur_shift - 3]) != REDIS_OK) { return FALSE; @@ -1268,7 +1268,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, 64 + 1; for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) { - guchar *hval; + unsigned char *hval; /* * For each command with shingles we additionally emit 32 commands: * SETEX __ @@ -1282,7 +1282,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, io_cmd->cmd.shingle.sgl.hashes[i]); value = g_string_sized_new(sizeof("4294967296")); rspamd_printf_gstring(value, "%d", - (gint) rspamd_fuzzy_backend_get_expire(bk)); + (int) rspamd_fuzzy_backend_get_expire(bk)); hval = g_malloc(sizeof(io_cmd->cmd.shingle.basic.digest)); memcpy(hval, io_cmd->cmd.shingle.basic.digest, sizeof(io_cmd->cmd.shingle.basic.digest)); @@ -1299,7 +1299,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 4, - (const gchar **) &session->argv[cur_shift - 4], + (const char **) &session->argv[cur_shift - 4], &session->argv_lens[cur_shift - 4]) != REDIS_OK) { return FALSE; @@ -1324,7 +1324,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 2, - (const gchar **) &session->argv[cur_shift - 2], + (const char **) &session->argv[cur_shift - 2], &session->argv_lens[cur_shift - 2]) != REDIS_OK) { return FALSE; @@ -1349,7 +1349,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, io_cmd->cmd.shingle.sgl.hashes[i]); value = g_string_sized_new(sizeof("18446744073709551616")); rspamd_printf_gstring(value, "%d", - (gint) rspamd_fuzzy_backend_get_expire(bk)); + (int) rspamd_fuzzy_backend_get_expire(bk)); session->argv[cur_shift] = g_strdup("EXPIRE"); session->argv_lens[cur_shift++] = sizeof("EXPIRE") - 1; session->argv[cur_shift] = key->str; @@ -1361,7 +1361,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 3, - (const gchar **) &session->argv[cur_shift - 3], + (const char **) &session->argv[cur_shift - 3], &session->argv_lens[cur_shift - 3]) != REDIS_OK) { return FALSE; @@ -1431,7 +1431,7 @@ rspamd_fuzzy_redis_update_callback(redisAsyncContext *c, gpointer r, } void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, - GArray *updates, const gchar *src, + GArray *updates, const char *src, rspamd_fuzzy_update_cb cb, void *ud, void *subr_ud) { @@ -1440,11 +1440,11 @@ void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, struct upstream *up; struct upstream_list *ups; rspamd_inet_addr_t *addr; - guint i; + unsigned int i; GString *key; struct fuzzy_peer_cmd *io_cmd; struct rspamd_fuzzy_cmd *cmd = NULL; - guint nargs, cur_shift; + unsigned int nargs, cur_shift; g_assert(backend != NULL); @@ -1532,7 +1532,7 @@ void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, /* First of all check digest */ session->nargs = nargs; - session->argv = g_malloc0(sizeof(gchar *) * session->nargs); + session->argv = g_malloc0(sizeof(char *) * session->nargs); session->argv_lens = g_malloc0(sizeof(gsize) * session->nargs); up = rspamd_upstream_get(ups, @@ -1564,7 +1564,7 @@ void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 1, - (const gchar **) session->argv, + (const char **) session->argv, session->argv_lens) != REDIS_OK) { if (cb) { @@ -1603,7 +1603,7 @@ void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, NULL, NULL, 2, - (const gchar **) &session->argv[cur_shift - 2], + (const char **) &session->argv[cur_shift - 2], &session->argv_lens[cur_shift - 2]) != REDIS_OK) { if (cb) { @@ -1621,7 +1621,7 @@ void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_update_callback, session, 1, - (const gchar **) &session->argv[cur_shift], + (const char **) &session->argv[cur_shift], &session->argv_lens[cur_shift]) != REDIS_OK) { if (cb) { diff --git a/src/libserver/fuzzy_backend/fuzzy_backend_redis.h b/src/libserver/fuzzy_backend/fuzzy_backend_redis.h index 3cfa16259..afeb1c573 100644 --- a/src/libserver/fuzzy_backend/fuzzy_backend_redis.h +++ b/src/libserver/fuzzy_backend/fuzzy_backend_redis.h @@ -38,7 +38,7 @@ void rspamd_fuzzy_backend_check_redis(struct rspamd_fuzzy_backend *bk, void *subr_ud); void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, - GArray *updates, const gchar *src, + GArray *updates, const char *src, rspamd_fuzzy_update_cb cb, void *ud, void *subr_ud); @@ -47,12 +47,12 @@ void rspamd_fuzzy_backend_count_redis(struct rspamd_fuzzy_backend *bk, void *subr_ud); void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk, - const gchar *src, + const char *src, rspamd_fuzzy_version_cb cb, void *ud, void *subr_ud); -const gchar *rspamd_fuzzy_backend_id_redis(struct rspamd_fuzzy_backend *bk, - void *subr_ud); +const char *rspamd_fuzzy_backend_id_redis(struct rspamd_fuzzy_backend *bk, + void *subr_ud); void rspamd_fuzzy_backend_expire_redis(struct rspamd_fuzzy_backend *bk, void *subr_ud); diff --git a/src/libserver/fuzzy_backend/fuzzy_backend_sqlite.c b/src/libserver/fuzzy_backend/fuzzy_backend_sqlite.c index df91c65b0..8ba625446 100644 --- a/src/libserver/fuzzy_backend/fuzzy_backend_sqlite.c +++ b/src/libserver/fuzzy_backend/fuzzy_backend_sqlite.c @@ -25,14 +25,14 @@ struct rspamd_fuzzy_backend_sqlite { sqlite3 *db; char *path; - gchar id[MEMPOOL_UID_LEN]; + char id[MEMPOOL_UID_LEN]; gsize count; gsize expired; rspamd_mempool_t *pool; }; -static const gdouble sql_sleep_time = 0.1; -static const guint max_retries = 10; +static const double sql_sleep_time = 0.1; +static const unsigned int max_retries = 10; #define msg_err_fuzzy_backend(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \ backend->pool->tag.tagname, backend->pool->tag.uid, \ @@ -107,10 +107,10 @@ enum rspamd_fuzzy_statement_idx { }; static struct rspamd_fuzzy_stmts { enum rspamd_fuzzy_statement_idx idx; - const gchar *sql; - const gchar *args; + const char *sql; + const char *args; sqlite3_stmt *stmt; - gint result; + int result; } prepared_stmts[RSPAMD_FUZZY_BACKEND_MAX] = { {.idx = RSPAMD_FUZZY_BACKEND_TRANSACTION_START, @@ -267,7 +267,7 @@ rspamd_fuzzy_backend_sqlite_run_stmt(struct rspamd_fuzzy_backend_sqlite *backend sqlite3_stmt *stmt; int i; const char *argtypes; - guint retries = 0; + unsigned int retries = 0; struct timespec ts; if (idx < 0 || idx >= RSPAMD_FUZZY_BACKEND_MAX) { @@ -306,7 +306,7 @@ rspamd_fuzzy_backend_sqlite_run_stmt(struct rspamd_fuzzy_backend_sqlite *backend sqlite3_bind_int64(stmt, i + 1, va_arg(ap, int64_t)); break; case 'S': - sqlite3_bind_int(stmt, i + 1, va_arg(ap, gint)); + sqlite3_bind_int(stmt, i + 1, va_arg(ap, int)); break; case 'D': /* Special case for digests variable */ @@ -361,12 +361,12 @@ rspamd_fuzzy_backend_sqlite_close_stmts(struct rspamd_fuzzy_backend_sqlite *bk) } static gboolean -rspamd_fuzzy_backend_sqlite_run_sql(const gchar *sql, struct rspamd_fuzzy_backend_sqlite *bk, +rspamd_fuzzy_backend_sqlite_run_sql(const char *sql, struct rspamd_fuzzy_backend_sqlite *bk, GError **err) { - guint retries = 0; + unsigned int retries = 0; struct timespec ts; - gint ret; + int ret; do { ret = sqlite3_exec(bk->db, sql, NULL, NULL, NULL); @@ -385,11 +385,11 @@ rspamd_fuzzy_backend_sqlite_run_sql(const gchar *sql, struct rspamd_fuzzy_backen } static struct rspamd_fuzzy_backend_sqlite * -rspamd_fuzzy_backend_sqlite_open_db(const gchar *path, GError **err) +rspamd_fuzzy_backend_sqlite_open_db(const char *path, GError **err) { struct rspamd_fuzzy_backend_sqlite *bk; rspamd_cryptobox_hash_state_t st; - guchar hash_out[rspamd_cryptobox_HASHBYTES]; + unsigned char hash_out[rspamd_cryptobox_HASHBYTES]; g_assert(path != NULL); @@ -424,7 +424,7 @@ rspamd_fuzzy_backend_sqlite_open_db(const gchar *path, GError **err) } struct rspamd_fuzzy_backend_sqlite * -rspamd_fuzzy_backend_sqlite_open(const gchar *path, +rspamd_fuzzy_backend_sqlite_open(const char *path, gboolean vacuum, GError **err) { @@ -451,7 +451,7 @@ rspamd_fuzzy_backend_sqlite_open(const gchar *path, return backend; } -static gint +static int rspamd_fuzzy_backend_sqlite_int64_cmp(const void *a, const void *b) { int64_t ia = *(int64_t *) a, ib = *(int64_t *) b; @@ -605,9 +605,9 @@ rspamd_fuzzy_backend_sqlite_check(struct rspamd_fuzzy_backend_sqlite *backend, gboolean rspamd_fuzzy_backend_sqlite_prepare_update(struct rspamd_fuzzy_backend_sqlite *backend, - const gchar *source) + const char *source) { - gint rc; + int rc; if (backend == NULL) { return FALSE; @@ -657,8 +657,8 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, if (rc != SQLITE_OK) { msg_warn_fuzzy_backend("cannot update hash to %d -> " "%*xs: %s", - (gint) cmd->flag, - (gint) sizeof(cmd->digest), cmd->digest, + (int) cmd->flag, + (int) sizeof(cmd->digest), cmd->digest, sqlite3_errmsg(backend->db)); } } @@ -674,8 +674,8 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, if (rc != SQLITE_OK) { msg_warn_fuzzy_backend("cannot update hash to %d -> " "%*xs: %s", - (gint) cmd->flag, - (gint) sizeof(cmd->digest), cmd->digest, + (int) cmd->flag, + (int) sizeof(cmd->digest), cmd->digest, sqlite3_errmsg(backend->db)); } } @@ -684,7 +684,7 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, rspamd_fuzzy_backend_sqlite_cleanup_stmt(backend, RSPAMD_FUZZY_BACKEND_CHECK); rc = rspamd_fuzzy_backend_sqlite_run_stmt(backend, FALSE, RSPAMD_FUZZY_BACKEND_INSERT, - (gint) cmd->flag, + (int) cmd->flag, cmd->digest, (int64_t) cmd->value); @@ -715,8 +715,8 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, else { msg_warn_fuzzy_backend("cannot add hash to %d -> " "%*xs: %s", - (gint) cmd->flag, - (gint) sizeof(cmd->digest), cmd->digest, + (int) cmd->flag, + (int) sizeof(cmd->digest), cmd->digest, sqlite3_errmsg(backend->db)); } @@ -729,9 +729,9 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, gboolean rspamd_fuzzy_backend_sqlite_finish_update(struct rspamd_fuzzy_backend_sqlite *backend, - const gchar *source, gboolean version_bump) + const char *source, gboolean version_bump) { - gint rc = SQLITE_OK, wal_frames, wal_checkpointed, ver; + int rc = SQLITE_OK, wal_frames, wal_checkpointed, ver; /* Get and update version */ if (version_bump) { @@ -800,8 +800,8 @@ rspamd_fuzzy_backend_sqlite_del(struct rspamd_fuzzy_backend_sqlite *backend, if (rc != SQLITE_OK) { msg_warn_fuzzy_backend("cannot update hash to %d -> " "%*xs: %s", - (gint) cmd->flag, - (gint) sizeof(cmd->digest), cmd->digest, + (int) cmd->flag, + (int) sizeof(cmd->digest), cmd->digest, sqlite3_errmsg(backend->db)); } } @@ -827,13 +827,13 @@ rspamd_fuzzy_backend_sqlite_sync(struct rspamd_fuzzy_backend_sqlite *backend, const uint64_t max_changes = 5000; gboolean ret = FALSE; int64_t expire_lim, expired; - gint rc, i, orphaned_cnt = 0; + int rc, i, orphaned_cnt = 0; GError *err = NULL; - static const gchar orphaned_shingles[] = "SELECT shingles.value,shingles.number " - "FROM shingles " - "LEFT JOIN digests ON " - "shingles.digest_id=digests.id WHERE " - "digests.id IS NULL;"; + static const char orphaned_shingles[] = "SELECT shingles.value,shingles.number " + "FROM shingles " + "LEFT JOIN digests ON " + "shingles.digest_id=digests.id WHERE " + "digests.id IS NULL;"; sqlite3_stmt *stmt; GArray *orphaned; struct orphaned_shingle_elt orphaned_elt, *pelt; @@ -925,7 +925,7 @@ rspamd_fuzzy_backend_sqlite_sync(struct rspamd_fuzzy_backend_sqlite *backend, "going to delete %ud orphaned shingles", orphaned_cnt); /* Need to delete orphaned elements */ - for (i = 0; i < (gint) orphaned_cnt; i++) { + for (i = 0; i < (int) orphaned_cnt; i++) { pelt = &g_array_index(orphaned, struct orphaned_shingle_elt, i); @@ -999,10 +999,10 @@ gsize rspamd_fuzzy_backend_sqlite_count(struct rspamd_fuzzy_backend_sqlite *back return 0; } -gint rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, - const gchar *source) +int rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, + const char *source) { - gint ret = 0; + int ret = 0; if (backend) { if (rspamd_fuzzy_backend_sqlite_run_stmt(backend, FALSE, @@ -1022,7 +1022,7 @@ gsize rspamd_fuzzy_backend_sqlite_expired(struct rspamd_fuzzy_backend_sqlite *ba return backend != NULL ? backend->expired : 0; } -const gchar * +const char * rspamd_fuzzy_sqlite_backend_id(struct rspamd_fuzzy_backend_sqlite *backend) { return backend != NULL ? backend->id : 0; diff --git a/src/libserver/fuzzy_backend/fuzzy_backend_sqlite.h b/src/libserver/fuzzy_backend/fuzzy_backend_sqlite.h index 62c028f3d..1ace52f35 100644 --- a/src/libserver/fuzzy_backend/fuzzy_backend_sqlite.h +++ b/src/libserver/fuzzy_backend/fuzzy_backend_sqlite.h @@ -31,7 +31,7 @@ struct rspamd_fuzzy_backend_sqlite; * @param err error pointer * @return backend structure or NULL */ -struct rspamd_fuzzy_backend_sqlite *rspamd_fuzzy_backend_sqlite_open(const gchar *path, +struct rspamd_fuzzy_backend_sqlite *rspamd_fuzzy_backend_sqlite_open(const char *path, gboolean vacuum, GError **err); @@ -50,7 +50,7 @@ struct rspamd_fuzzy_reply rspamd_fuzzy_backend_sqlite_check( * Prepare storage for updates (by starting transaction) */ gboolean rspamd_fuzzy_backend_sqlite_prepare_update(struct rspamd_fuzzy_backend_sqlite *backend, - const gchar *source); + const char *source); /** * Add digest to the database @@ -75,7 +75,7 @@ gboolean rspamd_fuzzy_backend_sqlite_del( * Commit updates to storage */ gboolean rspamd_fuzzy_backend_sqlite_finish_update(struct rspamd_fuzzy_backend_sqlite *backend, - const gchar *source, gboolean version_bump); + const char *source, gboolean version_bump); /** * Sync storage @@ -94,11 +94,11 @@ void rspamd_fuzzy_backend_sqlite_close(struct rspamd_fuzzy_backend_sqlite *backe gsize rspamd_fuzzy_backend_sqlite_count(struct rspamd_fuzzy_backend_sqlite *backend); -gint rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, const gchar *source); +int rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, const char *source); gsize rspamd_fuzzy_backend_sqlite_expired(struct rspamd_fuzzy_backend_sqlite *backend); -const gchar *rspamd_fuzzy_sqlite_backend_id(struct rspamd_fuzzy_backend_sqlite *backend); +const char *rspamd_fuzzy_sqlite_backend_id(struct rspamd_fuzzy_backend_sqlite *backend); #ifdef __cplusplus } diff --git a/src/libserver/fuzzy_wire.h b/src/libserver/fuzzy_wire.h index 40ca66c97..d67e38d7a 100644 --- a/src/libserver/fuzzy_wire.h +++ b/src/libserver/fuzzy_wire.h @@ -54,13 +54,13 @@ enum rspamd_fuzzy_epoch { RSPAMD_PACKED(rspamd_fuzzy_cmd) { - guint8 version; - guint8 cmd; - guint8 shingles_count; - guint8 flag; + uint8_t version; + uint8_t cmd; + uint8_t shingles_count; + uint8_t flag; int32_t value; uint32_t tag; - gchar digest[rspamd_cryptobox_HASHBYTES]; + char digest[rspamd_cryptobox_HASHBYTES]; }; RSPAMD_PACKED(rspamd_fuzzy_shingle_cmd) @@ -80,18 +80,18 @@ RSPAMD_PACKED(rspamd_fuzzy_reply_v1) RSPAMD_PACKED(rspamd_fuzzy_reply) { struct rspamd_fuzzy_reply_v1 v1; - gchar digest[rspamd_cryptobox_HASHBYTES]; + char digest[rspamd_cryptobox_HASHBYTES]; uint32_t ts; - guchar reserved[12]; + unsigned char reserved[12]; }; RSPAMD_PACKED(rspamd_fuzzy_encrypted_req_hdr) { - guchar magic[4]; - guchar key_id[RSPAMD_FUZZY_KEYLEN]; - guchar pubkey[32]; - guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES]; - guchar mac[rspamd_cryptobox_MAX_MACBYTES]; + unsigned char magic[4]; + unsigned char key_id[RSPAMD_FUZZY_KEYLEN]; + unsigned char pubkey[32]; + unsigned char nonce[rspamd_cryptobox_MAX_NONCEBYTES]; + unsigned char mac[rspamd_cryptobox_MAX_MACBYTES]; }; RSPAMD_PACKED(rspamd_fuzzy_encrypted_cmd) @@ -108,8 +108,8 @@ RSPAMD_PACKED(rspamd_fuzzy_encrypted_shingle_cmd) RSPAMD_PACKED(rspamd_fuzzy_encrypted_rep_hdr) { - guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES]; - guchar mac[rspamd_cryptobox_MAX_MACBYTES]; + unsigned char nonce[rspamd_cryptobox_MAX_NONCEBYTES]; + unsigned char mac[rspamd_cryptobox_MAX_MACBYTES]; }; RSPAMD_PACKED(rspamd_fuzzy_encrypted_reply) @@ -118,7 +118,7 @@ RSPAMD_PACKED(rspamd_fuzzy_encrypted_reply) struct rspamd_fuzzy_reply rep; }; -static const guchar fuzzy_encrypted_magic[4] = {'r', 's', 'f', 'e'}; +static const unsigned char fuzzy_encrypted_magic[4] = {'r', 's', 'f', 'e'}; enum rspamd_fuzzy_extension_type { RSPAMD_FUZZY_EXT_SOURCE_DOMAIN = 'd', @@ -128,13 +128,13 @@ enum rspamd_fuzzy_extension_type { struct rspamd_fuzzy_cmd_extension { enum rspamd_fuzzy_extension_type ext; - guint length; + unsigned int length; struct rspamd_fuzzy_cmd_extension *next; - guchar *payload; + unsigned char *payload; }; struct rspamd_fuzzy_stat_entry { - const gchar *name; + const char *name; uint64_t fuzzy_cnt; }; diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx index 5861d45b6..0fe31c2a3 100644 --- a/src/libserver/html/html.cxx +++ b/src/libserver/html/html.cxx @@ -43,7 +43,7 @@ namespace rspamd::html { -static const guint max_tags = 8192; /* Ignore tags if this maximum is reached */ +static const unsigned int max_tags = 8192; /* Ignore tags if this maximum is reached */ static const html_tags_storage html_tags_defs; @@ -658,7 +658,7 @@ html_process_url_tag(rspamd_mempool_t *pool, "%*s%s%*s", (int) hc->base_url->urllen, hc->base_url->string, need_slash ? "/" : "", - (gint) orig_len, href_value.data()); + (int) orig_len, href_value.data()); href_value = {buf, nlen}; } else if (href_value.size() > 2 && href_value[0] == '/' && href_value[1] != '/') { @@ -670,7 +670,7 @@ html_process_url_tag(rspamd_mempool_t *pool, auto nlen = (std::size_t) rspamd_snprintf(buf, len + 1, "%*s://%*s/%*s", (int) hc->base_url->protocollen, hc->base_url->string, (int) hc->base_url->hostlen, rspamd_url_host_unsafe(hc->base_url), - (gint) orig_len, href_value.data()); + (int) orig_len, href_value.data()); href_value = {buf, nlen}; } } @@ -769,21 +769,21 @@ html_process_data_image(rspamd_mempool_t *pool, * We ignore content type so far */ struct rspamd_image *parsed_image; - const gchar *semicolon_pos = input.data(), - *end = input.data() + input.size(); + const char *semicolon_pos = input.data(), + *end = input.data() + input.size(); - if ((semicolon_pos = (const gchar *) memchr(semicolon_pos, ';', end - semicolon_pos)) != NULL) { + if ((semicolon_pos = (const char *) memchr(semicolon_pos, ';', end - semicolon_pos)) != NULL) { if (end - semicolon_pos > sizeof("base64,")) { if (memcmp(semicolon_pos + 1, "base64,", sizeof("base64,") - 1) == 0) { - const gchar *data_pos = semicolon_pos + sizeof("base64,"); - gchar *decoded; + const char *data_pos = semicolon_pos + sizeof("base64,"); + char *decoded; gsize encoded_len = end - data_pos, decoded_len; rspamd_ftok_t inp; decoded_len = (encoded_len / 4 * 3) + 12; decoded = rspamd_mempool_alloc_buffer(pool, decoded_len); rspamd_cryptobox_base64_decode(data_pos, encoded_len, - reinterpret_cast(decoded), &decoded_len); + reinterpret_cast(decoded), &decoded_len); inp.begin = decoded; inp.len = decoded_len; @@ -1108,7 +1108,7 @@ html_process_displayed_href_tag(rspamd_mempool_t *pool, static auto html_append_tag_content(rspamd_mempool_t *pool, - const gchar *start, gsize len, + const char *start, gsize len, struct html_content *hc, html_tag *tag, GList **exceptions, @@ -1329,12 +1329,12 @@ auto html_process_input(struct rspamd_task *task, bool allow_css, std::uint16_t *cur_url_order) -> html_content * { - const gchar *p, *c, *end, *start; - guchar t; + const char *p, *c, *end, *start; + unsigned char t; auto closing = false; - guint obrace = 0, ebrace = 0; + unsigned int obrace = 0, ebrace = 0; struct rspamd_url *url = nullptr; - gint href_offset = -1; + int href_offset = -1; auto overflow_input = false; struct html_tag *cur_tag = nullptr, *parent_tag = nullptr, cur_closing_tag; struct tag_content_parser_state content_parser_env; @@ -1819,8 +1819,8 @@ auto html_process_input(struct rspamd_task *task, * Since closing tags must not have attributes, these assumptions * seems to be reasonable enough for our toy parser. */ - gint cur_lookahead = 1; - gint max_lookahead = MIN(end - p, 30); + int cur_lookahead = 1; + int max_lookahead = MIN(end - p, 30); bool valid_closing_tag = true; if (p + 1 < end && !g_ascii_isalpha(p[1])) { @@ -1828,7 +1828,7 @@ auto html_process_input(struct rspamd_task *task, } else { while (cur_lookahead < max_lookahead) { - gchar tt = p[cur_lookahead]; + char tt = p[cur_lookahead]; if (tt == '>') { break; } @@ -2296,12 +2296,12 @@ rspamd_html_process_part(rspamd_mempool_t *pool, NULL, NULL, FALSE, &order); } -guint rspamd_html_decode_entitles_inplace(gchar *s, gsize len) +unsigned int rspamd_html_decode_entitles_inplace(char *s, gsize len) { return rspamd::html::decode_html_entitles_inplace(s, len); } -gint rspamd_html_tag_by_name(const gchar *name) +int rspamd_html_tag_by_name(const char *name) { const auto *td = rspamd::html::html_tags_defs.by_name(name); @@ -2313,9 +2313,9 @@ gint rspamd_html_tag_by_name(const gchar *name) } gboolean -rspamd_html_tag_seen(void *ptr, const gchar *tagname) +rspamd_html_tag_seen(void *ptr, const char *tagname) { - gint id; + int id; auto *hc = rspamd::html::html_content::from_ptr(ptr); g_assert(hc != NULL); @@ -2329,8 +2329,8 @@ rspamd_html_tag_seen(void *ptr, const gchar *tagname) return FALSE; } -const gchar * -rspamd_html_tag_by_id(gint id) +const char * +rspamd_html_tag_by_id(int id) { if (id > Tag_UNKNOWN && id < Tag_MAX) { const auto *td = rspamd::html::html_tags_defs.by_id(id); @@ -2343,7 +2343,7 @@ rspamd_html_tag_by_id(gint id) return nullptr; } -const gchar * +const char * rspamd_html_tag_name(void *p, gsize *len) { auto *tag = reinterpret_cast(p); diff --git a/src/libserver/html/html.h b/src/libserver/html/html.h index 2d34f2a2e..1bab2d10e 100644 --- a/src/libserver/html/html.h +++ b/src/libserver/html/html.h @@ -49,10 +49,10 @@ extern "C" { struct rspamd_image; struct html_image { - guint height; - guint width; - guint flags; - gchar *src; + unsigned int height; + unsigned int width; + unsigned int flags; + char *src; struct rspamd_url *url; struct rspamd_image *embedded_image; void *tag; @@ -65,7 +65,7 @@ struct rspamd_task; /* * Decode HTML entitles in text. Text is modified in place. */ -guint rspamd_html_decode_entitles_inplace(gchar *s, gsize len); +unsigned int rspamd_html_decode_entitles_inplace(char *s, gsize len); void *rspamd_html_process_part(rspamd_mempool_t *pool, GByteArray *in); @@ -80,21 +80,21 @@ void *rspamd_html_process_part_full(struct rspamd_task *task, /* * Returns true if a specified tag has been seen in a part */ -gboolean rspamd_html_tag_seen(void *ptr, const gchar *tagname); +gboolean rspamd_html_tag_seen(void *ptr, const char *tagname); /** * Returns name for the specified tag id * @param id * @return */ -const gchar *rspamd_html_tag_by_id(gint id); +const char *rspamd_html_tag_by_id(int id); /** * Returns HTML tag id by name * @param name * @return */ -gint rspamd_html_tag_by_name(const gchar *name); +int rspamd_html_tag_by_name(const char *name); /** * Gets a name for a tag @@ -102,7 +102,7 @@ gint rspamd_html_tag_by_name(const gchar *name); * @param len * @return */ -const gchar *rspamd_html_tag_name(void *tag, gsize *len); +const char *rspamd_html_tag_name(void *tag, gsize *len); /** * Find HTML image by content id diff --git a/src/libserver/html/html.hxx b/src/libserver/html/html.hxx index 3320fd634..4d6955994 100644 --- a/src/libserver/html/html.hxx +++ b/src/libserver/html/html.hxx @@ -42,7 +42,7 @@ struct html_block; struct html_content { struct rspamd_url *base_url = nullptr; struct html_tag *root_tag = nullptr; - gint flags = 0; + int flags = 0; std::vector tags_seen; std::vector images; std::vector> all_tags; diff --git a/src/libserver/html/html_entities.cxx b/src/libserver/html/html_entities.cxx index c64253617..d7c709f2d 100644 --- a/src/libserver/html/html_entities.cxx +++ b/src/libserver/html/html_entities.cxx @@ -2237,7 +2237,7 @@ decode_html_entitles_inplace(char *s, std::size_t len, bool norm_spaces) * e - begin of entity */ char *t = s, *h = s, *e = s; - const gchar *end; + const char *end; bool seen_hash = false, seen_hex = false; enum { do_undefined, diff --git a/src/libserver/html/html_tag_defs.hxx b/src/libserver/html/html_tag_defs.hxx index 647f7c3c5..4cff79855 100644 --- a/src/libserver/html/html_tag_defs.hxx +++ b/src/libserver/html/html_tag_defs.hxx @@ -28,7 +28,7 @@ namespace rspamd::html { struct html_tag_def { std::string name; tag_id_t id; - guint flags; + unsigned int flags; }; #define TAG_DEF(id, name, flags) \ diff --git a/src/libserver/html/html_tests.cxx b/src/libserver/html/html_tests.cxx index 2fe6702df..00595feaa 100644 --- a/src/libserver/html/html_tests.cxx +++ b/src/libserver/html/html_tests.cxx @@ -1,11 +1,11 @@ -/*- - * Copyright 2021 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -59,7 +59,7 @@ TEST_SUITE("html") SUBCASE((std::string("extract tags from: ") + c.first).c_str()) { GByteArray *tmp = g_byte_array_sized_new(c.first.size()); - g_byte_array_append(tmp, (const guint8 *) c.first.data(), c.first.size()); + g_byte_array_append(tmp, (const uint8_t *) c.first.data(), c.first.size()); auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, nullptr, true, nullptr); CHECK(hc != nullptr); auto dump = html_debug_structure(*hc); @@ -230,7 +230,7 @@ TEST_SUITE("html") SUBCASE((fmt::format("html extraction case {}", i)).c_str()) { GByteArray *tmp = g_byte_array_sized_new(c.first.size()); - g_byte_array_append(tmp, (const guint8 *) c.first.data(), c.first.size()); + g_byte_array_append(tmp, (const uint8_t *) c.first.data(), c.first.size()); auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, nullptr, true, nullptr); CHECK(hc != nullptr); replace_newlines(hc->parsed); @@ -278,7 +278,7 @@ TEST_SUITE("html") GPtrArray *purls = g_ptr_array_new(); auto input = std::get<0>(c); GByteArray *tmp = g_byte_array_sized_new(input.size()); - g_byte_array_append(tmp, (const guint8 *) input.data(), input.size()); + g_byte_array_append(tmp, (const uint8_t *) input.data(), input.size()); auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, purls, true, nullptr); CHECK(hc != nullptr); auto &expected_text = std::get<2>(c); diff --git a/src/libserver/html/html_url.cxx b/src/libserver/html/html_url.cxx index 8f29f2c46..35d6c3f78 100644 --- a/src/libserver/html/html_url.cxx +++ b/src/libserver/html/html_url.cxx @@ -137,7 +137,7 @@ auto html_url_is_phished(rspamd_mempool_t *pool, struct rspamd_url *text_url; std::string_view disp_tok, href_tok; goffset url_pos; - gchar *url_str = NULL; + char *url_str = NULL; auto sz = text_data.size(); const auto *trimmed = rspamd_string_unicode_trim_inplace(text_data.data(), &sz); @@ -234,7 +234,7 @@ void html_check_displayed_url(rspamd_mempool_t *pool, struct rspamd_url *displayed_url = nullptr; struct rspamd_url *turl; struct rspamd_process_exception *ex; - guint saved_flags = 0; + unsigned int saved_flags = 0; gsize dlen; if (visible_part.empty()) { @@ -311,13 +311,13 @@ auto html_process_url(rspamd_mempool_t *pool, std::string_view &input) -> std::optional { struct rspamd_url *url; - guint saved_flags = 0; - gint rc; - const gchar *s, *prefix = "http://"; - gchar *d; + unsigned int saved_flags = 0; + int rc; + const char *s, *prefix = "http://"; + char *d; gsize dlen; gboolean has_bad_chars = FALSE, no_prefix = FALSE; - static const gchar hexdigests[] = "0123456789abcdef"; + static const char hexdigests[] = "0123456789abcdef"; auto sz = input.length(); const auto *trimmed = rspamd_string_unicode_trim_inplace(input.data(), &sz); @@ -328,7 +328,7 @@ auto html_process_url(rspamd_mempool_t *pool, std::string_view &input) dlen = 0; for (auto i = 0; i < sz; i++) { - if (G_UNLIKELY(((guint) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) { + if (G_UNLIKELY(((unsigned int) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) { dlen += 3; } else { @@ -397,7 +397,7 @@ auto html_process_url(rspamd_mempool_t *pool, std::string_view &input) if (G_UNLIKELY(g_ascii_isspace(s[i]))) { continue; } - else if (G_UNLIKELY(((guint) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) { + else if (G_UNLIKELY(((unsigned int) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) { /* URL encode */ *d++ = '%'; *d++ = hexdigests[(s[i] >> 4) & 0xf]; diff --git a/src/libserver/http/http_connection.c b/src/libserver/http/http_connection.c index 5557fbf25..ef39e11e7 100644 --- a/src/libserver/http/http_connection.c +++ b/src/libserver/http/http_connection.c @@ -39,7 +39,7 @@ struct _rspamd_http_privbuf { rspamd_fstring_t *data; - const gchar *zc_buf; + const char *zc_buf; gsize zc_remain; ref_entry_t ref; }; @@ -72,7 +72,7 @@ struct rspamd_http_connection_private { ev_tstamp timeout; struct rspamd_http_message *msg; struct iovec *out; - guint outlen; + unsigned int outlen; enum rspamd_http_priv_flags flags; gsize wr_pos; gsize wr_total; @@ -111,8 +111,8 @@ rspamd_http_privbuf_dtor(gpointer ud) g_free(p); } -static const gchar * -rspamd_http_code_to_str(gint code) +static const char * +rspamd_http_code_to_str(int code) { if (code == 200) { return "OK"; @@ -140,8 +140,8 @@ static void rspamd_http_parse_key(rspamd_ftok_t *data, struct rspamd_http_connection *conn, struct rspamd_http_connection_private *priv) { - guchar *decoded_id; - const gchar *eq_pos; + unsigned char *decoded_id; + const char *eq_pos; gsize id_len; struct rspamd_cryptobox_pubkey *pk; @@ -203,8 +203,8 @@ rspamd_http_check_special_header(struct rspamd_http_connection *conn, } } -static gint -rspamd_http_on_url(http_parser *parser, const gchar *at, size_t length) +static int +rspamd_http_on_url(http_parser *parser, const char *at, size_t length) { struct rspamd_http_connection *conn = (struct rspamd_http_connection *) parser->data; @@ -217,8 +217,8 @@ rspamd_http_on_url(http_parser *parser, const gchar *at, size_t length) return 0; } -static gint -rspamd_http_on_status(http_parser *parser, const gchar *at, size_t length) +static int +rspamd_http_on_status(http_parser *parser, const char *at, size_t length) { struct rspamd_http_connection *conn = (struct rspamd_http_connection *) parser->data; @@ -243,7 +243,7 @@ rspamd_http_finish_header(struct rspamd_http_connection *conn, { struct rspamd_http_header *hdr; khiter_t k; - gint r; + int r; priv->header->combined = rspamd_fstring_append(priv->header->combined, "\r\n", 2); @@ -276,9 +276,9 @@ rspamd_http_init_header(struct rspamd_http_connection_private *priv) priv->header->combined = rspamd_fstring_new(); } -static gint +static int rspamd_http_on_header_field(http_parser *parser, - const gchar *at, + const char *at, size_t length) { struct rspamd_http_connection *conn = @@ -302,9 +302,9 @@ rspamd_http_on_header_field(http_parser *parser, return 0; } -static gint +static int rspamd_http_on_header_value(http_parser *parser, - const gchar *at, + const char *at, size_t length) { struct rspamd_http_connection *conn = @@ -412,14 +412,14 @@ rspamd_http_switch_zc(struct _rspamd_http_privbuf *pbuf, } static int -rspamd_http_on_body(http_parser *parser, const gchar *at, size_t length) +rspamd_http_on_body(http_parser *parser, const char *at, size_t length) { struct rspamd_http_connection *conn = (struct rspamd_http_connection *) parser->data; struct rspamd_http_connection_private *priv; struct rspamd_http_message *msg; struct _rspamd_http_privbuf *pbuf; - const gchar *p; + const char *p; priv = conn->priv; msg = priv->msg; @@ -457,7 +457,7 @@ rspamd_http_on_body(http_parser *parser, const gchar *at, size_t length) else { if (msg->body_buf.begin + msg->body_buf.len != at) { /* Likely chunked encoding */ - memmove((gchar *) msg->body_buf.begin + msg->body_buf.len, at, length); + memmove((char *) msg->body_buf.begin + msg->body_buf.len, at, length); p = msg->body_buf.begin + msg->body_buf.len; } @@ -481,7 +481,7 @@ rspamd_http_on_body(http_parser *parser, const gchar *at, size_t length) } static int -rspamd_http_on_body_decrypted(http_parser *parser, const gchar *at, size_t length) +rspamd_http_on_body_decrypted(http_parser *parser, const char *at, size_t length) { struct rspamd_http_connection *conn = (struct rspamd_http_connection *) parser->data; @@ -565,8 +565,8 @@ rspamd_http_decrypt_message(struct rspamd_http_connection *conn, struct rspamd_http_connection_private *priv, struct rspamd_cryptobox_pubkey *peer_key) { - guchar *nonce, *m; - const guchar *nm; + unsigned char *nonce, *m; + const unsigned char *nm; gsize dec_len; struct rspamd_http_message *msg = priv->msg; struct rspamd_http_header *hdr, *hcur, *hcurtmp; @@ -588,7 +588,7 @@ rspamd_http_decrypt_message(struct rspamd_http_connection *conn, if (!rspamd_cryptobox_decrypt_nm_inplace(m, dec_len, nonce, nm, m - rspamd_cryptobox_mac_bytes(mode), mode)) { msg_err("cannot verify encrypted message, first bytes of the input: %*xs", - (gint) MIN(msg->body_buf.len, 64), msg->body_buf.begin); + (int) MIN(msg->body_buf.len, 64), msg->body_buf.begin); return -1; } @@ -715,7 +715,7 @@ rspamd_http_simple_client_helper(struct rspamd_http_connection *conn) { struct rspamd_http_connection_private *priv; gpointer ssl; - gint request_method; + int request_method; GString *prev_host = NULL; priv = conn->priv; @@ -760,8 +760,8 @@ rspamd_http_write_helper(struct rspamd_http_connection *conn) { struct rspamd_http_connection_private *priv; struct iovec *start; - guint niov, i; - gint flags = 0; + unsigned int niov, i; + int flags = 0; gsize remain; gssize r; GError *err; @@ -864,14 +864,14 @@ call_finish_handler: } static gssize -rspamd_http_try_read(gint fd, +rspamd_http_try_read(int fd, struct rspamd_http_connection *conn, struct rspamd_http_connection_private *priv, struct _rspamd_http_privbuf *pbuf, - const gchar **buf_ptr) + const char **buf_ptr) { gssize r; - gchar *data; + char *data; gsize len; struct rspamd_http_message *msg; @@ -882,13 +882,13 @@ rspamd_http_try_read(gint fd, len = priv->buf->data->allocated; } else { - data = (gchar *) pbuf->zc_buf; + data = (char *) pbuf->zc_buf; len = pbuf->zc_remain; if (len == 0) { rspamd_http_message_grow_body(priv->msg, priv->buf->data->allocated); rspamd_http_switch_zc(pbuf, msg); - data = (gchar *) pbuf->zc_buf; + data = (char *) pbuf->zc_buf; len = pbuf->zc_remain; } } @@ -936,7 +936,7 @@ rspamd_http_event_handler(int fd, short what, gpointer ud) struct rspamd_http_connection *conn = (struct rspamd_http_connection *) ud; struct rspamd_http_connection_private *priv; struct _rspamd_http_privbuf *pbuf; - const gchar *d; + const char *d; gssize r; GError *err; @@ -1104,7 +1104,7 @@ rspamd_http_parser_reset(struct rspamd_http_connection *conn) static struct rspamd_http_connection * rspamd_http_connection_new_common(struct rspamd_http_context *ctx, - gint fd, + int fd, rspamd_http_body_handler_t body_handler, rspamd_http_error_handler_t error_handler, rspamd_http_finish_handler_t finish_handler, @@ -1156,7 +1156,7 @@ rspamd_http_connection_new_common(struct rspamd_http_context *ctx, struct rspamd_http_connection * rspamd_http_connection_new_server(struct rspamd_http_context *ctx, - gint fd, + int fd, rspamd_http_body_handler_t body_handler, rspamd_http_error_handler_t error_handler, rspamd_http_finish_handler_t finish_handler, @@ -1172,7 +1172,7 @@ rspamd_http_connection_new_client_socket(struct rspamd_http_context *ctx, rspamd_http_error_handler_t error_handler, rspamd_http_finish_handler_t finish_handler, unsigned opts, - gint fd) + int fd) { return rspamd_http_connection_new_common(ctx, fd, body_handler, error_handler, finish_handler, opts, RSPAMD_HTTP_CLIENT, 0, NULL); @@ -1186,7 +1186,7 @@ rspamd_http_connection_new_client(struct rspamd_http_context *ctx, unsigned opts, rspamd_inet_addr_t *addr) { - gint fd; + int fd; if (ctx == NULL) { ctx = rspamd_http_context_default(); @@ -1243,7 +1243,7 @@ rspamd_http_connection_new_client_keepalive(struct rspamd_http_context *ctx, rspamd_http_finish_handler_t finish_handler, unsigned opts, rspamd_inet_addr_t *addr, - const gchar *host) + const char *host) { struct rspamd_http_connection *conn; @@ -1336,7 +1336,7 @@ rspamd_http_connection_copy_msg(struct rspamd_http_message *msg, GError **err) { struct rspamd_http_message *new_msg; struct rspamd_http_header *hdr, *nhdr, *nhdrs, *hcur; - const gchar *old_body; + const char *old_body; gsize old_len; struct stat st; union _rspamd_storage_u *storage; @@ -1448,7 +1448,7 @@ rspamd_http_connection_copy_msg(struct rspamd_http_message *msg, GError **err) DL_APPEND(nhdrs, nhdr); } - gint r; + int r; khiter_t k = kh_put(rspamd_http_headers_hash, new_msg->headers, &nhdrs->name, &r); @@ -1498,7 +1498,7 @@ void rspamd_http_connection_free(struct rspamd_http_connection *conn) static void rspamd_http_connection_read_message_common(struct rspamd_http_connection *conn, gpointer ud, ev_tstamp timeout, - gint flags) + int flags) { struct rspamd_http_connection_private *priv = conn->priv; struct rspamd_http_message *req; @@ -1560,21 +1560,21 @@ rspamd_http_connection_encrypt_message( struct rspamd_http_connection *conn, struct rspamd_http_message *msg, struct rspamd_http_connection_private *priv, - guchar *pbody, - guint bodylen, - guchar *pmethod, - guint methodlen, - guint preludelen, - gint hdrcount, - guchar *np, - guchar *mp, + unsigned char *pbody, + unsigned int bodylen, + unsigned char *pmethod, + unsigned int methodlen, + unsigned int preludelen, + int hdrcount, + unsigned char *np, + unsigned char *mp, struct rspamd_cryptobox_pubkey *peer_key) { struct rspamd_cryptobox_segment *segments; - guchar *crlfp; - const guchar *nm; - gint i, cnt; - guint outlen; + unsigned char *crlfp; + const unsigned char *nm; + int i, cnt; + unsigned int outlen; struct rspamd_http_header *hdr, *hcur; enum rspamd_cryptobox_mode mode; @@ -1669,16 +1669,16 @@ rspamd_http_detach_shared(struct rspamd_http_message *msg) rspamd_http_message_set_body_from_fstring_steal(msg, cpy_str); } -gint rspamd_http_message_write_header(const gchar *mime_type, gboolean encrypted, - gchar *repbuf, gsize replen, gsize bodylen, gsize enclen, const gchar *host, - struct rspamd_http_connection *conn, struct rspamd_http_message *msg, - rspamd_fstring_t **buf, - struct rspamd_http_connection_private *priv, - struct rspamd_cryptobox_pubkey *peer_key) +int rspamd_http_message_write_header(const char *mime_type, gboolean encrypted, + char *repbuf, gsize replen, gsize bodylen, gsize enclen, const char *host, + struct rspamd_http_connection *conn, struct rspamd_http_message *msg, + rspamd_fstring_t **buf, + struct rspamd_http_connection_private *priv, + struct rspamd_cryptobox_pubkey *peer_key) { - gchar datebuf[64]; - gint meth_len = 0; - const gchar *conn_type = "close"; + char datebuf[64]; + int meth_len = 0; + const char *conn_type = "close"; if (conn->type == RSPAMD_HTTP_SERVER) { /* Format reply */ @@ -1789,7 +1789,7 @@ gint rspamd_http_message_write_header(const gchar *mime_type, gboolean encrypted GString tmp; /* Unfortunately, spamc protocol is deadly brain damaged */ - tmp.str = (gchar *) msg->body_buf.begin; + tmp.str = (char *) msg->body_buf.begin; tmp.len = msg->body_buf.len; if (rspamd_string_find_eoh(&tmp, &eoh_pos) != -1 && @@ -2011,21 +2011,21 @@ gint rspamd_http_message_write_header(const gchar *mime_type, gboolean encrypted static gboolean rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, struct rspamd_http_message *msg, - const gchar *host, - const gchar *mime_type, + const char *host, + const char *mime_type, gpointer ud, ev_tstamp timeout, gboolean allow_shared) { struct rspamd_http_connection_private *priv = conn->priv; struct rspamd_http_header *hdr, *hcur; - gchar repbuf[512], *pbody; - gint i, hdrcount, meth_len = 0, preludelen = 0; + char repbuf[512], *pbody; + int i, hdrcount, meth_len = 0, preludelen = 0; gsize bodylen, enclen = 0; rspamd_fstring_t *buf; gboolean encrypted = FALSE; - guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES], mac[rspamd_cryptobox_MAX_MACBYTES]; - guchar *np = NULL, *mp = NULL, *meth_pos = NULL; + unsigned char nonce[rspamd_cryptobox_MAX_NONCEBYTES], mac[rspamd_cryptobox_MAX_MACBYTES]; + unsigned char *np = NULL, *mp = NULL, *meth_pos = NULL; struct rspamd_cryptobox_pubkey *peer_key = NULL; enum rspamd_cryptobox_mode mode; GError *err; @@ -2079,7 +2079,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, } if (allow_shared) { - gchar tmpbuf[64]; + char tmpbuf[64]; if (!(msg->flags & RSPAMD_HTTP_FLAG_SHMEM) || msg->body_buf.c.shared.name == NULL) { @@ -2103,7 +2103,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, if (priv->ctx->config.user_agent && conn->type == RSPAMD_HTTP_CLIENT) { rspamd_ftok_t srch; khiter_t k; - gint r; + int r; RSPAMD_FTOK_ASSIGN(&srch, "User-Agent"); @@ -2111,7 +2111,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, if (r != 0) { hdr = g_malloc0(sizeof(struct rspamd_http_header)); - guint vlen = strlen(priv->ctx->config.user_agent); + unsigned int vlen = strlen(priv->ctx->config.user_agent); hdr->combined = rspamd_fstring_sized_new(srch.len + vlen + 4); rspamd_printf_fstring(&hdr->combined, "%T: %*s\r\n", &srch, vlen, priv->ctx->config.user_agent); @@ -2136,7 +2136,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, msg->method = HTTP_GET; } else { - pbody = (gchar *) msg->body_buf.begin; + pbody = (char *) msg->body_buf.begin; bodylen = msg->body_buf.len; msg->method = HTTP_POST; } @@ -2219,7 +2219,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, } } else { - pbody = (gchar *) msg->body_buf.begin; + pbody = (char *) msg->body_buf.begin; bodylen = msg->body_buf.len; priv->outlen = 3; @@ -2230,7 +2230,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, } else if (msg->body_buf.len > 0) { allow_shared = FALSE; - pbody = (gchar *) msg->body_buf.begin; + pbody = (char *) msg->body_buf.begin; bodylen = msg->body_buf.len; priv->outlen = 2; } @@ -2274,7 +2274,7 @@ priv->out[0].iov_len = buf->len; /* Buf will be used eventually for encryption */ if (encrypted) { - gint meth_offset, nonce_offset, mac_offset; + int meth_offset, nonce_offset, mac_offset; mode = rspamd_keypair_alg(priv->local_key); ottery_rand_bytes(nonce, rspamd_cryptobox_nonce_bytes(mode)); @@ -2417,8 +2417,8 @@ return TRUE; gboolean rspamd_http_connection_write_message(struct rspamd_http_connection *conn, struct rspamd_http_message *msg, - const gchar *host, - const gchar *mime_type, + const char *host, + const char *mime_type, gpointer ud, ev_tstamp timeout) { @@ -2429,8 +2429,8 @@ rspamd_http_connection_write_message(struct rspamd_http_connection *conn, gboolean rspamd_http_connection_write_message_shared(struct rspamd_http_connection *conn, struct rspamd_http_message *msg, - const gchar *host, - const gchar *mime_type, + const char *host, + const char *mime_type, gpointer ud, ev_tstamp timeout) { @@ -2497,7 +2497,7 @@ rspamd_http_message_parse_query(struct rspamd_http_message *msg) GHashTable *res; rspamd_fstring_t *key = NULL, *value = NULL; rspamd_ftok_t *key_tok = NULL, *value_tok = NULL; - const gchar *p, *c, *end; + const char *p, *c, *end; struct http_parser_url u; enum { parse_key, diff --git a/src/libserver/http/http_connection.h b/src/libserver/http/http_connection.h index e98d16455..f6ec03d95 100644 --- a/src/libserver/http/http_connection.h +++ b/src/libserver/http/http_connection.h @@ -51,7 +51,7 @@ struct rspamd_http_connection_entry; struct rspamd_keepalive_hash_key; struct rspamd_storage_shmem { - gchar *shm_name; + char *shm_name; ref_entry_t ref; }; @@ -98,7 +98,7 @@ enum rspamd_http_options { typedef int (*rspamd_http_body_handler_t)(struct rspamd_http_connection *conn, struct rspamd_http_message *msg, - const gchar *chunk, + const char *chunk, gsize len); typedef void (*rspamd_http_error_handler_t)(struct rspamd_http_connection *conn, @@ -116,15 +116,15 @@ struct rspamd_http_connection { rspamd_http_error_handler_t error_handler; rspamd_http_finish_handler_t finish_handler; gpointer ud; - const gchar *log_tag; + const char *log_tag; /* Used for keepalive */ struct rspamd_keepalive_hash_key *keepalive_hash_key; gsize max_size; unsigned opts; enum rspamd_http_connection_type type; gboolean finished; - gint fd; - gint ref; + int fd; + int ref; }; /** @@ -139,7 +139,7 @@ struct rspamd_http_connection { */ struct rspamd_http_connection *rspamd_http_connection_new_server( struct rspamd_http_context *ctx, - gint fd, + int fd, rspamd_http_body_handler_t body_handler, rspamd_http_error_handler_t error_handler, rspamd_http_finish_handler_t finish_handler, @@ -162,7 +162,7 @@ struct rspamd_http_connection *rspamd_http_connection_new_client_keepalive( rspamd_http_finish_handler_t finish_handler, unsigned opts, rspamd_inet_addr_t *addr, - const gchar *host); + const char *host); /** * Creates an ordinary connection using the address specified (if proxy is not set) @@ -198,7 +198,7 @@ struct rspamd_http_connection *rspamd_http_connection_new_client_socket( rspamd_http_error_handler_t error_handler, rspamd_http_finish_handler_t finish_handler, unsigned opts, - gint fd); + int fd); /** * Set key pointed by an opaque pointer @@ -255,16 +255,16 @@ void rspamd_http_connection_read_message_shared( gboolean rspamd_http_connection_write_message( struct rspamd_http_connection *conn, struct rspamd_http_message *msg, - const gchar *host, - const gchar *mime_type, + const char *host, + const char *mime_type, gpointer ud, ev_tstamp timeout); gboolean rspamd_http_connection_write_message_shared( struct rspamd_http_connection *conn, struct rspamd_http_message *msg, - const gchar *host, - const gchar *mime_type, + const char *host, + const char *mime_type, gpointer ud, ev_tstamp timeout); diff --git a/src/libserver/http/http_context.c b/src/libserver/http/http_context.c index e9cfe187d..fe9412fe2 100644 --- a/src/libserver/http/http_context.c +++ b/src/libserver/http/http_context.c @@ -90,10 +90,10 @@ rspamd_http_context_new_default(struct rspamd_config *cfg, struct rspamd_http_context *ctx; static const int default_kp_size = 1024; - static const gdouble default_rotate_time = 120; - static const gdouble default_keepalive_interval = 65; - static const gchar *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL; - static const gchar *default_server_hdr = "rspamd/" RSPAMD_VERSION_FULL; + static const double default_rotate_time = 120; + static const double default_keepalive_interval = 65; + static const char *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL; + static const char *default_server_hdr = "rspamd/" RSPAMD_VERSION_FULL; ctx = g_malloc0(sizeof(*ctx)); ctx->config.kp_cache_size_client = default_kp_size; @@ -122,7 +122,7 @@ rspamd_http_context_new_default(struct rspamd_config *cfg, static void rspamd_http_context_parse_proxy(struct rspamd_http_context *ctx, - const gchar *name, + const char *name, struct upstream_list **pls) { struct http_parser_url u; @@ -401,7 +401,7 @@ bool rspamd_keep_alive_key_equal(struct rspamd_keepalive_hash_key *k1, struct rspamd_http_connection * rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx, const rspamd_inet_addr_t *addr, - const gchar *host, + const char *host, bool is_ssl) { struct rspamd_keepalive_hash_key hk, *phk; @@ -412,7 +412,7 @@ rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx, } hk.addr = (rspamd_inet_addr_t *) addr; - hk.host = (gchar *) host; + hk.host = (char *) host; hk.port = rspamd_inet_address_get_port(addr); hk.is_ssl = is_ssl; @@ -427,8 +427,8 @@ rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx, if (g_queue_get_length(conns) > 0) { struct rspamd_http_keepalive_cbdata *cbd; struct rspamd_http_connection *conn; - gint err; - socklen_t len = sizeof(gint); + int err; + socklen_t len = sizeof(int); cbd = g_queue_pop_head(conns); rspamd_ev_watcher_stop(ctx->event_loop, &cbd->ev); @@ -475,7 +475,7 @@ rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx, const rspamd_inet_addr_t * rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx, - const gchar *host, + const char *host, unsigned port, bool is_ssl) { @@ -486,7 +486,7 @@ rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx, ctx = rspamd_http_context_default(); } - hk.host = (gchar *) host; + hk.host = (char *) host; hk.port = port; hk.is_ssl = is_ssl; @@ -507,14 +507,14 @@ rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx, void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx, struct rspamd_http_connection *conn, const rspamd_inet_addr_t *addr, - const gchar *host, + const char *host, bool is_ssl) { struct rspamd_keepalive_hash_key hk, *phk; khiter_t k; hk.addr = (rspamd_inet_addr_t *) addr; - hk.host = (gchar *) host; + hk.host = (char *) host; hk.is_ssl = is_ssl; hk.port = rspamd_inet_address_get_port(addr); @@ -530,7 +530,7 @@ void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx, else { /* Create new one */ GQueue empty_init = G_QUEUE_INIT; - gint r; + int r; phk = g_malloc(sizeof(*phk)); phk->conns = empty_init; @@ -550,7 +550,7 @@ void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx, } static void -rspamd_http_keepalive_handler(gint fd, short what, gpointer ud) +rspamd_http_keepalive_handler(int fd, short what, gpointer ud) { struct rspamd_http_keepalive_cbdata *cbdata = (struct rspamd_http_keepalive_cbdata *) ud; /* @@ -607,7 +607,7 @@ void rspamd_http_context_push_keepalive(struct rspamd_http_context *ctx, struct ev_loop *event_loop) { struct rspamd_http_keepalive_cbdata *cbdata; - gdouble timeout = ctx->config.keepalive_interval; + double timeout = ctx->config.keepalive_interval; g_assert(conn->keepalive_hash_key != NULL); diff --git a/src/libserver/http/http_context.h b/src/libserver/http/http_context.h index f3622ae7f..1b15f4067 100644 --- a/src/libserver/http/http_context.h +++ b/src/libserver/http/http_context.h @@ -33,14 +33,14 @@ struct rspamd_http_message; struct upstream_ctx; struct rspamd_http_context_cfg { - guint kp_cache_size_client; - guint kp_cache_size_server; - guint ssl_cache_size; - gdouble keepalive_interval; - gdouble client_key_rotate_time; - const gchar *user_agent; - const gchar *http_proxy; - const gchar *server_hdr; + unsigned int kp_cache_size_client; + unsigned int kp_cache_size_server; + unsigned int ssl_cache_size; + double keepalive_interval; + double client_key_rotate_time; + const char *user_agent; + const char *http_proxy; + const char *server_hdr; }; /** @@ -76,7 +76,7 @@ struct rspamd_http_context *rspamd_http_context_default(void); */ struct rspamd_http_connection *rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx, const rspamd_inet_addr_t *addr, - const gchar *host, + const char *host, bool is_ssl); /** @@ -88,7 +88,7 @@ struct rspamd_http_connection *rspamd_http_context_check_keepalive(struct rspamd * @return */ const rspamd_inet_addr_t *rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx, - const gchar *host, + const char *host, unsigned port, bool is_ssl); @@ -101,7 +101,7 @@ const rspamd_inet_addr_t *rspamd_http_context_has_keepalive(struct rspamd_http_c * @param host */ void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx, struct rspamd_http_connection *conn, - const rspamd_inet_addr_t *addr, const gchar *host, bool is_ssl); + const rspamd_inet_addr_t *addr, const char *host, bool is_ssl); /** * Pushes a connection to keepalive pool after client request is finished, diff --git a/src/libserver/http/http_message.c b/src/libserver/http/http_message.c index e02827a76..0c9708450 100644 --- a/src/libserver/http/http_message.c +++ b/src/libserver/http/http_message.c @@ -47,13 +47,13 @@ rspamd_http_new_message(enum rspamd_http_message_type type) } struct rspamd_http_message * -rspamd_http_message_from_url(const gchar *url) +rspamd_http_message_from_url(const char *url) { struct http_parser_url pu; struct rspamd_http_message *msg; - const gchar *host, *path; + const char *host, *path; size_t pathlen, urllen; - guint flags = 0; + unsigned int flags = 0; if (url == NULL) { return NULL; @@ -127,11 +127,11 @@ rspamd_http_message_from_url(const gchar *url) return msg; } -const gchar * +const char * rspamd_http_message_get_body(struct rspamd_http_message *msg, gsize *blen) { - const gchar *ret = NULL; + const char *ret = NULL; if (msg->body_buf.len > 0) { ret = msg->body_buf.begin; @@ -169,7 +169,7 @@ rspamd_http_message_shmem_ref(struct rspamd_http_message *msg) return NULL; } -guint rspamd_http_message_get_flags(struct rspamd_http_message *msg) +unsigned int rspamd_http_message_get_flags(struct rspamd_http_message *msg) { return msg->flags; } @@ -181,7 +181,7 @@ void rspamd_http_message_shmem_unref(struct rspamd_storage_shmem *p) gboolean rspamd_http_message_set_body(struct rspamd_http_message *msg, - const gchar *data, gsize len) + const char *data, gsize len) { union _rspamd_storage_u *storage; storage = &msg->body_buf.c; @@ -264,9 +264,9 @@ rspamd_http_message_set_body(struct rspamd_http_message *msg, } void rspamd_http_message_set_method(struct rspamd_http_message *msg, - const gchar *method) + const char *method) { - gint i; + int i; /* Linear search: not very efficient method */ for (i = 0; i < HTTP_METHOD_MAX; i++) { @@ -278,7 +278,7 @@ void rspamd_http_message_set_method(struct rspamd_http_message *msg, gboolean rspamd_http_message_set_body_from_fd(struct rspamd_http_message *msg, - gint fd) + int fd) { union _rspamd_storage_u *storage; struct stat st; @@ -413,7 +413,7 @@ rspamd_http_message_grow_body(struct rspamd_http_message *msg, gsize len) gboolean rspamd_http_message_append_body(struct rspamd_http_message *msg, - const gchar *data, gsize len) + const char *data, gsize len) { union _rspamd_storage_u *storage; @@ -522,14 +522,14 @@ void rspamd_http_message_set_peer_key(struct rspamd_http_message *msg, } void rspamd_http_message_add_header_len(struct rspamd_http_message *msg, - const gchar *name, - const gchar *value, + const char *name, + const char *value, gsize len) { struct rspamd_http_header *hdr, *found; - guint nlen, vlen; + unsigned int nlen, vlen; khiter_t k; - gint r; + int r; if (msg != NULL && name != NULL && value != NULL) { hdr = g_malloc0(sizeof(struct rspamd_http_header)); @@ -541,7 +541,7 @@ void rspamd_http_message_add_header_len(struct rspamd_http_message *msg, } hdr->combined = rspamd_fstring_sized_new(nlen + vlen + 4); - rspamd_printf_fstring(&hdr->combined, "%s: %*s\r\n", name, (gint) vlen, + rspamd_printf_fstring(&hdr->combined, "%s: %*s\r\n", name, (int) vlen, value); hdr->name.begin = hdr->combined->str; hdr->name.len = nlen; @@ -564,8 +564,8 @@ void rspamd_http_message_add_header_len(struct rspamd_http_message *msg, } void rspamd_http_message_add_header(struct rspamd_http_message *msg, - const gchar *name, - const gchar *value) + const char *name, + const char *value) { if (value) { rspamd_http_message_add_header_len(msg, name, value, strlen(value)); @@ -573,13 +573,13 @@ void rspamd_http_message_add_header(struct rspamd_http_message *msg, } void rspamd_http_message_add_header_fstr(struct rspamd_http_message *msg, - const gchar *name, + const char *name, rspamd_fstring_t *value) { struct rspamd_http_header *hdr, *found = NULL; - guint nlen, vlen; + unsigned int nlen, vlen; khiter_t k; - gint r; + int r; if (msg != NULL && name != NULL && value != NULL) { hdr = g_malloc0(sizeof(struct rspamd_http_header)); @@ -609,11 +609,11 @@ void rspamd_http_message_add_header_fstr(struct rspamd_http_message *msg, const rspamd_ftok_t * rspamd_http_message_find_header(struct rspamd_http_message *msg, - const gchar *name) + const char *name) { const rspamd_ftok_t *res = NULL; rspamd_ftok_t srch; - guint slen = strlen(name); + unsigned int slen = strlen(name); khiter_t k; if (msg != NULL) { @@ -633,15 +633,15 @@ rspamd_http_message_find_header(struct rspamd_http_message *msg, GPtrArray * rspamd_http_message_find_header_multiple( struct rspamd_http_message *msg, - const gchar *name) + const char *name) { GPtrArray *res = NULL; struct rspamd_http_header *hdr, *cur; rspamd_ftok_t srch; khiter_t k; - guint cnt = 0; + unsigned int cnt = 0; - guint slen = strlen(name); + unsigned int slen = strlen(name); if (msg != NULL) { srch.begin = name; @@ -669,11 +669,11 @@ rspamd_http_message_find_header_multiple( gboolean rspamd_http_message_remove_header(struct rspamd_http_message *msg, - const gchar *name) + const char *name) { struct rspamd_http_header *hdr, *hcur, *hcurtmp; gboolean res = FALSE; - guint slen = strlen(name); + unsigned int slen = strlen(name); rspamd_ftok_t srch; khiter_t k; @@ -699,7 +699,7 @@ rspamd_http_message_remove_header(struct rspamd_http_message *msg, return res; } -const gchar * +const char * rspamd_http_message_get_http_host(struct rspamd_http_message *msg, gsize *hostlen) { @@ -738,7 +738,7 @@ bool rspamd_http_message_is_standard_port(struct rspamd_http_message *msg) return msg->port == 80; } -const gchar *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len) +const char *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len) { if (msg->url) { *len = msg->url->len; diff --git a/src/libserver/http/http_message.h b/src/libserver/http/http_message.h index a483b316a..45ca3a2f9 100644 --- a/src/libserver/http/http_message.h +++ b/src/libserver/http/http_message.h @@ -83,7 +83,7 @@ void rspamd_http_message_set_peer_key(struct rspamd_http_message *msg, * @param url * @return new message or NULL */ -struct rspamd_http_message *rspamd_http_message_from_url(const gchar *url); +struct rspamd_http_message *rspamd_http_message_from_url(const char *url); /** * Returns body for a message @@ -91,8 +91,8 @@ struct rspamd_http_message *rspamd_http_message_from_url(const gchar *url); * @param blen pointer where to save body length * @return pointer to body start */ -const gchar *rspamd_http_message_get_body(struct rspamd_http_message *msg, - gsize *blen); +const char *rspamd_http_message_get_body(struct rspamd_http_message *msg, + gsize *blen); /** * Set message's body from the string @@ -102,7 +102,7 @@ const gchar *rspamd_http_message_get_body(struct rspamd_http_message *msg, * @return TRUE if a message's body has been set */ gboolean rspamd_http_message_set_body(struct rspamd_http_message *msg, - const gchar *data, gsize len); + const char *data, gsize len); /** * Set message's method by name @@ -110,7 +110,7 @@ gboolean rspamd_http_message_set_body(struct rspamd_http_message *msg, * @param method */ void rspamd_http_message_set_method(struct rspamd_http_message *msg, - const gchar *method); + const char *method); /** * Maps fd as message's body @@ -119,7 +119,7 @@ void rspamd_http_message_set_method(struct rspamd_http_message *msg, * @return TRUE if a message's body has been set */ gboolean rspamd_http_message_set_body_from_fd(struct rspamd_http_message *msg, - gint fd); + int fd); /** * Uses rspamd_fstring_t as message's body, string is consumed by this operation @@ -147,7 +147,7 @@ gboolean rspamd_http_message_set_body_from_fstring_copy(struct rspamd_http_messa * @return TRUE if a message's body has been set */ gboolean rspamd_http_message_append_body(struct rspamd_http_message *msg, - const gchar *data, gsize len); + const char *data, gsize len); /** * Append a header to http message @@ -156,16 +156,16 @@ gboolean rspamd_http_message_append_body(struct rspamd_http_message *msg, * @param value */ void rspamd_http_message_add_header(struct rspamd_http_message *msg, - const gchar *name, - const gchar *value); + const char *name, + const char *value); void rspamd_http_message_add_header_len(struct rspamd_http_message *msg, - const gchar *name, - const gchar *value, + const char *name, + const char *value, gsize len); void rspamd_http_message_add_header_fstr(struct rspamd_http_message *msg, - const gchar *name, + const char *name, rspamd_fstring_t *value); /** @@ -175,7 +175,7 @@ void rspamd_http_message_add_header_fstr(struct rspamd_http_message *msg, */ const rspamd_ftok_t *rspamd_http_message_find_header( struct rspamd_http_message *msg, - const gchar *name); + const char *name); /** * Search for a header that has multiple values @@ -185,7 +185,7 @@ const rspamd_ftok_t *rspamd_http_message_find_header( */ GPtrArray *rspamd_http_message_find_header_multiple( struct rspamd_http_message *msg, - const gchar *name); + const char *name); /** * Remove specific header from a message @@ -194,7 +194,7 @@ GPtrArray *rspamd_http_message_find_header_multiple( * @return */ gboolean rspamd_http_message_remove_header(struct rspamd_http_message *msg, - const gchar *name); + const char *name); /** * Free HTTP message @@ -228,7 +228,7 @@ void rspamd_http_message_shmem_unref(struct rspamd_storage_shmem *p); * @param msg * @return */ -guint rspamd_http_message_get_flags(struct rspamd_http_message *msg); +unsigned int rspamd_http_message_get_flags(struct rspamd_http_message *msg); /** * Returns an HTTP hostname for a message, derived from a header if it has it @@ -237,8 +237,8 @@ guint rspamd_http_message_get_flags(struct rspamd_http_message *msg); * @param hostlen output of the host length * @return */ -const gchar *rspamd_http_message_get_http_host(struct rspamd_http_message *msg, - gsize *hostlen); +const char *rspamd_http_message_get_http_host(struct rspamd_http_message *msg, + gsize *hostlen); /** * Returns true if a message has standard port (80 or 443 for https) @@ -247,7 +247,7 @@ const gchar *rspamd_http_message_get_http_host(struct rspamd_http_message *msg, */ bool rspamd_http_message_is_standard_port(struct rspamd_http_message *msg); -const gchar *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len); +const char *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len); #ifdef __cplusplus } diff --git a/src/libserver/http/http_private.h b/src/libserver/http/http_private.h index bad0231a8..de683a91b 100644 --- a/src/libserver/http/http_private.h +++ b/src/libserver/http/http_private.h @@ -54,20 +54,20 @@ struct rspamd_http_message { struct _rspamd_body_buf_s { /* Data start */ - const gchar *begin; + const char *begin; /* Data len */ gsize len; /* Allocated len */ gsize allocated_len; /* Data buffer (used to write data inside) */ - gchar *str; + char *str; /* Internal storage */ union _rspamd_storage_u { rspamd_fstring_t *normal; struct _rspamd_storage_shared_s { struct rspamd_storage_shmem *name; - gint shm_fd; + int shm_fd; } shared; } c; } body_buf; @@ -77,15 +77,15 @@ struct rspamd_http_message { time_t last_modified; unsigned port; int type; - gint code; + int code; enum http_method method; - gint flags; + int flags; ref_entry_t ref; }; struct rspamd_keepalive_hash_key { rspamd_inet_addr_t *addr; - gchar *host; + char *host; gboolean is_ssl; unsigned port; GQueue conns; diff --git a/src/libserver/http/http_router.c b/src/libserver/http/http_router.c index 1375bf69c..aca791a27 100644 --- a/src/libserver/http/http_router.c +++ b/src/libserver/http/http_router.c @@ -35,8 +35,8 @@ enum http_magic_type { }; static const struct _rspamd_http_magic { - const gchar *ext; - const gchar *ct; + const char *ext; + const char *ct; } http_file_types[] = { [HTTP_MAGIC_PLAIN] = {"txt", "text/plain"}, [HTTP_MAGIC_HTML] = {"html", "text/html"}, @@ -101,11 +101,11 @@ rspamd_http_router_error_handler(struct rspamd_http_connection *conn, } } -static const gchar * -rspamd_http_router_detect_ct(const gchar *path) +static const char * +rspamd_http_router_detect_ct(const char *path) { - const gchar *dot; - guint i; + const char *dot; + unsigned int i; dot = strrchr(path, '.'); if (dot == NULL) { @@ -123,7 +123,7 @@ rspamd_http_router_detect_ct(const gchar *path) } static gboolean -rspamd_http_router_is_subdir(const gchar *parent, const gchar *sub) +rspamd_http_router_is_subdir(const char *parent, const char *sub) { if (parent == NULL || sub == NULL || *parent == '\0') { return FALSE; @@ -150,8 +150,8 @@ rspamd_http_router_try_file(struct rspamd_http_connection_entry *entry, rspamd_ftok_t *lookup, gboolean expand_path) { struct stat st; - gint fd; - gchar filebuf[PATH_MAX], realbuf[PATH_MAX], *dir; + int fd; + char filebuf[PATH_MAX], realbuf[PATH_MAX], *dir; struct rspamd_http_message *reply_msg; rspamd_snprintf(filebuf, sizeof(filebuf), "%s%c%T", @@ -256,10 +256,10 @@ rspamd_http_router_finish_handler(struct rspamd_http_connection *conn, rspamd_ftok_t lookup; const rspamd_ftok_t *encoding; struct http_parser_url u; - guint i; + unsigned int i; rspamd_regexp_t *re; struct rspamd_http_connection_router *router; - gchar *pathbuf = NULL; + char *pathbuf = NULL; G_STATIC_ASSERT(sizeof(rspamd_http_router_handler_t) == sizeof(gpointer)); @@ -439,7 +439,7 @@ void rspamd_http_router_set_key(struct rspamd_http_connection_router *router, } void rspamd_http_router_add_path(struct rspamd_http_connection_router *router, - const gchar *path, rspamd_http_router_handler_t handler) + const char *path, rspamd_http_router_handler_t handler) { gpointer ptr; rspamd_ftok_t *key; @@ -466,7 +466,7 @@ void rspamd_http_router_set_unknown_handler(struct rspamd_http_connection_router } void rspamd_http_router_add_header(struct rspamd_http_connection_router *router, - const gchar *name, const gchar *value) + const char *name, const char *value) { if (name != NULL && value != NULL && router != NULL) { g_hash_table_replace(router->response_headers, g_strdup(name), @@ -504,7 +504,7 @@ void rspamd_http_router_add_regexp(struct rspamd_http_connection_router *router, } void rspamd_http_router_handle_socket(struct rspamd_http_connection_router *router, - gint fd, gpointer ud) + int fd, gpointer ud) { struct rspamd_http_connection_entry *conn; @@ -532,7 +532,7 @@ void rspamd_http_router_free(struct rspamd_http_connection_router *router) { struct rspamd_http_connection_entry *conn, *tmp; rspamd_regexp_t *re; - guint i; + unsigned int i; if (router) { DL_FOREACH_SAFE(router->conns, conn, tmp) diff --git a/src/libserver/http/http_router.h b/src/libserver/http/http_router.h index 1bf70ed97..0245fd40e 100644 --- a/src/libserver/http/http_router.h +++ b/src/libserver/http/http_router.h @@ -53,7 +53,7 @@ struct rspamd_http_connection_router { ev_tstamp timeout; struct ev_loop *event_loop; struct rspamd_http_context *ctx; - gchar *default_fs_path; + char *default_fs_path; rspamd_http_router_handler_t unknown_method_handler; struct rspamd_cryptobox_keypair *key; rspamd_http_router_error_handler_t error_handler; @@ -87,7 +87,7 @@ void rspamd_http_router_set_key(struct rspamd_http_connection_router *router, * Add new path to the router */ void rspamd_http_router_add_path(struct rspamd_http_connection_router *router, - const gchar *path, rspamd_http_router_handler_t handler); + const char *path, rspamd_http_router_handler_t handler); /** * Add custom header to append to router replies @@ -96,7 +96,7 @@ void rspamd_http_router_add_path(struct rspamd_http_connection_router *router, * @param value */ void rspamd_http_router_add_header(struct rspamd_http_connection_router *router, - const gchar *name, const gchar *value); + const char *name, const char *value); /** * Sets method to handle unknown request methods @@ -133,7 +133,7 @@ void rspamd_http_router_add_regexp(struct rspamd_http_connection_router *router, */ void rspamd_http_router_handle_socket( struct rspamd_http_connection_router *router, - gint fd, + int fd, gpointer ud); /** diff --git a/src/libserver/http/http_util.c b/src/libserver/http/http_util.c index b43785be6..13469155e 100644 --- a/src/libserver/http/http_util.c +++ b/src/libserver/http/http_util.c @@ -18,22 +18,22 @@ #include "libutil/printf.h" #include "libutil/util.h" -static const gchar *http_week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; -static const gchar *http_month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; +static const char *http_week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; +static const char *http_month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; /* * Obtained from nginx * Copyright (C) Igor Sysoev */ -static guint mday[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +static unsigned int mday[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; time_t -rspamd_http_parse_date(const gchar *header, gsize len) +rspamd_http_parse_date(const char *header, gsize len) { - const gchar *p, *end; - gint month; - guint day, year, hour, min, sec; + const char *p, *end; + int month; + unsigned int day, year, hour, min, sec; uint64_t time; enum { no = 0, @@ -282,7 +282,7 @@ rspamd_http_parse_date(const gchar *header, gsize len) return (time_t) time; } -glong rspamd_http_date_format(gchar *buf, gsize len, time_t time) +glong rspamd_http_date_format(char *buf, gsize len, time_t time) { struct tm tms; diff --git a/src/libserver/http/http_util.h b/src/libserver/http/http_util.h index ec575081e..26e1f5741 100644 --- a/src/libserver/http/http_util.h +++ b/src/libserver/http/http_util.h @@ -29,7 +29,7 @@ extern "C" { * @param len length of header * @return time_t or (time_t)-1 in case of error */ -time_t rspamd_http_parse_date(const gchar *header, gsize len); +time_t rspamd_http_parse_date(const char *header, gsize len); /** * Prints HTTP date from `time` to `buf` using standard HTTP date format @@ -38,7 +38,7 @@ time_t rspamd_http_parse_date(const gchar *header, gsize len); * @param time time in unix seconds * @return number of bytes written */ -glong rspamd_http_date_format(gchar *buf, gsize len, time_t time); +glong rspamd_http_date_format(char *buf, gsize len, time_t time); #ifdef __cplusplus } diff --git a/src/libserver/logger.h b/src/libserver/logger.h index 4d8a6ec81..e86922bf6 100644 --- a/src/libserver/logger.h +++ b/src/libserver/logger.h @@ -24,10 +24,10 @@ enum rspamd_log_flags { }; typedef struct rspamd_logger_s rspamd_logger_t; -typedef bool (*rspamd_log_func_t)(const gchar *module, const gchar *id, - const gchar *function, - gint level_flags, - const gchar *message, +typedef bool (*rspamd_log_func_t)(const char *module, const char *id, + const char *function, + int level_flags, + const char *message, gsize mlen, rspamd_logger_t *logger, gpointer arg); @@ -68,7 +68,7 @@ struct rspamd_logger_funcs { * This logger is also used as an emergency logger * @return new rspamd logger object */ -rspamd_logger_t *rspamd_log_open_emergency(rspamd_mempool_t *pool, gint flags); +rspamd_logger_t *rspamd_log_open_emergency(rspamd_mempool_t *pool, int flags); /** * Open specific (configured logging) @@ -80,7 +80,7 @@ rspamd_logger_t *rspamd_log_open_emergency(rspamd_mempool_t *pool, gint flags); */ rspamd_logger_t *rspamd_log_open_specific(rspamd_mempool_t *pool, struct rspamd_config *config, - const gchar *ptype, + const char *ptype, uid_t uid, gid_t gid); /** @@ -88,15 +88,15 @@ rspamd_logger_t *rspamd_log_open_specific(rspamd_mempool_t *pool, * @param logger * @param level */ -void rspamd_log_set_log_level(rspamd_logger_t *logger, gint level); -gint rspamd_log_get_log_level(rspamd_logger_t *logger); -const gchar *rspamd_get_log_severity_string(gint level_flags); +void rspamd_log_set_log_level(rspamd_logger_t *logger, int level); +int rspamd_log_get_log_level(rspamd_logger_t *logger); +const char *rspamd_get_log_severity_string(int level_flags); /** * Set log flags (from enum rspamd_log_flags) * @param logger * @param flags */ -void rspamd_log_set_log_flags(rspamd_logger_t *logger, gint flags); +void rspamd_log_set_log_flags(rspamd_logger_t *logger, int flags); /** * Close log file or destroy other structures @@ -122,40 +122,40 @@ void rspamd_log_on_fork(GQuark ptype, struct rspamd_config *cfg, /** * Log function that is compatible for glib messages */ -void rspamd_glib_log_function(const gchar *log_domain, +void rspamd_glib_log_function(const char *log_domain, GLogLevelFlags log_level, - const gchar *message, + const char *message, gpointer arg); /** * Log function for printing glib assertions */ -void rspamd_glib_printerr_function(const gchar *message); +void rspamd_glib_printerr_function(const char *message); /** * Function with variable number of arguments support */ bool rspamd_common_log_function(rspamd_logger_t *logger, - gint level_flags, - const gchar *module, const gchar *id, - const gchar *function, const gchar *fmt, ...); + int level_flags, + const char *module, const char *id, + const char *function, const char *fmt, ...); -bool rspamd_common_logv(rspamd_logger_t *logger, gint level_flags, - const gchar *module, const gchar *id, const gchar *function, - const gchar *fmt, va_list args); +bool rspamd_common_logv(rspamd_logger_t *logger, int level_flags, + const char *module, const char *id, const char *function, + const char *fmt, va_list args); /** * Add new logging module, returns module ID * @param mod * @return */ -gint rspamd_logger_add_debug_module(const gchar *mod); +int rspamd_logger_add_debug_module(const char *mod); /* * Macro to use for faster debug modules */ #define INIT_LOG_MODULE(mname) \ - static gint rspamd_##mname##_log_id = -1; \ + static int rspamd_##mname##_log_id = -1; \ RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) \ { \ rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \ @@ -163,14 +163,14 @@ gint rspamd_logger_add_debug_module(const gchar *mod); #define INIT_LOG_MODULE_PUBLIC(mname) \ - gint rspamd_##mname##_log_id = -1; \ + int rspamd_##mname##_log_id = -1; \ RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) \ { \ rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \ } #define EXTERN_LOG_MODULE_DEF(mname) \ - extern gint rspamd_##mname##_log_id + extern int rspamd_##mname##_log_id void rspamd_logger_configure_modules(GHashTable *mods_enabled); @@ -178,30 +178,30 @@ void rspamd_logger_configure_modules(GHashTable *mods_enabled); * Conditional debug function */ bool rspamd_conditional_debug(rspamd_logger_t *logger, - rspamd_inet_addr_t *addr, const gchar *module, const gchar *id, - const gchar *function, const gchar *fmt, ...); + rspamd_inet_addr_t *addr, const char *module, const char *id, + const char *function, const char *fmt, ...); bool rspamd_conditional_debug_fast(rspamd_logger_t *logger, rspamd_inet_addr_t *addr, - gint mod_id, - const gchar *module, const gchar *id, - const gchar *function, const gchar *fmt, ...); + int mod_id, + const char *module, const char *id, + const char *function, const char *fmt, ...); bool rspamd_conditional_debug_fast_num_id(rspamd_logger_t *logger, rspamd_inet_addr_t *addr, - gint mod_id, - const gchar *module, uint64_t id, - const gchar *function, const gchar *fmt, ...); + int mod_id, + const char *module, uint64_t id, + const char *function, const char *fmt, ...); gboolean rspamd_logger_need_log(rspamd_logger_t *rspamd_log, GLogLevelFlags log_level, - gint module_id); + int module_id); /** * Function with variable number of arguments support that uses static default logger */ -bool rspamd_default_log_function(gint level_flags, - const gchar *module, const gchar *id, - const gchar *function, - const gchar *fmt, +bool rspamd_default_log_function(int level_flags, + const char *module, const char *id, + const char *function, + const char *fmt, ...); /** @@ -211,10 +211,10 @@ bool rspamd_default_log_function(gint level_flags, * @param fmt * @param args */ -bool rspamd_default_logv(gint level_flags, - const gchar *module, const gchar *id, - const gchar *function, - const gchar *fmt, +bool rspamd_default_logv(int level_flags, + const char *module, const char *id, + const char *function, + const char *fmt, va_list args); /** @@ -254,7 +254,7 @@ struct rspamd_logger_funcs *rspamd_logger_set_log_function(rspamd_logger_t *logg /* Typical functions */ -extern guint rspamd_task_log_id; +extern unsigned int rspamd_task_log_id; #ifdef __cplusplus #define RSPAMD_LOG_FUNC __func__ #else diff --git a/src/libserver/logger/logger.c b/src/libserver/logger/logger.c index 202837563..13bac5cbe 100644 --- a/src/libserver/logger/logger.c +++ b/src/libserver/logger/logger.c @@ -27,9 +27,9 @@ static rspamd_logger_t *default_logger = NULL; static rspamd_logger_t *emergency_logger = NULL; static struct rspamd_log_modules *log_modules = NULL; -static const gchar lf_chr = '\n'; +static const char lf_chr = '\n'; -guint rspamd_task_log_id = (guint) -1; +unsigned int rspamd_task_log_id = (unsigned int) -1; RSPAMD_CONSTRUCTOR(rspamd_task_log_init) { rspamd_task_log_id = rspamd_logger_add_debug_module("task"); @@ -47,7 +47,7 @@ rspamd_log_emergency_logger(void) return emergency_logger; } -void rspamd_log_set_log_level(rspamd_logger_t *logger, gint level) +void rspamd_log_set_log_level(rspamd_logger_t *logger, int level) { if (logger == NULL) { logger = default_logger; @@ -56,7 +56,7 @@ void rspamd_log_set_log_level(rspamd_logger_t *logger, gint level) logger->log_level = level; } -gint rspamd_log_get_log_level(rspamd_logger_t *logger) +int rspamd_log_get_log_level(rspamd_logger_t *logger) { if (logger == NULL) { logger = default_logger; @@ -65,7 +65,7 @@ gint rspamd_log_get_log_level(rspamd_logger_t *logger) return logger->log_level; } -void rspamd_log_set_log_flags(rspamd_logger_t *logger, gint flags) +void rspamd_log_set_log_flags(rspamd_logger_t *logger, int flags) { g_assert(logger != NULL); @@ -139,7 +139,7 @@ rspamd_emergency_logger_dtor(gpointer d) } rspamd_logger_t * -rspamd_log_open_emergency(rspamd_mempool_t *pool, gint flags) +rspamd_log_open_emergency(rspamd_mempool_t *pool, int flags) { rspamd_logger_t *logger; GError *err = NULL; @@ -185,7 +185,7 @@ rspamd_log_open_emergency(rspamd_mempool_t *pool, gint flags) rspamd_logger_t * rspamd_log_open_specific(rspamd_mempool_t *pool, struct rspamd_config *cfg, - const gchar *ptype, + const char *ptype, uid_t uid, gid_t gid) { rspamd_logger_t *logger; @@ -314,7 +314,7 @@ void rspamd_log_on_fork(GQuark ptype, struct rspamd_config *cfg, inline gboolean rspamd_logger_need_log(rspamd_logger_t *rspamd_log, GLogLevelFlags log_level, - gint module_id) + int module_id) { g_assert(rspamd_log != NULL); @@ -330,15 +330,15 @@ rspamd_logger_need_log(rspamd_logger_t *rspamd_log, GLogLevelFlags log_level, return FALSE; } -static gchar * -rspamd_log_encrypt_message(const gchar *begin, const gchar *end, gsize *enc_len, +static char * +rspamd_log_encrypt_message(const char *begin, const char *end, gsize *enc_len, rspamd_logger_t *rspamd_log) { - guchar *out; - gchar *b64; - guchar *p, *nonce, *mac; - const guchar *comp; - guint len, inlen; + unsigned char *out; + char *b64; + unsigned char *p, *nonce, *mac; + const unsigned char *comp; + unsigned int len, inlen; g_assert(end > begin); /* base64 (pubkey | nonce | message) */ @@ -370,8 +370,8 @@ rspamd_log_encrypt_message(const gchar *begin, const gchar *end, gsize *enc_len, static void rspamd_log_write_ringbuffer(rspamd_logger_t *rspamd_log, - const gchar *module, const gchar *id, - const gchar *data, glong len) + const char *module, const char *id, + const char *data, glong len) { uint32_t row_num; struct rspamd_logger_error_log *elog; @@ -391,7 +391,7 @@ rspamd_log_write_ringbuffer(rspamd_logger_t *rspamd_log, #endif if (row_num < elog->max_elts) { - elt = (struct rspamd_logger_error_elt *) (((guchar *) elog->elts) + + elt = (struct rspamd_logger_error_elt *) (((unsigned char *) elog->elts) + (sizeof(*elt) + elog->elt_len) * row_num); g_atomic_int_set(&elt->completed, 0); } @@ -423,14 +423,14 @@ rspamd_log_write_ringbuffer(rspamd_logger_t *rspamd_log, g_atomic_int_set(&elt->completed, 1); } -bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags, - const gchar *module, const gchar *id, const gchar *function, - const gchar *fmt, va_list args) +bool rspamd_common_logv(rspamd_logger_t *rspamd_log, int level_flags, + const char *module, const char *id, const char *function, + const char *fmt, va_list args) { - gchar *end; - gint level = level_flags & (RSPAMD_LOG_LEVEL_MASK & G_LOG_LEVEL_MASK), mod_id; + char *end; + int level = level_flags & (RSPAMD_LOG_LEVEL_MASK & G_LOG_LEVEL_MASK), mod_id; bool ret = false; - gchar logbuf[RSPAMD_LOGBUF_SIZE], *log_line; + char logbuf[RSPAMD_LOGBUF_SIZE], *log_line; gsize nescaped; if (G_UNLIKELY(rspamd_log == NULL)) { @@ -443,7 +443,7 @@ bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags, /* Just fprintf message to stderr */ if (level >= G_LOG_LEVEL_INFO) { end = rspamd_vsnprintf(logbuf, sizeof(logbuf), fmt, args); - rspamd_fprintf(stderr, "%*s\n", (gint) (end - log_line), + rspamd_fprintf(stderr, "%*s\n", (int) (end - log_line), log_line); } } @@ -461,7 +461,7 @@ bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags, if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_RSPAMADM)) { if ((nescaped = rspamd_log_line_need_escape(logbuf, end - logbuf)) != 0) { gsize unescaped_len = end - logbuf; - gchar *logbuf_escaped = g_alloca(unescaped_len + nescaped * 4); + char *logbuf_escaped = g_alloca(unescaped_len + nescaped * 4); log_line = logbuf_escaped; end = rspamd_log_line_hex_escape(logbuf, unescaped_len, @@ -470,7 +470,7 @@ bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags, } if ((level_flags & RSPAMD_LOG_ENCRYPTED) && rspamd_log->pk) { - gchar *encrypted; + char *encrypted; gsize enc_len; encrypted = rspamd_log_encrypt_message(log_line, end, &enc_len, @@ -522,10 +522,10 @@ bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags, * This log functions select real logger and write message if level is less or equal to configured log level */ bool rspamd_common_log_function(rspamd_logger_t *rspamd_log, - gint level_flags, - const gchar *module, const gchar *id, - const gchar *function, - const gchar *fmt, + int level_flags, + const char *module, const char *id, + const char *function, + const char *fmt, ...) { va_list vp; @@ -537,16 +537,16 @@ bool rspamd_common_log_function(rspamd_logger_t *rspamd_log, return ret; } -bool rspamd_default_logv(gint level_flags, const gchar *module, const gchar *id, - const gchar *function, - const gchar *fmt, va_list args) +bool rspamd_default_logv(int level_flags, const char *module, const char *id, + const char *function, + const char *fmt, va_list args) { return rspamd_common_logv(NULL, level_flags, module, id, function, fmt, args); } -bool rspamd_default_log_function(gint level_flags, - const gchar *module, const gchar *id, - const gchar *function, const gchar *fmt, ...) +bool rspamd_default_log_function(int level_flags, + const char *module, const char *id, + const char *function, const char *fmt, ...) { va_list vp; @@ -566,13 +566,13 @@ bool rspamd_default_log_function(gint level_flags, * Write log line depending on ip */ bool rspamd_conditional_debug(rspamd_logger_t *rspamd_log, - rspamd_inet_addr_t *addr, const gchar *module, const gchar *id, - const gchar *function, const gchar *fmt, ...) + rspamd_inet_addr_t *addr, const char *module, const char *id, + const char *function, const char *fmt, ...) { - static gchar logbuf[LOGBUF_LEN]; + static char logbuf[LOGBUF_LEN]; va_list vp; - gchar *end; - gint mod_id; + char *end; + int mod_id; if (rspamd_log == NULL) { rspamd_log = default_logger; @@ -607,12 +607,12 @@ bool rspamd_conditional_debug(rspamd_logger_t *rspamd_log, bool rspamd_conditional_debug_fast(rspamd_logger_t *rspamd_log, rspamd_inet_addr_t *addr, - gint mod_id, const gchar *module, const gchar *id, - const gchar *function, const gchar *fmt, ...) + int mod_id, const char *module, const char *id, + const char *function, const char *fmt, ...) { - static gchar logbuf[LOGBUF_LEN]; + static char logbuf[LOGBUF_LEN]; va_list vp; - gchar *end; + char *end; if (rspamd_log == NULL) { rspamd_log = default_logger; @@ -644,12 +644,12 @@ bool rspamd_conditional_debug_fast(rspamd_logger_t *rspamd_log, bool rspamd_conditional_debug_fast_num_id(rspamd_logger_t *rspamd_log, rspamd_inet_addr_t *addr, - gint mod_id, const gchar *module, uint64_t id, - const gchar *function, const gchar *fmt, ...) + int mod_id, const char *module, uint64_t id, + const char *function, const char *fmt, ...) { - static gchar logbuf[LOGBUF_LEN], idbuf[64]; + static char logbuf[LOGBUF_LEN], idbuf[64]; va_list vp; - gchar *end; + char *end; if (rspamd_log == NULL) { rspamd_log = default_logger; @@ -683,9 +683,9 @@ bool rspamd_conditional_debug_fast_num_id(rspamd_logger_t *rspamd_log, /** * Wrapper for glib logger */ -void rspamd_glib_log_function(const gchar *log_domain, +void rspamd_glib_log_function(const char *log_domain, GLogLevelFlags log_level, - const gchar *message, + const char *message, gpointer arg) { rspamd_logger_t *rspamd_log = (rspamd_logger_t *) arg; @@ -702,7 +702,7 @@ void rspamd_glib_log_function(const gchar *log_domain, } } -void rspamd_glib_printerr_function(const gchar *message) +void rspamd_glib_printerr_function(const char *message) { rspamd_common_log_function(NULL, G_LOG_LEVEL_CRITICAL, "glib", NULL, G_STRFUNC, @@ -735,7 +735,7 @@ rspamd_log_counters(rspamd_logger_t *logger) return NULL; } -static gint +static int rspamd_log_errlog_cmp(const ucl_object_t **o1, const ucl_object_t **o2) { const ucl_object_t *ts1, *ts2; @@ -744,7 +744,7 @@ rspamd_log_errlog_cmp(const ucl_object_t **o1, const ucl_object_t **o2) ts2 = ucl_object_lookup(*o2, "ts"); if (ts1 && ts2) { - gdouble t1 = ucl_object_todouble(ts1), t2 = ucl_object_todouble(ts2); + double t1 = ucl_object_todouble(ts1), t2 = ucl_object_todouble(ts2); if (t1 > t2) { return -1; @@ -762,7 +762,7 @@ rspamd_log_errorbuf_export(const rspamd_logger_t *logger) { struct rspamd_logger_error_elt *cpy, *cur; ucl_object_t *top = ucl_object_typed_new(UCL_ARRAY); - guint i; + unsigned int i; if (logger->errlog == NULL) { return top; @@ -773,7 +773,7 @@ rspamd_log_errorbuf_export(const rspamd_logger_t *logger) memcpy(cpy, logger->errlog->elts, logger->errlog->max_elts * (sizeof(*cpy) + logger->errlog->elt_len)); for (i = 0; i < logger->errlog->max_elts; i++) { - cur = (struct rspamd_logger_error_elt *) ((guchar *) cpy + + cur = (struct rspamd_logger_error_elt *) ((unsigned char *) cpy + i * ((sizeof(*cpy) + logger->errlog->elt_len))); if (cur->completed) { ucl_object_t *obj = ucl_object_typed_new(UCL_OBJECT); @@ -802,7 +802,7 @@ rspamd_log_errorbuf_export(const rspamd_logger_t *logger) return top; } -static guint +static unsigned int rspamd_logger_allocate_mod_bit(void) { if (log_modules->bitset_allocated * NBBY > log_modules->bitset_len + 1) { @@ -828,7 +828,7 @@ RSPAMD_DESTRUCTOR(rspamd_debug_modules_dtor) } } -gint rspamd_logger_add_debug_module(const gchar *mname) +int rspamd_logger_add_debug_module(const char *mname) { struct rspamd_log_module *m; @@ -864,7 +864,7 @@ void rspamd_logger_configure_modules(GHashTable *mods_enabled) { GHashTableIter it; gpointer k, v; - guint id; + unsigned int id; /* Clear all in bitset_allocated -> this are bytes not bits */ memset(log_modules->bitset, 0, log_modules->bitset_allocated); @@ -872,16 +872,16 @@ void rspamd_logger_configure_modules(GHashTable *mods_enabled) g_hash_table_iter_init(&it, mods_enabled); while (g_hash_table_iter_next(&it, &k, &v)) { - rspamd_logger_add_debug_module((const gchar *) k); + rspamd_logger_add_debug_module((const char *) k); } g_hash_table_iter_init(&it, mods_enabled); while (g_hash_table_iter_next(&it, &k, &v)) { - id = rspamd_logger_add_debug_module((const gchar *) k); + id = rspamd_logger_add_debug_module((const char *) k); if (isclr(log_modules->bitset, id)) { - msg_info("enable debugging for module %s (%d)", (const gchar *) k, + msg_info("enable debugging for module %s (%d)", (const char *) k, id); setbit(log_modules->bitset, id); } @@ -898,12 +898,12 @@ rspamd_logger_set_log_function(rspamd_logger_t *logger, } -gchar * -rspamd_log_line_hex_escape(const guchar *src, gsize srclen, - gchar *dst, gsize dstlen) +char * +rspamd_log_line_hex_escape(const unsigned char *src, gsize srclen, + char *dst, gsize dstlen) { - static const gchar hexdigests[16] = "0123456789ABCDEF"; - gchar *d = dst; + static const char hexdigests[16] = "0123456789ABCDEF"; + char *d = dst; static uint32_t escape[] = { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ @@ -950,7 +950,7 @@ rspamd_log_line_hex_escape(const guchar *src, gsize srclen, return d; } -gsize rspamd_log_line_need_escape(const guchar *src, gsize srclen) +gsize rspamd_log_line_need_escape(const unsigned char *src, gsize srclen) { static uint32_t escape[] = { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ @@ -984,8 +984,8 @@ gsize rspamd_log_line_need_escape(const guchar *src, gsize srclen) return n; } -const gchar * -rspamd_get_log_severity_string(gint level_flags) +const char * +rspamd_get_log_severity_string(int level_flags) { unsigned int bitnum; static const char *level_strs[G_LOG_LEVEL_USER_SHIFT] = { @@ -1008,7 +1008,7 @@ rspamd_get_log_severity_string(gint level_flags) } static inline void -log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, +log_time(double now, rspamd_logger_t *rspamd_log, char *timebuf, size_t len) { time_t sec = (time_t) now; @@ -1019,10 +1019,10 @@ log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, r = strftime(timebuf, len, "%F %H:%M:%S", &tms); if (rspamd_log->flags & RSPAMD_LOG_FLAG_USEC) { - gchar usec_buf[16]; + char usec_buf[16]; rspamd_snprintf(usec_buf, sizeof(usec_buf), "%.5f", - now - (gdouble) sec); + now - (double) sec); rspamd_snprintf(timebuf + r, len - r, "%s", usec_buf + 1); } @@ -1030,11 +1030,11 @@ log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx, double ts, - const gchar *module, - const gchar *id, - const gchar *function, - gint level_flags, - const gchar *message, + const char *module, + const char *id, + const char *function, + int level_flags, + const char *message, gsize mlen, rspamd_logger_t *logger) { @@ -1052,8 +1052,8 @@ void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx, } glong r; - static gchar timebuf[64], modulebuf[64]; - static gchar tmpbuf[256]; + static char timebuf[64], modulebuf[64]; + static char tmpbuf[256]; if (!log_json && !log_systemd) { log_time(ts, logger, timebuf, sizeof(timebuf)); @@ -1061,7 +1061,7 @@ void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx, if (G_UNLIKELY(log_json)) { /* Perform JSON logging */ - guint slen = id ? strlen(id) : strlen("(NULL)"); + unsigned int slen = id ? strlen(id) : strlen("(NULL)"); slen = MIN(RSPAMD_LOG_ID_LEN, slen); r = rspamd_snprintf(tmpbuf, sizeof(tmpbuf), "{\"ts\": %f, " "\"pid\": %P, " @@ -1237,7 +1237,7 @@ void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx, m = modulebuf; if (id != NULL) { - guint slen = strlen(id); + unsigned int slen = strlen(id); slen = MIN(RSPAMD_LOG_ID_LEN, slen); mr = rspamd_snprintf(m, mremain, "<%*.s>; ", slen, id); diff --git a/src/libserver/logger/logger_console.c b/src/libserver/logger/logger_console.c index 7f3c7708f..e2a024ab9 100644 --- a/src/libserver/logger/logger_console.c +++ b/src/libserver/logger/logger_console.c @@ -24,15 +24,15 @@ #define CONSOLE_LOG_QUARK g_quark_from_static_string("console_logger") -static const gchar lf_chr = '\n'; +static const char lf_chr = '\n'; struct rspamd_console_logger_priv { - gint fd; - gint crit_fd; + int fd; + int crit_fd; }; /* Copy & paste :( */ static inline void -log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, +log_time(double now, rspamd_logger_t *rspamd_log, char *timebuf, size_t len) { time_t sec = (time_t) now; @@ -43,10 +43,10 @@ log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, r = strftime(timebuf, len, "%F %H:%M:%S", &tms); if (rspamd_log->flags & RSPAMD_LOG_FLAG_USEC) { - gchar usec_buf[16]; + char usec_buf[16]; rspamd_snprintf(usec_buf, sizeof(usec_buf), "%.5f", - now - (gdouble) sec); + now - (double) sec); rspamd_snprintf(timebuf + r, len - r, "%s", usec_buf + 1); } @@ -136,16 +136,16 @@ void rspamd_log_console_dtor(rspamd_logger_t *logger, gpointer arg) g_free(priv); } -bool rspamd_log_console_log(const gchar *module, const gchar *id, - const gchar *function, - gint level_flags, - const gchar *message, +bool rspamd_log_console_log(const char *module, const char *id, + const char *function, + int level_flags, + const char *message, gsize mlen, rspamd_logger_t *rspamd_log, gpointer arg) { struct rspamd_console_logger_priv *priv = (struct rspamd_console_logger_priv *) arg; - gint fd, r; + int fd, r; double now; if (level_flags & G_LOG_LEVEL_CRITICAL) { diff --git a/src/libserver/logger/logger_file.c b/src/libserver/logger/logger_file.c index f45d61cf1..489a786e5 100644 --- a/src/libserver/logger/logger_file.c +++ b/src/libserver/logger/logger_file.c @@ -25,32 +25,32 @@ #define FILE_LOG_QUARK g_quark_from_static_string("file_logger") struct rspamd_file_logger_priv { - gint fd; + int fd; struct { uint32_t size; uint32_t used; u_char *buf; } io_buf; gboolean throttling; - gchar *log_file; + char *log_file; gboolean is_buffered; gboolean log_severity; time_t throttling_time; uint32_t repeats; uint64_t last_line_cksum; - gchar *saved_message; + char *saved_message; gsize saved_mlen; - gchar *saved_function; - gchar *saved_module; - gchar *saved_id; - guint saved_loglevel; + char *saved_function; + char *saved_module; + char *saved_id; + unsigned int saved_loglevel; }; /** * Calculate checksum for log line (used for repeating logic) */ static inline uint64_t -rspamd_log_calculate_cksum(const gchar *message, size_t mlen) +rspamd_log_calculate_cksum(const char *message, size_t mlen) { return rspamd_cryptobox_fast_hash(message, mlen, rspamd_hash_seed()); } @@ -64,12 +64,12 @@ direct_write_log_line(rspamd_logger_t *rspamd_log, void *data, gsize count, gboolean is_iov, - gint level_flags) + int level_flags) { struct iovec *iov; - const gchar *line; + const char *line; glong r; - gint fd; + int fd; gboolean locked = FALSE; iov = (struct iovec *) data; @@ -81,7 +81,7 @@ direct_write_log_line(rspamd_logger_t *rspamd_log, if (is_iov) { tlen = 0; - for (guint i = 0; i < count; i++) { + for (unsigned int i = 0; i < count; i++) { tlen += iov[i].iov_len; } } @@ -109,7 +109,7 @@ direct_write_log_line(rspamd_logger_t *rspamd_log, r = writev(fd, iov, count); } else { - line = (const gchar *) data; + line = (const char *) data; r = write(fd, line, count); } @@ -159,9 +159,9 @@ direct_write_log_line(rspamd_logger_t *rspamd_log, static void fill_buffer(rspamd_logger_t *rspamd_log, struct rspamd_file_logger_priv *priv, - const struct iovec *iov, gint iovcnt) + const struct iovec *iov, int iovcnt) { - gint i; + int i; for (i = 0; i < iovcnt; i++) { memcpy(priv->io_buf.buf + priv->io_buf.used, @@ -192,11 +192,11 @@ static bool file_log_helper(rspamd_logger_t *rspamd_log, struct rspamd_file_logger_priv *priv, const struct iovec *iov, - guint iovcnt, - gint level_flags) + unsigned int iovcnt, + int level_flags) { size_t len = 0; - guint i; + unsigned int i; if (!priv->is_buffered) { /* Write string directly */ @@ -233,7 +233,7 @@ static void rspamd_log_reset_repeated(rspamd_logger_t *rspamd_log, struct rspamd_file_logger_priv *priv) { - gchar tmpbuf[256]; + char tmpbuf[256]; gssize r; if (priv->repeats > REPEATS_MIN) { @@ -275,13 +275,13 @@ rspamd_log_reset_repeated(rspamd_logger_t *rspamd_log, } } -static gint +static int rspamd_try_open_log_fd(rspamd_logger_t *rspamd_log, struct rspamd_file_logger_priv *priv, uid_t uid, gid_t gid, GError **err) { - gint fd; + int fd; fd = open(priv->log_file, O_CREAT | O_WRONLY | O_APPEND, @@ -366,16 +366,16 @@ void rspamd_log_file_dtor(rspamd_logger_t *logger, gpointer arg) g_free(priv); } -bool rspamd_log_file_log(const gchar *module, const gchar *id, - const gchar *function, - gint level_flags, - const gchar *message, +bool rspamd_log_file_log(const char *module, const char *id, + const char *function, + int level_flags, + const char *message, gsize mlen, rspamd_logger_t *rspamd_log, gpointer arg) { struct rspamd_file_logger_priv *priv = (struct rspamd_file_logger_priv *) arg; - gdouble now; + double now; uint64_t cksum; gboolean got_time = FALSE; diff --git a/src/libserver/logger/logger_private.h b/src/libserver/logger/logger_private.h index d155bdcb0..80178ad32 100644 --- a/src/libserver/logger/logger_private.h +++ b/src/libserver/logger/logger_private.h @@ -24,25 +24,25 @@ #define LOGBUF_LEN 8192 struct rspamd_log_module { - gchar *mname; - guint id; + char *mname; + unsigned int id; }; struct rspamd_log_modules { - guchar *bitset; - guint bitset_len; /* Number of BITS used in bitset */ - guint bitset_allocated; /* Size of bitset allocated in BYTES */ + unsigned char *bitset; + unsigned int bitset_len; /* Number of BITS used in bitset */ + unsigned int bitset_allocated; /* Size of bitset allocated in BYTES */ GHashTable *modules; }; struct rspamd_logger_error_elt { - gint completed; + int completed; GQuark ptype; pid_t pid; - gdouble ts; - gchar id[RSPAMD_LOG_ID_LEN + 1]; - gchar module[9]; - gchar message[]; + double ts; + char id[RSPAMD_LOG_ID_LEN + 1]; + char module[9]; + char message[]; }; struct rspamd_logger_error_log { @@ -51,8 +51,8 @@ struct rspamd_logger_error_log { uint32_t max_elts; uint32_t elt_len; /* Avoid false cache sharing */ - guchar __padding[64 - sizeof(gpointer) * 2 - sizeof(uint64_t)]; - guint cur_row; + unsigned char __padding[64 - sizeof(gpointer) * 2 - sizeof(uint64_t)]; + unsigned int cur_row; }; /** @@ -61,20 +61,20 @@ struct rspamd_logger_error_log { */ struct rspamd_logger_s { struct rspamd_logger_funcs ops; - gint log_level; + int log_level; struct rspamd_logger_error_log *errlog; struct rspamd_cryptobox_pubkey *pk; struct rspamd_cryptobox_keypair *keypair; - guint flags; + unsigned int flags; gboolean closed; gboolean enabled; gboolean is_debug; gboolean no_lock; pid_t pid; - const gchar *process_type; + const char *process_type; struct rspamd_radix_map_helper *debug_ip; rspamd_mempool_mutex_t *mtx; rspamd_mempool_t *pool; @@ -93,10 +93,10 @@ void *rspamd_log_file_init(rspamd_logger_t *logger, struct rspamd_config *cfg, void *rspamd_log_file_reload(rspamd_logger_t *logger, struct rspamd_config *cfg, gpointer arg, uid_t uid, gid_t gid, GError **err); void rspamd_log_file_dtor(rspamd_logger_t *logger, gpointer arg); -bool rspamd_log_file_log(const gchar *module, const gchar *id, - const gchar *function, - gint level_flags, - const gchar *message, +bool rspamd_log_file_log(const char *module, const char *id, + const char *function, + int level_flags, + const char *message, gsize mlen, rspamd_logger_t *rspamd_log, gpointer arg); @@ -128,10 +128,10 @@ struct rspamd_logger_iov_ctx { */ void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx, double ts, - const gchar *module, const gchar *id, - const gchar *function, - gint level_flags, - const gchar *message, + const char *module, const char *id, + const char *function, + int level_flags, + const char *message, gsize mlen, rspamd_logger_t *rspamd_log); @@ -148,8 +148,8 @@ void rspamd_log_iov_free(struct rspamd_logger_iov_ctx *iov_ctx); * @param dstlen * @return end of the escaped buffer */ -gchar *rspamd_log_line_hex_escape(const guchar *src, gsize srclen, - gchar *dst, gsize dstlen); +char *rspamd_log_line_hex_escape(const unsigned char *src, gsize srclen, + char *dst, gsize dstlen); /** * Returns number of characters to be escaped, e.g. a caller can allocate a new buffer * the desired number of characters @@ -157,7 +157,7 @@ gchar *rspamd_log_line_hex_escape(const guchar *src, gsize srclen, * @param srclen * @return number of characters to be escaped */ -gsize rspamd_log_line_need_escape(const guchar *src, gsize srclen); +gsize rspamd_log_line_need_escape(const unsigned char *src, gsize srclen); static const struct rspamd_logger_funcs file_log_funcs = { .init = rspamd_log_file_init, @@ -175,10 +175,10 @@ void *rspamd_log_syslog_init(rspamd_logger_t *logger, struct rspamd_config *cfg, void *rspamd_log_syslog_reload(rspamd_logger_t *logger, struct rspamd_config *cfg, gpointer arg, uid_t uid, gid_t gid, GError **err); void rspamd_log_syslog_dtor(rspamd_logger_t *logger, gpointer arg); -bool rspamd_log_syslog_log(const gchar *module, const gchar *id, - const gchar *function, - gint level_flags, - const gchar *message, +bool rspamd_log_syslog_log(const char *module, const char *id, + const char *function, + int level_flags, + const char *message, gsize mlen, rspamd_logger_t *rspamd_log, gpointer arg); @@ -199,10 +199,10 @@ void *rspamd_log_console_init(rspamd_logger_t *logger, struct rspamd_config *cfg void *rspamd_log_console_reload(rspamd_logger_t *logger, struct rspamd_config *cfg, gpointer arg, uid_t uid, gid_t gid, GError **err); void rspamd_log_console_dtor(rspamd_logger_t *logger, gpointer arg); -bool rspamd_log_console_log(const gchar *module, const gchar *id, - const gchar *function, - gint level_flags, - const gchar *message, +bool rspamd_log_console_log(const char *module, const char *id, + const char *function, + int level_flags, + const char *message, gsize mlen, rspamd_logger_t *rspamd_log, gpointer arg); diff --git a/src/libserver/logger/logger_syslog.c b/src/libserver/logger/logger_syslog.c index faade1d01..ba46df085 100644 --- a/src/libserver/logger/logger_syslog.c +++ b/src/libserver/logger/logger_syslog.c @@ -22,7 +22,7 @@ #define SYSLOG_LOG_QUARK g_quark_from_static_string("syslog_logger") struct rspamd_syslog_logger_priv { - gint log_facility; + int log_facility; }; #ifdef HAVE_SYSLOG_H @@ -55,24 +55,24 @@ void rspamd_log_syslog_dtor(rspamd_logger_t *logger, gpointer arg) closelog(); g_free(priv); } -bool rspamd_log_syslog_log(const gchar *module, const gchar *id, - const gchar *function, - gint level_flags, - const gchar *message, +bool rspamd_log_syslog_log(const char *module, const char *id, + const char *function, + int level_flags, + const char *message, gsize mlen, rspamd_logger_t *rspamd_log, gpointer arg) { static const struct { GLogLevelFlags glib_level; - gint syslog_level; + int syslog_level; } levels_match[] = { {G_LOG_LEVEL_DEBUG, LOG_DEBUG}, {G_LOG_LEVEL_INFO, LOG_INFO}, {G_LOG_LEVEL_WARNING, LOG_WARNING}, {G_LOG_LEVEL_CRITICAL, LOG_ERR}}; unsigned i; - gint syslog_level; + int syslog_level; if (!(level_flags & RSPAMD_LOG_FORCED) && !rspamd_log->enabled) { return false; @@ -119,7 +119,7 @@ bool rspamd_log_syslog_log(const gchar *module, const gchar *id, idbuf, module != NULL ? module : "", function != NULL ? function : "", - (gint) mlen, message); + (int) mlen, message); } else { /* Escaped version */ @@ -228,7 +228,7 @@ bool rspamd_log_syslog_log(const gchar *module, const gchar *id, idbuf, module != NULL ? module : "", function != NULL ? function : "", - (gint) mlen, message); + (int) mlen, message); } return true; @@ -245,10 +245,10 @@ rspamd_log_syslog_init(rspamd_logger_t *logger, struct rspamd_config *cfg, return NULL; } -bool rspamd_log_syslog_log(const gchar *module, const gchar *id, - const gchar *function, - gint level_flags, - const gchar *message, +bool rspamd_log_syslog_log(const char *module, const char *id, + const char *function, + int level_flags, + const char *message, gsize mlen, rspamd_logger_t *rspamd_log, gpointer arg) diff --git a/src/libserver/maps/map.c b/src/libserver/maps/map.c index 3efd5a501..15fce7e9d 100644 --- a/src/libserver/maps/map.c +++ b/src/libserver/maps/map.c @@ -65,19 +65,19 @@ static void rspamd_map_process_periodic(struct map_periodic_cbdata *cbd); static void rspamd_map_schedule_periodic(struct rspamd_map *map, int how); static gboolean read_map_file_chunks(struct rspamd_map *map, struct map_cb_data *cbdata, - const gchar *fname, + const char *fname, gsize len, goffset off); static gboolean rspamd_map_save_http_cached_file(struct rspamd_map *map, struct rspamd_map_backend *bk, struct http_map_data *htdata, - const guchar *data, + const unsigned char *data, gsize len); static gboolean rspamd_map_update_http_cached_file(struct rspamd_map *map, struct rspamd_map_backend *bk, struct http_map_data *htdata); -guint rspamd_map_log_id = (guint) -1; +unsigned int rspamd_map_log_id = (unsigned int) -1; RSPAMD_CONSTRUCTOR(rspamd_map_log_init) { rspamd_map_log_id = rspamd_logger_add_debug_module("map"); @@ -89,7 +89,7 @@ RSPAMD_CONSTRUCTOR(rspamd_map_log_init) static void write_http_request(struct http_callback_data *cbd) { - gchar datebuf[128]; + char datebuf[128]; struct rspamd_http_message *msg; msg = rspamd_http_new_message(HTTP_REQUEST); @@ -153,7 +153,7 @@ free_http_cbdata_common(struct http_callback_data *cbd, gboolean plan_new) if (cbd->addrs) { rspamd_inet_addr_t *addr; - guint i; + unsigned int i; PTR_ARRAY_FOREACH(cbd->addrs, i, addr) { @@ -306,7 +306,7 @@ http_map_finish(struct rspamd_http_connection *conn, struct rspamd_http_map_cached_cbdata *cache_cbd; const rspamd_ftok_t *expires_hdr, *etag_hdr; char next_check_date[128]; - guchar *in = NULL; + unsigned char *in = NULL; gsize dlen = 0; map = cbd->map; @@ -444,7 +444,7 @@ http_map_finish(struct rspamd_http_connection *conn, ZSTD_DStream *zstream; ZSTD_inBuffer zin; ZSTD_outBuffer zout; - guchar *out; + unsigned char *out; gsize outlen, r; zstream = ZSTD_createDStream(); @@ -585,12 +585,12 @@ err: static gboolean read_map_file_chunks(struct rspamd_map *map, struct map_cb_data *cbdata, - const gchar *fname, gsize len, goffset off) + const char *fname, gsize len, goffset off) { - gint fd; + int fd; gssize r, avail; gsize buflen = 1024 * 1024; - gchar *pos, *bytes; + char *pos, *bytes; fd = rspamd_file_xopen(fname, O_RDONLY, 0, TRUE); @@ -602,7 +602,7 @@ read_map_file_chunks(struct rspamd_map *map, struct map_cb_data *cbdata, if (lseek(fd, off, SEEK_SET) == -1) { msg_err_map("can't seek in map to pos %d for buffered reading %s: %s", - (gint) off, fname, strerror(errno)); + (int) off, fname, strerror(errno)); close(fd); return FALSE; @@ -614,13 +614,13 @@ read_map_file_chunks(struct rspamd_map *map, struct map_cb_data *cbdata, pos = bytes; while ((r = read(fd, pos, avail)) > 0) { - gchar *end = bytes + (pos - bytes) + r; + char *end = bytes + (pos - bytes) + r; msg_debug_map("%s: read map chunk, %z bytes", fname, r); pos = map->read_callback(bytes, end - bytes, cbdata, r == len); if (pos && pos > bytes && pos < end) { - guint remain = end - pos; + unsigned int remain = end - pos; memmove(bytes, pos, remain); pos = bytes + remain; @@ -660,10 +660,10 @@ read_map_file_chunks(struct rspamd_map *map, struct map_cb_data *cbdata, } static gboolean -rspamd_map_check_sig_pk_mem(const guchar *sig, +rspamd_map_check_sig_pk_mem(const unsigned char *sig, gsize siglen, struct rspamd_map *map, - const guchar *input, + const unsigned char *input, gsize inlen, struct rspamd_cryptobox_pubkey *pk) { @@ -698,15 +698,15 @@ static gboolean rspamd_map_check_file_sig(const char *fname, struct rspamd_map *map, struct rspamd_map_backend *bk, - const guchar *input, + const unsigned char *input, gsize inlen) { - guchar *data; + unsigned char *data; struct rspamd_cryptobox_pubkey *pk = NULL; GString *b32_key; gboolean ret = TRUE; gsize len = 0; - gchar fpath[PATH_MAX]; + char fpath[PATH_MAX]; if (bk->trusted_pubkey == NULL) { /* Try to load and check pubkey */ @@ -772,7 +772,7 @@ static gboolean read_map_file(struct rspamd_map *map, struct file_map_data *data, struct rspamd_map_backend *bk, struct map_periodic_cbdata *periodic) { - gchar *bytes; + char *bytes; gsize len; struct stat st; @@ -836,7 +836,7 @@ read_map_file(struct rspamd_map *map, struct file_map_data *data, ZSTD_DStream *zstream; ZSTD_inBuffer zin; ZSTD_outBuffer zout; - guchar *out; + unsigned char *out; gsize outlen, r; zstream = ZSTD_createDStream(); @@ -908,7 +908,7 @@ static gboolean read_map_static(struct rspamd_map *map, struct static_map_data *data, struct rspamd_map_backend *bk, struct map_periodic_cbdata *periodic) { - guchar *bytes; + unsigned char *bytes; gsize len; if (map->read_callback == NULL || map->fin_callback == NULL) { @@ -925,7 +925,7 @@ read_map_static(struct rspamd_map *map, struct static_map_data *data, ZSTD_DStream *zstream; ZSTD_inBuffer zin; ZSTD_outBuffer zout; - guchar *out; + unsigned char *out; gsize outlen, r; zstream = ZSTD_createDStream(); @@ -1041,11 +1041,11 @@ rspamd_map_periodic_callback(struct ev_loop *loop, ev_timer *w, int revents) static void rspamd_map_schedule_periodic(struct rspamd_map *map, int how) { - const gdouble error_mult = 20.0, lock_mult = 0.1; - static const gdouble min_timer_interval = 2.0; - const gchar *reason = "unknown reason"; - gdouble jittered_sec; - gdouble timeout; + const double error_mult = 20.0, lock_mult = 0.1; + static const double min_timer_interval = 2.0; + const char *reason = "unknown reason"; + double jittered_sec; + double timeout; struct map_periodic_cbdata *cbd; if (map->scheduled_check || (map->wrk && @@ -1070,7 +1070,7 @@ rspamd_map_schedule_periodic(struct rspamd_map *map, int how) if (timeout > 0 && timeout < map->poll_timeout) { /* Early check case, jitter */ - gdouble poll_timeout = map->poll_timeout; + double poll_timeout = map->poll_timeout; if (how & RSPAMD_MAP_SCHEDULE_ERROR) { poll_timeout = map->poll_timeout * error_mult; @@ -1172,7 +1172,7 @@ rspamd_map_schedule_periodic(struct rspamd_map *map, int how) cbd, jittered_sec, map->name, reason); } -static gint +static int rspamd_map_af_to_weight(const rspamd_inet_addr_t *addr) { int ret; @@ -1192,12 +1192,12 @@ rspamd_map_af_to_weight(const rspamd_inet_addr_t *addr) return ret; } -static gint +static int rspamd_map_dns_address_sort_func(gconstpointer a, gconstpointer b) { const rspamd_inet_addr_t *ip1 = *(const rspamd_inet_addr_t **) a, *ip2 = *(const rspamd_inet_addr_t **) b; - gint w1, w2; + int w1, w2; w1 = rspamd_map_af_to_weight(ip1); w2 = rspamd_map_af_to_weight(ip2); @@ -1212,7 +1212,7 @@ rspamd_map_dns_callback(struct rdns_reply *reply, void *arg) struct http_callback_data *cbd = arg; struct rdns_reply_entry *cur_rep; struct rspamd_map *map; - guint flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED; + unsigned int flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED; map = cbd->map; @@ -1264,7 +1264,7 @@ rspamd_map_dns_callback(struct rdns_reply *reply, void *arg) if (cbd->stage == http_map_http_conn && cbd->addrs->len > 0) { rspamd_ptr_array_shuffle(cbd->addrs); - gint idx = 0; + int idx = 0; /* * For the existing addr we can just select any address as we have * data available @@ -1328,7 +1328,7 @@ rspamd_map_dns_callback(struct rdns_reply *reply, void *arg) static gboolean rspamd_map_read_cached(struct rspamd_map *map, struct rspamd_map_backend *bk, - struct map_periodic_cbdata *periodic, const gchar *host) + struct map_periodic_cbdata *periodic, const char *host) { gsize mmap_len, len; gpointer in; @@ -1366,7 +1366,7 @@ rspamd_map_read_cached(struct rspamd_map *map, struct rspamd_map_backend *bk, ZSTD_DStream *zstream; ZSTD_inBuffer zin; ZSTD_outBuffer zout; - guchar *out; + unsigned char *out; gsize outlen, r; zstream = ZSTD_createDStream(); @@ -1429,8 +1429,8 @@ static gboolean rspamd_map_has_http_cached_file(struct rspamd_map *map, struct rspamd_map_backend *bk) { - gchar path[PATH_MAX]; - guchar digest[rspamd_cryptobox_HASHBYTES]; + char path[PATH_MAX]; + unsigned char digest[rspamd_cryptobox_HASHBYTES]; struct rspamd_config *cfg = map->cfg; struct stat st; @@ -1454,13 +1454,13 @@ static gboolean rspamd_map_save_http_cached_file(struct rspamd_map *map, struct rspamd_map_backend *bk, struct http_map_data *htdata, - const guchar *data, + const unsigned char *data, gsize len) { - gchar path[PATH_MAX]; - guchar digest[rspamd_cryptobox_HASHBYTES]; + char path[PATH_MAX]; + unsigned char digest[rspamd_cryptobox_HASHBYTES]; struct rspamd_config *cfg = map->cfg; - gint fd; + int fd; struct rspamd_http_file_data header; if (cfg->maps_cache_dir == NULL || cfg->maps_cache_dir[0] == '\0') { @@ -1539,10 +1539,10 @@ rspamd_map_update_http_cached_file(struct rspamd_map *map, struct rspamd_map_backend *bk, struct http_map_data *htdata) { - gchar path[PATH_MAX]; - guchar digest[rspamd_cryptobox_HASHBYTES]; + char path[PATH_MAX]; + unsigned char digest[rspamd_cryptobox_HASHBYTES]; struct rspamd_config *cfg = map->cfg; - gint fd; + int fd; struct rspamd_http_file_data header; if (!rspamd_map_has_http_cached_file(map, bk)) { @@ -1612,10 +1612,10 @@ rspamd_map_read_http_cached_file(struct rspamd_map *map, struct http_map_data *htdata, struct map_cb_data *cbdata) { - gchar path[PATH_MAX]; - guchar digest[rspamd_cryptobox_HASHBYTES]; + char path[PATH_MAX]; + unsigned char digest[rspamd_cryptobox_HASHBYTES]; struct rspamd_config *cfg = map->cfg; - gint fd; + int fd; struct stat st; struct rspamd_http_file_data header; @@ -1707,7 +1707,7 @@ rspamd_map_read_http_cached_file(struct rspamd_map *map, } struct tm tm; - gchar ncheck_buf[32], lm_buf[32]; + char ncheck_buf[32], lm_buf[32]; rspamd_localtime(map->next_check, &tm); strftime(ncheck_buf, sizeof(ncheck_buf) - 1, "%Y-%m-%d %H:%M:%S", &tm); @@ -1737,7 +1737,7 @@ rspamd_map_common_http_callback(struct rspamd_map *map, { struct http_map_data *data; struct http_callback_data *cbd; - guint flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED; + unsigned int flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED; data = bk->data.hd; @@ -1846,7 +1846,7 @@ check: } else if (map->r->r) { /* Send both A and AAAA requests */ - guint nreq = 0; + unsigned int nreq = 0; if (rdns_make_request_full(map->r->r, rspamd_map_dns_callback, cbd, map->cfg->dns_timeout, map->cfg->dns_retransmits, 1, @@ -2107,7 +2107,7 @@ rspamd_map_on_stat(struct ev_loop *loop, ev_stat *w, int revents) /* Fire need modify flag */ struct rspamd_map_backend *bk; - guint i; + unsigned int i; PTR_ARRAY_FOREACH(map->backends, i, bk) { @@ -2138,7 +2138,7 @@ void rspamd_map_watch(struct rspamd_config *cfg, GList *cur = cfg->maps; struct rspamd_map *map; struct rspamd_map_backend *bk; - guint i; + unsigned int i; g_assert(how > RSPAMD_MAP_WATCH_MIN && how < RSPAMD_MAP_WATCH_MAX); @@ -2228,7 +2228,7 @@ void rspamd_map_preload(struct rspamd_config *cfg) GList *cur = cfg->maps; struct rspamd_map *map; struct rspamd_map_backend *bk; - guint i; + unsigned int i; gboolean map_ok; /* First of all do synced read of data */ @@ -2337,7 +2337,7 @@ void rspamd_map_remove_all(struct rspamd_config *cfg) GList *cur; struct rspamd_map_backend *bk; struct map_cb_data cbdata; - guint i; + unsigned int i; for (cur = cfg->maps; cur != NULL; cur = g_list_next(cur)) { map = cur->data; @@ -2374,11 +2374,11 @@ void rspamd_map_remove_all(struct rspamd_config *cfg) cfg->maps = NULL; } -static const gchar * +static const char * rspamd_map_check_proto(struct rspamd_config *cfg, - const gchar *map_line, struct rspamd_map_backend *bk) + const char *map_line, struct rspamd_map_backend *bk) { - const gchar *pos = map_line, *end, *end_key; + const char *pos = map_line, *end, *end_key; g_assert(bk != NULL); g_assert(pos != NULL); @@ -2489,7 +2489,7 @@ rspamd_map_check_proto(struct rspamd_config *cfg, } gboolean -rspamd_map_is_map(const gchar *map_line) +rspamd_map_is_map(const char *map_line) { gboolean ret = FALSE; @@ -2589,14 +2589,14 @@ rspamd_map_backend_dtor(struct rspamd_map_backend *bk) } static struct rspamd_map_backend * -rspamd_map_parse_backend(struct rspamd_config *cfg, const gchar *map_line) +rspamd_map_parse_backend(struct rspamd_config *cfg, const char *map_line) { struct rspamd_map_backend *bk; struct file_map_data *fdata = NULL; struct http_map_data *hdata = NULL; struct static_map_data *sdata = NULL; struct http_parser_url up; - const gchar *end, *p; + const char *end, *p; rspamd_ftok_t tok; bk = g_malloc0(sizeof(*bk)); @@ -2693,8 +2693,8 @@ rspamd_map_parse_backend(struct rspamd_config *cfg, const gchar *map_line) if (up.field_set & (1u << UF_USERINFO)) { /* Create authorisation header for basic auth */ - guint len = sizeof("Basic ") + - up.field_data[UF_USERINFO].len * 8 / 5 + 4; + unsigned int len = sizeof("Basic ") + + up.field_data[UF_USERINFO].len * 8 / 5 + 4; hdata->userinfo = g_malloc(len); rspamd_snprintf(hdata->userinfo, len, "Basic %*Bs", (int) up.field_data[UF_USERINFO].len, @@ -2731,7 +2731,7 @@ rspamd_map_parse_backend(struct rspamd_config *cfg, const gchar *map_line) ucl_object_type(user_obj) == UCL_STRING && ucl_object_type(password_obj) == UCL_STRING) { - gchar *tmpbuf; + char *tmpbuf; unsigned tlen; /* User + password + ':' */ @@ -2793,9 +2793,9 @@ static void rspamd_map_calculate_hash(struct rspamd_map *map) { struct rspamd_map_backend *bk; - guint i; + unsigned int i; rspamd_cryptobox_hash_state_t st; - gchar *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES]; + char *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES]; rspamd_cryptobox_hash_init(&st, NULL, 0); @@ -2816,7 +2816,7 @@ rspamd_map_add_static_string(struct rspamd_config *cfg, GString *target) { gsize sz; - const gchar *dline; + const char *dline; if (ucl_object_type(elt) != UCL_STRING) { msg_err_config("map has static backend but `data` is " @@ -2841,8 +2841,8 @@ rspamd_map_add_static_string(struct rspamd_config *cfg, struct rspamd_map * rspamd_map_add(struct rspamd_config *cfg, - const gchar *map_line, - const gchar *description, + const char *map_line, + const char *description, map_cb_t read_callback, map_fin_cb_t fin_callback, map_dtor_t dtor, @@ -2873,7 +2873,7 @@ rspamd_map_add(struct rspamd_config *cfg, map->cfg = cfg; map->id = rspamd_random_uint64_fast(); map->locked = - rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(gint)); + rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(int)); map->backends = g_ptr_array_sized_new(1); map->wrk = worker; rspamd_mempool_add_destructor(cfg->cfg_pool, rspamd_ptr_array_free_hard, @@ -2904,8 +2904,8 @@ rspamd_map_add(struct rspamd_config *cfg, struct rspamd_map * rspamd_map_add_fake(struct rspamd_config *cfg, - const gchar *description, - const gchar *name) + const char *description, + const char *name) { struct rspamd_map *map; @@ -2943,19 +2943,19 @@ rspamd_map_add_backend(struct rspamd_map *map, struct rspamd_map_backend *bk) struct rspamd_map * rspamd_map_add_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, - const gchar *description, + const char *description, map_cb_t read_callback, map_fin_cb_t fin_callback, map_dtor_t dtor, void **user_data, struct rspamd_worker *worker, - gint flags) + int flags) { ucl_object_iter_t it = NULL; const ucl_object_t *cur, *elt; struct rspamd_map *map; struct rspamd_map_backend *bk; - guint i; + unsigned int i; g_assert(obj != NULL); @@ -2973,7 +2973,7 @@ rspamd_map_add_from_ucl(struct rspamd_config *cfg, map->cfg = cfg; map->id = rspamd_random_uint64_fast(); map->locked = - rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(gint)); + rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(int)); map->backends = g_ptr_array_new(); map->wrk = worker; map->no_file_read = (flags & RSPAMD_MAP_FILE_NO_READ); diff --git a/src/libserver/maps/map.h b/src/libserver/maps/map.h index 04df16ef0..b2ba53118 100644 --- a/src/libserver/maps/map.h +++ b/src/libserver/maps/map.h @@ -30,8 +30,8 @@ struct rspamd_map; /** * Callback types */ -typedef gchar *(*map_cb_t)(gchar *chunk, gint len, - struct map_cb_data *data, gboolean final); +typedef char *(*map_cb_t)(char *chunk, int len, + struct map_cb_data *data, gboolean final); typedef void (*map_fin_cb_t)(struct map_cb_data *data, void **target); @@ -50,7 +50,7 @@ typedef void (*rspamd_map_on_load_function)(struct rspamd_map *map, gpointer ud) */ struct map_cb_data { struct rspamd_map *map; - gint state; + int state; bool errored; void *prev_data; void *cur_data; @@ -61,7 +61,7 @@ struct map_cb_data { * @param map_line * @return */ -gboolean rspamd_map_is_map(const gchar *map_line); +gboolean rspamd_map_is_map(const char *map_line); enum rspamd_map_flags { RSPAMD_MAP_DEFAULT = 0, @@ -73,8 +73,8 @@ enum rspamd_map_flags { * Add map from line */ struct rspamd_map *rspamd_map_add(struct rspamd_config *cfg, - const gchar *map_line, - const gchar *description, + const char *map_line, + const char *description, map_cb_t read_callback, map_fin_cb_t fin_callback, map_dtor_t dtor, @@ -87,7 +87,7 @@ struct rspamd_map *rspamd_map_add(struct rspamd_config *cfg, */ struct rspamd_map *rspamd_map_add_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, - const gchar *description, + const char *description, map_cb_t read_callback, map_fin_cb_t fin_callback, map_dtor_t dtor, @@ -102,8 +102,8 @@ struct rspamd_map *rspamd_map_add_from_ucl(struct rspamd_config *cfg, * @return */ struct rspamd_map *rspamd_map_add_fake(struct rspamd_config *cfg, - const gchar *description, - const gchar *name); + const char *description, + const char *name); enum rspamd_map_watch_type { diff --git a/src/libserver/maps/map_helpers.c b/src/libserver/maps/map_helpers.c index 8cb5eda78..505932563 100644 --- a/src/libserver/maps/map_helpers.c +++ b/src/libserver/maps/map_helpers.c @@ -36,12 +36,12 @@ static const uint64_t map_hash_seed = 0xdeadbabeULL; -static const gchar *const hash_fill = "1"; +static const char *const hash_fill = "1"; struct rspamd_map_helper_value { gsize hits; gconstpointer key; - gchar value[]; /* Null terminated */ + char value[]; /* Null terminated */ }; #define rspamd_map_ftok_hash(t) (rspamd_icase_hash((t).begin, (t).len, rspamd_hash_seed())) @@ -75,7 +75,7 @@ struct rspamd_cdb_map_helper { struct rspamd_regexp_map_helper { rspamd_cryptobox_hash_state_t hst; - guchar re_digest[rspamd_cryptobox_HASHBYTES]; + unsigned char re_digest[rspamd_cryptobox_HASHBYTES]; rspamd_mempool_t *pool; struct rspamd_map *map; GPtrArray *regexps; @@ -85,9 +85,9 @@ struct rspamd_regexp_map_helper { #ifdef WITH_HYPERSCAN rspamd_hyperscan_t *hs_db; hs_scratch_t *hs_scratch; - gchar **patterns; - gint *flags; - gint *ids; + char **patterns; + int *flags; + int *ids; #endif }; @@ -111,13 +111,13 @@ struct rspamd_regexp_map_helper { stripped_value = g_strstrip(value); \ } while (0) -gchar * +char * rspamd_parse_kv_list( - gchar *chunk, - gint len, + char *chunk, + int len, struct map_cb_data *data, rspamd_map_insert_func func, - const gchar *default_value, + const char *default_value, gboolean final) { enum { @@ -135,9 +135,9 @@ rspamd_parse_kv_list( map_read_eol, }; - gchar *c, *p, *key = NULL, *value = NULL, *stripped_key, *stripped_value, *end; + char *c, *p, *key = NULL, *value = NULL, *stripped_key, *stripped_value, *end; struct rspamd_map *map = data->map; - guint line_number = 0; + unsigned int line_number = 0; p = chunk; c = p; @@ -470,7 +470,7 @@ void rspamd_map_helper_insert_radix(gpointer st, gconstpointer key, gconstpointe khiter_t k; gconstpointer nk; rspamd_ftok_t tok; - gint res; + int res; struct rspamd_map *map; map = r->map; @@ -524,7 +524,7 @@ void rspamd_map_helper_insert_radix_resolve(gpointer st, gconstpointer key, gcon khiter_t k; gconstpointer nk; rspamd_ftok_t tok; - gint res; + int res; struct rspamd_map *map; map = r->map; @@ -583,7 +583,7 @@ void rspamd_map_helper_insert_hash(gpointer st, gconstpointer key, gconstpointer khiter_t k; gconstpointer nk; gsize vlen; - gint r; + int r; rspamd_ftok_t tok; struct rspamd_map *map; @@ -629,16 +629,16 @@ void rspamd_map_helper_insert_re(gpointer st, gconstpointer key, gconstpointer v struct rspamd_regexp_map_helper *re_map = st; struct rspamd_map *map; rspamd_regexp_t *re; - gchar *escaped; + char *escaped; GError *err = NULL; - gint pcre_flags; + int pcre_flags; gsize escaped_len; struct rspamd_map_helper_value *val; khiter_t k; rspamd_ftok_t tok; gconstpointer nk; gsize vlen; - gint r; + int r; map = re_map->map; @@ -801,7 +801,7 @@ rspamd_map_helper_new_radix(struct rspamd_map *map) { struct rspamd_radix_map_helper *r; rspamd_mempool_t *pool; - const gchar *name = "unnamed"; + const char *name = "unnamed"; if (map) { pool = rspamd_mempool_new(rspamd_mempool_suggest_size(), @@ -882,7 +882,7 @@ rspamd_map_helper_new_regexp(struct rspamd_map *map, void rspamd_map_helper_destroy_regexp(struct rspamd_regexp_map_helper *re_map) { rspamd_regexp_t *re; - guint i; + unsigned int i; if (!re_map || !re_map->regexps) { return; @@ -924,10 +924,10 @@ void rspamd_map_helper_destroy_regexp(struct rspamd_regexp_map_helper *re_map) rspamd_mempool_delete(pool); } -gchar * +char * rspamd_kv_list_read( - gchar *chunk, - gint len, + char *chunk, + int len, struct map_cb_data *data, gboolean final) { @@ -990,10 +990,10 @@ void rspamd_kv_list_dtor(struct map_cb_data *data) } } -gchar * +char * rspamd_radix_read( - gchar *chunk, - gint len, + char *chunk, + int len, struct map_cb_data *data, gboolean final) { @@ -1065,7 +1065,7 @@ void rspamd_radix_dtor(struct map_cb_data *data) static gboolean rspamd_try_load_re_map_cache(struct rspamd_regexp_map_helper *re_map) { - gchar fp[PATH_MAX]; + char fp[PATH_MAX]; struct rspamd_map *map; map = re_map->map; @@ -1076,7 +1076,7 @@ rspamd_try_load_re_map_cache(struct rspamd_regexp_map_helper *re_map) rspamd_snprintf(fp, sizeof(fp), "%s/%*xs.hsmc", map->cfg->hs_cache_dir, - (gint) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest); + (int) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest); re_map->hs_db = rspamd_hyperscan_maybe_load(fp, 0); @@ -1086,9 +1086,9 @@ rspamd_try_load_re_map_cache(struct rspamd_regexp_map_helper *re_map) static gboolean rspamd_try_save_re_map_cache(struct rspamd_regexp_map_helper *re_map) { - gchar fp[PATH_MAX], np[PATH_MAX]; + char fp[PATH_MAX], np[PATH_MAX]; gsize len; - gint fd; + int fd; char *bytes = NULL; struct rspamd_map *map; @@ -1115,7 +1115,7 @@ rspamd_try_save_re_map_cache(struct rspamd_regexp_map_helper *re_map) rspamd_snprintf(np, sizeof(np), "%s/%*xs.hsmc", re_map->map->cfg->hs_cache_dir, - (gint) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest); + (int) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest); if (rename(fp, np) == -1) { msg_warn_map("cannot rename hyperscan cache from %s to %s: %s", @@ -1148,12 +1148,12 @@ static void rspamd_re_map_finalize(struct rspamd_regexp_map_helper *re_map) { #ifdef WITH_HYPERSCAN - guint i; + unsigned int i; hs_platform_info_t plt; hs_compile_error_t *err; struct rspamd_map *map; rspamd_regexp_t *re; - gint pcre_flags; + int pcre_flags; map = re_map->map; @@ -1170,14 +1170,14 @@ rspamd_re_map_finalize(struct rspamd_regexp_map_helper *re_map) return; } - re_map->patterns = g_new(gchar *, re_map->regexps->len); - re_map->flags = g_new(gint, re_map->regexps->len); - re_map->ids = g_new(gint, re_map->regexps->len); + re_map->patterns = g_new(char *, re_map->regexps->len); + re_map->flags = g_new(int, re_map->regexps->len); + re_map->ids = g_new(int, re_map->regexps->len); for (i = 0; i < re_map->regexps->len; i++) { - const gchar *pat; - gchar *escaped; - gint pat_flags; + const char *pat; + char *escaped; + int pat_flags; re = g_ptr_array_index(re_map->regexps, i); pcre_flags = rspamd_regexp_get_pcre_flags(re); @@ -1225,10 +1225,10 @@ rspamd_re_map_finalize(struct rspamd_regexp_map_helper *re_map) if (re_map->regexps->len > 0 && re_map->patterns) { if (!rspamd_try_load_re_map_cache(re_map)) { - gdouble ts1 = rspamd_get_ticks(FALSE); + double ts1 = rspamd_get_ticks(FALSE); hs_database_t *hs_db = NULL; - if (hs_compile_multi((const gchar **) re_map->patterns, + if (hs_compile_multi((const char **) re_map->patterns, re_map->flags, re_map->ids, re_map->regexps->len, @@ -1249,7 +1249,7 @@ rspamd_re_map_finalize(struct rspamd_regexp_map_helper *re_map) char fpath[PATH_MAX]; rspamd_snprintf(fpath, sizeof(fpath), "%s/%*xs.hsmc", re_map->map->cfg->hs_cache_dir, - (gint) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest); + (int) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest); re_map->hs_db = rspamd_hyperscan_from_raw_db(hs_db, fpath); } else { @@ -1278,10 +1278,10 @@ rspamd_re_map_finalize(struct rspamd_regexp_map_helper *re_map) #endif } -gchar * +char * rspamd_regexp_list_read_single( - gchar *chunk, - gint len, + char *chunk, + int len, struct map_cb_data *data, gboolean final) { @@ -1301,10 +1301,10 @@ rspamd_regexp_list_read_single( final); } -gchar * +char * rspamd_glob_list_read_single( - gchar *chunk, - gint len, + char *chunk, + int len, struct map_cb_data *data, gboolean final) { @@ -1324,10 +1324,10 @@ rspamd_glob_list_read_single( final); } -gchar * +char * rspamd_regexp_list_read_multiple( - gchar *chunk, - gint len, + char *chunk, + int len, struct map_cb_data *data, gboolean final) { @@ -1348,10 +1348,10 @@ rspamd_regexp_list_read_multiple( final); } -gchar * +char * rspamd_glob_list_read_multiple( - gchar *chunk, - gint len, + char *chunk, + int len, struct map_cb_data *data, gboolean final) { @@ -1423,7 +1423,7 @@ rspamd_match_hs_single_handler(unsigned int id, unsigned long long from, unsigned long long to, unsigned int flags, void *context) { - guint *i = context; + unsigned int *i = context; /* Always return non-zero as we need a single match here */ *i = id; @@ -1434,11 +1434,11 @@ rspamd_match_hs_single_handler(unsigned int id, unsigned long long from, gconstpointer rspamd_match_regexp_map_single(struct rspamd_regexp_map_helper *map, - const gchar *in, gsize len) + const char *in, gsize len) { - guint i; + unsigned int i; rspamd_regexp_t *re; - gint res = 0; + int res = 0; gpointer ret = NULL; struct rspamd_map_helper_value *val; gboolean validated = FALSE; @@ -1526,12 +1526,12 @@ rspamd_match_hs_multiple_handler(unsigned int id, unsigned long long from, GPtrArray * rspamd_match_regexp_map_all(struct rspamd_regexp_map_helper *map, - const gchar *in, gsize len) + const char *in, gsize len) { - guint i; + unsigned int i; rspamd_regexp_t *re; GPtrArray *ret; - gint res = 0; + int res = 0; gboolean validated = FALSE; struct rspamd_map_helper_value *val; @@ -1594,7 +1594,7 @@ rspamd_match_regexp_map_all(struct rspamd_regexp_map_helper *map, } gconstpointer -rspamd_match_hash_map(struct rspamd_hash_map_helper *map, const gchar *in, +rspamd_match_hash_map(struct rspamd_hash_map_helper *map, const char *in, gsize len) { khiter_t k; @@ -1622,7 +1622,7 @@ rspamd_match_hash_map(struct rspamd_hash_map_helper *map, const gchar *in, gconstpointer rspamd_match_radix_map(struct rspamd_radix_map_helper *map, - const guchar *in, gsize inlen) + const unsigned char *in, gsize inlen) { struct rspamd_map_helper_value *val; @@ -1706,9 +1706,9 @@ void rspamd_map_helper_destroy_cdb(struct rspamd_cdb_map_helper *c) g_free(c); } -gchar * -rspamd_cdb_list_read(gchar *chunk, - gint len, +char * +rspamd_cdb_list_read(char *chunk, + int len, struct map_cb_data *data, gboolean final) { @@ -1741,7 +1741,7 @@ rspamd_cdb_list_read(gchar *chunk, if (found == NULL) { /* New cdb */ - gint fd; + int fd; struct cdb *cdb; fd = rspamd_file_xopen(chunk, O_RDONLY, 0, TRUE); @@ -1813,7 +1813,7 @@ void rspamd_cdb_list_dtor(struct map_cb_data *data) gconstpointer rspamd_match_cdb_map(struct rspamd_cdb_map_helper *map, - const gchar *in, gsize inlen) + const char *in, gsize inlen) { if (map == NULL || map->cdbs.head == NULL) { return NULL; diff --git a/src/libserver/maps/map_helpers.h b/src/libserver/maps/map_helpers.h index 82c62b637..41e352c01 100644 --- a/src/libserver/maps/map_helpers.h +++ b/src/libserver/maps/map_helpers.h @@ -53,9 +53,9 @@ typedef void (*rspamd_map_insert_func)(gpointer st, gconstpointer key, /** * Radix list is a list like ip/mask */ -gchar *rspamd_radix_read( - gchar *chunk, - gint len, +char *rspamd_radix_read( + char *chunk, + int len, struct map_cb_data *data, gboolean final); @@ -66,9 +66,9 @@ void rspamd_radix_dtor(struct map_cb_data *data); /** * Kv list is an ordinal list of keys and values separated by whitespace */ -gchar *rspamd_kv_list_read( - gchar *chunk, - gint len, +char *rspamd_kv_list_read( + char *chunk, + int len, struct map_cb_data *data, gboolean final); @@ -80,9 +80,9 @@ void rspamd_kv_list_dtor(struct map_cb_data *data); * Cdb is a cdb mapped file with shared data * chunk must be filename! */ -gchar *rspamd_cdb_list_read( - gchar *chunk, - gint len, +char *rspamd_cdb_list_read( + char *chunk, + int len, struct map_cb_data *data, gboolean final); void rspamd_cdb_list_fin(struct map_cb_data *data, void **target); @@ -92,27 +92,27 @@ void rspamd_cdb_list_dtor(struct map_cb_data *data); * Regexp list is a list of regular expressions */ -gchar *rspamd_regexp_list_read_single( - gchar *chunk, - gint len, +char *rspamd_regexp_list_read_single( + char *chunk, + int len, struct map_cb_data *data, gboolean final); -gchar *rspamd_regexp_list_read_multiple( - gchar *chunk, - gint len, +char *rspamd_regexp_list_read_multiple( + char *chunk, + int len, struct map_cb_data *data, gboolean final); -gchar *rspamd_glob_list_read_single( - gchar *chunk, - gint len, +char *rspamd_glob_list_read_single( + char *chunk, + int len, struct map_cb_data *data, gboolean final); -gchar *rspamd_glob_list_read_multiple( - gchar *chunk, - gint len, +char *rspamd_glob_list_read_multiple( + char *chunk, + int len, struct map_cb_data *data, gboolean final); @@ -123,13 +123,13 @@ void rspamd_regexp_list_dtor(struct map_cb_data *data); /** * FSM for lists parsing (support comments, blank lines and partial replies) */ -gchar * +char * rspamd_parse_kv_list( - gchar *chunk, - gint len, + char *chunk, + int len, struct map_cb_data *data, rspamd_map_insert_func func, - const gchar *default_value, + const char *default_value, gboolean final); /** @@ -141,7 +141,7 @@ rspamd_parse_kv_list( * @return */ gconstpointer rspamd_match_regexp_map_single(struct rspamd_regexp_map_helper *map, - const gchar *in, gsize len); + const char *in, gsize len); /** * Find a multiple (all) matching regexp for the specified text or NULL if @@ -152,7 +152,7 @@ gconstpointer rspamd_match_regexp_map_single(struct rspamd_regexp_map_helper *ma * @return */ GPtrArray *rspamd_match_regexp_map_all(struct rspamd_regexp_map_helper *map, - const gchar *in, gsize len); + const char *in, gsize len); /** * Find value matching specific key in a hash map @@ -162,7 +162,7 @@ GPtrArray *rspamd_match_regexp_map_all(struct rspamd_regexp_map_helper *map, * @return */ gconstpointer rspamd_match_hash_map(struct rspamd_hash_map_helper *map, - const gchar *in, gsize len); + const char *in, gsize len); /** * Find value matching specific key in a cdb map @@ -172,7 +172,7 @@ gconstpointer rspamd_match_hash_map(struct rspamd_hash_map_helper *map, * @return rspamd_ftok_t pointer (allocated in a static buffer!) */ gconstpointer rspamd_match_cdb_map(struct rspamd_cdb_map_helper *map, - const gchar *in, gsize len); + const char *in, gsize len); /** * Find value matching specific key in a hash map @@ -182,7 +182,7 @@ gconstpointer rspamd_match_cdb_map(struct rspamd_cdb_map_helper *map, * @return */ gconstpointer rspamd_match_radix_map(struct rspamd_radix_map_helper *map, - const guchar *in, gsize inlen); + const unsigned char *in, gsize inlen); gconstpointer rspamd_match_radix_map_addr(struct rspamd_radix_map_helper *map, const rspamd_inet_addr_t *addr); diff --git a/src/libserver/maps/map_private.h b/src/libserver/maps/map_private.h index 458c83230..d0b22fe36 100644 --- a/src/libserver/maps/map_private.h +++ b/src/libserver/maps/map_private.h @@ -29,7 +29,7 @@ extern "C" { typedef void (*rspamd_map_tmp_dtor)(gpointer p); -extern guint rspamd_map_log_id; +extern unsigned int rspamd_map_log_id; #define msg_err_map(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \ "map", map->tag, \ RSPAMD_LOG_FUNC, \ @@ -58,7 +58,7 @@ enum fetch_proto { * Data specific to file maps */ struct file_map_data { - gchar *filename; + char *filename; gboolean need_modify; ev_stat st_ev; }; @@ -77,10 +77,10 @@ struct rspamd_http_map_cached_cbdata { }; struct rspamd_map_cachepoint { - gint available; + int available; gsize len; time_t last_modified; - gchar shmem_name[256]; + char shmem_name[256]; }; /** @@ -91,20 +91,20 @@ struct http_map_data { struct rspamd_map_cachepoint *cache; /* Non-shared for cache owner, used to cleanup cache */ struct rspamd_http_map_cached_cbdata *cur_cache_cbd; - gchar *userinfo; - gchar *path; - gchar *host; - gchar *rest; + char *userinfo; + char *path; + char *host; + char *rest; rspamd_fstring_t *etag; time_t last_modified; time_t last_checked; gboolean request_sent; uint64_t gen; - guint16 port; + uint16_t port; }; struct static_map_data { - guchar *data; + unsigned char *data; gsize len; gboolean processed; }; @@ -127,7 +127,7 @@ struct rspamd_map_backend { uint32_t id; struct rspamd_cryptobox_pubkey *trusted_pubkey; union rspamd_map_backend_data data; - gchar *uri; + char *uri; ref_entry_t ref; }; @@ -144,8 +144,8 @@ struct rspamd_map { void **user_data; struct ev_loop *event_loop; struct rspamd_worker *wrk; - gchar *description; - gchar *name; + char *description; + char *name; uint32_t id; struct map_periodic_cbdata *scheduled_check; rspamd_map_tmp_dtor tmp_dtor; @@ -159,7 +159,7 @@ struct rspamd_map { uint64_t digest; /* Should we check HTTP or just load cached data */ ev_tstamp timeout; - gdouble poll_timeout; + double poll_timeout; time_t next_check; bool active_http; bool non_trivial; /* E.g. has http backends in active mode */ @@ -168,8 +168,8 @@ struct rspamd_map { bool no_file_read; /* Do not read files */ bool seen; /* This map has already been watched or pre-loaded */ /* Shared lock for temporary disabling of map reading (e.g. when this map is written by UI) */ - gint *locked; - gchar tag[MEMPOOL_UID_LEN]; + int *locked; + char tag[MEMPOOL_UID_LEN]; }; enum rspamd_map_http_stage { @@ -186,15 +186,15 @@ struct map_periodic_cbdata { gboolean need_modify; gboolean errored; gboolean locked; - guint cur_backend; + unsigned int cur_backend; ref_entry_t ref; }; -static const gchar rspamd_http_file_magic[] = +static const char rspamd_http_file_magic[] = {'r', 'm', 'c', 'd', '2', '0', '0', '0'}; struct rspamd_http_file_data { - guchar magic[sizeof(rspamd_http_file_magic)]; + unsigned char magic[sizeof(rspamd_http_file_magic)]; goffset data_off; gulong mtime; gulong next_check; diff --git a/src/libserver/milter.c b/src/libserver/milter.c index f60c606f3..dd64822c4 100644 --- a/src/libserver/milter.c +++ b/src/libserver/milter.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2017 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -90,12 +90,12 @@ rspamd_milter_obuf_free(struct rspamd_milter_outbuf *obuf) static void rspamd_milter_session_reset(struct rspamd_milter_session *session, - guint how) + unsigned int how) { struct rspamd_milter_outbuf *obuf, *obuf_tmp; struct rspamd_milter_private *priv = session->priv; struct rspamd_email_address *cur; - guint i; + unsigned int i; if (how & RSPAMD_MILTER_RESET_IO) { msg_debug_milter("cleanup IO on abort"); @@ -127,7 +127,7 @@ rspamd_milter_session_reset(struct rspamd_milter_session *session, } msg_debug_milter("cleanup %d recipients on abort", - (gint) session->rcpts->len); + (int) session->rcpts->len); g_ptr_array_free(session->rcpts, TRUE); session->rcpts = NULL; @@ -141,7 +141,7 @@ rspamd_milter_session_reset(struct rspamd_milter_session *session, if (priv->headers) { msg_debug_milter("cleanup headers"); - gchar *k; + char *k; GArray *ar; kh_foreach(priv->headers, k, ar, { @@ -206,7 +206,7 @@ rspamd_milter_session_dtor(struct rspamd_milter_session *session) } if (priv->headers) { - gchar *k; + char *k; GArray *ar; kh_foreach(priv->headers, k, ar, { @@ -247,16 +247,16 @@ rspamd_milter_on_protocol_ping(struct rspamd_milter_session *session, struct rspamd_milter_private *priv) { GError *err = NULL; - static const gchar reply[] = "HTTP/1.1 200 OK\r\n" - "Connection: close\r\n" - "Server: rspamd/2.7 (milter mode)\r\n" - "Content-Length: 6\r\n" - "Content-Type: text/plain\r\n" - "\r\n" - "pong\r\n"; + static const char reply[] = "HTTP/1.1 200 OK\r\n" + "Connection: close\r\n" + "Server: rspamd/2.7 (milter mode)\r\n" + "Content-Length: 6\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "pong\r\n"; if (write(priv->fd, reply, sizeof(reply)) == -1) { - gint serrno = errno; + int serrno = errno; msg_err_milter("cannot write pong reply: %s", strerror(serrno)); g_set_error(&err, rspamd_milter_quark(), serrno, "ping command IO error: %s", strerror(serrno)); @@ -272,8 +272,8 @@ rspamd_milter_on_protocol_ping(struct rspamd_milter_session *session, } } -static gint -rspamd_milter_http_on_url(http_parser *parser, const gchar *at, size_t length) +static int +rspamd_milter_http_on_url(http_parser *parser, const char *at, size_t length) { GString *url = (GString *) parser->data; @@ -283,7 +283,7 @@ rspamd_milter_http_on_url(http_parser *parser, const gchar *at, size_t length) } static void -rspamd_milter_io_handler(gint fd, gshort what, void *ud) +rspamd_milter_io_handler(int fd, gshort what, void *ud) { struct rspamd_milter_session *session = ud; struct rspamd_milter_private *priv; @@ -329,8 +329,8 @@ rspamd_milter_process_command(struct rspamd_milter_session *session, { GError *err; rspamd_fstring_t *buf; - const guchar *pos, *end, *zero; - guint cmdlen; + const unsigned char *pos, *end, *zero; + unsigned int cmdlen; uint32_t version, actions, protocol; buf = priv->parser.buf; @@ -364,7 +364,7 @@ rspamd_milter_process_command(struct rspamd_milter_session *session, */ zero = memchr(pos, '\0', cmdlen); - if (zero == NULL || zero > (end - sizeof(guint16) + 1)) { + if (zero == NULL || zero > (end - sizeof(uint16_t) + 1)) { err = g_error_new(rspamd_milter_quark(), EINVAL, "invalid " "connect command (no name)"); rspamd_milter_on_protocol_error(session, priv, err); @@ -372,9 +372,9 @@ rspamd_milter_process_command(struct rspamd_milter_session *session, return FALSE; } else { - guchar proto; - guint16 port; - gchar ip6_str[INET6_ADDRSTRLEN + 3]; + unsigned char proto; + uint16_t port; + char ip6_str[INET6_ADDRSTRLEN + 3]; gsize r; /* @@ -524,7 +524,7 @@ rspamd_milter_process_command(struct rspamd_milter_session *session, else { rspamd_fstring_t *name, *value; rspamd_ftok_t *name_tok, *value_tok; - const guchar *zero_val; + const unsigned char *zero_val; zero_val = memchr(zero + 1, '\0', end - zero - 1); @@ -607,16 +607,16 @@ rspamd_milter_process_command(struct rspamd_milter_session *session, else { if (end > zero && *(end - 1) == '\0') { khiter_t k; - gint res; + int res; - k = kh_get(milter_headers_hash_t, priv->headers, (gchar *) pos); + k = kh_get(milter_headers_hash_t, priv->headers, (char *) pos); if (k == kh_end(priv->headers)) { GArray *ar; k = kh_put(milter_headers_hash_t, priv->headers, g_strdup(pos), &res); - ar = g_array_new(FALSE, FALSE, sizeof(gint)); + ar = g_array_new(FALSE, FALSE, sizeof(int)); g_array_append_val(ar, priv->cur_hdr); kh_value(priv->headers, k) = ar; } @@ -644,7 +644,7 @@ rspamd_milter_process_command(struct rspamd_milter_session *session, while (pos < end) { struct rspamd_email_address *addr; - gchar *cpy; + char *cpy; zero = memchr(pos, '\0', end - pos); @@ -748,7 +748,7 @@ rspamd_milter_process_command(struct rspamd_milter_session *session, while (pos < end) { struct rspamd_email_address *addr; - gchar *cpy; + char *cpy; zero = memchr(pos, '\0', end - pos); @@ -807,7 +807,7 @@ rspamd_milter_process_command(struct rspamd_milter_session *session, } static gboolean -rspamd_milter_is_valid_cmd(guchar c) +rspamd_milter_is_valid_cmd(unsigned char c) { switch (c) { case RSPAMD_MILTER_CMD_ABORT: @@ -837,7 +837,7 @@ static gboolean rspamd_milter_consume_input(struct rspamd_milter_session *session, struct rspamd_milter_private *priv) { - const guchar *p, *end; + const unsigned char *p, *end; GError *err; p = priv->parser.buf->str + priv->parser.pos; @@ -845,7 +845,7 @@ rspamd_milter_consume_input(struct rspamd_milter_session *session, while (p < end) { msg_debug_milter("offset: %d, state: %d", - (gint) (p - (const guchar *) priv->parser.buf->str), + (int) (p - (const unsigned char *) priv->parser.buf->str), priv->parser.state); switch (priv->parser.state) { @@ -891,7 +891,7 @@ rspamd_milter_consume_input(struct rspamd_milter_session *session, } p++; - priv->parser.cmd_start = p - (const guchar *) priv->parser.buf->str; + priv->parser.cmd_start = p - (const unsigned char *) priv->parser.buf->str; break; case st_read_data: /* We might need some more data in buffer for further steps */ @@ -959,7 +959,7 @@ rspamd_milter_consume_input(struct rspamd_milter_session *session, return FALSE; } if (priv->parser.buf->allocated < priv->parser.datalen) { - priv->parser.pos = p - (const guchar *) priv->parser.buf->str; + priv->parser.pos = p - (const unsigned char *) priv->parser.buf->str; priv->parser.buf = rspamd_fstring_grow(priv->parser.buf, priv->parser.buf->len + priv->parser.datalen); /* This can realloc buffer */ @@ -981,7 +981,7 @@ rspamd_milter_consume_input(struct rspamd_milter_session *session, } else { /* Need to read more */ - priv->parser.pos = p - (const guchar *) priv->parser.buf->str; + priv->parser.pos = p - (const unsigned char *) priv->parser.buf->str; rspamd_milter_plan_io(session, priv, EV_READ); goto end; } @@ -1190,14 +1190,14 @@ rspamd_milter_handle_session(struct rspamd_milter_session *session, gboolean -rspamd_milter_handle_socket(gint fd, ev_tstamp timeout, +rspamd_milter_handle_socket(int fd, ev_tstamp timeout, rspamd_mempool_t *pool, struct ev_loop *ev_base, rspamd_milter_finish finish_cb, rspamd_milter_error error_cb, void *ud) { struct rspamd_milter_session *session; struct rspamd_milter_private *priv; - gint nfd = dup(fd); + int nfd = dup(fd); if (nfd == -1) { GError *err = g_error_new(rspamd_milter_quark(), errno, @@ -1266,16 +1266,16 @@ rspamd_milter_set_reply(struct rspamd_milter_session *session, return ret; } -#define SET_COMMAND(cmd, sz, reply, pos) \ - do { \ - uint32_t _len; \ - _len = (sz) + 1; \ - (reply) = rspamd_fstring_sized_new(sizeof(_len) + _len); \ - (reply)->len = sizeof(_len) + _len; \ - _len = htonl(_len); \ - memcpy((reply)->str, &_len, sizeof(_len)); \ - (reply)->str[sizeof(_len)] = (cmd); \ - (pos) = (guchar *) (reply)->str + sizeof(_len) + 1; \ +#define SET_COMMAND(cmd, sz, reply, pos) \ + do { \ + uint32_t _len; \ + _len = (sz) + 1; \ + (reply) = rspamd_fstring_sized_new(sizeof(_len) + _len); \ + (reply)->len = sizeof(_len) + _len; \ + _len = htonl(_len); \ + memcpy((reply)->str, &_len, sizeof(_len)); \ + (reply)->str[sizeof(_len)] = (cmd); \ + (pos) = (unsigned char *) (reply)->str + sizeof(_len) + 1; \ } while (0) gboolean @@ -1284,7 +1284,7 @@ rspamd_milter_send_action(struct rspamd_milter_session *session, { uint32_t ver, actions, protocol, idx; va_list ap; - guchar cmd, *pos; + unsigned char cmd, *pos; rspamd_fstring_t *reply = NULL; gsize len; GString *name, *value; @@ -1418,7 +1418,7 @@ rspamd_milter_del_header(struct rspamd_milter_session *session, GString value; uint32_t idx = 1; - value.str = (gchar *) ""; + value.str = (char *) ""; value.len = 0; return rspamd_milter_send_action(session, RSPAMD_MILTER_CHGHEADER, @@ -1584,7 +1584,7 @@ struct rspamd_http_message * rspamd_milter_to_http(struct rspamd_milter_session *session) { struct rspamd_http_message *msg; - guint i; + unsigned int i; struct rspamd_email_address *rcpt; struct rspamd_milter_private *priv = session->priv; @@ -1662,9 +1662,9 @@ rspamd_milter_update_userdata(struct rspamd_milter_session *session, static void rspamd_milter_remove_header_safe(struct rspamd_milter_session *session, - const gchar *key, gint nhdr) + const char *key, int nhdr) { - gint i; + int i; GString *hname, *hvalue; struct rspamd_milter_private *priv = session->priv; khiter_t k; @@ -1717,11 +1717,11 @@ rspamd_milter_remove_header_safe(struct rspamd_milter_session *session, static void rspamd_milter_extract_single_header(struct rspamd_milter_session *session, - const gchar *hdr, const ucl_object_t *obj) + const char *hdr, const ucl_object_t *obj) { GString *hname, *hvalue; struct rspamd_milter_private *priv = session->priv; - gint idx = -1; + int idx = -1; const ucl_object_t *val; val = ucl_object_lookup(obj, "value"); @@ -1995,12 +1995,12 @@ rspamd_milter_process_milter_block(struct rspamd_milter_session *session, void rspamd_milter_send_task_results(struct rspamd_milter_session *session, const ucl_object_t *results, - const gchar *new_body, + const char *new_body, gsize bodylen) { const ucl_object_t *elt; struct rspamd_milter_private *priv = session->priv; - const gchar *str_action; + const char *str_action; struct rspamd_action *action; rspamd_fstring_t *xcode = NULL, *rcode = NULL, *reply = NULL; GString *hname, *hvalue; @@ -2035,7 +2035,7 @@ void rspamd_milter_send_task_results(struct rspamd_milter_session *session, elt = ucl_object_lookup(results, "messages"); if (elt) { const ucl_object_t *smtp_res; - const gchar *msg; + const char *msg; gsize len = 0; smtp_res = ucl_object_lookup(elt, "smtp_message"); diff --git a/src/libserver/milter.h b/src/libserver/milter.h index 096cda89f..840f69126 100644 --- a/src/libserver/milter.h +++ b/src/libserver/milter.h @@ -52,9 +52,9 @@ struct rspamd_http_message; struct rspamd_config; struct rspamd_milter_context { - const gchar *spam_header; - const gchar *client_ca_name; - const gchar *reject_message; + const char *spam_header; + const char *client_ca_name; + const char *reject_message; void *sessions_cache; struct rspamd_config *cfg; gboolean discard_on_reject; @@ -73,10 +73,10 @@ struct rspamd_milter_session { ref_entry_t ref; }; -typedef void (*rspamd_milter_finish)(gint fd, +typedef void (*rspamd_milter_finish)(int fd, struct rspamd_milter_session *session, void *ud); -typedef void (*rspamd_milter_error)(gint fd, +typedef void (*rspamd_milter_error)(int fd, struct rspamd_milter_session *session, void *ud, GError *err); @@ -88,7 +88,7 @@ typedef void (*rspamd_milter_error)(gint fd, * @param ud * @return */ -gboolean rspamd_milter_handle_socket(gint fd, ev_tstamp timeout, +gboolean rspamd_milter_handle_socket(int fd, ev_tstamp timeout, rspamd_mempool_t *pool, struct ev_loop *ev_base, rspamd_milter_finish finish_cb, rspamd_milter_error error_cb, void *ud); @@ -164,7 +164,7 @@ struct rspamd_http_message *rspamd_milter_to_http( */ void rspamd_milter_send_task_results(struct rspamd_milter_session *session, const ucl_object_t *results, - const gchar *new_body, + const char *new_body, gsize bodylen); /** diff --git a/src/libserver/milter_internal.h b/src/libserver/milter_internal.h index bc292d380..68d43d99f 100644 --- a/src/libserver/milter_internal.h +++ b/src/libserver/milter_internal.h @@ -43,7 +43,7 @@ struct rspamd_milter_parser { goffset cmd_start; gsize datalen; enum rspamd_milter_state state; - gchar cur_cmd; + char cur_cmd; }; struct rspamd_milter_outbuf { @@ -70,7 +70,7 @@ struct rspamd_milter_private { struct ev_loop *event_loop; rspamd_mempool_t *pool; khash_t(milter_headers_hash_t) * headers; - gint cur_hdr; + int cur_hdr; rspamd_milter_finish fin_cb; rspamd_milter_error err_cb; void *ud; diff --git a/src/libserver/monitored.c b/src/libserver/monitored.c index cd8b4d675..593c745c4 100644 --- a/src/libserver/monitored.c +++ b/src/libserver/monitored.c @@ -22,12 +22,12 @@ #include "logger.h" #include "contrib/uthash/utlist.h" -static const gdouble default_monitoring_interval = 60.0; -static const guint default_max_errors = 2; -static const gdouble default_max_monitored_mult = 32; -static const gdouble default_min_monitored_mult = 0.1; -static const gdouble default_initial_monitored_mult = default_min_monitored_mult; -static const gdouble default_offline_monitored_mult = 8.0; +static const double default_monitoring_interval = 60.0; +static const unsigned int default_max_errors = 2; +static const double default_max_monitored_mult = 32; +static const double default_min_monitored_mult = 0.1; +static const double default_initial_monitored_mult = default_min_monitored_mult; +static const double default_offline_monitored_mult = 8.0; struct rspamd_monitored_methods { void *(*monitored_config)(struct rspamd_monitored *m, @@ -48,31 +48,31 @@ struct rspamd_monitored_ctx { GHashTable *helts; mon_change_cb change_cb; gpointer ud; - gdouble monitoring_interval; - gdouble max_monitored_mult; - gdouble min_monitored_mult; - gdouble initial_monitored_mult; - gdouble offline_monitored_mult; - guint max_errors; + double monitoring_interval; + double max_monitored_mult; + double min_monitored_mult; + double initial_monitored_mult; + double offline_monitored_mult; + unsigned int max_errors; gboolean initialized; }; struct rspamd_monitored { - gchar *url; - gdouble monitoring_mult; - gdouble offline_time; - gdouble total_offline_time; - gdouble latency; - guint nchecks; - guint max_errors; - guint cur_errors; + char *url; + double monitoring_mult; + double offline_time; + double total_offline_time; + double latency; + unsigned int nchecks; + unsigned int max_errors; + unsigned int cur_errors; gboolean alive; enum rspamd_monitored_type type; enum rspamd_monitored_flags flags; struct rspamd_monitored_ctx *ctx; struct rspamd_monitored_methods proc; ev_timer periodic; - gchar tag[RSPAMD_MONITORED_TAG_LEN]; + char tag[RSPAMD_MONITORED_TAG_LEN]; }; #define msg_err_mon(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \ @@ -100,7 +100,7 @@ INIT_LOG_MODULE(monitored) static inline void rspamd_monitored_propagate_error(struct rspamd_monitored *m, - const gchar *error) + const char *error) { if (m->alive) { if (m->cur_errors < m->max_errors) { @@ -154,9 +154,9 @@ rspamd_monitored_propagate_error(struct rspamd_monitored *m, } static inline void -rspamd_monitored_propagate_success(struct rspamd_monitored *m, gdouble lat) +rspamd_monitored_propagate_success(struct rspamd_monitored *m, double lat) { - gdouble t; + double t; m->cur_errors = 0; @@ -201,7 +201,7 @@ static void rspamd_monitored_periodic(EV_P_ ev_timer *w, int revents) { struct rspamd_monitored *m = (struct rspamd_monitored *) w->data; - gdouble jittered; + double jittered; gboolean ret = FALSE; if (m->proc.monitored_update) { @@ -222,17 +222,17 @@ struct rspamd_dns_monitored_conf { GString *request; radix_compressed_t *expected; struct rspamd_monitored *m; - gint expected_code; - gdouble check_tm; + int expected_code; + double check_tm; }; static void rspamd_monitored_dns_random(struct rspamd_monitored *m, struct rspamd_dns_monitored_conf *conf) { - gchar random_prefix[32]; - const gchar dns_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; - gint len; + char random_prefix[32]; + const char dns_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; + int len; len = rspamd_random_uint64_fast() % sizeof(random_prefix); @@ -240,8 +240,8 @@ rspamd_monitored_dns_random(struct rspamd_monitored *m, len = 8; } - for (guint i = 0; i < len; i++) { - guint idx = rspamd_random_uint64_fast() % (sizeof(dns_chars) - 1); + for (unsigned int i = 0; i < len; i++) { + unsigned int idx = rspamd_random_uint64_fast() % (sizeof(dns_chars) - 1); random_prefix[i] = dns_chars[idx]; } @@ -257,7 +257,7 @@ rspamd_monitored_dns_conf(struct rspamd_monitored *m, { struct rspamd_dns_monitored_conf *conf; const ucl_object_t *elt; - gint rt; + int rt; GString *req = g_string_sized_new(127); conf = g_malloc0(sizeof(*conf)); @@ -337,7 +337,7 @@ rspamd_monitored_dns_cb(struct rdns_reply *reply, void *arg) struct rspamd_monitored *m; struct rdns_reply_entry *cur; gboolean is_special_reply = FALSE; - gdouble lat; + double lat; m = conf->m; lat = rspamd_get_calendar_ticks() - conf->check_tm; @@ -499,7 +499,7 @@ void rspamd_monitored_ctx_config(struct rspamd_monitored_ctx *ctx, gpointer ud) { struct rspamd_monitored *m; - guint i; + unsigned int i; g_assert(ctx != NULL); ctx->event_loop = ev_base; @@ -532,15 +532,15 @@ rspamd_monitored_ctx_get_ev_base(struct rspamd_monitored_ctx *ctx) struct rspamd_monitored * rspamd_monitored_create_(struct rspamd_monitored_ctx *ctx, - const gchar *line, + const char *line, enum rspamd_monitored_type type, enum rspamd_monitored_flags flags, const ucl_object_t *opts, - const gchar *loc) + const char *loc) { struct rspamd_monitored *m; rspamd_cryptobox_hash_state_t st; - gchar *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES]; + char *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES]; g_assert(ctx != NULL); @@ -633,7 +633,7 @@ rspamd_monitored_set_alive(struct rspamd_monitored *m, gboolean alive) return st; } -gdouble +double rspamd_monitored_offline_time(struct rspamd_monitored *m) { g_assert(m != NULL); @@ -645,7 +645,7 @@ rspamd_monitored_offline_time(struct rspamd_monitored *m) return 0; } -gdouble +double rspamd_monitored_total_offline_time(struct rspamd_monitored *m) { g_assert(m != NULL); @@ -658,7 +658,7 @@ rspamd_monitored_total_offline_time(struct rspamd_monitored *m) return m->total_offline_time; } -gdouble +double rspamd_monitored_latency(struct rspamd_monitored *m) { g_assert(m != NULL); @@ -675,7 +675,7 @@ void rspamd_monitored_stop(struct rspamd_monitored *m) void rspamd_monitored_start(struct rspamd_monitored *m) { - gdouble jittered; + double jittered; g_assert(m != NULL); jittered = rspamd_time_jitter(m->ctx->monitoring_interval * m->monitoring_mult, @@ -695,7 +695,7 @@ void rspamd_monitored_start(struct rspamd_monitored *m) void rspamd_monitored_ctx_destroy(struct rspamd_monitored_ctx *ctx) { struct rspamd_monitored *m; - guint i; + unsigned int i; g_assert(ctx != NULL); @@ -714,10 +714,10 @@ void rspamd_monitored_ctx_destroy(struct rspamd_monitored_ctx *ctx) struct rspamd_monitored * rspamd_monitored_by_tag(struct rspamd_monitored_ctx *ctx, - guchar tag[RSPAMD_MONITORED_TAG_LEN]) + unsigned char tag[RSPAMD_MONITORED_TAG_LEN]) { struct rspamd_monitored *res; - gchar rtag[RSPAMD_MONITORED_TAG_LEN]; + char rtag[RSPAMD_MONITORED_TAG_LEN]; rspamd_strlcpy(rtag, tag, sizeof(rtag)); res = g_hash_table_lookup(ctx->helts, rtag); @@ -727,7 +727,7 @@ rspamd_monitored_by_tag(struct rspamd_monitored_ctx *ctx, void rspamd_monitored_get_tag(struct rspamd_monitored *m, - guchar tag_out[RSPAMD_MONITORED_TAG_LEN]) + unsigned char tag_out[RSPAMD_MONITORED_TAG_LEN]) { g_assert(m != NULL); diff --git a/src/libserver/monitored.h b/src/libserver/monitored.h index 01f050a76..af293f7a8 100644 --- a/src/libserver/monitored.h +++ b/src/libserver/monitored.h @@ -75,11 +75,11 @@ struct ev_loop *rspamd_monitored_ctx_get_ev_base(struct rspamd_monitored_ctx *ct */ struct rspamd_monitored *rspamd_monitored_create_( struct rspamd_monitored_ctx *ctx, - const gchar *line, + const char *line, enum rspamd_monitored_type type, enum rspamd_monitored_flags flags, const ucl_object_t *opts, - const gchar *loc); + const char *loc); #define rspamd_monitored_create(ctx, line, type, flags, opts) \ rspamd_monitored_create_(ctx, line, type, flags, opts, G_STRFUNC) @@ -91,7 +91,7 @@ struct rspamd_monitored *rspamd_monitored_create_( * @return */ struct rspamd_monitored *rspamd_monitored_by_tag(struct rspamd_monitored_ctx *ctx, - guchar tag[RSPAMD_MONITORED_TAG_LEN]); + unsigned char tag[RSPAMD_MONITORED_TAG_LEN]); /** * Sets `tag_out` to the monitored tag @@ -99,7 +99,7 @@ struct rspamd_monitored *rspamd_monitored_by_tag(struct rspamd_monitored_ctx *ct * @param tag_out */ void rspamd_monitored_get_tag(struct rspamd_monitored *m, - guchar tag_out[RSPAMD_MONITORED_TAG_LEN]); + unsigned char tag_out[RSPAMD_MONITORED_TAG_LEN]); /** * Return TRUE if monitored object is alive @@ -120,21 +120,21 @@ gboolean rspamd_monitored_set_alive(struct rspamd_monitored *m, gboolean alive); * @param m * @return */ -gdouble rspamd_monitored_offline_time(struct rspamd_monitored *m); +double rspamd_monitored_offline_time(struct rspamd_monitored *m); /** * Returns the total offline time for a monitored object * @param m * @return */ -gdouble rspamd_monitored_total_offline_time(struct rspamd_monitored *m); +double rspamd_monitored_total_offline_time(struct rspamd_monitored *m); /** * Returns the latency for monitored object (in seconds) * @param m * @return */ -gdouble rspamd_monitored_latency(struct rspamd_monitored *m); +double rspamd_monitored_latency(struct rspamd_monitored *m); /** * Explicitly disable monitored object diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 20b0a6117..8da246bdb 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -64,11 +64,11 @@ rspamd_protocol_quark(void) /* * Remove <> from the fixed string and copy it to the pool */ -static gchar * +static char * rspamd_protocol_escape_braces(struct rspamd_task *task, rspamd_ftok_t *in) { - guint nchars = 0; - const gchar *p; + unsigned int nchars = 0; + const char *p; rspamd_ftok_t tok; gboolean has_obrace = FALSE; @@ -112,7 +112,7 @@ rspamd_protocol_handle_url(struct rspamd_task *task, GHashTable *query_args; GHashTableIter it; struct http_parser_url u; - const gchar *p; + const char *p; gsize pathlen; rspamd_ftok_t *key, *value; gpointer k, v; @@ -222,7 +222,7 @@ rspamd_protocol_handle_url(struct rspamd_task *task, g_hash_table_iter_init(&it, query_args); while (g_hash_table_iter_next(&it, &k, &v)) { - gchar *key_cpy; + char *key_cpy; key = k; value = v; @@ -254,7 +254,7 @@ rspamd_protocol_process_recipients(struct rspamd_task *task, quoted_string, normal_string, } state = skip_spaces; - const gchar *p, *end, *start_addr; + const char *p, *end, *start_addr; struct rspamd_email_address *addr; p = hdr->begin; @@ -375,7 +375,7 @@ rspamd_protocol_process_recipients(struct rspamd_task *task, } while (0) static void -rspamd_protocol_handle_flag(struct rspamd_task *task, const gchar *str, +rspamd_protocol_handle_flag(struct rspamd_task *task, const char *str, gsize len) { gboolean known = FALSE; @@ -395,7 +395,7 @@ rspamd_protocol_handle_flag(struct rspamd_task *task, const gchar *str, CHECK_PROTOCOL_FLAG("groups", RSPAMD_TASK_PROTOCOL_FLAG_GROUPS); if (!known) { - msg_warn_protocol("unknown flag: %*s", (gint) len, str); + msg_warn_protocol("unknown flag: %*s", (int) len, str); } } @@ -409,7 +409,7 @@ rspamd_protocol_process_flags(struct rspamd_task *task, const rspamd_ftok_t *hdr skip_spaces, read_flag, } state = skip_spaces; - const gchar *p, *end, *start; + const char *p, *end, *start; p = hdr->begin; end = hdr->begin + hdr->len; @@ -460,7 +460,7 @@ rspamd_protocol_handle_headers(struct rspamd_task *task, rspamd_ftok_t *hn_tok, *hv_tok, srch; gboolean has_ip = FALSE, seen_settings_header = FALSE; struct rspamd_http_header *header, *h; - gchar *ntok; + char *ntok; kh_foreach_value (msg->headers, header, { DL_FOREACH (header, h) { @@ -705,7 +705,7 @@ rspamd_protocol_handle_headers(struct rspamd_task *task, } IF_HEADER(MTA_TAG_HEADER) { - gchar *mta_tag; + char *mta_tag; mta_tag = rspamd_mempool_ftokdup(task->task_pool, hv_tok); rspamd_mempool_set_variable(task->task_pool, RSPAMD_MEMPOOL_MTA_TAG, @@ -714,7 +714,7 @@ rspamd_protocol_handle_headers(struct rspamd_task *task, } IF_HEADER(MTA_NAME_HEADER) { - gchar *mta_name; + char *mta_name; mta_name = rspamd_mempool_ftokdup(task->task_pool, hv_tok); rspamd_mempool_set_variable(task->task_pool, RSPAMD_MEMPOOL_MTA_NAME, @@ -774,11 +774,11 @@ rspamd_protocol_parse_task_flags(rspamd_mempool_t *pool, GError **err) { struct rspamd_rcl_struct_parser *pd = ud; - gint *target; - const gchar *key; + int *target; + const char *key; gboolean value; - target = (gint *) (((gchar *) pd->user_struct) + pd->offset); + target = (int *) (((char *) pd->user_struct) + pd->offset); key = ucl_object_key(obj); value = ucl_object_toboolean(obj); @@ -909,7 +909,7 @@ struct tree_cb_data { static ucl_object_t * rspamd_protocol_extended_url(struct rspamd_task *task, struct rspamd_url *url, - const gchar *encoded, gsize enclen) + const char *encoded, gsize enclen) { ucl_object_t *obj, *elt; @@ -958,9 +958,9 @@ urls_protocol_cb(struct rspamd_url *url, struct tree_cb_data *cb) { ucl_object_t *obj; struct rspamd_task *task = cb->task; - const gchar *user_field = "unknown", *encoded = NULL; + const char *user_field = "unknown", *encoded = NULL; gboolean has_user = FALSE; - guint len = 0; + unsigned int len = 0; gsize enclen = 0; if (!(task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_EXT_URLS)) { @@ -1014,7 +1014,7 @@ urls_protocol_cb(struct rspamd_url *url, struct tree_cb_data *cb) has_user ? "user" : "from", len, user_field, rspamd_inet_address_to_string(task->from_addr), - (gint) enclen, encoded); + (int) enclen, encoded); } } @@ -1078,12 +1078,12 @@ rspamd_emails_tree_ucl(khash_t(rspamd_url_hash) * set, /* Write new subject */ -static const gchar * +static const char * rspamd_protocol_rewrite_subject(struct rspamd_task *task) { GString *subj_buf; - gchar *res; - const gchar *s, *c, *p; + char *res; + const char *s, *c, *p; gsize slen = 0; c = rspamd_mempool_get_variable(task->task_pool, "metric_subject"); @@ -1157,7 +1157,7 @@ static ucl_object_t * rspamd_metric_symbol_ucl(struct rspamd_task *task, struct rspamd_symbol_result *sym) { ucl_object_t *obj = NULL, *ar; - const gchar *description = NULL; + const char *description = NULL; struct rspamd_symbol_option *opt; if (sym->sym != NULL) { @@ -1200,7 +1200,7 @@ rspamd_metric_symbol_ucl(struct rspamd_task *task, struct rspamd_symbol_result * static ucl_object_t * rspamd_metric_group_ucl(struct rspamd_task *task, - struct rspamd_symbols_group *gr, gdouble score) + struct rspamd_symbols_group *gr, double score) { ucl_object_t *obj = NULL; @@ -1224,7 +1224,7 @@ rspamd_scan_result_ucl(struct rspamd_task *task, gboolean is_spam; struct rspamd_action *action; ucl_object_t *obj = NULL, *sobj; - const gchar *subject; + const char *subject; struct rspamd_passthrough_result *pr = NULL; action = rspamd_check_action_metric(task, &pr, NULL); @@ -1338,7 +1338,7 @@ rspamd_scan_result_ucl(struct rspamd_task *task, /* Handle groups if needed */ if (task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_GROUPS) { struct rspamd_symbols_group *gr; - gdouble gr_score; + double gr_score; obj = ucl_object_typed_new(UCL_OBJECT); ucl_object_reserve(obj, kh_size(mres->sym_groups)); @@ -1462,7 +1462,7 @@ rspamd_protocol_output_profiling(struct rspamd_task *task, GHashTableIter it; gpointer k, v; ucl_object_t *prof; - gdouble val; + double val; prof = ucl_object_typed_new(UCL_OBJECT); tbl = rspamd_mempool_get_variable(task->task_pool, "profile"); @@ -1471,7 +1471,7 @@ rspamd_protocol_output_profiling(struct rspamd_task *task, g_hash_table_iter_init(&it, tbl); while (g_hash_table_iter_next(&it, &k, &v)) { - val = *(gdouble *) v; + val = *(double *) v; ucl_object_insert_key(prof, ucl_object_fromdouble(val), (const char *) k, 0, false); } @@ -1643,7 +1643,7 @@ void rspamd_protocol_http_reply(struct rspamd_http_message *msg, ucl_object_t *top = NULL; rspamd_fstring_t *reply; - gint flags = RSPAMD_PROTOCOL_DEFAULT; + int flags = RSPAMD_PROTOCOL_DEFAULT; struct rspamd_action *action; /* Removed in 2.0 */ @@ -1722,7 +1722,7 @@ void rspamd_protocol_http_reply(struct rspamd_http_message *msg, /* In case of milter, we append just body, otherwise - full message */ if (task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_MILTER) { - const gchar *start; + const char *start; goffset len, hdr_off; start = task->msg.begin; @@ -1816,7 +1816,7 @@ void rspamd_protocol_http_reply(struct rspamd_http_message *msg, if (task->cfg->libs_ctx->out_dict && task->cfg->libs_ctx->out_dict->id != 0) { - gchar dict_str[32]; + char dict_str[32]; rspamd_snprintf(dict_str, sizeof(dict_str), "%ud", task->cfg->libs_ctx->out_dict->id); @@ -1889,7 +1889,7 @@ void rspamd_protocol_write_log_pipe(struct rspamd_task *task) lua_State *L = task->cfg->lua_state; struct rspamd_scan_result *mres; struct rspamd_symbol_result *sym; - gint id, i; + int id, i; uint32_t n = 0, nextra = 0; gsize sz; GArray *extra; @@ -2101,7 +2101,7 @@ void rspamd_protocol_write_log_pipe(struct rspamd_task *task) void rspamd_protocol_write_reply(struct rspamd_task *task, ev_tstamp timeout) { struct rspamd_http_message *msg; - const gchar *ctype = "application/json"; + const char *ctype = "application/json"; rspamd_fstring_t *reply; msg = rspamd_http_new_message(HTTP_RESPONSE); @@ -2150,7 +2150,7 @@ void rspamd_protocol_write_reply(struct rspamd_task *task, ev_tstamp timeout) /* We also need to validate utf8 */ if (out_type != UCL_EMIT_MSGPACK && rspamd_fast_utf8_validate(reply->str, reply->len) != 0) { gsize valid_len; - gchar *validated; + char *validated; /* We copy reply several times here, but it should be a rare case */ validated = rspamd_str_make_utf_valid(reply->str, reply->len, diff --git a/src/libserver/protocol.h b/src/libserver/protocol.h index fb4625caf..94fbcbf04 100644 --- a/src/libserver/protocol.h +++ b/src/libserver/protocol.h @@ -46,8 +46,8 @@ struct rspamd_protocol_log_message_sum { uint32_t nresults; uint32_t nextra; uint32_t settings_id; - gdouble score; - gdouble required_score; + double score; + double required_score; struct rspamd_protocol_log_symbol_result results[]; }; diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index da667fc5e..647375bcd 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -78,8 +78,8 @@ INIT_LOG_MODULE(re_cache) #ifdef WITH_HYPERSCAN #define RSPAMD_HS_MAGIC_LEN (sizeof(rspamd_hs_magic)) -static const guchar rspamd_hs_magic[] = {'r', 's', 'h', 's', 'r', 'e', '1', '1'}, - rspamd_hs_magic_vector[] = {'r', 's', 'h', 's', 'r', 'v', '1', '1'}; +static const unsigned char rspamd_hs_magic[] = {'r', 's', 'h', 's', 'r', 'e', '1', '1'}, + rspamd_hs_magic_vector[] = {'r', 's', 'h', 's', 'r', 'v', '1', '1'}; #endif @@ -92,13 +92,13 @@ struct rspamd_re_class { GHashTable *re; rspamd_cryptobox_hash_state_t *st; - gchar hash[rspamd_cryptobox_HASHBYTES + 1]; + char hash[rspamd_cryptobox_HASHBYTES + 1]; #ifdef WITH_HYPERSCAN rspamd_hyperscan_t *hs_db; hs_scratch_t *hs_scratch; - gint *hs_ids; - guint nhs; + int *hs_ids; + unsigned int nhs; #endif }; @@ -110,11 +110,11 @@ enum rspamd_re_cache_elt_match_type { struct rspamd_re_cache_elt { rspamd_regexp_t *re; - gint lua_cbref; + int lua_cbref; enum rspamd_re_cache_elt_match_type match_type; }; -KHASH_INIT(lua_selectors_hash, gchar *, int, 1, kh_str_hash_func, kh_str_hash_equal); +KHASH_INIT(lua_selectors_hash, char *, int, 1, kh_str_hash_func, kh_str_hash_equal); struct rspamd_re_cache { GHashTable *re_classes; @@ -122,9 +122,9 @@ struct rspamd_re_cache { GPtrArray *re; khash_t(lua_selectors_hash) * selectors; ref_entry_t ref; - guint nre; - guint max_re_data; - gchar hash[rspamd_cryptobox_HASHBYTES + 1]; + unsigned int nre; + unsigned int max_re_data; + char hash[rspamd_cryptobox_HASHBYTES + 1]; lua_State *L; #ifdef WITH_HYPERSCAN enum rspamd_hyperscan_status hyperscan_loaded; @@ -134,17 +134,17 @@ struct rspamd_re_cache { }; struct rspamd_re_selector_result { - guchar **scvec; - guint *lenvec; - guint cnt; + unsigned char **scvec; + unsigned int *lenvec; + unsigned int cnt; }; KHASH_INIT(selectors_results_hash, int, struct rspamd_re_selector_result, 1, kh_int_hash_func, kh_int_hash_equal); struct rspamd_re_runtime { - guchar *checked; - guchar *results; + unsigned char *checked; + unsigned char *results; khash_t(selectors_results_hash) * sel_cache; struct rspamd_re_cache *cache; struct rspamd_re_cache_stat stat; @@ -180,8 +180,8 @@ rspamd_re_cache_destroy(struct rspamd_re_cache *cache) GHashTableIter it; gpointer k, v; struct rspamd_re_class *re_class; - gchar *skey; - gint sref; + char *skey; + int sref; g_assert(cache != NULL); g_hash_table_iter_init(&it, cache->re_classes); @@ -216,7 +216,7 @@ rspamd_re_cache_destroy(struct rspamd_re_cache *cache) }); struct rspamd_re_cache_elt *elt; - guint i; + unsigned int i; PTR_ARRAY_FOREACH(cache->re, i, elt) { @@ -277,7 +277,7 @@ rspamd_re_cache_add(struct rspamd_re_cache *cache, rspamd_regexp_t *re, enum rspamd_re_type type, gconstpointer type_data, gsize datalen, - gint lua_cbref) + int lua_cbref) { uint64_t class_id; struct rspamd_re_class *re_class; @@ -371,7 +371,7 @@ void rspamd_re_cache_replace(struct rspamd_re_cache *cache, } } -static gint +static int rspamd_re_cache_sort_func(gconstpointer a, gconstpointer b) { struct rspamd_re_cache_elt *const *re1 = a, *const *re2 = b; @@ -382,14 +382,14 @@ rspamd_re_cache_sort_func(gconstpointer a, gconstpointer b) void rspamd_re_cache_init(struct rspamd_re_cache *cache, struct rspamd_config *cfg) { - guint i, fl; + unsigned int i, fl; GHashTableIter it; gpointer k, v; struct rspamd_re_class *re_class; rspamd_cryptobox_hash_state_t st_global; rspamd_regexp_t *re; struct rspamd_re_cache_elt *elt; - guchar hash_out[rspamd_cryptobox_HASHBYTES]; + unsigned char hash_out[rspamd_cryptobox_HASHBYTES]; g_assert(cache != NULL); @@ -424,32 +424,32 @@ void rspamd_re_cache_init(struct rspamd_re_cache *cache, struct rspamd_config *c rspamd_cryptobox_HASHBYTES); /* PCRE flags */ fl = rspamd_regexp_get_pcre_flags(re); - rspamd_cryptobox_hash_update(re_class->st, (const guchar *) &fl, + rspamd_cryptobox_hash_update(re_class->st, (const unsigned char *) &fl, sizeof(fl)); - rspamd_cryptobox_hash_update(&st_global, (const guchar *) &fl, + rspamd_cryptobox_hash_update(&st_global, (const unsigned char *) &fl, sizeof(fl)); /* Rspamd flags */ fl = rspamd_regexp_get_flags(re); - rspamd_cryptobox_hash_update(re_class->st, (const guchar *) &fl, + rspamd_cryptobox_hash_update(re_class->st, (const unsigned char *) &fl, sizeof(fl)); - rspamd_cryptobox_hash_update(&st_global, (const guchar *) &fl, + rspamd_cryptobox_hash_update(&st_global, (const unsigned char *) &fl, sizeof(fl)); /* Limit of hits */ fl = rspamd_regexp_get_maxhits(re); - rspamd_cryptobox_hash_update(re_class->st, (const guchar *) &fl, + rspamd_cryptobox_hash_update(re_class->st, (const unsigned char *) &fl, sizeof(fl)); - rspamd_cryptobox_hash_update(&st_global, (const guchar *) &fl, + rspamd_cryptobox_hash_update(&st_global, (const unsigned char *) &fl, sizeof(fl)); /* Numeric order */ - rspamd_cryptobox_hash_update(re_class->st, (const guchar *) &i, + rspamd_cryptobox_hash_update(re_class->st, (const unsigned char *) &i, sizeof(i)); - rspamd_cryptobox_hash_update(&st_global, (const guchar *) &i, + rspamd_cryptobox_hash_update(&st_global, (const unsigned char *) &i, sizeof(i)); } rspamd_cryptobox_hash_final(&st_global, hash_out); rspamd_snprintf(cache->hash, sizeof(cache->hash), "%*xs", - (gint) rspamd_cryptobox_HASHBYTES, hash_out); + (int) rspamd_cryptobox_HASHBYTES, hash_out); /* Now finalize all classes */ g_hash_table_iter_init(&it, cache->re_classes); @@ -468,7 +468,7 @@ void rspamd_re_cache_init(struct rspamd_re_cache *cache, struct rspamd_config *c sizeof(cache->re->len)); rspamd_cryptobox_hash_final(re_class->st, hash_out); rspamd_snprintf(re_class->hash, sizeof(re_class->hash), "%*xs", - (gint) rspamd_cryptobox_HASHBYTES, hash_out); + (int) rspamd_cryptobox_HASHBYTES, hash_out); free(re_class->st); /* Due to posix_memalign */ re_class->st = NULL; } @@ -477,7 +477,7 @@ void rspamd_re_cache_init(struct rspamd_re_cache *cache, struct rspamd_config *c cache->L = cfg->lua_state; #ifdef WITH_HYPERSCAN - const gchar *platform = "generic"; + const char *platform = "generic"; rspamd_fstring_t *features = rspamd_fstring_new(); cache->disable_hyperscan = cfg->disable_hyperscan; @@ -524,7 +524,7 @@ rspamd_re_cache_runtime_new(struct rspamd_re_cache *cache) rt = g_malloc0(sizeof(*rt) + NBYTES(cache->nre) + cache->nre); rt->cache = cache; REF_RETAIN(cache); - rt->checked = ((guchar *) rt) + sizeof(*rt); + rt->checked = ((unsigned char *) rt) + sizeof(*rt); rt->results = rt->checked + NBYTES(cache->nre); rt->stat.regexp_total = cache->nre; #ifdef WITH_HYPERSCAN @@ -545,14 +545,14 @@ rspamd_re_cache_get_stat(struct rspamd_re_runtime *rt) static gboolean rspamd_re_cache_check_lua_condition(struct rspamd_task *task, rspamd_regexp_t *re, - const guchar *in, gsize len, + const unsigned char *in, gsize len, goffset start, goffset end, - gint lua_cbref) + int lua_cbref) { lua_State *L = (lua_State *) task->cfg->lua_state; GError *err = NULL; struct rspamd_lua_text __attribute__((unused)) * t; - gint text_pos; + int text_pos; if (G_LIKELY(lua_cbref == -1)) { return TRUE; @@ -580,19 +580,19 @@ rspamd_re_cache_check_lua_condition(struct rspamd_task *task, return res; } -static guint +static unsigned int rspamd_re_cache_process_pcre(struct rspamd_re_runtime *rt, rspamd_regexp_t *re, struct rspamd_task *task, - const guchar *in, gsize len, + const unsigned char *in, gsize len, gboolean is_raw, - gint lua_cbref) + int lua_cbref) { - guint r = 0; - const gchar *start = NULL, *end = NULL; - guint max_hits = rspamd_regexp_get_maxhits(re); + unsigned int r = 0; + const char *start = NULL, *end = NULL; + unsigned int max_hits = rspamd_regexp_get_maxhits(re); uint64_t id = rspamd_regexp_get_cache_id(re); - gdouble t1 = NAN, t2, pr; - const gdouble slow_time = 1e8; + double t1 = NAN, t2, pr; + const double slow_time = 1e8; if (in == NULL) { return rt->results[id]; @@ -623,7 +623,7 @@ rspamd_re_cache_process_pcre(struct rspamd_re_runtime *rt, is_raw, NULL)) { if (rspamd_re_cache_check_lua_condition(task, re, in, len, - start - (const gchar *) in, end - (const gchar *) in, lua_cbref)) { + start - (const char *) in, end - (const char *) in, lua_cbref)) { r++; msg_debug_re_task("found regexp /%s/, total hits: %d", rspamd_regexp_get_pattern(re), r); @@ -660,14 +660,14 @@ rspamd_re_cache_process_pcre(struct rspamd_re_runtime *rt, #ifdef WITH_HYPERSCAN struct rspamd_re_hyperscan_cbdata { struct rspamd_re_runtime *rt; - const guchar **ins; - const guint *lens; - guint count; + const unsigned char **ins; + const unsigned int *lens; + unsigned int count; rspamd_regexp_t *re; struct rspamd_task *task; }; -static gint +static int rspamd_re_cache_hyperscan_cb(unsigned int id, unsigned long long from, unsigned long long to, @@ -677,7 +677,7 @@ rspamd_re_cache_hyperscan_cb(unsigned int id, struct rspamd_re_hyperscan_cbdata *cbdata = ud; struct rspamd_re_runtime *rt; struct rspamd_re_cache_elt *cache_elt; - guint ret, maxhits, i, processed; + unsigned int ret, maxhits, i, processed; struct rspamd_task *task; rt = cbdata->rt; @@ -727,18 +727,18 @@ rspamd_re_cache_hyperscan_cb(unsigned int id, } #endif -static guint +static unsigned int rspamd_re_cache_process_regexp_data(struct rspamd_re_runtime *rt, rspamd_regexp_t *re, struct rspamd_task *task, - const guchar **in, guint *lens, - guint count, + const unsigned char **in, unsigned int *lens, + unsigned int count, gboolean is_raw, gboolean *processed_hyperscan) { uint64_t re_id; - guint ret = 0; - guint i; + unsigned int ret = 0; + unsigned int i; struct rspamd_re_cache_elt *cache_elt; re_id = rspamd_regexp_get_cache_id(re); @@ -830,12 +830,12 @@ static void rspamd_re_cache_finish_class(struct rspamd_task *task, struct rspamd_re_runtime *rt, struct rspamd_re_class *re_class, - const gchar *class_name) + const char *class_name) { #ifdef WITH_HYPERSCAN - guint i; + unsigned int i; uint64_t re_id; - guint found = 0; + unsigned int found = 0; /* Set all bits that are not checked and included in hyperscan to 1 */ for (i = 0; i < re_class->nhs; i++) { @@ -853,29 +853,29 @@ rspamd_re_cache_finish_class(struct rspamd_task *task, msg_debug_re_task("finished hyperscan for class %s; %d " "matches found; %d hyperscan supported regexps; %d total regexps", - class_name, found, re_class->nhs, (gint) g_hash_table_size(re_class->re)); + class_name, found, re_class->nhs, (int) g_hash_table_size(re_class->re)); #endif } static gboolean rspamd_re_cache_process_selector(struct rspamd_task *task, struct rspamd_re_runtime *rt, - const gchar *name, - guchar ***svec, - guint **lenvec, - guint *n) + const char *name, + unsigned char ***svec, + unsigned int **lenvec, + unsigned int *n) { - gint ref; + int ref; khiter_t k; lua_State *L; - gint err_idx, ret; + int err_idx, ret; struct rspamd_task **ptask; gboolean result = FALSE; struct rspamd_re_cache *cache = rt->cache; struct rspamd_re_selector_result *sr; L = cache->L; - k = kh_get(lua_selectors_hash, cache->selectors, (gchar *) name); + k = kh_get(lua_selectors_hash, cache->selectors, (char *) name); if (k == kh_end(cache->selectors)) { msg_err_task("cannot find selector %s, not registered", name); @@ -920,7 +920,7 @@ rspamd_re_cache_process_selector(struct rspamd_task *task, else { struct rspamd_lua_text *txt; gsize slen; - const gchar *sel_data; + const char *sel_data; if (lua_type(L, -1) != LUA_TTABLE) { txt = lua_check_text_or_string(L, -1); @@ -931,8 +931,8 @@ rspamd_re_cache_process_selector(struct rspamd_task *task, sel_data = txt->start; slen = txt->len; *n = 1; - *svec = g_malloc(sizeof(guchar *)); - *lenvec = g_malloc(sizeof(guint)); + *svec = g_malloc(sizeof(unsigned char *)); + *lenvec = g_malloc(sizeof(unsigned int)); (*svec)[0] = g_malloc(slen); memcpy((*svec)[0], sel_data, slen); (*lenvec)[0] = slen; @@ -948,8 +948,8 @@ rspamd_re_cache_process_selector(struct rspamd_task *task, msg_debug_re_cache("re selector %s returned %d elements", name, *n); if (*n > 0) { - *svec = g_malloc(sizeof(guchar *) * (*n)); - *lenvec = g_malloc(sizeof(guint) * (*n)); + *svec = g_malloc(sizeof(unsigned char *) * (*n)); + *lenvec = g_malloc(sizeof(unsigned int) * (*n)); for (int i = 0; i < *n; i++) { lua_rawgeti(L, -1, i + 1); @@ -993,15 +993,15 @@ rspamd_re_cache_process_selector(struct rspamd_task *task, return result; } -static inline guint +static inline unsigned int rspamd_process_words_vector(GArray *words, - const guchar **scvec, - guint *lenvec, + const unsigned char **scvec, + unsigned int *lenvec, struct rspamd_re_class *re_class, - guint cnt, + unsigned int cnt, gboolean *raw) { - guint j; + unsigned int j; rspamd_stat_token_t *tok; if (words) { @@ -1047,7 +1047,7 @@ rspamd_process_words_vector(GArray *words, return cnt; } -static guint +static unsigned int rspamd_re_cache_process_headers_list(struct rspamd_task *task, struct rspamd_re_runtime *rt, rspamd_regexp_t *re, @@ -1056,11 +1056,11 @@ rspamd_re_cache_process_headers_list(struct rspamd_task *task, gboolean is_strong, gboolean *processed_hyperscan) { - const guchar **scvec, *in; + const unsigned char **scvec, *in; gboolean raw = FALSE; - guint *lenvec; + unsigned int *lenvec; struct rspamd_mime_header *cur; - guint cnt = 0, i = 0, ret = 0; + unsigned int cnt = 0, i = 0, ret = 0; DL_COUNT(rh, cur, cnt); @@ -1076,7 +1076,7 @@ rspamd_re_cache_process_headers_list(struct rspamd_task *task, } if (re_class->type == RSPAMD_RE_RAWHEADER) { - in = (const guchar *) cur->value; + in = (const unsigned char *) cur->value; lenvec[i] = strlen(cur->value); if (rspamd_fast_utf8_validate(in, lenvec[i]) != 0) { @@ -1084,11 +1084,11 @@ rspamd_re_cache_process_headers_list(struct rspamd_task *task, } } else { - in = (const guchar *) cur->decoded; + in = (const unsigned char *) cur->decoded; /* Validate input^W^WNo need to validate as it is already valid */ if (!in) { lenvec[i] = 0; - scvec[i] = (guchar *) ""; + scvec[i] = (unsigned char *) ""; continue; } @@ -1118,24 +1118,24 @@ rspamd_re_cache_process_headers_list(struct rspamd_task *task, /* * Calculates the specified regexp for the specified class if it's not calculated */ -static guint +static unsigned int rspamd_re_cache_exec_re(struct rspamd_task *task, struct rspamd_re_runtime *rt, rspamd_regexp_t *re, struct rspamd_re_class *re_class, gboolean is_strong) { - guint ret = 0, i, re_id; + unsigned int ret = 0, i, re_id; struct rspamd_mime_header *rh; - const gchar *in; - const guchar **scvec = NULL; - guint *lenvec = NULL; + const char *in; + const unsigned char **scvec = NULL; + unsigned int *lenvec = NULL; gboolean raw = FALSE, processed_hyperscan = FALSE; struct rspamd_mime_text_part *text_part; struct rspamd_mime_part *mime_part; struct rspamd_url *url; - guint len = 0, cnt = 0; - const gchar *class_name; + unsigned int len = 0, cnt = 0; + const char *class_name; class_name = rspamd_re_cache_type_to_string(re_class->type); msg_debug_re_task("start check re type: %s: /%s/", @@ -1164,7 +1164,7 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, in = MESSAGE_FIELD(task, raw_headers_content).begin; len = MESSAGE_FIELD(task, raw_headers_content).len; ret = rspamd_re_cache_process_regexp_data(rt, re, - task, (const guchar **) &in, &len, 1, raw, &processed_hyperscan); + task, (const unsigned char **) &in, &len, 1, raw, &processed_hyperscan); msg_debug_re_task("checked allheader regexp: %s -> %d", rspamd_regexp_get_pattern(re), ret); break; @@ -1230,7 +1230,7 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, } } - scvec[i] = (guchar *) in; + scvec[i] = (unsigned char *) in; lenvec[i] = len; } @@ -1259,7 +1259,7 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, len = url->urllen; if (len > 0 && !(url->flags & RSPAMD_URL_FLAG_IMAGE)) { - scvec[i] = (guchar *) in; + scvec[i] = (unsigned char *) in; lenvec[i++] = len; } }); @@ -1274,7 +1274,7 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, len = url->urllen; if (len > 0 && !(url->flags & RSPAMD_URL_FLAG_IMAGE)) { - scvec[i] = (guchar *) in; + scvec[i] = (unsigned char *) in; lenvec[i++] = len; } } @@ -1306,7 +1306,7 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, in = rspamd_url_user_unsafe(url); len = url->userlen + 1 + url->hostlen; - scvec[i] = (guchar *) in; + scvec[i] = (unsigned char *) in; lenvec[i++] = len; }); @@ -1324,7 +1324,7 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, len = task->msg.len; ret = rspamd_re_cache_process_regexp_data(rt, re, task, - (const guchar **) &in, &len, 1, raw, &processed_hyperscan); + (const unsigned char **) &in, &len, 1, raw, &processed_hyperscan); msg_debug_re_task("checked rawbody regexp: %s -> %d", rspamd_regexp_get_pattern(re), ret); break; @@ -1349,18 +1349,18 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, rh = rspamd_message_get_header_array(task, "Subject", FALSE); if (rh) { - scvec[0] = (guchar *) rh->decoded; + scvec[0] = (unsigned char *) rh->decoded; lenvec[0] = strlen(rh->decoded); } else { - scvec[0] = (guchar *) ""; + scvec[0] = (unsigned char *) ""; lenvec[0] = 0; } PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, text_part) { if (text_part->utf_stripped_content) { - scvec[i + 1] = (guchar *) text_part->utf_stripped_content->data; + scvec[i + 1] = (unsigned char *) text_part->utf_stripped_content->data; lenvec[i + 1] = text_part->utf_stripped_content->len; if (!IS_TEXT_PART_UTF(text_part)) { @@ -1368,7 +1368,7 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, } } else { - scvec[i + 1] = (guchar *) ""; + scvec[i + 1] = (unsigned char *) ""; lenvec[i + 1] = 0; } } @@ -1397,7 +1397,7 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, text_part = g_ptr_array_index(MESSAGE_FIELD(task, text_parts), i); if (text_part->parsed.len > 0) { - scvec[i] = (guchar *) text_part->parsed.begin; + scvec[i] = (unsigned char *) text_part->parsed.begin; lenvec[i] = text_part->parsed.len; if (!IS_TEXT_PART_UTF(text_part)) { @@ -1405,7 +1405,7 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, } } else { - scvec[i] = (guchar *) ""; + scvec[i] = (unsigned char *) ""; lenvec[i] = 0; } } @@ -1468,7 +1468,7 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, case RSPAMD_RE_SELECTOR: if (rspamd_re_cache_process_selector(task, rt, re_class->type_data, - (guchar ***) &scvec, + (unsigned char ***) &scvec, &lenvec, &cnt)) { ret = rspamd_re_cache_process_regexp_data(rt, re, @@ -1497,12 +1497,12 @@ rspamd_re_cache_exec_re(struct rspamd_task *task, return rt->results[re_id]; } -gint rspamd_re_cache_process(struct rspamd_task *task, - rspamd_regexp_t *re, - enum rspamd_re_type type, - gconstpointer type_data, - gsize datalen, - gboolean is_strong) +int rspamd_re_cache_process(struct rspamd_task *task, + rspamd_regexp_t *re, + enum rspamd_re_type type, + gconstpointer type_data, + gsize datalen, + gboolean is_strong) { uint64_t re_id; struct rspamd_re_class *re_class; @@ -1571,7 +1571,7 @@ void rspamd_re_cache_runtime_destroy(struct rspamd_re_runtime *rt) struct rspamd_re_selector_result sr; kh_foreach_value(rt->sel_cache, sr, { - for (guint i = 0; i < sr.cnt; i++) { + for (unsigned int i = 0; i < sr.cnt; i++) { g_free((gpointer) sr.scvec[i]); } @@ -1602,9 +1602,9 @@ rspamd_re_cache_ref(struct rspamd_re_cache *cache) return cache; } -guint rspamd_re_cache_set_limit(struct rspamd_re_cache *cache, guint limit) +unsigned int rspamd_re_cache_set_limit(struct rspamd_re_cache *cache, unsigned int limit) { - guint old; + unsigned int old; g_assert(cache != NULL); @@ -1614,10 +1614,10 @@ guint rspamd_re_cache_set_limit(struct rspamd_re_cache *cache, guint limit) return old; } -const gchar * +const char * rspamd_re_cache_type_to_string(enum rspamd_re_type type) { - const gchar *ret = "unknown"; + const char *ret = "unknown"; switch (type) { case RSPAMD_RE_HEADER: @@ -1738,16 +1738,16 @@ rspamd_re_cache_type_from_string(const char *str) } #ifdef WITH_HYPERSCAN -static gchar * +static char * rspamd_re_cache_hs_pattern_from_pcre(rspamd_regexp_t *re) { /* * Workaround for bug in ragel 7.0.0.11 * https://github.com/intel/hyperscan/issues/133 */ - const gchar *pat = rspamd_regexp_get_pattern(re); - guint flags = rspamd_regexp_get_flags(re), esc_flags = RSPAMD_REGEXP_ESCAPE_RE; - gchar *escaped; + const char *pat = rspamd_regexp_get_pattern(re); + unsigned int flags = rspamd_regexp_get_flags(re), esc_flags = RSPAMD_REGEXP_ESCAPE_RE; + char *escaped; gsize esc_len; if (flags & RSPAMD_REGEXP_FLAG_UTF) { @@ -1761,16 +1761,16 @@ rspamd_re_cache_hs_pattern_from_pcre(rspamd_regexp_t *re) static gboolean rspamd_re_cache_is_finite(struct rspamd_re_cache *cache, - rspamd_regexp_t *re, gint flags, gdouble max_time) + rspamd_regexp_t *re, int flags, double max_time) { pid_t cld; - gint status; + int status; struct timespec ts; hs_compile_error_t *hs_errors; hs_database_t *test_db; - gdouble wait_time; - const gint max_tries = 10; - gint tries = 0, rc; + double wait_time; + const int max_tries = 10; + int tries = 0, rc; void (*old_hdl)(int); wait_time = max_time / max_tries; @@ -1781,7 +1781,7 @@ rspamd_re_cache_is_finite(struct rspamd_re_cache *cache, if (cld == 0) { /* Try to compile pattern */ - gchar *pat = rspamd_re_cache_hs_pattern_from_pcre(re); + char *pat = rspamd_re_cache_hs_pattern_from_pcre(re); if (hs_compile(pat, flags | HS_FLAG_PREFILTER, @@ -1852,10 +1852,10 @@ struct rspamd_re_cache_hs_compile_cbdata { GHashTableIter it; struct rspamd_re_cache *cache; const char *cache_dir; - gdouble max_time; + double max_time; gboolean silent; - guint total; - void (*cb)(guint ncompiled, GError *err, void *cbd); + unsigned int total; + void (*cb)(unsigned int ncompiled, GError *err, void *cbd); void *cbd; }; @@ -1885,17 +1885,17 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents) GHashTableIter cit; gpointer k, v; struct rspamd_re_class *re_class; - gchar path[PATH_MAX], npath[PATH_MAX]; + char path[PATH_MAX], npath[PATH_MAX]; hs_database_t *test_db; - gint fd, i, n, *hs_ids = NULL, pcre_flags, re_flags; + int fd, i, n, *hs_ids = NULL, pcre_flags, re_flags; rspamd_cryptobox_fast_hash_state_t crc_st; uint64_t crc; rspamd_regexp_t *re; hs_compile_error_t *hs_errors = NULL; - guint *hs_flags = NULL; + unsigned int *hs_flags = NULL; const hs_expr_ext_t **hs_exts = NULL; - gchar **hs_pats = NULL; - gchar *hs_serialized = NULL; + char **hs_pats = NULL; + char *hs_serialized = NULL; gsize serialized_len; struct iovec iov[7]; struct rspamd_re_cache *cache; @@ -1933,7 +1933,7 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents) msg_info_re_cache( "skip already valid class %s(%*s) to cache %6s, %d regexps", rspamd_re_cache_type_to_string(re_class->type), - (gint) re_class->type_len - 1, + (int) re_class->type_len - 1, re_class->type_data, re_class->hash, n); @@ -1966,8 +1966,8 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents) g_hash_table_iter_init(&cit, re_class->re); n = g_hash_table_size(re_class->re); - hs_flags = g_new0(guint, n); - hs_ids = g_new0(guint, n); + hs_flags = g_new0(unsigned int, n); + hs_ids = g_new0(unsigned int, n); hs_pats = g_new0(char *, n); hs_exts = g_new0(const hs_expr_ext_t *, n); i = 0; @@ -2015,7 +2015,7 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents) hs_flags[i] |= HS_FLAG_SINGLEMATCH; } - gchar *pat = rspamd_re_cache_hs_pattern_from_pcre(re); + char *pat = rspamd_re_cache_hs_pattern_from_pcre(re); if (hs_compile(pat, hs_flags[i], @@ -2055,7 +2055,7 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents) do { \ g_free(hs_flags); \ g_free(hs_ids); \ - for (guint j = 0; j < i; j++) { \ + for (unsigned int j = 0; j < i; j++) { \ g_free(hs_pats[j]); \ } \ g_free(hs_pats); \ @@ -2156,11 +2156,11 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents) msg_info_re_cache( "compiled class %s(%*s) to cache %6s, %d/%d regexps", rspamd_re_cache_type_to_string(re_class->type), - (gint) re_class->type_len - 1, + (int) re_class->type_len - 1, re_class->type_data, re_class->hash, n, - (gint) g_hash_table_size(re_class->re)); + (int) g_hash_table_size(re_class->re)); } else { msg_info_re_cache( @@ -2168,7 +2168,7 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents) rspamd_re_cache_type_to_string(re_class->type), re_class->hash, n, - (gint) g_hash_table_size(re_class->re)); + (int) g_hash_table_size(re_class->re)); } cbdata->total += n; @@ -2198,7 +2198,7 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents) "no suitable regular expressions %s (%d original): " "remove temporary file %s", rspamd_re_cache_type_to_string(re_class->type), - (gint) g_hash_table_size(re_class->re), + (int) g_hash_table_size(re_class->re), path); CLEANUP_ALLOCATED(true); @@ -2213,13 +2213,13 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents) #endif -gint rspamd_re_cache_compile_hyperscan(struct rspamd_re_cache *cache, - const char *cache_dir, - gdouble max_time, - gboolean silent, - struct ev_loop *event_loop, - void (*cb)(guint ncompiled, GError *err, void *cbd), - void *cbd) +int rspamd_re_cache_compile_hyperscan(struct rspamd_re_cache *cache, + const char *cache_dir, + double max_time, + gboolean silent, + struct ev_loop *event_loop, + void (*cb)(unsigned int ncompiled, GError *err, void *cbd), + void *cbd) { g_assert(cache != NULL); g_assert(cache_dir != NULL); @@ -2261,17 +2261,17 @@ rspamd_re_cache_is_valid_hyperscan_file(struct rspamd_re_cache *cache, #ifndef WITH_HYPERSCAN return FALSE; #else - gint fd, n, ret; - guchar magicbuf[RSPAMD_HS_MAGIC_LEN]; - const guchar *mb; + int fd, n, ret; + unsigned char magicbuf[RSPAMD_HS_MAGIC_LEN]; + const unsigned char *mb; GHashTableIter it; gpointer k, v; struct rspamd_re_class *re_class; gsize len; - const gchar *hash_pos; + const char *hash_pos; hs_platform_info_t test_plt; hs_database_t *test_db = NULL; - guchar *map, *p, *end; + unsigned char *map, *p, *end; rspamd_cryptobox_fast_hash_state_t crc_st; uint64_t crc, valid_crc; @@ -2403,9 +2403,9 @@ rspamd_re_cache_is_valid_hyperscan_file(struct rspamd_re_cache *cache, p = map + RSPAMD_HS_MAGIC_LEN + sizeof(test_plt); end = map + len; memcpy(&n, p, sizeof(n)); - p += sizeof(gint); + p += sizeof(int); - if (n <= 0 || 2 * n * sizeof(gint) + /* IDs + flags */ + if (n <= 0 || 2 * n * sizeof(int) + /* IDs + flags */ sizeof(uint64_t) + /* crc */ RSPAMD_HS_MAGIC_LEN + /* header */ sizeof(cache->plt) > @@ -2429,15 +2429,15 @@ rspamd_re_cache_is_valid_hyperscan_file(struct rspamd_re_cache *cache, * */ - memcpy(&crc, p + n * 2 * sizeof(gint), sizeof(crc)); + memcpy(&crc, p + n * 2 * sizeof(int), sizeof(crc)); rspamd_cryptobox_fast_hash_init(&crc_st, 0xdeadbabe); /* IDs */ - rspamd_cryptobox_fast_hash_update(&crc_st, p, n * sizeof(gint)); + rspamd_cryptobox_fast_hash_update(&crc_st, p, n * sizeof(int)); /* Flags */ - rspamd_cryptobox_fast_hash_update(&crc_st, p + n * sizeof(gint), - n * sizeof(gint)); + rspamd_cryptobox_fast_hash_update(&crc_st, p + n * sizeof(int), + n * sizeof(int)); /* HS database */ - p += n * sizeof(gint) * 2 + sizeof(uint64_t); + p += n * sizeof(int) * 2 + sizeof(uint64_t); rspamd_cryptobox_fast_hash_update(&crc_st, p, end - p); valid_crc = rspamd_cryptobox_fast_hash_final(&crc_st); @@ -2492,11 +2492,11 @@ rspamd_re_cache_load_hyperscan(struct rspamd_re_cache *cache, #ifndef WITH_HYPERSCAN return RSPAMD_HYPERSCAN_UNSUPPORTED; #else - gchar path[PATH_MAX]; - gint fd, i, n, *hs_ids = NULL, *hs_flags = NULL, total = 0, ret; + char path[PATH_MAX]; + int fd, i, n, *hs_ids = NULL, *hs_flags = NULL, total = 0, ret; GHashTableIter it; gpointer k, v; - guint8 *map, *p; + uint8_t *map, *p; struct rspamd_re_class *re_class; struct rspamd_re_cache_elt *elt; struct stat st; @@ -2536,9 +2536,9 @@ rspamd_re_cache_load_hyperscan(struct rspamd_re_cache *cache, close(fd); p = map + RSPAMD_HS_MAGIC_LEN + sizeof(cache->plt); - n = *(gint *) p; + n = *(int *) p; - if (n <= 0 || 2 * n * sizeof(gint) + /* IDs + flags */ + if (n <= 0 || 2 * n * sizeof(int) + /* IDs + flags */ sizeof(uint64_t) + /* crc */ RSPAMD_HS_MAGIC_LEN + /* header */ sizeof(cache->plt) > @@ -2631,7 +2631,7 @@ rspamd_re_cache_load_hyperscan(struct rspamd_re_cache *cache, * specify that they should be matched using hyperscan */ for (i = 0; i < n; i++) { - g_assert((gint) cache->re->len > hs_ids[i] && hs_ids[i] >= 0); + g_assert((int) cache->re->len > hs_ids[i] && hs_ids[i] >= 0); elt = g_ptr_array_index(cache->re, hs_ids[i]); if (hs_flags[i] & HS_FLAG_PREFILTER) { @@ -2686,16 +2686,16 @@ rspamd_re_cache_load_hyperscan(struct rspamd_re_cache *cache, } void rspamd_re_cache_add_selector(struct rspamd_re_cache *cache, - const gchar *sname, - gint ref) + const char *sname, + int ref) { khiter_t k; - k = kh_get(lua_selectors_hash, cache->selectors, (gchar *) sname); + k = kh_get(lua_selectors_hash, cache->selectors, (char *) sname); if (k == kh_end(cache->selectors)) { - gchar *cpy = g_strdup(sname); - gint res; + char *cpy = g_strdup(sname); + int res; k = kh_put(lua_selectors_hash, cache->selectors, cpy, &res); diff --git a/src/libserver/re_cache.h b/src/libserver/re_cache.h index b55942866..20b1108e0 100644 --- a/src/libserver/re_cache.h +++ b/src/libserver/re_cache.h @@ -50,10 +50,10 @@ enum rspamd_re_type { struct rspamd_re_cache_stat { uint64_t bytes_scanned; uint64_t bytes_scanned_pcre; - guint regexp_checked; - guint regexp_matched; - guint regexp_total; - guint regexp_fast_cached; + unsigned int regexp_checked; + unsigned int regexp_matched; + unsigned int regexp_total; + unsigned int regexp_fast_cached; }; /** @@ -74,7 +74,7 @@ rspamd_regexp_t * rspamd_re_cache_add(struct rspamd_re_cache *cache, rspamd_regexp_t *re, enum rspamd_re_type type, gconstpointer type_data, gsize datalen, - gint lua_cbref); + int lua_cbref); /** * Replace regexp in the cache with another regexp @@ -128,12 +128,12 @@ rspamd_re_cache_get_stat(struct rspamd_re_runtime *rt); * @param datalen associated data length * @param is_strong use case sensitive match when looking for headers */ -gint rspamd_re_cache_process(struct rspamd_task *task, - rspamd_regexp_t *re, - enum rspamd_re_type type, - gconstpointer type_data, - gsize datalen, - gboolean is_strong); +int rspamd_re_cache_process(struct rspamd_task *task, + rspamd_regexp_t *re, + enum rspamd_re_type type, + gconstpointer type_data, + gsize datalen, + gboolean is_strong); int rspamd_re_cache_process_ffi(void *ptask, void *pre, @@ -159,12 +159,12 @@ struct rspamd_re_cache *rspamd_re_cache_ref(struct rspamd_re_cache *cache); /** * Set limit for all regular expressions in the cache, returns previous limit */ -guint rspamd_re_cache_set_limit(struct rspamd_re_cache *cache, guint limit); +unsigned int rspamd_re_cache_set_limit(struct rspamd_re_cache *cache, unsigned int limit); /** * Convert re type to a human readable string (constant one) */ -const gchar *rspamd_re_cache_type_to_string(enum rspamd_re_type type); +const char *rspamd_re_cache_type_to_string(enum rspamd_re_type type); /** * Convert re type string to the type enum @@ -175,13 +175,13 @@ struct ev_loop; /** * Compile expressions to the hyperscan tree and store in the `cache_dir` */ -gint rspamd_re_cache_compile_hyperscan(struct rspamd_re_cache *cache, - const char *cache_dir, - gdouble max_time, - gboolean silent, - struct ev_loop *event_loop, - void (*cb)(guint ncompiled, GError *err, void *cbd), - void *cbd); +int rspamd_re_cache_compile_hyperscan(struct rspamd_re_cache *cache, + const char *cache_dir, + double max_time, + gboolean silent, + struct ev_loop *event_loop, + void (*cb)(unsigned int ncompiled, GError *err, void *cbd), + void *cbd); /** * Returns TRUE if the specified file is valid hyperscan cache @@ -203,7 +203,7 @@ enum rspamd_hyperscan_status rspamd_re_cache_load_hyperscan( * Registers lua selector in the cache */ void rspamd_re_cache_add_selector(struct rspamd_re_cache *cache, - const gchar *sname, gint ref); + const char *sname, int ref); #ifdef __cplusplus } diff --git a/src/libserver/redis_pool.cxx b/src/libserver/redis_pool.cxx index 9c2d6cf6d..cea8d0c86 100644 --- a/src/libserver/redis_pool.cxx +++ b/src/libserver/redis_pool.cxx @@ -53,7 +53,7 @@ struct redis_pool_connection { redis_pool *pool; conn_iter_t elt_pos; ev_timer timeout; - gchar tag[MEMPOOL_UID_LEN]; + char tag[MEMPOOL_UID_LEN]; rspamd_redis_pool_connection_state state; auto schedule_timeout() -> void; @@ -102,8 +102,8 @@ public: redis_pool_elt(redis_pool_elt &&other) = default; explicit redis_pool_elt(redis_pool *_pool, - const gchar *_db, const gchar *_username, - const gchar *_password, + const char *_db, const char *_username, + const char *_password, const char *_ip, int _port) : pool(_pool), ip(_ip), port(_port), key(redis_pool_elt::make_key(_db, _username, _password, _ip, _port)) @@ -150,8 +150,8 @@ public: conn->elt_pos = std::prev(std::end(terminating)); } - inline static auto make_key(const gchar *db, const gchar *username, - const gchar *password, const char *ip, int port) -> redis_pool_key_t + inline static auto make_key(const char *db, const char *username, + const char *password, const char *ip, int port) -> redis_pool_key_t { rspamd_cryptobox_fast_hash_state_t st; @@ -241,8 +241,8 @@ public: cfg = _cfg; } - auto new_connection(const gchar *db, const gchar *username, - const gchar *password, const char *ip, int port) -> redisAsyncContext *; + auto new_connection(const char *db, const char *username, + const char *password, const char *ip, int port) -> redisAsyncContext *; auto release_connection(redisAsyncContext *ctx, enum rspamd_redis_pool_release_type how) -> void; @@ -452,8 +452,8 @@ auto redis_pool_elt::new_connection() -> redisAsyncContext * g_assert(conn->state != rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_ACTIVE); if (conn->ctx->err == REDIS_OK) { /* Also check SO_ERROR */ - gint err; - socklen_t len = sizeof(gint); + int err; + socklen_t len = sizeof(int); if (getsockopt(conn->ctx->c.fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) == -1) { @@ -504,8 +504,8 @@ auto redis_pool_elt::new_connection() -> redisAsyncContext * RSPAMD_UNREACHABLE; } -auto redis_pool::new_connection(const gchar *db, const gchar *username, - const gchar *password, const char *ip, int port) -> redisAsyncContext * +auto redis_pool::new_connection(const char *db, const char *username, + const char *password, const char *ip, int port) -> redisAsyncContext * { if (!wanna_die) { @@ -602,8 +602,8 @@ void rspamd_redis_pool_config(void *p, struct redisAsyncContext * rspamd_redis_pool_connect(void *p, - const gchar *db, const gchar *username, - const gchar *password, const char *ip, int port) + const char *db, const char *username, + const char *password, const char *ip, int port) { g_assert(p != NULL); auto *pool = reinterpret_cast(p); @@ -631,10 +631,10 @@ void rspamd_redis_pool_destroy(void *p) delete pool; } -const gchar * +const char * rspamd_redis_type_to_string(int type) { - const gchar *ret = "unknown"; + const char *ret = "unknown"; switch (type) { case REDIS_REPLY_STRING: diff --git a/src/libserver/redis_pool.h b/src/libserver/redis_pool.h index ecdaa0f85..3e951081b 100644 --- a/src/libserver/redis_pool.h +++ b/src/libserver/redis_pool.h @@ -53,7 +53,7 @@ void rspamd_redis_pool_config(void *pool, */ struct redisAsyncContext *rspamd_redis_pool_connect( void *pool, - const gchar *db, const gchar *username, const gchar *password, + const char *db, const char *username, const char *password, const char *ip, int port); enum rspamd_redis_pool_release_type { @@ -82,7 +82,7 @@ void rspamd_redis_pool_destroy(void *pool); * @param type * @return */ -const gchar *rspamd_redis_type_to_string(int type); +const char *rspamd_redis_type_to_string(int type); #ifdef __cplusplus } diff --git a/src/libserver/roll_history.c b/src/libserver/roll_history.c index f567b0b82..66a53a597 100644 --- a/src/libserver/roll_history.c +++ b/src/libserver/roll_history.c @@ -20,7 +20,7 @@ #include "unix-std.h" #include "cfg_file_private.h" -static const gchar rspamd_history_magic_old[] = {'r', 's', 'h', '1'}; +static const char rspamd_history_magic_old[] = {'r', 's', 'h', '1'}; /** * Returns new roll history @@ -28,7 +28,7 @@ static const gchar rspamd_history_magic_old[] = {'r', 's', 'h', '1'}; * @return new structure */ struct roll_history * -rspamd_roll_history_new(rspamd_mempool_t *pool, guint max_rows, +rspamd_roll_history_new(rspamd_mempool_t *pool, unsigned int max_rows, struct rspamd_config *cfg) { struct roll_history *history; @@ -68,8 +68,8 @@ rspamd_roll_history_new(rspamd_mempool_t *pool, guint max_rows, } struct history_metric_callback_data { - gchar *pos; - gint remain; + char *pos; + int remain; }; static void @@ -77,7 +77,7 @@ roll_history_symbols_callback(gpointer key, gpointer value, void *user_data) { struct history_metric_callback_data *cb = user_data; struct rspamd_symbol_result *s = value; - guint wr; + unsigned int wr; if (s->flags & RSPAMD_SYMBOL_RESULT_IGNORED) { return; @@ -98,7 +98,7 @@ roll_history_symbols_callback(gpointer key, gpointer value, void *user_data) void rspamd_roll_history_update(struct roll_history *history, struct rspamd_task *task) { - guint row_num; + unsigned int row_num; struct roll_history_row *row; struct rspamd_scan_result *metric_res; struct history_metric_callback_data cbdata; @@ -187,16 +187,16 @@ void rspamd_roll_history_update(struct roll_history *history, * @return TRUE if history has been loaded */ gboolean -rspamd_roll_history_load(struct roll_history *history, const gchar *filename) +rspamd_roll_history_load(struct roll_history *history, const char *filename) { - gint fd; + int fd; struct stat st; - gchar magic[sizeof(rspamd_history_magic_old)]; + char magic[sizeof(rspamd_history_magic_old)]; ucl_object_t *top; const ucl_object_t *cur, *elt; struct ucl_parser *parser; struct roll_history_row *row; - guint n, i; + unsigned int n, i; g_assert(history != NULL); if (history->disabled) { @@ -365,12 +365,12 @@ rspamd_roll_history_load(struct roll_history *history, const gchar *filename) * @return TRUE if history has been saved */ gboolean -rspamd_roll_history_save(struct roll_history *history, const gchar *filename) +rspamd_roll_history_save(struct roll_history *history, const char *filename) { - gint fd; + int fd; FILE *fp; ucl_object_t *obj, *elt; - guint i; + unsigned int i; struct roll_history_row *row; struct ucl_emitter_functions *emitter_func; diff --git a/src/libserver/roll_history.h b/src/libserver/roll_history.h index 62bce7f7d..18d9ff5cd 100644 --- a/src/libserver/roll_history.h +++ b/src/libserver/roll_history.h @@ -38,23 +38,23 @@ struct rspamd_config; struct roll_history_row { ev_tstamp timestamp; - gchar message_id[HISTORY_MAX_ID]; - gchar symbols[HISTORY_MAX_SYMBOLS]; - gchar user[HISTORY_MAX_USER]; - gchar from_addr[HISTORY_MAX_ADDR]; + char message_id[HISTORY_MAX_ID]; + char symbols[HISTORY_MAX_SYMBOLS]; + char user[HISTORY_MAX_USER]; + char from_addr[HISTORY_MAX_ADDR]; gsize len; - gdouble scan_time; - gdouble score; - gdouble required_score; - gint action; - guint completed; + double scan_time; + double score; + double required_score; + int action; + unsigned int completed; }; struct roll_history { struct roll_history_row *rows; gboolean disabled; - guint nrows; - guint cur_row; + unsigned int nrows; + unsigned int cur_row; }; /** @@ -63,7 +63,7 @@ struct roll_history { * @return new structure */ struct roll_history *rspamd_roll_history_new(rspamd_mempool_t *pool, - guint max_rows, struct rspamd_config *cfg); + unsigned int max_rows, struct rspamd_config *cfg); /** * Update roll history with data from task @@ -80,7 +80,7 @@ void rspamd_roll_history_update(struct roll_history *history, * @return TRUE if history has been loaded */ gboolean rspamd_roll_history_load(struct roll_history *history, - const gchar *filename); + const char *filename); /** * Save history to file @@ -89,7 +89,7 @@ gboolean rspamd_roll_history_load(struct roll_history *history, * @return TRUE if history has been saved */ gboolean rspamd_roll_history_save(struct roll_history *history, - const gchar *filename); + const char *filename); #ifdef __cplusplus } diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c index 69af0597f..8dd7595f4 100644 --- a/src/libserver/rspamd_control.c +++ b/src/libserver/rspamd_control.c @@ -43,20 +43,20 @@ struct rspamd_control_reply_elt { GQuark wrk_type; pid_t wrk_pid; gpointer ud; - gint attached_fd; + int attached_fd; GHashTable *pending_elts; struct rspamd_control_reply_elt *prev, *next; }; struct rspamd_control_session { - gint fd; + int fd; struct ev_loop *event_loop; struct rspamd_main *rspamd_main; struct rspamd_http_connection *conn; struct rspamd_control_command cmd; struct rspamd_control_reply_elt *replies; rspamd_inet_addr_t *addr; - guint replies_remain; + unsigned int replies_remain; gboolean is_reply; }; @@ -89,7 +89,7 @@ rspamd_control_stop_pending(struct rspamd_control_reply_elt *elt) } void rspamd_control_send_error(struct rspamd_control_session *session, - gint code, const gchar *error_msg, ...) + int code, const char *error_msg, ...) { struct rspamd_http_message *msg; rspamd_fstring_t *reply; @@ -165,10 +165,10 @@ rspamd_control_write_reply(struct rspamd_control_session *session) { ucl_object_t *rep, *cur, *workers; struct rspamd_control_reply_elt *elt; - gchar tmpbuf[64]; - gdouble total_utime = 0, total_systime = 0; + char tmpbuf[64]; + double total_utime = 0, total_systime = 0; struct ucl_parser *parser; - guint total_conns = 0; + unsigned int total_conns = 0; rep = ucl_object_typed_new(UCL_OBJECT); workers = ucl_object_typed_new(UCL_OBJECT); @@ -287,11 +287,11 @@ rspamd_control_write_reply(struct rspamd_control_session *session) } static void -rspamd_control_wrk_io(gint fd, short what, gpointer ud) +rspamd_control_wrk_io(int fd, short what, gpointer ud) { struct rspamd_control_reply_elt *elt = ud; struct rspamd_control_session *session; - guchar fdspace[CMSG_SPACE(sizeof(int))]; + unsigned char fdspace[CMSG_SPACE(sizeof(int))]; struct iovec iov; struct msghdr msg; gssize r; @@ -364,7 +364,7 @@ void rspamd_pending_control_free(gpointer p) static struct rspamd_control_reply_elt * rspamd_control_broadcast_cmd(struct rspamd_main *rspamd_main, struct rspamd_control_command *cmd, - gint attached_fd, + int attached_fd, rspamd_ev_cb handler, gpointer ud, pid_t except_pid) @@ -376,7 +376,7 @@ rspamd_control_broadcast_cmd(struct rspamd_main *rspamd_main, struct msghdr msg; struct cmsghdr *cmsg; struct iovec iov; - guchar fdspace[CMSG_SPACE(sizeof(int))]; + unsigned char fdspace[CMSG_SPACE(sizeof(int))]; gssize r; g_hash_table_iter_init(&it, rspamd_main->workers); @@ -457,13 +457,13 @@ void rspamd_control_broadcast_srv_cmd(struct rspamd_main *rspamd_main, rspamd_control_ignore_io_handler, NULL, except_pid); } -static gint +static int rspamd_control_finish_handler(struct rspamd_http_connection *conn, struct rspamd_http_message *msg) { struct rspamd_control_session *session = conn->ud; rspamd_ftok_t srch; - guint i; + unsigned int i; gboolean found = FALSE; struct rspamd_control_reply_elt *cur; @@ -512,7 +512,7 @@ rspamd_control_finish_handler(struct rspamd_http_connection *conn, } void rspamd_control_process_client_socket(struct rspamd_main *rspamd_main, - gint fd, rspamd_inet_addr_t *addr) + int fd, rspamd_inet_addr_t *addr) { struct rspamd_control_session *session; @@ -543,8 +543,8 @@ struct rspamd_worker_control_data { }; static void -rspamd_control_default_cmd_handler(gint fd, - gint attached_fd, +rspamd_control_default_cmd_handler(int fd, + int attached_fd, struct rspamd_worker_control_data *cd, struct rspamd_control_command *cmd) { @@ -624,8 +624,8 @@ rspamd_control_default_worker_handler(EV_P_ ev_io *w, int revents) static struct rspamd_control_command cmd; static struct msghdr msg; static struct iovec iov; - static guchar fdspace[CMSG_SPACE(sizeof(int))]; - gint rfd = -1; + static unsigned char fdspace[CMSG_SPACE(sizeof(int))]; + int rfd = -1; gssize r; iov.iov_base = &cmd; @@ -652,16 +652,16 @@ rspamd_control_default_worker_handler(EV_P_ ev_io *w, int revents) close(w->fd); } } - else if (r < (gint) sizeof(cmd)) { - msg_err("short read of control command: %d of %d", (gint) r, - (gint) sizeof(cmd)); + else if (r < (int) sizeof(cmd)) { + msg_err("short read of control command: %d of %d", (int) r, + (int) sizeof(cmd)); if (r == 0) { ev_io_stop(cd->ev_base, &cd->io_ev); close(w->fd); } } - else if ((gint) cmd.type >= 0 && cmd.type < RSPAMD_CONTROL_MAX) { + else if ((int) cmd.type >= 0 && cmd.type < RSPAMD_CONTROL_MAX) { if (msg.msg_controllen >= CMSG_LEN(sizeof(int))) { rfd = *(int *) CMSG_DATA(CMSG_FIRSTHDR(&msg)); @@ -680,7 +680,7 @@ rspamd_control_default_worker_handler(EV_P_ ev_io *w, int revents) } } else { - msg_err("unknown command: %d", (gint) cmd.type); + msg_err("unknown command: %d", (int) cmd.type); } } @@ -723,7 +723,7 @@ void rspamd_control_worker_add_cmd_handler(struct rspamd_worker *worker, struct rspamd_srv_reply_data { struct rspamd_worker *worker; struct rspamd_main *srv; - gint fd; + int fd; struct rspamd_srv_reply rep; }; @@ -843,9 +843,9 @@ rspamd_srv_handler(EV_P_ ev_io *w, int revents) struct msghdr msg; struct cmsghdr *cmsg; static struct iovec iov; - static guchar fdspace[CMSG_SPACE(sizeof(int))]; - gint *spair, rfd = -1; - gchar *nid; + static unsigned char fdspace[CMSG_SPACE(sizeof(int))]; + int *spair, rfd = -1; + char *nid; struct rspamd_control_command wcmd; gssize r; @@ -882,7 +882,7 @@ rspamd_srv_handler(EV_P_ ev_io *w, int revents) } else if (r != sizeof(cmd)) { msg_err_main("cannot read from worker's srv pipe incomplete command: %d != %d; command = %s", - (gint) r, (gint) sizeof(cmd), rspamd_srv_command_to_string(cmd.type)); + (int) r, (int) sizeof(cmd), rspamd_srv_command_to_string(cmd.type)); } else { rdata = g_malloc0(sizeof(*rdata)); @@ -901,7 +901,7 @@ rspamd_srv_handler(EV_P_ ev_io *w, int revents) case RSPAMD_SRV_SOCKETPAIR: spair = g_hash_table_lookup(rspamd_main->spairs, cmd.cmd.spair.pair_id); if (spair == NULL) { - spair = g_malloc(sizeof(gint) * 2); + spair = g_malloc(sizeof(int) * 2); if (rspamd_socketpair(spair, cmd.cmd.spair.af) == -1) { rdata->rep.reply.spair.code = errno; @@ -1073,7 +1073,7 @@ void rspamd_srv_start_watching(struct rspamd_main *srv, struct rspamd_srv_request_data { struct rspamd_worker *worker; struct rspamd_srv_command cmd; - gint attached_fd; + int attached_fd; struct rspamd_srv_reply rep; rspamd_srv_reply_handler handler; ev_io io_ev; @@ -1086,10 +1086,10 @@ rspamd_srv_request_handler(EV_P_ ev_io *w, int revents) struct rspamd_srv_request_data *rd = (struct rspamd_srv_request_data *) w->data; struct msghdr msg; struct iovec iov; - guchar fdspace[CMSG_SPACE(sizeof(int))]; + unsigned char fdspace[CMSG_SPACE(sizeof(int))]; struct cmsghdr *cmsg; gssize r; - gint rfd = -1; + int rfd = -1; if (revents == EV_WRITE) { /* Send request to server */ @@ -1156,9 +1156,9 @@ rspamd_srv_request_handler(EV_P_ ev_io *w, int revents) goto cleanup; } - if (r != (gint) sizeof(rd->rep)) { + if (r != (int) sizeof(rd->rep)) { msg_err("cannot read from server pipe, invalid length: %d != %d; command = %s", - (gint) r, (int) sizeof(rd->rep), rspamd_srv_command_to_string(rd->cmd.type)); + (int) r, (int) sizeof(rd->rep), rspamd_srv_command_to_string(rd->cmd.type)); goto cleanup; } @@ -1185,7 +1185,7 @@ cleanup: void rspamd_srv_send_command(struct rspamd_worker *worker, struct ev_loop *ev_base, struct rspamd_srv_command *cmd, - gint attached_fd, + int attached_fd, rspamd_srv_reply_handler handler, gpointer ud) { @@ -1211,7 +1211,7 @@ void rspamd_srv_send_command(struct rspamd_worker *worker, } enum rspamd_control_type -rspamd_control_command_from_string(const gchar *str) +rspamd_control_command_from_string(const char *str) { enum rspamd_control_type ret = RSPAMD_CONTROL_MAX; @@ -1253,10 +1253,10 @@ rspamd_control_command_from_string(const gchar *str) return ret; } -const gchar * +const char * rspamd_control_command_to_string(enum rspamd_control_type cmd) { - const gchar *reply = "unknown"; + const char *reply = "unknown"; switch (cmd) { case RSPAMD_CONTROL_STAT: @@ -1296,9 +1296,9 @@ rspamd_control_command_to_string(enum rspamd_control_type cmd) return reply; } -const gchar *rspamd_srv_command_to_string(enum rspamd_srv_type cmd) +const char *rspamd_srv_command_to_string(enum rspamd_srv_type cmd) { - const gchar *reply = "unknown"; + const char *reply = "unknown"; switch (cmd) { case RSPAMD_SRV_SOCKETPAIR: diff --git a/src/libserver/rspamd_control.h b/src/libserver/rspamd_control.h index c9f608fe1..a08ba7948 100644 --- a/src/libserver/rspamd_control.h +++ b/src/libserver/rspamd_control.h @@ -60,23 +60,23 @@ struct rspamd_control_command { enum rspamd_control_type type; union { struct { - guint unused; + unsigned int unused; } stat; struct { - guint unused; + unsigned int unused; } reload; struct { - guint unused; + unsigned int unused; } reresolve; struct { - guint unused; + unsigned int unused; } recompile; struct { gboolean forced; - gchar cache_dir[CONTROL_PATHLEN]; + char cache_dir[CONTROL_PATHLEN]; } hs_loaded; struct { - gchar tag[32]; + char tag[32]; gboolean alive; pid_t sender; } monitored_change; @@ -84,10 +84,10 @@ struct rspamd_control_command { enum rspamd_log_pipe_type type; } log_pipe; struct { - guint unused; + unsigned int unused; } fuzzy_stat; struct { - guint unused; + unsigned int unused; } fuzzy_sync; struct { enum { @@ -96,7 +96,7 @@ struct rspamd_control_command { rspamd_child_terminated, } what; pid_t pid; - guint additional; + unsigned int additional; } child_change; struct { union { @@ -113,39 +113,39 @@ struct rspamd_control_reply { enum rspamd_control_type type; union { struct { - guint conns; - gdouble uptime; - gdouble utime; - gdouble systime; + unsigned int conns; + double uptime; + double utime; + double systime; gulong maxrss; } stat; struct { - guint status; + unsigned int status; } reload; struct { - guint status; + unsigned int status; } reresolve; struct { - guint status; + unsigned int status; } recompile; struct { - guint status; + unsigned int status; } hs_loaded; struct { - guint status; + unsigned int status; } monitored_change; struct { - guint status; + unsigned int status; } log_pipe; struct { - guint status; - gchar storage_id[MEMPOOL_UID_LEN]; + unsigned int status; + char storage_id[MEMPOOL_UID_LEN]; } fuzzy_stat; struct { - guint status; + unsigned int status; } fuzzy_sync; struct { - guint status; + unsigned int status; } fuzzy_blocked; } reply; }; @@ -157,16 +157,16 @@ struct rspamd_srv_command { uint64_t id; union { struct { - gint af; - gchar pair_id[PAIR_ID_LEN]; - guint pair_num; + int af; + char pair_id[PAIR_ID_LEN]; + unsigned int pair_num; } spair; struct { gboolean forced; - gchar cache_dir[CONTROL_PATHLEN]; + char cache_dir[CONTROL_PATHLEN]; } hs_loaded; struct { - gchar tag[32]; + char tag[32]; gboolean alive; pid_t sender; } monitored_change; @@ -182,11 +182,11 @@ struct rspamd_srv_command { } state; } on_fork; struct { - guint status; + unsigned int status; /* TODO: add more fields */ } heartbeat; struct { - guint status; + unsigned int status; } health; /* Used when a worker loads a valid hyperscan file */ struct { @@ -209,28 +209,28 @@ struct rspamd_srv_reply { uint64_t id; union { struct { - gint code; + int code; } spair; struct { - gint forced; + int forced; } hs_loaded; struct { - gint status; + int status; }; struct { enum rspamd_log_pipe_type type; } log_pipe; struct { - gint status; + int status; } on_fork; struct { - gint status; + int status; } heartbeat; struct { - guint status; - guint workers_count; - guint scanners_count; - guint workers_hb_lost; + unsigned int status; + unsigned int workers_count; + unsigned int scanners_count; + unsigned int workers_hb_lost; } health; struct { int unused; @@ -243,20 +243,20 @@ struct rspamd_srv_reply { typedef gboolean (*rspamd_worker_control_handler)(struct rspamd_main *rspamd_main, struct rspamd_worker *worker, - gint fd, - gint attached_fd, + int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud); typedef void (*rspamd_srv_reply_handler)(struct rspamd_worker *worker, - struct rspamd_srv_reply *rep, gint rep_fd, + struct rspamd_srv_reply *rep, int rep_fd, gpointer ud); /** * Process client socket connection */ void rspamd_control_process_client_socket(struct rspamd_main *rspamd_main, - gint fd, rspamd_inet_addr_t *addr); + int fd, rspamd_inet_addr_t *addr); /** * Register default handlers for a worker @@ -287,7 +287,7 @@ void rspamd_srv_start_watching(struct rspamd_main *srv, void rspamd_srv_send_command(struct rspamd_worker *worker, struct ev_loop *ev_base, struct rspamd_srv_command *cmd, - gint attached_fd, + int attached_fd, rspamd_srv_reply_handler handler, gpointer ud); @@ -306,16 +306,16 @@ void rspamd_control_broadcast_srv_cmd(struct rspamd_main *rspamd_main, * @param str * @return */ -enum rspamd_control_type rspamd_control_command_from_string(const gchar *str); +enum rspamd_control_type rspamd_control_command_from_string(const char *str); /** * Returns command name from it's type * @param cmd * @return */ -const gchar *rspamd_control_command_to_string(enum rspamd_control_type cmd); +const char *rspamd_control_command_to_string(enum rspamd_control_type cmd); -const gchar *rspamd_srv_command_to_string(enum rspamd_srv_type cmd); +const char *rspamd_srv_command_to_string(enum rspamd_srv_type cmd); /** * Used to cleanup pending events diff --git a/src/libserver/rspamd_symcache.h b/src/libserver/rspamd_symcache.h index 8ad3e34a2..5725a2885 100644 --- a/src/libserver/rspamd_symcache.h +++ b/src/libserver/rspamd_symcache.h @@ -75,13 +75,13 @@ struct rspamd_abstract_callback_data { */ struct rspamd_symcache_item_stat { struct rspamd_counter_data time_counter; - gdouble avg_time; - gdouble weight; - guint hits; + double avg_time; + double weight; + unsigned int hits; uint64_t total_hits; struct rspamd_counter_data frequency_counter; - gdouble avg_frequency; - gdouble stddev_frequency; + double avg_frequency; + double stddev_frequency; }; /** @@ -118,13 +118,13 @@ gboolean rspamd_symcache_init(struct rspamd_symcache *cache); * @param type * @param parent */ -gint rspamd_symcache_add_symbol(struct rspamd_symcache *cache, - const gchar *name, - gint priority, - symbol_func_t func, - gpointer user_data, - int type, - gint parent); +int rspamd_symcache_add_symbol(struct rspamd_symcache *cache, + const char *name, + int priority, + symbol_func_t func, + gpointer user_data, + int type, + int parent); /** * Adds augmentation to the symbol @@ -144,7 +144,7 @@ bool rspamd_symcache_add_symbol_augmentation(struct rspamd_symcache *cache, * @param cbref */ void rspamd_symcache_set_peak_callback(struct rspamd_symcache *cache, - gint cbref); + int cbref); /** * Add delayed condition to the specific symbol in cache. So symbol can be absent @@ -156,8 +156,8 @@ void rspamd_symcache_set_peak_callback(struct rspamd_symcache *cache, * @return TRUE if condition has been added */ gboolean rspamd_symcache_add_condition_delayed(struct rspamd_symcache *cache, - const gchar *sym, - lua_State *L, gint cbref); + const char *sym, + lua_State *L, int cbref); /** * Find symbol in cache by id and returns its id resolving virtual symbols if @@ -166,8 +166,8 @@ gboolean rspamd_symcache_add_condition_delayed(struct rspamd_symcache *cache, * @param name * @return id of symbol or (-1) if a symbol has not been found */ -gint rspamd_symcache_find_symbol(struct rspamd_symcache *cache, - const gchar *name); +int rspamd_symcache_find_symbol(struct rspamd_symcache *cache, + const char *name); /** * Get statistics for a specific symbol @@ -178,18 +178,18 @@ gint rspamd_symcache_find_symbol(struct rspamd_symcache *cache, * @return */ gboolean rspamd_symcache_stat_symbol(struct rspamd_symcache *cache, - const gchar *name, - gdouble *frequency, - gdouble *freq_stddev, - gdouble *tm, - guint *nhits); + const char *name, + double *frequency, + double *freq_stddev, + double *tm, + unsigned int *nhits); /** * Returns number of symbols registered in symbols cache * @param cache * @return number of symbols in the cache */ -guint rspamd_symcache_stats_symbols_count(struct rspamd_symcache *cache); +unsigned int rspamd_symcache_stats_symbols_count(struct rspamd_symcache *cache); /** * Validate cache items against theirs weights defined in metrics @@ -209,7 +209,7 @@ gboolean rspamd_symcache_validate(struct rspamd_symcache *cache, */ gboolean rspamd_symcache_process_symbols(struct rspamd_task *task, struct rspamd_symcache *cache, - guint stage); + unsigned int stage); /** * Return statistics about the cache as ucl object (array of objects one per item) @@ -234,7 +234,7 @@ void *rspamd_symcache_start_refresh(struct rspamd_symcache *cache, */ void rspamd_symcache_inc_frequency(struct rspamd_symcache *_cache, struct rspamd_symcache_item *item, - const gchar *sym_name); + const char *sym_name); /** * Add delayed dependency that is resolved on cache post-load routine @@ -243,7 +243,7 @@ void rspamd_symcache_inc_frequency(struct rspamd_symcache *_cache, * @param to */ void rspamd_symcache_add_delayed_dependency(struct rspamd_symcache *cache, - const gchar *from, const gchar *to); + const char *from, const char *to); /** * Get abstract callback data for a symbol (or its parent symbol) @@ -252,7 +252,7 @@ void rspamd_symcache_add_delayed_dependency(struct rspamd_symcache *cache, * @return abstract callback data or NULL if symbol is absent or has no data attached */ struct rspamd_abstract_callback_data *rspamd_symcache_get_cbdata( - struct rspamd_symcache *cache, const gchar *symbol); + struct rspamd_symcache *cache, const char *symbol); /** * Returns symbol's parent name (or symbol name itself) @@ -260,14 +260,14 @@ struct rspamd_abstract_callback_data *rspamd_symcache_get_cbdata( * @param symbol * @return */ -const gchar *rspamd_symcache_get_parent(struct rspamd_symcache *cache, - const gchar *symbol); +const char *rspamd_symcache_get_parent(struct rspamd_symcache *cache, + const char *symbol); -guint rspamd_symcache_get_symbol_flags(struct rspamd_symcache *cache, - const gchar *symbol); +unsigned int rspamd_symcache_get_symbol_flags(struct rspamd_symcache *cache, + const char *symbol); void rspamd_symcache_get_symbol_details(struct rspamd_symcache *cache, - const gchar *symbol, + const char *symbol, ucl_object_t *this_sym_ucl); @@ -290,7 +290,7 @@ gboolean rspamd_symcache_process_settings(struct rspamd_task *task, */ gboolean rspamd_symcache_is_checked(struct rspamd_task *task, struct rspamd_symcache *cache, - const gchar *symbol); + const char *symbol); /** * Returns checksum for all cache items @@ -308,7 +308,7 @@ uint64_t rspamd_symcache_get_cksum(struct rspamd_symcache *cache); */ gboolean rspamd_symcache_is_symbol_enabled(struct rspamd_task *task, struct rspamd_symcache *cache, - const gchar *symbol); + const char *symbol); /** * Enable this symbol for task @@ -319,7 +319,7 @@ gboolean rspamd_symcache_is_symbol_enabled(struct rspamd_task *task, */ gboolean rspamd_symcache_enable_symbol(struct rspamd_task *task, struct rspamd_symcache *cache, - const gchar *symbol); + const char *symbol); /** * Enable this symbol for task @@ -330,7 +330,7 @@ gboolean rspamd_symcache_enable_symbol(struct rspamd_task *task, */ gboolean rspamd_symcache_disable_symbol(struct rspamd_task *task, struct rspamd_symcache *cache, - const gchar *symbol); + const char *symbol); /** * Disable execution of a symbol or a pattern (a string enclosed in `//`) permanently @@ -340,7 +340,7 @@ gboolean rspamd_symcache_disable_symbol(struct rspamd_task *task, * @return */ void rspamd_symcache_disable_symbol_static(struct rspamd_symcache *cache, - const gchar *symbol); + const char *symbol); /** * Add a symbol or a pattern to the list of explicitly and statically enabled symbols * @param cache @@ -348,7 +348,7 @@ void rspamd_symcache_disable_symbol_static(struct rspamd_symcache *cache, * @return */ void rspamd_symcache_enable_symbol_static(struct rspamd_symcache *cache, - const gchar *symbol); + const char *symbol); /** * Process specific function for each cache element (in order they are added) @@ -387,10 +387,10 @@ void rspamd_symcache_finalize_item(struct rspamd_task *task, /* * Increase number of async events pending for an item */ -guint rspamd_symcache_item_async_inc_full(struct rspamd_task *task, - struct rspamd_symcache_dynamic_item *item, - const gchar *subsystem, - const gchar *loc); +unsigned int rspamd_symcache_item_async_inc_full(struct rspamd_task *task, + struct rspamd_symcache_dynamic_item *item, + const char *subsystem, + const char *loc); #define rspamd_symcache_item_async_inc(task, item, subsystem) \ rspamd_symcache_item_async_inc_full(task, item, subsystem, G_STRLOC) @@ -398,10 +398,10 @@ guint rspamd_symcache_item_async_inc_full(struct rspamd_task *task, /* * Decrease number of async events pending for an item, asserts if no events pending */ -guint rspamd_symcache_item_async_dec_full(struct rspamd_task *task, - struct rspamd_symcache_dynamic_item *item, - const gchar *subsystem, - const gchar *loc); +unsigned int rspamd_symcache_item_async_dec_full(struct rspamd_task *task, + struct rspamd_symcache_dynamic_item *item, + const char *subsystem, + const char *loc); #define rspamd_symcache_item_async_dec(task, item, subsystem) \ rspamd_symcache_item_async_dec_full(task, item, subsystem, G_STRLOC) @@ -415,8 +415,8 @@ guint rspamd_symcache_item_async_dec_full(struct rspamd_task *task, */ gboolean rspamd_symcache_item_async_dec_check_full(struct rspamd_task *task, struct rspamd_symcache_dynamic_item *item, - const gchar *subsystem, - const gchar *loc); + const char *subsystem, + const char *loc); #define rspamd_symcache_item_async_dec_check(task, item, subsystem) \ rspamd_symcache_item_async_dec_check_full(task, item, subsystem, G_STRLOC) @@ -429,7 +429,7 @@ gboolean rspamd_symcache_item_async_dec_check_full(struct rspamd_task *task, */ void rspamd_symcache_disable_all_symbols(struct rspamd_task *task, struct rspamd_symcache *cache, - guint skip_mask); + unsigned int skip_mask); /** * Iterates over the list of the enabled composites calling specified function @@ -451,9 +451,9 @@ void rspamd_symcache_composites_foreach(struct rspamd_task *task, * @param nids */ bool rspamd_symcache_set_allowed_settings_ids(struct rspamd_symcache *cache, - const gchar *symbol, + const char *symbol, const uint32_t *ids, - guint nids); + unsigned int nids); /** * Sets denied settings ids for a symbol * @param cache @@ -462,9 +462,9 @@ bool rspamd_symcache_set_allowed_settings_ids(struct rspamd_symcache *cache, * @param nids */ bool rspamd_symcache_set_forbidden_settings_ids(struct rspamd_symcache *cache, - const gchar *symbol, + const char *symbol, const uint32_t *ids, - guint nids); + unsigned int nids); /** * Returns allowed ids for a symbol as a constant array @@ -474,8 +474,8 @@ bool rspamd_symcache_set_forbidden_settings_ids(struct rspamd_symcache *cache, * @return */ const uint32_t *rspamd_symcache_get_allowed_settings_ids(struct rspamd_symcache *cache, - const gchar *symbol, - guint *nids); + const char *symbol, + unsigned int *nids); /** * Returns denied ids for a symbol as a constant array @@ -485,8 +485,8 @@ const uint32_t *rspamd_symcache_get_allowed_settings_ids(struct rspamd_symcache * @return */ const uint32_t *rspamd_symcache_get_forbidden_settings_ids(struct rspamd_symcache *cache, - const gchar *symbol, - guint *nids); + const char *symbol, + unsigned int *nids); /** @@ -515,18 +515,18 @@ gboolean rspamd_symcache_is_item_allowed(struct rspamd_task *task, * @param item * @return */ -gint rspamd_symcache_dyn_item_flags(struct rspamd_task *task, - struct rspamd_symcache_dynamic_item *dyn_item); -gint rspamd_symcache_item_flags(struct rspamd_symcache_item *item); +int rspamd_symcache_dyn_item_flags(struct rspamd_task *task, + struct rspamd_symcache_dynamic_item *dyn_item); +int rspamd_symcache_item_flags(struct rspamd_symcache_item *item); /** * Returns cache item name * @param item * @return */ -const gchar *rspamd_symcache_dyn_item_name(struct rspamd_task *task, - struct rspamd_symcache_dynamic_item *dyn_item); -const gchar *rspamd_symcache_item_name(struct rspamd_symcache_item *item); +const char *rspamd_symcache_dyn_item_name(struct rspamd_task *task, + struct rspamd_symcache_dynamic_item *dyn_item); +const char *rspamd_symcache_item_name(struct rspamd_symcache_item *item); /** * Returns the current item stat diff --git a/src/libserver/spf.c b/src/libserver/spf.c index 5f8fc14ba..32c020bf3 100644 --- a/src/libserver/spf.c +++ b/src/libserver/spf.c @@ -43,22 +43,22 @@ struct spf_resolved_element { GPtrArray *elts; - gchar *cur_domain; + char *cur_domain; gboolean redirected; /* Ignore level, it's redirected */ }; struct spf_record { - gint nested; - gint dns_requests; - gint requests_inflight; + int nested; + int dns_requests; + int requests_inflight; - guint ttl; + unsigned int ttl; GPtrArray *resolved; /* Array of struct spf_resolved_element */ - const gchar *sender; - const gchar *sender_domain; - const gchar *top_record; - gchar *local_part; + const char *sender; + const char *sender_domain; + const char *top_record; + char *local_part; struct rspamd_task *task; spf_cb_t callback; gpointer cbdata; @@ -66,9 +66,9 @@ struct spf_record { }; struct rspamd_spf_library_ctx { - guint max_dns_nesting; - guint max_dns_requests; - guint min_cache_ttl; + unsigned int max_dns_nesting; + unsigned int max_dns_requests; + unsigned int min_cache_ttl; gboolean disable_ipv6; rspamd_lru_hash_t *spf_hash; }; @@ -129,7 +129,7 @@ struct spf_dns_cb { struct spf_record *rec; struct spf_addr *addr; struct spf_resolved_element *resolved; - const gchar *ptr_host; + const char *ptr_host; spf_action_t cur_action; gboolean in_include; }; @@ -235,11 +235,11 @@ void spf_library_config(const ucl_object_t *obj) } static gboolean start_spf_parse(struct spf_record *rec, - struct spf_resolved_element *resolved, gchar *begin); + struct spf_resolved_element *resolved, char *begin); /* Determine spf mech */ static spf_mech_t -check_spf_mech(const gchar *elt, gboolean *need_shift) +check_spf_mech(const char *elt, gboolean *need_shift) { g_assert(elt != NULL); @@ -260,7 +260,7 @@ check_spf_mech(const gchar *elt, gboolean *need_shift) } } -static const gchar * +static const char * rspamd_spf_dns_action_to_str(spf_action_t act) { const char *ret = "unknown"; @@ -297,7 +297,7 @@ rspamd_spf_dns_action_to_str(spf_action_t act) static struct spf_addr * rspamd_spf_new_addr(struct spf_record *rec, - struct spf_resolved_element *resolved, const gchar *elt) + struct spf_resolved_element *resolved, const char *elt) { gboolean need_shift = FALSE; struct spf_addr *naddr; @@ -334,7 +334,7 @@ rspamd_spf_free_addr(gpointer a) } static struct spf_resolved_element * -rspamd_spf_new_addr_list(struct spf_record *rec, const gchar *domain) +rspamd_spf_new_addr_list(struct spf_record *rec, const char *domain) { struct spf_resolved_element *resolved; @@ -356,7 +356,7 @@ spf_record_destructor(gpointer r) { struct spf_record *rec = r; struct spf_resolved_element *elt; - guint i; + unsigned int i; if (rec) { for (i = 0; i < rec->resolved->len; i++) { @@ -374,7 +374,7 @@ static void rspamd_flatten_record_dtor(struct spf_resolved *r) { struct spf_addr *addr; - guint i; + unsigned int i; for (i = 0; i < r->elts->len; i++) { addr = &g_array_index(r->elts, struct spf_addr, i); @@ -393,7 +393,7 @@ rspamd_spf_process_reference(struct spf_resolved *target, { struct spf_resolved_element *elt, *relt; struct spf_addr *cur = NULL, taddr, *cur_addr; - guint i; + unsigned int i; if (addr) { g_assert(addr->m.idx < rec->resolved->len); @@ -521,7 +521,7 @@ rspamd_spf_record_flatten(struct spf_record *rec) return res; } -static gint +static int rspamd_spf_elts_cmp(gconstpointer a, gconstpointer b) { struct spf_addr *addr_a, *addr_b; @@ -565,7 +565,7 @@ rspamd_spf_record_postprocess(struct spf_resolved *rec, struct rspamd_task *task { g_array_sort(rec->elts, rspamd_spf_elts_cmp); - for (guint i = 0; i < rec->elts->len; i++) { + for (unsigned int i = 0; i < rec->elts->len; i++) { struct spf_addr *cur_addr = &g_array_index(rec->elts, struct spf_addr, i); if (cur_addr->flags & RSPAMD_SPF_FLAG_IPV6) { @@ -579,7 +579,7 @@ rspamd_spf_record_postprocess(struct spf_resolved *rec, struct rspamd_task *task t[2] = ((uint64_t) (cur_addr->mech)) << 48u; t[2] |= cur_addr->m.dual.mask_v6; - for (guint j = 0; j < G_N_ELEMENTS(t); j++) { + for (unsigned int j = 0; j < G_N_ELEMENTS(t); j++) { rec->digest = mum_hash_step(rec->digest, t[j]); } } @@ -769,7 +769,7 @@ spf_record_process_addr(struct spf_record *rec, struct spf_addr *addr, struct rd static void spf_record_addr_set(struct spf_addr *addr, gboolean allow_any) { - guchar fill; + unsigned char fill; if (!(addr->flags & RSPAMD_SPF_FLAG_PROCESSED)) { if (allow_any) { @@ -880,7 +880,7 @@ spf_record_dns_callback(struct rdns_reply *reply, gpointer arg) LL_FOREACH(reply->entries, elt_data) { /* Adjust ttl if a resolved record has lower ttl than spf record itself */ - if ((guint) elt_data->ttl < rec->ttl) { + if ((unsigned int) elt_data->ttl < rec->ttl) { msg_debug_spf("reducing ttl from %d to %d after DNS resolving", rec->ttl, elt_data->ttl); rec->ttl = elt_data->ttl; @@ -1134,7 +1134,7 @@ end: * ip6-cidr-length = "/" 1*DIGIT * dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] */ -static const gchar * +static const char * parse_spf_domain_mask(struct spf_record *rec, struct spf_addr *addr, struct spf_resolved_element *resolved, gboolean allow_mask) @@ -1150,10 +1150,10 @@ parse_spf_domain_mask(struct spf_record *rec, struct spf_addr *addr, parse_ipv6_mask, skip_garbage } state = 0; - const gchar *p = addr->spf_string, *host, *c; - gchar *hostbuf; - gchar t; - guint16 cur_mask = 0; + const char *p = addr->spf_string, *host, *c; + char *hostbuf; + char t; + uint16_t cur_mask = 0; host = resolved->cur_domain; c = p; @@ -1272,7 +1272,7 @@ parse_spf_a(struct spf_record *rec, struct spf_resolved_element *resolved, struct spf_addr *addr) { struct spf_dns_cb *cb; - const gchar *host = NULL; + const char *host = NULL; struct rspamd_task *task = rec->task; CHECK_REC(rec); @@ -1328,8 +1328,8 @@ parse_spf_ptr(struct spf_record *rec, struct spf_resolved_element *resolved, struct spf_addr *addr) { struct spf_dns_cb *cb; - const gchar *host; - gchar *ptr; + const char *host; + char *ptr; struct rspamd_task *task = rec->task; CHECK_REC(rec); @@ -1375,7 +1375,7 @@ parse_spf_mx(struct spf_record *rec, struct spf_resolved_element *resolved, struct spf_addr *addr) { struct spf_dns_cb *cb; - const gchar *host; + const char *host; struct rspamd_task *task = rec->task; CHECK_REC(rec); @@ -1430,9 +1430,9 @@ static gboolean parse_spf_ip4(struct spf_record *rec, struct spf_addr *addr) { /* ip4:addr[/mask] */ - const gchar *semicolon, *slash; + const char *semicolon, *slash; gsize len; - gchar ipbuf[INET_ADDRSTRLEN + 1]; + char ipbuf[INET_ADDRSTRLEN + 1]; uint32_t mask; static const uint32_t min_valid_mask = 8; @@ -1467,7 +1467,7 @@ parse_spf_ip4(struct spf_record *rec, struct spf_addr *addr) } if (slash) { - gchar *end = NULL; + char *end = NULL; mask = strtoul(slash + 1, &end, 10); if (mask > 32) { @@ -1506,9 +1506,9 @@ static gboolean parse_spf_ip6(struct spf_record *rec, struct spf_addr *addr) { /* ip6:addr[/mask] */ - const gchar *semicolon, *slash; + const char *semicolon, *slash; gsize len; - gchar ipbuf[INET6_ADDRSTRLEN + 1]; + char ipbuf[INET6_ADDRSTRLEN + 1]; uint32_t mask; static const uint32_t min_valid_mask = 8; @@ -1543,7 +1543,7 @@ parse_spf_ip6(struct spf_record *rec, struct spf_addr *addr) } if (slash) { - gchar *end = NULL; + char *end = NULL; mask = strtoul(slash + 1, &end, 10); if (mask > 128) { msg_notice_spf("invalid mask for ip6 element for %s: %s", addr->spf_string, @@ -1582,7 +1582,7 @@ static gboolean parse_spf_include(struct spf_record *rec, struct spf_addr *addr) { struct spf_dns_cb *cb; - const gchar *domain; + const char *domain; struct rspamd_task *task = rec->task; CHECK_REC(rec); @@ -1641,7 +1641,7 @@ parse_spf_redirect(struct spf_record *rec, struct spf_resolved_element *resolved, struct spf_addr *addr) { struct spf_dns_cb *cb; - const gchar *domain; + const char *domain; struct rspamd_task *task = rec->task; CHECK_REC(rec); @@ -1694,7 +1694,7 @@ static gboolean parse_spf_exists(struct spf_record *rec, struct spf_addr *addr) { struct spf_dns_cb *cb; - const gchar *host; + const char *host; struct rspamd_task *task = rec->task; struct spf_resolved_element *resolved; @@ -1738,11 +1738,11 @@ parse_spf_exists(struct spf_record *rec, struct spf_addr *addr) } static gsize -rspamd_spf_split_elt(const gchar *val, gsize len, gint *pos, - gsize poslen, gchar delim) +rspamd_spf_split_elt(const char *val, gsize len, int *pos, + gsize poslen, char delim) { - const gchar *p, *end; - guint cur_pos = 0, cur_st = 0, nsub = 0; + const char *p, *end; + unsigned int cur_pos = 0, cur_st = 0, nsub = 0; p = val; end = val + len; @@ -1781,14 +1781,14 @@ rspamd_spf_split_elt(const gchar *val, gsize len, gint *pos, } static gsize -rspamd_spf_process_substitution(const gchar *macro_value, - gsize macro_len, guint ndelim, gchar delim, gboolean reversed, - gchar *dest) +rspamd_spf_process_substitution(const char *macro_value, + gsize macro_len, unsigned int ndelim, char delim, gboolean reversed, + char *dest) { - gchar *d = dest; - const gchar canon_delim = '.'; - guint vlen, i; - gint pos[49 * 2], tlen; + char *d = dest; + const char canon_delim = '.'; + unsigned int vlen, i; + int pos[49 * 2], tlen; if (!reversed && ndelim == 0 && delim == canon_delim) { /* Trivial case */ @@ -1843,15 +1843,15 @@ rspamd_spf_process_substitution(const gchar *macro_value, return (d - dest); } -static const gchar * +static const char * expand_spf_macro(struct spf_record *rec, struct spf_resolved_element *resolved, - const gchar *begin) + const char *begin) { - const gchar *p, *macro_value = NULL; - gchar *c, *new, *tmp, delim = '.'; + const char *p, *macro_value = NULL; + char *c, *new, *tmp, delim = '.'; gsize len = 0, macro_len = 0; - gint state = 0, ndelim = 0; - gchar ip_buf[64 + 1]; /* cannot use INET6_ADDRSTRLEN as we use ptr lookup */ + int state = 0, ndelim = 0; + char ip_buf[64 + 1]; /* cannot use INET6_ADDRSTRLEN as we use ptr lookup */ gboolean need_expand = FALSE, reversed; struct rspamd_task *task; @@ -2222,13 +2222,13 @@ expand_spf_macro(struct spf_record *rec, struct spf_resolved_element *resolved, static gboolean spf_process_element(struct spf_record *rec, struct spf_resolved_element *resolved, - const gchar *elt, - const gchar **elts) + const char *elt, + const char **elts) { struct spf_addr *addr = NULL; gboolean res = FALSE; - const gchar *begin; - gchar t; + const char *begin; + char t; g_assert(elt != NULL); g_assert(rec != NULL); @@ -2329,7 +2329,7 @@ spf_process_element(struct spf_record *rec, */ gboolean ignore_redirect = FALSE; - for (const gchar **tmp = elts; *tmp != NULL; tmp++) { + for (const char **tmp = elts; *tmp != NULL; tmp++) { if (g_ascii_strcasecmp((*tmp) + 1, "all") == 0) { ignore_redirect = TRUE; break; @@ -2378,7 +2378,7 @@ spf_process_element(struct spf_record *rec, } static void -parse_spf_scopes(struct spf_record *rec, gchar **begin) +parse_spf_scopes(struct spf_record *rec, char **begin) { for (;;) { if (g_ascii_strncasecmp(*begin, SPF_SCOPE_PRA, sizeof(SPF_SCOPE_PRA) - 1) == 0) { @@ -2402,9 +2402,9 @@ parse_spf_scopes(struct spf_record *rec, gchar **begin) static gboolean start_spf_parse(struct spf_record *rec, struct spf_resolved_element *resolved, - gchar *begin) + char *begin) { - gchar **elts, **cur_elt; + char **elts, **cur_elt; gsize len; /* Skip spaces */ @@ -2439,7 +2439,7 @@ start_spf_parse(struct spf_record *rec, struct spf_resolved_element *resolved, msg_debug_spf( "spf error for domain %s: bad spf record start: %*s", rec->sender_domain, - (gint) len, + (int) len, begin); return FALSE; @@ -2455,7 +2455,7 @@ start_spf_parse(struct spf_record *rec, struct spf_resolved_element *resolved, cur_elt = elts; while (*cur_elt) { - spf_process_element(rec, resolved, *cur_elt, (const gchar **) elts); + spf_process_element(rec, resolved, *cur_elt, (const char **) elts); cur_elt++; } @@ -2609,10 +2609,10 @@ rspamd_spf_get_cred(struct rspamd_task *task) return cred; } -const gchar * +const char * rspamd_spf_get_domain(struct rspamd_task *task) { - gchar *domain = NULL; + char *domain = NULL; struct rspamd_spf_cred *cred; cred = rspamd_spf_get_cred(task); @@ -2686,22 +2686,22 @@ rspamd_spf_resolve(struct rspamd_task *task, spf_cb_t callback, } struct spf_resolved * -_spf_record_ref(struct spf_resolved *flat, const gchar *loc) +_spf_record_ref(struct spf_resolved *flat, const char *loc) { REF_RETAIN(flat); return flat; } -void _spf_record_unref(struct spf_resolved *flat, const gchar *loc) +void _spf_record_unref(struct spf_resolved *flat, const char *loc) { REF_RELEASE(flat); } -gchar * +char * spf_addr_mask_to_string(struct spf_addr *addr) { GString *res; - gchar *s, ipstr[INET6_ADDRSTRLEN + 1]; + char *s, ipstr[INET6_ADDRSTRLEN + 1]; if (addr->flags & RSPAMD_SPF_FLAG_ANY) { res = g_string_new("any"); @@ -2731,10 +2731,10 @@ spf_addr_mask_to_string(struct spf_addr *addr) struct spf_addr * spf_addr_match_task(struct rspamd_task *task, struct spf_resolved *rec) { - const guint8 *s, *d; - guint af, mask, bmask, addrlen; + const uint8_t *s, *d; + unsigned int af, mask, bmask, addrlen; struct spf_addr *selected = NULL, *addr, *any_addr = NULL; - guint i; + unsigned int i; if (task->from_addr == NULL) { return FALSE; @@ -2753,11 +2753,11 @@ spf_addr_match_task(struct rspamd_task *task, struct spf_resolved *rec) d = rspamd_inet_address_get_hash_key(task->from_addr, &addrlen); if (af == AF_INET6) { - s = (const guint8 *) addr->addr6; + s = (const uint8_t *) addr->addr6; mask = addr->m.dual.mask_v6; } else { - s = (const guint8 *) addr->addr4; + s = (const uint8_t *) addr->addr4; mask = addr->m.dual.mask_v4; } diff --git a/src/libserver/spf.h b/src/libserver/spf.h index 07bb05b1a..cc0ee4c05 100644 --- a/src/libserver/spf.h +++ b/src/libserver/spf.h @@ -1,3 +1,19 @@ +/* + * Copyright 2024 Vsevolod Stakhov + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef RSPAMD_SPF_H #define RSPAMD_SPF_H @@ -22,7 +38,7 @@ typedef enum spf_mech_e { SPF_NEUTRAL } spf_mech_t; -static inline gchar spf_mech_char(spf_mech_t mech) +static inline char spf_mech_char(spf_mech_t mech) { switch (mech) { case SPF_FAIL: @@ -68,18 +84,18 @@ typedef enum spf_action_e { #define SPF_MIN_CACHE_TTL (60 * 5) /* 5 minutes */ struct spf_addr { - guchar addr6[sizeof(struct in6_addr)]; - guchar addr4[sizeof(struct in_addr)]; + unsigned char addr6[sizeof(struct in6_addr)]; + unsigned char addr4[sizeof(struct in_addr)]; union { struct { - guint16 mask_v4; - guint16 mask_v6; + uint16_t mask_v4; + uint16_t mask_v6; } dual; uint32_t idx; } m; - guint flags; + unsigned int flags; spf_mech_t mech; - gchar *spf_string; + char *spf_string; struct spf_addr *prev, *next; }; @@ -91,20 +107,20 @@ enum rspamd_spf_resolved_flags { }; struct spf_resolved { - gchar *domain; - gchar *top_record; - guint ttl; - gint flags; - gdouble timestamp; + char *domain; + char *top_record; + unsigned int ttl; + int flags; + double timestamp; uint64_t digest; GArray *elts; /* Flat list of struct spf_addr */ ref_entry_t ref; /* Refcounting */ }; struct rspamd_spf_cred { - gchar *local_part; - gchar *domain; - gchar *sender; + char *local_part; + char *domain; + char *sender; }; /* @@ -118,19 +134,19 @@ gboolean rspamd_spf_resolve(struct rspamd_task *task, /* * Get a domain for spf for specified task */ -const gchar *rspamd_spf_get_domain(struct rspamd_task *task); +const char *rspamd_spf_get_domain(struct rspamd_task *task); struct rspamd_spf_cred *rspamd_spf_get_cred(struct rspamd_task *task); /* * Increase refcount */ -struct spf_resolved *_spf_record_ref(struct spf_resolved *rec, const gchar *loc); +struct spf_resolved *_spf_record_ref(struct spf_resolved *rec, const char *loc); #define spf_record_ref(rec) \ _spf_record_ref((rec), G_STRLOC) /* * Decrease refcount */ -void _spf_record_unref(struct spf_resolved *rec, const gchar *loc); +void _spf_record_unref(struct spf_resolved *rec, const char *loc); #define spf_record_unref(rec) \ _spf_record_unref((rec), G_STRLOC) @@ -139,7 +155,7 @@ void _spf_record_unref(struct spf_resolved *rec, const gchar *loc); * @param addr * @return */ -gchar *spf_addr_mask_to_string(struct spf_addr *addr); +char *spf_addr_mask_to_string(struct spf_addr *addr); /** * Returns spf address that matches the specific task (or nil if not matched) diff --git a/src/libserver/ssl_util.c b/src/libserver/ssl_util.c index 8ee53b0fb..b739961a8 100644 --- a/src/libserver/ssl_util.c +++ b/src/libserver/ssl_util.c @@ -52,20 +52,20 @@ struct rspamd_ssl_ctx { }; struct rspamd_ssl_connection { - gint fd; + int fd; enum rspamd_ssl_state state; enum rspamd_ssl_shutdown shut; gboolean verify_peer; SSL *ssl; struct rspamd_ssl_ctx *ssl_ctx; - gchar *hostname; + char *hostname; struct rspamd_io_ev *ev; struct rspamd_io_ev *shut_ev; struct ev_loop *event_loop; rspamd_ssl_handler_t handler; rspamd_ssl_error_handler_t err_handler; gpointer handler_data; - gchar log_tag[8]; + char log_tag[8]; }; #define msg_debug_ssl(...) rspamd_conditional_debug_fast(NULL, NULL, \ @@ -73,7 +73,7 @@ struct rspamd_ssl_connection { RSPAMD_LOG_FUNC, \ __VA_ARGS__) -static void rspamd_ssl_event_handler(gint fd, short what, gpointer ud); +static void rspamd_ssl_event_handler(int fd, short what, gpointer ud); INIT_LOG_MODULE(ssl) @@ -227,7 +227,7 @@ rspamd_tls_check_subject_altname(X509 *cert, const char *name) data = (const char *) ASN1_STRING_data(altname->d.dNSName); len = ASN1_STRING_length(altname->d.dNSName); - if (len < 0 || len != (gint) strlen(data)) { + if (len < 0 || len != (int) strlen(data)) { ret = FALSE; break; } @@ -303,7 +303,7 @@ rspamd_tls_check_common_name(X509 *cert, const char *name) common_name_len + 1); /* NUL bytes in CN? */ - if (common_name_len != (gint) strlen(common_name)) { + if (common_name_len != (int) strlen(common_name)) { goto out; } @@ -393,11 +393,11 @@ rspamd_ssl_peer_verify(struct rspamd_ssl_connection *c) } static void -rspamd_tls_set_error(gint retcode, const gchar *stage, GError **err) +rspamd_tls_set_error(int retcode, const char *stage, GError **err) { GString *reason; - gchar buf[120]; - gint err_code = 0; + char buf[120]; + int err_code = 0; reason = g_string_sized_new(sizeof(buf)); @@ -454,8 +454,8 @@ rspamd_ssl_connection_dtor(struct rspamd_ssl_connection *conn) static void rspamd_ssl_shutdown(struct rspamd_ssl_connection *conn) { - gint ret = 0, nret, retries; - static const gint max_retries = 5; + int ret = 0, nret, retries; + static const int max_retries = 5; /* * Fucking openssl... @@ -538,10 +538,10 @@ rspamd_ssl_shutdown(struct rspamd_ssl_connection *conn) } static void -rspamd_ssl_event_handler(gint fd, short what, gpointer ud) +rspamd_ssl_event_handler(int fd, short what, gpointer ud) { struct rspamd_ssl_connection *conn = ud; - gint ret; + int ret; GError *err = NULL; if (what == EV_TIMER) { @@ -633,7 +633,7 @@ rspamd_ssl_event_handler(gint fd, short what, gpointer ud) struct rspamd_ssl_connection * rspamd_ssl_connection_new(gpointer ssl_ctx, struct ev_loop *ev_base, - gboolean verify_peer, const gchar *log_tag) + gboolean verify_peer, const char *log_tag) { struct rspamd_ssl_connection *conn; struct rspamd_ssl_ctx *ctx = (struct rspamd_ssl_ctx *) ssl_ctx; @@ -657,12 +657,12 @@ rspamd_ssl_connection_new(gpointer ssl_ctx, struct ev_loop *ev_base, gboolean -rspamd_ssl_connect_fd(struct rspamd_ssl_connection *conn, gint fd, - const gchar *hostname, struct rspamd_io_ev *ev, ev_tstamp timeout, +rspamd_ssl_connect_fd(struct rspamd_ssl_connection *conn, int fd, + const char *hostname, struct rspamd_io_ev *ev, ev_tstamp timeout, rspamd_ssl_handler_t handler, rspamd_ssl_error_handler_t err_handler, gpointer handler_data) { - gint ret; + int ret; SSL_SESSION *session = NULL; g_assert(conn != NULL); @@ -689,7 +689,7 @@ rspamd_ssl_connect_fd(struct rspamd_ssl_connection *conn, gint fd, } /* We dup fd to allow graceful closing */ - gint nfd = dup(fd); + int nfd = dup(fd); if (nfd == -1) { return FALSE; @@ -775,7 +775,7 @@ gssize rspamd_ssl_read(struct rspamd_ssl_connection *conn, gpointer buf, gsize buflen) { - gint ret; + int ret; short what; GError *err = NULL; @@ -850,7 +850,7 @@ gssize rspamd_ssl_write(struct rspamd_ssl_connection *conn, gconstpointer buf, gsize buflen) { - gint ret; + int ret; short what; GError *err = NULL; @@ -927,8 +927,8 @@ rspamd_ssl_writev(struct rspamd_ssl_connection *conn, struct iovec *iov, * Static is needed to avoid issue: * https://github.com/openssl/openssl/issues/6865 */ - static guchar ssl_buf[16384]; - guchar *p; + static unsigned char ssl_buf[16384]; + unsigned char *p; struct iovec *cur; gsize i, remain; @@ -999,8 +999,8 @@ rspamd_init_ssl_ctx_common(void) { struct rspamd_ssl_ctx *ret; SSL_CTX *ssl_ctx; - gint ssl_options; - static const guint client_cache_size = 1024; + int ssl_options; + static const unsigned int client_cache_size = 1024; rspamd_openssl_maybe_init(); @@ -1080,7 +1080,7 @@ void rspamd_openssl_maybe_init(void) OPENSSL_config(NULL); #endif if (RAND_status() == 0) { - guchar seed[128]; + unsigned char seed[128]; /* Try to use ottery to seed rand */ ottery_rand_bytes(seed, sizeof(seed)); diff --git a/src/libserver/ssl_util.h b/src/libserver/ssl_util.h index cde7d47a8..862ad460f 100644 --- a/src/libserver/ssl_util.h +++ b/src/libserver/ssl_util.h @@ -26,7 +26,7 @@ extern "C" { struct rspamd_ssl_connection; -typedef void (*rspamd_ssl_handler_t)(gint fd, short what, gpointer d); +typedef void (*rspamd_ssl_handler_t)(int fd, short what, gpointer d); typedef void (*rspamd_ssl_error_handler_t)(gpointer d, GError *err); @@ -38,7 +38,7 @@ typedef void (*rspamd_ssl_error_handler_t)(gpointer d, GError *err); struct rspamd_ssl_connection *rspamd_ssl_connection_new(gpointer ssl_ctx, struct ev_loop *ev_base, gboolean verify_peer, - const gchar *log_tag); + const char *log_tag); /** * Connects SSL session using the specified (connected) FD @@ -51,8 +51,8 @@ struct rspamd_ssl_connection *rspamd_ssl_connection_new(gpointer ssl_ctx, * @param handler_data opaque data * @return TRUE if a session has been connected */ -gboolean rspamd_ssl_connect_fd(struct rspamd_ssl_connection *conn, gint fd, - const gchar *hostname, struct rspamd_io_ev *ev, ev_tstamp timeout, +gboolean rspamd_ssl_connect_fd(struct rspamd_ssl_connection *conn, int fd, + const char *hostname, struct rspamd_io_ev *ev, ev_tstamp timeout, rspamd_ssl_handler_t handler, rspamd_ssl_error_handler_t err_handler, gpointer handler_data); diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx index 5a5e60c95..1ffcd9ceb 100644 --- a/src/libserver/symcache/symcache_c.cxx +++ b/src/libserver/symcache/symcache_c.cxx @@ -58,13 +58,13 @@ void rspamd_symcache_save(struct rspamd_symcache *cache) real_cache->save_items(); } -gint rspamd_symcache_add_symbol(struct rspamd_symcache *cache, - const gchar *name, - gint priority, - symbol_func_t func, - gpointer user_data, - int type, - gint parent) +int rspamd_symcache_add_symbol(struct rspamd_symcache *cache, + const char *name, + int priority, + symbol_func_t func, + gpointer user_data, + int type, + int parent) { auto *real_cache = C_API_SYMCACHE(cache); @@ -110,7 +110,7 @@ bool rspamd_symcache_add_symbol_augmentation(struct rspamd_symcache *cache, return item->add_augmentation(*real_cache, augmentation, value); } -void rspamd_symcache_set_peak_callback(struct rspamd_symcache *cache, gint cbref) +void rspamd_symcache_set_peak_callback(struct rspamd_symcache *cache, int cbref) { auto *real_cache = C_API_SYMCACHE(cache); @@ -119,7 +119,7 @@ void rspamd_symcache_set_peak_callback(struct rspamd_symcache *cache, gint cbref gboolean rspamd_symcache_add_condition_delayed(struct rspamd_symcache *cache, - const gchar *sym, lua_State *L, gint cbref) + const char *sym, lua_State *L, int cbref) { auto *real_cache = C_API_SYMCACHE(cache); @@ -128,8 +128,8 @@ rspamd_symcache_add_condition_delayed(struct rspamd_symcache *cache, return TRUE; } -gint rspamd_symcache_find_symbol(struct rspamd_symcache *cache, - const gchar *name) +int rspamd_symcache_find_symbol(struct rspamd_symcache *cache, + const char *name) { auto *real_cache = C_API_SYMCACHE(cache); @@ -149,11 +149,11 @@ gint rspamd_symcache_find_symbol(struct rspamd_symcache *cache, gboolean rspamd_symcache_stat_symbol(struct rspamd_symcache *cache, - const gchar *name, - gdouble *frequency, - gdouble *freq_stddev, - gdouble *tm, - guint *nhits) + const char *name, + double *frequency, + double *freq_stddev, + double *tm, + unsigned int *nhits) { auto *real_cache = C_API_SYMCACHE(cache); @@ -175,7 +175,7 @@ rspamd_symcache_stat_symbol(struct rspamd_symcache *cache, } -guint rspamd_symcache_stats_symbols_count(struct rspamd_symcache *cache) +unsigned int rspamd_symcache_stats_symbols_count(struct rspamd_symcache *cache) { auto *real_cache = C_API_SYMCACHE(cache); return real_cache->get_stats_symbols_count(); @@ -225,15 +225,15 @@ void rspamd_symcache_inc_frequency(struct rspamd_symcache *cache, struct rspamd_ } void rspamd_symcache_add_delayed_dependency(struct rspamd_symcache *cache, - const gchar *from, const gchar *to) + const char *from, const char *to) { auto *real_cache = C_API_SYMCACHE(cache); real_cache->add_delayed_dependency(from, to); } -const gchar * +const char * rspamd_symcache_get_parent(struct rspamd_symcache *cache, - const gchar *symbol) + const char *symbol) { auto *real_cache = C_API_SYMCACHE(cache); @@ -250,7 +250,7 @@ rspamd_symcache_get_parent(struct rspamd_symcache *cache, return nullptr; } -const gchar * +const char * rspamd_symcache_item_name(struct rspamd_symcache_item *item) { auto *real_item = C_API_SYMCACHE_ITEM(item); @@ -262,7 +262,7 @@ rspamd_symcache_item_name(struct rspamd_symcache_item *item) return real_item->get_name().c_str(); } -gint rspamd_symcache_item_flags(struct rspamd_symcache_item *item) +int rspamd_symcache_item_flags(struct rspamd_symcache_item *item) { auto *real_item = C_API_SYMCACHE_ITEM(item); @@ -274,7 +274,7 @@ gint rspamd_symcache_item_flags(struct rspamd_symcache_item *item) } -const gchar * +const char * rspamd_symcache_dyn_item_name(struct rspamd_task *task, struct rspamd_symcache_dynamic_item *dyn_item) { @@ -290,8 +290,8 @@ rspamd_symcache_dyn_item_name(struct rspamd_task *task, return static_item->get_name().c_str(); } -gint rspamd_symcache_item_flags(struct rspamd_task *task, - struct rspamd_symcache_dynamic_item *dyn_item) +int rspamd_symcache_item_flags(struct rspamd_task *task, + struct rspamd_symcache_dynamic_item *dyn_item) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(dyn_item); @@ -305,8 +305,8 @@ gint rspamd_symcache_item_flags(struct rspamd_task *task, return static_item->get_flags(); } -guint rspamd_symcache_get_symbol_flags(struct rspamd_symcache *cache, - const gchar *symbol) +unsigned int rspamd_symcache_get_symbol_flags(struct rspamd_symcache *cache, + const char *symbol) { auto *real_cache = C_API_SYMCACHE(cache); @@ -327,7 +327,7 @@ rspamd_symcache_item_stat(struct rspamd_symcache_item *item) } void rspamd_symcache_get_symbol_details(struct rspamd_symcache *cache, - const gchar *symbol, + const char *symbol, ucl_object_t *this_sym_ucl) { auto *real_cache = C_API_SYMCACHE(cache); @@ -361,9 +361,9 @@ void rspamd_symcache_process_settings_elt(struct rspamd_symcache *cache, } bool rspamd_symcache_set_allowed_settings_ids(struct rspamd_symcache *cache, - const gchar *symbol, + const char *symbol, const uint32_t *ids, - guint nids) + unsigned int nids) { auto *real_cache = C_API_SYMCACHE(cache); @@ -378,9 +378,9 @@ bool rspamd_symcache_set_allowed_settings_ids(struct rspamd_symcache *cache, } bool rspamd_symcache_set_forbidden_settings_ids(struct rspamd_symcache *cache, - const gchar *symbol, + const char *symbol, const uint32_t *ids, - guint nids) + unsigned int nids) { auto *real_cache = C_API_SYMCACHE(cache); @@ -396,8 +396,8 @@ bool rspamd_symcache_set_forbidden_settings_ids(struct rspamd_symcache *cache, const uint32_t * rspamd_symcache_get_allowed_settings_ids(struct rspamd_symcache *cache, - const gchar *symbol, - guint *nids) + const char *symbol, + unsigned int *nids) { auto *real_cache = C_API_SYMCACHE(cache); @@ -407,8 +407,8 @@ rspamd_symcache_get_allowed_settings_ids(struct rspamd_symcache *cache, const uint32_t * rspamd_symcache_get_forbidden_settings_ids(struct rspamd_symcache *cache, - const gchar *symbol, - guint *nids) + const char *symbol, + unsigned int *nids) { auto *real_cache = C_API_SYMCACHE(cache); @@ -418,7 +418,7 @@ rspamd_symcache_get_forbidden_settings_ids(struct rspamd_symcache *cache, void rspamd_symcache_disable_all_symbols(struct rspamd_task *task, struct rspamd_symcache *_cache, - guint skip_mask) + unsigned int skip_mask) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); @@ -428,7 +428,7 @@ void rspamd_symcache_disable_all_symbols(struct rspamd_task *task, gboolean rspamd_symcache_disable_symbol(struct rspamd_task *task, struct rspamd_symcache *cache, - const gchar *symbol) + const char *symbol) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); auto *real_cache = C_API_SYMCACHE(cache); @@ -443,7 +443,7 @@ rspamd_symcache_disable_symbol(struct rspamd_task *task, gboolean rspamd_symcache_enable_symbol(struct rspamd_task *task, struct rspamd_symcache *cache, - const gchar *symbol) + const char *symbol) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); auto *real_cache = C_API_SYMCACHE(cache); @@ -456,7 +456,7 @@ rspamd_symcache_enable_symbol(struct rspamd_task *task, } void rspamd_symcache_disable_symbol_static(struct rspamd_symcache *cache, - const gchar *symbol) + const char *symbol) { auto *real_cache = C_API_SYMCACHE(cache); @@ -464,7 +464,7 @@ void rspamd_symcache_disable_symbol_static(struct rspamd_symcache *cache, } void rspamd_symcache_enable_symbol_static(struct rspamd_symcache *cache, - const gchar *symbol) + const char *symbol) { auto *real_cache = C_API_SYMCACHE(cache); @@ -499,7 +499,7 @@ void rspamd_symcache_timeout_result_free(struct rspamd_symcache_timeout_result * gboolean rspamd_symcache_is_checked(struct rspamd_task *task, struct rspamd_symcache *cache, - const gchar *symbol) + const char *symbol) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); auto *real_cache = C_API_SYMCACHE(cache); @@ -542,7 +542,7 @@ rspamd_symcache_is_item_allowed(struct rspamd_task *task, gboolean rspamd_symcache_is_symbol_enabled(struct rspamd_task *task, struct rspamd_symcache *cache, - const gchar *symbol) + const char *symbol) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); auto *real_cache = C_API_SYMCACHE(cache); @@ -589,10 +589,10 @@ void rspamd_symcache_enable_profile(struct rspamd_task *task) cache_runtime->set_profile_mode(true); } -guint rspamd_symcache_item_async_inc_full(struct rspamd_task *task, - struct rspamd_symcache_dynamic_item *item, - const gchar *subsystem, - const gchar *loc) +unsigned int rspamd_symcache_item_async_inc_full(struct rspamd_task *task, + struct rspamd_symcache_dynamic_item *item, + const char *subsystem, + const char *loc) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(item); @@ -606,10 +606,10 @@ guint rspamd_symcache_item_async_inc_full(struct rspamd_task *task, return ++real_dyn_item->async_events; } -guint rspamd_symcache_item_async_dec_full(struct rspamd_task *task, - struct rspamd_symcache_dynamic_item *item, - const gchar *subsystem, - const gchar *loc) +unsigned int rspamd_symcache_item_async_dec_full(struct rspamd_task *task, + struct rspamd_symcache_dynamic_item *item, + const char *subsystem, + const char *loc) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(item); @@ -635,8 +635,8 @@ guint rspamd_symcache_item_async_dec_full(struct rspamd_task *task, gboolean rspamd_symcache_item_async_dec_check_full(struct rspamd_task *task, struct rspamd_symcache_dynamic_item *item, - const gchar *subsystem, - const gchar *loc) + const char *subsystem, + const char *loc) { if (rspamd_symcache_item_async_dec_full(task, item, subsystem, loc) == 0) { rspamd_symcache_finalize_item(task, item); @@ -649,7 +649,7 @@ rspamd_symcache_item_async_dec_check_full(struct rspamd_task *task, struct rspamd_abstract_callback_data * rspamd_symcache_get_cbdata(struct rspamd_symcache *cache, - const gchar *symbol) + const char *symbol) { auto *real_cache = C_API_SYMCACHE(cache); @@ -687,7 +687,7 @@ void rspamd_symcache_composites_foreach(struct rspamd_task *task, gboolean rspamd_symcache_process_symbols(struct rspamd_task *task, struct rspamd_symcache *cache, - guint stage) + unsigned int stage) { auto *real_cache = C_API_SYMCACHE(cache); diff --git a/src/libserver/symcache/symcache_impl.cxx b/src/libserver/symcache/symcache_impl.cxx index b4236c978..869e025b3 100644 --- a/src/libserver/symcache/symcache_impl.cxx +++ b/src/libserver/symcache/symcache_impl.cxx @@ -249,7 +249,7 @@ auto symcache::load_items() -> bool } - if (cached_map->get_size() < (gint) sizeof(symcache_header)) { + if (cached_map->get_size() < (int) sizeof(symcache_header)) { msg_info_cache("cannot use file %s, truncated: %z", cfg->cache_filename, errno, strerror(errno)); return false; @@ -531,7 +531,7 @@ auto symcache::get_item_by_name_mut(std::string_view name, bool resolve_parent) auto symcache::add_dependency(int id_from, std::string_view to, int virtual_id_from) -> void { - g_assert(id_from >= 0 && id_from < (gint) items_by_id.size()); + g_assert(id_from >= 0 && id_from < (int) items_by_id.size()); const auto &source = items_by_id[id_from]; g_assert(source.get() != nullptr); @@ -542,7 +542,7 @@ auto symcache::add_dependency(int id_from, std::string_view to, int virtual_id_f if (virtual_id_from >= 0) { - g_assert(virtual_id_from < (gint) items_by_id.size()); + g_assert(virtual_id_from < (int) items_by_id.size()); /* We need that for settings id propagation */ const auto &vsource = items_by_id[virtual_id_from]; g_assert(vsource.get() != nullptr); diff --git a/src/libserver/symcache/symcache_runtime.cxx b/src/libserver/symcache/symcache_runtime.cxx index d9622d8a2..15f970d8c 100644 --- a/src/libserver/symcache/symcache_runtime.cxx +++ b/src/libserver/symcache/symcache_runtime.cxx @@ -678,7 +678,7 @@ rspamd_delayed_timer_dtor(gpointer d) auto symcache_runtime::finalize_item(struct rspamd_task *task, cache_dynamic_item *dyn_item) -> void { /* Limit to consider a rule as slow (in milliseconds) */ - constexpr const gdouble slow_diff_limit = 300; + constexpr const double slow_diff_limit = 300; auto *item = get_item_by_dynamic_item(dyn_item); /* Sanity checks */ g_assert(items_inflight > 0); diff --git a/src/libserver/task.c b/src/libserver/task.c index 4518477fc..13f4fa1e6 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -70,7 +70,7 @@ rspamd_task_new(struct rspamd_worker *worker, { struct rspamd_task *new_task; rspamd_mempool_t *task_pool; - guint flags = 0; + unsigned int flags = 0; if (pool == NULL) { task_pool = rspamd_mempool_new(rspamd_mempool_suggest_size(), @@ -173,8 +173,8 @@ rspamd_task_fin(void *arg) void rspamd_task_free(struct rspamd_task *task) { struct rspamd_email_address *addr; - static guint free_iters = 0; - guint i; + static unsigned int free_iters = 0; + unsigned int i; if (task) { debug_task("free pointer %p", task); @@ -253,7 +253,7 @@ void rspamd_task_free(struct rspamd_task *task) /* Perform more expensive cleanup cycle */ gsize allocated = 0, active = 0, metadata = 0, resident = 0, mapped = 0, old_lua_mem = 0; - gdouble t1, t2; + double t1, t2; old_lua_mem = lua_gc(task->cfg->lua_state, LUA_GCCOUNT, 0); t1 = rspamd_get_ticks(FALSE); @@ -280,7 +280,7 @@ void rspamd_task_free(struct rspamd_task *task) old_lua_mem, lua_gc(task->cfg->lua_state, LUA_GCCOUNT, 0), (t2 - t1) * 1000.0); free_iters = rspamd_time_jitter(0, - (gdouble) task->cfg->full_gc_iters / 2); + (double) task->cfg->full_gc_iters / 2); } REF_RELEASE(task->cfg); @@ -307,7 +307,7 @@ void rspamd_task_free(struct rspamd_task *task) struct rspamd_task_map { gpointer begin; gulong len; - gint fd; + int fd; }; static void @@ -321,19 +321,19 @@ rspamd_task_unmapper(gpointer ud) gboolean rspamd_task_load_message(struct rspamd_task *task, - struct rspamd_http_message *msg, const gchar *start, gsize len) + struct rspamd_http_message *msg, const char *start, gsize len) { - guint control_len, r; + unsigned int control_len, r; struct ucl_parser *parser; ucl_object_t *control_obj; - gchar filepath[PATH_MAX], *fp; - gint fd, flen; + char filepath[PATH_MAX], *fp; + int fd, flen; gulong offset = 0, shmem_size = 0; rspamd_ftok_t *tok; gpointer map; struct stat st; struct rspamd_task_map *m; - const gchar *ft; + const char *ft; #ifdef HAVE_SANE_SHMEM ft = "shm"; @@ -425,7 +425,7 @@ rspamd_task_load_message(struct rspamd_task *task, } } - task->msg.begin = ((guchar *) map) + offset; + task->msg.begin = ((unsigned char *) map) + offset; task->msg.len = shmem_size; m = rspamd_mempool_alloc(task->task_pool, sizeof(*m)); m->begin = map; @@ -532,7 +532,7 @@ rspamd_task_load_message(struct rspamd_task *task, ZSTD_DStream *zstream; ZSTD_inBuffer zin; ZSTD_outBuffer zout; - guchar *out; + unsigned char *out; gsize outlen, r; gulong dict_id; @@ -665,10 +665,10 @@ rspamd_task_load_message(struct rspamd_task *task, return TRUE; } -static guint -rspamd_task_select_processing_stage(struct rspamd_task *task, guint stages) +static unsigned int +rspamd_task_select_processing_stage(struct rspamd_task *task, unsigned int stages) { - guint st, mask; + unsigned int st, mask; mask = task->processed_stages; @@ -697,9 +697,9 @@ rspamd_task_select_processing_stage(struct rspamd_task *task, guint stages) } gboolean -rspamd_task_process(struct rspamd_task *task, guint stages) +rspamd_task_process(struct rspamd_task *task, unsigned int stages) { - guint st; + unsigned int st; gboolean ret = TRUE, all_done = TRUE; GError *stat_error = NULL; @@ -884,11 +884,11 @@ rspamd_task_get_sender(struct rspamd_task *task) return task->from_envelope; } -static const gchar * +static const char * rspamd_task_cache_principal_recipient(struct rspamd_task *task, - const gchar *rcpt, gsize len) + const char *rcpt, gsize len) { - gchar *rcpt_lc; + char *rcpt_lc; if (rcpt == NULL) { return NULL; @@ -904,12 +904,12 @@ rspamd_task_cache_principal_recipient(struct rspamd_task *task, return rcpt_lc; } -const gchar * +const char * rspamd_task_get_principal_recipient(struct rspamd_task *task) { - const gchar *val; + const char *val; struct rspamd_email_address *addr; - guint i; + unsigned int i; val = rspamd_mempool_get_variable(task->task_pool, RSPAMD_MEMPOOL_PRINCIPAL_RECIPIENT); @@ -950,7 +950,7 @@ rspamd_task_get_principal_recipient(struct rspamd_task *task) gboolean rspamd_learn_task_spam(struct rspamd_task *task, gboolean is_spam, - const gchar *classifier, + const char *classifier, GError **err) { if (is_spam) { @@ -1043,12 +1043,12 @@ rspamd_task_log_check_condition(struct rspamd_task *task, /* * Sort by symbol's score -> name */ -static gint +static int rspamd_task_compare_log_sym(gconstpointer a, gconstpointer b) { const struct rspamd_symbol_result *s1 = *(const struct rspamd_symbol_result **) a, *s2 = *(const struct rspamd_symbol_result **) b; - gdouble w1, w2; + double w1, w2; w1 = fabs(s1->score); @@ -1061,7 +1061,7 @@ rspamd_task_compare_log_sym(gconstpointer a, gconstpointer b) return (w2 - w1) * 1000.0; } -static gint +static int rspamd_task_compare_log_group(gconstpointer a, gconstpointer b) { const struct rspamd_symbols_group *s1 = *(const struct rspamd_symbols_group **) a, @@ -1075,7 +1075,7 @@ static rspamd_ftok_t rspamd_task_log_metric_res(struct rspamd_task *task, struct rspamd_log_format *lf) { - static gchar scorebuf[32]; + static char scorebuf[32]; rspamd_ftok_t res = {.begin = NULL, .len = 0}; struct rspamd_scan_result *mres; gboolean first = TRUE; @@ -1084,9 +1084,9 @@ rspamd_task_log_metric_res(struct rspamd_task *task, GPtrArray *sorted_symbols; struct rspamd_action *act; struct rspamd_symbols_group *gr; - guint i, j; + unsigned int i, j; khiter_t k; - guint max_log_elts = task->cfg->log_task_max_elts; + unsigned int max_log_elts = task->cfg->log_task_max_elts; mres = task->result; act = rspamd_check_action_metric(task, NULL, NULL); @@ -1152,7 +1152,7 @@ rspamd_task_log_metric_res(struct rspamd_task *task, DL_FOREACH(sym->opts_head, opt) { rspamd_printf_fstring(&symbuf, "%*s;", - (gint) opt->optlen, opt->option); + (int) opt->optlen, opt->option); if (j >= max_log_elts && opt->next) { rspamd_printf_fstring(&symbuf, "...;"); @@ -1237,7 +1237,7 @@ rspamd_task_log_write_var(struct rspamd_task *task, rspamd_fstring_t *logbuf, const rspamd_ftok_t *var, const rspamd_ftok_t *content) { rspamd_fstring_t *res = logbuf; - const gchar *p, *c, *end; + const char *p, *c, *end; if (content == NULL) { /* Just output variable */ @@ -1274,16 +1274,16 @@ rspamd_task_log_write_var(struct rspamd_task *task, rspamd_fstring_t *logbuf, static rspamd_fstring_t * rspamd_task_write_ialist(struct rspamd_task *task, - GPtrArray *addrs, gint lim, + GPtrArray *addrs, int lim, struct rspamd_log_format *lf, rspamd_fstring_t *logbuf) { rspamd_fstring_t *res = logbuf, *varbuf; rspamd_ftok_t var = {.begin = NULL, .len = 0}; struct rspamd_email_address *addr; - gint i, nchars = 0, wr = 0, cur_chars; + int i, nchars = 0, wr = 0, cur_chars; gboolean has_orig = FALSE; - guint max_log_elts = task->cfg->log_task_max_elts; + unsigned int max_log_elts = task->cfg->log_task_max_elts; if (addrs && lim <= 0) { lim = addrs->len; @@ -1344,15 +1344,15 @@ rspamd_task_write_ialist(struct rspamd_task *task, static rspamd_fstring_t * rspamd_task_write_addr_list(struct rspamd_task *task, - GPtrArray *addrs, gint lim, + GPtrArray *addrs, int lim, struct rspamd_log_format *lf, rspamd_fstring_t *logbuf) { rspamd_fstring_t *res = logbuf, *varbuf; rspamd_ftok_t var = {.begin = NULL, .len = 0}; struct rspamd_email_address *addr; - guint max_log_elts = task->cfg->log_task_max_elts; - guint i; + unsigned int max_log_elts = task->cfg->log_task_max_elts; + unsigned int i; if (lim <= 0) { lim = addrs->len; @@ -1396,8 +1396,8 @@ rspamd_task_log_variable(struct rspamd_task *task, { rspamd_fstring_t *res = logbuf; rspamd_ftok_t var = {.begin = NULL, .len = 0}; - static gchar numbuf[128]; - static const gchar undef[] = "undef"; + static char numbuf[128]; + static const char undef[] = "undef"; switch (lf->type) { /* String vars */ @@ -1508,7 +1508,7 @@ rspamd_task_log_variable(struct rspamd_task *task, case RSPAMD_LOG_DIGEST: if (task->message) { var.len = rspamd_snprintf(numbuf, sizeof(numbuf), "%*xs", - (gint) sizeof(MESSAGE_FIELD(task, digest)), + (int) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest)); var.begin = numbuf; } @@ -1593,7 +1593,7 @@ void rspamd_task_write_log(struct rspamd_task *task) rspamd_fstring_t *logbuf; struct rspamd_log_format *lf; struct rspamd_task **ptask; - const gchar *lua_str; + const char *lua_str; gsize lua_str_len; lua_State *L; @@ -1652,7 +1652,7 @@ void rspamd_task_write_log(struct rspamd_task *task) rspamd_fstring_free(logbuf); } -gdouble +double rspamd_task_get_required_score(struct rspamd_task *task, struct rspamd_scan_result *m) { if (m == NULL) { @@ -1663,7 +1663,7 @@ rspamd_task_get_required_score(struct rspamd_task *task, struct rspamd_scan_resu } } - for (guint i = m->nactions; i-- > 0;) { + for (unsigned int i = m->nactions; i-- > 0;) { struct rspamd_action_config *action_lim = &m->actions_config[i]; @@ -1678,7 +1678,7 @@ rspamd_task_get_required_score(struct rspamd_task *task, struct rspamd_scan_resu rspamd_ftok_t * rspamd_task_get_request_header(struct rspamd_task *task, - const gchar *name) + const char *name) { struct rspamd_request_header_chain *ret = rspamd_task_get_request_header_multiple(task, name); @@ -1692,13 +1692,13 @@ rspamd_task_get_request_header(struct rspamd_task *task, struct rspamd_request_header_chain * rspamd_task_get_request_header_multiple(struct rspamd_task *task, - const gchar *name) + const char *name) { struct rspamd_request_header_chain *ret = NULL; rspamd_ftok_t srch; khiter_t k; - srch.begin = (gchar *) name; + srch.begin = (char *) name; srch.len = strlen(name); k = kh_get(rspamd_req_headers_hash, task->request_headers, @@ -1717,7 +1717,7 @@ void rspamd_task_add_request_header(struct rspamd_task *task, { khiter_t k; - gint res; + int res; struct rspamd_request_header_chain *chain, *nchain; k = kh_put(rspamd_req_headers_hash, task->request_headers, @@ -1743,11 +1743,11 @@ void rspamd_task_add_request_header(struct rspamd_task *task, } -void rspamd_task_profile_set(struct rspamd_task *task, const gchar *key, - gdouble value) +void rspamd_task_profile_set(struct rspamd_task *task, const char *key, + double value) { GHashTable *tbl; - gdouble *pval; + double *pval; if (key == NULL) { return; @@ -1773,11 +1773,11 @@ void rspamd_task_profile_set(struct rspamd_task *task, const gchar *key, } } -gdouble * -rspamd_task_profile_get(struct rspamd_task *task, const gchar *key) +double * +rspamd_task_profile_get(struct rspamd_task *task, const char *key) { GHashTable *tbl; - gdouble *pval = NULL; + double *pval = NULL; tbl = rspamd_mempool_get_variable(task->task_pool, RSPAMD_MEMPOOL_PROFILE); @@ -1801,10 +1801,10 @@ rspamd_task_set_finish_time(struct rspamd_task *task) return FALSE; } -const gchar * +const char * rspamd_task_stage_name(enum rspamd_task_stage stg) { - const gchar *ret = "unknown stage"; + const char *ret = "unknown stage"; switch (stg) { case RSPAMD_TASK_STAGE_CONNECT: @@ -1937,7 +1937,7 @@ void rspamd_task_timeout(EV_P_ ev_timer *w, int revents) void rspamd_worker_guard_handler(EV_P_ ev_io *w, int revents) { struct rspamd_task *task = (struct rspamd_task *) w->data; - gchar fake_buf[1024]; + char fake_buf[1024]; gssize r; r = read(w->fd, fake_buf, sizeof(fake_buf)); diff --git a/src/libserver/task.h b/src/libserver/task.h index 8d4fa1b23..cba9bbbd4 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -145,9 +145,9 @@ enum rspamd_newlines_type; struct rspamd_message; struct rspamd_task_data_storage { - const gchar *begin; + const char *begin; gsize len; - gchar *fpath; + char *fpath; }; struct rspamd_request_header_chain { @@ -158,8 +158,8 @@ struct rspamd_request_header_chain { __KHASH_TYPE(rspamd_req_headers_hash, rspamd_ftok_t *, struct rspamd_request_header_chain *); struct rspamd_lua_cached_entry { - gint ref; - guint id; + int ref; + unsigned int id; }; KHASH_INIT(rspamd_task_lua_cache, char *, struct rspamd_lua_cached_entry, 1, kh_str_hash_func, kh_str_hash_equal); @@ -170,18 +170,18 @@ KHASH_INIT(rspamd_task_lua_cache, char *, struct rspamd_lua_cached_entry, 1, kh_ struct rspamd_task { struct rspamd_worker *worker; /**< pointer to worker object */ enum rspamd_command cmd; /**< command */ - gint sock; /**< socket descriptor */ + int sock; /**< socket descriptor */ uint32_t dns_requests; /**< number of DNS requests per this task */ uint32_t flags; /**< Bit flags */ uint32_t protocol_flags; uint32_t processed_stages; /**< bits of stages that are processed */ - gchar *helo; /**< helo header value */ - gchar *queue_id; /**< queue id if specified */ + char *helo; /**< helo header value */ + char *queue_id; /**< queue id if specified */ rspamd_inet_addr_t *from_addr; /**< from addr for a task */ rspamd_inet_addr_t *client_addr; /**< address of connected socket */ - gchar *deliver_to; /**< address to deliver */ - gchar *auth_user; /**< SMTP authenticated user */ - const gchar *hostname; /**< hostname reported by MTA */ + char *deliver_to; /**< address to deliver */ + char *auth_user; /**< SMTP authenticated user */ + const char *hostname; /**< hostname reported by MTA */ khash_t(rspamd_req_headers_hash) * request_headers; /**< HTTP headers in a request */ struct rspamd_task_data_storage msg; /**< message buffer */ struct rspamd_http_connection *http_conn; /**< HTTP server connection */ @@ -218,7 +218,7 @@ struct rspamd_task { ucl_object_t *settings; /**< Settings applied to task */ struct rspamd_config_settings_elt *settings_elt; /**< preprocessed settings id elt */ - const gchar *classifier; /**< Classifier to learn (if needed) */ + const char *classifier; /**< Classifier to learn (if needed) */ struct rspamd_lang_detector *lang_det; /**< Languages detector */ struct rspamd_message *message; }; @@ -254,14 +254,14 @@ gboolean rspamd_task_fin(void *arg); */ gboolean rspamd_task_load_message(struct rspamd_task *task, struct rspamd_http_message *msg, - const gchar *start, gsize len); + const char *start, gsize len); /** * Process task * @param task task to process * @return task has been successfully parsed and processed */ -gboolean rspamd_task_process(struct rspamd_task *task, guint stages); +gboolean rspamd_task_process(struct rspamd_task *task, unsigned int stages); /** * Return address of sender or NULL @@ -278,7 +278,7 @@ struct rspamd_email_address *rspamd_task_get_sender(struct rspamd_task *task); * @param task * @return */ -const gchar *rspamd_task_get_principal_recipient(struct rspamd_task *task); +const char *rspamd_task_get_principal_recipient(struct rspamd_task *task); /** * Add a recipient for a task @@ -286,7 +286,7 @@ const gchar *rspamd_task_get_principal_recipient(struct rspamd_task *task); * @param rcpt string representation of recipient address * @return TRUE if an address has been parsed and added */ -gboolean rspamd_task_add_recipient(struct rspamd_task *task, const gchar *rcpt); +gboolean rspamd_task_add_recipient(struct rspamd_task *task, const char *rcpt); /** * Learn specified statfile with message in a task @@ -297,7 +297,7 @@ gboolean rspamd_task_add_recipient(struct rspamd_task *task, const gchar *rcpt); */ gboolean rspamd_learn_task_spam(struct rspamd_task *task, gboolean is_spam, - const gchar *classifier, + const char *classifier, GError **err); /** @@ -308,8 +308,8 @@ gboolean rspamd_learn_task_spam(struct rspamd_task *task, */ struct rspamd_scan_result; -gdouble rspamd_task_get_required_score(struct rspamd_task *task, - struct rspamd_scan_result *m); +double rspamd_task_get_required_score(struct rspamd_task *task, + struct rspamd_scan_result *m); /** * Returns the first header as value for a header @@ -318,7 +318,7 @@ gdouble rspamd_task_get_required_score(struct rspamd_task *task, * @return */ rspamd_ftok_t *rspamd_task_get_request_header(struct rspamd_task *task, - const gchar *name); + const char *name); /** * Returns all headers with the specific name @@ -328,7 +328,7 @@ rspamd_ftok_t *rspamd_task_get_request_header(struct rspamd_task *task, */ struct rspamd_request_header_chain *rspamd_task_get_request_header_multiple( struct rspamd_task *task, - const gchar *name); + const char *name); /** * Adds a new request header to task (name and value should be mapped to fstring) @@ -350,8 +350,8 @@ void rspamd_task_write_log(struct rspamd_task *task); * @param key * @param value */ -void rspamd_task_profile_set(struct rspamd_task *task, const gchar *key, - gdouble value); +void rspamd_task_profile_set(struct rspamd_task *task, const char *key, + double value); /** * Get value for a specific profiling key @@ -359,7 +359,7 @@ void rspamd_task_profile_set(struct rspamd_task *task, const gchar *key, * @param key * @return */ -gdouble *rspamd_task_profile_get(struct rspamd_task *task, const gchar *key); +double *rspamd_task_profile_get(struct rspamd_task *task, const char *key); /** * Sets finishing time for a task if not yet set @@ -373,7 +373,7 @@ gboolean rspamd_task_set_finish_time(struct rspamd_task *task); * @param stg * @return */ -const gchar *rspamd_task_stage_name(enum rspamd_task_stage stg); +const char *rspamd_task_stage_name(enum rspamd_task_stage stg); /* * Called on forced timeout diff --git a/src/libserver/url.c b/src/libserver/url.c index cf140f507..b0ece195b 100644 --- a/src/libserver/url.c +++ b/src/libserver/url.c @@ -28,14 +28,14 @@ #include typedef struct url_match_s { - const gchar *m_begin; + const char *m_begin; gsize m_len; - const gchar *pattern; - const gchar *prefix; - const gchar *newline_pos; - const gchar *prev_newline_pos; + const char *pattern; + const char *prefix; + const char *newline_pos; + const char *prev_newline_pos; gboolean add_prefix; - gchar st; + char st; } url_match_t; #define URL_MATCHER_FLAG_NOHTML (1u << 0u) @@ -47,7 +47,7 @@ struct url_callback_data; static const struct { enum rspamd_url_protocol proto; - const gchar *name; + const char *name; gsize len; } rspamd_url_protocols[] = { {.proto = PROTOCOL_FILE, @@ -75,58 +75,58 @@ static const struct { .name = NULL, .len = 0}}; struct url_matcher { - const gchar *pattern; - const gchar *prefix; + const char *pattern; + const char *prefix; gboolean (*start)(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); gboolean (*end)(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); - gint flags; + int flags; }; static gboolean url_file_start(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); static gboolean url_file_end(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); static gboolean url_web_start(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); static gboolean url_web_end(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); static gboolean url_tld_start(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); static gboolean url_tld_end(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); static gboolean url_email_start(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); static gboolean url_email_end(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); static gboolean url_tel_start(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); static gboolean url_tel_end(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match); struct url_matcher static_matchers[] = { @@ -173,9 +173,9 @@ struct url_matcher static_matchers[] = { 0}}; struct rspamd_url_flag_name { - const gchar *name; - gint flag; - gint hash; + const char *name; + int flag; + int hash; } url_flag_names[] = { {"phished", RSPAMD_URL_FLAG_PHISHED, -1}, {"numeric", RSPAMD_URL_FLAG_NUMERIC, -1}, @@ -220,19 +220,19 @@ __KHASH_IMPL(rspamd_url_host_hash, kh_inline, struct rspamd_url *, char, false, rspamd_url_host_hash, rspamd_urls_host_cmp); struct url_callback_data { - const gchar *begin; - gchar *url_str; + const char *begin; + char *url_str; rspamd_mempool_t *pool; - gint len; + int len; enum rspamd_url_find_type how; gboolean prefix_added; - guint newline_idx; + unsigned int newline_idx; GArray *matchers; GPtrArray *newlines; - const gchar *start; - const gchar *fin; - const gchar *end; - const gchar *last_at; + const char *start; + const char *fin; + const char *end; + const char *last_at; url_insert_function func; void *funcd; }; @@ -381,12 +381,12 @@ static const unsigned int url_scanner_table[256] = { IS_URLSAFE | IS_DOMAIN, IS_URLSAFE | IS_DOMAIN, IS_URLSAFE | IS_DOMAIN, IS_URLSAFE | IS_DOMAIN}; -#define is_lwsp(x) ((url_scanner_table[(guchar) (x)] & IS_LWSP) != 0) -#define is_mailsafe(x) ((url_scanner_table[(guchar) (x)] & (IS_MAILSAFE)) != 0) -#define is_domain(x) ((url_scanner_table[(guchar) (x)] & IS_DOMAIN) != 0) -#define is_urlsafe(x) ((url_scanner_table[(guchar) (x)] & (IS_URLSAFE)) != 0) +#define is_lwsp(x) ((url_scanner_table[(unsigned char) (x)] & IS_LWSP) != 0) +#define is_mailsafe(x) ((url_scanner_table[(unsigned char) (x)] & (IS_MAILSAFE)) != 0) +#define is_domain(x) ((url_scanner_table[(unsigned char) (x)] & IS_DOMAIN) != 0) +#define is_urlsafe(x) ((url_scanner_table[(unsigned char) (x)] & (IS_URLSAFE)) != 0) -const gchar * +const char * rspamd_url_strerror(int err) { switch (err) { @@ -414,15 +414,15 @@ rspamd_url_strerror(int err) } static gboolean -rspamd_url_parse_tld_file(const gchar *fname, +rspamd_url_parse_tld_file(const char *fname, struct url_match_scanner *scanner) { FILE *f; struct url_matcher m; - gchar *linebuf = NULL, *p; + char *linebuf = NULL, *p; gsize buflen = 0; gssize r; - gint flags; + int flags; f = fopen(fname, "r"); @@ -483,7 +483,7 @@ rspamd_url_parse_tld_file(const gchar *fname, static void rspamd_url_add_static_matchers(struct url_match_scanner *sc) { - gint n = G_N_ELEMENTS(static_matchers), i; + int n = G_N_ELEMENTS(static_matchers), i; for (i = 0; i < n; i++) { if (static_matchers[i].flags & URL_MATCHER_FLAG_REGEXP) { @@ -535,7 +535,7 @@ void rspamd_url_deinit(void) } } -void rspamd_url_init(const gchar *tld_file) +void rspamd_url_init(const char *tld_file) { GError *err = NULL; gboolean ret = TRUE; @@ -609,15 +609,15 @@ void rspamd_url_init(const gchar *tld_file) } /* Generate hashes for flags */ - for (gint i = 0; i < G_N_ELEMENTS(url_flag_names); i++) { + for (int i = 0; i < G_N_ELEMENTS(url_flag_names); i++) { url_flag_names[i].hash = rspamd_cryptobox_fast_hash_specific(RSPAMD_CRYPTOBOX_HASHFAST_INDEPENDENT, url_flag_names[i].name, strlen(url_flag_names[i].name), 0); } /* Ensure that we have no hashes collisions O(N^2) but this array is small */ - for (gint i = 0; i < G_N_ELEMENTS(url_flag_names) - 1; i++) { - for (gint j = i + 1; j < G_N_ELEMENTS(url_flag_names); j++) { + for (int i = 0; i < G_N_ELEMENTS(url_flag_names) - 1; i++) { + for (int j = i + 1; j < G_N_ELEMENTS(url_flag_names); j++) { if (url_flag_names[i].hash == url_flag_names[j].hash) { msg_err("collision: both %s and %s map to %d", url_flag_names[i].name, url_flag_names[j].name, @@ -638,7 +638,7 @@ void rspamd_url_init(const gchar *tld_file) } while (0) static bool -is_url_start(gchar c) +is_url_start(char c) { if (c == '(' || c == '{' || @@ -652,7 +652,7 @@ is_url_start(gchar c) } static bool -is_url_end(gchar c) +is_url_end(char c) { if (c == ')' || c == '}' || @@ -679,19 +679,19 @@ is_domain_start(int p) return FALSE; } -static const guint max_domain_length = 253; -static const guint max_dns_label = 63; -static const guint max_email_user = 64; +static const unsigned int max_domain_length = 253; +static const unsigned int max_dns_label = 63; +static const unsigned int max_email_user = 64; -static gint +static int rspamd_mailto_parse(struct http_parser_url *u, - const gchar *str, gsize len, - gchar const **end, - enum rspamd_url_parse_flags parse_flags, guint *flags) + const char *str, gsize len, + char const **end, + enum rspamd_url_parse_flags parse_flags, unsigned int *flags) { - const gchar *p = str, *c = str, *last = str + len; - gchar t; - gint ret = 1; + const char *p = str, *c = str, *last = str + len; + char t; + int ret = 1; enum { parse_mailto, parse_slash, @@ -871,12 +871,12 @@ out: return ret; } -static gint +static int rspamd_telephone_parse(struct http_parser_url *u, - const gchar *str, gsize len, - gchar const **end, + const char *str, gsize len, + char const **end, enum rspamd_url_parse_flags parse_flags, - guint *flags) + unsigned int *flags) { enum { parse_protocol, @@ -889,9 +889,9 @@ rspamd_telephone_parse(struct http_parser_url *u, parse_phone, } st = parse_protocol; - const gchar *p = str, *c = str, *last = str + len; - gchar t; - gint ret = 1, i; + const char *p = str, *c = str, *last = str + len; + char t; + int ret = 1, i; UChar32 uc; if (u != NULL) { @@ -1012,18 +1012,18 @@ out: return ret; } -static gint -rspamd_web_parse(struct http_parser_url *u, const gchar *str, gsize len, - gchar const **end, +static int +rspamd_web_parse(struct http_parser_url *u, const char *str, gsize len, + char const **end, enum rspamd_url_parse_flags parse_flags, - guint *flags) + unsigned int *flags) { - const gchar *p = str, *c = str, *last = str + len, *slash = NULL, - *password_start = NULL, *user_start = NULL; - gchar t = 0; + const char *p = str, *c = str, *last = str + len, *slash = NULL, + *password_start = NULL, *user_start = NULL; + char t = 0; UChar32 uc; glong pt; - gint ret = 1; + int ret = 1; gboolean user_seen = FALSE; enum { parse_protocol, @@ -1336,9 +1336,9 @@ rspamd_web_parse(struct http_parser_url *u, const gchar *str, gsize len, } else if (*p != '.' && *p != '-' && *p != '_' && *p != '%') { if (*p & 0x80) { - guint i = 0; + unsigned int i = 0; - U8_NEXT(((const guchar *) p), i, last - p, uc); + U8_NEXT(((const unsigned char *) p), i, last - p, uc); if (uc < 0) { /* Bad utf8 */ @@ -1393,7 +1393,7 @@ rspamd_web_parse(struct http_parser_url *u, const gchar *str, gsize len, break; case parse_port_password: if (g_ascii_isdigit(t)) { - const gchar *tmp = p; + const char *tmp = p; while (tmp < last) { if (!g_ascii_isdigit(*tmp)) { @@ -1648,19 +1648,19 @@ out: #undef SET_U -static gint +static int rspamd_tld_trie_callback(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, + unsigned int strnum, + int match_start, + int match_pos, + const char *text, gsize len, void *context) { struct url_matcher *matcher; - const gchar *start, *pos, *p; + const char *start, *pos, *p; struct rspamd_url *url = context; - gint ndots; + int ndots; matcher = &g_array_index(url_scanner->matchers_full, struct url_matcher, strnum); @@ -1675,9 +1675,9 @@ rspamd_tld_trie_callback(struct rspamd_multipattern *mp, p = pos - 1; start = rspamd_url_host_unsafe(url); - if (*pos != '.' || match_pos != (gint) url->hostlen) { + if (*pos != '.' || match_pos != (int) url->hostlen) { /* Something weird has been found */ - if (match_pos == (gint) url->hostlen - 1) { + if (match_pos == (int) url->hostlen - 1) { pos = rspamd_url_host_unsafe(url) + match_pos; if (*pos == '.') { /* This is dot at the end of domain */ @@ -1719,8 +1719,8 @@ static void rspamd_url_regen_from_inet_addr(struct rspamd_url *uri, const void *addr, int af, rspamd_mempool_t *pool) { - gchar *strbuf, *p; - const gchar *start_offset; + char *strbuf, *p; + const char *start_offset; gsize slen = uri->urllen - uri->hostlen; goffset r = 0; @@ -1738,7 +1738,7 @@ rspamd_url_regen_from_inet_addr(struct rspamd_url *uri, const void *addr, int af /* Allocate new string to build it from IP */ strbuf = rspamd_mempool_alloc(pool, slen + 1); r += rspamd_snprintf(strbuf + r, slen - r, "%*s", - (gint) (uri->hostshift), + (int) (uri->hostshift), uri->string); uri->hostshift = r; @@ -1761,7 +1761,7 @@ rspamd_url_regen_from_inet_addr(struct rspamd_url *uri, const void *addr, int af p = strbuf + r; start_offset = p + 1; r += rspamd_snprintf(strbuf + r, slen - r, "/%*s", - (gint) uri->datalen, + (int) uri->datalen, rspamd_url_data_unsafe(uri)); uri->datashift = start_offset - strbuf; } @@ -1777,7 +1777,7 @@ rspamd_url_regen_from_inet_addr(struct rspamd_url *uri, const void *addr, int af p = strbuf + r; start_offset = p + 1; r += rspamd_snprintf(strbuf + r, slen - r, "?%*s", - (gint) uri->querylen, + (int) uri->querylen, rspamd_url_query_unsafe(uri)); uri->queryshift = start_offset - strbuf; } @@ -1785,7 +1785,7 @@ rspamd_url_regen_from_inet_addr(struct rspamd_url *uri, const void *addr, int af p = strbuf + r; start_offset = p + 1; r += rspamd_snprintf(strbuf + r, slen - r, "#%*s", - (gint) uri->fragmentlen, + (int) uri->fragmentlen, rspamd_url_fragment_unsafe(uri)); uri->fragmentshift = start_offset - strbuf; } @@ -1797,8 +1797,8 @@ rspamd_url_regen_from_inet_addr(struct rspamd_url *uri, const void *addr, int af static gboolean rspamd_url_maybe_regenerate_from_ip(struct rspamd_url *uri, rspamd_mempool_t *pool) { - const gchar *p, *end, *c; - gchar *errstr; + const char *p, *end, *c; + char *errstr; struct in_addr in4; struct in6_addr in6; gboolean ret = FALSE, check_num = TRUE; @@ -1834,7 +1834,7 @@ rspamd_url_maybe_regenerate_from_ip(struct rspamd_url *uri, rspamd_mempool_t *po } else { /* Heuristics for broken urls */ - gchar buf[INET6_ADDRSTRLEN + 1]; + char buf[INET6_ADDRSTRLEN + 1]; /* Try also numeric notation */ c = p; n = 0; @@ -1844,7 +1844,7 @@ rspamd_url_maybe_regenerate_from_ip(struct rspamd_url *uri, rspamd_mempool_t *po while (p <= end && check_num) { if (shift < 32 && ((*p == '.' && dots < 3) || (p == end && dots <= 3))) { - if (p - c + 1 >= (gint) sizeof(buf)) { + if (p - c + 1 >= (int) sizeof(buf)) { msg_debug_pool("invalid numeric url %*.s...: too long", INET6_ADDRSTRLEN, c); return FALSE; @@ -1933,7 +1933,7 @@ rspamd_url_maybe_regenerate_from_ip(struct rspamd_url *uri, rspamd_mempool_t *po uri->flags |= RSPAMD_URL_FLAG_OBSCURED; ret = TRUE; } - else if (end - c > (gint) sizeof(buf) - 1) { + else if (end - c > (int) sizeof(buf) - 1) { rspamd_strlcpy(buf, c, end - c + 1); if (inet_pton(AF_INET6, buf, &in6) == 1) { @@ -1952,8 +1952,8 @@ static void rspamd_url_shift(struct rspamd_url *uri, gsize nlen, enum http_parser_url_fields field) { - guint old_shift, shift = 0; - gint remain; + unsigned int old_shift, shift = 0; + int remain; /* Shift remaining data */ switch (field) { @@ -2081,8 +2081,8 @@ rspamd_url_shift(struct rspamd_url *uri, gsize nlen, static void rspamd_telephone_normalise_inplace(struct rspamd_url *uri) { - gchar *t, *h, *end; - gint i = 0, w, orig_len; + char *t, *h, *end; + int i = 0, w, orig_len; UChar32 uc; t = rspamd_url_host_unsafe(uri); @@ -2141,10 +2141,10 @@ is_idna_label_dot(UChar ch) static bool rspamd_url_remove_dots(struct rspamd_url *uri) { - const gchar *hstart = rspamd_url_host_unsafe(uri); - gchar *t; + const char *hstart = rspamd_url_host_unsafe(uri); + char *t; UChar32 uc; - gint i = 0, hlen; + int i = 0, hlen; bool ret = false; if (uri->hostlen == 0) { @@ -2155,7 +2155,7 @@ rspamd_url_remove_dots(struct rspamd_url *uri) t = rspamd_url_host_unsafe(uri); while (i < hlen) { - gint prev_i = i; + int prev_i = i; U8_NEXT(hstart, i, hlen, uc); if (is_idna_label_dot(uc)) { @@ -2185,14 +2185,14 @@ rspamd_url_remove_dots(struct rspamd_url *uri) enum uri_errno rspamd_url_parse(struct rspamd_url *uri, - gchar *uristring, gsize len, + char *uristring, gsize len, rspamd_mempool_t *pool, enum rspamd_url_parse_flags parse_flags) { struct http_parser_url u; - gchar *p; - const gchar *end; - guint complen, ret, flags = 0; + char *p; + const char *end; + unsigned int complen, ret, flags = 0; gsize unquoted_len = 0; memset(uri, 0, sizeof(*uri)); @@ -2239,7 +2239,7 @@ rspamd_url_parse(struct rspamd_url *uri, return URI_ERRNO_BAD_FORMAT; } - if (end > uristring && (guint) (end - uristring) != len) { + if (end > uristring && (unsigned int) (end - uristring) != len) { len = end - uristring; } @@ -2269,9 +2269,9 @@ rspamd_url_parse(struct rspamd_url *uri, uri->urllen = len; uri->flags = flags; - for (guint i = 0; i < UF_MAX; i++) { + for (unsigned int i = 0; i < UF_MAX; i++) { if (u.field_set & (1 << i)) { - guint shift = u.field_data[i].off; + unsigned int shift = u.field_data[i].off; complen = u.field_data[i].len; if (complen >= G_MAXUINT16) { @@ -2341,7 +2341,7 @@ rspamd_url_parse(struct rspamd_url *uri, if (uri->protocol & (PROTOCOL_HTTP | PROTOCOL_HTTPS | PROTOCOL_MAILTO | PROTOCOL_FTP | PROTOCOL_FILE)) { /* Ensure that hostname starts with something sane (exclude numeric urls) */ - const gchar *host = rspamd_url_host_unsafe(uri); + const char *host = rspamd_url_host_unsafe(uri); if (!(is_domain_start(host[0]) || host[0] == ':')) { return URI_ERRNO_BAD_FORMAT; @@ -2535,8 +2535,8 @@ rspamd_url_parse(struct rspamd_url *uri, if (uri->protocol & (PROTOCOL_HTTP | PROTOCOL_HTTPS | PROTOCOL_FTP) && uri->protocollen > 0 && uri->urllen > uri->protocollen + 2) { - gchar *pos = &uri->string[uri->protocollen], - *host_start = rspamd_url_host_unsafe(uri); + char *pos = &uri->string[uri->protocollen], + *host_start = rspamd_url_host_unsafe(uri); while (pos < host_start) { if (*pos == '\\') { @@ -2575,24 +2575,24 @@ rspamd_url_parse(struct rspamd_url *uri, } struct tld_trie_cbdata { - const gchar *begin; + const char *begin; gsize len; rspamd_ftok_t *out; }; -static gint +static int rspamd_tld_trie_find_callback(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, + unsigned int strnum, + int match_start, + int match_pos, + const char *text, gsize len, void *context) { struct url_matcher *matcher; - const gchar *start, *pos, *p; + const char *start, *pos, *p; struct tld_trie_cbdata *cbdata = context; - gint ndots = 1; + int ndots = 1; matcher = &g_array_index(url_scanner->matchers_full, struct url_matcher, strnum); @@ -2606,9 +2606,9 @@ rspamd_tld_trie_find_callback(struct rspamd_multipattern *mp, p = pos - 1; start = text; - if (*pos != '.' || match_pos != (gint) cbdata->len) { + if (*pos != '.' || match_pos != (int) cbdata->len) { /* Something weird has been found */ - if (match_pos != (gint) cbdata->len - 1) { + if (match_pos != (int) cbdata->len - 1) { /* Search more */ return 0; } @@ -2640,7 +2640,7 @@ rspamd_tld_trie_find_callback(struct rspamd_multipattern *mp, } gboolean -rspamd_url_find_tld(const gchar *in, gsize inlen, rspamd_ftok_t *out) +rspamd_url_find_tld(const char *in, gsize inlen, rspamd_ftok_t *out) { struct tld_trie_cbdata cbdata; @@ -2665,7 +2665,7 @@ rspamd_url_find_tld(const gchar *in, gsize inlen, rspamd_ftok_t *out) return FALSE; } -static const gchar url_braces[] = { +static const char url_braces[] = { '(', ')', '{', '}', '[', ']', @@ -2676,7 +2676,7 @@ static const gchar url_braces[] = { static gboolean url_file_start(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match) { match->m_begin = pos; @@ -2693,12 +2693,12 @@ url_file_start(struct url_callback_data *cb, static gboolean url_file_end(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match) { - const gchar *p; - gchar stop; - guint i; + const char *p; + char stop; + unsigned int i; p = pos + strlen(match->pattern); stop = *p; @@ -2727,12 +2727,12 @@ url_file_end(struct url_callback_data *cb, static gboolean url_tld_start(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match) { - const gchar *p = pos; - guint processed = 0; - static const guint max_shift = 253 + sizeof("https://"); + const char *p = pos; + unsigned int processed = 0; + static const unsigned int max_shift = 253 + sizeof("https://"); /* Try to find the start of the url by finding any non-urlsafe character or whitespace/punctuation */ while (p >= cb->begin) { @@ -2795,10 +2795,10 @@ url_tld_start(struct url_callback_data *cb, static gboolean url_tld_end(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match) { - const gchar *p; + const char *p; gboolean ret = FALSE; p = pos + match->m_len; @@ -2843,7 +2843,7 @@ url_tld_end(struct url_callback_data *cb, static gboolean url_web_start(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match) { /* Check what we have found */ @@ -2858,7 +2858,7 @@ url_web_start(struct url_callback_data *cb, } } else { - guchar prev = *(pos - 1); + unsigned char prev = *(pos - 1); if (g_ascii_isalnum(prev)) { /* Part of another url */ @@ -2886,12 +2886,12 @@ url_web_start(struct url_callback_data *cb, static gboolean url_web_end(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match) { - const gchar *last = NULL; - gint len = cb->end - pos; - guint flags = 0; + const char *last = NULL; + int len = cb->end - pos; + unsigned int flags = 0; if (match->newline_pos && match->st != '<') { /* We should also limit our match end to the newline */ @@ -2926,7 +2926,7 @@ url_web_end(struct url_callback_data *cb, static gboolean url_email_start(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match) { if (!match->prefix || match->prefix[0] == '\0') { @@ -2961,13 +2961,13 @@ url_email_start(struct url_callback_data *cb, static gboolean url_email_end(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match) { - const gchar *last = NULL; + const char *last = NULL; struct http_parser_url u; - gint len = cb->end - pos; - guint flags = 0; + int len = cb->end - pos; + unsigned int flags = 0; if (match->newline_pos && match->st != '<') { /* We should also limit our match end to the newline */ @@ -2994,7 +2994,7 @@ url_email_end(struct url_callback_data *cb, return TRUE; } else { - const gchar *c, *p; + const char *c, *p; /* * Here we have just '@', so we need to find both start and end of the * pattern @@ -3060,7 +3060,7 @@ url_email_end(struct url_callback_data *cb, static gboolean url_tel_start(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match) { match->m_begin = pos; @@ -3077,13 +3077,13 @@ url_tel_start(struct url_callback_data *cb, static gboolean url_tel_end(struct url_callback_data *cb, - const gchar *pos, + const char *pos, url_match_t *match) { - const gchar *last = NULL; + const char *last = NULL; struct http_parser_url u; - gint len = cb->end - pos; - guint flags = 0; + int len = cb->end - pos; + unsigned int flags = 0; if (match->newline_pos && match->st != '<') { /* We should also limit our match end to the newline */ @@ -3106,8 +3106,8 @@ url_tel_end(struct url_callback_data *cb, static gboolean -rspamd_url_trie_is_match(struct url_matcher *matcher, const gchar *pos, - const gchar *end, const gchar *newline_pos) +rspamd_url_trie_is_match(struct url_matcher *matcher, const char *pos, + const char *end, const char *newline_pos) { if (matcher->flags & URL_MATCHER_FLAG_TLD_MATCH) { /* Immediately check pos for valid chars */ @@ -3134,18 +3134,18 @@ rspamd_url_trie_is_match(struct url_matcher *matcher, const gchar *pos, return TRUE; } -static gint +static int rspamd_url_trie_callback(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, + unsigned int strnum, + int match_start, + int match_pos, + const char *text, gsize len, void *context) { struct url_matcher *matcher; url_match_t m; - const gchar *pos, *newline_pos = NULL; + const char *pos, *newline_pos = NULL; struct url_callback_data *cb = context; pos = text + match_pos; @@ -3204,7 +3204,7 @@ rspamd_url_trie_callback(struct rspamd_multipattern *mp, cb->len + 1, "%s%*s", m.prefix, - (gint) m.m_len, + (int) m.m_len, m.m_begin); cb->prefix_added = TRUE; } @@ -3231,14 +3231,14 @@ rspamd_url_trie_callback(struct rspamd_multipattern *mp, gboolean rspamd_url_find(rspamd_mempool_t *pool, - const gchar *begin, gsize len, - gchar **url_str, + const char *begin, gsize len, + char **url_str, enum rspamd_url_find_type how, goffset *url_pos, gboolean *prefix_added) { struct url_callback_data cb; - gint ret; + int ret; memset(&cb, 0, sizeof(cb)); cb.begin = begin; @@ -3286,12 +3286,12 @@ rspamd_url_find(rspamd_mempool_t *pool, return FALSE; } -static gint +static int rspamd_url_trie_generic_callback_common(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, + unsigned int strnum, + int match_start, + int match_pos, + const char *text, gsize len, void *context, gboolean multiple) @@ -3299,9 +3299,9 @@ rspamd_url_trie_generic_callback_common(struct rspamd_multipattern *mp, struct rspamd_url *url; struct url_matcher *matcher; url_match_t m; - const gchar *pos, *newline_pos = NULL; + const char *pos, *newline_pos = NULL; struct url_callback_data *cb = context; - gint rc; + int rc; rspamd_mempool_t *pool; pos = text + match_pos; @@ -3363,7 +3363,7 @@ rspamd_url_trie_generic_callback_common(struct rspamd_multipattern *mp, cb->len + 1, "%s%*s", m.prefix, - (gint) m.m_len, + (int) m.m_len, m.m_begin); cb->prefix_added = TRUE; } @@ -3414,12 +3414,12 @@ rspamd_url_trie_generic_callback_common(struct rspamd_multipattern *mp, return !multiple; } -static gint +static int rspamd_url_trie_generic_callback_multiple(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, + unsigned int strnum, + int match_start, + int match_pos, + const char *text, gsize len, void *context) { @@ -3427,12 +3427,12 @@ rspamd_url_trie_generic_callback_multiple(struct rspamd_multipattern *mp, match_pos, text, len, context, TRUE); } -static gint +static int rspamd_url_trie_generic_callback_single(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, + unsigned int strnum, + int match_start, + int match_pos, + const char *text, gsize len, void *context) { @@ -3468,7 +3468,7 @@ rspamd_url_query_callback(struct rspamd_url *url, gsize start_offset, if (kh_size(MESSAGE_FIELD(task, urls)) > cbd->task->cfg->max_urls) { msg_err_task("part has too many URLs, we cannot process more: " "%d urls extracted ", - (guint) kh_size(MESSAGE_FIELD(task, urls))); + (unsigned int) kh_size(MESSAGE_FIELD(task, urls))); return FALSE; } @@ -3531,7 +3531,7 @@ rspamd_url_text_part_callback(struct rspamd_url *url, gsize start_offset, if (kh_size(MESSAGE_FIELD(task, urls)) > cbd->task->cfg->max_urls) { msg_err_task("part has too many URLs, we cannot process more: " "%d urls extracted ", - (guint) kh_size(MESSAGE_FIELD(task, urls))); + (unsigned int) kh_size(MESSAGE_FIELD(task, urls))); return FALSE; } @@ -3589,7 +3589,7 @@ void rspamd_url_text_extract(rspamd_mempool_t *pool, } void rspamd_url_find_multiple(rspamd_mempool_t *pool, - const gchar *in, + const char *in, gsize inlen, enum rspamd_url_find_type how, GPtrArray *nlines, @@ -3637,7 +3637,7 @@ void rspamd_url_find_multiple(rspamd_mempool_t *pool, } void rspamd_url_find_single(rspamd_mempool_t *pool, - const gchar *in, + const char *in, gsize inlen, enum rspamd_url_find_type how, url_insert_function func, @@ -3697,9 +3697,9 @@ rspamd_url_task_subject_callback(struct rspamd_url *url, gsize start_offset, gsize end_offset, gpointer ud) { struct rspamd_task *task = ud; - gchar *url_str = NULL; + char *url_str = NULL; struct rspamd_url *query_url; - gint rc; + int rc; gboolean prefix_added; /* It is just a displayed URL, we should not check it for certain things */ @@ -3778,7 +3778,7 @@ rspamd_url_host_hash(struct rspamd_url *url) static inline bool rspamd_emails_cmp(struct rspamd_url *u1, struct rspamd_url *u2) { - gint r; + int r; if (u1->hostlen != u2->hostlen || u1->hostlen == 0) { return FALSE; @@ -3838,10 +3838,10 @@ rspamd_urls_host_cmp(struct rspamd_url *u1, struct rspamd_url *u2) return r == 0; } -gsize rspamd_url_decode(gchar *dst, const gchar *src, gsize size) +gsize rspamd_url_decode(char *dst, const char *src, gsize size) { - gchar *d, ch, c, decoded; - const gchar *s; + char *d, ch, c, decoded; + const char *s; enum { sw_usual = 0, sw_quoted, @@ -3992,36 +3992,36 @@ static const unsigned char rspamd_url_encoding_classes[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -#define CHECK_URL_COMPONENT(beg, len, flags) \ - do { \ - for (i = 0; i < (len); i++) { \ - if ((rspamd_url_encoding_classes[(guchar) (beg)[i]] & (flags)) == 0) { \ - dlen += 2; \ - } \ - } \ +#define CHECK_URL_COMPONENT(beg, len, flags) \ + do { \ + for (i = 0; i < (len); i++) { \ + if ((rspamd_url_encoding_classes[(unsigned char) (beg)[i]] & (flags)) == 0) { \ + dlen += 2; \ + } \ + } \ } while (0) -#define ENCODE_URL_COMPONENT(beg, len, flags) \ - do { \ - for (i = 0; i < (len) && dend > d; i++) { \ - if ((rspamd_url_encoding_classes[(guchar) (beg)[i]] & (flags)) == 0) { \ - *d++ = '%'; \ - *d++ = hexdigests[(guchar) ((beg)[i] >> 4) & 0xf]; \ - *d++ = hexdigests[(guchar) (beg)[i] & 0xf]; \ - } \ - else { \ - *d++ = (beg)[i]; \ - } \ - } \ +#define ENCODE_URL_COMPONENT(beg, len, flags) \ + do { \ + for (i = 0; i < (len) && dend > d; i++) { \ + if ((rspamd_url_encoding_classes[(unsigned char) (beg)[i]] & (flags)) == 0) { \ + *d++ = '%'; \ + *d++ = hexdigests[(unsigned char) ((beg)[i] >> 4) & 0xf]; \ + *d++ = hexdigests[(unsigned char) (beg)[i] & 0xf]; \ + } \ + else { \ + *d++ = (beg)[i]; \ + } \ + } \ } while (0) -const gchar * +const char * rspamd_url_encode(struct rspamd_url *url, gsize *pdlen, rspamd_mempool_t *pool) { - guchar *dest, *d, *dend; - static const gchar hexdigests[16] = "0123456789ABCDEF"; - guint i; + unsigned char *dest, *d, *dend; + static const char hexdigests[16] = "0123456789ABCDEF"; + unsigned int i; gsize dlen = 0; g_assert(pdlen != NULL && url != NULL && pool != NULL); @@ -4051,19 +4051,19 @@ rspamd_url_encode(struct rspamd_url *url, gsize *pdlen, if (url->protocollen > 0) { if (!(url->protocol & PROTOCOL_UNKNOWN)) { - const gchar *known_proto = rspamd_url_protocol_name(url->protocol); - d += rspamd_snprintf((gchar *) d, dend - d, + const char *known_proto = rspamd_url_protocol_name(url->protocol); + d += rspamd_snprintf((char *) d, dend - d, "%s://", known_proto); } else { - d += rspamd_snprintf((gchar *) d, dend - d, + d += rspamd_snprintf((char *) d, dend - d, "%*s://", - (gint) url->protocollen, url->string); + (int) url->protocollen, url->string); } } else { - d += rspamd_snprintf((gchar *) d, dend - d, "http://"); + d += rspamd_snprintf((char *) d, dend - d, "http://"); } if (url->userlen > 0) { @@ -4095,19 +4095,19 @@ rspamd_url_encode(struct rspamd_url *url, gsize *pdlen, *pdlen = (d - dest); - return (const gchar *) dest; + return (const char *) dest; } gboolean rspamd_url_is_domain(int c) { - return is_domain((guchar) c); + return is_domain((unsigned char) c); } -const gchar * +const char * rspamd_url_protocol_name(enum rspamd_url_protocol proto) { - const gchar *ret = "unknown"; + const char *ret = "unknown"; switch (proto) { case PROTOCOL_HTTP: @@ -4136,7 +4136,7 @@ rspamd_url_protocol_name(enum rspamd_url_protocol proto) } enum rspamd_url_protocol -rspamd_url_protocol_from_string(const gchar *str) +rspamd_url_protocol_from_string(const char *str) { enum rspamd_url_protocol ret = PROTOCOL_UNKNOWN; @@ -4168,7 +4168,7 @@ bool rspamd_url_set_add_or_increase(khash_t(rspamd_url_hash) * set, bool enforce_replace) { khiter_t k; - gint r; + int r; k = kh_get(rspamd_url_hash, set, u); @@ -4210,7 +4210,7 @@ rspamd_url_set_add_or_return(khash_t(rspamd_url_hash) * set, struct rspamd_url *u) { khiter_t k; - gint r; + int r; if (set) { k = kh_get(rspamd_url_hash, set, u); @@ -4231,7 +4231,7 @@ rspamd_url_set_add_or_return(khash_t(rspamd_url_hash) * set, bool rspamd_url_host_set_add(khash_t(rspamd_url_host_hash) * set, struct rspamd_url *u) { - gint r; + int r; if (set) { kh_put(rspamd_url_host_hash, set, u, &r); @@ -4280,10 +4280,10 @@ bool rspamd_url_host_set_has(khash_t(rspamd_url_host_hash) * set, struct rspamd_ return false; } -bool rspamd_url_flag_from_string(const gchar *str, gint *flag) +bool rspamd_url_flag_from_string(const char *str, int *flag) { - gint h = rspamd_cryptobox_fast_hash_specific(RSPAMD_CRYPTOBOX_HASHFAST_INDEPENDENT, - str, strlen(str), 0); + int h = rspamd_cryptobox_fast_hash_specific(RSPAMD_CRYPTOBOX_HASHFAST_INDEPENDENT, + str, strlen(str), 0); for (int i = 0; i < G_N_ELEMENTS(url_flag_names); i++) { if (url_flag_names[i].hash == h) { @@ -4297,7 +4297,7 @@ bool rspamd_url_flag_from_string(const gchar *str, gint *flag) } -const gchar * +const char * rspamd_url_flag_to_string(int flag) { for (int i = 0; i < G_N_ELEMENTS(url_flag_names); i++) { diff --git a/src/libserver/url.h b/src/libserver/url.h index d1fb8c908..671d25b27 100644 --- a/src/libserver/url.h +++ b/src/libserver/url.h @@ -1,3 +1,19 @@ +/* + * Copyright 2024 Vsevolod Stakhov + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* URL check functions */ #ifndef URL_H #define URL_H @@ -48,7 +64,7 @@ enum rspamd_url_flags { #define RSPAMD_URL_MAX_FLAG_SHIFT (26u) struct rspamd_url_tag { - const gchar *data; + const char *data; struct rspamd_url_tag *prev, *next; }; @@ -71,8 +87,8 @@ struct rspamd_url { uint16_t queryshift; uint16_t fragmentshift; uint16_t tldshift; - guint16 usershift; - guint16 userlen; + uint16_t usershift; + uint16_t userlen; uint16_t hostlen; uint16_t datalen; @@ -93,10 +109,10 @@ struct rspamd_url { * Rarely used url fields */ struct rspamd_url_ext { - gchar *visible_part; + char *visible_part; struct rspamd_url *linked_url; - guint16 port; + uint16_t port; }; #define rspamd_url_user(u) ((u)->userlen > 0 ? (u)->string + (u)->usershift : NULL) @@ -147,7 +163,7 @@ enum rspamd_url_find_type { * Initialize url library * @param cfg */ -void rspamd_url_init(const gchar *tld_file); +void rspamd_url_init(const char *tld_file); void rspamd_url_deinit(void); @@ -171,7 +187,7 @@ void rspamd_url_text_extract(rspamd_mempool_t *pool, * @param uri url object, must be pre allocated */ enum uri_errno rspamd_url_parse(struct rspamd_url *uri, - gchar *uristring, + char *uristring, gsize len, rspamd_mempool_t *pool, enum rspamd_url_parse_flags flags); @@ -187,8 +203,8 @@ enum uri_errno rspamd_url_parse(struct rspamd_url *uri, * @return TRUE if url is found in specified text */ gboolean rspamd_url_find(rspamd_mempool_t *pool, - const gchar *begin, gsize len, - gchar **url_str, + const char *begin, gsize len, + char **url_str, enum rspamd_url_find_type how, goffset *url_pos, gboolean *prefix_added); @@ -196,7 +212,7 @@ gboolean rspamd_url_find(rspamd_mempool_t *pool, /* * Return text representation of url parsing error */ -const gchar *rspamd_url_strerror(int err); +const char *rspamd_url_strerror(int err); /** @@ -206,7 +222,7 @@ const gchar *rspamd_url_strerror(int err); * @param out output rspamd_ftok_t with tld position * @return TRUE if tld has been found */ -gboolean rspamd_url_find_tld(const gchar *in, gsize inlen, rspamd_ftok_t *out); +gboolean rspamd_url_find_tld(const char *in, gsize inlen, rspamd_ftok_t *out); typedef gboolean (*url_insert_function)(struct rspamd_url *url, gsize start_offset, gsize end_offset, void *ud); @@ -221,7 +237,7 @@ typedef gboolean (*url_insert_function)(struct rspamd_url *url, * @param ud */ void rspamd_url_find_multiple(rspamd_mempool_t *pool, - const gchar *in, gsize inlen, + const char *in, gsize inlen, enum rspamd_url_find_type how, GPtrArray *nlines, url_insert_function func, @@ -237,7 +253,7 @@ void rspamd_url_find_multiple(rspamd_mempool_t *pool, * @param ud */ void rspamd_url_find_single(rspamd_mempool_t *pool, - const gchar *in, gsize inlen, + const char *in, gsize inlen, enum rspamd_url_find_type how, url_insert_function func, gpointer ud); @@ -260,7 +276,7 @@ gboolean rspamd_url_task_subject_callback(struct rspamd_url *url, * @param size * @return */ -gsize rspamd_url_decode(gchar *dst, const gchar *src, gsize size); +gsize rspamd_url_decode(char *dst, const char *src, gsize size); /** * Encode url if needed. In this case, memory is allocated from the specific pool. @@ -269,8 +285,8 @@ gsize rspamd_url_decode(gchar *dst, const gchar *src, gsize size); * @param pool * @return */ -const gchar *rspamd_url_encode(struct rspamd_url *url, gsize *dlen, - rspamd_mempool_t *pool); +const char *rspamd_url_encode(struct rspamd_url *url, gsize *dlen, + rspamd_mempool_t *pool); /** @@ -285,7 +301,7 @@ gboolean rspamd_url_is_domain(int c); * @param proto * @return */ -const gchar *rspamd_url_protocol_name(enum rspamd_url_protocol proto); +const char *rspamd_url_protocol_name(enum rspamd_url_protocol proto); /** @@ -293,7 +309,7 @@ const gchar *rspamd_url_protocol_name(enum rspamd_url_protocol proto); * @param str * @return */ -enum rspamd_url_protocol rspamd_url_protocol_from_string(const gchar *str); +enum rspamd_url_protocol rspamd_url_protocol_from_string(const char *str); /** * Converts string to a url flag @@ -301,14 +317,14 @@ enum rspamd_url_protocol rspamd_url_protocol_from_string(const gchar *str); * @param flag * @return */ -bool rspamd_url_flag_from_string(const gchar *str, gint *flag); +bool rspamd_url_flag_from_string(const char *str, int *flag); /** * Converts url flag to a string * @param flag * @return */ -const gchar *rspamd_url_flag_to_string(int flag); +const char *rspamd_url_flag_to_string(int flag); /* Defines sets of urls indexed by url as is */ KHASH_DECLARE(rspamd_url_hash, struct rspamd_url *, char); diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index b8ded1b95..91bda8fb2 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -565,7 +565,7 @@ rspamd_controller_maybe_compress(struct rspamd_http_connection_entry *entry, } void rspamd_controller_send_error(struct rspamd_http_connection_entry *entry, - gint code, const gchar *error_msg, ...) + int code, const char *error_msg, ...) { struct rspamd_http_message *msg; va_list args; @@ -619,7 +619,7 @@ void rspamd_controller_send_openmetrics(struct rspamd_http_connection_entry *ent } void rspamd_controller_send_string(struct rspamd_http_connection_entry *entry, - const gchar *str) + const char *str) { struct rspamd_http_message *msg; rspamd_fstring_t *reply; @@ -680,7 +680,7 @@ rspamd_worker_drop_priv(struct rspamd_main *rspamd_main) if (rspamd_main->is_privileged) { if (setgid(rspamd_main->workers_gid) == -1) { msg_err_main("cannot setgid to %d (%s), aborting", - (gint) rspamd_main->workers_gid, + (int) rspamd_main->workers_gid, strerror(errno)); exit(-errno); } @@ -694,7 +694,7 @@ rspamd_worker_drop_priv(struct rspamd_main *rspamd_main) if (setuid(rspamd_main->workers_uid) == -1) { msg_err_main("cannot setuid to %d (%s), aborting", - (gint) rspamd_main->workers_uid, + (int) rspamd_main->workers_uid, strerror(errno)); exit(-errno); } @@ -848,13 +848,13 @@ static void rspamd_main_heartbeat_cb(EV_P_ ev_timer *w, int revents) { struct rspamd_worker *wrk = (struct rspamd_worker *) w->data; - gdouble time_from_last = ev_time(); + double time_from_last = ev_time(); struct rspamd_main *rspamd_main; static struct rspamd_control_command cmd; struct tm tm; - gchar timebuf[64]; - gchar usec_buf[16]; - gint r; + char timebuf[64]; + char usec_buf[16]; + int r; time_from_last -= wrk->hb.last_event; rspamd_main = wrk->srv; @@ -866,7 +866,7 @@ rspamd_main_heartbeat_cb(EV_P_ ev_timer *w, int revents) rspamd_localtime(wrk->hb.last_event, &tm); r = strftime(timebuf, sizeof(timebuf), "%F %H:%M:%S", &tm); rspamd_snprintf(usec_buf, sizeof(usec_buf), "%.5f", - wrk->hb.last_event - (gdouble) (time_t) wrk->hb.last_event); + wrk->hb.last_event - (double) (time_t) wrk->hb.last_event); rspamd_snprintf(timebuf + r, sizeof(timebuf) - r, "%s", usec_buf + 1); @@ -922,7 +922,7 @@ rspamd_main_heartbeat_cb(EV_P_ ev_timer *w, int revents) rspamd_localtime(wrk->hb.last_event, &tm); r = strftime(timebuf, sizeof(timebuf), "%F %H:%M:%S", &tm); rspamd_snprintf(usec_buf, sizeof(usec_buf), "%.5f", - wrk->hb.last_event - (gdouble) (time_t) wrk->hb.last_event); + wrk->hb.last_event - (double) (time_t) wrk->hb.last_event); rspamd_snprintf(timebuf + r, sizeof(timebuf) - r, "%s", usec_buf + 1); @@ -968,7 +968,7 @@ rspamd_maybe_reuseport_socket(struct rspamd_worker_listen_socket *ls) } #if defined(SO_REUSEPORT) && defined(SO_REUSEADDR) && defined(LINUX) - gint nfd = -1; + int nfd = -1; if (ls->type == RSPAMD_WORKER_SOCKET_UDP) { nfd = rspamd_inet_address_listen(ls->addr, @@ -1026,7 +1026,7 @@ rspamd_handle_child_fork(struct rspamd_worker *wrk, struct rspamd_worker_conf *cf, GHashTable *listen_sockets) { - gint rc; + int rc; struct rlimit rlim; /* Update pid for logging */ @@ -1245,7 +1245,7 @@ rspamd_handle_main_fork(struct rspamd_worker *wrk, struct rspamd_worker * rspamd_fork_worker(struct rspamd_main *rspamd_main, struct rspamd_worker_conf *cf, - guint index, + unsigned int index, struct ev_loop *ev_base, rspamd_worker_term_cb term_handler, GHashTable *listen_sockets) @@ -1461,8 +1461,8 @@ rspamd_worker_check_controller_presence(struct rspamd_worker *w) struct rspamd_worker_session_elt { void *ptr; - guint *pref; - const gchar *tag; + unsigned int *pref; + const char *tag; time_t when; }; @@ -1473,7 +1473,7 @@ struct rspamd_worker_session_cache { struct ev_timer periodic; }; -static gint +static int rspamd_session_cache_sort_cmp(gconstpointer pa, gconstpointer pb) { const struct rspamd_worker_session_elt @@ -1489,12 +1489,12 @@ rspamd_sessions_cache_periodic(EV_P_ ev_timer *w, int revents) struct rspamd_worker_session_cache *c = (struct rspamd_worker_session_cache *) w->data; GHashTableIter it; - gchar timebuf[32]; + char timebuf[32]; gpointer k, v; struct rspamd_worker_session_elt *elt; struct tm tms; GPtrArray *res; - guint i; + unsigned int i; if (g_hash_table_size(c->cache) > c->cfg->max_sessions_cache) { res = g_ptr_array_sized_new(g_hash_table_size(c->cache)); @@ -1505,7 +1505,7 @@ rspamd_sessions_cache_periodic(EV_P_ ev_timer *w, int revents) } msg_err("sessions cache is overflowed %d elements where %d is limit", - (gint) res->len, (gint) c->cfg->max_sessions_cache); + (int) res->len, (int) c->cfg->max_sessions_cache); g_ptr_array_sort(res, rspamd_session_cache_sort_cmp); PTR_ARRAY_FOREACH(res, i, elt) @@ -1529,7 +1529,7 @@ rspamd_worker_session_cache_new(struct rspamd_worker *w, struct ev_loop *ev_base) { struct rspamd_worker_session_cache *c; - static const gdouble periodic_interval = 60.0; + static const double periodic_interval = 60.0; c = g_malloc0(sizeof(*c)); c->ev_base = ev_base; @@ -1545,8 +1545,8 @@ rspamd_worker_session_cache_new(struct rspamd_worker *w, } -void rspamd_worker_session_cache_add(void *cache, const gchar *tag, - guint *pref, void *ptr) +void rspamd_worker_session_cache_add(void *cache, const char *tag, + unsigned int *pref, void *ptr) { struct rspamd_worker_session_cache *c = cache; struct rspamd_worker_session_elt *elt; @@ -1576,7 +1576,7 @@ rspamd_worker_monitored_on_change(struct rspamd_monitored_ctx *ctx, struct rspamd_worker *worker = ud; struct rspamd_config *cfg = worker->srv->cfg; struct ev_loop *ev_base; - guchar tag[RSPAMD_MONITORED_TAG_LEN]; + unsigned char tag[RSPAMD_MONITORED_TAG_LEN]; static struct rspamd_srv_command srv_cmd; rspamd_monitored_get_tag(m, tag); @@ -1721,10 +1721,10 @@ rspamd_enable_accept_event(EV_P_ ev_timer *w, int revents) ev_io_start(EV_A_ & ac_ev->accept_ev); } -void rspamd_worker_throttle_accept_events(gint sock, void *data) +void rspamd_worker_throttle_accept_events(int sock, void *data) { struct rspamd_worker_accept_event *head, *cur; - const gdouble throttling = 0.5; + const double throttling = 0.5; head = (struct rspamd_worker_accept_event *) data; @@ -1853,8 +1853,8 @@ rspamd_check_termination_clause(struct rspamd_main *rspamd_main, #ifdef WITH_HYPERSCAN gboolean rspamd_worker_hyperscan_ready(struct rspamd_main *rspamd_main, - struct rspamd_worker *worker, gint fd, - gint attached_fd, + struct rspamd_worker *worker, int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud) { @@ -1893,8 +1893,8 @@ rspamd_worker_check_context(gpointer ctx, uint64_t magic) static gboolean rspamd_worker_log_pipe_handler(struct rspamd_main *rspamd_main, - struct rspamd_worker *worker, gint fd, - gint attached_fd, + struct rspamd_worker *worker, int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud) { @@ -1928,8 +1928,8 @@ rspamd_worker_log_pipe_handler(struct rspamd_main *rspamd_main, static gboolean rspamd_worker_monitored_handler(struct rspamd_main *rspamd_main, - struct rspamd_worker *worker, gint fd, - gint attached_fd, + struct rspamd_worker *worker, int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud) { @@ -1996,9 +1996,9 @@ void rspamd_controller_store_saved_stats(struct rspamd_main *rspamd_main, struct rspamd_stat *stat; ucl_object_t *top, *sub; struct ucl_emitter_functions *efuncs; - gint i, fd; + int i, fd; FILE *fp; - gchar fpath[PATH_MAX]; + char fpath[PATH_MAX]; if (cfg->stats_file == NULL) { return; @@ -2082,7 +2082,7 @@ rspamd_controller_load_saved_stats(struct rspamd_main *rspamd_main, ucl_object_t *obj; const ucl_object_t *elt, *subelt; struct rspamd_stat *stat, stat_copy; - gint i; + int i; if (cfg->stats_file == NULL) { return; @@ -2164,9 +2164,9 @@ rspamd_controller_rrd_update(EV_P_ ev_timer *w, int revents) (struct rspamd_controller_periodics_cbdata *) w->data; struct rspamd_stat *stat; GArray ar; - gdouble points[METRIC_ACTION_MAX]; + double points[METRIC_ACTION_MAX]; GError *err = NULL; - guint i; + unsigned int i; g_assert(cbd->rrd != NULL); stat = cbd->stat; @@ -2175,7 +2175,7 @@ rspamd_controller_rrd_update(EV_P_ ev_timer *w, int revents) points[i] = stat->actions_stat[i]; } - ar.data = (gchar *) points; + ar.data = (char *) points; ar.len = sizeof(points); if (!rspamd_rrd_add_record(cbd->rrd, &ar, rspamd_get_calendar_ticks(), @@ -2265,8 +2265,8 @@ void rspamd_worker_init_controller(struct rspamd_worker *worker, } } -gdouble -rspamd_worker_check_and_adjust_timeout(struct rspamd_config *cfg, gdouble timeout) +double +rspamd_worker_check_and_adjust_timeout(struct rspamd_config *cfg, double timeout) { if (isnan(timeout)) { /* Use implicit timeout from cfg->task_timeout */ diff --git a/src/libserver/worker_util.h b/src/libserver/worker_util.h index 6e3a3ddfd..e3627092d 100644 --- a/src/libserver/worker_util.h +++ b/src/libserver/worker_util.h @@ -26,10 +26,10 @@ extern "C" { #endif #ifndef HAVE_SA_SIGINFO -typedef void (*rspamd_sig_handler_t)(gint); +typedef void (*rspamd_sig_handler_t)(int); #else -typedef void (*rspamd_sig_handler_t)(gint, siginfo_t *, void *); +typedef void (*rspamd_sig_handler_t)(int, siginfo_t *, void *); #endif @@ -82,13 +82,13 @@ void rspamd_worker_set_signal_handler(int signo, */ void rspamd_worker_stop_accept(struct rspamd_worker *worker); -typedef gint (*rspamd_controller_func_t)( +typedef int (*rspamd_controller_func_t)( struct rspamd_http_connection_entry *conn_ent, struct rspamd_http_message *msg, struct module_ctx *ctx); struct rspamd_custom_controller_command { - const gchar *command; + const char *command; struct module_ctx *ctx; gboolean privileged; gboolean require_message; @@ -103,7 +103,7 @@ struct rspamd_controller_session { struct rspamd_worker *wrk; rspamd_mempool_t *pool; struct rspamd_task *task; - gchar *classifier; + char *classifier; rspamd_inet_addr_t *from_addr; struct rspamd_config *cfg; struct rspamd_lang_detector *lang_det; @@ -118,7 +118,7 @@ struct rspamd_controller_session { * @param error_msg error message */ void rspamd_controller_send_error(struct rspamd_http_connection_entry *entry, - gint code, const gchar *error_msg, ...); + int code, const char *error_msg, ...); /** * Send openmetrics-formatted strings using HTTP @@ -134,7 +134,7 @@ void rspamd_controller_send_openmetrics(struct rspamd_http_connection_entry *ent * @param str string to send */ void rspamd_controller_send_string(struct rspamd_http_connection_entry *entry, - const gchar *str); + const char *str); /** * Send UCL using HTTP and JSON serialization @@ -180,8 +180,8 @@ gboolean rspamd_worker_is_scanner(struct rspamd_worker *w); * @param timeout * @return */ -gdouble rspamd_worker_check_and_adjust_timeout(struct rspamd_config *cfg, - gdouble timeout); +double rspamd_worker_check_and_adjust_timeout(struct rspamd_config *cfg, + double timeout); /** * Returns TRUE if a specific worker is a primary controller @@ -210,8 +210,8 @@ void *rspamd_worker_session_cache_new(struct rspamd_worker *w, * @param pref * @param ptr */ -void rspamd_worker_session_cache_add(void *cache, const gchar *tag, - guint *pref, void *ptr); +void rspamd_worker_session_cache_add(void *cache, const char *tag, + unsigned int *pref, void *ptr); /** * Removes session from cache @@ -224,7 +224,7 @@ void rspamd_worker_session_cache_remove(void *cache, void *ptr); * Fork new worker with the specified configuration */ struct rspamd_worker *rspamd_fork_worker(struct rspamd_main *, - struct rspamd_worker_conf *, guint idx, + struct rspamd_worker_conf *, unsigned int idx, struct ev_loop *ev_base, rspamd_worker_term_cb term_handler, GHashTable *listen_sockets); @@ -254,7 +254,7 @@ void rspamd_worker_init_monitored(struct rspamd_worker *worker, * @param sock * @param data struct rspamd_worker_accept_event * list */ -void rspamd_worker_throttle_accept_events(gint sock, void *data); +void rspamd_worker_throttle_accept_events(int sock, void *data); /** * Checks (and logs) the worker's termination status. Returns TRUE if a worker @@ -303,8 +303,8 @@ void rspamd_controller_store_saved_stats(struct rspamd_main *rspamd_main, struct rspamd_control_command; gboolean rspamd_worker_hyperscan_ready(struct rspamd_main *rspamd_main, - struct rspamd_worker *worker, gint fd, - gint attached_fd, + struct rspamd_worker *worker, int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud); diff --git a/src/libstat/backends/backends.h b/src/libstat/backends/backends.h index 4b16950bb..cf7f276ab 100644 --- a/src/libstat/backends/backends.h +++ b/src/libstat/backends/backends.h @@ -44,17 +44,17 @@ struct rspamd_stat_backend { gpointer (*runtime)(struct rspamd_task *task, struct rspamd_statfile_config *stcf, gboolean learn, gpointer ctx, - gint id); + int id); gboolean (*process_tokens)(struct rspamd_task *task, GPtrArray *tokens, - gint id, + int id, gpointer ctx); gboolean (*finalize_process)(struct rspamd_task *task, gpointer runtime, gpointer ctx); gboolean (*learn_tokens)(struct rspamd_task *task, GPtrArray *tokens, - gint id, + int id, gpointer ctx); gulong (*total_learns)(struct rspamd_task *task, @@ -83,15 +83,15 @@ struct rspamd_stat_backend { struct rspamd_config *cfg, struct rspamd_statfile *st); \ gpointer rspamd_##name##_runtime(struct rspamd_task *task, \ struct rspamd_statfile_config *stcf, \ - gboolean learn, gpointer ctx, gint id); \ + gboolean learn, gpointer ctx, int id); \ gboolean rspamd_##name##_process_tokens(struct rspamd_task *task, \ - GPtrArray *tokens, gint id, \ + GPtrArray *tokens, int id, \ gpointer runtime); \ gboolean rspamd_##name##_finalize_process(struct rspamd_task *task, \ gpointer runtime, \ gpointer ctx); \ gboolean rspamd_##name##_learn_tokens(struct rspamd_task *task, \ - GPtrArray *tokens, gint id, \ + GPtrArray *tokens, int id, \ gpointer runtime); \ gboolean rspamd_##name##_finalize_learn(struct rspamd_task *task, \ gpointer runtime, \ diff --git a/src/libstat/backends/cdb_backend.cxx b/src/libstat/backends/cdb_backend.cxx index 81d87f319..7bdbcb394 100644 --- a/src/libstat/backends/cdb_backend.cxx +++ b/src/libstat/backends/cdb_backend.cxx @@ -380,7 +380,7 @@ rspamd_cdb_runtime(struct rspamd_task *task, struct rspamd_statfile_config *stcf, gboolean learn, gpointer ctx, - gint _id) + int _id) { /* In CDB we don't have any dynamic stuff */ return ctx; @@ -389,7 +389,7 @@ rspamd_cdb_runtime(struct rspamd_task *task, gboolean rspamd_cdb_process_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, + int id, gpointer runtime) { auto *cdbp = CDB_FROM_RAW(runtime); @@ -431,7 +431,7 @@ rspamd_cdb_finalize_process(struct rspamd_task *task, gboolean rspamd_cdb_learn_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, + int id, gpointer ctx) { return false; diff --git a/src/libstat/backends/http_backend.cxx b/src/libstat/backends/http_backend.cxx index 075e50870..d71e4b3ad 100644 --- a/src/libstat/backends/http_backend.cxx +++ b/src/libstat/backends/http_backend.cxx @@ -91,7 +91,7 @@ public: auto process_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, + int id, bool learn) -> bool; private: @@ -158,7 +158,7 @@ auto http_backend_runtime::create(struct rspamd_task *task, bool is_learn) -> ht return new (allocated_runtime) http_backend_runtime{task, is_learn}; } -auto http_backend_runtime::process_tokens(struct rspamd_task *task, GPtrArray *tokens, gint id, bool learn) -> bool +auto http_backend_runtime::process_tokens(struct rspamd_task *task, GPtrArray *tokens, int id, bool learn) -> bool { if (!learn) { if (id == seen_statfiles.size() - 1) { @@ -322,7 +322,7 @@ rspamd_http_runtime(struct rspamd_task *task, struct rspamd_statfile_config *stcf, gboolean learn, gpointer ctx, - gint id) + int id) { auto maybe_existing = rspamd_mempool_get_variable(task->task_pool, RSPAMD_MEMPOOL_HTTP_STAT_BACKEND_RUNTIME); @@ -347,7 +347,7 @@ rspamd_http_runtime(struct rspamd_task *task, gboolean rspamd_http_process_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, + int id, gpointer runtime) { auto real_runtime = (rspamd::stat::http::http_backend_runtime *) runtime; @@ -371,7 +371,7 @@ rspamd_http_finalize_process(struct rspamd_task *task, gboolean rspamd_http_learn_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, + int id, gpointer runtime) { auto real_runtime = (rspamd::stat::http::http_backend_runtime *) runtime; diff --git a/src/libstat/backends/mmaped_file.c b/src/libstat/backends/mmaped_file.c index f4354d8e1..4430bb9a4 100644 --- a/src/libstat/backends/mmaped_file.c +++ b/src/libstat/backends/mmaped_file.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -69,12 +69,12 @@ struct stat_file { */ typedef struct { #ifdef HAVE_PATH_MAX - gchar filename[PATH_MAX]; /**< name of file */ + char filename[PATH_MAX]; /**< name of file */ #else - gchar filename[MAXPATHLEN]; /**< name of file */ + char filename[MAXPATHLEN]; /**< name of file */ #endif rspamd_mempool_t *pool; - gint fd; /**< descriptor */ + int fd; /**< descriptor */ void *map; /**< mmaped area */ off_t seek_pos; /**< current seek position */ struct stat_file_section cur_section; /**< current section */ @@ -94,13 +94,13 @@ static void rspamd_mmaped_file_set_block_common(rspamd_mempool_t *pool, uint32_t h1, uint32_t h2, double value); rspamd_mmaped_file_t *rspamd_mmaped_file_open(rspamd_mempool_t *pool, - const gchar *filename, size_t size, + const char *filename, size_t size, struct rspamd_statfile_config *stcf); -gint rspamd_mmaped_file_create(const gchar *filename, size_t size, - struct rspamd_statfile_config *stcf, - rspamd_mempool_t *pool); -gint rspamd_mmaped_file_close_file(rspamd_mempool_t *pool, - rspamd_mmaped_file_t *file); +int rspamd_mmaped_file_create(const char *filename, size_t size, + struct rspamd_statfile_config *stcf, + rspamd_mempool_t *pool); +int rspamd_mmaped_file_close_file(rspamd_mempool_t *pool, + rspamd_mmaped_file_t *file); double rspamd_mmaped_file_get_block(rspamd_mmaped_file_t *file, @@ -108,7 +108,7 @@ rspamd_mmaped_file_get_block(rspamd_mmaped_file_t *file, uint32_t h2) { struct stat_file_block *block; - guint i, blocknum; + unsigned int i, blocknum; u_char *c; if (!file->map) { @@ -141,7 +141,7 @@ rspamd_mmaped_file_set_block_common(rspamd_mempool_t *pool, { struct stat_file_block *block, *to_expire = NULL; struct stat_file_header *header; - guint i, blocknum; + unsigned int i, blocknum; u_char *c; double min = G_MAXDOUBLE; @@ -327,12 +327,12 @@ rspamd_mmaped_file_get_total(rspamd_mmaped_file_t *file) } /* Check whether specified file is statistic file and calculate its len in blocks */ -static gint +static int rspamd_mmaped_file_check(rspamd_mempool_t *pool, rspamd_mmaped_file_t *file) { struct stat_file *f; - gchar *c; - static gchar valid_version[] = RSPAMD_STATFILE_VERSION; + char *c; + static char valid_version[] = RSPAMD_STATFILE_VERSION; if (!file || !file->map) { @@ -388,13 +388,13 @@ rspamd_mmaped_file_check(rspamd_mempool_t *pool, rspamd_mmaped_file_t *file) static rspamd_mmaped_file_t * rspamd_mmaped_file_reindex(rspamd_mempool_t *pool, - const gchar *filename, + const char *filename, size_t old_size, size_t size, struct rspamd_statfile_config *stcf) { - gchar *backup, *lock; - gint fd, lock_fd; + char *backup, *lock; + int fd, lock_fd; rspamd_mmaped_file_t *new, *old = NULL; u_char *map, *pos; struct stat_file_block *block; @@ -527,12 +527,12 @@ rspamd_mmaped_file_reindex(rspamd_mempool_t *pool, static void rspamd_mmaped_file_preload(rspamd_mmaped_file_t *file) { - guint8 *pos, *end; - volatile guint8 t; + uint8_t *pos, *end; + volatile uint8_t t; gsize size; - pos = (guint8 *) file->map; - end = (guint8 *) file->map + file->len; + pos = (uint8_t *) file->map; + end = (uint8_t *) file->map + file->len; if (madvise(pos, end - pos, MADV_SEQUENTIAL) == -1) { msg_info("madvise failed: %s", strerror(errno)); @@ -554,13 +554,13 @@ rspamd_mmaped_file_preload(rspamd_mmaped_file_t *file) rspamd_mmaped_file_t * rspamd_mmaped_file_open(rspamd_mempool_t *pool, - const gchar *filename, size_t size, + const char *filename, size_t size, struct rspamd_statfile_config *stcf) { struct stat st; rspamd_mmaped_file_t *new_file; - gchar *lock; - gint lock_fd; + char *lock; + int lock_fd; lock = g_strconcat(filename, ".lock", NULL); lock_fd = open(lock, O_WRONLY | O_CREAT | O_EXCL, 00600); @@ -649,8 +649,8 @@ rspamd_mmaped_file_open(rspamd_mempool_t *pool, return new_file; } -gint rspamd_mmaped_file_close_file(rspamd_mempool_t *pool, - rspamd_mmaped_file_t *file) +int rspamd_mmaped_file_close_file(rspamd_mempool_t *pool, + rspamd_mmaped_file_t *file) { if (file->map) { msg_info_pool("syncing statfile %s", file->filename); @@ -666,10 +666,10 @@ gint rspamd_mmaped_file_close_file(rspamd_mempool_t *pool, return 0; } -gint rspamd_mmaped_file_create(const gchar *filename, - size_t size, - struct rspamd_statfile_config *stcf, - rspamd_mempool_t *pool) +int rspamd_mmaped_file_create(const char *filename, + size_t size, + struct rspamd_statfile_config *stcf, + rspamd_mempool_t *pool) { struct stat_file_header header = { .magic = {'r', 's', 'd'}, @@ -683,9 +683,9 @@ gint rspamd_mmaped_file_create(const gchar *filename, }; struct stat_file_block block = {0, 0, 0}; struct rspamd_stat_tokenizer *tokenizer; - gint fd, lock_fd; - guint buflen = 0, nblocks; - gchar *buf = NULL, *lock; + int fd, lock_fd; + unsigned int buflen = 0, nblocks; + char *buf = NULL, *lock; struct stat sb; gpointer tok_conf; gsize tok_conf_len; @@ -855,7 +855,7 @@ rspamd_mmaped_file_init(struct rspamd_stat_ctx *ctx, struct rspamd_statfile_config *stf = st->stcf; rspamd_mmaped_file_t *mf; const ucl_object_t *filenameo, *sizeo; - const gchar *filename; + const char *filename; gsize size; filenameo = ucl_object_lookup(stf->opts, "filename"); @@ -931,7 +931,7 @@ rspamd_mmaped_file_runtime(struct rspamd_task *task, struct rspamd_statfile_config *stcf, gboolean learn, gpointer p, - gint _id) + int _id) { rspamd_mmaped_file_t *mf = p; @@ -940,21 +940,21 @@ rspamd_mmaped_file_runtime(struct rspamd_task *task, gboolean rspamd_mmaped_file_process_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, + int id, gpointer p) { rspamd_mmaped_file_t *mf = p; uint32_t h1, h2; rspamd_token_t *tok; - guint i; + unsigned int i; g_assert(tokens != NULL); g_assert(p != NULL); for (i = 0; i < tokens->len; i++) { tok = g_ptr_array_index(tokens, i); - memcpy(&h1, (guchar *) &tok->data, sizeof(h1)); - memcpy(&h2, ((guchar *) &tok->data) + sizeof(h1), sizeof(h2)); + memcpy(&h1, (unsigned char *) &tok->data, sizeof(h1)); + memcpy(&h2, ((unsigned char *) &tok->data) + sizeof(h1), sizeof(h2)); tok->values[id] = rspamd_mmaped_file_get_block(mf, h1, h2); } @@ -970,21 +970,21 @@ rspamd_mmaped_file_process_tokens(struct rspamd_task *task, GPtrArray *tokens, gboolean rspamd_mmaped_file_learn_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, + int id, gpointer p) { rspamd_mmaped_file_t *mf = p; uint32_t h1, h2; rspamd_token_t *tok; - guint i; + unsigned int i; g_assert(tokens != NULL); g_assert(p != NULL); for (i = 0; i < tokens->len; i++) { tok = g_ptr_array_index(tokens, i); - memcpy(&h1, (guchar *) &tok->data, sizeof(h1)); - memcpy(&h2, ((guchar *) &tok->data) + sizeof(h1), sizeof(h2)); + memcpy(&h1, (unsigned char *) &tok->data, sizeof(h1)); + memcpy(&h2, ((unsigned char *) &tok->data) + sizeof(h1), sizeof(h2)); rspamd_mmaped_file_set_block(task->task_pool, mf, h1, h2, tok->values[id]); } diff --git a/src/libstat/backends/redis_backend.cxx b/src/libstat/backends/redis_backend.cxx index 630c895a2..6abcfa122 100644 --- a/src/libstat/backends/redis_backend.cxx +++ b/src/libstat/backends/redis_backend.cxx @@ -169,7 +169,7 @@ public: #define GET_TASK_ELT(task, elt) (task == nullptr ? nullptr : (task)->elt) -static const gchar *M = "redis statistics"; +static const char *M = "redis statistics"; static GQuark rspamd_redis_stat_quark(void) @@ -180,14 +180,14 @@ rspamd_redis_stat_quark(void) /* * Non-static for lua unit testing */ -gsize rspamd_redis_expand_object(const gchar *pattern, +gsize rspamd_redis_expand_object(const char *pattern, struct redis_stat_ctx *ctx, struct rspamd_task *task, - gchar **target) + char **target) { gsize tlen = 0; - const gchar *p = pattern, *elt; - gchar *d, *end; + const char *p = pattern, *elt; + char *d, *end; enum { just_char, percent_char, @@ -196,8 +196,8 @@ gsize rspamd_redis_expand_object(const gchar *pattern, struct rspamd_statfile_config *stcf; lua_State *L = nullptr; struct rspamd_task **ptask; - const gchar *rcpt = nullptr; - gint err_idx; + const char *rcpt = nullptr; + int err_idx; g_assert(ctx != nullptr); g_assert(task != nullptr); @@ -315,7 +315,7 @@ gsize rspamd_redis_expand_object(const gchar *pattern, return -1; } - *target = (gchar *) rspamd_mempool_alloc(task->task_pool, tlen + 1); + *target = (char *) rspamd_mempool_alloc(task->task_pool, tlen + 1); d = *target; end = d + tlen + 1; d[tlen] = '\0'; @@ -441,7 +441,7 @@ rspamd_redis_parse_classifier_opts(struct redis_stat_ctx *backend, const ucl_object_t *classifier_obj, struct rspamd_config *cfg) { - const gchar *lua_script; + const char *lua_script; const ucl_object_t *elt, *users_enabled; auto *L = RSPAMD_LUA_CFG_STATE(cfg); @@ -590,7 +590,7 @@ rspamd_redis_init(struct rspamd_stat_ctx *ctx, gpointer rspamd_redis_runtime(struct rspamd_task *task, struct rspamd_statfile_config *stcf, - gboolean learn, gpointer c, gint _id) + gboolean learn, gpointer c, int _id) { struct redis_stat_ctx *ctx = REDIS_CTX(c); char *object_expanded = nullptr; @@ -708,7 +708,7 @@ msgpack_str_len(std::size_t len) -> std::size_t * Serialise stat tokens to message pack */ static char * -rspamd_redis_serialize_tokens(struct rspamd_task *task, const gchar *prefix, GPtrArray *tokens, gsize *ser_len) +rspamd_redis_serialize_tokens(struct rspamd_task *task, const char *prefix, GPtrArray *tokens, gsize *ser_len) { /* Each token is int64_t that requires 10 bytes (2 int32_t) + 4 bytes array len + 1 byte array magic */ char max_int64_str[] = "18446744073709551615"; @@ -719,16 +719,16 @@ rspamd_redis_serialize_tokens(struct rspamd_task *task, const gchar *prefix, GPt /* Calculate required length */ req_len += tokens->len * (msgpack_str_len(sizeof(max_int64_str) + prefix_len) + 1); - auto *buf = (gchar *) rspamd_mempool_alloc(task->task_pool, req_len); + auto *buf = (char *) rspamd_mempool_alloc(task->task_pool, req_len); auto *p = buf; /* Array */ - *p++ = (gchar) 0xdd; + *p++ = (char) 0xdd; /* Length in big-endian (4 bytes) */ - *p++ = (gchar) ((tokens->len >> 24) & 0xff); - *p++ = (gchar) ((tokens->len >> 16) & 0xff); - *p++ = (gchar) ((tokens->len >> 8) & 0xff); - *p++ = (gchar) (tokens->len & 0xff); + *p++ = (char) ((tokens->len >> 24) & 0xff); + *p++ = (char) ((tokens->len >> 16) & 0xff); + *p++ = (char) ((tokens->len >> 8) & 0xff); + *p++ = (char) (tokens->len & 0xff); int i; @@ -772,13 +772,13 @@ rspamd_redis_serialize_text_tokens(struct rspamd_task *task, GPtrArray *tokens, } } - auto *buf = (gchar *) rspamd_mempool_alloc(task->task_pool, req_len); + auto *buf = (char *) rspamd_mempool_alloc(task->task_pool, req_len); auto *p = buf; /* Array */ std::uint32_t nlen = tokens->len * 2; nlen = GUINT32_TO_BE(nlen); - *p++ = (gchar) 0xdd; + *p++ = (char) 0xdd; /* Length in big-endian (4 bytes) */ memcpy(p, &nlen, sizeof(nlen)); p += sizeof(nlen); @@ -807,7 +807,7 @@ rspamd_redis_serialize_text_tokens(struct rspamd_task *task, GPtrArray *tokens, return buf; } -static gint +static int rspamd_redis_classified(lua_State *L) { const auto *cookie = lua_tostring(L, lua_upvalueindex(1)); @@ -895,7 +895,7 @@ rspamd_redis_classified(lua_State *L) gboolean rspamd_redis_process_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, gpointer p) + int id, gpointer p) { auto *rt = REDIS_RUNTIME(p); auto *L = rt->ctx->L; @@ -918,11 +918,11 @@ rspamd_redis_process_tokens(struct rspamd_task *task, } gsize tokens_len; - gchar *tokens_buf = rspamd_redis_serialize_tokens(task, rt->redis_object_expanded, tokens, &tokens_len); + char *tokens_buf = rspamd_redis_serialize_tokens(task, rt->redis_object_expanded, tokens, &tokens_len); rt->id = id; lua_pushcfunction(L, &rspamd_lua_traceback); - gint err_idx = lua_gettop(L); + int err_idx = lua_gettop(L); /* Function arguments */ lua_rawgeti(L, LUA_REGISTRYINDEX, rt->ctx->cbref_classify); @@ -963,7 +963,7 @@ rspamd_redis_finalize_process(struct rspamd_task *task, gpointer runtime, } -static gint +static int rspamd_redis_learned(lua_State *L) { const auto *cookie = lua_tostring(L, lua_upvalueindex(1)); @@ -994,7 +994,7 @@ rspamd_redis_learned(lua_State *L) gboolean rspamd_redis_learn_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, gpointer p) + int id, gpointer p) { auto *rt = REDIS_RUNTIME(p); auto *L = rt->ctx->L; @@ -1008,19 +1008,19 @@ rspamd_redis_learn_tokens(struct rspamd_task *task, } gsize tokens_len; - gchar *tokens_buf = rspamd_redis_serialize_tokens(task, rt->redis_object_expanded, tokens, &tokens_len); + char *tokens_buf = rspamd_redis_serialize_tokens(task, rt->redis_object_expanded, tokens, &tokens_len); rt->id = id; gsize text_tokens_len = 0; - gchar *text_tokens_buf = nullptr; + char *text_tokens_buf = nullptr; if (rt->ctx->store_tokens) { text_tokens_buf = rspamd_redis_serialize_text_tokens(task, tokens, &text_tokens_len); } lua_pushcfunction(L, &rspamd_lua_traceback); - gint err_idx = lua_gettop(L); + int err_idx = lua_gettop(L); auto nargs = 8; /* Function arguments */ diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c index b26c1a86f..973dc30a7 100644 --- a/src/libstat/backends/sqlite3_backend.c +++ b/src/libstat/backends/sqlite3_backend.c @@ -28,15 +28,15 @@ struct rspamd_stat_sqlite3_db { sqlite3 *sqlite; - gchar *fname; + char *fname; GArray *prstmt; lua_State *L; rspamd_mempool_t *pool; gboolean in_transaction; gboolean enable_users; gboolean enable_languages; - gint cbref_user; - gint cbref_language; + int cbref_user; + int cbref_language; }; struct rspamd_stat_sqlite3_rt { @@ -161,8 +161,8 @@ rspamd_sqlite3_get_user(struct rspamd_stat_sqlite3_db *db, struct rspamd_task *task, gboolean learn) { int64_t id = 0; /* Default user is 0 */ - gint rc, err_idx; - const gchar *user = NULL; + int rc, err_idx; + const char *user = NULL; struct rspamd_task **ptask; lua_State *L = db->L; @@ -220,9 +220,9 @@ rspamd_sqlite3_get_language(struct rspamd_stat_sqlite3_db *db, struct rspamd_task *task, gboolean learn) { int64_t id = 0; /* Default language is 0 */ - gint rc, err_idx; - guint i; - const gchar *language = NULL; + int rc, err_idx; + unsigned int i; + const char *language = NULL; struct rspamd_mime_text_part *tp; struct rspamd_task **ptask; lua_State *L = db->L; @@ -286,7 +286,7 @@ rspamd_sqlite3_get_language(struct rspamd_stat_sqlite3_db *db, static struct rspamd_stat_sqlite3_db * rspamd_sqlite3_opendb(rspamd_mempool_t *pool, struct rspamd_statfile_config *stcf, - const gchar *path, const ucl_object_t *opts, + const char *path, const ucl_object_t *opts, gboolean create, GError **err) { struct rspamd_stat_sqlite3_db *bk; @@ -294,9 +294,9 @@ rspamd_sqlite3_opendb(rspamd_mempool_t *pool, gpointer tk_conf; gsize sz = 0; int64_t sz64 = 0; - gchar *tok_conf_encoded; - gint ret, ntries = 0; - const gint max_tries = 100; + char *tok_conf_encoded; + int ret, ntries = 0; + const int max_tries = 100; struct timespec sleep_ts = { .tv_sec = 0, .tv_nsec = 1000000}; @@ -375,7 +375,7 @@ rspamd_sqlite3_init(struct rspamd_stat_ctx *ctx, struct rspamd_classifier_config *clf = st->classifier->cfg; struct rspamd_statfile_config *stf = st->stcf; const ucl_object_t *filenameo, *lang_enabled, *users_enabled; - const gchar *filename, *lua_script; + const char *filename, *lua_script; struct rspamd_stat_sqlite3_db *bk; GError *err = NULL; @@ -502,7 +502,7 @@ void rspamd_sqlite3_close(gpointer p) gpointer rspamd_sqlite3_runtime(struct rspamd_task *task, - struct rspamd_statfile_config *stcf, gboolean learn, gpointer p, gint _id) + struct rspamd_statfile_config *stcf, gboolean learn, gpointer p, int _id) { struct rspamd_stat_sqlite3_rt *rt = NULL; struct rspamd_stat_sqlite3_db *bk = p; @@ -522,12 +522,12 @@ rspamd_sqlite3_runtime(struct rspamd_task *task, gboolean rspamd_sqlite3_process_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, gpointer p) + int id, gpointer p) { struct rspamd_stat_sqlite3_db *bk; struct rspamd_stat_sqlite3_rt *rt = p; int64_t iv = 0; - guint i; + unsigned int i; rspamd_token_t *tok; g_assert(p != NULL); @@ -625,12 +625,12 @@ rspamd_sqlite3_finalize_process(struct rspamd_task *task, gpointer runtime, gboolean rspamd_sqlite3_learn_tokens(struct rspamd_task *task, GPtrArray *tokens, - gint id, gpointer p) + int id, gpointer p) { struct rspamd_stat_sqlite3_db *bk; struct rspamd_stat_sqlite3_rt *rt = p; int64_t iv = 0; - guint i; + unsigned int i; rspamd_token_t *tok; g_assert(tokens != NULL); @@ -691,7 +691,7 @@ rspamd_sqlite3_finalize_learn(struct rspamd_task *task, gpointer runtime, { struct rspamd_stat_sqlite3_rt *rt = runtime; struct rspamd_stat_sqlite3_db *bk; - gint wal_frames, wal_checkpointed, mode; + int wal_frames, wal_checkpointed, mode; g_assert(rt != NULL); bk = rt->db; diff --git a/src/libstat/classifiers/bayes.c b/src/libstat/classifiers/bayes.c index abefcd7d9..93b5149da 100644 --- a/src/libstat/classifiers/bayes.c +++ b/src/libstat/classifiers/bayes.c @@ -49,11 +49,11 @@ bayes_error_quark(void) * @param freedom_deg number of degrees of freedom * @return */ -static gdouble -inv_chi_square(struct rspamd_task *task, gdouble value, gint freedom_deg) +static double +inv_chi_square(struct rspamd_task *task, double value, int freedom_deg) { double prob, sum, m; - gint i; + int i; errno = 0; m = -value; @@ -85,7 +85,7 @@ inv_chi_square(struct rspamd_task *task, gdouble value, gint freedom_deg) * from 1.0 (no confidence) to 0.0 (full confidence) */ for (i = 1; i < freedom_deg; i++) { - prob *= m / (gdouble) i; + prob *= m / (double) i; sum += prob; msg_debug_bayes("i=%d, probability: %g, sum: %g", i, prob, sum); } @@ -96,7 +96,7 @@ inv_chi_square(struct rspamd_task *task, gdouble value, gint freedom_deg) struct bayes_task_closure { double ham_prob; double spam_prob; - gdouble meta_skip_prob; + double meta_skip_prob; uint64_t processed_tokens; uint64_t total_hits; uint64_t text_tokens; @@ -117,12 +117,12 @@ static void bayes_classify_token(struct rspamd_classifier *ctx, rspamd_token_t *tok, struct bayes_task_closure *cl) { - guint i; - gint id; - guint spam_count = 0, ham_count = 0, total_count = 0; + unsigned int i; + int id; + unsigned int spam_count = 0, ham_count = 0, total_count = 0; struct rspamd_statfile *st; struct rspamd_task *task; - const gchar *token_type = "txt"; + const char *token_type = "txt"; double spam_prob, spam_freq, ham_freq, bayes_spam_prob, bayes_ham_prob, ham_prob, fw, w, val; @@ -152,7 +152,7 @@ bayes_classify_token(struct rspamd_classifier *ctx, } for (i = 0; i < ctx->statfiles_ids->len; i++) { - id = g_array_index(ctx->statfiles_ids, gint, i); + id = g_array_index(ctx->statfiles_ids, int, i); st = g_ptr_array_index(ctx->ctx->statfiles, id); g_assert(st != NULL); val = tok->values[id]; @@ -269,12 +269,12 @@ bayes_classify(struct rspamd_classifier *ctx, struct rspamd_task *task) { double final_prob, h, s, *pprob; - gchar sumbuf[32]; + char sumbuf[32]; struct rspamd_statfile *st = NULL; struct bayes_task_closure cl; rspamd_token_t *tok; - guint i, text_tokens = 0; - gint id; + unsigned int i, text_tokens = 0; + int id; g_assert(ctx != NULL); g_assert(tokens != NULL); @@ -340,13 +340,13 @@ bayes_classify(struct rspamd_classifier *ctx, } if (ctx->cfg->min_tokens > 0 && - cl.text_tokens < (gint) (ctx->cfg->min_tokens * 0.1)) { + cl.text_tokens < (int) (ctx->cfg->min_tokens * 0.1)) { msg_info_bayes("ignore bayes probability since we have " "found too few text tokens: %uL (of %ud checked), " "at least %d required", cl.text_tokens, text_tokens, - (gint) (ctx->cfg->min_tokens * 0.1)); + (int) (ctx->cfg->min_tokens * 0.1)); return TRUE; } @@ -413,7 +413,7 @@ bayes_classify(struct rspamd_classifier *ctx, if (cl.processed_tokens > 0 && fabs(final_prob - 0.5) > 0.05) { /* Now we can have exactly one HAM and exactly one SPAM statfiles per classifier */ for (i = 0; i < ctx->statfiles_ids->len; i++) { - id = g_array_index(ctx->statfiles_ids, gint, i); + id = g_array_index(ctx->statfiles_ids, int, i); st = g_ptr_array_index(ctx->ctx->statfiles, id); if (final_prob > 0.5 && st->stcf->is_spam) { @@ -468,8 +468,8 @@ bayes_learn_spam(struct rspamd_classifier *ctx, gboolean unlearn, GError **err) { - guint i, j, total_cnt, spam_cnt, ham_cnt; - gint id; + unsigned int i, j, total_cnt, spam_cnt, ham_cnt; + int id; struct rspamd_statfile *st; rspamd_token_t *tok; gboolean incrementing; @@ -486,7 +486,7 @@ bayes_learn_spam(struct rspamd_classifier *ctx, tok = g_ptr_array_index(tokens, i); for (j = 0; j < ctx->statfiles_ids->len; j++) { - id = g_array_index(ctx->statfiles_ids, gint, j); + id = g_array_index(ctx->statfiles_ids, int, j); st = g_ptr_array_index(ctx->ctx->statfiles, id); g_assert(st != NULL); diff --git a/src/libstat/classifiers/classifiers.h b/src/libstat/classifiers/classifiers.h index 949408c6b..22978e673 100644 --- a/src/libstat/classifiers/classifiers.h +++ b/src/libstat/classifiers/classifiers.h @@ -91,7 +91,7 @@ gboolean lua_classifier_learn_spam(struct rspamd_classifier *ctx, gboolean unlearn, GError **err); -extern gint rspamd_bayes_log_id; +extern int rspamd_bayes_log_id; #define msg_debug_bayes(...) rspamd_conditional_debug_fast(NULL, task->from_addr, \ rspamd_bayes_log_id, "bayes", task->task_pool->tag.uid, \ G_STRFUNC, \ diff --git a/src/libstat/classifiers/lua_classifier.c b/src/libstat/classifiers/lua_classifier.c index 88ab015d6..d30de01a9 100644 --- a/src/libstat/classifiers/lua_classifier.c +++ b/src/libstat/classifiers/lua_classifier.c @@ -20,9 +20,9 @@ #include "lua/lua_common.h" struct rspamd_lua_classifier_ctx { - gchar *name; - gint classify_ref; - gint learn_ref; + char *name; + int classify_ref; + int learn_ref; }; static GHashTable *lua_classifiers = NULL; @@ -53,7 +53,7 @@ lua_classifier_init(struct rspamd_config *cfg, { struct rspamd_lua_classifier_ctx *ctx; lua_State *L = cl->ctx->cfg->lua_state; - gint cb_classify = -1, cb_learn = -1; + int cb_classify = -1, cb_learn = -1; if (lua_classifiers == NULL) { lua_classifiers = g_hash_table_new_full(rspamd_strcase_hash, @@ -135,7 +135,7 @@ lua_classifier_classify(struct rspamd_classifier *cl, struct rspamd_classifier_config **pcfg; lua_State *L; rspamd_token_t *tok; - guint i; + unsigned int i; uint64_t v; ctx = g_hash_table_lookup(lua_classifiers, cl->subrs->name); @@ -190,7 +190,7 @@ lua_classifier_learn_spam(struct rspamd_classifier *cl, struct rspamd_classifier_config **pcfg; lua_State *L; rspamd_token_t *tok; - guint i; + unsigned int i; uint64_t v; ctx = g_hash_table_lookup(lua_classifiers, cl->subrs->name); diff --git a/src/libstat/learn_cache/learn_cache.h b/src/libstat/learn_cache/learn_cache.h index 11a66fc09..9aea31218 100644 --- a/src/libstat/learn_cache/learn_cache.h +++ b/src/libstat/learn_cache/learn_cache.h @@ -41,13 +41,13 @@ struct rspamd_stat_cache { gpointer (*runtime)(struct rspamd_task *task, gpointer ctx, gboolean learn); - gint (*check)(struct rspamd_task *task, - gboolean is_spam, - gpointer runtime); + int (*check)(struct rspamd_task *task, + gboolean is_spam, + gpointer runtime); - gint (*learn)(struct rspamd_task *task, - gboolean is_spam, - gpointer runtime); + int (*learn)(struct rspamd_task *task, + gboolean is_spam, + gpointer runtime); void (*close)(gpointer ctx); @@ -61,12 +61,12 @@ struct rspamd_stat_cache { const ucl_object_t *cf); \ gpointer rspamd_stat_cache_##name##_runtime(struct rspamd_task *task, \ gpointer ctx, gboolean learn); \ - gint rspamd_stat_cache_##name##_check(struct rspamd_task *task, \ - gboolean is_spam, \ - gpointer runtime); \ - gint rspamd_stat_cache_##name##_learn(struct rspamd_task *task, \ - gboolean is_spam, \ - gpointer runtime); \ + int rspamd_stat_cache_##name##_check(struct rspamd_task *task, \ + gboolean is_spam, \ + gpointer runtime); \ + int rspamd_stat_cache_##name##_learn(struct rspamd_task *task, \ + gboolean is_spam, \ + gpointer runtime); \ void rspamd_stat_cache_##name##_close(gpointer ctx) RSPAMD_STAT_CACHE_DEF(sqlite3); diff --git a/src/libstat/learn_cache/redis_cache.cxx b/src/libstat/learn_cache/redis_cache.cxx index 0be56bccd..15dccf141 100644 --- a/src/libstat/learn_cache/redis_cache.cxx +++ b/src/libstat/learn_cache/redis_cache.cxx @@ -68,7 +68,7 @@ rspamd_stat_cache_redis_generate_id(struct rspamd_task *task) sizeof(tok->data)); } - guchar out[rspamd_cryptobox_HASHBYTES]; + unsigned char out[rspamd_cryptobox_HASHBYTES]; rspamd_cryptobox_hash_final(&st, out); auto *b32out = rspamd_mempool_alloc_array_type(task->task_pool, @@ -152,7 +152,7 @@ rspamd_stat_cache_redis_runtime(struct rspamd_task *task, return (void *) ctx; } -static gint +static int rspamd_stat_cache_checked(lua_State *L) { auto *task = lua_check_task(L, 1); @@ -181,9 +181,9 @@ rspamd_stat_cache_checked(lua_State *L) return 0; } -gint rspamd_stat_cache_redis_check(struct rspamd_task *task, - gboolean is_spam, - gpointer runtime) +int rspamd_stat_cache_redis_check(struct rspamd_task *task, + gboolean is_spam, + gpointer runtime) { auto *ctx = (struct rspamd_redis_cache_ctx *) runtime; auto *h = (char *) rspamd_mempool_get_variable(task->task_pool, "words_hash"); @@ -195,7 +195,7 @@ gint rspamd_stat_cache_redis_check(struct rspamd_task *task, auto *L = ctx->L; lua_pushcfunction(L, &rspamd_lua_traceback); - gint err_idx = lua_gettop(L); + int err_idx = lua_gettop(L); /* Function arguments */ lua_rawgeti(L, LUA_REGISTRYINDEX, ctx->check_ref); @@ -214,9 +214,9 @@ gint rspamd_stat_cache_redis_check(struct rspamd_task *task, return RSPAMD_LEARN_OK; } -gint rspamd_stat_cache_redis_learn(struct rspamd_task *task, - gboolean is_spam, - gpointer runtime) +int rspamd_stat_cache_redis_learn(struct rspamd_task *task, + gboolean is_spam, + gpointer runtime) { auto *ctx = (struct rspamd_redis_cache_ctx *) runtime; @@ -229,7 +229,7 @@ gint rspamd_stat_cache_redis_learn(struct rspamd_task *task, auto *L = ctx->L; lua_pushcfunction(L, &rspamd_lua_traceback); - gint err_idx = lua_gettop(L); + int err_idx = lua_gettop(L); /* Function arguments */ lua_rawgeti(L, LUA_REGISTRYINDEX, ctx->learn_ref); diff --git a/src/libstat/learn_cache/sqlite3_cache.c b/src/libstat/learn_cache/sqlite3_cache.c index 36e9382cd..9a070aa14 100644 --- a/src/libstat/learn_cache/sqlite3_cache.c +++ b/src/libstat/learn_cache/sqlite3_cache.c @@ -104,8 +104,8 @@ rspamd_stat_cache_sqlite3_init(struct rspamd_stat_ctx *ctx, { struct rspamd_stat_sqlite3_ctx *new = NULL; const ucl_object_t *elt; - gchar dbpath[PATH_MAX]; - const gchar *path = SQLITE_CACHE_PATH; + char dbpath[PATH_MAX]; + const char *path = SQLITE_CACHE_PATH; sqlite3 *sqlite; GError *err = NULL; @@ -154,17 +154,17 @@ rspamd_stat_cache_sqlite3_runtime(struct rspamd_task *task, return ctx; } -gint rspamd_stat_cache_sqlite3_check(struct rspamd_task *task, - gboolean is_spam, - gpointer runtime) +int rspamd_stat_cache_sqlite3_check(struct rspamd_task *task, + gboolean is_spam, + gpointer runtime) { struct rspamd_stat_sqlite3_ctx *ctx = runtime; rspamd_cryptobox_hash_state_t st; rspamd_token_t *tok; - guchar *out; - gchar *user = NULL; - guint i; - gint rc; + unsigned char *out; + char *user = NULL; + unsigned int i; + int rc; int64_t flag; if (task->tokens == NULL || task->tokens->len == 0) { @@ -184,7 +184,7 @@ gint rspamd_stat_cache_sqlite3_check(struct rspamd_task *task, for (i = 0; i < task->tokens->len; i++) { tok = g_ptr_array_index(task->tokens, i); - rspamd_cryptobox_hash_update(&st, (guchar *) &tok->data, + rspamd_cryptobox_hash_update(&st, (unsigned char *) &tok->data, sizeof(tok->data)); } @@ -219,13 +219,13 @@ gint rspamd_stat_cache_sqlite3_check(struct rspamd_task *task, return RSPAMD_LEARN_OK; } -gint rspamd_stat_cache_sqlite3_learn(struct rspamd_task *task, - gboolean is_spam, - gpointer runtime) +int rspamd_stat_cache_sqlite3_learn(struct rspamd_task *task, + gboolean is_spam, + gpointer runtime) { struct rspamd_stat_sqlite3_ctx *ctx = runtime; gboolean unlearn = !!(task->flags & RSPAMD_TASK_FLAG_UNLEARN); - guchar *h; + unsigned char *h; int64_t flag; h = rspamd_mempool_get_variable(task->task_pool, "words_hash"); diff --git a/src/libstat/stat_api.h b/src/libstat/stat_api.h index af3cdc8b9..f28922588 100644 --- a/src/libstat/stat_api.h +++ b/src/libstat/stat_api.h @@ -50,14 +50,14 @@ typedef struct rspamd_stat_token_s { rspamd_ftok_unicode_t unicode; /* array of unicode characters, normalized, lowercased */ rspamd_ftok_t normalized; /* normalized and lowercased utf8 */ rspamd_ftok_t stemmed; /* stemmed utf8 */ - guint flags; + unsigned int flags; } rspamd_stat_token_t; #define RSPAMD_TOKEN_VALUE_TYPE float typedef struct token_node_s { uint64_t data; - guint window_idx; - guint flags; + unsigned int window_idx; + unsigned int flags; rspamd_stat_token_t *t1; rspamd_stat_token_t *t2; RSPAMD_TOKEN_VALUE_TYPE values[0]; @@ -104,7 +104,7 @@ void rspamd_stat_process_tokenize(struct rspamd_stat_ctx *st_ctx, * @return TRUE if task has been classified */ rspamd_stat_result_t rspamd_stat_classify(struct rspamd_task *task, - lua_State *L, guint stage, GError **err); + lua_State *L, unsigned int stage, GError **err); /** @@ -124,8 +124,8 @@ gboolean rspamd_stat_check_autolearn(struct rspamd_task *task); * @return TRUE if task has been learned */ rspamd_stat_result_t rspamd_stat_learn(struct rspamd_task *task, - gboolean spam, lua_State *L, const gchar *classifier, - guint stage, + gboolean spam, lua_State *L, const char *classifier, + unsigned int stage, GError **err); /** diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index 0e1ae5432..8a5313df2 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -118,9 +118,9 @@ void rspamd_stat_init(struct rspamd_config *cfg, struct ev_loop *ev_base) struct rspamd_statfile *st; struct rspamd_classifier *cl; const ucl_object_t *cache_obj = NULL, *cache_name_obj; - const gchar *cache_name = NULL; + const char *cache_name = NULL; lua_State *L = cfg->lua_state; - guint lua_classifiers_cnt = 0, i; + unsigned int lua_classifiers_cnt = 0, i; gboolean skip_cache = FALSE; if (stat_ctx == NULL) { @@ -205,7 +205,7 @@ void rspamd_stat_init(struct rspamd_config *cfg, struct ev_loop *ev_base) } else { /* Call this function to obtain closure */ - gint err_idx, ret; + int err_idx, ret; struct rspamd_config **pcfg; lua_pushcfunction(L, &rspamd_lua_traceback); @@ -248,7 +248,7 @@ void rspamd_stat_init(struct rspamd_config *cfg, struct ev_loop *ev_base) cl = g_malloc0(sizeof(*cl)); cl->cfg = clf; cl->ctx = stat_ctx; - cl->statfiles_ids = g_array_new(FALSE, FALSE, sizeof(gint)); + cl->statfiles_ids = g_array_new(FALSE, FALSE, sizeof(int)); cl->subrs = rspamd_stat_get_classifier(clf->classifier); if (cl->subrs == NULL) { @@ -391,8 +391,8 @@ void rspamd_stat_close(void) struct rspamd_stat_ctx *st_ctx; struct rspamd_stat_async_elt *aelt; GList *cur; - guint i, j; - gint id; + unsigned int i, j; + int id; st_ctx = rspamd_stat_get_ctx(); g_assert(st_ctx != NULL); @@ -401,7 +401,7 @@ void rspamd_stat_close(void) cl = g_ptr_array_index(st_ctx->classifiers, i); for (j = 0; j < cl->statfiles_ids->len; j++) { - id = g_array_index(cl->statfiles_ids, gint, j); + id = g_array_index(cl->statfiles_ids, int, j); st = g_ptr_array_index(st_ctx->statfiles, id); if (!(st->classifier->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND)) { st->backend->close(st->bkcf); @@ -454,9 +454,9 @@ rspamd_stat_get_ctx(void) } struct rspamd_stat_classifier * -rspamd_stat_get_classifier(const gchar *name) +rspamd_stat_get_classifier(const char *name) { - guint i; + unsigned int i; if (name == NULL || name[0] == '\0') { name = RSPAMD_DEFAULT_CLASSIFIER; @@ -474,9 +474,9 @@ rspamd_stat_get_classifier(const gchar *name) } struct rspamd_stat_backend * -rspamd_stat_get_backend(const gchar *name) +rspamd_stat_get_backend(const char *name) { - guint i; + unsigned int i; if (name == NULL || name[0] == '\0') { name = RSPAMD_DEFAULT_BACKEND; @@ -494,9 +494,9 @@ rspamd_stat_get_backend(const gchar *name) } struct rspamd_stat_tokenizer * -rspamd_stat_get_tokenizer(const gchar *name) +rspamd_stat_get_tokenizer(const char *name) { - guint i; + unsigned int i; if (name == NULL || name[0] == '\0') { name = RSPAMD_DEFAULT_TOKENIZER; @@ -514,9 +514,9 @@ rspamd_stat_get_tokenizer(const gchar *name) } struct rspamd_stat_cache * -rspamd_stat_get_cache(const gchar *name) +rspamd_stat_get_cache(const char *name) { - guint i; + unsigned int i; if (name == NULL || name[0] == '\0') { name = RSPAMD_DEFAULT_CACHE; @@ -548,7 +548,7 @@ static void rspamd_async_elt_on_timer(EV_P_ ev_timer *w, int revents) { struct rspamd_stat_async_elt *elt = (struct rspamd_stat_async_elt *) w->data; - gdouble jittered_time; + double jittered_time; if (elt->enabled) { @@ -564,7 +564,7 @@ struct rspamd_stat_async_elt * rspamd_stat_ctx_register_async(rspamd_stat_async_handler handler, rspamd_stat_async_cleanup cleanup, gpointer d, - gdouble timeout) + double timeout) { struct rspamd_stat_async_elt *elt; struct rspamd_stat_ctx *st_ctx; diff --git a/src/libstat/stat_internal.h b/src/libstat/stat_internal.h index 604a2af91..96d67cbf6 100644 --- a/src/libstat/stat_internal.h +++ b/src/libstat/stat_internal.h @@ -43,14 +43,14 @@ struct rspamd_classifier { gpointer cachecf; gulong spam_learns; gulong ham_learns; - gint autolearn_cbref; + int autolearn_cbref; struct rspamd_classifier_config *cfg; struct rspamd_stat_classifier *subrs; gpointer specific; }; struct rspamd_statfile { - gint id; + int id; struct rspamd_statfile_config *stcf; struct rspamd_classifier *classifier; struct rspamd_stat_backend *backend; @@ -70,7 +70,7 @@ struct rspamd_stat_async_elt { rspamd_stat_async_cleanup cleanup; struct ev_loop *event_loop; ev_timer timer_ev; - gdouble timeout; + double timeout; gboolean enabled; gpointer ud; ref_entry_t ref; @@ -79,13 +79,13 @@ struct rspamd_stat_async_elt { struct rspamd_stat_ctx { /* Subroutines for all objects */ struct rspamd_stat_classifier *classifiers_subrs; - guint classifiers_count; + unsigned int classifiers_count; struct rspamd_stat_tokenizer *tokenizers_subrs; - guint tokenizers_count; + unsigned int tokenizers_count; struct rspamd_stat_backend *backends_subrs; - guint backends_count; + unsigned int backends_count; struct rspamd_stat_cache *caches_subrs; - guint caches_count; + unsigned int caches_count; /* Runtime configuration */ GPtrArray *statfiles; /* struct rspamd_statfile */ @@ -93,7 +93,7 @@ struct rspamd_stat_ctx { GQueue *async_elts; /* struct rspamd_stat_async_elt */ struct rspamd_config *cfg; - gint lua_stat_tokens_ref; + int lua_stat_tokens_ref; /* Global tokenizer */ struct rspamd_stat_tokenizer *tokenizer; @@ -110,17 +110,17 @@ typedef enum rspamd_learn_cache_result { struct rspamd_stat_ctx *rspamd_stat_get_ctx(void); -struct rspamd_stat_classifier *rspamd_stat_get_classifier(const gchar *name); +struct rspamd_stat_classifier *rspamd_stat_get_classifier(const char *name); -struct rspamd_stat_backend *rspamd_stat_get_backend(const gchar *name); +struct rspamd_stat_backend *rspamd_stat_get_backend(const char *name); -struct rspamd_stat_tokenizer *rspamd_stat_get_tokenizer(const gchar *name); +struct rspamd_stat_tokenizer *rspamd_stat_get_tokenizer(const char *name); -struct rspamd_stat_cache *rspamd_stat_get_cache(const gchar *name); +struct rspamd_stat_cache *rspamd_stat_get_cache(const char *name); struct rspamd_stat_async_elt *rspamd_stat_ctx_register_async( rspamd_stat_async_handler handler, rspamd_stat_async_cleanup cleanup, - gpointer d, gdouble timeout); + gpointer d, double timeout); static GQuark rspamd_stat_quark(void) { diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index c15c32bf0..7f62d4e2a 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -30,7 +30,7 @@ #define RSPAMD_LEARN_OP 1 #define RSPAMD_UNLEARN_OP 2 -static const gdouble similarity_threshold = 80.0; +static const double similarity_threshold = 80.0; static void rspamd_stat_tokenize_parts_metadata(struct rspamd_stat_ctx *st_ctx, @@ -38,7 +38,7 @@ rspamd_stat_tokenize_parts_metadata(struct rspamd_stat_ctx *st_ctx, { GArray *ar; rspamd_stat_token_t elt; - guint i; + unsigned int i; lua_State *L = task->cfg->lua_state; ar = g_array_sized_new(FALSE, FALSE, sizeof(elt), 16); @@ -46,7 +46,7 @@ rspamd_stat_tokenize_parts_metadata(struct rspamd_stat_ctx *st_ctx, elt.flags = RSPAMD_STAT_TOKEN_FLAG_META; if (st_ctx->lua_stat_tokens_ref != -1) { - gint err_idx, ret; + int err_idx, ret; struct rspamd_task **ptask; lua_pushcfunction(L, &rspamd_lua_traceback); @@ -69,7 +69,7 @@ rspamd_stat_tokenize_parts_metadata(struct rspamd_stat_ctx *st_ctx, lua_typename(L, lua_type(L, -1))); } else { - guint vlen; + unsigned int vlen; rspamd_ftok_t tok; vlen = rspamd_lua_table_size(L, -1); @@ -121,10 +121,10 @@ void rspamd_stat_process_tokenize(struct rspamd_stat_ctx *st_ctx, struct rspamd_mime_text_part *part; rspamd_cryptobox_hash_state_t hst; rspamd_token_t *st_tok; - guint i, reserved_len = 0; - gdouble *pdiff; - guchar hout[rspamd_cryptobox_HASHBYTES]; - gchar *b32_hout; + unsigned int i, reserved_len = 0; + double *pdiff; + unsigned char hout[rspamd_cryptobox_HASHBYTES]; + char *b32_hout; if (st_ctx == NULL) { st_ctx = rspamd_stat_get_ctx(); @@ -179,7 +179,7 @@ void rspamd_stat_process_tokenize(struct rspamd_stat_ctx *st_ctx, PTR_ARRAY_FOREACH(task->tokens, i, st_tok) { - rspamd_cryptobox_hash_update(&hst, (guchar *) &st_tok->data, + rspamd_cryptobox_hash_update(&hst, (unsigned char *) &st_tok->data, sizeof(st_tok->data)); } @@ -203,9 +203,9 @@ rspamd_stat_classifier_is_skipped(struct rspamd_task *task, gboolean ret = FALSE; while (cur) { - gint cb_ref = GPOINTER_TO_INT(cur->data); - gint old_top = lua_gettop(L); - gint nargs; + int cb_ref = GPOINTER_TO_INT(cur->data); + int old_top = lua_gettop(L); + int nargs; lua_rawgeti(L, LUA_REGISTRYINDEX, cb_ref); /* Push task and two booleans: is_spam and is_unlearn */ @@ -269,7 +269,7 @@ static void rspamd_stat_preprocess(struct rspamd_stat_ctx *st_ctx, struct rspamd_task *task, gboolean is_learn, gboolean is_spam) { - guint i; + unsigned int i; struct rspamd_statfile *st; gpointer bk_run; @@ -303,7 +303,7 @@ rspamd_stat_preprocess(struct rspamd_stat_ctx *st_ctx, if (skip_classifier) { /* Set NULL for all statfiles indexed by id */ for (int j = 0; j < cl->statfiles_ids->len; j++) { - int id = g_array_index(cl->statfiles_ids, gint, j); + int id = g_array_index(cl->statfiles_ids, int, j); g_ptr_array_index(task->stat_runtimes, id) = NULL; } } @@ -347,7 +347,7 @@ static void rspamd_stat_backends_process(struct rspamd_stat_ctx *st_ctx, struct rspamd_task *task) { - guint i; + unsigned int i; struct rspamd_statfile *st; gpointer bk_run; @@ -367,7 +367,7 @@ static void rspamd_stat_classifiers_process(struct rspamd_stat_ctx *st_ctx, struct rspamd_task *task) { - guint i, j, id; + unsigned int i, j, id; struct rspamd_classifier *cl; struct rspamd_statfile *st; gpointer bk_run; @@ -429,7 +429,7 @@ rspamd_stat_classifiers_process(struct rspamd_stat_ctx *st_ctx, /* Do not process classifiers on backend failures */ for (j = 0; j < cl->statfiles_ids->len; j++) { - id = g_array_index(cl->statfiles_ids, gint, j); + id = g_array_index(cl->statfiles_ids, int, j); bk_run = g_ptr_array_index(task->stat_runtimes, id); st = g_ptr_array_index(st_ctx->statfiles, id); @@ -444,7 +444,7 @@ rspamd_stat_classifiers_process(struct rspamd_stat_ctx *st_ctx, /* Ensure that all symbols enabled */ if (!skip && !(cl->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND)) { for (j = 0; j < cl->statfiles_ids->len; j++) { - id = g_array_index(cl->statfiles_ids, gint, j); + id = g_array_index(cl->statfiles_ids, int, j); bk_run = g_ptr_array_index(task->stat_runtimes, id); st = g_ptr_array_index(st_ctx->statfiles, id); @@ -483,7 +483,7 @@ rspamd_stat_classifiers_process(struct rspamd_stat_ctx *st_ctx, } rspamd_stat_result_t -rspamd_stat_classify(struct rspamd_task *task, lua_State *L, guint stage, +rspamd_stat_classify(struct rspamd_task *task, lua_State *L, unsigned int stage, GError **err) { struct rspamd_stat_ctx *st_ctx; @@ -518,14 +518,14 @@ rspamd_stat_classify(struct rspamd_task *task, lua_State *L, guint stage, static gboolean rspamd_stat_cache_check(struct rspamd_stat_ctx *st_ctx, struct rspamd_task *task, - const gchar *classifier, + const char *classifier, gboolean spam, GError **err) { rspamd_learn_t learn_res = RSPAMD_LEARN_OK; struct rspamd_classifier *cl, *sel = NULL; gpointer rt; - guint i; + unsigned int i; /* Check whether we have learned that file */ for (i = 0; i < st_ctx->classifiers->len; i++) { @@ -579,12 +579,12 @@ rspamd_stat_cache_check(struct rspamd_stat_ctx *st_ctx, static gboolean rspamd_stat_classifiers_learn(struct rspamd_stat_ctx *st_ctx, struct rspamd_task *task, - const gchar *classifier, + const char *classifier, gboolean spam, GError **err) { struct rspamd_classifier *cl, *sel = NULL; - guint i; + unsigned int i; gboolean learned = FALSE, too_small = FALSE, too_large = FALSE; if ((task->flags & RSPAMD_TASK_FLAG_ALREADY_LEARNED) && err != NULL && @@ -680,15 +680,15 @@ rspamd_stat_classifiers_learn(struct rspamd_stat_ctx *st_ctx, static gboolean rspamd_stat_backends_learn(struct rspamd_stat_ctx *st_ctx, struct rspamd_task *task, - const gchar *classifier, + const char *classifier, gboolean spam, GError **err) { struct rspamd_classifier *cl, *sel = NULL; struct rspamd_statfile *st; gpointer bk_run; - guint i, j; - gint id; + unsigned int i, j; + int id; gboolean res = FALSE, backend_found = FALSE; for (i = 0; i < st_ctx->classifiers->len; i++) { @@ -708,7 +708,7 @@ rspamd_stat_backends_learn(struct rspamd_stat_ctx *st_ctx, sel = cl; for (j = 0; j < cl->statfiles_ids->len; j++) { - id = g_array_index(cl->statfiles_ids, gint, j); + id = g_array_index(cl->statfiles_ids, int, j); st = g_ptr_array_index(st_ctx->statfiles, id); bk_run = g_ptr_array_index(task->stat_runtimes, id); @@ -802,15 +802,15 @@ end: static gboolean rspamd_stat_backends_post_learn(struct rspamd_stat_ctx *st_ctx, struct rspamd_task *task, - const gchar *classifier, + const char *classifier, gboolean spam, GError **err) { struct rspamd_classifier *cl; struct rspamd_statfile *st; gpointer bk_run, cache_run; - guint i, j; - gint id; + unsigned int i, j; + int id; gboolean res = TRUE; for (i = 0; i < st_ctx->classifiers->len; i++) { @@ -828,7 +828,7 @@ rspamd_stat_backends_post_learn(struct rspamd_stat_ctx *st_ctx, } for (j = 0; j < cl->statfiles_ids->len; j++) { - id = g_array_index(cl->statfiles_ids, gint, j); + id = g_array_index(cl->statfiles_ids, int, j); st = g_ptr_array_index(st_ctx->statfiles, id); bk_run = g_ptr_array_index(task->stat_runtimes, id); @@ -857,7 +857,7 @@ rspamd_stat_backends_post_learn(struct rspamd_stat_ctx *st_ctx, rspamd_stat_result_t rspamd_stat_learn(struct rspamd_task *task, - gboolean spam, lua_State *L, const gchar *classifier, guint stage, + gboolean spam, lua_State *L, const char *classifier, unsigned int stage, GError **err) { struct rspamd_stat_ctx *st_ctx; @@ -925,8 +925,8 @@ rspamd_stat_has_classifier_symbols(struct rspamd_task *task, struct rspamd_scan_result *mres, struct rspamd_classifier *cl) { - guint i; - gint id; + unsigned int i; + int id; struct rspamd_statfile *st; struct rspamd_stat_ctx *st_ctx; gboolean is_spam; @@ -939,7 +939,7 @@ rspamd_stat_has_classifier_symbols(struct rspamd_task *task, is_spam = !!(task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM); for (i = 0; i < cl->statfiles_ids->len; i++) { - id = g_array_index(cl->statfiles_ids, gint, i); + id = g_array_index(cl->statfiles_ids, int, i); st = g_ptr_array_index(st_ctx->statfiles, id); if (rspamd_task_find_symbol_result(task, st->stcf->symbol, NULL)) { @@ -965,11 +965,11 @@ rspamd_stat_check_autolearn(struct rspamd_task *task) struct rspamd_scan_result *mres = NULL; struct rspamd_task **ptask; lua_State *L; - guint i; - gint err_idx; + unsigned int i; + int err_idx; gboolean ret = FALSE; - gdouble ham_score, spam_score; - const gchar *lua_script, *lua_ret; + double ham_score, spam_score; + const char *lua_script, *lua_ret; g_assert(RSPAMD_TASK_IS_CLASSIFIED(task)); st_ctx = rspamd_stat_get_ctx(); @@ -1025,7 +1025,7 @@ rspamd_stat_check_autolearn(struct rspamd_task *task) spam_score = ucl_object_todouble(elt2); if (ham_score > spam_score) { - gdouble t; + double t; t = ham_score; ham_score = spam_score; @@ -1198,8 +1198,8 @@ rspamd_stat_statistics(struct rspamd_task *task, gpointer backend_runtime; ucl_object_t *res = NULL, *elt; uint64_t learns = 0; - guint i, j; - gint id; + unsigned int i, j; + int id; st_ctx = rspamd_stat_get_ctx(); g_assert(st_ctx != NULL); @@ -1214,7 +1214,7 @@ rspamd_stat_statistics(struct rspamd_task *task, } for (j = 0; j < cl->statfiles_ids->len; j++) { - id = g_array_index(cl->statfiles_ids, gint, j); + id = g_array_index(cl->statfiles_ids, int, j); st = g_ptr_array_index(st_ctx->statfiles, id); backend_runtime = st->backend->runtime(task, st->stcf, FALSE, st->bkcf, id); diff --git a/src/libstat/tokenizers/osb.c b/src/libstat/tokenizers/osb.c index 3f770c69e..039ead231 100644 --- a/src/libstat/tokenizers/osb.c +++ b/src/libstat/tokenizers/osb.c @@ -49,7 +49,7 @@ static const int primes[] = { 3277, }; -static const guchar osb_tokenizer_magic[] = {'o', 's', 'b', 't', 'o', 'k', 'v', '2'}; +static const unsigned char osb_tokenizer_magic[] = {'o', 's', 'b', 't', 'o', 'k', 'v', '2'}; enum rspamd_osb_hash_type { RSPAMD_OSB_HASH_COMPAT = 0, @@ -58,7 +58,7 @@ enum rspamd_osb_hash_type { }; struct rspamd_osb_tokenizer_config { - guchar magic[8]; + unsigned char magic[8]; gshort version; gshort window_size; enum rspamd_osb_hash_type ht; @@ -92,7 +92,7 @@ rspamd_tokenizer_osb_config_from_ucl(rspamd_mempool_t *pool, { const ucl_object_t *elt; struct rspamd_osb_tokenizer_config *cf, *def; - guchar *key = NULL; + unsigned char *key = NULL; gsize keylen; @@ -266,12 +266,12 @@ struct token_pipe_entry { rspamd_stat_token_t *t; }; -gint rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx, - struct rspamd_task *task, - GArray *words, - gboolean is_utf, - const gchar *prefix, - GPtrArray *result) +int rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx, + struct rspamd_task *task, + GArray *words, + gboolean is_utf, + const char *prefix, + GPtrArray *result) { rspamd_token_t *new_tok = NULL; rspamd_stat_token_t *token; @@ -280,7 +280,7 @@ gint rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx, struct token_pipe_entry *hashpipe; uint32_t h1, h2; gsize token_size; - guint processed = 0, i, w, window_size, token_flags = 0; + unsigned int processed = 0, i, w, window_size, token_flags = 0; if (words == NULL) { return FALSE; @@ -309,7 +309,7 @@ gint rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx, for (w = 0; w < words->len; w++) { token = &g_array_index(words, rspamd_stat_token_t, w); token_flags = token->flags; - const gchar *begin; + const char *begin; gsize len; if (token->flags & @@ -341,7 +341,7 @@ gint rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx, begin, len, osb_cf->seed); } else { - rspamd_cryptobox_siphash((guchar *) &cur, begin, + rspamd_cryptobox_siphash((unsigned char *) &cur, begin, len, osb_cf->sk); if (prefix) { @@ -373,8 +373,8 @@ gint rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx, ((uint32_t) hashpipe[i].h) * primes[i << 1]; \ h2 = ((uint32_t) hashpipe[0].h) * primes[1] + \ ((uint32_t) hashpipe[i].h) * primes[(i << 1) - 1]; \ - memcpy((guchar *) &new_tok->data, &h1, sizeof(h1)); \ - memcpy(((guchar *) &new_tok->data) + sizeof(h1), &h2, sizeof(h2)); \ + memcpy((unsigned char *) &new_tok->data, &h1, sizeof(h1)); \ + memcpy(((unsigned char *) &new_tok->data) + sizeof(h1), &h2, sizeof(h2)); \ } \ else { \ new_tok->data = hashpipe[0].h * primes[0] + hashpipe[i].h * primes[i << 1]; \ diff --git a/src/libstat/tokenizers/tokenizers.c b/src/libstat/tokenizers/tokenizers.c index 702668142..0ea1bcfc6 100644 --- a/src/libstat/tokenizers/tokenizers.c +++ b/src/libstat/tokenizers/tokenizers.c @@ -35,11 +35,11 @@ #include -typedef gboolean (*token_get_function)(rspamd_stat_token_t *buf, gchar const **pos, +typedef gboolean (*token_get_function)(rspamd_stat_token_t *buf, char const **pos, rspamd_stat_token_t *token, GList **exceptions, gsize *rl, gboolean check_signature); -const gchar t_delimiters[256] = { +const char t_delimiters[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -70,11 +70,11 @@ const gchar t_delimiters[256] = { /* Get next word from specified f_str_t buf */ static gboolean rspamd_tokenizer_get_word_raw(rspamd_stat_token_t *buf, - gchar const **cur, rspamd_stat_token_t *token, + char const **cur, rspamd_stat_token_t *token, GList **exceptions, gsize *rl, gboolean unused) { gsize remain, pos; - const gchar *p; + const char *p; struct rspamd_process_exception *ex = NULL; if (buf == NULL) { @@ -127,11 +127,11 @@ rspamd_tokenizer_get_word_raw(rspamd_stat_token_t *buf, pos++; p++; remain--; - } while (remain > 0 && t_delimiters[(guchar) *p]); + } while (remain > 0 && t_delimiters[(unsigned char) *p]); token->original.begin = p; - while (remain > 0 && !t_delimiters[(guchar) *p]) { + while (remain > 0 && !t_delimiters[(unsigned char) *p]) { if (ex != NULL && ex->pos == pos) { *exceptions = g_list_next(*exceptions); *cur = p + ex->len; @@ -160,15 +160,15 @@ rspamd_tokenizer_get_word_raw(rspamd_stat_token_t *buf, static inline gboolean rspamd_tokenize_check_limit(gboolean decay, - guint word_decay, - guint nwords, + unsigned int word_decay, + unsigned int nwords, uint64_t *hv, uint64_t *prob, const rspamd_stat_token_t *token, gssize remain, gssize total) { - static const gdouble avg_word_len = 6.0; + static const double avg_word_len = 6.0; if (!decay) { if (token->original.len >= sizeof(uint64_t)) { @@ -180,12 +180,12 @@ rspamd_tokenize_check_limit(gboolean decay, /* Check for decay */ if (word_decay > 0 && nwords > word_decay && remain < (gssize) total) { /* Start decay */ - gdouble decay_prob; + double decay_prob; *hv = mum_hash_finish(*hv); /* We assume that word is 6 symbols length in average */ - decay_prob = (gdouble) word_decay / ((total - (remain)) / avg_word_len) * 10; + decay_prob = (double) word_decay / ((total - (remain)) / avg_word_len) * 10; decay_prob = floor(decay_prob) / 10.0; if (decay_prob >= 1.0) { @@ -212,10 +212,10 @@ rspamd_tokenize_check_limit(gboolean decay, } static inline gboolean -rspamd_utf_word_valid(const guchar *text, const guchar *end, +rspamd_utf_word_valid(const unsigned char *text, const unsigned char *end, int32_t start, int32_t finish) { - const guchar *st = text + start, *fin = text + finish; + const unsigned char *st = text + start, *fin = text + finish; UChar32 c; if (st >= end || fin > end || st >= fin) { @@ -278,7 +278,7 @@ rspamd_tokenize_exception(struct rspamd_process_exception *ex, GArray *res) GArray * -rspamd_tokenize_text(const gchar *text, gsize len, +rspamd_tokenize_text(const char *text, gsize len, const UText *utxt, enum rspamd_tokenize_type how, struct rspamd_config *cfg, @@ -288,11 +288,11 @@ rspamd_tokenize_text(const gchar *text, gsize len, rspamd_mempool_t *pool) { rspamd_stat_token_t token, buf; - const gchar *pos = NULL; + const char *pos = NULL; gsize l = 0; GArray *res; GList *cur = exceptions; - guint min_len = 0, max_len = 0, word_decay = 0, initial_size = 128; + unsigned int min_len = 0, max_len = 0, word_decay = 0, initial_size = 128; uint64_t hv = 0; gboolean decay = FALSE, long_text_mode = FALSE; uint64_t prob = 0; @@ -429,7 +429,7 @@ rspamd_tokenize_text(const gchar *text, gsize len, msg_warn_pool_check( "tokenization reversed back on position %d," "%d new position (%d backward), likely libicu bug!", - (gint) (p), (gint) (old_p), old_p - p); + (int) (p), (int) (old_p), old_p - p); goto end; } @@ -468,7 +468,7 @@ rspamd_tokenize_text(const gchar *text, gsize len, msg_warn_pool_check( "tokenization reversed back on position %d," "%d new position (%d backward), likely libicu bug!", - (gint) (p), (gint) (old_p), old_p - p); + (int) (p), (int) (old_p), old_p - p); goto end; } @@ -573,7 +573,7 @@ rspamd_tokenize_text(const gchar *text, gsize len, if (p != UBRK_DONE && p <= last) { msg_warn_pool_check("tokenization reversed back on position %d," "%d new position (%d backward), likely libicu bug!", - (gint) (p), (gint) (last), last - p); + (int) (p), (int) (last), last - p); goto end; } @@ -595,12 +595,12 @@ end: #undef SHIFT_EX static void -rspamd_add_metawords_from_str(const gchar *beg, gsize len, +rspamd_add_metawords_from_str(const char *beg, gsize len, struct rspamd_task *task) { UText utxt = UTEXT_INITIALIZER; UErrorCode uc_err = U_ZERO_ERROR; - guint i = 0; + unsigned int i = 0; UChar32 uc; gboolean valid_utf = TRUE; @@ -649,7 +649,7 @@ rspamd_add_metawords_from_str(const gchar *beg, gsize len, void rspamd_tokenize_meta_words(struct rspamd_task *task) { - guint i = 0; + unsigned int i = 0; rspamd_stat_token_t *tok; if (MESSAGE_FIELD(task, subject)) { @@ -668,7 +668,7 @@ void rspamd_tokenize_meta_words(struct rspamd_task *task) } if (task->meta_words != NULL) { - const gchar *language = NULL; + const char *language = NULL; if (MESSAGE_FIELD(task, text_parts) && MESSAGE_FIELD(task, text_parts)->len > 0) { @@ -736,9 +736,9 @@ static inline void rspamd_ucs32_to_normalised(rspamd_stat_token_t *tok, rspamd_mempool_t *pool) { - guint i, doff = 0; + unsigned int i, doff = 0; gsize utflen = 0; - gchar *dest; + char *dest; UChar32 t; for (i = 0; i < tok->unicode.len; i++) { @@ -822,7 +822,7 @@ void rspamd_normalize_single_word(rspamd_stat_token_t *tok, rspamd_mempool_t *po if (!U_SUCCESS(uc_err)) { if (uc_err != U_BUFFER_OVERFLOW_ERROR) { msg_warn_pool_check("cannot normalise text '%*s': %s", - (gint) tok->original.len, tok->original.begin, + (int) tok->original.len, tok->original.begin, u_errorName(uc_err)); rspamd_uchars_to_ucs32(tmpbuf, ulen, tok, pool); rspamd_ucs32_to_normalised(tok, pool); @@ -847,7 +847,7 @@ void rspamd_normalize_single_word(rspamd_stat_token_t *tok, rspamd_mempool_t *po else { if (tok->flags & RSPAMD_STAT_TOKEN_FLAG_TEXT) { /* Simple lowercase */ - gchar *dest; + char *dest; dest = rspamd_mempool_alloc(pool, tok->original.len + 1); rspamd_strlcpy(dest, tok->original.begin, tok->original.len + 1); @@ -861,7 +861,7 @@ void rspamd_normalize_single_word(rspamd_stat_token_t *tok, rspamd_mempool_t *po void rspamd_normalize_words(GArray *words, rspamd_mempool_t *pool) { rspamd_stat_token_t *tok; - guint i; + unsigned int i; for (i = 0; i < words->len; i++) { tok = &g_array_index(words, rspamd_stat_token_t, i); @@ -870,14 +870,14 @@ void rspamd_normalize_words(GArray *words, rspamd_mempool_t *pool) } void rspamd_stem_words(GArray *words, rspamd_mempool_t *pool, - const gchar *language, + const char *language, struct rspamd_lang_detector *lang_detector) { static GHashTable *stemmers = NULL; struct sb_stemmer *stem = NULL; - guint i; + unsigned int i; rspamd_stat_token_t *tok; - gchar *dest; + char *dest; gsize dlen; if (!stemmers) { @@ -914,7 +914,7 @@ void rspamd_stem_words(GArray *words, rspamd_mempool_t *pool, if (tok->flags & RSPAMD_STAT_TOKEN_FLAG_UTF) { if (stem) { - const gchar *stemmed = NULL; + const char *stemmed = NULL; stemmed = sb_stemmer_stem(stem, tok->normalized.begin, tok->normalized.len); diff --git a/src/libstat/tokenizers/tokenizers.h b/src/libstat/tokenizers/tokenizers.h index ff5c530c5..d4a8824a8 100644 --- a/src/libstat/tokenizers/tokenizers.h +++ b/src/libstat/tokenizers/tokenizers.h @@ -36,17 +36,17 @@ struct rspamd_stat_ctx; /* Common tokenizer structure */ struct rspamd_stat_tokenizer { - gchar *name; + char *name; gpointer (*get_config)(rspamd_mempool_t *pool, struct rspamd_tokenizer_config *cf, gsize *len); - gint (*tokenize_func)(struct rspamd_stat_ctx *ctx, - struct rspamd_task *task, - GArray *words, - gboolean is_utf, - const gchar *prefix, - GPtrArray *result); + int (*tokenize_func)(struct rspamd_stat_ctx *ctx, + struct rspamd_task *task, + GArray *words, + gboolean is_utf, + const char *prefix, + GPtrArray *result); }; enum rspamd_tokenize_type { @@ -56,11 +56,11 @@ enum rspamd_tokenize_type { }; /* Compare two token nodes */ -gint token_node_compare_func(gconstpointer a, gconstpointer b); +int token_node_compare_func(gconstpointer a, gconstpointer b); /* Tokenize text into array of words (rspamd_stat_token_t type) */ -GArray *rspamd_tokenize_text(const gchar *text, gsize len, +GArray *rspamd_tokenize_text(const char *text, gsize len, const UText *utxt, enum rspamd_tokenize_type how, struct rspamd_config *cfg, @@ -70,12 +70,12 @@ GArray *rspamd_tokenize_text(const gchar *text, gsize len, rspamd_mempool_t *pool); /* OSB tokenize function */ -gint rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx, - struct rspamd_task *task, - GArray *words, - gboolean is_utf, - const gchar *prefix, - GPtrArray *result); +int rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx, + struct rspamd_task *task, + GArray *words, + gboolean is_utf, + const char *prefix, + GPtrArray *result); gpointer rspamd_tokenizer_osb_get_config(rspamd_mempool_t *pool, struct rspamd_tokenizer_config *cf, @@ -88,7 +88,7 @@ void rspamd_normalize_single_word(rspamd_stat_token_t *tok, rspamd_mempool_t *po void rspamd_normalize_words(GArray *words, rspamd_mempool_t *pool); void rspamd_stem_words(GArray *words, rspamd_mempool_t *pool, - const gchar *language, + const char *language, struct rspamd_lang_detector *lang_detector); void rspamd_tokenize_meta_words(struct rspamd_task *task); diff --git a/src/libutil/addr.c b/src/libutil/addr.c index a7dafe43b..3cac4de87 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -55,7 +55,7 @@ union sa_inet { struct rspamd_addr_unix { struct sockaddr_un addr; - gint mode; + int mode; uid_t owner; gid_t group; }; @@ -69,7 +69,7 @@ struct rspamd_inet_addr_s { struct rspamd_addr_inet in; struct rspamd_addr_unix *un; } u; - gint af; + int af; socklen_t slen; }; @@ -109,7 +109,7 @@ rspamd_ip_validate_af(rspamd_inet_addr_t *addr) (pool != NULL) ? rspamd_mempool_alloc0((pool), (sz)) : g_malloc0(sz) static rspamd_inet_addr_t * -rspamd_inet_addr_create(gint af, rspamd_mempool_t *pool) +rspamd_inet_addr_create(int af, rspamd_mempool_t *pool) { rspamd_inet_addr_t *addr; @@ -144,7 +144,7 @@ static void rspamd_ip_check_ipv6(void) { if (ipv6_status == RSPAMD_IPV6_UNDEFINED) { - gint s; + int s; s = socket(AF_INET6, SOCK_STREAM, 0); @@ -200,11 +200,11 @@ rspamd_ip_is_valid(const rspamd_inet_addr_t *addr) return ret; } -gint rspamd_accept_from_socket(gint sock, rspamd_inet_addr_t **target, - rspamd_accept_throttling_handler hdl, - void *hdl_data) +int rspamd_accept_from_socket(int sock, rspamd_inet_addr_t **target, + rspamd_accept_throttling_handler hdl, + void *hdl_data) { - gint nfd, serrno; + int nfd, serrno; union sa_union su; socklen_t len = sizeof(su); rspamd_inet_addr_t *addr = NULL; @@ -232,12 +232,12 @@ gint rspamd_accept_from_socket(gint sock, rspamd_inet_addr_t **target, if (su.sa.sa_family == AF_INET6) { /* Deal with bloody v4 mapped to v6 addresses */ - static const guint8 mask[] = { + static const uint8_t mask[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - const guint8 *p; + const uint8_t *p; - if (memcmp((const guint8 *) &su.s6.sin6_addr, mask, sizeof(mask)) == 0) { - p = (const guint8 *) &su.s6.sin6_addr; + if (memcmp((const uint8_t *) &su.s6.sin6_addr, mask, sizeof(mask)) == 0) { + p = (const uint8_t *) &su.s6.sin6_addr; if ((p[10] == 0xff && p[11] == 0xff)) { addr = rspamd_inet_addr_create(AF_INET, NULL); @@ -313,7 +313,7 @@ rspamd_parse_unix_path(rspamd_inet_addr_t **target, rspamd_mempool_t *pool, enum rspamd_inet_address_parse_flags how) { - gchar **tokens, **cur_tok, *p, *pwbuf; + char **tokens, **cur_tok, *p, *pwbuf; glong pwlen; struct passwd pw, *ppw; struct group gr, *pgr; @@ -456,12 +456,12 @@ err: } gboolean -rspamd_parse_inet_address_ip4(const guchar *text, gsize len, gpointer target) +rspamd_parse_inet_address_ip4(const unsigned char *text, gsize len, gpointer target) { - const guchar *p; - guchar c; + const unsigned char *p; + unsigned char c; uint32_t addr = 0, *addrptr = target; - guint octet = 0, n = 0; + unsigned int octet = 0, n = 0; g_assert(text != NULL); g_assert(target != NULL); @@ -504,12 +504,12 @@ rspamd_parse_inet_address_ip4(const guchar *text, gsize len, gpointer target) } gboolean -rspamd_parse_inet_address_ip6(const guchar *text, gsize len, gpointer target) +rspamd_parse_inet_address_ip6(const unsigned char *text, gsize len, gpointer target) { - guchar t, *zero = NULL, *s, *d, *addr = target; - const guchar *p, *digit = NULL, *percent; + unsigned char t, *zero = NULL, *s, *d, *addr = target; + const unsigned char *p, *digit = NULL, *percent; gsize len4 = 0; - guint n = 8, nibbles = 0, word = 0; + unsigned int n = 8, nibbles = 0, word = 0; g_assert(text != NULL); g_assert(target != NULL); @@ -582,8 +582,8 @@ rspamd_parse_inet_address_ip6(const guchar *text, gsize len, gpointer target) } word = ntohl(word); - *addr++ = (guchar) ((word >> 24) & 0xff); - *addr++ = (guchar) ((word >> 16) & 0xff); + *addr++ = (unsigned char) ((word >> 24) & 0xff); + *addr++ = (unsigned char) ((word >> 16) & 0xff); n--; break; } @@ -613,8 +613,8 @@ rspamd_parse_inet_address_ip6(const guchar *text, gsize len, gpointer target) return FALSE; } - *addr++ = (guchar) (word >> 8); - *addr++ = (guchar) (word & 0xff); + *addr++ = (unsigned char) (word >> 8); + *addr++ = (unsigned char) (word & 0xff); if (--n) { if (zero) { @@ -645,12 +645,12 @@ rspamd_inet_address_v6_maybe_map(const struct sockaddr_in6 *sin6, { rspamd_inet_addr_t *addr = NULL; /* 10 zero bytes or 80 bits */ - static const guint8 mask[] = { + static const uint8_t mask[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - const guint8 *p; + const uint8_t *p; - if (memcmp((const guint8 *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) { - p = (const guint8 *) &sin6->sin6_addr; + if (memcmp((const uint8_t *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) { + p = (const uint8_t *) &sin6->sin6_addr; if ((p[10] == 0xff && p[11] == 0xff)) { addr = rspamd_inet_addr_create(AF_INET, pool); @@ -678,12 +678,12 @@ rspamd_inet_address_v6_maybe_map_static(const struct sockaddr_in6 *sin6, rspamd_inet_addr_t *addr) { /* 10 zero bytes or 80 bits */ - static const guint8 mask[] = { + static const uint8_t mask[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - const guint8 *p; + const uint8_t *p; - if (memcmp((const guint8 *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) { - p = (const guint8 *) &sin6->sin6_addr; + if (memcmp((const uint8_t *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) { + p = (const uint8_t *) &sin6->sin6_addr; if ((p[10] == 0xff && p[11] == 0xff)) { memcpy(&addr->u.in.addr.s4.sin_addr, &p[12], @@ -719,7 +719,7 @@ rspamd_parse_inet_address_common(rspamd_inet_addr_t **target, union sa_inet su; const char *end = NULL; char ipbuf[INET6_ADDRSTRLEN + 1]; - guint iplen; + unsigned int iplen; gulong portnum; if (srclen == 0) { @@ -737,7 +737,7 @@ rspamd_parse_inet_address_common(rspamd_inet_addr_t **target, } if (src[0] == '[') { - const gchar *ip_start; + const char *ip_start; /* Ipv6 address in format [::1]:port or just [::1] */ end = memchr(src + 1, ']', srclen - 1); @@ -851,7 +851,7 @@ rspamd_parse_inet_address_ip(const char *src, gsize srclen, { const char *end; char ipbuf[INET6_ADDRSTRLEN + 1]; - guint iplen; + unsigned int iplen; gulong portnum; gboolean ret = FALSE; union sa_inet su; @@ -951,7 +951,7 @@ const char * rspamd_inet_address_to_string(const rspamd_inet_addr_t *addr) { static char addr_str[NADDR_BUFS][INET6_ADDRSTRLEN + 1]; - static guint cur_addr = 0; + static unsigned int cur_addr = 0; char *addr_buf; if (addr == NULL) { @@ -980,7 +980,7 @@ const char * rspamd_inet_address_to_string_pretty(const rspamd_inet_addr_t *addr) { static char addr_str[NADDR_BUFS][PRETTY_IP_BUFSIZE]; - static guint cur_addr = 0; + static unsigned int cur_addr = 0; char *addr_buf; if (addr == NULL) { @@ -1034,7 +1034,7 @@ void rspamd_inet_address_set_port(rspamd_inet_addr_t *addr, uint16_t port) } } -int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, gint type, +int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, int type, gboolean async) { int fd, r; @@ -1084,12 +1084,12 @@ int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, gint type, return fd; } -int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type, +int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, int type, enum rspamd_inet_address_listen_opts opts, - gint listen_queue) + int listen_queue) { - gint fd, r; - gint on = 1, serrno; + int fd, r; + int on = 1, serrno; const struct sockaddr *sa; const char *path; @@ -1116,7 +1116,7 @@ int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type, } #if defined(SO_REUSEADDR) - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(gint)) == -1) { + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(int)) == -1) { msg_err("cannot set SO_REUSEADDR on %s (fd=%d): %s", rspamd_inet_address_to_string_pretty(addr), fd, strerror(errno)); @@ -1128,7 +1128,7 @@ int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type, if (opts & RSPAMD_INET_ADDRESS_LISTEN_REUSEPORT) { on = 1; - if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (const void *) &on, sizeof(gint)) == -1) { + if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (const void *) &on, sizeof(int)) == -1) { msg_err("cannot set SO_REUSEPORT on %s (fd=%d): %s", rspamd_inet_address_to_string_pretty(addr), fd, strerror(errno)); @@ -1142,9 +1142,9 @@ int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type, /* We need to set this flag to avoid errors */ on = 1; #ifdef SOL_IPV6 - (void) setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(gint)); + (void) setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(int)); #elif defined(IPPROTO_IPV6) - (void) setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(gint)); + (void) setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(int)); #endif } #endif @@ -1210,7 +1210,7 @@ err: } gssize -rspamd_inet_address_recvfrom(gint fd, void *buf, gsize len, gint fl, +rspamd_inet_address_recvfrom(int fd, void *buf, gsize len, int fl, rspamd_inet_addr_t **target) { gssize ret; @@ -1245,7 +1245,7 @@ rspamd_inet_address_recvfrom(gint fd, void *buf, gsize len, gint fl, } gssize -rspamd_inet_address_sendto(gint fd, const void *buf, gsize len, gint fl, +rspamd_inet_address_sendto(int fd, const void *buf, gsize len, int fl, const rspamd_inet_addr_t *addr) { gssize r; @@ -1271,12 +1271,12 @@ rspamd_inet_address_sendto(gint fd, const void *buf, gsize len, gint fl, } static gboolean -rspamd_check_port_priority(const char *line, guint default_port, - guint *priority, gchar *out, +rspamd_check_port_priority(const char *line, unsigned int default_port, + unsigned int *priority, char *out, gsize outlen, rspamd_mempool_t *pool) { - guint real_port = default_port, real_priority = 0; - gchar *err_str, *err_str_prio; + unsigned int real_port = default_port, real_priority = 0; + char *err_str, *err_str_prio; if (line && line[0] == ':') { errno = 0; @@ -1318,13 +1318,13 @@ rspamd_check_port_priority(const char *line, guint default_port, static enum rspamd_parse_host_port_result rspamd_resolve_addrs(const char *begin, size_t len, GPtrArray **addrs, - const gchar *portbuf, gint flags, + const char *portbuf, int flags, rspamd_mempool_t *pool) { struct addrinfo hints, *res, *cur; rspamd_inet_addr_t *cur_addr = NULL; - gint r, addr_cnt; - gchar *addr_cpy = NULL; + int r, addr_cnt; + char *addr_cpy = NULL; enum rspamd_parse_host_port_result ret = RSPAMD_PARSE_ADDR_FAIL; rspamd_ip_check_ipv6(); @@ -1428,16 +1428,16 @@ rspamd_resolve_addrs(const char *begin, size_t len, GPtrArray **addrs, } enum rspamd_parse_host_port_result -rspamd_parse_host_port_priority(const gchar *str, +rspamd_parse_host_port_priority(const char *str, GPtrArray **addrs, - guint *priority, - gchar **name_ptr, - guint default_port, + unsigned int *priority, + char **name_ptr, + unsigned int default_port, gboolean allow_listen, rspamd_mempool_t *pool) { - gchar portbuf[8]; - const gchar *p, *name = NULL; + char portbuf[8]; + const char *p, *name = NULL; gsize namelen; rspamd_inet_addr_t *cur_addr = NULL; enum rspamd_parse_host_port_result ret = RSPAMD_PARSE_ADDR_FAIL; @@ -1571,7 +1571,7 @@ rspamd_parse_host_port_priority(const gchar *str, portbuf, 0, pool); } else { - const gchar *second_semicolon = strchr(p + 1, ':'); + const char *second_semicolon = strchr(p + 1, ':'); name = str; @@ -1608,10 +1608,10 @@ rspamd_parse_host_port_priority(const gchar *str, return ret; } -guchar * -rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, guint *klen) +unsigned char * +rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, unsigned int *klen) { - guchar *res = NULL; + unsigned char *res = NULL; static struct in_addr local = {INADDR_LOOPBACK}; g_assert(addr != NULL); @@ -1619,15 +1619,15 @@ rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, guint *klen) if (addr->af == AF_INET) { *klen = sizeof(struct in_addr); - res = (guchar *) &addr->u.in.addr.s4.sin_addr; + res = (unsigned char *) &addr->u.in.addr.s4.sin_addr; } else if (addr->af == AF_INET6) { *klen = sizeof(struct in6_addr); - res = (guchar *) &addr->u.in.addr.s6.sin6_addr; + res = (unsigned char *) &addr->u.in.addr.s6.sin6_addr; } else if (addr->af == AF_UNIX) { *klen = sizeof(struct in_addr); - res = (guchar *) &local; + res = (unsigned char *) &local; } else { *klen = 0; @@ -1726,7 +1726,7 @@ rspamd_inet_address_from_rnds(const struct rdns_reply_entry *rep) return addr; } -void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask) +void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, unsigned int mask) { uint32_t umsk, *p; @@ -1757,7 +1757,7 @@ void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask) } } -static gint +static int rspamd_inet_address_af_order(const rspamd_inet_addr_t *addr) { int ret; @@ -1777,8 +1777,8 @@ rspamd_inet_address_af_order(const rspamd_inet_addr_t *addr) return ret; } -gint rspamd_inet_address_compare(const rspamd_inet_addr_t *a1, - const rspamd_inet_addr_t *a2, gboolean compare_ports) +int rspamd_inet_address_compare(const rspamd_inet_addr_t *a1, + const rspamd_inet_addr_t *a2, gboolean compare_ports) { g_assert(a1 != NULL); g_assert(a2 != NULL); @@ -1828,8 +1828,8 @@ gint rspamd_inet_address_compare(const rspamd_inet_addr_t *a1, return 0; } -gint rspamd_inet_address_compare_ptr(gconstpointer a1, - gconstpointer a2) +int rspamd_inet_address_compare_ptr(gconstpointer a1, + gconstpointer a2) { const rspamd_inet_addr_t **i1 = (const rspamd_inet_addr_t **) a1, **i2 = (const rspamd_inet_addr_t **) a2; @@ -1858,7 +1858,7 @@ rspamd_inet_address_copy(const rspamd_inet_addr_t *addr, rspamd_mempool_t *pool) return n; } -gint rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr) +int rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr) { g_assert(addr != NULL); @@ -1882,11 +1882,11 @@ rspamd_inet_address_get_sa(const rspamd_inet_addr_t *addr, } -guint rspamd_inet_address_hash(gconstpointer a) +unsigned int rspamd_inet_address_hash(gconstpointer a) { const rspamd_inet_addr_t *addr = a; struct { - gchar buf[sizeof(struct in6_addr)]; /* 16 bytes */ + char buf[sizeof(struct in6_addr)]; /* 16 bytes */ int af; } layout; @@ -1922,11 +1922,11 @@ guint rspamd_inet_address_hash(gconstpointer a) return k; } -guint rspamd_inet_address_port_hash(gconstpointer a) +unsigned int rspamd_inet_address_port_hash(gconstpointer a) { const rspamd_inet_addr_t *addr = a; struct { - gchar buf[sizeof(struct in6_addr)]; /* 16 bytes */ + char buf[sizeof(struct in6_addr)]; /* 16 bytes */ int port; int af; } layout; diff --git a/src/libutil/addr.h b/src/libutil/addr.h index 25a364125..9feb7f05f 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -92,7 +92,7 @@ rspamd_inet_addr_t *rspamd_inet_address_from_rnds( * @param target target structure * @return TRUE if the address has been parsed, otherwise `target` content is undefined */ -gboolean rspamd_parse_inet_address_ip6(const guchar *text, gsize len, +gboolean rspamd_parse_inet_address_ip6(const unsigned char *text, gsize len, gpointer target); enum rspamd_inet_address_parse_flags { @@ -110,7 +110,7 @@ enum rspamd_inet_address_parse_flags { * @param target target structure * @return TRUE if the address has been parsed, otherwise `target` content is undefined */ -gboolean rspamd_parse_inet_address_ip4(const guchar *text, gsize len, +gboolean rspamd_parse_inet_address_ip4(const unsigned char *text, gsize len, gpointer target); /** @@ -173,7 +173,7 @@ uint16_t rspamd_inet_address_get_port(const rspamd_inet_addr_t *addr); * @param addr * @return */ -gint rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr); +int rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr); /** * Returns sockaddr and size for this address @@ -190,7 +190,7 @@ struct sockaddr *rspamd_inet_address_get_sa(const rspamd_inet_addr_t *addr, * @param klen * @return */ -guchar *rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, guint *klen); +unsigned char *rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, unsigned int *klen); /** * Receive data from an unconnected socket and fill the inet_addr structure if needed @@ -200,7 +200,7 @@ guchar *rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, guint * * @param target * @return same as recvfrom(2) */ -gssize rspamd_inet_address_recvfrom(gint fd, void *buf, gsize len, gint fl, +gssize rspamd_inet_address_recvfrom(int fd, void *buf, gsize len, int fl, rspamd_inet_addr_t **target); /** @@ -211,7 +211,7 @@ gssize rspamd_inet_address_recvfrom(gint fd, void *buf, gsize len, gint fl, * @param target * @return */ -gssize rspamd_inet_address_sendto(gint fd, const void *buf, gsize len, gint fl, +gssize rspamd_inet_address_sendto(int fd, const void *buf, gsize len, int fl, const rspamd_inet_addr_t *addr); /** @@ -225,7 +225,7 @@ void rspamd_inet_address_set_port(rspamd_inet_addr_t *addr, uint16_t port); * @param async perform operations asynchronously * @return newly created and connected socket */ -int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, gint type, +int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, int type, gboolean async); enum rspamd_inet_address_listen_opts { @@ -241,9 +241,9 @@ enum rspamd_inet_address_listen_opts { * @param opts * @return */ -int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type, +int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, int type, enum rspamd_inet_address_listen_opts opts, - gint listen_queue); + int listen_queue); /** * Check whether specified ip is valid (not INADDR_ANY or INADDR_NONE) for ipv4 or ipv6 @@ -253,7 +253,7 @@ int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type, */ gboolean rspamd_ip_is_valid(const rspamd_inet_addr_t *addr); -typedef void (*rspamd_accept_throttling_handler)(gint, void *); +typedef void (*rspamd_accept_throttling_handler)(int, void *); /** * Accept from listening socket filling addr structure @@ -261,10 +261,10 @@ typedef void (*rspamd_accept_throttling_handler)(gint, void *); * @param target allocated inet addr structure * @return */ -gint rspamd_accept_from_socket(gint sock, - rspamd_inet_addr_t **target, - rspamd_accept_throttling_handler hdl, - void *hdl_data); +int rspamd_accept_from_socket(int sock, + rspamd_inet_addr_t **target, + rspamd_accept_throttling_handler hdl, + void *hdl_data); enum rspamd_parse_host_port_result { RSPAMD_PARSE_ADDR_FAIL = 0, @@ -279,10 +279,10 @@ enum rspamd_parse_host_port_result { * @return RSPAMD_PARSE_ADDR_FAIL in case of error, RSPAMD_PARSE_ADDR_NUMERIC in case of pure ip/unix socket */ enum rspamd_parse_host_port_result -rspamd_parse_host_port_priority(const gchar *str, +rspamd_parse_host_port_priority(const char *str, GPtrArray **addrs, - guint *priority, gchar **name, - guint default_port, + unsigned int *priority, char **name, + unsigned int default_port, gboolean allow_listen, rspamd_mempool_t *pool); @@ -297,7 +297,7 @@ void rspamd_inet_address_free(rspamd_inet_addr_t *addr); * @param addr * @param mask */ -void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask); +void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, unsigned int mask); /** * Compare a1 and a2 and return value >0, ==0 and <0 if a1 is more, equal or less than a2 correspondingly @@ -305,8 +305,8 @@ void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask); * @param a2 * @return */ -gint rspamd_inet_address_compare(const rspamd_inet_addr_t *a1, - const rspamd_inet_addr_t *a2, gboolean compare_ports); +int rspamd_inet_address_compare(const rspamd_inet_addr_t *a1, + const rspamd_inet_addr_t *a2, gboolean compare_ports); /** * Utility function to compare addresses by in g_ptr_array @@ -314,8 +314,8 @@ gint rspamd_inet_address_compare(const rspamd_inet_addr_t *a1, * @param a2 * @return */ -gint rspamd_inet_address_compare_ptr(gconstpointer a1, - gconstpointer a2); +int rspamd_inet_address_compare_ptr(gconstpointer a1, + gconstpointer a2); /** * Performs deep copy of rspamd inet addr @@ -327,9 +327,9 @@ rspamd_inet_addr_t *rspamd_inet_address_copy(const rspamd_inet_addr_t *addr, rsp /** * Returns hash for inet address (ignoring port) */ -guint rspamd_inet_address_hash(gconstpointer a); +unsigned int rspamd_inet_address_hash(gconstpointer a); -guint rspamd_inet_address_port_hash(gconstpointer a); +unsigned int rspamd_inet_address_port_hash(gconstpointer a); /** * Returns true if two address are equal diff --git a/src/libutil/cxx/utf8_util.cxx b/src/libutil/cxx/utf8_util.cxx index 5fc83ca85..05a7f9d7b 100644 --- a/src/libutil/cxx/utf8_util.cxx +++ b/src/libutil/cxx/utf8_util.cxx @@ -161,8 +161,8 @@ rspamd_normalise_unicode_inplace(char *start, size_t *len) return static_cast(ret); } -gchar * -rspamd_utf8_transliterate(const gchar *start, gsize len, gsize *target_len) +char * +rspamd_utf8_transliterate(const char *start, gsize len, gsize *target_len) { UErrorCode uc_err = U_ZERO_ERROR; @@ -195,7 +195,7 @@ rspamd_utf8_transliterate(const gchar *start, gsize len, gsize *target_len) // We assume that all characters are now ascii auto dest_len = uc_string.length(); - gchar *dest = (gchar *) g_malloc(dest_len + 1); + char *dest = (char *) g_malloc(dest_len + 1); auto sink = icu::CheckedArrayByteSink(dest, dest_len); uc_string.toUTF8(sink); diff --git a/src/libutil/cxx/utf8_util.h b/src/libutil/cxx/utf8_util.h index 044beae36..fcb0d2f70 100644 --- a/src/libutil/cxx/utf8_util.h +++ b/src/libutil/cxx/utf8_util.h @@ -49,7 +49,7 @@ enum rspamd_utf8_normalise_result { * @param len * @return TRUE if a string has been normalised */ -enum rspamd_utf8_normalise_result rspamd_normalise_unicode_inplace(gchar *start, gsize *len); +enum rspamd_utf8_normalise_result rspamd_normalise_unicode_inplace(char *start, gsize *len); /** * Transliterate a string to ASCII @@ -58,7 +58,7 @@ enum rspamd_utf8_normalise_result rspamd_normalise_unicode_inplace(gchar *start, * @param target_len * @return a new string that should be freed with g_free */ -gchar *rspamd_utf8_transliterate(const gchar *start, gsize len, gsize *target_len); +char *rspamd_utf8_transliterate(const char *start, gsize len, gsize *target_len); /** * Compare two strings using libicu collator diff --git a/src/libutil/expression.c b/src/libutil/expression.c index 51eac6885..e36964e72 100644 --- a/src/libutil/expression.c +++ b/src/libutil/expression.c @@ -47,8 +47,8 @@ enum rspamd_expression_op_flag { struct rspamd_expression_operation { enum rspamd_expression_op op; - guint logical_priority; - guint op_flags; + unsigned int logical_priority; + unsigned int op_flags; }; struct rspamd_expression_elt { @@ -56,12 +56,12 @@ struct rspamd_expression_elt { union { rspamd_expression_atom_t *atom; struct rspamd_expression_operation op; - gdouble lim; + double lim; } p; - gint flags; - gint priority; - gdouble value; + int flags; + int priority; + double value; }; struct rspamd_expression { @@ -69,14 +69,14 @@ struct rspamd_expression { GArray *expressions; GPtrArray *expression_stack; GNode *ast; - gchar *log_id; - guint next_resort; - guint evals; + char *log_id; + unsigned int next_resort; + unsigned int evals; }; struct rspamd_expr_process_data { gpointer *ud; - gint flags; + int flags; /* != NULL if trace is collected */ GPtrArray *trace; rspamd_expression_process_cb process_closure; @@ -106,12 +106,12 @@ rspamd_expr_quark(void) return g_quark_from_static_string("rspamd-expression"); } -static const gchar *RSPAMD_CONST_FUNCTION +static const char *RSPAMD_CONST_FUNCTION rspamd_expr_op_to_str(enum rspamd_expression_op op); -static const gchar * +static const char * rspamd_expr_op_to_str(enum rspamd_expression_op op) { - const gchar *op_str = NULL; + const char *op_str = NULL; switch (op) { case OP_AND: @@ -181,7 +181,7 @@ static gpointer rspamd_expr_stack_elt_pop(GPtrArray *stack) { gpointer e; - gint idx; + int idx; if (stack->len == 0) { return NULL; @@ -212,7 +212,7 @@ static gpointer rspamd_expr_stack_peek(struct rspamd_expression *expr) { gpointer e; - gint idx; + int idx; GPtrArray *stack = expr->expression_stack; if (stack->len == 0) { @@ -228,12 +228,12 @@ rspamd_expr_stack_peek(struct rspamd_expression *expr) /* * Return operation priority */ -static gint RSPAMD_CONST_FUNCTION +static int RSPAMD_CONST_FUNCTION rspamd_expr_logic_priority(enum rspamd_expression_op op); -static gint +static int rspamd_expr_logic_priority(enum rspamd_expression_op op) { - gint ret = 0; + int ret = 0; switch (op) { case OP_NOT: @@ -273,13 +273,13 @@ rspamd_expr_logic_priority(enum rspamd_expression_op op) return ret; } -static guint RSPAMD_CONST_FUNCTION +static unsigned int RSPAMD_CONST_FUNCTION rspamd_expr_op_flags(enum rspamd_expression_op op); -static guint +static unsigned int rspamd_expr_op_flags(enum rspamd_expression_op op) { - guint ret = 0; + unsigned int ret = 0; switch (op) { case OP_NOT: @@ -323,9 +323,9 @@ rspamd_expr_op_flags(enum rspamd_expression_op op) * Return TRUE if symbol is operation symbol */ static gboolean RSPAMD_CONST_FUNCTION -rspamd_expr_is_operation_symbol(gchar a); +rspamd_expr_is_operation_symbol(char a); static gboolean -rspamd_expr_is_operation_symbol(gchar a) +rspamd_expr_is_operation_symbol(char a) { switch (a) { case '!': @@ -348,18 +348,18 @@ rspamd_expr_is_operation_symbol(gchar a) static gboolean rspamd_expr_is_operation(struct rspamd_expression *e, - const gchar *p, const gchar *end, rspamd_regexp_t *num_re) + const char *p, const char *end, rspamd_regexp_t *num_re) { if (rspamd_expr_is_operation_symbol(*p)) { if (p + 1 < end) { - gchar t = *(p + 1); + char t = *(p + 1); if (t == ':') { /* Special case, treat it as an atom */ } else if (*p == '/') { /* Lookahead for division operation to distinguish from regexp */ - const gchar *track = p + 1; + const char *track = p + 1; /* Skip spaces */ while (track < end && g_ascii_isspace(*track)) { @@ -409,7 +409,7 @@ rspamd_expr_is_operation(struct rspamd_expression *e, /* Return character representation of operation */ static enum rspamd_expression_op -rspamd_expr_str_to_op(const gchar *a, const gchar *end, const gchar **next) +rspamd_expr_str_to_op(const char *a, const char *end, const char **next) { enum rspamd_expression_op op = OP_INVALID; @@ -538,7 +538,7 @@ rspamd_expr_str_to_op(const gchar *a, const gchar *end, const gchar **next) static void rspamd_expression_destroy(struct rspamd_expression *expr) { - guint i; + unsigned int i; struct rspamd_expression_elt *elt; if (expr != NULL) { @@ -714,7 +714,7 @@ rspamd_ast_priority_traverse(GNode *node, gpointer d) { struct rspamd_expression_elt *elt = node->data, *cur_elt; struct rspamd_expression *expr = d; - gint cnt = 0; + int cnt = 0; GNode *cur; if (node->children) { @@ -750,11 +750,11 @@ rspamd_ast_priority_traverse(GNode *node, gpointer d) #define ATOM_PRIORITY(a) ((a)->p.atom->hits / ((a)->p.atom->exec_time.mean > 0 ? (a)->p.atom->exec_time.mean * 10000000 : 1.0)) -static gint +static int rspamd_ast_priority_cmp(GNode *a, GNode *b) { struct rspamd_expression_elt *ea = a->data, *eb = b->data; - gdouble w1, w2; + double w1, w2; if (ea->type == ELT_LIMIT) { return 1; @@ -819,7 +819,7 @@ rspamd_expr_dup_elt(rspamd_mempool_t *pool, struct rspamd_expression_elt *elt) } gboolean -rspamd_parse_expression(const gchar *line, gsize len, +rspamd_parse_expression(const char *line, gsize len, const struct rspamd_atom_subr *subr, gpointer subr_data, rspamd_mempool_t *pool, GError **err, struct rspamd_expression **target) @@ -829,7 +829,7 @@ rspamd_parse_expression(const gchar *line, gsize len, rspamd_expression_atom_t *atom; rspamd_regexp_t *num_re; enum rspamd_expression_op op, op_stack; - const gchar *p, *c, *end; + const char *p, *c, *end; GPtrArray *operand_stack; GNode *tmp; @@ -1020,7 +1020,7 @@ rspamd_parse_expression(const gchar *line, gsize len, goto error_label; } - guint op_priority = rspamd_expr_logic_priority(op); + unsigned int op_priority = rspamd_expr_logic_priority(op); msg_debug_expression("found op: %s; priority = %d", rspamd_expr_op_to_str(op), op_priority); @@ -1064,8 +1064,8 @@ rspamd_parse_expression(const gchar *line, gsize len, } /* We ignore associativity for now */ - guint op_priority = rspamd_expr_logic_priority(op), - stack_op_priority = rspamd_expr_logic_priority(op_stack); + unsigned int op_priority = rspamd_expr_logic_priority(op), + stack_op_priority = rspamd_expr_logic_priority(op_stack); msg_debug_expression("operators stack %d; operands stack: %d; " "process operation '%s'(%d); pop operation '%s'(%d)", @@ -1201,7 +1201,7 @@ error_label: * Node optimizer function: skip nodes that are not relevant */ static gboolean -rspamd_ast_node_done(struct rspamd_expression_elt *elt, gdouble acc) +rspamd_ast_node_done(struct rspamd_expression_elt *elt, double acc) { gboolean ret = FALSE; @@ -1225,10 +1225,10 @@ rspamd_ast_node_done(struct rspamd_expression_elt *elt, gdouble acc) } -static gdouble -rspamd_ast_do_unary_op(struct rspamd_expression_elt *elt, gdouble operand) +static double +rspamd_ast_do_unary_op(struct rspamd_expression_elt *elt, double operand) { - gdouble ret; + double ret; g_assert(elt->type == ELT_OP); switch (elt->p.op.op) { @@ -1242,10 +1242,10 @@ rspamd_ast_do_unary_op(struct rspamd_expression_elt *elt, gdouble operand) return ret; } -static gdouble -rspamd_ast_do_binary_op(struct rspamd_expression_elt *elt, gdouble op1, gdouble op2) +static double +rspamd_ast_do_binary_op(struct rspamd_expression_elt *elt, double op1, double op2) { - gdouble ret; + double ret; g_assert(elt->type == ELT_OP); @@ -1288,10 +1288,10 @@ rspamd_ast_do_binary_op(struct rspamd_expression_elt *elt, gdouble op1, gdouble return ret; } -static gdouble -rspamd_ast_do_nary_op(struct rspamd_expression_elt *elt, gdouble val, gdouble acc) +static double +rspamd_ast_do_nary_op(struct rspamd_expression_elt *elt, double val, double acc) { - gdouble ret; + double ret; g_assert(elt->type == ELT_OP); @@ -1329,17 +1329,17 @@ rspamd_ast_do_nary_op(struct rspamd_expression_elt *elt, gdouble val, gdouble ac return ret; } -static gdouble +static double rspamd_ast_process_node(struct rspamd_expression *e, GNode *node, struct rspamd_expr_process_data *process_data) { struct rspamd_expression_elt *elt; GNode *cld; - gdouble acc = NAN; + double acc = NAN; float t1, t2; - gdouble val; + double val; gboolean calc_ticks = FALSE; - __attribute__((unused)) const gchar *op_name = NULL; + __attribute__((unused)) const char *op_name = NULL; elt = node->data; @@ -1412,7 +1412,7 @@ rspamd_ast_process_node(struct rspamd_expression *e, GNode *node, c2 = c1->next; g_assert(c2->next == NULL); - gdouble val1, val2; + double val1, val2; msg_debug_expression_verbose("proceed binary operation %s", op_name); @@ -1457,15 +1457,15 @@ rspamd_ast_cleanup_traverse(GNode *n, gpointer d) return FALSE; } -gdouble +double rspamd_process_expression_closure(struct rspamd_expression *expr, rspamd_expression_process_cb cb, - gint flags, + int flags, gpointer runtime_ud, GPtrArray **track) { struct rspamd_expr_process_data pd; - gdouble ret = 0; + double ret = 0; g_assert(expr != NULL); /* Ensure that stack is empty at this point */ @@ -1505,9 +1505,9 @@ rspamd_process_expression_closure(struct rspamd_expression *expr, return ret; } -gdouble +double rspamd_process_expression_track(struct rspamd_expression *expr, - gint flags, + int flags, gpointer runtime_ud, GPtrArray **track) { @@ -1515,9 +1515,9 @@ rspamd_process_expression_track(struct rspamd_expression *expr, expr->subr->process, flags, runtime_ud, track); } -gdouble +double rspamd_process_expression(struct rspamd_expression *expr, - gint flags, + int flags, gpointer runtime_ud) { return rspamd_process_expression_closure(expr, @@ -1528,7 +1528,7 @@ static gboolean rspamd_ast_string_traverse(GNode *n, gpointer d) { GString *res = d; - gint cnt; + int cnt; GNode *cur; struct rspamd_expression_elt *elt = n->data; const char *op_str = NULL; diff --git a/src/libutil/expression.h b/src/libutil/expression.h index ea4e102bb..44a793e46 100644 --- a/src/libutil/expression.h +++ b/src/libutil/expression.h @@ -54,28 +54,28 @@ typedef struct rspamd_expression_atom_s { /* Opaque userdata */ gpointer data; /* String representation of atom */ - const gchar *str; + const char *str; /* Length of the string representation of atom */ - guint len; + unsigned int len; /* Relative priority */ - gint priority; - guint hits; + int priority; + unsigned int hits; struct rspamd_counter_data exec_time; } rspamd_expression_atom_t; -typedef gdouble (*rspamd_expression_process_cb)(gpointer runtime_data, - rspamd_expression_atom_t *atom); +typedef double (*rspamd_expression_process_cb)(gpointer runtime_data, + rspamd_expression_atom_t *atom); struct rspamd_atom_subr { /* Parses atom from string and returns atom structure */ - rspamd_expression_atom_t *(*parse)(const gchar *line, gsize len, + rspamd_expression_atom_t *(*parse)(const char *line, gsize len, rspamd_mempool_t *pool, gpointer ud, GError **err); /* Process atom via the opaque pointer (e.g. struct rspamd_task *) */ rspamd_expression_process_cb process; /* Calculates the relative priority of the expression */ - gint (*priority)(rspamd_expression_atom_t *atom); + int (*priority)(rspamd_expression_atom_t *atom); void (*destroy)(rspamd_expression_atom_t *atom); }; @@ -94,7 +94,7 @@ struct rspamd_expression; * @param target the target expression * @return TRUE if an expression have been parsed */ -gboolean rspamd_parse_expression(const gchar *line, gsize len, +gboolean rspamd_parse_expression(const char *line, gsize len, const struct rspamd_atom_subr *subr, gpointer subr_data, rspamd_mempool_t *pool, GError **err, struct rspamd_expression **target); @@ -105,9 +105,9 @@ gboolean rspamd_parse_expression(const gchar *line, gsize len, * @param data opaque data pointer for all the atoms * @return the value of expression */ -gdouble rspamd_process_expression(struct rspamd_expression *expr, - gint flags, - gpointer runtime_ud); +double rspamd_process_expression(struct rspamd_expression *expr, + int flags, + gpointer runtime_ud); /** * Process the expression and return its value using atom 'process' functions with the specified data pointer. @@ -117,10 +117,10 @@ gdouble rspamd_process_expression(struct rspamd_expression *expr, * @param track pointer array to atoms tracking * @return the value of expression */ -gdouble rspamd_process_expression_track(struct rspamd_expression *expr, - gint flags, - gpointer runtime_ud, - GPtrArray **track); +double rspamd_process_expression_track(struct rspamd_expression *expr, + int flags, + gpointer runtime_ud, + GPtrArray **track); /** * Process the expression with the custom processor @@ -129,11 +129,11 @@ gdouble rspamd_process_expression_track(struct rspamd_expression *expr, * @param process_data * @return */ -gdouble rspamd_process_expression_closure(struct rspamd_expression *expr, - rspamd_expression_process_cb cb, - gint flags, - gpointer runtime_ud, - GPtrArray **track); +double rspamd_process_expression_closure(struct rspamd_expression *expr, + rspamd_expression_process_cb cb, + int flags, + gpointer runtime_ud, + GPtrArray **track); /** * Shows string representation of an expression diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c index f092b307f..ffe130477 100644 --- a/src/libutil/fstring.c +++ b/src/libutil/fstring.c @@ -72,7 +72,7 @@ rspamd_fstring_sized_new(gsize initial_size) } rspamd_fstring_t * -rspamd_fstring_new_init(const gchar *init, gsize len) +rspamd_fstring_new_init(const char *init, gsize len) { rspamd_fstring_t *s; gsize real_size = MAX(default_initial_size, len); @@ -92,7 +92,7 @@ rspamd_fstring_new_init(const gchar *init, gsize len) } rspamd_fstring_t * -rspamd_fstring_assign(rspamd_fstring_t *str, const gchar *init, gsize len) +rspamd_fstring_assign(rspamd_fstring_t *str, const char *init, gsize len) { gsize avail; @@ -244,7 +244,7 @@ rspamd_fstrhash_lc(const rspamd_ftok_t *str, gboolean is_utf) { gsize i; uint64_t hval; - const gchar *p, *end = NULL; + const char *p, *end = NULL; gunichar uc; if (str == NULL) { @@ -301,10 +301,10 @@ rspamd_fstring_equal(const rspamd_fstring_t *s1, return FALSE; } -gint rspamd_fstring_casecmp(const rspamd_fstring_t *s1, - const rspamd_fstring_t *s2) +int rspamd_fstring_casecmp(const rspamd_fstring_t *s1, + const rspamd_fstring_t *s2) { - gint ret = 0; + int ret = 0; g_assert(s1 != NULL && s2 != NULL); @@ -318,8 +318,8 @@ gint rspamd_fstring_casecmp(const rspamd_fstring_t *s1, return ret; } -gint rspamd_fstring_cmp(const rspamd_fstring_t *s1, - const rspamd_fstring_t *s2) +int rspamd_fstring_cmp(const rspamd_fstring_t *s1, + const rspamd_fstring_t *s2) { g_assert(s1 != NULL && s2 != NULL); @@ -330,10 +330,10 @@ gint rspamd_fstring_cmp(const rspamd_fstring_t *s1, return s1->len - s2->len; } -gint rspamd_ftok_casecmp(const rspamd_ftok_t *s1, - const rspamd_ftok_t *s2) +int rspamd_ftok_casecmp(const rspamd_ftok_t *s1, + const rspamd_ftok_t *s2) { - gint ret = 0; + int ret = 0; g_assert(s1 != NULL && s2 != NULL); @@ -347,8 +347,8 @@ gint rspamd_ftok_casecmp(const rspamd_ftok_t *s1, return ret; } -gint rspamd_ftok_cmp(const rspamd_ftok_t *s1, - const rspamd_ftok_t *s2) +int rspamd_ftok_cmp(const rspamd_ftok_t *s1, + const rspamd_ftok_t *s2) { g_assert(s1 != NULL && s2 != NULL); @@ -429,7 +429,7 @@ rspamd_ftok_cstr(const rspamd_ftok_t *s) } gboolean -rspamd_ftok_cstr_equal(const rspamd_ftok_t *s, const gchar *pat, +rspamd_ftok_cstr_equal(const rspamd_ftok_t *s, const char *pat, gboolean icase) { gsize slen; @@ -449,10 +449,10 @@ rspamd_ftok_cstr_equal(const rspamd_ftok_t *s, const gchar *pat, return (rspamd_ftok_cmp(s, &srch) == 0); } -gchar * +char * rspamd_ftokdup(const rspamd_ftok_t *src) { - gchar *newstr; + char *newstr; if (src == NULL) { return NULL; @@ -465,10 +465,10 @@ rspamd_ftokdup(const rspamd_ftok_t *src) return newstr; } -gchar * +char * rspamd_fstringdup(const rspamd_fstring_t *src) { - gchar *newstr; + char *newstr; if (src == NULL) { return NULL; diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h index 30a32a389..0792ab9fa 100644 --- a/src/libutil/fstring.h +++ b/src/libutil/fstring.h @@ -32,7 +32,7 @@ extern "C" { typedef struct f_str_s { gsize len; gsize allocated; - gchar str[]; + char str[]; } rspamd_fstring_t; #define RSPAMD_FSTRING_DATA(s) ((s)->str) @@ -41,7 +41,7 @@ typedef struct f_str_s { typedef struct f_str_tok { gsize len; - const gchar *begin; + const char *begin; } rspamd_ftok_t; typedef struct f_str_unicode_tok { @@ -64,14 +64,14 @@ rspamd_fstring_t *rspamd_fstring_sized_new(gsize initial_size) /** * Create new fixed length string and initialize it with the initial data */ -rspamd_fstring_t *rspamd_fstring_new_init(const gchar *init, gsize len) +rspamd_fstring_t *rspamd_fstring_new_init(const char *init, gsize len) G_GNUC_WARN_UNUSED_RESULT; /** * Assign new value to fixed string */ rspamd_fstring_t *rspamd_fstring_assign(rspamd_fstring_t *str, - const gchar *init, gsize len) G_GNUC_WARN_UNUSED_RESULT; + const char *init, gsize len) G_GNUC_WARN_UNUSED_RESULT; /** * Free fixed length string @@ -125,26 +125,26 @@ gboolean rspamd_fstring_equal(const rspamd_fstring_t *s1, /** * Compare two fixed strings ignoring case */ -gint rspamd_fstring_casecmp(const rspamd_fstring_t *s1, - const rspamd_fstring_t *s2); +int rspamd_fstring_casecmp(const rspamd_fstring_t *s1, + const rspamd_fstring_t *s2); /** * Compare two fixed strings */ -gint rspamd_fstring_cmp(const rspamd_fstring_t *s1, - const rspamd_fstring_t *s2); +int rspamd_fstring_cmp(const rspamd_fstring_t *s1, + const rspamd_fstring_t *s2); /** * Compare two fixed tokens ignoring case */ -gint rspamd_ftok_casecmp(const rspamd_ftok_t *s1, - const rspamd_ftok_t *s2); +int rspamd_ftok_casecmp(const rspamd_ftok_t *s1, + const rspamd_ftok_t *s2); /** * Compare two fixed tokens */ -gint rspamd_ftok_cmp(const rspamd_ftok_t *s1, - const rspamd_ftok_t *s2); +int rspamd_ftok_cmp(const rspamd_ftok_t *s1, + const rspamd_ftok_t *s2); /** * Returns true if `s1` starts with `s2` @@ -159,7 +159,7 @@ gboolean rspamd_ftok_starts_with(const rspamd_ftok_t *s1, * Return TRUE if ftok is equal to specified C string */ gboolean rspamd_ftok_cstr_equal(const rspamd_ftok_t *s, - const gchar *pat, gboolean icase); + const char *pat, gboolean icase); /** * Free fstring_t that is mapped to ftok_t @@ -199,14 +199,14 @@ rspamd_fstring_t *rspamd_fstring_grow(rspamd_fstring_t *str, * @param src * @return */ -gchar *rspamd_ftokdup(const rspamd_ftok_t *src) G_GNUC_WARN_UNUSED_RESULT; +char *rspamd_ftokdup(const rspamd_ftok_t *src) G_GNUC_WARN_UNUSED_RESULT; /** * Copies fstring to zero terminated string (must be freed using g_free) * @param src * @return */ -gchar *rspamd_fstringdup(const rspamd_fstring_t *src) G_GNUC_WARN_UNUSED_RESULT; +char *rspamd_fstringdup(const rspamd_fstring_t *src) G_GNUC_WARN_UNUSED_RESULT; #define RSPAMD_FTOK_ASSIGN(t, lit) \ do { \ diff --git a/src/libutil/hash.c b/src/libutil/hash.c index d2af88c16..1f2f76c7a 100644 --- a/src/libutil/hash.c +++ b/src/libutil/hash.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,16 +22,16 @@ * LRU hashing */ -static const guint log_base = 10; -static const guint eviction_candidates = 16; -static const gdouble lfu_base_value = 5.0; +static const unsigned int log_base = 10; +static const unsigned int eviction_candidates = 16; +static const double lfu_base_value = 5.0; struct rspamd_lru_volatile_element_s; struct rspamd_lru_hash_s { - guint maxsize; - guint eviction_min_prio; - guint eviction_used; + unsigned int maxsize; + unsigned int eviction_min_prio; + unsigned int eviction_used; struct rspamd_lru_element_s **eviction_pool; GDestroyNotify value_destroy; @@ -52,10 +52,10 @@ enum rspamd_lru_element_flags { }; struct rspamd_lru_element_s { - guint16 last; - guint8 lg_usages; - guint8 eviction_pos; - guint8 flags; + uint16_t last; + uint8_t lg_usages; + uint8_t eviction_pos; + uint8_t flags; gpointer data; }; @@ -66,7 +66,7 @@ struct rspamd_lru_volatile_element_s { }; typedef struct rspamd_lru_volatile_element_s rspamd_lru_vol_element_t; -#define TIME_TO_TS(t) ((guint16) (((t) / 60) & 0xFFFFU)) +#define TIME_TO_TS(t) ((uint16_t) (((t) / 60) & 0xFFFFU)) static rspamd_lru_vol_element_t * rspamd_lru_hash_get(const rspamd_lru_hash_t *h, gconstpointer key) @@ -153,7 +153,7 @@ rspamd_lru_hash_resize(rspamd_lru_hash_t *h, khint_t new_mask; new_mask = new_n_buckets - 1; val = h->vals[j]; - val.e.eviction_pos = (guint8) -1; + val.e.eviction_pos = (uint8_t) -1; __ac_set_isdel_true(h->flags, j); while (1) { /* kick-out process; sort of like in Cuckoo hashing */ @@ -178,7 +178,7 @@ rspamd_lru_hash_resize(rspamd_lru_hash_t *h, rspamd_lru_vol_element_t tmp = h->vals[i]; h->vals[i] = val; val = tmp; - val.e.eviction_pos = (guint8) -1; + val.e.eviction_pos = (uint8_t) -1; } __ac_set_isdel_true(h->flags, i); /* mark it as deleted in the old hash table */ @@ -310,7 +310,7 @@ static void rspamd_lru_hash_remove_evicted(rspamd_lru_hash_t *hash, rspamd_lru_element_t *elt) { - guint i; + unsigned int i; rspamd_lru_element_t *cur; g_assert(hash->eviction_used > 0); @@ -345,7 +345,7 @@ rspamd_lru_hash_remove_evicted(rspamd_lru_hash_t *hash, static void rspamd_lru_hash_update_counter(rspamd_lru_element_t *elt) { - guint8 counter = elt->lg_usages; + uint8_t counter = elt->lg_usages; if (counter != 255) { double r, baseval, p; @@ -378,10 +378,10 @@ static gboolean rspamd_lru_hash_maybe_evict(rspamd_lru_hash_t *hash, rspamd_lru_element_t *elt) { - guint i; + unsigned int i; rspamd_lru_element_t *cur; - if (elt->eviction_pos == (guint8) -1) { + if (elt->eviction_pos == (uint8_t) -1) { if (hash->eviction_used < eviction_candidates) { /* There are free places in eviction pool */ hash->eviction_pool[hash->eviction_used] = elt; @@ -424,7 +424,7 @@ rspamd_lru_hash_maybe_evict(rspamd_lru_hash_t *hash, static void rspamd_lru_hash_remove_node(rspamd_lru_hash_t *hash, rspamd_lru_element_t *elt) { - if (elt->eviction_pos != (guint8) -1) { + if (elt->eviction_pos != (uint8_t) -1) { rspamd_lru_hash_remove_evicted(hash, elt); } @@ -435,9 +435,9 @@ static void rspamd_lru_hash_evict(rspamd_lru_hash_t *hash, time_t now) { double r; - guint i; + unsigned int i; rspamd_lru_element_t *elt = NULL; - guint nexpired = 0; + unsigned int nexpired = 0; /* * We either evict one node from the eviction list @@ -503,7 +503,7 @@ rspamd_lru_hash_evict(rspamd_lru_hash_t *hash, time_t now) } rspamd_lru_hash_t * -rspamd_lru_hash_new_full(gint maxsize, +rspamd_lru_hash_new_full(int maxsize, GDestroyNotify key_destroy, GDestroyNotify value_destroy, GHashFunc hf, @@ -532,7 +532,7 @@ rspamd_lru_hash_new_full(gint maxsize, } rspamd_lru_hash_t * -rspamd_lru_hash_new(gint maxsize, +rspamd_lru_hash_new(int maxsize, GDestroyNotify key_destroy, GDestroyNotify value_destroy) { @@ -593,11 +593,11 @@ void rspamd_lru_hash_insert(rspamd_lru_hash_t *hash, gpointer key, gpointer value, time_t now, - guint ttl) + unsigned int ttl) { rspamd_lru_element_t *node; rspamd_lru_vol_element_t *vnode; - gint ret; + int ret; vnode = rspamd_lru_hash_put(hash, key, &ret); node = &vnode->e; @@ -629,9 +629,9 @@ void rspamd_lru_hash_insert(rspamd_lru_hash_t *hash, } node->data = value; - node->lg_usages = (guint8) lfu_base_value; + node->lg_usages = (uint8_t) lfu_base_value; node->last = TIME_TO_TS(now); - node->eviction_pos = (guint8) -1; + node->eviction_pos = (uint8_t) -1; if (ret != 0) { /* Also need to check maxsize */ @@ -679,7 +679,7 @@ rspamd_lru_hash_element_data(rspamd_lru_element_t *elt) int rspamd_lru_hash_foreach(rspamd_lru_hash_t *h, int it, gpointer *k, gpointer *v) { - gint i; + int i; g_assert(it >= 0); for (i = it; i != kh_end(h); ++i) { @@ -701,7 +701,7 @@ int rspamd_lru_hash_foreach(rspamd_lru_hash_t *h, int it, gpointer *k, } -guint rspamd_lru_hash_size(rspamd_lru_hash_t *hash) +unsigned int rspamd_lru_hash_size(rspamd_lru_hash_t *hash) { return kh_size(hash); } @@ -710,7 +710,7 @@ guint rspamd_lru_hash_size(rspamd_lru_hash_t *hash) * Returns hash capacity * @param hash hash object */ -guint rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash) +unsigned int rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash) { return hash->maxsize; } \ No newline at end of file diff --git a/src/libutil/hash.h b/src/libutil/hash.h index 3882ce5c7..1feeacf5f 100644 --- a/src/libutil/hash.h +++ b/src/libutil/hash.h @@ -27,7 +27,7 @@ typedef struct rspamd_lru_element_s rspamd_lru_element_t; * @param key_equal_func pointer to function for comparing keys * @return new rspamd_hash object */ -rspamd_lru_hash_t *rspamd_lru_hash_new(gint maxsize, +rspamd_lru_hash_t *rspamd_lru_hash_new(int maxsize, GDestroyNotify key_destroy, GDestroyNotify value_destroy); @@ -40,7 +40,7 @@ rspamd_lru_hash_t *rspamd_lru_hash_new(gint maxsize, * @param key_equal_func pointer to function for comparing keys * @return new rspamd_hash object */ -rspamd_lru_hash_t *rspamd_lru_hash_new_full(gint maxsize, +rspamd_lru_hash_t *rspamd_lru_hash_new_full(int maxsize, GDestroyNotify key_destroy, GDestroyNotify value_destroy, GHashFunc hfunc, @@ -75,7 +75,7 @@ void rspamd_lru_hash_insert(rspamd_lru_hash_t *hash, gpointer key, gpointer value, time_t now, - guint ttl); + unsigned int ttl); /** * Remove lru hash @@ -99,13 +99,13 @@ int rspamd_lru_hash_foreach(rspamd_lru_hash_t *hash, int it, gpointer *k, * Returns number of elements in a hash * @param hash hash object */ -guint rspamd_lru_hash_size(rspamd_lru_hash_t *hash); +unsigned int rspamd_lru_hash_size(rspamd_lru_hash_t *hash); /** * Returns hash capacity * @param hash hash object */ -guint rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash); +unsigned int rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash); #ifdef __cplusplus } diff --git a/src/libutil/heap.c b/src/libutil/heap.c index 8ce70cf71..dcff58b40 100644 --- a/src/libutil/heap.c +++ b/src/libutil/heap.c @@ -140,9 +140,9 @@ rspamd_min_heap_pop(struct rspamd_min_heap *heap) } void rspamd_min_heap_update_elt(struct rspamd_min_heap *heap, - struct rspamd_min_heap_elt *elt, guint npri) + struct rspamd_min_heap_elt *elt, unsigned int npri) { - guint oldpri; + unsigned int oldpri; g_assert(heap != NULL); g_assert(elt->idx > 0 && elt->idx <= heap->ar->len); @@ -188,7 +188,7 @@ void rspamd_min_heap_destroy(struct rspamd_min_heap *heap) } struct rspamd_min_heap_elt * -rspamd_min_heap_index(struct rspamd_min_heap *heap, guint idx) +rspamd_min_heap_index(struct rspamd_min_heap *heap, unsigned int idx) { g_assert(heap != NULL); g_assert(idx < heap->ar->len); diff --git a/src/libutil/heap.h b/src/libutil/heap.h index 805f817c9..d56ee02b2 100644 --- a/src/libutil/heap.h +++ b/src/libutil/heap.h @@ -28,8 +28,8 @@ extern "C" { struct rspamd_min_heap_elt { gpointer data; - guint pri; - guint idx; + unsigned int pri; + unsigned int idx; }; struct rspamd_min_heap; @@ -64,7 +64,7 @@ struct rspamd_min_heap_elt *rspamd_min_heap_pop(struct rspamd_min_heap *heap); * @param npri new priority */ void rspamd_min_heap_update_elt(struct rspamd_min_heap *heap, - struct rspamd_min_heap_elt *elt, guint npri); + struct rspamd_min_heap_elt *elt, unsigned int npri); /** @@ -88,7 +88,7 @@ void rspamd_min_heap_destroy(struct rspamd_min_heap *heap); * @return */ struct rspamd_min_heap_elt *rspamd_min_heap_index(struct rspamd_min_heap *heap, - guint idx); + unsigned int idx); #ifdef __cplusplus } diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index 9d7c4a99a..2912d423c 100644 --- a/src/libutil/mem_pool.c +++ b/src/libutil/mem_pool.c @@ -65,7 +65,7 @@ static inline uint32_t rspamd_entry_hash(const char *str) { - return (guint) rspamd_cryptobox_fast_hash(str, strlen(str), rspamd_hash_seed()); + return (unsigned int) rspamd_cryptobox_fast_hash(str, strlen(str), rspamd_hash_seed()); } static inline int @@ -75,7 +75,7 @@ rspamd_entry_equal(const char *k1, const char *k2) } -KHASH_INIT(mempool_entry, const gchar *, struct rspamd_mempool_entry_point *, +KHASH_INIT(mempool_entry, const char *, struct rspamd_mempool_entry_point *, 1, rspamd_entry_hash, rspamd_entry_equal) static khash_t(mempool_entry) *mempool_entries = NULL; @@ -103,10 +103,10 @@ pool_chain_free(struct _pool_chain *chain) #define FIXED_POOL_SIZE 4096 static inline struct rspamd_mempool_entry_point * -rspamd_mempool_entry_new(const gchar *loc) +rspamd_mempool_entry_new(const char *loc) { struct rspamd_mempool_entry_point **pentry, *entry; - gint r; + int r; khiter_t k; k = kh_put(mempool_entry, mempool_entries, loc, &r); @@ -150,7 +150,7 @@ RSPAMD_DESTRUCTOR(rspamd_mempool_entries_dtor) } static inline struct rspamd_mempool_entry_point * -rspamd_mempool_get_entry(const gchar *loc) +rspamd_mempool_get_entry(const char *loc) { khiter_t k; struct rspamd_mempool_entry_point *elt; @@ -194,9 +194,9 @@ rspamd_mempool_chain_new(gsize size, gsize alignment, enum rspamd_mempool_chain_ abort(); } chain = map; - chain->begin = ((guint8 *) chain) + sizeof(struct _pool_chain); + chain->begin = ((uint8_t *) chain) + sizeof(struct _pool_chain); #elif defined(HAVE_MMAP_ZERO) - gint fd; + int fd; fd = open("/dev/zero", O_RDWR); if (fd == -1) { @@ -214,7 +214,7 @@ rspamd_mempool_chain_new(gsize size, gsize alignment, enum rspamd_mempool_chain_ abort(); } chain = map; - chain->begin = ((guint8 *) chain) + sizeof(struct _pool_chain); + chain->begin = ((uint8_t *) chain) + sizeof(struct _pool_chain); #else #error No mmap methods are defined #endif @@ -226,7 +226,7 @@ rspamd_mempool_chain_new(gsize size, gsize alignment, enum rspamd_mempool_chain_ optimal_size = sys_alloc_size(total_size); #endif total_size = MAX(total_size, optimal_size); - gint ret = posix_memalign(&map, alignment, total_size); + int ret = posix_memalign(&map, alignment, total_size); if (ret != 0 || map == NULL) { g_error("%s: failed to allocate %" G_GSIZE_FORMAT " bytes: %d - %s", @@ -235,7 +235,7 @@ rspamd_mempool_chain_new(gsize size, gsize alignment, enum rspamd_mempool_chain_ } chain = map; - chain->begin = ((guint8 *) chain) + sizeof(struct _pool_chain); + chain->begin = ((uint8_t *) chain) + sizeof(struct _pool_chain); g_atomic_int_add(&mem_pool_stat->bytes_allocated, total_size); g_atomic_int_inc(&mem_pool_stat->chunks_allocated); } @@ -280,7 +280,7 @@ rspamd_mempool_append_chain(rspamd_mempool_t *pool, * @return new memory pool object */ rspamd_mempool_t * -rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc) +rspamd_mempool_new_(gsize size, const char *tag, int flags, const char *loc) { rspamd_mempool_t *new_pool; gpointer map; @@ -301,7 +301,7 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc) } mem_pool_stat = (rspamd_mempool_stat_t *) map; #elif defined(HAVE_MMAP_ZERO) - gint fd; + int fd; fd = open("/dev/zero", O_RDWR); g_assert(fd != -1); @@ -359,9 +359,9 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc) * alignment (if needed) * memory chunk */ - guchar *mem_chunk; - gint ret = posix_memalign((void **) &mem_chunk, MIN_MEM_ALIGNMENT, - total_size); + unsigned char *mem_chunk; + int ret = posix_memalign((void **) &mem_chunk, MIN_MEM_ALIGNMENT, + total_size); gsize priv_offset; if (ret != 0 || mem_chunk == NULL) { @@ -416,10 +416,10 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc) priv_offset + sizeof(struct rspamd_mempool_specific)); - guchar *unaligned = mem_chunk + - priv_offset + - sizeof(struct rspamd_mempool_specific) + - sizeof(struct _pool_chain); + unsigned char *unaligned = mem_chunk + + priv_offset + + sizeof(struct rspamd_mempool_specific) + + sizeof(struct _pool_chain); nchain->slice_size = size; nchain->begin = unaligned; @@ -430,7 +430,7 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc) /* Adjust stats */ g_atomic_int_add(&mem_pool_stat->bytes_allocated, - (gint) size); + (int) size); g_atomic_int_add(&mem_pool_stat->chunks_allocated, 1); return new_pool; @@ -439,14 +439,14 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc) static void * memory_pool_alloc_common(rspamd_mempool_t *pool, gsize size, gsize alignment, enum rspamd_mempool_chain_type pool_type, - const gchar *loc) + const char *loc) RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; -void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const gchar *loc) +void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const char *loc) { if (pool && G_UNLIKELY(pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) { - GHashTable *debug_tbl = *(GHashTable **) (((guchar *) pool + sizeof(*pool))); + GHashTable *debug_tbl = *(GHashTable **) (((unsigned char *) pool + sizeof(*pool))); gpointer ptr; ptr = g_hash_table_lookup(debug_tbl, loc); @@ -464,9 +464,9 @@ void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const gcha static void * memory_pool_alloc_common(rspamd_mempool_t *pool, gsize size, gsize alignment, - enum rspamd_mempool_chain_type pool_type, const gchar *loc) + enum rspamd_mempool_chain_type pool_type, const char *loc) { - guint8 *tmp; + uint8_t *tmp; struct _pool_chain *new, *cur; gsize free = 0; @@ -549,7 +549,7 @@ memory_pool_alloc_common(rspamd_mempool_t *pool, gsize size, gsize alignment, void * -rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc) +rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc) { return memory_pool_alloc_common(pool, size, alignment, RSPAMD_MEMPOOL_NORMAL, loc); } @@ -561,7 +561,7 @@ rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const #define MUL_NO_OVERFLOW (1UL << (sizeof(gsize) * 4)) void * -rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const gchar *loc) +rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const char *loc) { if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && nmemb > 0 && G_MAXSIZE / nmemb < size) { @@ -574,7 +574,7 @@ rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsi } void * -rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc) +rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc) { void *pointer = rspamd_mempool_alloc_(pool, size, alignment, loc); memset(pointer, 0, size); @@ -582,7 +582,7 @@ rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, cons return pointer; } void * -rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc) +rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc) { void *pointer = rspamd_mempool_alloc_shared_(pool, size, alignment, loc); @@ -591,14 +591,14 @@ rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignmen } void * -rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc) +rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc) { return memory_pool_alloc_common(pool, size, alignment, RSPAMD_MEMPOOL_SHARED, loc); } -gchar * -rspamd_mempool_strdup_(rspamd_mempool_t *pool, const gchar *src, const gchar *loc) +char * +rspamd_mempool_strdup_(rspamd_mempool_t *pool, const char *src, const char *loc) { if (src == NULL) { return NULL; @@ -606,10 +606,10 @@ rspamd_mempool_strdup_(rspamd_mempool_t *pool, const gchar *src, const gchar *lo return rspamd_mempool_strdup_len_(pool, src, strlen(src), loc); } -gchar * -rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const gchar *src, gsize len, const gchar *loc) +char * +rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const char *src, gsize len, const char *loc) { - gchar *newstr; + char *newstr; if (src == NULL) { return NULL; @@ -622,11 +622,11 @@ rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const gchar *src, gsize len, return newstr; } -gchar * +char * rspamd_mempool_ftokdup_(rspamd_mempool_t *pool, const rspamd_ftok_t *src, - const gchar *loc) + const char *loc) { - gchar *newstr; + char *newstr; if (src == NULL) { return NULL; @@ -642,8 +642,8 @@ rspamd_mempool_ftokdup_(rspamd_mempool_t *pool, const rspamd_ftok_t *src, void rspamd_mempool_add_destructor_full(rspamd_mempool_t *pool, rspamd_mempool_destruct_t func, void *data, - const gchar *function, - const gchar *line) + const char *function, + const char *line) { struct _pool_destructors *cur; @@ -685,10 +685,10 @@ void rspamd_mempool_replace_destructor(rspamd_mempool_t *pool, } } -static gint +static int cmp_int(gconstpointer a, gconstpointer b) { - gint i1 = *(const gint *) a, i2 = *(const gint *) b; + int i1 = *(const int *) a, i2 = *(const int *) b; return i1 - i2; } @@ -696,14 +696,14 @@ cmp_int(gconstpointer a, gconstpointer b) static void rspamd_mempool_adjust_entry(struct rspamd_mempool_entry_point *e) { - gint sz[G_N_ELEMENTS(e->elts)], sel_pos, sel_neg; - guint i, jitter; + int sz[G_N_ELEMENTS(e->elts)], sel_pos, sel_neg; + unsigned int i, jitter; for (i = 0; i < G_N_ELEMENTS(sz); i++) { - sz[i] = e->elts[i].fragmentation - (gint) e->elts[i].leftover; + sz[i] = e->elts[i].fragmentation - (int) e->elts[i].leftover; } - qsort(sz, G_N_ELEMENTS(sz), sizeof(gint), cmp_int); + qsort(sz, G_N_ELEMENTS(sz), sizeof(int), cmp_int); jitter = rspamd_random_uint64_fast() % 10; /* * Take stochastic quantiles @@ -751,11 +751,11 @@ rspamd_mempool_variables_cleanup(rspamd_mempool_t *pool) * previous count * 3) Our variables count is less than some hard limit */ - static const guint max_preallocated_vars = 512; + static const unsigned int max_preallocated_vars = 512; - guint cur_size = kh_size(pool->priv->variables); - guint old_guess = pool->priv->entry->cur_vars; - guint new_guess; + unsigned int cur_size = kh_size(pool->priv->variables); + unsigned int old_guess = pool->priv->entry->cur_vars; + unsigned int new_guess; if (old_guess == 0) { new_guess = MIN(cur_size, max_preallocated_vars); @@ -801,16 +801,16 @@ void rspamd_mempool_destructors_enforce(rspamd_mempool_t *pool) struct mempool_debug_elt { gsize sz; - const gchar *loc; + const char *loc; }; -static gint +static int rspamd_mempool_debug_elt_cmp(const void *a, const void *b) { const struct mempool_debug_elt *e1 = a, *e2 = b; /* Inverse order */ - return (gint) ((gssize) e2->sz) - ((gssize) e1->sz); + return (int) ((gssize) e2->sz) - ((gssize) e1->sz); } void rspamd_mempool_delete(rspamd_mempool_t *pool) @@ -818,7 +818,7 @@ void rspamd_mempool_delete(rspamd_mempool_t *pool) struct _pool_chain *cur, *tmp; struct _pool_destructors *destructor; gpointer ptr; - guint i; + unsigned int i; gsize len; POOL_MTX_LOCK(); @@ -826,7 +826,7 @@ void rspamd_mempool_delete(rspamd_mempool_t *pool) cur = pool->priv->pools[RSPAMD_MEMPOOL_NORMAL]; if (G_UNLIKELY(pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) { - GHashTable *debug_tbl = *(GHashTable **) (((guchar *) pool) + sizeof(*pool)); + GHashTable *debug_tbl = *(GHashTable **) (((unsigned char *) pool) + sizeof(*pool)); /* Show debug info */ gsize ndtor = 0; LL_COUNT(pool->priv->dtors_head, destructor, ndtor); @@ -850,14 +850,14 @@ void rspamd_mempool_delete(rspamd_mempool_t *pool) while (g_hash_table_iter_next(&it, &k, &v)) { struct mempool_debug_elt e; - e.loc = (const gchar *) k; + e.loc = (const char *) k; e.sz = GPOINTER_TO_SIZE(v); g_array_append_val(sorted_debug_size, e); } g_array_sort(sorted_debug_size, rspamd_mempool_debug_elt_cmp); - for (guint _i = 0; _i < sorted_debug_size->len; _i++) { + for (unsigned int _i = 0; _i < sorted_debug_size->len; _i++) { struct mempool_debug_elt *e; e = &g_array_index(sorted_debug_size, struct mempool_debug_elt, _i); @@ -905,7 +905,7 @@ void rspamd_mempool_delete(rspamd_mempool_t *pool) LL_FOREACH_SAFE(pool->priv->pools[i], cur, tmp) { g_atomic_int_add(&mem_pool_stat->bytes_allocated, - -((gint) cur->slice_size)); + -((int) cur->slice_size)); g_atomic_int_add(&mem_pool_stat->chunks_allocated, -1); len = cur->slice_size + sizeof(struct _pool_chain); @@ -957,7 +957,7 @@ gsize rspamd_mempool_suggest_size_(const char *loc) /* * Own emulation */ -static inline gint +static inline int __mutex_spin(rspamd_mempool_mutex_t *mutex) { /* check spin count */ @@ -1159,7 +1159,7 @@ void rspamd_mempool_wunlock_rwlock(rspamd_mempool_rwlock_t *lock) #define RSPAMD_MEMPOOL_VARS_HASH_SEED 0xb32ad7c55eb2e647ULL void rspamd_mempool_set_variable(rspamd_mempool_t *pool, - const gchar *name, + const char *name, gpointer value, rspamd_mempool_destruct_t destructor) { @@ -1175,10 +1175,10 @@ void rspamd_mempool_set_variable(rspamd_mempool_t *pool, } } - gint hv = rspamd_cryptobox_fast_hash(name, strlen(name), - RSPAMD_MEMPOOL_VARS_HASH_SEED); + int hv = rspamd_cryptobox_fast_hash(name, strlen(name), + RSPAMD_MEMPOOL_VARS_HASH_SEED); khiter_t it; - gint r; + int r; it = kh_put(rspamd_mempool_vars_hash, pool->priv->variables, hv, &r); @@ -1204,15 +1204,15 @@ void rspamd_mempool_set_variable(rspamd_mempool_t *pool, } gpointer -rspamd_mempool_get_variable(rspamd_mempool_t *pool, const gchar *name) +rspamd_mempool_get_variable(rspamd_mempool_t *pool, const char *name) { if (pool->priv->variables == NULL) { return NULL; } khiter_t it; - gint hv = rspamd_cryptobox_fast_hash(name, strlen(name), - RSPAMD_MEMPOOL_VARS_HASH_SEED); + int hv = rspamd_cryptobox_fast_hash(name, strlen(name), + RSPAMD_MEMPOOL_VARS_HASH_SEED); it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv); @@ -1227,15 +1227,15 @@ rspamd_mempool_get_variable(rspamd_mempool_t *pool, const gchar *name) } gpointer -rspamd_mempool_steal_variable(rspamd_mempool_t *pool, const gchar *name) +rspamd_mempool_steal_variable(rspamd_mempool_t *pool, const char *name) { if (pool->priv->variables == NULL) { return NULL; } khiter_t it; - gint hv = rspamd_cryptobox_fast_hash(name, strlen(name), - RSPAMD_MEMPOOL_VARS_HASH_SEED); + int hv = rspamd_cryptobox_fast_hash(name, strlen(name), + RSPAMD_MEMPOOL_VARS_HASH_SEED); it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv); @@ -1251,12 +1251,12 @@ rspamd_mempool_steal_variable(rspamd_mempool_t *pool, const gchar *name) return NULL; } -void rspamd_mempool_remove_variable(rspamd_mempool_t *pool, const gchar *name) +void rspamd_mempool_remove_variable(rspamd_mempool_t *pool, const char *name) { if (pool->priv->variables != NULL) { khiter_t it; - gint hv = rspamd_cryptobox_fast_hash(name, strlen(name), - RSPAMD_MEMPOOL_VARS_HASH_SEED); + int hv = rspamd_cryptobox_fast_hash(name, strlen(name), + RSPAMD_MEMPOOL_VARS_HASH_SEED); it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv); diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h index de0fea14b..651b44661 100644 --- a/src/libutil/mem_pool.h +++ b/src/libutil/mem_pool.h @@ -85,9 +85,9 @@ typedef void (*rspamd_mempool_destruct_t)(void *ptr); */ #if !defined(HAVE_PTHREAD_PROCESS_SHARED) || defined(DISABLE_PTHREAD_MUTEX) typedef struct memory_pool_mutex_s { - gint lock; + int lock; pid_t owner; - guint spin; + unsigned int spin; } rspamd_mempool_mutex_t; /** * Rwlock for locking shared memory regions @@ -105,8 +105,8 @@ typedef pthread_rwlock_t rspamd_mempool_rwlock_t; * Tag to use for logging purposes */ struct rspamd_mempool_tag { - gchar tagname[MEMPOOL_TAG_LEN]; /**< readable name */ - gchar uid[MEMPOOL_UID_LEN]; /**< unique id */ + char tagname[MEMPOOL_TAG_LEN]; /**< readable name */ + char uid[MEMPOOL_UID_LEN]; /**< unique id */ }; enum rspamd_mempool_flags { @@ -128,14 +128,14 @@ typedef struct memory_pool_s { * Statistics structure */ typedef struct memory_pool_stat_s { - guint pools_allocated; /**< total number of allocated pools */ - guint pools_freed; /**< number of freed pools */ - guint bytes_allocated; /**< bytes that are allocated with pool allocator */ - guint chunks_allocated; /**< number of chunks that are allocated */ - guint shared_chunks_allocated; /**< shared chunks allocated */ - guint chunks_freed; /**< chunks freed */ - guint oversized_chunks; /**< oversized chunks */ - guint fragmented_size; /**< fragmentation size */ + unsigned int pools_allocated; /**< total number of allocated pools */ + unsigned int pools_freed; /**< number of freed pools */ + unsigned int bytes_allocated; /**< bytes that are allocated with pool allocator */ + unsigned int chunks_allocated; /**< number of chunks that are allocated */ + unsigned int shared_chunks_allocated; /**< shared chunks allocated */ + unsigned int chunks_freed; /**< chunks freed */ + unsigned int oversized_chunks; /**< oversized chunks */ + unsigned int fragmented_size; /**< fragmentation size */ } rspamd_mempool_stat_t; @@ -144,8 +144,8 @@ typedef struct memory_pool_stat_s { * @param size size of pool's page * @return new memory pool object */ -rspamd_mempool_t *rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, - const gchar *loc); +rspamd_mempool_t *rspamd_mempool_new_(gsize size, const char *tag, int flags, + const char *loc); #define rspamd_mempool_new(size, tag, flags) \ rspamd_mempool_new_((size), (tag), (flags), G_STRLOC) @@ -158,7 +158,7 @@ rspamd_mempool_t *rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, * @param size bytes to allocate * @return pointer to allocated object */ -void *rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc) +void *rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc) RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; /** * Allocates array handling potential integer overflow @@ -169,7 +169,7 @@ void *rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, * @param loc * @return */ -void *rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const gchar *loc) +void *rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const char *loc) RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; #define rspamd_mempool_alloc(pool, size) \ rspamd_mempool_alloc_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC)) @@ -188,7 +188,7 @@ void *rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize siz * @param size * @param loc */ -void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const gchar *loc); +void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const char *loc); #define rspamd_mempool_notify_alloc(pool, size) \ rspamd_mempool_notify_alloc_((pool), (size), (G_STRLOC)) @@ -198,7 +198,7 @@ void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const gcha * @param size bytes to allocate * @return pointer to allocated object */ -void *rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc) +void *rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc) RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; #define rspamd_mempool_alloc0(pool, size) \ rspamd_mempool_alloc0_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC)) @@ -212,11 +212,11 @@ void *rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment * @param src source string * @return pointer to newly created string that is copy of src */ -gchar *rspamd_mempool_strdup_(rspamd_mempool_t *pool, const gchar *src, const gchar *loc) +char *rspamd_mempool_strdup_(rspamd_mempool_t *pool, const char *src, const char *loc) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT); #define rspamd_mempool_strdup(pool, src) \ rspamd_mempool_strdup_((pool), (src), (G_STRLOC)) -gchar *rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const gchar *src, gsize len, const gchar *loc) +char *rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const char *src, gsize len, const char *loc) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT); #define rspamd_mempool_strdup_len(pool, src, len) \ rspamd_mempool_strdup_len_((pool), (src), (len), (G_STRLOC)) @@ -229,9 +229,9 @@ struct f_str_tok; * @param src source string * @return pointer to newly created string that is copy of src */ -gchar *rspamd_mempool_ftokdup_(rspamd_mempool_t *pool, - const struct f_str_tok *src, - const gchar *loc) +char *rspamd_mempool_ftokdup_(rspamd_mempool_t *pool, + const struct f_str_tok *src, + const char *loc) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT); #define rspamd_mempool_ftokdup(pool, src) \ rspamd_mempool_ftokdup_((pool), (src), (G_STRLOC)) @@ -241,7 +241,7 @@ gchar *rspamd_mempool_ftokdup_(rspamd_mempool_t *pool, * @param pool memory pool object * @param size bytes to allocate */ -void *rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc) +void *rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc) RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; #define rspamd_mempool_alloc_shared(pool, size) \ rspamd_mempool_alloc_shared_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC)) @@ -249,7 +249,7 @@ void *rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize ali (type *) (rspamd_mempool_alloc_shared_((pool), sizeof(type), \ MAX(MIN_MEM_ALIGNMENT, RSPAMD_ALIGNOF(type)), (G_STRLOC))) -void *rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc) +void *rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc) RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; #define rspamd_mempool_alloc0_shared(pool, size) \ rspamd_mempool_alloc0_shared_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC)) @@ -266,8 +266,8 @@ void *rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize al void rspamd_mempool_add_destructor_full(rspamd_mempool_t *pool, rspamd_mempool_destruct_t func, void *data, - const gchar *function, - const gchar *line); + const char *function, + const char *line); /* Macros for common usage */ #define rspamd_mempool_add_destructor(pool, func, data) \ @@ -377,7 +377,7 @@ gsize rspamd_mempool_get_wasted_size(rspamd_mempool_t *pool); * @param destructor pointer to function-destructor */ void rspamd_mempool_set_variable(rspamd_mempool_t *pool, - const gchar *name, + const char *name, gpointer value, rspamd_mempool_destruct_t destructor); @@ -388,7 +388,7 @@ void rspamd_mempool_set_variable(rspamd_mempool_t *pool, * @return NULL or pointer to variable data */ gpointer rspamd_mempool_get_variable(rspamd_mempool_t *pool, - const gchar *name); + const char *name); /** * Steal memory pool variable * @param pool @@ -396,7 +396,7 @@ gpointer rspamd_mempool_get_variable(rspamd_mempool_t *pool, * @return */ gpointer rspamd_mempool_steal_variable(rspamd_mempool_t *pool, - const gchar *name); + const char *name); /** * Removes variable from memory pool @@ -404,7 +404,7 @@ gpointer rspamd_mempool_steal_variable(rspamd_mempool_t *pool, * @param name name of variable */ void rspamd_mempool_remove_variable(rspamd_mempool_t *pool, - const gchar *name); + const char *name); /** * Prepend element to a list creating it in the memory pool diff --git a/src/libutil/mem_pool_internal.h b/src/libutil/mem_pool_internal.h index 9fff5c7de..26a687b6c 100644 --- a/src/libutil/mem_pool_internal.h +++ b/src/libutil/mem_pool_internal.h @@ -1,11 +1,11 @@ -/*- - * Copyright 2019 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ */ #define align_ptr(p, a) \ - ((guint8 *) ((uintptr_t) (p) + ((-(intptr_t) (p)) & ((a) -1)))) + ((uint8_t *) ((uintptr_t) (p) + ((-(intptr_t) (p)) & ((a) -1)))) enum rspamd_mempool_chain_type { RSPAMD_MEMPOOL_NORMAL = 0, @@ -38,7 +38,7 @@ struct entry_elt { }; struct rspamd_mempool_entry_point { - gchar src[ENTRY_LEN]; + char src[ENTRY_LEN]; uint32_t cur_suggestion; uint32_t cur_elts; uint32_t cur_vars; @@ -51,8 +51,8 @@ struct rspamd_mempool_entry_point { struct _pool_destructors { rspamd_mempool_destruct_t func; /**< pointer to destructor */ void *data; /**< data to free */ - const gchar *function; /**< function from which this destructor was added */ - const gchar *loc; /**< line number */ + const char *function; /**< function from which this destructor was added */ + const char *loc; /**< line number */ struct _pool_destructors *next; }; @@ -74,16 +74,16 @@ struct rspamd_mempool_specific { struct rspamd_mempool_entry_point *entry; gsize elt_len; /**< size of an element */ gsize used_memory; - guint wasted_memory; - gint flags; + unsigned int wasted_memory; + int flags; }; /** * Pool page structure */ struct _pool_chain { - guint8 *begin; /**< begin of pool chain block */ - guint8 *pos; /**< current start of free space in block */ + uint8_t *begin; /**< begin of pool chain block */ + uint8_t *pos; /**< current start of free space in block */ gsize slice_size; /**< length of block */ struct _pool_chain *next; }; diff --git a/src/libutil/multipattern.c b/src/libutil/multipattern.c index bf3c7ad9a..3c9be0df3 100644 --- a/src/libutil/multipattern.c +++ b/src/libutil/multipattern.c @@ -49,14 +49,14 @@ struct RSPAMD_ALIGNED(64) rspamd_multipattern { GArray *hs_pats; GArray *hs_ids; GArray *hs_flags; - guint scratch_used; + unsigned int scratch_used; #endif ac_trie_t *t; GArray *pats; GArray *res; gboolean compiled; - guint cnt; + unsigned int cnt; enum rspamd_multipattern_flags flags; }; @@ -83,7 +83,7 @@ rspamd_hs_check(void) return hs_suitable_cpu == RSPAMD_HS_SUPPORTED; } -void rspamd_multipattern_library_init(const gchar *cache_dir) +void rspamd_multipattern_library_init(const char *cache_dir) { hs_cache_dir = cache_dir; #ifdef WITH_HYPERSCAN @@ -92,13 +92,13 @@ void rspamd_multipattern_library_init(const gchar *cache_dir) } #ifdef WITH_HYPERSCAN -static gchar * -rspamd_multipattern_escape_tld_hyperscan(const gchar *pattern, gsize slen, +static char * +rspamd_multipattern_escape_tld_hyperscan(const char *pattern, gsize slen, gsize *dst_len) { gsize len; - const gchar *p, *prefix, *suffix; - gchar *res; + const char *p, *prefix, *suffix; + char *res; /* * We understand the following cases @@ -141,13 +141,13 @@ rspamd_multipattern_escape_tld_hyperscan(const gchar *pattern, gsize slen, } #endif -static gchar * -rspamd_multipattern_escape_tld_acism(const gchar *pattern, gsize len, +static char * +rspamd_multipattern_escape_tld_acism(const char *pattern, gsize len, gsize *dst_len) { gsize dlen, slen; - const gchar *p, *prefix; - gchar *res; + const char *p, *prefix; + char *res; /* * We understand the following cases @@ -192,13 +192,13 @@ rspamd_multipattern_escape_tld_acism(const gchar *pattern, gsize len, /* * Escapes special characters from specific pattern */ -static gchar * -rspamd_multipattern_pattern_filter(const gchar *pattern, gsize len, +static char * +rspamd_multipattern_pattern_filter(const char *pattern, gsize len, enum rspamd_multipattern_flags flags, gsize *dst_len) { - gchar *ret = NULL; - gint gl_flags = RSPAMD_REGEXP_ESCAPE_ASCII; + char *ret = NULL; + int gl_flags = RSPAMD_REGEXP_ESCAPE_ASCII; if (flags & RSPAMD_MULTIPATTERN_UTF8) { gl_flags |= RSPAMD_REGEXP_ESCAPE_UTF; @@ -207,7 +207,7 @@ rspamd_multipattern_pattern_filter(const gchar *pattern, gsize len, #ifdef WITH_HYPERSCAN if (rspamd_hs_check()) { if (flags & RSPAMD_MULTIPATTERN_TLD) { - gchar *tmp; + char *tmp; gsize tlen; tmp = rspamd_multipattern_escape_tld_hyperscan(pattern, len, &tlen); @@ -262,9 +262,9 @@ rspamd_multipattern_create(enum rspamd_multipattern_flags flags) #ifdef WITH_HYPERSCAN if (rspamd_hs_check()) { - mp->hs_pats = g_array_new(FALSE, TRUE, sizeof(gchar *)); - mp->hs_flags = g_array_new(FALSE, TRUE, sizeof(gint)); - mp->hs_ids = g_array_new(FALSE, TRUE, sizeof(gint)); + mp->hs_pats = g_array_new(FALSE, TRUE, sizeof(char *)); + mp->hs_flags = g_array_new(FALSE, TRUE, sizeof(int)); + mp->hs_ids = g_array_new(FALSE, TRUE, sizeof(int)); rspamd_cryptobox_hash_init(&mp->hash_state, NULL, 0); return mp; @@ -277,7 +277,7 @@ rspamd_multipattern_create(enum rspamd_multipattern_flags flags) } struct rspamd_multipattern * -rspamd_multipattern_create_sized(guint npatterns, +rspamd_multipattern_create_sized(unsigned int npatterns, enum rspamd_multipattern_flags flags) { struct rspamd_multipattern *mp; @@ -290,9 +290,9 @@ rspamd_multipattern_create_sized(guint npatterns, #ifdef WITH_HYPERSCAN if (rspamd_hs_check()) { - mp->hs_pats = g_array_sized_new(FALSE, TRUE, sizeof(gchar *), npatterns); - mp->hs_flags = g_array_sized_new(FALSE, TRUE, sizeof(gint), npatterns); - mp->hs_ids = g_array_sized_new(FALSE, TRUE, sizeof(gint), npatterns); + mp->hs_pats = g_array_sized_new(FALSE, TRUE, sizeof(char *), npatterns); + mp->hs_flags = g_array_sized_new(FALSE, TRUE, sizeof(int), npatterns); + mp->hs_ids = g_array_sized_new(FALSE, TRUE, sizeof(int), npatterns); rspamd_cryptobox_hash_init(&mp->hash_state, NULL, 0); return mp; @@ -305,7 +305,7 @@ rspamd_multipattern_create_sized(guint npatterns, } void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp, - const gchar *pattern, gint flags) + const char *pattern, int flags) { g_assert(pattern != NULL); @@ -313,7 +313,7 @@ void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp, } void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp, - const gchar *pattern, gsize patlen, gint flags) + const char *pattern, gsize patlen, int flags) { gsize dlen; @@ -323,9 +323,9 @@ void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp, #ifdef WITH_HYPERSCAN if (rspamd_hs_check()) { - gchar *np; - gint fl = HS_FLAG_SOM_LEFTMOST; - gint adjusted_flags = mp->flags | flags; + char *np; + int fl = HS_FLAG_SOM_LEFTMOST; + int adjusted_flags = mp->flags | flags; if (adjusted_flags & RSPAMD_MULTIPATTERN_ICASE) { fl |= HS_FLAG_CASELESS; @@ -372,11 +372,11 @@ void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp, } struct rspamd_multipattern * -rspamd_multipattern_create_full(const gchar **patterns, - guint npatterns, enum rspamd_multipattern_flags flags) +rspamd_multipattern_create_full(const char **patterns, + unsigned int npatterns, enum rspamd_multipattern_flags flags) { struct rspamd_multipattern *mp; - guint i; + unsigned int i; g_assert(npatterns > 0); g_assert(patterns != NULL); @@ -393,16 +393,16 @@ rspamd_multipattern_create_full(const gchar **patterns, #ifdef WITH_HYPERSCAN static gboolean rspamd_multipattern_try_load_hs(struct rspamd_multipattern *mp, - const guchar *hash) + const unsigned char *hash) { - gchar fp[PATH_MAX]; + char fp[PATH_MAX]; if (hs_cache_dir == NULL) { return FALSE; } rspamd_snprintf(fp, sizeof(fp), "%s/%*xs.hsmp", hs_cache_dir, - (gint) rspamd_cryptobox_HASHBYTES / 2, hash); + (int) rspamd_cryptobox_HASHBYTES / 2, hash); mp->hs_db = rspamd_hyperscan_maybe_load(fp, 0); return mp->hs_db != NULL; @@ -410,12 +410,12 @@ rspamd_multipattern_try_load_hs(struct rspamd_multipattern *mp, static void rspamd_multipattern_try_save_hs(struct rspamd_multipattern *mp, - const guchar *hash) + const unsigned char *hash) { - gchar fp[PATH_MAX], np[PATH_MAX]; + char fp[PATH_MAX], np[PATH_MAX]; char *bytes = NULL; gsize len; - gint fd; + int fd; if (hs_cache_dir == NULL) { return; @@ -438,7 +438,7 @@ rspamd_multipattern_try_save_hs(struct rspamd_multipattern *mp, fsync(fd); rspamd_snprintf(np, sizeof(np), "%s/%*xs.hsmp", hs_cache_dir, - (gint) rspamd_cryptobox_HASHBYTES / 2, hash); + (int) rspamd_cryptobox_HASHBYTES / 2, hash); if (rename(fp, np) == -1) { msg_warn("cannot rename hyperscan cache from %s to %s: %s", @@ -473,10 +473,10 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError ** #ifdef WITH_HYPERSCAN if (rspamd_hs_check()) { - guint i; + unsigned int i; hs_platform_info_t plt; hs_compile_error_t *hs_errors; - guchar hash[rspamd_cryptobox_HASHBYTES]; + unsigned char hash[rspamd_cryptobox_HASHBYTES]; if (mp->cnt > 0) { g_assert(hs_populate_platform(&plt) == HS_SUCCESS); @@ -508,7 +508,7 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError ** if (hs_cache_dir != NULL) { char fpath[PATH_MAX]; rspamd_snprintf(fpath, sizeof(fpath), "%s/%*xs.hsmp", hs_cache_dir, - (gint) rspamd_cryptobox_HASHBYTES / 2, hash); + (int) rspamd_cryptobox_HASHBYTES / 2, hash); mp->hs_db = rspamd_hyperscan_from_raw_db(db, fpath); } else { @@ -564,9 +564,9 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError ** mp->res = g_array_sized_new(FALSE, TRUE, sizeof(rspamd_regexp_t *), mp->cnt); - for (guint i = 0; i < mp->cnt; i++) { + for (unsigned int i = 0; i < mp->cnt; i++) { const ac_trie_pat_t *pat; - const gchar *pat_flags = NULL; + const char *pat_flags = NULL; if (mp->flags & RSPAMD_MULTIPATTERN_UTF8) { pat_flags = "u"; @@ -594,16 +594,16 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError ** struct rspamd_multipattern_cbdata { struct rspamd_multipattern *mp; - const gchar *in; + const char *in; gsize len; rspamd_multipattern_cb_t cb; gpointer ud; - guint nfound; - gint ret; + unsigned int nfound; + int ret; }; #ifdef WITH_HYPERSCAN -static gint +static int rspamd_multipattern_hs_cb(unsigned int id, unsigned long long from, unsigned long long to, @@ -611,7 +611,7 @@ rspamd_multipattern_hs_cb(unsigned int id, void *ud) { struct rspamd_multipattern_cbdata *cbd = ud; - gint ret = 0; + int ret = 0; if (to > 0) { @@ -629,11 +629,11 @@ rspamd_multipattern_hs_cb(unsigned int id, } #endif -static gint +static int rspamd_multipattern_acism_cb(int strnum, int textpos, void *context) { struct rspamd_multipattern_cbdata *cbd = context; - gint ret; + int ret; ac_trie_pat_t pat; pat = g_array_index(cbd->mp->pats, ac_trie_pat_t, strnum); @@ -646,12 +646,12 @@ rspamd_multipattern_acism_cb(int strnum, int textpos, void *context) return ret; } -gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp, - const gchar *in, gsize len, rspamd_multipattern_cb_t cb, - gpointer ud, guint *pnfound) +int rspamd_multipattern_lookup(struct rspamd_multipattern *mp, + const char *in, gsize len, rspamd_multipattern_cb_t cb, + gpointer ud, unsigned int *pnfound) { struct rspamd_multipattern_cbdata cbd; - gint ret = 0; + int ret = 0; g_assert(mp != NULL); @@ -670,7 +670,7 @@ gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp, #ifdef WITH_HYPERSCAN if (rspamd_hs_check()) { hs_scratch_t *scr = NULL; - guint i; + unsigned int i; for (i = 0; i < MAX_SCRATCH; i++) { if (!(mp->scratch_used & (1 << i))) { @@ -702,13 +702,13 @@ gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp, } #endif - gint state = 0; + int state = 0; if (mp->flags & (RSPAMD_MULTIPATTERN_GLOB | RSPAMD_MULTIPATTERN_RE)) { /* Terribly inefficient, but who cares - just use hyperscan */ - for (guint i = 0; i < mp->cnt; i++) { + for (unsigned int i = 0; i < mp->cnt; i++) { rspamd_regexp_t *re = g_array_index(mp->res, rspamd_regexp_t *, i); - const gchar *start = NULL, *end = NULL; + const char *start = NULL, *end = NULL; while (rspamd_regexp_search(re, in, @@ -745,12 +745,12 @@ gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp, void rspamd_multipattern_destroy(struct rspamd_multipattern *mp) { - guint i; + unsigned int i; if (mp) { #ifdef WITH_HYPERSCAN if (rspamd_hs_check()) { - gchar *p; + char *p; if (mp->compiled && mp->cnt > 0) { for (i = 0; i < MAX_SCRATCH; i++) { @@ -763,7 +763,7 @@ void rspamd_multipattern_destroy(struct rspamd_multipattern *mp) } for (i = 0; i < mp->cnt; i++) { - p = g_array_index(mp->hs_pats, gchar *, i); + p = g_array_index(mp->hs_pats, char *, i); g_free(p); } @@ -783,7 +783,7 @@ void rspamd_multipattern_destroy(struct rspamd_multipattern *mp) for (i = 0; i < mp->cnt; i++) { pat = g_array_index(mp->pats, ac_trie_pat_t, i); - g_free((gchar *) pat.ptr); + g_free((char *) pat.ptr); } g_array_free(mp->pats, TRUE); @@ -792,16 +792,16 @@ void rspamd_multipattern_destroy(struct rspamd_multipattern *mp) } } -const gchar * +const char * rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp, - guint index) + unsigned int index) { g_assert(mp != NULL); g_assert(index < mp->cnt); #ifdef WITH_HYPERSCAN if (rspamd_hs_check()) { - return g_array_index(mp->hs_pats, gchar *, index); + return g_array_index(mp->hs_pats, char *, index); } #endif @@ -812,7 +812,7 @@ rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp, return pat.ptr; } -guint rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp) +unsigned int rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp) { g_assert(mp != NULL); diff --git a/src/libutil/multipattern.h b/src/libutil/multipattern.h index 15099aaca..771dcd94a 100644 --- a/src/libutil/multipattern.h +++ b/src/libutil/multipattern.h @@ -56,19 +56,19 @@ struct rspamd_cryptobox_library_ctx; * @param context userdata * @return if 0 then search for another pattern, otherwise return this value to caller */ -typedef gint (*rspamd_multipattern_cb_t)(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, - gsize len, - void *context); +typedef int (*rspamd_multipattern_cb_t)(struct rspamd_multipattern *mp, + unsigned int strnum, + int match_start, + int match_pos, + const char *text, + gsize len, + void *context); /** * Init multipart library and set the appropriate cache dir * @param cache_dir */ -void rspamd_multipattern_library_init(const gchar *cache_dir); +void rspamd_multipattern_library_init(const char *cache_dir); /** * Creates empty multipattern structure @@ -84,7 +84,7 @@ struct rspamd_multipattern *rspamd_multipattern_create( * @param reserved * @return */ -struct rspamd_multipattern *rspamd_multipattern_create_sized(guint reserved, +struct rspamd_multipattern *rspamd_multipattern_create_sized(unsigned int reserved, enum rspamd_multipattern_flags flags); /** @@ -95,8 +95,8 @@ struct rspamd_multipattern *rspamd_multipattern_create_sized(guint reserved, * @return new multipattern structure */ struct rspamd_multipattern *rspamd_multipattern_create_full( - const gchar **patterns, - guint npatterns, + const char **patterns, + unsigned int npatterns, enum rspamd_multipattern_flags flags); /** @@ -105,7 +105,7 @@ struct rspamd_multipattern *rspamd_multipattern_create_full( * @param pattern */ void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp, - const gchar *pattern, gint flags); + const char *pattern, int flags); /** * Adds new pattern from arbitrary string @@ -115,7 +115,7 @@ void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp, * @param flags */ void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp, - const gchar *pattern, gsize patlen, gint flags); + const char *pattern, gsize patlen, int flags); #define RSPAMD_MULTIPATTERN_COMPILE_NO_FS (0x1u << 0u) @@ -137,9 +137,9 @@ gboolean rspamd_multipattern_compile(struct rspamd_multipattern *mp, * @param ud callback data * @return */ -gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp, - const gchar *in, gsize len, rspamd_multipattern_cb_t cb, - gpointer ud, guint *pnfound); +int rspamd_multipattern_lookup(struct rspamd_multipattern *mp, + const char *in, gsize len, rspamd_multipattern_cb_t cb, + gpointer ud, unsigned int *pnfound); /** * Get pattern string from multipattern identified by index @@ -147,15 +147,15 @@ gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp, * @param index * @return */ -const gchar *rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp, - guint index); +const char *rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp, + unsigned int index); /** * Returns number of patterns in a multipattern matcher * @param mp * @return */ -guint rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp); +unsigned int rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp); /** * Destroys multipattern structure diff --git a/src/libutil/printf.c b/src/libutil/printf.c index b8322fc6b..82eab0ab8 100644 --- a/src/libutil/printf.c +++ b/src/libutil/printf.c @@ -46,13 +46,13 @@ * From FreeBSD libutil code */ static const int maxscale = 6; -static const gchar _hex[] = "0123456789abcdef"; -static const gchar _HEX[] = "0123456789ABCDEF"; +static const char _hex[] = "0123456789abcdef"; +static const char _HEX[] = "0123456789ABCDEF"; -static gchar * -rspamd_humanize_number(gchar *buf, gchar *last, int64_t num, gboolean bytes) +static char * +rspamd_humanize_number(char *buf, char *last, int64_t num, gboolean bytes) { - const gchar *prefixes; + const char *prefixes; int i, r, remainder, sign; int64_t divisor; gsize len = last - buf; @@ -96,7 +96,7 @@ rspamd_humanize_number(gchar *buf, gchar *last, int64_t num, gboolean bytes) else { /* Floating point version */ r = rspamd_snprintf(buf, len, "%.2f%s", - sign * (num + remainder / (gdouble) divisor), + sign * (num + remainder / (double) divisor), SCALE2PREFIX(i)); } @@ -255,11 +255,11 @@ static const char int_lookup_table[200] = { '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'}; -static inline guint -rspamd_uint32_print(uint32_t in, gchar *out) +static inline unsigned int +rspamd_uint32_print(uint32_t in, char *out) { - guint ndigits = rspamd_decimal_digits32(in); - gchar *p; + unsigned int ndigits = rspamd_decimal_digits32(in); + char *p; p = out + ndigits - 1; @@ -286,12 +286,12 @@ rspamd_uint32_print(uint32_t in, gchar *out) return ndigits; } -static inline guint -rspamd_uint64_print(uint64_t in, gchar *out) +static inline unsigned int +rspamd_uint64_print(uint64_t in, char *out) { - guint ndigits = rspamd_decimal_digits64(in); + unsigned int ndigits = rspamd_decimal_digits64(in); uint32_t v32; - gchar *p; + char *p; p = out + ndigits - 1; @@ -376,11 +376,11 @@ rspamd_ffsll(long long n) #endif } -static gchar * -rspamd_sprintf_num(gchar *buf, gchar *last, uint64_t ui64, gchar zero, - guint hexadecimal, guint binary, guint width) +static char * +rspamd_sprintf_num(char *buf, char *last, uint64_t ui64, char zero, + unsigned int hexadecimal, unsigned int binary, unsigned int width) { - gchar *p, temp[64]; + char *p, temp[64]; size_t len = 0; if (G_LIKELY(hexadecimal == 0 && binary == 0)) { @@ -436,7 +436,7 @@ rspamd_sprintf_num(gchar *buf, gchar *last, uint64_t ui64, gchar zero, len = last - buf; } - return ((gchar *) memcpy(buf, p, len)) + len; + return ((char *) memcpy(buf, p, len)) + len; } struct rspamd_printf_char_buf { @@ -446,7 +446,7 @@ struct rspamd_printf_char_buf { }; static glong -rspamd_printf_append_char(const gchar *buf, glong buflen, gpointer ud) +rspamd_printf_append_char(const char *buf, glong buflen, gpointer ud) { struct rspamd_printf_char_buf *dst = (struct rspamd_printf_char_buf *) ud; glong wr; @@ -464,7 +464,7 @@ rspamd_printf_append_char(const gchar *buf, glong buflen, gpointer ud) } static glong -rspamd_printf_append_file(const gchar *buf, glong buflen, gpointer ud) +rspamd_printf_append_file(const char *buf, glong buflen, gpointer ud) { FILE *dst = (FILE *) ud; if (buflen > 0) { @@ -476,7 +476,7 @@ rspamd_printf_append_file(const gchar *buf, glong buflen, gpointer ud) } static glong -rspamd_printf_append_gstring(const gchar *buf, glong buflen, gpointer ud) +rspamd_printf_append_gstring(const char *buf, glong buflen, gpointer ud) { GString *dst = (GString *) ud; @@ -488,7 +488,7 @@ rspamd_printf_append_gstring(const gchar *buf, glong buflen, gpointer ud) } static glong -rspamd_printf_append_fstring(const gchar *buf, glong buflen, gpointer ud) +rspamd_printf_append_fstring(const char *buf, glong buflen, gpointer ud) { rspamd_fstring_t **dst = ud; @@ -499,7 +499,7 @@ rspamd_printf_append_fstring(const gchar *buf, glong buflen, gpointer ud) return buflen; } -glong rspamd_fprintf(FILE *f, const gchar *fmt, ...) +glong rspamd_fprintf(FILE *f, const char *fmt, ...) { va_list args; glong r; @@ -511,7 +511,7 @@ glong rspamd_fprintf(FILE *f, const gchar *fmt, ...) return r; } -glong rspamd_printf(const gchar *fmt, ...) +glong rspamd_printf(const char *fmt, ...) { va_list args; glong r; @@ -523,7 +523,7 @@ glong rspamd_printf(const gchar *fmt, ...) return r; } -glong rspamd_log_fprintf(FILE *f, const gchar *fmt, ...) +glong rspamd_log_fprintf(FILE *f, const char *fmt, ...) { va_list args; glong r; @@ -538,9 +538,9 @@ glong rspamd_log_fprintf(FILE *f, const gchar *fmt, ...) } -glong rspamd_snprintf(gchar *buf, glong max, const gchar *fmt, ...) +glong rspamd_snprintf(char *buf, glong max, const char *fmt, ...) { - gchar *r; + char *r; va_list args; va_start(args, fmt); @@ -550,8 +550,8 @@ glong rspamd_snprintf(gchar *buf, glong max, const gchar *fmt, ...) return (r - buf); } -gchar * -rspamd_vsnprintf(gchar *buf, glong max, const gchar *fmt, va_list args) +char * +rspamd_vsnprintf(char *buf, glong max, const char *fmt, va_list args) { struct rspamd_printf_char_buf dst; @@ -564,7 +564,7 @@ rspamd_vsnprintf(gchar *buf, glong max, const gchar *fmt, va_list args) return dst.pos; } -glong rspamd_printf_gstring(GString *s, const gchar *fmt, ...) +glong rspamd_printf_gstring(GString *s, const char *fmt, ...) { va_list args; glong r; @@ -576,12 +576,12 @@ glong rspamd_printf_gstring(GString *s, const gchar *fmt, ...) return r; } -glong rspamd_vprintf_gstring(GString *s, const gchar *fmt, va_list args) +glong rspamd_vprintf_gstring(GString *s, const char *fmt, va_list args) { return rspamd_vprintf_common(rspamd_printf_append_gstring, s, fmt, args); } -glong rspamd_printf_fstring(rspamd_fstring_t **s, const gchar *fmt, ...) +glong rspamd_printf_fstring(rspamd_fstring_t **s, const char *fmt, ...) { va_list args; glong r; @@ -593,7 +593,7 @@ glong rspamd_printf_fstring(rspamd_fstring_t **s, const gchar *fmt, ...) return r; } -glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const gchar *fmt, va_list args) +glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const char *fmt, va_list args) { return rspamd_vprintf_common(rspamd_printf_append_fstring, s, fmt, args); } @@ -616,18 +616,18 @@ glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const gchar *fmt, va_list arg glong rspamd_vprintf_common(rspamd_printf_append_func func, gpointer apd, - const gchar *fmt, + const char *fmt, va_list args) { - gchar zero, numbuf[G_ASCII_DTOSTR_BUF_SIZE], dtoabuf[32], *p, *last; - guchar c; - const gchar *buf_start = fmt; - gint d; - gdouble f; + char zero, numbuf[G_ASCII_DTOSTR_BUF_SIZE], dtoabuf[32], *p, *last; + unsigned char c; + const char *buf_start = fmt; + int d; + double f; glong written = 0, wr, slen; int64_t i64; uint64_t ui64; - guint width, sign, hex, humanize, bytes, frac_width, b32, b64; + unsigned int width, sign, hex, humanize, bytes, frac_width, b32, b64; rspamd_fstring_t *v; rspamd_ftok_t *tok; GString *gs; @@ -654,7 +654,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, i64 = 0; ui64 = 0; - zero = (gchar) ((*++fmt == '0') ? '0' : ' '); + zero = (char) ((*++fmt == '0') ? '0' : ' '); width = 0; sign = 1; hex = 0; @@ -718,11 +718,11 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, fmt++; if (*fmt == '*') { - d = (gint) va_arg(args, gint); + d = (int) va_arg(args, int); if (G_UNLIKELY(d < 0)) { return 0; } - frac_width = (guint) d; + frac_width = (unsigned int) d; fmt++; } else { @@ -734,7 +734,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, break; case '*': - d = (gint) va_arg(args, gint); + d = (int) va_arg(args, int); if (G_UNLIKELY(d < 0)) { return 0; } @@ -824,14 +824,14 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, continue; case 's': - p = va_arg(args, gchar *); + p = va_arg(args, char *); if (p == NULL) { p = "(NULL)"; slen = sizeof("(NULL)") - 1; } if (G_UNLIKELY(b32)) { - gchar *b32buf; + char *b32buf; if (G_UNLIKELY(slen == -1)) { if (G_LIKELY(width != 0)) { @@ -854,7 +854,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, } } else if (G_UNLIKELY(hex)) { - gchar hexbuf[2]; + char hexbuf[2]; if (G_UNLIKELY(slen == -1)) { if (G_LIKELY(width != 0)) { @@ -878,7 +878,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, buf_start = fmt; } else if (G_UNLIKELY(b64)) { - gchar *b64buf; + char *b64buf; gsize olen = 0; if (G_UNLIKELY(slen == -1)) { @@ -942,10 +942,10 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, case 'd': if (sign) { - i64 = (int64_t) va_arg(args, gint); + i64 = (int64_t) va_arg(args, int); } else { - ui64 = (uint64_t) va_arg(args, guint); + ui64 = (uint64_t) va_arg(args, unsigned int); } break; @@ -978,7 +978,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, case 'f': - f = (gdouble) va_arg(args, double); + f = (double) va_arg(args, double); slen = fpconv_dtoa(f, dtoabuf, frac_width, false); RSPAMD_PRINTF_APPEND(dtoabuf, slen); @@ -986,14 +986,14 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, continue; case 'g': - f = (gdouble) va_arg(args, double); + f = (double) va_arg(args, double); slen = fpconv_dtoa(f, dtoabuf, 0, true); RSPAMD_PRINTF_APPEND(dtoabuf, slen); continue; case 'F': - f = (gdouble) va_arg(args, long double); + f = (double) va_arg(args, long double); slen = fpconv_dtoa(f, dtoabuf, frac_width, false); RSPAMD_PRINTF_APPEND(dtoabuf, slen); @@ -1001,7 +1001,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, continue; case 'G': - f = (gdouble) va_arg(args, long double); + f = (double) va_arg(args, long double); slen = fpconv_dtoa(f, dtoabuf, 0, true); RSPAMD_PRINTF_APPEND(dtoabuf, slen); @@ -1016,10 +1016,10 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func, break; case 'c': - c = va_arg(args, gint); + c = va_arg(args, int); c &= 0xffu; if (G_UNLIKELY(hex)) { - gchar hexbuf[2]; + char hexbuf[2]; hexbuf[0] = hex == 2 ? _HEX[(c >> 4u) & 0xfu] : _hex[(c >> 4u) & 0xfu]; hexbuf[1] = hex == 2 ? _HEX[c & 0xfu] : _hex[c & 0xfu]; diff --git a/src/libutil/printf.h b/src/libutil/printf.h index b4db34b8e..363f47bd9 100644 --- a/src/libutil/printf.h +++ b/src/libutil/printf.h @@ -27,7 +27,7 @@ extern "C" { * %[0][width][x][X]O off_t * %[0][width]T time_t * %[0][width][u][x|X|h|H|b|B]z ssize_t/size_t - * %[0][width][u][x|X|h|H|b|B]d gint/guint + * %[0][width][u][x|X|h|H|b|B]d int/unsigned int * %[0][width][u][x|X|h|H|b|B]l long * %[0][width][u][x|X|h|H|b|B]D int32_t/uint32_t * %[0][width][u][x|X|h|H|b|B]L int64_t/uint64_t @@ -48,7 +48,7 @@ extern "C" { * %*s length and string * %Z '\0' * %N '\n' - * %c gchar + * %c char * %t time_t * %e GError * * %% % @@ -62,31 +62,31 @@ extern "C" { * @param ud opaque pointer * @return number of characters written */ -typedef glong (*rspamd_printf_append_func)(const gchar *buf, glong buflen, +typedef glong (*rspamd_printf_append_func)(const char *buf, glong buflen, gpointer ud); -glong rspamd_fprintf(FILE *f, const gchar *fmt, ...); +glong rspamd_fprintf(FILE *f, const char *fmt, ...); -glong rspamd_printf(const gchar *fmt, ...); +glong rspamd_printf(const char *fmt, ...); -glong rspamd_log_fprintf(FILE *f, const gchar *fmt, ...); +glong rspamd_log_fprintf(FILE *f, const char *fmt, ...); -glong rspamd_snprintf(gchar *buf, glong max, const gchar *fmt, ...); +glong rspamd_snprintf(char *buf, glong max, const char *fmt, ...); -gchar *rspamd_vsnprintf(gchar *buf, glong max, const gchar *fmt, - va_list args); +char *rspamd_vsnprintf(char *buf, glong max, const char *fmt, + va_list args); -glong rspamd_printf_gstring(GString *s, const gchar *fmt, ...); +glong rspamd_printf_gstring(GString *s, const char *fmt, ...); -glong rspamd_vprintf_gstring(GString *s, const gchar *fmt, va_list args); +glong rspamd_vprintf_gstring(GString *s, const char *fmt, va_list args); -glong rspamd_printf_fstring(rspamd_fstring_t **s, const gchar *fmt, ...); +glong rspamd_printf_fstring(rspamd_fstring_t **s, const char *fmt, ...); -glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const gchar *fmt, va_list args); +glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const char *fmt, va_list args); glong rspamd_vprintf_common(rspamd_printf_append_func func, gpointer apd, - const gchar *fmt, + const char *fmt, va_list args); #ifdef __cplusplus diff --git a/src/libutil/radix.c b/src/libutil/radix.c index 93c728c8f..2cae8e34a 100644 --- a/src/libutil/radix.c +++ b/src/libutil/radix.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -41,14 +41,14 @@ INIT_LOG_MODULE(radix) struct radix_tree_compressed { rspamd_mempool_t *pool; struct btrie *tree; - const gchar *name; + const char *name; size_t size; - guint duplicates; + unsigned int duplicates; gboolean own_pool; }; uintptr_t -radix_find_compressed(radix_compressed_t *tree, const guint8 *key, gsize keylen) +radix_find_compressed(radix_compressed_t *tree, const uint8_t *key, gsize keylen) { gconstpointer ret; @@ -66,14 +66,14 @@ radix_find_compressed(radix_compressed_t *tree, const guint8 *key, gsize keylen) uintptr_t radix_insert_compressed(radix_compressed_t *tree, - guint8 *key, gsize keylen, + uint8_t *key, gsize keylen, gsize masklen, uintptr_t value) { - static const guint max_duplicates = 32; - guint keybits = keylen * NBBY; + static const unsigned int max_duplicates = 32; + unsigned int keybits = keylen * NBBY; uintptr_t old; - gchar ip_str[INET6_ADDRSTRLEN + 1]; + char ip_str[INET6_ADDRSTRLEN + 1]; int ret; g_assert(tree != NULL); @@ -103,14 +103,14 @@ radix_insert_compressed(radix_compressed_t *tree, tree->name, (gpointer) value, inet_ntop(AF_INET, key, ip_str, sizeof(ip_str) - 1), - (gint) (keybits - masklen)); + (int) (keybits - masklen)); } else if (keybits == 128) { msg_err_radix("%s: cannot insert %p, key: [%s]/%d, duplicate value", tree->name, (gpointer) value, inet_ntop(AF_INET6, key, ip_str, sizeof(ip_str) - 1), - (gint) (keybits - masklen)); + (int) (keybits - masklen)); } else { msg_err_radix("%s: cannot insert %p with mask %z, key: %*xs, duplicate value", @@ -130,7 +130,7 @@ radix_insert_compressed(radix_compressed_t *tree, radix_compressed_t * -radix_create_compressed(const gchar *tree_name) +radix_create_compressed(const char *tree_name) { radix_compressed_t *tree; @@ -150,7 +150,7 @@ radix_create_compressed(const gchar *tree_name) } radix_compressed_t * -radix_create_compressed_with_pool(rspamd_mempool_t *pool, const gchar *tree_name) +radix_create_compressed_with_pool(rspamd_mempool_t *pool, const char *tree_name) { radix_compressed_t *tree; @@ -179,9 +179,9 @@ uintptr_t radix_find_compressed_addr(radix_compressed_t *tree, const rspamd_inet_addr_t *addr) { - const guchar *key; - guint klen = 0; - guchar buf[16]; + const unsigned char *key; + unsigned int klen = 0; + unsigned char buf[16]; if (addr == NULL) { return RADIX_NO_VALUE; @@ -207,19 +207,19 @@ radix_find_compressed_addr(radix_compressed_t *tree, return RADIX_NO_VALUE; } -gint rspamd_radix_add_iplist(const gchar *list, const gchar *separators, - radix_compressed_t *tree, gconstpointer value, - gboolean resolve, const gchar *tree_name) +int rspamd_radix_add_iplist(const char *list, const char *separators, + radix_compressed_t *tree, gconstpointer value, + gboolean resolve, const char *tree_name) { - gchar *token, *ipnet, *err_str, **strv, **cur, *brace; + char *token, *ipnet, *err_str, **strv, **cur, *brace; union { struct in_addr ina; struct in6_addr ina6; - guchar buf[16]; + unsigned char buf[16]; } addr_buf; - guint k = G_MAXINT; - gint af; - gint res = 0, r; + unsigned int k = G_MAXINT; + int af; + int res = 0, r; struct addrinfo hints, *ai_res, *cur_ai; /* Split string if there are multiple items inside a single string */ @@ -388,8 +388,8 @@ gint rspamd_radix_add_iplist(const gchar *list, const gchar *separators, } gboolean -radix_add_generic_iplist(const gchar *ip_list, radix_compressed_t **tree, - gboolean resolve, const gchar *tree_name) +radix_add_generic_iplist(const char *ip_list, radix_compressed_t **tree, + gboolean resolve, const char *tree_name) { static const char fill_ptr[] = "1"; @@ -423,7 +423,7 @@ radix_get_pool(radix_compressed_t *tree) return NULL; } -const gchar * +const char * radix_get_info(radix_compressed_t *tree) { if (tree == NULL) { diff --git a/src/libutil/radix.h b/src/libutil/radix.h index a85da5b5f..c4fe96441 100644 --- a/src/libutil/radix.h +++ b/src/libutil/radix.h @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -39,7 +39,7 @@ typedef struct radix_tree_compressed radix_compressed_t; */ uintptr_t radix_insert_compressed(radix_compressed_t *tree, - guint8 *key, gsize keylen, + uint8_t *key, gsize keylen, gsize masklen, uintptr_t value); @@ -50,7 +50,7 @@ radix_insert_compressed(radix_compressed_t *tree, * @param keylen length of a key * @return opaque pointer or `RADIX_NO_VALUE` if no value has been found */ -uintptr_t radix_find_compressed(radix_compressed_t *tree, const guint8 *key, +uintptr_t radix_find_compressed(radix_compressed_t *tree, const uint8_t *key, gsize keylen); /** @@ -72,9 +72,9 @@ void radix_destroy_compressed(radix_compressed_t *tree); * Create new radix trie * @return */ -radix_compressed_t *radix_create_compressed(const gchar *tree_name); +radix_compressed_t *radix_create_compressed(const char *tree_name); -radix_compressed_t *radix_create_compressed_with_pool(rspamd_mempool_t *pool, const gchar *tree_name); +radix_compressed_t *radix_create_compressed_with_pool(rspamd_mempool_t *pool, const char *tree_name); /** * Insert list of ip addresses and masks to the radix tree @@ -83,19 +83,19 @@ radix_compressed_t *radix_create_compressed_with_pool(rspamd_mempool_t *pool, co * @param tree target tree * @return number of elements inserted */ -gint rspamd_radix_add_iplist(const gchar *list, const gchar *separators, - radix_compressed_t *tree, gconstpointer value, - gboolean resolve, const gchar *tree_name); +int rspamd_radix_add_iplist(const char *list, const char *separators, + radix_compressed_t *tree, gconstpointer value, + gboolean resolve, const char *tree_name); /** * Generic version of @see rspamd_radix_add_iplist. This function creates tree * if `tree` is NULL. */ gboolean -radix_add_generic_iplist(const gchar *ip_list, +radix_add_generic_iplist(const char *ip_list, radix_compressed_t **tree, gboolean resolve, - const gchar *tree_name); + const char *tree_name); /** * Returns number of elements in the tree @@ -109,7 +109,7 @@ gsize radix_get_size(radix_compressed_t *tree); * @param tree * @return constant string */ -const gchar *radix_get_info(radix_compressed_t *tree); +const char *radix_get_info(radix_compressed_t *tree); /** * Returns memory pool associated with the radix tree diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c index 63ce73f5f..b97e66a03 100644 --- a/src/libutil/regexp.c +++ b/src/libutil/regexp.c @@ -45,13 +45,13 @@ #define PCRE_FLAG(x) G_PASTE(PCRE2_, x) #endif -typedef guchar regexp_id_t[rspamd_cryptobox_HASHBYTES]; +typedef unsigned char regexp_id_t[rspamd_cryptobox_HASHBYTES]; #undef DISABLE_JIT_FAST struct rspamd_regexp_s { - gdouble exec_time; - gchar *pattern; + double exec_time; + char *pattern; PCRE_T *re; PCRE_T *raw_re; #ifndef WITH_PCRE2 @@ -67,10 +67,10 @@ struct rspamd_regexp_s { gpointer re_class; uint64_t cache_id; gsize match_limit; - guint max_hits; - gint flags; - gint pcre_flags; - gint ncaptures; + unsigned int max_hits; + int flags; + int pcre_flags; + int ncaptures; }; struct rspamd_regexp_cache { @@ -96,7 +96,7 @@ rspamd_regexp_quark(void) } static void -rspamd_regexp_generate_id(const gchar *pattern, const gchar *flags, +rspamd_regexp_generate_id(const char *pattern, const char *flags, regexp_id_t out) { rspamd_cryptobox_hash_state_t st; @@ -164,7 +164,7 @@ rspamd_regexp_post_process(rspamd_regexp_t *r) rspamd_regexp_library_init(NULL); } #if defined(WITH_PCRE2) - static const guint max_recursion_depth = 100000, max_backtrack = 1000000; + static const unsigned int max_recursion_depth = 100000, max_backtrack = 1000000; /* Create match context */ r->mcontext = pcre2_match_context_create(NULL); @@ -186,7 +186,7 @@ rspamd_regexp_post_process(rspamd_regexp_t *r) } #ifdef HAVE_PCRE_JIT - guint jit_flags = can_jit ? PCRE2_JIT_COMPLETE : 0; + unsigned int jit_flags = can_jit ? PCRE2_JIT_COMPLETE : 0; gsize jsz; PCRE2_UCHAR errstr[128]; int errcode; @@ -231,9 +231,9 @@ rspamd_regexp_post_process(rspamd_regexp_t *r) #endif #else - const gchar *err_str = "unknown"; + const char *err_str = "unknown"; gboolean try_jit = TRUE, try_raw_jit = TRUE; - gint study_flags = 0; + int study_flags = 0; #if defined(HAVE_PCRE_JIT) study_flags |= PCRE_STUDY_JIT_COMPILE; @@ -270,7 +270,7 @@ rspamd_regexp_post_process(rspamd_regexp_t *r) /* JIT path */ if (try_jit) { #ifdef HAVE_PCRE_JIT - gint jit, n; + int jit, n; if (can_jit) { jit = 0; @@ -295,7 +295,7 @@ rspamd_regexp_post_process(rspamd_regexp_t *r) if (try_raw_jit) { #ifdef HAVE_PCRE_JIT - gint jit, n; + int jit, n; if (can_jit) { @@ -320,21 +320,21 @@ rspamd_regexp_post_process(rspamd_regexp_t *r) } rspamd_regexp_t * -rspamd_regexp_new_len(const gchar *pattern, gsize len, const gchar *flags, +rspamd_regexp_new_len(const char *pattern, gsize len, const char *flags, GError **err) { - const gchar *start = pattern, *end = start + len, *flags_str = NULL, *flags_end = NULL; - gchar *err_str; + const char *start = pattern, *end = start + len, *flags_str = NULL, *flags_end = NULL; + char *err_str; rspamd_regexp_t *res; gboolean explicit_utf = FALSE; PCRE_T *r; - gchar sep = 0, *real_pattern; + char sep = 0, *real_pattern; #ifndef WITH_PCRE2 - gint err_off; + int err_off; #else gsize err_off; #endif - gint regexp_flags = 0, rspamd_flags = 0, err_code, ncaptures; + int regexp_flags = 0, rspamd_flags = 0, err_code, ncaptures; gboolean strict_flags = FALSE; rspamd_regexp_library_init(NULL); @@ -367,7 +367,7 @@ rspamd_regexp_new_len(const gchar *pattern, gsize len, const gchar *flags, rspamd_flags &= ~RSPAMD_REGEXP_FLAG_FULL_MATCH; } else { - gchar *last_sep = rspamd_memrchr(pattern, sep, len); + char *last_sep = rspamd_memrchr(pattern, sep, len); if (last_sep == NULL || last_sep <= start) { g_set_error(err, rspamd_regexp_quark(), EINVAL, @@ -480,7 +480,7 @@ fin: if (r == NULL) { g_set_error(err, rspamd_regexp_quark(), EINVAL, "regexp parsing error: '%s' at position %d; pattern: %s", - err_str, (gint) err_off, real_pattern); + err_str, (int) err_off, real_pattern); g_free(real_pattern); return NULL; @@ -516,7 +516,7 @@ fin: #endif if (res->raw_re == NULL) { msg_warn("raw regexp parsing error: '%s': '%s' at position %d", - err_str, real_pattern, (gint) err_off); + err_str, real_pattern, (int) err_off); } } @@ -541,7 +541,7 @@ fin: } rspamd_regexp_t * -rspamd_regexp_new(const gchar *pattern, const gchar *flags, +rspamd_regexp_new(const char *pattern, const char *flags, GError **err) { return rspamd_regexp_new_len(pattern, strlen(pattern), flags, err); @@ -549,8 +549,8 @@ rspamd_regexp_new(const gchar *pattern, const gchar *flags, #ifndef WITH_PCRE2 gboolean -rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len, - const gchar **start, const gchar **end, gboolean raw, +rspamd_regexp_search(const rspamd_regexp_t *re, const char *text, gsize len, + const char **start, const char **end, gboolean raw, GArray *captures) { pcre *r; @@ -558,9 +558,9 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len, #if defined(HAVE_PCRE_JIT) && defined(HAVE_PCRE_JIT_FAST) && !defined(DISABLE_JIT_FAST) pcre_jit_stack *st = NULL; #endif - const gchar *mt; + const char *mt; gsize remain = 0; - gint rc, match_flags = 0, *ovec, ncaptures, i; + int rc, match_flags = 0, *ovec, ncaptures, i; const int junk = 0xdeadbabe; g_assert(re != NULL); @@ -578,7 +578,7 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len, /* Incremental search */ mt = (*end); - if ((gint) len > (mt - text)) { + if ((int) len > (mt - text)) { remain = len - (mt - text); } } @@ -620,7 +620,7 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len, } ncaptures = (re->ncaptures + 1) * 3; - ovec = g_alloca(sizeof(gint) * ncaptures); + ovec = g_alloca(sizeof(int) * ncaptures); for (i = 0; i < ncaptures; i++) { @@ -697,7 +697,7 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len, if (re->flags & RSPAMD_REGEXP_FLAG_FULL_MATCH) { /* We also ensure that the match is full */ - if (ovec[0] != 0 || (guint) ovec[1] < len) { + if (ovec[0] != 0 || (unsigned int) ovec[1] < len) { return FALSE; } } @@ -710,17 +710,17 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len, #else /* PCRE 2 version */ gboolean -rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len, - const gchar **start, const gchar **end, gboolean raw, +rspamd_regexp_search(const rspamd_regexp_t *re, const char *text, gsize len, + const char **start, const char **end, gboolean raw, GArray *captures) { pcre2_match_data *match_data; pcre2_match_context *mcontext; PCRE_T *r; - const gchar *mt; + const char *mt; PCRE2_SIZE remain = 0, *ovec; const PCRE2_SIZE junk = 0xdeadbabeeeeeeeeULL; - gint rc, match_flags, novec, i; + int rc, match_flags, novec, i; gboolean ret = FALSE; g_assert(re != NULL); @@ -738,7 +738,7 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len, /* Incremental search */ mt = (*end); - if ((gint) len > (mt - text)) { + if ((int) len > (mt - text)) { remain = len - (mt - text); } } @@ -838,7 +838,7 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len, if (re->flags & RSPAMD_REGEXP_FLAG_FULL_MATCH) { /* We also ensure that the match is full */ - if (ovec[0] != 0 || (guint) ovec[1] < len) { + if (ovec[0] != 0 || (unsigned int) ovec[1] < len) { ret = FALSE; } } @@ -858,9 +858,9 @@ rspamd_regexp_get_pattern(const rspamd_regexp_t *re) return re->pattern; } -guint rspamd_regexp_set_flags(rspamd_regexp_t *re, guint new_flags) +unsigned int rspamd_regexp_set_flags(rspamd_regexp_t *re, unsigned int new_flags) { - guint old_flags; + unsigned int old_flags; g_assert(re != NULL); old_flags = re->flags; @@ -869,30 +869,30 @@ guint rspamd_regexp_set_flags(rspamd_regexp_t *re, guint new_flags) return old_flags; } -guint rspamd_regexp_get_flags(const rspamd_regexp_t *re) +unsigned int rspamd_regexp_get_flags(const rspamd_regexp_t *re) { g_assert(re != NULL); return re->flags; } -guint rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re) +unsigned int rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re) { g_assert(re != NULL); return re->pcre_flags; } -guint rspamd_regexp_get_maxhits(const rspamd_regexp_t *re) +unsigned int rspamd_regexp_get_maxhits(const rspamd_regexp_t *re) { g_assert(re != NULL); return re->max_hits; } -guint rspamd_regexp_set_maxhits(rspamd_regexp_t *re, guint new_maxhits) +unsigned int rspamd_regexp_set_maxhits(rspamd_regexp_t *re, unsigned int new_maxhits) { - guint old_hits; + unsigned int old_hits; g_assert(re != NULL); old_hits = re->max_hits; @@ -940,10 +940,10 @@ gsize rspamd_regexp_set_match_limit(rspamd_regexp_t *re, gsize lim) } gboolean -rspamd_regexp_match(const rspamd_regexp_t *re, const gchar *text, gsize len, +rspamd_regexp_match(const rspamd_regexp_t *re, const char *text, gsize len, gboolean raw) { - const gchar *start = NULL, *end = NULL; + const char *start = NULL, *end = NULL; g_assert(re != NULL); g_assert(text != NULL); @@ -994,7 +994,7 @@ rspamd_regexp_get_ud(const rspamd_regexp_t *re) gboolean rspamd_regexp_equal(gconstpointer a, gconstpointer b) { - const guchar *ia = a, *ib = b; + const unsigned char *ia = a, *ib = b; return (memcmp(ia, ib, sizeof(regexp_id_t)) == 0); } @@ -1002,7 +1002,7 @@ rspamd_regexp_equal(gconstpointer a, gconstpointer b) uint32_t rspamd_regexp_hash(gconstpointer a) { - const guchar *ia = a; + const unsigned char *ia = a; uint32_t res; memcpy(&res, ia, sizeof(res)); @@ -1013,7 +1013,7 @@ rspamd_regexp_hash(gconstpointer a) gboolean rspamd_regexp_cmp(gconstpointer a, gconstpointer b) { - const guchar *ia = a, *ib = b; + const unsigned char *ia = a, *ib = b; return memcmp(ia, ib, sizeof(regexp_id_t)); } @@ -1039,8 +1039,8 @@ rspamd_regexp_cache_new(void) rspamd_regexp_t * rspamd_regexp_cache_query(struct rspamd_regexp_cache *cache, - const gchar *pattern, - const gchar *flags) + const char *pattern, + const char *flags) { rspamd_regexp_t *res = NULL; regexp_id_t id; @@ -1061,8 +1061,8 @@ rspamd_regexp_cache_query(struct rspamd_regexp_cache *cache, rspamd_regexp_t * rspamd_regexp_cache_create(struct rspamd_regexp_cache *cache, - const gchar *pattern, - const gchar *flags, GError **err) + const char *pattern, + const char *flags, GError **err) { rspamd_regexp_t *res; @@ -1160,8 +1160,8 @@ void rspamd_regexp_library_init(struct rspamd_config *cfg) if (check_jit) { #ifdef HAVE_PCRE_JIT - gint jit, rc; - gchar *str; + int jit, rc; + char *str; #ifndef WITH_PCRE2 rc = pcre_config(PCRE_CONFIG_JIT, &jit); @@ -1243,13 +1243,13 @@ rspamd_regexp_set_class(rspamd_regexp_t *re, gpointer re_class) } rspamd_regexp_t * -rspamd_regexp_from_glob(const gchar *gl, gsize sz, GError **err) +rspamd_regexp_from_glob(const char *gl, gsize sz, GError **err) { GString *out; rspamd_regexp_t *re; - const gchar *end; + const char *end; gboolean escaping = FALSE; - gint nbraces = 0; + int nbraces = 0; g_assert(gl != NULL); diff --git a/src/libutil/regexp.h b/src/libutil/regexp.h index 5be9046be..44881512b 100644 --- a/src/libutil/regexp.h +++ b/src/libutil/regexp.h @@ -57,7 +57,7 @@ struct rspamd_re_capture { * @param err error pointer set if compilation failed * @return new regexp object */ -rspamd_regexp_t *rspamd_regexp_new(const gchar *pattern, const gchar *flags, +rspamd_regexp_t *rspamd_regexp_new(const char *pattern, const char *flags, GError **err); /** @@ -67,7 +67,7 @@ rspamd_regexp_t *rspamd_regexp_new(const gchar *pattern, const gchar *flags, * @param err error pointer set if compilation failed * @return new regexp object */ -rspamd_regexp_t *rspamd_regexp_new_len(const gchar *pattern, gsize len, const gchar *flags, +rspamd_regexp_t *rspamd_regexp_new_len(const char *pattern, gsize len, const char *flags, GError **err); /** @@ -82,8 +82,8 @@ rspamd_regexp_t *rspamd_regexp_new_len(const gchar *pattern, gsize len, const gc * @return */ gboolean rspamd_regexp_search(const rspamd_regexp_t *re, - const gchar *text, gsize len, - const gchar **start, const gchar **end, gboolean raw, + const char *text, gsize len, + const char **start, const char **end, gboolean raw, GArray *captures); @@ -95,7 +95,7 @@ gboolean rspamd_regexp_search(const rspamd_regexp_t *re, * @return */ gboolean rspamd_regexp_match(const rspamd_regexp_t *re, - const gchar *text, gsize len, gboolean raw); + const char *text, gsize len, gboolean raw); /** * Increase refcount for a regexp object @@ -139,27 +139,27 @@ const char *rspamd_regexp_get_pattern(const rspamd_regexp_t *re); /** * Get PCRE flags for the regexp */ -guint rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re); +unsigned int rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re); /** * Get rspamd flags for the regexp */ -guint rspamd_regexp_get_flags(const rspamd_regexp_t *re); +unsigned int rspamd_regexp_get_flags(const rspamd_regexp_t *re); /** * Set rspamd flags for the regexp */ -guint rspamd_regexp_set_flags(rspamd_regexp_t *re, guint new_flags); +unsigned int rspamd_regexp_set_flags(rspamd_regexp_t *re, unsigned int new_flags); /** * Set regexp maximum hits */ -guint rspamd_regexp_get_maxhits(const rspamd_regexp_t *re); +unsigned int rspamd_regexp_get_maxhits(const rspamd_regexp_t *re); /** * Get regexp maximum hits */ -guint rspamd_regexp_set_maxhits(rspamd_regexp_t *re, guint new_maxhits); +unsigned int rspamd_regexp_set_maxhits(rspamd_regexp_t *re, unsigned int new_maxhits); /** * Returns cache id for a regexp @@ -206,8 +206,8 @@ struct rspamd_regexp_cache *rspamd_regexp_cache_new(void); * @return */ rspamd_regexp_t *rspamd_regexp_cache_query(struct rspamd_regexp_cache *cache, - const gchar *pattern, - const gchar *flags); + const char *pattern, + const char *flags); /** * Create or get cached regexp from the specified cache @@ -218,8 +218,8 @@ rspamd_regexp_t *rspamd_regexp_cache_query(struct rspamd_regexp_cache *cache, * @return new regexp object */ rspamd_regexp_t *rspamd_regexp_cache_create(struct rspamd_regexp_cache *cache, - const gchar *pattern, - const gchar *flags, GError **err); + const char *pattern, + const char *flags, GError **err); /** * Remove regexp from the cache @@ -254,7 +254,7 @@ gboolean rspamd_regexp_equal(gconstpointer a, gconstpointer b); /** * Acts like memcmp but for regexp */ -gint rspamd_regexp_cmp(gconstpointer a, gconstpointer b); +int rspamd_regexp_cmp(gconstpointer a, gconstpointer b); /** * Initialize superglobal regexp cache and library @@ -267,7 +267,7 @@ void rspamd_regexp_library_init(struct rspamd_config *cfg); * @param err * @return */ -rspamd_regexp_t *rspamd_regexp_from_glob(const gchar *gl, gsize sz, GError **err); +rspamd_regexp_t *rspamd_regexp_from_glob(const char *gl, gsize sz, GError **err); #ifdef __cplusplus } diff --git a/src/libutil/rrd.c b/src/libutil/rrd.c index 451e22202..9f128ff95 100644 --- a/src/libutil/rrd.c +++ b/src/libutil/rrd.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -55,7 +55,7 @@ rrd_error_quark(void) * Convert rrd dst type from string to numeric value */ enum rrd_dst_type -rrd_dst_from_string(const gchar *str) +rrd_dst_from_string(const char *str) { if (g_ascii_strcasecmp(str, "counter") == 0) { return RRD_DST_COUNTER; @@ -79,7 +79,7 @@ rrd_dst_from_string(const gchar *str) /** * Convert numeric presentation of dst to string */ -const gchar * +const char * rrd_dst_to_string(enum rrd_dst_type type) { switch (type) { @@ -104,7 +104,7 @@ rrd_dst_to_string(enum rrd_dst_type type) * Convert rrd consolidation function type from string to numeric value */ enum rrd_cf_type -rrd_cf_from_string(const gchar *str) +rrd_cf_from_string(const char *str) { if (g_ascii_strcasecmp(str, "average") == 0) { return RRD_CF_AVERAGE; @@ -126,7 +126,7 @@ rrd_cf_from_string(const gchar *str) /** * Convert numeric presentation of cf to string */ -const gchar * +const char * rrd_cf_to_string(enum rrd_cf_type type) { switch (type) { @@ -147,7 +147,7 @@ rrd_cf_to_string(enum rrd_cf_type type) return "U"; } -void rrd_make_default_rra(const gchar *cf_name, +void rrd_make_default_rra(const char *cf_name, gulong pdp_cnt, gulong rows, struct rrd_rra_def *rra) @@ -162,8 +162,8 @@ void rrd_make_default_rra(const gchar *cf_name, rra->par[RRA_cdp_xff_val].dv = 0.5; } -void rrd_make_default_ds(const gchar *name, - const gchar *type, +void rrd_make_default_ds(const char *name, + const char *type, gulong pdp_step, struct rrd_ds_def *ds) { @@ -183,13 +183,13 @@ void rrd_make_default_ds(const gchar *name, * Check rrd file for correctness (size, cookies, etc) */ static gboolean -rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err) +rspamd_rrd_check_file(const char *filename, gboolean need_data, GError **err) { - gint fd, i; + int fd, i; struct stat st; struct rrd_file_head head; struct rrd_rra_def rra; - gint head_size; + int head_size; fd = open(filename, O_RDWR); if (fd == -1) { @@ -207,7 +207,7 @@ rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err) if (st.st_size < (goffset) sizeof(struct rrd_file_head)) { /* We have trimmed file */ g_set_error(err, rrd_error_quark(), EINVAL, "rrd size is bad: %ud", - (guint) st.st_size); + (unsigned int) st.st_size); close(fd); return FALSE; } @@ -268,7 +268,7 @@ rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err) close(fd); return FALSE; } - for (i = 0; i < (gint) head.rra_cnt; i++) { + for (i = 0; i < (int) head.rra_cnt; i++) { if (read(fd, &rra, sizeof(rra)) != sizeof(rra)) { g_set_error(err, rrd_error_quark(), errno, "rrd read rra error: %s", @@ -276,13 +276,13 @@ rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err) close(fd); return FALSE; } - head_size += rra.row_cnt * head.ds_cnt * sizeof(gdouble); + head_size += rra.row_cnt * head.ds_cnt * sizeof(double); } if (st.st_size != head_size) { g_set_error(err, rrd_error_quark(), EINVAL, "rrd file seems to have incorrect size: %d, must be %d", - (gint) st.st_size, head_size); + (int) st.st_size, head_size); close(fd); return FALSE; } @@ -299,7 +299,7 @@ rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err) static void rspamd_rrd_adjust_pointers(struct rspamd_rrd_file *file, gboolean completed) { - guint8 *ptr; + uint8_t *ptr; ptr = file->map; file->stat_head = (struct rrd_file_head *) ptr; @@ -318,7 +318,7 @@ rspamd_rrd_adjust_pointers(struct rspamd_rrd_file *file, gboolean completed) file->rra_ptr = (struct rrd_rra_ptr *) ptr; if (completed) { ptr += sizeof(struct rrd_rra_ptr) * file->stat_head->rra_cnt; - file->rrd_value = (gdouble *) ptr; + file->rrd_value = (double *) ptr; } else { file->rrd_value = NULL; @@ -328,9 +328,9 @@ rspamd_rrd_adjust_pointers(struct rspamd_rrd_file *file, gboolean completed) static void rspamd_rrd_calculate_checksum(struct rspamd_rrd_file *file) { - guchar sigbuf[rspamd_cryptobox_HASHBYTES]; + unsigned char sigbuf[rspamd_cryptobox_HASHBYTES]; struct rrd_ds_def *ds; - guint i; + unsigned int i; rspamd_cryptobox_hash_state_t st; if (file->finalized) { @@ -349,12 +349,12 @@ rspamd_rrd_calculate_checksum(struct rspamd_rrd_file *file) } static int -rspamd_rrd_open_exclusive(const gchar *filename) +rspamd_rrd_open_exclusive(const char *filename) { struct timespec sleep_ts = { .tv_sec = 0, .tv_nsec = 1000000}; - gint fd; + int fd; fd = open(filename, O_RDWR); @@ -389,10 +389,10 @@ rspamd_rrd_open_exclusive(const gchar *filename) * @return */ static struct rspamd_rrd_file * -rspamd_rrd_open_common(const gchar *filename, gboolean completed, GError **err) +rspamd_rrd_open_common(const char *filename, gboolean completed, GError **err) { struct rspamd_rrd_file *file; - gint fd; + int fd; struct stat st; if (!rspamd_rrd_check_file(filename, completed, err)) { @@ -453,7 +453,7 @@ rspamd_rrd_open_common(const gchar *filename, gboolean completed, GError **err) * @return rrd file structure */ struct rspamd_rrd_file * -rspamd_rrd_open(const gchar *filename, GError **err) +rspamd_rrd_open(const char *filename, GError **err) { struct rspamd_rrd_file *file; @@ -474,11 +474,11 @@ rspamd_rrd_open(const gchar *filename, GError **err) * @return TRUE if file has been created */ struct rspamd_rrd_file * -rspamd_rrd_create(const gchar *filename, +rspamd_rrd_create(const char *filename, gulong ds_count, gulong rra_count, gulong pdp_step, - gdouble initial_ticks, + double initial_ticks, GError **err) { struct rspamd_rrd_file *new; @@ -489,8 +489,8 @@ rspamd_rrd_create(const gchar *filename, struct rrd_pdp_prep pdp; struct rrd_cdp_prep cdp; struct rrd_rra_ptr rra_ptr; - gint fd; - guint i, j; + int fd; + unsigned int i, j; /* Open file */ fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0644); @@ -680,10 +680,10 @@ rspamd_rrd_add_rra(struct rspamd_rrd_file *file, GArray *rra, GError **err) gboolean rspamd_rrd_finalize(struct rspamd_rrd_file *file, GError **err) { - gint fd; - guint i; - gint count = 0; - gdouble vbuf[1024]; + int fd; + unsigned int i; + int count = 0; + double vbuf[1024]; struct stat st; if (file == NULL || file->filename == NULL || file->fd == -1) { @@ -720,7 +720,7 @@ rspamd_rrd_finalize(struct rspamd_rrd_file *file, GError **err) while (count > 0) { /* Write values in buffered matter */ if (write(fd, vbuf, - MIN((gint) G_N_ELEMENTS(vbuf), count) * sizeof(gdouble)) == -1) { + MIN((int) G_N_ELEMENTS(vbuf), count) * sizeof(double)) == -1) { g_set_error(err, rrd_error_quark(), errno, "rrd write error: %s", strerror(errno)); @@ -769,11 +769,11 @@ rspamd_rrd_finalize(struct rspamd_rrd_file *file, GError **err) */ static gboolean rspamd_rrd_update_pdp_prep(struct rspamd_rrd_file *file, - gdouble *vals, - gdouble *pdp_new, - gdouble interval) + double *vals, + double *pdp_new, + double interval) { - guint i; + unsigned int i; enum rrd_dst_type type; for (i = 0; i < file->stat_head->ds_cnt; i++) { @@ -840,12 +840,12 @@ rspamd_rrd_update_pdp_prep(struct rspamd_rrd_file *file, */ static void rspamd_rrd_update_pdp_step(struct rspamd_rrd_file *file, - gdouble *pdp_new, - gdouble *pdp_temp, - gdouble interval, + double *pdp_new, + double *pdp_temp, + double interval, gulong pdp_diff) { - guint i; + unsigned int i; rrd_value_t *scratch; gulong heartbeat; @@ -896,17 +896,17 @@ rspamd_rrd_update_pdp_step(struct rspamd_rrd_file *file, */ static void rspamd_rrd_update_cdp(struct rspamd_rrd_file *file, - gdouble pdp_steps, - gdouble pdp_offset, + double pdp_steps, + double pdp_offset, gulong *rra_steps, gulong rra_index, - gdouble *pdp_temp) + double *pdp_temp) { - guint i; + unsigned int i; struct rrd_rra_def *rra; rrd_value_t *scratch; enum rrd_cf_type cf; - gdouble last_cdp = INFINITY, cur_cdp = INFINITY; + double last_cdp = INFINITY, cur_cdp = INFINITY; gulong pdp_in_cdp; rra = &file->rra_def[rra_index]; @@ -1064,10 +1064,10 @@ rspamd_rrd_update_cdp(struct rspamd_rrd_file *file, */ void rspamd_rrd_write_rra(struct rspamd_rrd_file *file, gulong *rra_steps) { - guint i, j, ds_cnt; + unsigned int i, j, ds_cnt; struct rrd_rra_def *rra; struct rrd_cdp_prep *cdp; - gdouble *rra_row = file->rrd_value, *cur_row; + double *rra_row = file->rrd_value, *cur_row; ds_cnt = file->stat_head->ds_cnt; @@ -1105,16 +1105,16 @@ void rspamd_rrd_write_rra(struct rspamd_rrd_file *file, gulong *rra_steps) gboolean rspamd_rrd_add_record(struct rspamd_rrd_file *file, GArray *points, - gdouble ticks, + double ticks, GError **err) { - gdouble interval, *pdp_new, *pdp_temp; - guint i; + double interval, *pdp_new, *pdp_temp; + unsigned int i; glong seconds, microseconds; gulong pdp_steps, cur_pdp_count, prev_pdp_step, cur_pdp_step, prev_pdp_age, cur_pdp_age, *rra_steps, pdp_offset; - if (file == NULL || file->stat_head->ds_cnt * sizeof(gdouble) != + if (file == NULL || file->stat_head->ds_cnt * sizeof(double) != points->len) { g_set_error(err, rrd_error_quark(), EINVAL, @@ -1125,18 +1125,18 @@ rspamd_rrd_add_record(struct rspamd_rrd_file *file, /* Get interval */ seconds = (glong) ticks; microseconds = (glong) ((ticks - seconds) * 1000000.); - interval = ticks - ((gdouble) file->live_head->last_up + + interval = ticks - ((double) file->live_head->last_up + file->live_head->last_up_usec / 1000000.); msg_debug_rrd("update rrd record after %.3f seconds", interval); /* Update PDP preparation values */ - pdp_new = g_malloc0(sizeof(gdouble) * file->stat_head->ds_cnt); - pdp_temp = g_malloc0(sizeof(gdouble) * file->stat_head->ds_cnt); + pdp_new = g_malloc0(sizeof(double) * file->stat_head->ds_cnt); + pdp_temp = g_malloc0(sizeof(double) * file->stat_head->ds_cnt); /* How much steps need to be updated in each RRA */ rra_steps = g_malloc0(sizeof(gulong) * file->stat_head->rra_cnt); - if (!rspamd_rrd_update_pdp_prep(file, (gdouble *) points->data, pdp_new, + if (!rspamd_rrd_update_pdp_prep(file, (double *) points->data, pdp_new, interval)) { g_set_error(err, rrd_error_quark(), EINVAL, @@ -1239,7 +1239,7 @@ rspamd_rrd_add_record(struct rspamd_rrd_file *file, * @param file * @return */ -gint rspamd_rrd_close(struct rspamd_rrd_file *file) +int rspamd_rrd_close(struct rspamd_rrd_file *file) { if (file == NULL) { errno = EINVAL; @@ -1257,12 +1257,12 @@ gint rspamd_rrd_close(struct rspamd_rrd_file *file) } static struct rspamd_rrd_file * -rspamd_rrd_create_file(const gchar *path, gboolean finalize, GError **err) +rspamd_rrd_create_file(const char *path, gboolean finalize, GError **err) { struct rspamd_rrd_file *file; struct rrd_ds_def ds[RSPAMD_RRD_DS_COUNT]; struct rrd_rra_def rra[RSPAMD_RRD_RRA_COUNT]; - gint i; + int i; GArray ar; /* Try to create new rrd file */ @@ -1281,7 +1281,7 @@ rspamd_rrd_create_file(const gchar *path, gboolean finalize, GError **err) rrd_dst_to_string(RRD_DST_COUNTER), 1, &ds[i]); } - ar.data = (gchar *) ds; + ar.data = (char *) ds; ar.len = sizeof(ds); if (!rspamd_rrd_add_ds(file, &ar, err)) { @@ -1301,7 +1301,7 @@ rspamd_rrd_create_file(const gchar *path, gboolean finalize, GError **err) /* Once per hour for 1 year */ rrd_make_default_rra(rrd_cf_to_string(RRD_CF_AVERAGE), 60 * 60, 365 * 24, &rra[3]); - ar.data = (gchar *) rra; + ar.data = (char *) rra; ar.len = sizeof(rra); if (!rspamd_rrd_add_rra(file, &ar, err)) { @@ -1319,11 +1319,11 @@ rspamd_rrd_create_file(const gchar *path, gboolean finalize, GError **err) static void rspamd_rrd_convert_ds(struct rspamd_rrd_file *old, - struct rspamd_rrd_file *cur, gint idx_old, gint idx_new) + struct rspamd_rrd_file *cur, int idx_old, int idx_new) { struct rrd_pdp_prep *pdp_prep_old, *pdp_prep_new; struct rrd_cdp_prep *cdp_prep_old, *cdp_prep_new; - gdouble *val_old, *val_new; + double *val_old, *val_new; gulong rra_cnt, i, j, points_cnt, old_ds, new_ds; rra_cnt = old->stat_head->rra_cnt; @@ -1351,11 +1351,11 @@ rspamd_rrd_convert_ds(struct rspamd_rrd_file *old, } static struct rspamd_rrd_file * -rspamd_rrd_convert(const gchar *path, struct rspamd_rrd_file *old, +rspamd_rrd_convert(const char *path, struct rspamd_rrd_file *old, GError **err) { struct rspamd_rrd_file *rrd; - gchar tpath[PATH_MAX]; + char tpath[PATH_MAX]; g_assert(old != NULL); @@ -1403,7 +1403,7 @@ rspamd_rrd_convert(const gchar *path, struct rspamd_rrd_file *old, } struct rspamd_rrd_file * -rspamd_rrd_file_default(const gchar *path, +rspamd_rrd_file_default(const char *path, GError **err) { struct rspamd_rrd_file *file, *nf; @@ -1465,8 +1465,8 @@ rspamd_rrd_query(struct rspamd_rrd_file *file, { struct rspamd_rrd_query_result *res; struct rrd_rra_def *rra; - const gdouble *rra_offset = NULL; - guint i; + const double *rra_offset = NULL; + unsigned int i; g_assert(file != NULL); @@ -1479,8 +1479,8 @@ rspamd_rrd_query(struct rspamd_rrd_file *file, res = g_malloc0(sizeof(*res)); res->ds_count = file->stat_head->ds_cnt; - res->last_update = (gdouble) file->live_head->last_up + - ((gdouble) file->live_head->last_up_usec / 1e6f); + res->last_update = (double) file->live_head->last_up + + ((double) file->live_head->last_up_usec / 1e6f); res->pdp_per_cdp = file->rra_def[rra_num].pdp_cnt; res->rra_rows = file->rra_def[rra_num].row_cnt; rra_offset = file->rrd_value; diff --git a/src/libutil/rrd.h b/src/libutil/rrd.h index 3d814771a..2379b7e09 100644 --- a/src/libutil/rrd.h +++ b/src/libutil/rrd.h @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -37,9 +37,9 @@ typedef union { struct rrd_file_head { /* Data Base Identification Section ** */ - gchar cookie[4]; /* RRD */ - gchar version[5]; /* version of the format */ - gdouble float_cookie; /* is it the correct double representation ? */ + char cookie[4]; /* RRD */ + char version[5]; /* version of the format */ + double float_cookie; /* is it the correct double representation ? */ /* Data Base Structure Definition **** */ gulong ds_cnt; /* how many different ds provide input to the rrd */ @@ -75,9 +75,9 @@ enum rrd_ds_param { #define RRD_DST_SIZE 20 struct rrd_ds_def { - gchar ds_nam[RRD_DS_NAM_SIZE]; /* Name of the data source (null terminated) */ - gchar dst[RRD_DST_SIZE]; /* Type of data source (null terminated) */ - rrd_value_t par[10]; /* index of this array see ds_param_en */ + char ds_nam[RRD_DS_NAM_SIZE]; /* Name of the data source (null terminated) */ + char dst[RRD_DST_SIZE]; /* Type of data source (null terminated) */ + rrd_value_t par[10]; /* index of this array see ds_param_en */ }; /* RRA definition */ @@ -103,7 +103,7 @@ enum rrd_rra_param { #define RRD_CF_NAM_SIZE 20 struct rrd_rra_def { - gchar cf_nam[RRD_CF_NAM_SIZE]; /* consolidation function (null term) */ + char cf_nam[RRD_CF_NAM_SIZE]; /* consolidation function (null term) */ gulong row_cnt; /* number of entries in the store */ gulong pdp_cnt; /* how many primary data points are * required for a consolidated data point?*/ @@ -125,12 +125,12 @@ enum rrd_pdp_param { this depends on dst */ struct rrd_pdp_prep { - gchar last_ds[RRD_LAST_DS_LEN]; /* the last reading from the data + char last_ds[RRD_LAST_DS_LEN]; /* the last reading from the data * source. this is stored in ASCII * to cater for very large counters * we might encounter in connection * with SNMP. */ - rrd_value_t scratch[10]; /* contents according to pdp_par_en */ + rrd_value_t scratch[10]; /* contents according to pdp_par_en */ }; #define RRD_MAX_CDP_PAR_EN 10 @@ -200,14 +200,14 @@ struct rspamd_rrd_file { struct rrd_pdp_prep *pdp_prep; /* pdp data prep area */ struct rrd_cdp_prep *cdp_prep; /* cdp prep area */ struct rrd_rra_ptr *rra_ptr; /* list of rra pointers */ - gdouble *rrd_value; /* list of rrd values */ + double *rrd_value; /* list of rrd values */ - gchar *filename; - guint8 *map; /* mmapped area */ - gsize size; /* its size */ + char *filename; + uint8_t *map; /* mmapped area */ + gsize size; /* its size */ gboolean finalized; - gchar *id; - gint fd; + char *id; + int fd; }; @@ -219,7 +219,7 @@ struct rspamd_rrd_file { * @param err error pointer * @return rrd file structure */ -struct rspamd_rrd_file *rspamd_rrd_open(const gchar *filename, GError **err); +struct rspamd_rrd_file *rspamd_rrd_open(const char *filename, GError **err); /** * Create basic header for rrd file @@ -230,11 +230,11 @@ struct rspamd_rrd_file *rspamd_rrd_open(const gchar *filename, GError **err); * @param err error pointer * @return TRUE if file has been created */ -struct rspamd_rrd_file *rspamd_rrd_create(const gchar *filename, +struct rspamd_rrd_file *rspamd_rrd_create(const char *filename, gulong ds_count, gulong rra_count, gulong pdp_step, - gdouble initial_ticks, + double initial_ticks, GError **err); /** @@ -276,7 +276,7 @@ gboolean rspamd_rrd_finalize(struct rspamd_rrd_file *file, GError **err); */ gboolean rspamd_rrd_add_record(struct rspamd_rrd_file *file, GArray *points, - gdouble ticks, + double ticks, GError **err); /** @@ -284,7 +284,7 @@ gboolean rspamd_rrd_add_record(struct rspamd_rrd_file *file, * @param file * @return */ -gint rspamd_rrd_close(struct rspamd_rrd_file *file); +int rspamd_rrd_close(struct rspamd_rrd_file *file); /* * Conversion functions @@ -293,29 +293,29 @@ gint rspamd_rrd_close(struct rspamd_rrd_file *file); /** * Convert rrd dst type from string to numeric value */ -enum rrd_dst_type rrd_dst_from_string(const gchar *str); +enum rrd_dst_type rrd_dst_from_string(const char *str); /** * Convert numeric presentation of dst to string */ -const gchar *rrd_dst_to_string(enum rrd_dst_type type); +const char *rrd_dst_to_string(enum rrd_dst_type type); /** * Convert rrd consolidation function type from string to numeric value */ -enum rrd_cf_type rrd_cf_from_string(const gchar *str); +enum rrd_cf_type rrd_cf_from_string(const char *str); /** * Convert numeric presentation of cf to string */ -const gchar *rrd_cf_to_string(enum rrd_cf_type type); +const char *rrd_cf_to_string(enum rrd_cf_type type); /* Default RRA and DS */ /** * Create default RRA */ -void rrd_make_default_rra(const gchar *cf_name, +void rrd_make_default_rra(const char *cf_name, gulong pdp_cnt, gulong rows, struct rrd_rra_def *rra); @@ -323,15 +323,15 @@ void rrd_make_default_rra(const gchar *cf_name, /** * Create default DS */ -void rrd_make_default_ds(const gchar *name, - const gchar *type, +void rrd_make_default_ds(const char *name, + const char *type, gulong pdp_step, struct rrd_ds_def *ds); /** * Open or create the default rspamd rrd file */ -struct rspamd_rrd_file *rspamd_rrd_file_default(const gchar *path, +struct rspamd_rrd_file *rspamd_rrd_file_default(const char *path, GError **err); /** @@ -341,9 +341,9 @@ struct rspamd_rrd_query_result { gulong rra_rows; gulong pdp_per_cdp; gulong ds_count; - gdouble last_update; + double last_update; gulong cur_row; - const gdouble *data; + const double *data; }; /** diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c index f074c76ff..5fe110eb8 100644 --- a/src/libutil/shingles.c +++ b/src/libutil/shingles.c @@ -22,7 +22,7 @@ #define SHINGLES_WINDOW 3 #define SHINGLES_KEY_SIZE rspamd_cryptobox_SIPKEYBYTES -static guint +static unsigned int rspamd_shingles_keys_hash(gconstpointer k) { return rspamd_cryptobox_fast_hash(k, SHINGLES_KEY_SIZE, @@ -38,8 +38,8 @@ rspamd_shingles_keys_equal(gconstpointer k1, gconstpointer k2) static void rspamd_shingles_keys_free(gpointer p) { - guchar **k = p; - guint i; + unsigned char **k = p; + unsigned int i; for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) { g_free(k[i]); @@ -48,30 +48,30 @@ rspamd_shingles_keys_free(gpointer p) g_free(k); } -static guchar ** +static unsigned char ** rspamd_shingles_keys_new(void) { - guchar **k; - guint i; + unsigned char **k; + unsigned int i; - k = g_malloc0(sizeof(guchar *) * RSPAMD_SHINGLE_SIZE); + k = g_malloc0(sizeof(unsigned char *) * RSPAMD_SHINGLE_SIZE); for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) { - k[i] = g_malloc0(sizeof(guchar) * SHINGLES_KEY_SIZE); + k[i] = g_malloc0(sizeof(unsigned char) * SHINGLES_KEY_SIZE); } return k; } -static guchar ** -rspamd_shingles_get_keys_cached(const guchar key[SHINGLES_KEY_SIZE]) +static unsigned char ** +rspamd_shingles_get_keys_cached(const unsigned char key[SHINGLES_KEY_SIZE]) { static GHashTable *ht = NULL; - guchar **keys = NULL, *key_cpy; + unsigned char **keys = NULL, *key_cpy; rspamd_cryptobox_hash_state_t bs; - const guchar *cur_key; - guchar shabuf[rspamd_cryptobox_HASHBYTES], *out_key; - guint i; + const unsigned char *cur_key; + unsigned char shabuf[rspamd_cryptobox_HASHBYTES], *out_key; + unsigned int i; if (ht == NULL) { ht = g_hash_table_new_full(rspamd_shingles_keys_hash, @@ -113,7 +113,7 @@ rspamd_shingles_get_keys_cached(const guchar key[SHINGLES_KEY_SIZE]) struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops") rspamd_shingles_from_text(GArray *input, - const guchar key[16], + const unsigned char key[16], rspamd_mempool_t *pool, rspamd_shingles_filter filter, gpointer filterd, @@ -121,11 +121,11 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops") { struct rspamd_shingle *res; uint64_t **hashes; - guchar **keys; + unsigned char **keys; rspamd_fstring_t *row; rspamd_stat_token_t *word; uint64_t val; - gint i, j, k; + int i, j, k; gsize hlen, ilen = 0, beg = 0, widx = 0; enum rspamd_cryptobox_fast_hash_type ht; @@ -157,8 +157,8 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops") /* Now parse input words into a vector of hashes using rolling window */ if (alg == RSPAMD_SHINGLES_OLD) { - for (i = 0; i <= (gint) ilen; i++) { - if (i - beg >= SHINGLES_WINDOW || i == (gint) ilen) { + for (i = 0; i <= (int) ilen; i++) { + if (i - beg >= SHINGLES_WINDOW || i == (int) ilen) { for (j = beg; j < i; j++) { word = NULL; @@ -196,7 +196,7 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops") /* Now we need to create a new row here */ for (j = 0; j < RSPAMD_SHINGLE_SIZE; j++) { - rspamd_cryptobox_siphash((guchar *) &val, row->str, row->len, + rspamd_cryptobox_siphash((unsigned char *) &val, row->str, row->len, keys[j]); g_assert(hlen > beg); hashes[j][beg] = val; @@ -301,8 +301,8 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops") } struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops") - rspamd_shingles_from_image(guchar *dct, - const guchar key[16], + rspamd_shingles_from_image(unsigned char *dct, + const unsigned char key[16], rspamd_mempool_t *pool, rspamd_shingles_filter filter, gpointer filterd, @@ -310,10 +310,10 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops") { struct rspamd_shingle *shingle; uint64_t **hashes; - guchar **keys; + unsigned char **keys; uint64_t d; uint64_t val; - gint i, j; + int i, j; gsize hlen, beg = 0; enum rspamd_cryptobox_fast_hash_type ht; uint64_t res[SHINGLES_WINDOW * RSPAMD_SHINGLE_SIZE], seed; @@ -382,7 +382,7 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops") uint64_t rspamd_shingles_default_filter(uint64_t *input, gsize count, - gint shno, const guchar *key, gpointer ud) + int shno, const unsigned char *key, gpointer ud) { uint64_t minimal = G_MAXUINT64; gsize i; @@ -397,10 +397,10 @@ rspamd_shingles_default_filter(uint64_t *input, gsize count, } -gdouble rspamd_shingles_compare(const struct rspamd_shingle *a, - const struct rspamd_shingle *b) +double rspamd_shingles_compare(const struct rspamd_shingle *a, + const struct rspamd_shingle *b) { - gint i, common = 0; + int i, common = 0; for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) { if (a->hashes[i] == b->hashes[i]) { @@ -408,5 +408,5 @@ gdouble rspamd_shingles_compare(const struct rspamd_shingle *a, } } - return (gdouble) common / (gdouble) RSPAMD_SHINGLE_SIZE; + return (double) common / (double) RSPAMD_SHINGLE_SIZE; } diff --git a/src/libutil/shingles.h b/src/libutil/shingles.h index d0da3fc04..fe6f16cf8 100644 --- a/src/libutil/shingles.h +++ b/src/libutil/shingles.h @@ -43,7 +43,7 @@ enum rspamd_shingle_alg { * @return shingle value */ typedef uint64_t (*rspamd_shingles_filter)(uint64_t *input, gsize count, - gint shno, const guchar *key, gpointer ud); + int shno, const unsigned char *key, gpointer ud); /** * Generate shingles from the input of fixed size strings using lemmatizer @@ -56,7 +56,7 @@ typedef uint64_t (*rspamd_shingles_filter)(uint64_t *input, gsize count, * @return shingles array */ struct rspamd_shingle *rspamd_shingles_from_text(GArray *input, - const guchar key[16], + const unsigned char key[16], rspamd_mempool_t *pool, rspamd_shingles_filter filter, gpointer filterd, @@ -71,8 +71,8 @@ struct rspamd_shingle *rspamd_shingles_from_text(GArray *input, * @param filterd opaque data for filtering function * @return shingles array */ -struct rspamd_shingle *rspamd_shingles_from_image(guchar *dct, - const guchar key[16], +struct rspamd_shingle *rspamd_shingles_from_image(unsigned char *dct, + const unsigned char key[16], rspamd_mempool_t *pool, rspamd_shingles_filter filter, gpointer filterd, @@ -85,14 +85,14 @@ struct rspamd_shingle *rspamd_shingles_from_image(guchar *dct, * @param b * @return */ -gdouble rspamd_shingles_compare(const struct rspamd_shingle *a, - const struct rspamd_shingle *b); +double rspamd_shingles_compare(const struct rspamd_shingle *a, + const struct rspamd_shingle *b); /** * Default filtering function */ uint64_t rspamd_shingles_default_filter(uint64_t *input, gsize count, - gint shno, const guchar *key, gpointer ud); + int shno, const unsigned char *key, gpointer ud); #ifdef __cplusplus } diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c index 0c9b4463f..88d420425 100644 --- a/src/libutil/sqlite_utils.c +++ b/src/libutil/sqlite_utils.c @@ -28,10 +28,10 @@ rspamd_sqlite3_quark(void) GArray * rspamd_sqlite3_init_prstmt(sqlite3 *db, struct rspamd_sqlite3_prstmt *init_stmt, - gint max_idx, + int max_idx, GError **err) { - gint i; + int i; GArray *res; struct rspamd_sqlite3_prstmt *nst; @@ -58,18 +58,18 @@ rspamd_sqlite3_init_prstmt(sqlite3 *db, } int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts, - gint idx, ...) + int idx, ...) { - gint retcode; + int retcode; va_list ap; sqlite3_stmt *stmt; - gint i, rowid, nargs, j; + int i, rowid, nargs, j; int64_t len; gpointer p; struct rspamd_sqlite3_prstmt *nst; const char *argtypes; - if (idx < 0 || idx >= (gint) stmts->len) { + if (idx < 0 || idx >= (int) stmts->len) { return -1; } @@ -119,13 +119,13 @@ int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts case 'S': for (j = 0; j < nargs; j++, rowid++) { - sqlite3_bind_int(stmt, rowid, va_arg(ap, gint)); + sqlite3_bind_int(stmt, rowid, va_arg(ap, int)); } nargs = 1; break; case '*': - nargs = va_arg(ap, gint); + nargs = va_arg(ap, int); break; } } @@ -186,7 +186,7 @@ int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts void rspamd_sqlite3_close_prstmt(sqlite3 *db, GArray *stmts) { - guint i; + unsigned int i; struct rspamd_sqlite3_prstmt *nst; for (i = 0; i < stmts->len; i++) { @@ -202,9 +202,9 @@ void rspamd_sqlite3_close_prstmt(sqlite3 *db, GArray *stmts) } static gboolean -rspamd_sqlite3_wait(rspamd_mempool_t *pool, const gchar *lock) +rspamd_sqlite3_wait(rspamd_mempool_t *pool, const char *lock) { - gint fd; + int fd; pid_t pid; gssize r; struct timespec sleep_ts = { @@ -278,11 +278,11 @@ rspamd_sqlite3_wait(rspamd_mempool_t *pool, const gchar *lock) #define RSPAMD_SQLITE_CACHE_SIZE 262144 sqlite3 * -rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, const gchar *path, const gchar *create_sql, guint version, GError **err) +rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, const char *path, const char *create_sql, unsigned int version, GError **err) { sqlite3 *sqlite; - gint rc, flags, lock_fd; - gchar lock_path[PATH_MAX], dbdir[PATH_MAX], *pdir; + int rc, flags, lock_fd; + char lock_path[PATH_MAX], dbdir[PATH_MAX], *pdir; static const char sqlite_wal[] = "PRAGMA journal_mode=\"wal\";" "PRAGMA wal_autocheckpoint = 16;" @@ -587,9 +587,9 @@ rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, const gchar *path, const g } gboolean -rspamd_sqlite3_sync(sqlite3 *db, gint *wal_frames, gint *wal_checkpoints) +rspamd_sqlite3_sync(sqlite3 *db, int *wal_frames, int *wal_checkpoints) { - gint wf = 0, wc = 0, mode; + int wf = 0, wc = 0, mode; #ifdef SQLITE_OPEN_WAL #ifdef SQLITE_CHECKPOINT_TRUNCATE diff --git a/src/libutil/sqlite_utils.h b/src/libutil/sqlite_utils.h index 4bb8dea17..c17bf36f8 100644 --- a/src/libutil/sqlite_utils.h +++ b/src/libutil/sqlite_utils.h @@ -27,13 +27,13 @@ extern "C" { #endif struct rspamd_sqlite3_prstmt { - gint idx; - const gchar *sql; - const gchar *args; + int idx; + const char *sql; + const char *args; sqlite3_stmt *stmt; - gint result; - const gchar *ret; - gint flags; + int result; + const char *ret; + int flags; }; /** @@ -45,7 +45,7 @@ struct rspamd_sqlite3_prstmt { */ GArray *rspamd_sqlite3_init_prstmt(sqlite3 *db, struct rspamd_sqlite3_prstmt *init_stmt, - gint max_idx, + int max_idx, GError **err); /** @@ -56,8 +56,8 @@ GArray *rspamd_sqlite3_init_prstmt(sqlite3 *db, * @param idx * @return */ -gint rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts, - gint idx, ...); +int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts, + int idx, ...); /** * Close and free prepared statements @@ -73,7 +73,7 @@ void rspamd_sqlite3_close_prstmt(sqlite3 *db, GArray *stmts); * @return */ sqlite3 *rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, - const gchar *path, const gchar *create_sql, + const char *path, const char *create_sql, uint32_t version, GError **err); @@ -81,7 +81,7 @@ sqlite3 *rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, * Sync sqlite3 db ensuring that all wal things are done * @param db */ -gboolean rspamd_sqlite3_sync(sqlite3 *db, gint *wal_frames, gint *wal_checkpoints); +gboolean rspamd_sqlite3_sync(sqlite3 *db, int *wal_frames, int *wal_checkpoints); #ifdef __cplusplus } diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index 77fa20f54..eda3331fa 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -33,7 +33,7 @@ #include "contrib/fastutf8/fastutf8.h" -const guchar lc_map[256] = { +const unsigned char lc_map[256] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, @@ -67,13 +67,13 @@ const guchar lc_map[256] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}; -guint rspamd_str_lc(gchar *str, guint size) +unsigned int rspamd_str_lc(char *str, unsigned int size) { - guint leftover = size % 4; - guint fp, i; + unsigned int leftover = size % 4; + unsigned int fp, i; const uint8_t *s = (const uint8_t *) str; - gchar *dest = str; - guchar c1, c2, c3, c4; + char *dest = str; + unsigned char c1, c2, c3, c4; fp = size - leftover; @@ -88,25 +88,25 @@ guint rspamd_str_lc(gchar *str, guint size) switch (leftover) { case 3: - *dest++ = lc_map[(guchar) str[i++]]; + *dest++ = lc_map[(unsigned char) str[i++]]; /* FALLTHRU */ case 2: - *dest++ = lc_map[(guchar) str[i++]]; + *dest++ = lc_map[(unsigned char) str[i++]]; /* FALLTHRU */ case 1: - *dest = lc_map[(guchar) str[i]]; + *dest = lc_map[(unsigned char) str[i]]; } return size; } -gsize rspamd_str_copy_lc(const gchar *src, gchar *dst, gsize size) +gsize rspamd_str_copy_lc(const char *src, char *dst, gsize size) { - gchar *d = dst; + char *d = dst; /* Find aligned start */ while ((0xf & (uintptr_t) src) && size > 0) { - *d++ = lc_map[(guchar) *src++]; + *d++ = lc_map[(unsigned char) *src++]; size--; } @@ -130,23 +130,23 @@ gsize rspamd_str_copy_lc(const gchar *src, gchar *dst, gsize size) /* Leftover */ while (size > 0) { - *d++ = lc_map[(guchar) *src++]; + *d++ = lc_map[(unsigned char) *src++]; size--; } return (d - dst); } -gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l) +int rspamd_lc_cmp(const char *s, const char *d, gsize l) { gsize fp, i; - guchar c1, c2, c3, c4; + unsigned char c1, c2, c3, c4; union { - guchar c[4]; + unsigned char c[4]; uint32_t n; } cmp1, cmp2; gsize leftover = l % 4; - gint ret = 0; + int ret = 0; fp = l - leftover; @@ -185,16 +185,16 @@ gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l) * string to lower case, so some locale peculiarities are simply ignored * If the target string is longer than initial one, then we just trim it */ -guint rspamd_str_lc_utf8(gchar *str, guint size) +unsigned int rspamd_str_lc_utf8(char *str, unsigned int size) { - guchar *d = (guchar *) str, tst[6]; + unsigned char *d = (unsigned char *) str, tst[6]; int32_t i = 0, prev = 0; UChar32 uc; while (i < size) { prev = i; - U8_NEXT((guint8 *) str, i, size, uc); + U8_NEXT((uint8_t *) str, i, size, uc); uc = u_tolower(uc); int32_t olen = 0; @@ -210,13 +210,13 @@ guint rspamd_str_lc_utf8(gchar *str, guint size) } } - return d - (guchar *) str; + return d - (unsigned char *) str; } gboolean rspamd_strcase_equal(gconstpointer v, gconstpointer v2) { - if (g_ascii_strcasecmp((const gchar *) v, (const gchar *) v2) == 0) { + if (g_ascii_strcasecmp((const char *) v, (const char *) v2) == 0) { return TRUE; } @@ -224,14 +224,14 @@ rspamd_strcase_equal(gconstpointer v, gconstpointer v2) } uint64_t -rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed) +rspamd_icase_hash(const char *in, gsize len, uint64_t seed) { - guint leftover = len % sizeof(uint64_t); - guint fp, i; + unsigned int leftover = len % sizeof(uint64_t); + unsigned int fp, i; const uint8_t *s = (const uint8_t *) in; union { struct { - guchar c1, c2, c3, c4, c5, c6, c7, c8; + unsigned char c1, c2, c3, c4, c5, c6, c7, c8; } c; uint64_t pp; } u; @@ -257,19 +257,19 @@ rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed) switch (leftover) { case 7: - u.c.c7 = lc_map[(guchar) s[i++]]; /* FALLTHRU */ + u.c.c7 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */ case 6: - u.c.c6 = lc_map[(guchar) s[i++]]; /* FALLTHRU */ + u.c.c6 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */ case 5: - u.c.c5 = lc_map[(guchar) s[i++]]; /* FALLTHRU */ + u.c.c5 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */ case 4: - u.c.c4 = lc_map[(guchar) s[i++]]; /* FALLTHRU */ + u.c.c4 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */ case 3: - u.c.c3 = lc_map[(guchar) s[i++]]; /* FALLTHRU */ + u.c.c3 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */ case 2: - u.c.c2 = lc_map[(guchar) s[i++]]; /* FALLTHRU */ + u.c.c2 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */ case 1: - u.c.c1 = lc_map[(guchar) s[i]]; + u.c.c1 = lc_map[(unsigned char) s[i]]; break; } @@ -278,29 +278,29 @@ rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed) return h; } -guint rspamd_strcase_hash(gconstpointer key) +unsigned int rspamd_strcase_hash(gconstpointer key) { - const gchar *p = key; + const char *p = key; gsize len; len = strlen(p); - return (guint) rspamd_icase_hash(p, len, rspamd_hash_seed()); + return (unsigned int) rspamd_icase_hash(p, len, rspamd_hash_seed()); } -guint rspamd_str_hash(gconstpointer key) +unsigned int rspamd_str_hash(gconstpointer key) { gsize len; - len = strlen((const gchar *) key); + len = strlen((const char *) key); - return (guint) rspamd_cryptobox_fast_hash(key, len, rspamd_hash_seed()); + return (unsigned int) rspamd_cryptobox_fast_hash(key, len, rspamd_hash_seed()); } gboolean rspamd_str_equal(gconstpointer v, gconstpointer v2) { - return strcmp((const gchar *) v, (const gchar *) v2) == 0; + return strcmp((const char *) v, (const char *) v2) == 0; } gboolean @@ -317,11 +317,11 @@ rspamd_ftok_icase_equal(gconstpointer v, gconstpointer v2) } -guint rspamd_ftok_icase_hash(gconstpointer key) +unsigned int rspamd_ftok_icase_hash(gconstpointer key) { const rspamd_ftok_t *f = key; - return (guint) rspamd_icase_hash(f->begin, f->len, rspamd_hash_seed()); + return (unsigned int) rspamd_icase_hash(f->begin, f->len, rspamd_hash_seed()); } gboolean @@ -336,11 +336,11 @@ rspamd_gstring_icase_equal(gconstpointer v, gconstpointer v2) return FALSE; } -guint rspamd_gstring_icase_hash(gconstpointer key) +unsigned int rspamd_gstring_icase_hash(gconstpointer key) { const GString *f = key; - return (guint) rspamd_icase_hash(f->str, f->len, rspamd_hash_seed()); + return (unsigned int) rspamd_icase_hash(f->str, f->len, rspamd_hash_seed()); } /* https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord */ @@ -355,10 +355,10 @@ guint rspamd_gstring_icase_hash(gconstpointer key) #define HASZERO(x) ~(((((x) &ZEROMASK) + ZEROMASK) | (x)) | ZEROMASK) -gsize rspamd_strlcpy_fast(gchar *dst, const gchar *src, gsize siz) +gsize rspamd_strlcpy_fast(char *dst, const char *src, gsize siz) { - gchar *d = dst; - const gchar *s = src; + char *d = dst; + const char *s = src; gsize n = siz; WORD_TYPE *wd; const WORD_TYPE *ws; @@ -398,8 +398,8 @@ gsize rspamd_strlcpy_fast(gchar *dst, const gchar *src, gsize siz) return (d - dst); } -gsize rspamd_null_safe_copy(const gchar *src, gsize srclen, - gchar *dest, gsize destlen) +gsize rspamd_null_safe_copy(const char *src, gsize srclen, + char *dest, gsize destlen) { gsize copied = 0, si = 0, di = 0; @@ -424,9 +424,9 @@ gsize rspamd_null_safe_copy(const gchar *src, gsize srclen, size_t -rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz) +rspamd_strlcpy_safe(char *dst, const char *src, gsize siz) { - gchar *d = dst; + char *d = dst; gsize nleft = siz; if (nleft != 0) { @@ -451,10 +451,10 @@ rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz) * Try to convert string of length to long */ gboolean -rspamd_strtol(const gchar *s, gsize len, glong *value) +rspamd_strtol(const char *s, gsize len, glong *value) { - const gchar *p = s, *end = s + len; - gchar c; + const char *p = s, *end = s + len; + char c; glong v = 0; const glong cutoff = G_MAXLONG / 10, cutlim = G_MAXLONG % 10; gboolean neg; @@ -496,34 +496,34 @@ rspamd_strtol(const gchar *s, gsize len, glong *value) /* * Try to convert string of length to long */ -#define CONV_STR_LIM_DECIMAL(max_num) \ - do { \ - while (p < end) { \ - c = *p; \ - if (c >= '0' && c <= '9') { \ - c -= '0'; \ - if (v > cutoff || (v == cutoff && (guint8) c > cutlim)) { \ - *value = (max_num); \ - return FALSE; \ - } \ - else { \ - v *= 10; \ - v += c; \ - } \ - } \ - else { \ - *value = v; \ - return FALSE; \ - } \ - p++; \ - } \ +#define CONV_STR_LIM_DECIMAL(max_num) \ + do { \ + while (p < end) { \ + c = *p; \ + if (c >= '0' && c <= '9') { \ + c -= '0'; \ + if (v > cutoff || (v == cutoff && (uint8_t) c > cutlim)) { \ + *value = (max_num); \ + return FALSE; \ + } \ + else { \ + v *= 10; \ + v += c; \ + } \ + } \ + else { \ + *value = v; \ + return FALSE; \ + } \ + p++; \ + } \ } while (0) gboolean -rspamd_strtoul(const gchar *s, gsize len, gulong *value) +rspamd_strtoul(const char *s, gsize len, gulong *value) { - const gchar *p = s, *end = s + len; - gchar c; + const char *p = s, *end = s + len; + char c; gulong v = 0; const gulong cutoff = G_MAXULONG / 10, cutlim = G_MAXULONG % 10; @@ -535,10 +535,10 @@ rspamd_strtoul(const gchar *s, gsize len, gulong *value) } gboolean -rspamd_strtou64(const gchar *s, gsize len, uint64_t *value) +rspamd_strtou64(const char *s, gsize len, uint64_t *value) { - const gchar *p = s, *end = s + len; - gchar c; + const char *p = s, *end = s + len; + char c; uint64_t v = 0; const uint64_t cutoff = G_MAXUINT64 / 10, cutlim = G_MAXUINT64 % 10; @@ -550,10 +550,10 @@ rspamd_strtou64(const gchar *s, gsize len, uint64_t *value) } gboolean -rspamd_xstrtoul(const gchar *s, gsize len, gulong *value) +rspamd_xstrtoul(const char *s, gsize len, gulong *value) { - const gchar *p = s, *end = s + len; - gchar c; + const char *p = s, *end = s + len; + char c; gulong v = 0; const gulong cutoff = G_MAXULONG / 10, cutlim = G_MAXULONG % 10; @@ -562,7 +562,7 @@ rspamd_xstrtoul(const gchar *s, gsize len, gulong *value) c = g_ascii_tolower(*p); if (c >= '0' && c <= '9') { c -= '0'; - if (v > cutoff || (v == cutoff && (guint8) c > cutlim)) { + if (v > cutoff || (v == cutoff && (uint8_t) c > cutlim)) { /* Range error */ *value = G_MAXULONG; return FALSE; @@ -574,7 +574,7 @@ rspamd_xstrtoul(const gchar *s, gsize len, gulong *value) } else if (c >= 'a' || c <= 'f') { c = c - 'a' + 10; - if (v > cutoff || (v == cutoff && (guint8) c > cutlim)) { + if (v > cutoff || (v == cutoff && (uint8_t) c > cutlim)) { /* Range error */ *value = G_MAXULONG; return FALSE; @@ -615,16 +615,16 @@ rspamd_str_pool_copy(gconstpointer data, gpointer ud) * http://philzimmermann.com/docs/human-oriented-base-32-encoding.txt */ -gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out, gsize outlen, - enum rspamd_base32_type type) +int rspamd_encode_base32_buf(const unsigned char *in, gsize inlen, char *out, gsize outlen, + enum rspamd_base32_type type) { static const char b32_default[] = "ybndrfg8ejkmcpqxot1uwisza345h769", b32_bleach[] = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", b32_rfc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", *b32; - gchar *o, *end; + char *o, *end; gsize i; - gint remain = -1, x; + int remain = -1, x; bool inverse_order = true; end = out + outlen; @@ -744,12 +744,12 @@ gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out, gsize o return -1; } -gchar * -rspamd_encode_base32(const guchar *in, gsize inlen, enum rspamd_base32_type type) +char * +rspamd_encode_base32(const unsigned char *in, gsize inlen, enum rspamd_base32_type type) { gsize allocated_len = inlen * 8 / 5 + 2; - gchar *out; - gint outlen; + char *out; + int outlen; out = g_malloc(allocated_len); outlen = rspamd_encode_base32_buf(in, inlen, out, @@ -767,7 +767,7 @@ rspamd_encode_base32(const guchar *in, gsize inlen, enum rspamd_base32_type type } enum rspamd_base32_type -rspamd_base32_decode_type_from_str(const gchar *str) +rspamd_base32_decode_type_from_str(const char *str) { enum rspamd_base32_type ret = RSPAMD_BASE32_INVALID; @@ -788,7 +788,7 @@ rspamd_base32_decode_type_from_str(const gchar *str) return ret; } -static const guchar b32_dec_zbase[] = { +static const unsigned char b32_dec_zbase[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -821,7 +821,7 @@ static const guchar b32_dec_zbase[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; -static const guchar b32_dec_bleach[] = { +static const unsigned char b32_dec_bleach[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -854,7 +854,7 @@ static const guchar b32_dec_bleach[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; -static const guchar b32_dec_rfc[] = { +static const unsigned char b32_dec_rfc[] = { 0xff, 0xff, 0xff, @@ -1114,15 +1114,15 @@ static const guchar b32_dec_rfc[] = { }; -gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, gsize outlen, - enum rspamd_base32_type type) +int rspamd_decode_base32_buf(const char *in, gsize inlen, unsigned char *out, gsize outlen, + enum rspamd_base32_type type) { - guchar *o, *end, decoded; - guchar c; - guint acc = 0U; - guint processed_bits = 0; + unsigned char *o, *end, decoded; + unsigned char c; + unsigned int acc = 0U; + unsigned int processed_bits = 0; gsize i; - const guchar *b32_dec; + const unsigned char *b32_dec; bool inverse_bits = true; end = out + outlen; @@ -1147,7 +1147,7 @@ gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, gsize o if (inverse_bits) { for (i = 0; i < inlen; i++) { - c = (guchar) in[i]; + c = (unsigned char) in[i]; if (processed_bits >= 8) { /* Emit from left to right */ @@ -1174,7 +1174,7 @@ gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, gsize o } else { for (i = 0; i < inlen; i++) { - c = (guchar) in[i]; + c = (unsigned char) in[i]; decoded = b32_dec[c]; if (decoded == 0xff) { @@ -1210,11 +1210,11 @@ gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, gsize o return (o - out); } -guchar * -rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen, +unsigned char * +rspamd_decode_base32(const char *in, gsize inlen, gsize *outlen, enum rspamd_base32_type type) { - guchar *res; + unsigned char *res; gsize allocated_len = inlen * 5 / 8 + 2; gssize olen; @@ -1245,8 +1245,8 @@ rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen, } -gchar * -rspamd_encode_base64_common(const guchar *in, gsize inlen, gint str_len, +char * +rspamd_encode_base64_common(const unsigned char *in, gsize inlen, int str_len, gsize *outlen, gboolean fold, enum rspamd_newlines_type how) { #define ADD_SPLIT \ @@ -1264,10 +1264,10 @@ rspamd_encode_base64_common(const guchar *in, gsize inlen, gint str_len, } while (0) gsize allocated_len = (inlen / 3) * 4 + 5; - gchar *out, *o; + char *out, *o; uint64_t n; uint32_t rem, t, carry; - gint cols, shift; + int cols, shift; static const char b64_enc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" @@ -1415,16 +1415,16 @@ end: return out; } -gchar * -rspamd_encode_base64(const guchar *in, gsize inlen, gint str_len, +char * +rspamd_encode_base64(const unsigned char *in, gsize inlen, int str_len, gsize *outlen) { return rspamd_encode_base64_common(in, inlen, str_len, outlen, FALSE, RSPAMD_TASK_NEWLINES_CRLF); } -gchar * -rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len, +char * +rspamd_encode_base64_fold(const unsigned char *in, gsize inlen, int str_len, gsize *outlen, enum rspamd_newlines_type how) { return rspamd_encode_base64_common(in, inlen, str_len, outlen, TRUE, how); @@ -1436,15 +1436,15 @@ rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len, #define QP_SPAN_SPECIAL(span, str_len) ((str_len) > 0 && \ ((span) + 4) >= (str_len)) -gchar * -rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len, +char * +rspamd_encode_qp_fold(const unsigned char *in, gsize inlen, int str_len, gsize *outlen, enum rspamd_newlines_type how) { gsize olen = 0, span = 0, i = 0, seen_spaces = 0; - gchar *out; - gint ch, last_sp; - const guchar *end = in + inlen, *p = in; - static const gchar hexdigests[16] = "0123456789ABCDEF"; + char *out; + int ch, last_sp; + const unsigned char *end = in + inlen, *p = in; + static const char hexdigests[16] = "0123456789ABCDEF"; while (p < end) { ch = *p; @@ -1662,15 +1662,15 @@ rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len, #define MIN3(a, b, c) ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c))) -gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len, - const gchar *s2, gsize s2len, - guint replace_cost) +int rspamd_strings_levenshtein_distance(const char *s1, gsize s1len, + const char *s2, gsize s2len, + unsigned int replace_cost) { - gchar c1, c2, last_c2, last_c1; + char c1, c2, last_c2, last_c1; static GArray *current_row = NULL, *prev_row = NULL, *transp_row = NULL; - gint eq; - static const guint max_cmp = 8192; - gint ret; + int eq; + static const unsigned int max_cmp = 8192; + int ret; g_assert(s1 != NULL); g_assert(s2 != NULL); @@ -1689,7 +1689,7 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len, if (s1len > s2len) { /* Exchange s1 and s2 */ - const gchar *tmp; + const char *tmp; gsize tmplen; tmp = s2; @@ -1703,9 +1703,9 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len, /* Adjust static space */ if (current_row == NULL) { - current_row = g_array_sized_new(FALSE, FALSE, sizeof(gint), s1len + 1); - prev_row = g_array_sized_new(FALSE, FALSE, sizeof(gint), s1len + 1); - transp_row = g_array_sized_new(FALSE, FALSE, sizeof(gint), s1len + 1); + current_row = g_array_sized_new(FALSE, FALSE, sizeof(int), s1len + 1); + prev_row = g_array_sized_new(FALSE, FALSE, sizeof(int), s1len + 1); + transp_row = g_array_sized_new(FALSE, FALSE, sizeof(int), s1len + 1); g_array_set_size(current_row, s1len + 1); g_array_set_size(prev_row, s1len + 1); g_array_set_size(transp_row, s1len + 1); @@ -1716,33 +1716,33 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len, g_array_set_size(transp_row, s1len + 1); } - memset(current_row->data, 0, (s1len + 1) * sizeof(gint)); - memset(transp_row->data, 0, (s1len + 1) * sizeof(gint)); + memset(current_row->data, 0, (s1len + 1) * sizeof(int)); + memset(transp_row->data, 0, (s1len + 1) * sizeof(int)); - for (gint i = 0; i <= s1len; i++) { - g_array_index(prev_row, gint, i) = i; + for (int i = 0; i <= s1len; i++) { + g_array_index(prev_row, int, i) = i; } last_c2 = '\0'; - for (gint i = 1; i <= s2len; i++) { + for (int i = 1; i <= s2len; i++) { c2 = s2[i - 1]; - g_array_index(current_row, gint, 0) = i; + g_array_index(current_row, int, 0) = i; last_c1 = '\0'; - for (gint j = 1; j <= s1len; j++) { + for (int j = 1; j <= s1len; j++) { c1 = s1[j - 1]; eq = c1 == c2 ? 0 : replace_cost; - ret = MIN3(g_array_index(current_row, gint, j - 1) + 1, /* Insert */ - g_array_index(prev_row, gint, j) + 1, /* Remove */ - g_array_index(prev_row, gint, j - 1) + eq /* Replace */); + ret = MIN3(g_array_index(current_row, int, j - 1) + 1, /* Insert */ + g_array_index(prev_row, int, j) + 1, /* Remove */ + g_array_index(prev_row, int, j - 1) + eq /* Replace */); /* Take reordering into account */ if (c1 == last_c2 && c2 == last_c1 && j >= 2) { - ret = MIN(ret, g_array_index(transp_row, gint, j - 2) + eq); + ret = MIN(ret, g_array_index(transp_row, int, j - 2) + eq); } - g_array_index(current_row, gint, j) = ret; + g_array_index(current_row, int, j) = ret; last_c1 = c1; } @@ -1756,24 +1756,24 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len, current_row = tmp; } - ret = g_array_index(prev_row, gint, s1len); + ret = g_array_index(prev_row, int, s1len); return ret; } GString * -rspamd_header_value_fold(const gchar *name, gsize name_len, - const gchar *value, +rspamd_header_value_fold(const char *name, gsize name_len, + const char *value, gsize value_len, - guint fold_max, + unsigned int fold_max, enum rspamd_newlines_type how, - const gchar *fold_on_chars) + const char *fold_on_chars) { GString *res; - const guint default_fold_max = 76; - guint cur_len; - const gchar *p, *c, *end, *fold_sequence; - guint nspaces = 0; + const unsigned int default_fold_max = 76; + unsigned int cur_len; + const char *p, *c, *end, *fold_sequence; + unsigned int nspaces = 0; gboolean first_token = TRUE; enum { fold_before = 0, @@ -1940,7 +1940,7 @@ rspamd_header_value_fold(const gchar *name, gsize name_len, * Check any spaces that are appended to the result * before folding */ - const gchar *last = &res->str[res->len - 1]; + const char *last = &res->str[res->len - 1]; while (g_ascii_isspace(*last)) { last--; @@ -1965,7 +1965,7 @@ rspamd_header_value_fold(const gchar *name, gsize name_len, cur_len = 0; } else { - const gchar *last; + const char *last; /* Skip space if needed */ if (g_ascii_isspace(*c) && p > c) { @@ -2071,20 +2071,20 @@ rspamd_header_value_fold(const gchar *name, gsize name_len, return res; } -static inline bool rspamd_substring_cmp_func(guchar a, guchar b) +static inline bool rspamd_substring_cmp_func(unsigned char a, unsigned char b) { return a == b; } -static inline bool rspamd_substring_casecmp_func(guchar a, guchar b) +static inline bool rspamd_substring_casecmp_func(unsigned char a, unsigned char b) { return lc_map[a] == lc_map[b]; } -typedef bool (*rspamd_cmpchar_func_t)(guchar a, guchar b); +typedef bool (*rspamd_cmpchar_func_t)(unsigned char a, unsigned char b); static inline void -rspamd_substring_preprocess_kmp(const gchar *pat, gsize len, goffset *fsm, +rspamd_substring_preprocess_kmp(const char *pat, gsize len, goffset *fsm, rspamd_cmpchar_func_t f) { goffset i, j; @@ -2111,8 +2111,8 @@ rspamd_substring_preprocess_kmp(const gchar *pat, gsize len, goffset *fsm, } static inline goffset -rspamd_substring_search_preprocessed(const gchar *in, gsize inlen, - const gchar *srch, +rspamd_substring_search_preprocessed(const char *in, gsize inlen, + const char *srch, gsize srchlen, const goffset *fsm, rspamd_cmpchar_func_t f) @@ -2164,8 +2164,8 @@ rspamd_substring_search_preprocessed(const gchar *in, gsize inlen, } static inline goffset -rspamd_substring_search_common(const gchar *in, gsize inlen, - const gchar *srch, gsize srchlen, rspamd_cmpchar_func_t f) +rspamd_substring_search_common(const char *in, gsize inlen, + const char *srch, gsize srchlen, rspamd_cmpchar_func_t f) { static goffset st_fsm[128]; goffset *fsm, ret; @@ -2188,12 +2188,12 @@ rspamd_substring_search_common(const gchar *in, gsize inlen, } goffset -rspamd_substring_search(const gchar *in, gsize inlen, - const gchar *srch, gsize srchlen) +rspamd_substring_search(const char *in, gsize inlen, + const char *srch, gsize srchlen) { if (inlen > srchlen) { if (G_UNLIKELY(srchlen == 1)) { - const gchar *p; + const char *p; p = memchr(in, srch[0], inlen); @@ -2221,16 +2221,16 @@ rspamd_substring_search(const gchar *in, gsize inlen, } goffset -rspamd_substring_search_caseless(const gchar *in, gsize inlen, - const gchar *srch, gsize srchlen) +rspamd_substring_search_caseless(const char *in, gsize inlen, + const char *srch, gsize srchlen) { if (inlen > srchlen) { if (G_UNLIKELY(srchlen == 1)) { goffset i; - gchar s = lc_map[(guchar) srch[0]]; + char s = lc_map[(unsigned char) srch[0]]; for (i = 0; i < inlen; i++) { - if (lc_map[(guchar) in[i]] == s) { + if (lc_map[(unsigned char) in[i]] == s) { return i; } } @@ -2251,7 +2251,7 @@ rspamd_substring_search_caseless(const gchar *in, gsize inlen, goffset rspamd_string_find_eoh(GString *input, goffset *body_start) { - const gchar *p, *c = NULL, *end; + const char *p, *c = NULL, *end; enum { skip_char = 0, got_cr, @@ -2492,12 +2492,12 @@ rspamd_string_find_eoh(GString *input, goffset *body_start) return -1; } -gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out, - gsize outlen) +int rspamd_encode_hex_buf(const unsigned char *in, gsize inlen, char *out, + gsize outlen) { - gchar *o, *end; - const guchar *p; - static const gchar hexdigests[16] = "0123456789abcdef"; + char *o, *end; + const unsigned char *p; + static const char hexdigests[16] = "0123456789abcdef"; end = out + outlen; o = out; @@ -2516,12 +2516,12 @@ gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out, return -1; } -gchar * -rspamd_encode_hex(const guchar *in, gsize inlen) +char * +rspamd_encode_hex(const unsigned char *in, gsize inlen) { - gchar *out; + char *out; gsize outlen = inlen * 2 + 1; - gint olen; + int olen; if (in == NULL) { return NULL; @@ -2543,12 +2543,12 @@ rspamd_encode_hex(const guchar *in, gsize inlen) } gssize -rspamd_decode_hex_buf(const gchar *in, gsize inlen, - guchar *out, gsize outlen) +rspamd_decode_hex_buf(const char *in, gsize inlen, + unsigned char *out, gsize outlen) { - guchar *o, *end, ret = 0; - const gchar *p; - gchar c; + unsigned char *o, *end, ret = 0; + const char *p; + char c; end = out + outlen; o = out; @@ -2587,12 +2587,12 @@ rspamd_decode_hex_buf(const gchar *in, gsize inlen, return -1; } -guchar * -rspamd_decode_hex(const gchar *in, gsize inlen) +unsigned char * +rspamd_decode_hex(const char *in, gsize inlen) { - guchar *out; + unsigned char *out; gsize outlen = (inlen / 2 + inlen % 2) + 1; - gint olen; + int olen; if (in == NULL) { return NULL; @@ -2614,12 +2614,12 @@ rspamd_decode_hex(const gchar *in, gsize inlen) } gssize -rspamd_decode_qp_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen) +rspamd_decode_qp_buf(const char *in, gsize inlen, + char *out, gsize outlen) { - gchar *o, *end, *pos, c; - const gchar *p; - guchar ret; + char *o, *end, *pos, c; + const char *p; + unsigned char ret; gssize remain, processed; p = in; @@ -2715,7 +2715,7 @@ rspamd_decode_qp_buf(const gchar *in, gsize inlen, } if (end - o > 0) { - *o++ = (gchar) ret; + *o++ = (char) ret; } else { return (-1); @@ -2769,15 +2769,15 @@ rspamd_decode_qp_buf(const gchar *in, gsize inlen, } gssize -rspamd_decode_uue_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen) +rspamd_decode_uue_buf(const char *in, gsize inlen, + char *out, gsize outlen) { - gchar *o, *out_end; - const gchar *p; + char *o, *out_end; + const char *p; gssize remain; gboolean base64 = FALSE; goffset pos; - const gchar *nline = "\r\n"; + const char *nline = "\r\n"; p = in; o = out; @@ -2848,8 +2848,8 @@ rspamd_decode_uue_buf(const gchar *in, gsize inlen, while (remain > 0 && o < out_end) { /* Main cycle */ - const gchar *eol; - gint i, ch; + const char *eol; + int i, ch; pos = rspamd_memcspn(p, nline, remain); @@ -2930,10 +2930,10 @@ rspamd_decode_uue_buf(const gchar *in, gsize inlen, ((a)[(gsize) (b) / (8 * sizeof *(a))] op(gsize) 1 << ((gsize) (b) % (8 * sizeof *(a)))) -gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len) +gsize rspamd_memcspn(const char *s, const char *e, gsize len) { gsize byteset[32 / sizeof(gsize)]; - const gchar *p = s, *end = s + len; + const char *p = s, *end = s + len; if (!e[1]) { for (; p < end && *p != *e; p++) @@ -2943,18 +2943,18 @@ gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len) memset(byteset, 0, sizeof byteset); - for (; *e && BITOP(byteset, *(guchar *) e, |=); e++) + for (; *e && BITOP(byteset, *(unsigned char *) e, |=); e++) ; - for (; p < end && !BITOP(byteset, *(guchar *) p, &); p++) + for (; p < end && !BITOP(byteset, *(unsigned char *) p, &); p++) ; return p - s; } -gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len) +gsize rspamd_memspn(const char *s, const char *e, gsize len) { gsize byteset[32 / sizeof(gsize)]; - const gchar *p = s, *end = s + len; + const char *p = s, *end = s + len; if (!e[1]) { for (; p < end && *p == *e; p++) @@ -2964,21 +2964,21 @@ gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len) memset(byteset, 0, sizeof byteset); - for (; *e && BITOP(byteset, *(guchar *) e, |=); e++) + for (; *e && BITOP(byteset, *(unsigned char *) e, |=); e++) ; - for (; p < end && BITOP(byteset, *(guchar *) p, &); p++) + for (; p < end && BITOP(byteset, *(unsigned char *) p, &); p++) ; return p - s; } gssize -rspamd_decode_qp2047_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen) +rspamd_decode_qp2047_buf(const char *in, gsize inlen, + char *out, gsize outlen) { - gchar *o, *end, c; - const gchar *p; - guchar ret; + char *o, *end, c; + const char *p; + unsigned char ret; gsize remain, processed; p = in; @@ -3033,7 +3033,7 @@ rspamd_decode_qp2047_buf(const gchar *in, gsize inlen, } if (end - o > 0) { - *o++ = (gchar) ret; + *o++ = (char) ret; } else { return (-1); @@ -3080,11 +3080,11 @@ rspamd_decode_qp2047_buf(const gchar *in, gsize inlen, } gssize -rspamd_encode_qp2047_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen) +rspamd_encode_qp2047_buf(const char *in, gsize inlen, + char *out, gsize outlen) { - gchar *o = out, *end = out + outlen, c; - static const gchar hexdigests[16] = "0123456789ABCDEF"; + char *o = out, *end = out + outlen, c; + static const char hexdigests[16] = "0123456789ABCDEF"; while (inlen > 0 && o < end) { c = *in; @@ -3239,7 +3239,7 @@ rspamd_fstring_emit_append_double(double val, void *ud) #define MAX_PRECISION 6 if (isfinite(val)) { - if (val == (double) ((gint) val)) { + if (val == (double) ((int) val)) { rspamd_printf_fstring(buf, "%.1f", val); } else { @@ -3271,9 +3271,9 @@ void rspamd_ucl_emit_fstring_comments(const ucl_object_t *obj, #ifndef HAVE_MEMRCHR void * -rspamd_memrchr(const void *m, gint c, gsize len) +rspamd_memrchr(const void *m, int c, gsize len) { - const guint8 *p = m; + const uint8_t *p = m; for (gsize i = len; i > 0; i--) { if (p[i - 1] == c) { @@ -3337,14 +3337,14 @@ rspamd_get_unicode_normalizer(void) #endif } -gchar * -rspamd_str_regexp_escape(const gchar *pattern, gsize slen, +char * +rspamd_str_regexp_escape(const char *pattern, gsize slen, gsize *dst_len, enum rspamd_regexp_escape_flags flags) { - const gchar *p, *end = pattern + slen; - gchar *res, *d, t, *tmp_utf = NULL, *dend; + const char *p, *end = pattern + slen; + char *res, *d, t, *tmp_utf = NULL, *dend; gsize len; - static const gchar hexdigests[16] = "0123456789abcdef"; + static const char hexdigests[16] = "0123456789abcdef"; len = 0; p = pattern; @@ -3541,15 +3541,15 @@ rspamd_str_regexp_escape(const gchar *pattern, gsize slen, } -gchar * -rspamd_str_make_utf_valid(const guchar *src, gsize slen, +char * +rspamd_str_make_utf_valid(const unsigned char *src, gsize slen, gsize *dstlen, rspamd_mempool_t *pool) { UChar32 uc; goffset err_offset; - const guchar *p; - gchar *dst, *d; + const unsigned char *p; + char *dst, *d; gsize remain = slen, dlen = 0; if (src == NULL) { @@ -3569,7 +3569,7 @@ rspamd_str_make_utf_valid(const guchar *src, gsize slen, /* Check space required */ while (remain > 0 && (err_offset = rspamd_fast_utf8_validate(p, remain)) > 0) { - gint i = 0; + int i = 0; err_offset--; /* As it returns it 1 indexed */ p += err_offset; @@ -3610,13 +3610,13 @@ rspamd_str_make_utf_valid(const guchar *src, gsize slen, d += err_offset; /* Append 0xFFFD for each bad character */ - gint i = 0; + int i = 0; p += err_offset; remain -= err_offset; while (i < remain) { - gint old_i = i; + int old_i = i; U8_NEXT(p, i, remain, uc); if (uc < 0) { @@ -3655,9 +3655,9 @@ rspamd_str_make_utf_valid(const guchar *src, gsize slen, return dst; } -gsize rspamd_gstring_strip(GString *s, const gchar *strip_chars) +gsize rspamd_gstring_strip(GString *s, const char *strip_chars) { - const gchar *p, *sc; + const char *p, *sc; gsize strip_len = 0, total = 0; p = s->str + s->len - 1; @@ -3703,11 +3703,11 @@ gsize rspamd_gstring_strip(GString *s, const gchar *strip_chars) return total; } -const gchar *rspamd_string_len_strip(const gchar *in, - gsize *len, - const gchar *strip_chars) +const char *rspamd_string_len_strip(const char *in, + gsize *len, + const char *strip_chars) { - const gchar *p, *sc; + const char *p, *sc; gsize strip_len = 0, old_len = *len; p = in + old_len - 1; @@ -3755,13 +3755,13 @@ const gchar *rspamd_string_len_strip(const gchar *in, return in; } -gchar ** -rspamd_string_len_split(const gchar *in, gsize len, const gchar *spill, - gint max_elts, rspamd_mempool_t *pool) +char ** +rspamd_string_len_split(const char *in, gsize len, const char *spill, + int max_elts, rspamd_mempool_t *pool) { - const gchar *p = in, *end = in + len; + const char *p = in, *end = in + len; gsize detected_elts = 0; - gchar **res; + char **res; /* Detect number of elements */ while (p < end) { @@ -3780,7 +3780,7 @@ rspamd_string_len_split(const gchar *in, gsize len, const gchar *spill, p += rspamd_memspn(p, spill, end - p); } - res = pool ? rspamd_mempool_alloc(pool, sizeof(gchar *) * (detected_elts + 1)) : g_malloc(sizeof(gchar *) * (detected_elts + 1)); + res = pool ? rspamd_mempool_alloc(pool, sizeof(char *) * (detected_elts + 1)) : g_malloc(sizeof(char *) * (detected_elts + 1)); /* Last one */ res[detected_elts] = NULL; detected_elts = 0; @@ -3790,7 +3790,7 @@ rspamd_string_len_split(const gchar *in, gsize len, const gchar *spill, gsize cur_fragment = rspamd_memcspn(p, spill, end - p); if (cur_fragment > 0) { - gchar *elt; + char *elt; elt = pool ? rspamd_mempool_alloc(pool, cur_fragment + 1) : g_malloc(cur_fragment + 1); @@ -3816,12 +3816,12 @@ rspamd_string_len_split(const gchar *in, gsize len, const gchar *spill, #endif static inline gboolean -rspamd_str_has_8bit_u64(const guchar *beg, gsize len) +rspamd_str_has_8bit_u64(const unsigned char *beg, gsize len) { - guint8 orb = 0; + uint8_t orb = 0; if (len >= 16) { - const guchar *nextd = beg + sizeof(uint64_t); + const unsigned char *nextd = beg + sizeof(uint64_t); uint64_t n1 = 0, n2 = 0; do { @@ -3851,7 +3851,7 @@ rspamd_str_has_8bit_u64(const guchar *beg, gsize len) } gboolean -rspamd_str_has_8bit(const guchar *beg, gsize len) +rspamd_str_has_8bit(const unsigned char *beg, gsize len) { #if defined(__x86_64__) if (len >= 32) { diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h index ff5827a0b..a7252f3bf 100644 --- a/src/libutil/str_util.h +++ b/src/libutil/str_util.h @@ -36,12 +36,12 @@ enum rspamd_newlines_type { /** * Compare two memory regions of size `l` using case insensitive matching */ -gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l); +int rspamd_lc_cmp(const char *s, const char *d, gsize l); /** * Convert string to lowercase in-place using ASCII conversion */ -guint rspamd_str_lc(gchar *str, guint size); +unsigned int rspamd_str_lc(char *str, unsigned int size); /** * Performs ascii copy & lowercase @@ -49,26 +49,26 @@ guint rspamd_str_lc(gchar *str, guint size); * @param size * @return */ -gsize rspamd_str_copy_lc(const gchar *src, gchar *dst, gsize size); +gsize rspamd_str_copy_lc(const char *src, char *dst, gsize size); /** * Convert string to lowercase in-place using utf (limited) conversion */ -guint rspamd_str_lc_utf8(gchar *str, guint size); +unsigned int rspamd_str_lc_utf8(char *str, unsigned int size); /* * Hash table utility functions for case insensitive hashing */ -uint64_t rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed); +uint64_t rspamd_icase_hash(const char *in, gsize len, uint64_t seed); -guint rspamd_strcase_hash(gconstpointer key); +unsigned int rspamd_strcase_hash(gconstpointer key); gboolean rspamd_strcase_equal(gconstpointer v, gconstpointer v2); /* * Hash table utility functions for case sensitive hashing */ -guint rspamd_str_hash(gconstpointer key); +unsigned int rspamd_str_hash(gconstpointer key); gboolean rspamd_str_equal(gconstpointer v, gconstpointer v2); @@ -76,7 +76,7 @@ gboolean rspamd_str_equal(gconstpointer v, gconstpointer v2); /* * Hash table utility functions for hashing fixed strings */ -guint rspamd_ftok_icase_hash(gconstpointer key); +unsigned int rspamd_ftok_icase_hash(gconstpointer key); gboolean rspamd_ftok_icase_equal(gconstpointer v, gconstpointer v2); @@ -84,7 +84,7 @@ gboolean rspamd_ftok_icase_equal(gconstpointer v, gconstpointer v2); #define rspamd_ftok_hash(key) _wyhash32((key)->begin, (key)->len, 0) #define rspamd_ftok_equal(v1, v2) ((v1)->len == (v2)->len && memcmp((v1)->begin, (v2)->begin, (v1)->len) == 0) -guint rspamd_gstring_icase_hash(gconstpointer key); +unsigned int rspamd_gstring_icase_hash(gconstpointer key); gboolean rspamd_gstring_icase_equal(gconstpointer v, gconstpointer v2); @@ -98,9 +98,9 @@ gboolean rspamd_gstring_icase_equal(gconstpointer v, gconstpointer v2); * @param siz length of destination buffer * @return bytes copied */ -gsize rspamd_strlcpy_fast(gchar *dst, const gchar *src, gsize siz); +gsize rspamd_strlcpy_fast(char *dst, const char *src, gsize siz); -gsize rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz); +gsize rspamd_strlcpy_safe(char *dst, const char *src, gsize siz); #if defined(__has_feature) #if __has_feature(address_sanitizer) @@ -128,24 +128,24 @@ gsize rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz); * @param destlen * @return number of bytes copied */ -gsize rspamd_null_safe_copy(const gchar *src, gsize srclen, - gchar *dest, gsize destlen); +gsize rspamd_null_safe_copy(const char *src, gsize srclen, + char *dest, gsize destlen); /* * Try to convert string of length to long */ -gboolean rspamd_strtol(const gchar *s, gsize len, glong *value); +gboolean rspamd_strtol(const char *s, gsize len, glong *value); /* * Try to convert a string of length to unsigned long */ -gboolean rspamd_strtoul(const gchar *s, gsize len, gulong *value); -gboolean rspamd_strtou64(const gchar *s, gsize len, uint64_t *value); +gboolean rspamd_strtoul(const char *s, gsize len, gulong *value); +gboolean rspamd_strtou64(const char *s, gsize len, uint64_t *value); /* * Try to convert a hex string of length to unsigned long */ -gboolean rspamd_xstrtoul(const gchar *s, gsize len, gulong *value); +gboolean rspamd_xstrtoul(const char *s, gsize len, gulong *value); /** * Utility function to provide mem_pool copy for rspamd_hash_table_copy function @@ -161,7 +161,7 @@ gpointer rspamd_str_pool_copy(gconstpointer data, gpointer ud); * @param inlen input length * @return freshly allocated base32 encoding of a specified string */ -gchar *rspamd_encode_hex(const guchar *in, gsize inlen); +char *rspamd_encode_hex(const unsigned char *in, gsize inlen); /** * Decode string using hex encoding @@ -169,7 +169,7 @@ gchar *rspamd_encode_hex(const guchar *in, gsize inlen); * @param inlen input length * @return freshly allocated base32 decoded value or NULL if input is invalid */ -guchar *rspamd_decode_hex(const gchar *in, gsize inlen); +unsigned char *rspamd_decode_hex(const char *in, gsize inlen); enum rspamd_base32_type { RSPAMD_BASE32_DEFAULT = 0, @@ -184,7 +184,7 @@ enum rspamd_base32_type { * @param str * @return */ -enum rspamd_base32_type rspamd_base32_decode_type_from_str(const gchar *str); +enum rspamd_base32_type rspamd_base32_decode_type_from_str(const char *str); /** * Encode string using base32 encoding @@ -192,8 +192,8 @@ enum rspamd_base32_type rspamd_base32_decode_type_from_str(const gchar *str); * @param inlen input length * @return freshly allocated base32 encoding of a specified string */ -gchar *rspamd_encode_base32(const guchar *in, gsize inlen, - enum rspamd_base32_type type); +char *rspamd_encode_base32(const unsigned char *in, gsize inlen, + enum rspamd_base32_type type); /** * Decode string using base32 encoding @@ -201,7 +201,7 @@ gchar *rspamd_encode_base32(const guchar *in, gsize inlen, * @param inlen input length * @return freshly allocated base32 decoded value or NULL if input is invalid */ -guchar *rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen, enum rspamd_base32_type type); +unsigned char *rspamd_decode_base32(const char *in, gsize inlen, gsize *outlen, enum rspamd_base32_type type); /** * Encode string using base32 encoding @@ -211,8 +211,8 @@ guchar *rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen, enum r * @param outlen output buf len * @return encoded len if `outlen` is enough to encode `inlen` */ -gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out, - gsize outlen, enum rspamd_base32_type type); +int rspamd_encode_base32_buf(const unsigned char *in, gsize inlen, char *out, + gsize outlen, enum rspamd_base32_type type); /** * Decode string using base32 encoding @@ -222,8 +222,8 @@ gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out, * @param outlen output buf len * @return decoded len if in is valid base32 and `outlen` is enough to encode `inlen` */ -gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, - gsize outlen, enum rspamd_base32_type type); +int rspamd_decode_base32_buf(const char *in, gsize inlen, unsigned char *out, + gsize outlen, enum rspamd_base32_type type); /** * Encode string using hex encoding @@ -233,8 +233,8 @@ gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, * @param outlen output buf len * @return encoded len if `outlen` is enough to encode `inlen` */ -gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out, - gsize outlen); +int rspamd_encode_hex_buf(const unsigned char *in, gsize inlen, char *out, + gsize outlen); /** @@ -245,8 +245,8 @@ gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out, * @param outlen output buf len * @return decoded len if in is valid hex and `outlen` is enough to encode `inlen` */ -gssize rspamd_decode_hex_buf(const gchar *in, gsize inlen, - guchar *out, gsize outlen); +gssize rspamd_decode_hex_buf(const char *in, gsize inlen, + unsigned char *out, gsize outlen); /** * Common version of base64 encoder @@ -258,10 +258,10 @@ gssize rspamd_decode_hex_buf(const gchar *in, gsize inlen, * @param how * @return */ -gchar * -rspamd_encode_base64_common(const guchar *in, +char * +rspamd_encode_base64_common(const unsigned char *in, gsize inlen, - gint str_len, + int str_len, gsize *outlen, gboolean fold, enum rspamd_newlines_type how); @@ -273,8 +273,8 @@ rspamd_encode_base64_common(const guchar *in, * @param str_len maximum string length (if <= 0 then no lines are split) * @return freshly allocated base64 encoded value or NULL if input is invalid */ -gchar *rspamd_encode_base64(const guchar *in, gsize inlen, gint str_len, - gsize *outlen); +char *rspamd_encode_base64(const unsigned char *in, gsize inlen, int str_len, + gsize *outlen); /** * Encode and fold string using base64 encoding @@ -283,8 +283,8 @@ gchar *rspamd_encode_base64(const guchar *in, gsize inlen, gint str_len, * @param str_len maximum string length (if <= 0 then no lines are split) * @return freshly allocated base64 encoded value or NULL if input is invalid */ -gchar *rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len, - gsize *outlen, enum rspamd_newlines_type how); +char *rspamd_encode_base64_fold(const unsigned char *in, gsize inlen, int str_len, + gsize *outlen, enum rspamd_newlines_type how); /** * Encode and fold string using quoted printable encoding @@ -293,8 +293,8 @@ gchar *rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len, * @param str_len maximum string length (if <= 0 then no lines are split) * @return freshly allocated base64 encoded value or NULL if input is invalid */ -gchar *rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len, - gsize *outlen, enum rspamd_newlines_type how); +char *rspamd_encode_qp_fold(const unsigned char *in, gsize inlen, int str_len, + gsize *outlen, enum rspamd_newlines_type how); /** * Decode quoted-printable encoded buffer, input and output must not overlap @@ -304,8 +304,8 @@ gchar *rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len, * @param outlen length of output * @return real size of decoded output or (-1) if outlen is not enough */ -gssize rspamd_decode_qp_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen); +gssize rspamd_decode_qp_buf(const char *in, gsize inlen, + char *out, gsize outlen); /** * Decode uuencode encoded buffer, input and output must not overlap @@ -315,8 +315,8 @@ gssize rspamd_decode_qp_buf(const gchar *in, gsize inlen, * @param outlen length of output * @return real size of decoded output or (-1) if outlen is not enough */ -gssize rspamd_decode_uue_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen); +gssize rspamd_decode_uue_buf(const char *in, gsize inlen, + char *out, gsize outlen); /** * Decode quoted-printable encoded buffer using rfc2047 format, input and output must not overlap @@ -326,8 +326,8 @@ gssize rspamd_decode_uue_buf(const gchar *in, gsize inlen, * @param outlen length of output * @return real size of decoded output or (-1) if outlen is not enough */ -gssize rspamd_decode_qp2047_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen); +gssize rspamd_decode_qp2047_buf(const char *in, gsize inlen, + char *out, gsize outlen); /** * Encode quoted-printable buffer using rfc2047 format, input and output must not overlap @@ -337,8 +337,8 @@ gssize rspamd_decode_qp2047_buf(const gchar *in, gsize inlen, * @param outlen * @return */ -gssize rspamd_encode_qp2047_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen); +gssize rspamd_encode_qp2047_buf(const char *in, gsize inlen, + char *out, gsize outlen); #ifndef g_tolower #define g_tolower(x) (((x) >= 'A' && (x) <= 'Z') ? (x) - 'A' + 'a' : (x)) @@ -352,8 +352,8 @@ gssize rspamd_encode_qp2047_buf(const gchar *in, gsize inlen, * @param s2len * @return */ -gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len, - const gchar *s2, gsize s2len, guint replace_cost); +int rspamd_strings_levenshtein_distance(const char *s1, gsize s1len, + const char *s2, gsize s2len, unsigned int replace_cost); /** * Fold header using rfc822 rules, return new GString from the previous one @@ -364,13 +364,13 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len, * @param fold_on_chars * @return new GString with the folded value */ -GString *rspamd_header_value_fold(const gchar *name, +GString *rspamd_header_value_fold(const char *name, gsize name_len, - const gchar *value, + const char *value, gsize value_len, - guint fold_max, + unsigned int fold_max, enum rspamd_newlines_type how, - const gchar *fold_on_chars); + const char *fold_on_chars); /** * Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm @@ -381,8 +381,8 @@ GString *rspamd_header_value_fold(const gchar *name, * @param srchlen length of the search string * @return position of the first substring match or (-1) if not found */ -goffset rspamd_substring_search(const gchar *in, gsize inlen, - const gchar *srch, gsize srchlen); +goffset rspamd_substring_search(const char *in, gsize inlen, + const char *srch, gsize srchlen); /** * Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm in caseless matter (ASCII only) @@ -393,8 +393,8 @@ goffset rspamd_substring_search(const gchar *in, gsize inlen, * @param srchlen length of the search string * @return position of the first substring match or (-1) if not found */ -goffset rspamd_substring_search_caseless(const gchar *in, gsize inlen, - const gchar *srch, gsize srchlen); +goffset rspamd_substring_search_caseless(const char *in, gsize inlen, + const char *srch, gsize srchlen); /** * Search for end-of-headers mark in the input string. Returns position just after @@ -435,7 +435,7 @@ void rspamd_ucl_emit_fstring_comments(const ucl_object_t *obj, rspamd_fstring_t **target, const ucl_object_t *comments); -extern const guchar lc_map[256]; +extern const unsigned char lc_map[256]; /** * Search for the last occurrence of character `c` in memory block of size `len` @@ -447,7 +447,7 @@ extern const guchar lc_map[256]; #ifdef HAVE_MEMRCHR #define rspamd_memrchr memrchr #else -void *rspamd_memrchr(const void *m, gint c, gsize len); +void *rspamd_memrchr(const void *m, int c, gsize len); #endif /** @@ -457,7 +457,7 @@ void *rspamd_memrchr(const void *m, gint c, gsize len); * @param len length of `s` * @return segment size */ -gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len); +gsize rspamd_memcspn(const char *s, const char *e, gsize len); /** * Return length of memory segment starting in `s` that contains only chars from `e` @@ -466,7 +466,7 @@ gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len); * @param len length of `s` * @return segment size */ -gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len); +gsize rspamd_memspn(const char *s, const char *e, gsize len); /* https://graphics.stanford.edu/~seander/bithacks.html#HasMoreInWord */ #define rspamd_str_hasmore(x, n) ((((x) + ~0UL / 255 * (127 - (n))) | (x)) & ~0UL / 255 * 128) @@ -475,7 +475,7 @@ gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len); */ #define rspamd_is_aligned(p, n) (((uintptr_t) (p) & ((uintptr_t) (n) -1)) == 0) #define rspamd_is_aligned_as(p, v) rspamd_is_aligned(p, RSPAMD_ALIGNOF(__typeof((v)))) -gboolean rspamd_str_has_8bit(const guchar *beg, gsize len); +gboolean rspamd_str_has_8bit(const unsigned char *beg, gsize len); struct UConverter; @@ -501,8 +501,8 @@ enum rspamd_regexp_escape_flags { * @param allow_glob allow glob expressions to be translated into pcre * @return newly allocated zero terminated escaped pattern */ -gchar * -rspamd_str_regexp_escape(const gchar *pattern, gsize slen, +char * +rspamd_str_regexp_escape(const char *pattern, gsize slen, gsize *dst_len, enum rspamd_regexp_escape_flags flags) G_GNUC_WARN_UNUSED_RESULT; /** @@ -513,23 +513,23 @@ rspamd_str_regexp_escape(const gchar *pattern, gsize slen, * @param dstelen * @return */ -gchar *rspamd_str_make_utf_valid(const guchar *src, gsize slen, gsize *dstlen, - rspamd_mempool_t *pool) G_GNUC_WARN_UNUSED_RESULT; +char *rspamd_str_make_utf_valid(const unsigned char *src, gsize slen, gsize *dstlen, + rspamd_mempool_t *pool) G_GNUC_WARN_UNUSED_RESULT; /** * Strips characters in `strip_chars` from start and end of the GString * @param s * @param strip_chars */ -gsize rspamd_gstring_strip(GString *s, const gchar *strip_chars); +gsize rspamd_gstring_strip(GString *s, const char *strip_chars); /** * Strips characters in `strip_chars` from start and end of the sized string * @param s * @param strip_chars */ -const gchar *rspamd_string_len_strip(const gchar *in, - gsize *len, const gchar *strip_chars) G_GNUC_WARN_UNUSED_RESULT; +const char *rspamd_string_len_strip(const char *in, + gsize *len, const char *strip_chars) G_GNUC_WARN_UNUSED_RESULT; /** * Returns a NULL terminated list of zero terminated strings based on splitting of @@ -542,8 +542,8 @@ const gchar *rspamd_string_len_strip(const gchar *in, * @param max_elts * @return */ -gchar **rspamd_string_len_split(const gchar *in, gsize len, - const gchar *spill, gint max_elts, rspamd_mempool_t *pool); +char **rspamd_string_len_split(const char *in, gsize len, + const char *spill, int max_elts, rspamd_mempool_t *pool); #define IS_ZERO_WIDTH_SPACE(uc) ((uc) == 0x200B || \ (uc) == 0x200C || \ diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index a004a298b..300f907a7 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -31,14 +31,14 @@ struct upstream_inet_addr_entry { rspamd_inet_addr_t *addr; - guint priority; + unsigned int priority; struct upstream_inet_addr_entry *next; }; struct upstream_addr_elt { rspamd_inet_addr_t *addr; - guint priority; - guint errors; + unsigned int priority; + unsigned int errors; }; struct upstream_list_watcher { @@ -50,17 +50,17 @@ struct upstream_list_watcher { }; struct upstream { - guint weight; - guint cur_weight; - guint errors; - guint checked; - guint dns_requests; - gint active_idx; - guint ttl; - gchar *name; + unsigned int weight; + unsigned int cur_weight; + unsigned int errors; + unsigned int checked; + unsigned int dns_requests; + int active_idx; + unsigned int ttl; + char *name; ev_timer ev; - gdouble last_fail; - gdouble last_resolve; + double last_fail; + double last_resolve; gpointer ud; enum rspamd_upstream_flag flags; struct upstream_list *ls; @@ -69,12 +69,12 @@ struct upstream { struct { GPtrArray *addr; /* struct upstream_addr_elt */ - guint cur; + unsigned int cur; } addrs; struct upstream_inet_addr_entry *new_addrs; gpointer data; - gchar uid[8]; + char uid[8]; ref_entry_t ref; #ifdef UPSTREAMS_THREAD_SAFE rspamd_mutex_t *lock; @@ -82,17 +82,17 @@ struct upstream { }; struct upstream_limits { - gdouble revive_time; - gdouble revive_jitter; - gdouble error_time; - gdouble dns_timeout; - gdouble lazy_resolve_time; - guint max_errors; - guint dns_retransmits; + double revive_time; + double revive_jitter; + double error_time; + double dns_timeout; + double lazy_resolve_time; + unsigned int max_errors; + unsigned int dns_retransmits; }; struct upstream_list { - gchar *ups_line; + char *ups_line; struct upstream_ctx *ctx; GPtrArray *ups; GPtrArray *alive; @@ -100,7 +100,7 @@ struct upstream_list { uint64_t hash_seed; const struct upstream_limits *limits; enum rspamd_upstream_flag flags; - guint cur_elt; + unsigned int cur_elt; enum rspamd_upstream_rotation rot_alg; #ifdef UPSTREAMS_THREAD_SAFE rspamd_mutex_t *lock; @@ -146,20 +146,20 @@ INIT_LOG_MODULE(upstream) /* 4 errors in 10 seconds */ #define DEFAULT_MAX_ERRORS 4 -static const guint default_max_errors = DEFAULT_MAX_ERRORS; +static const unsigned int default_max_errors = DEFAULT_MAX_ERRORS; #define DEFAULT_REVIVE_TIME 60 -static const gdouble default_revive_time = DEFAULT_REVIVE_TIME; +static const double default_revive_time = DEFAULT_REVIVE_TIME; #define DEFAULT_REVIVE_JITTER 0.4 -static const gdouble default_revive_jitter = DEFAULT_REVIVE_JITTER; +static const double default_revive_jitter = DEFAULT_REVIVE_JITTER; #define DEFAULT_ERROR_TIME 10 -static const gdouble default_error_time = DEFAULT_ERROR_TIME; +static const double default_error_time = DEFAULT_ERROR_TIME; #define DEFAULT_DNS_TIMEOUT 1.0 -static const gdouble default_dns_timeout = DEFAULT_DNS_TIMEOUT; +static const double default_dns_timeout = DEFAULT_DNS_TIMEOUT; #define DEFAULT_DNS_RETRANSMITS 2 -static const guint default_dns_retransmits = DEFAULT_DNS_RETRANSMITS; +static const unsigned int default_dns_retransmits = DEFAULT_DNS_RETRANSMITS; /* TODO: make it configurable */ #define DEFAULT_LAZY_RESOLVE_TIME 3600.0 -static const gdouble default_lazy_resolve_time = DEFAULT_LAZY_RESOLVE_TIME; +static const double default_lazy_resolve_time = DEFAULT_LAZY_RESOLVE_TIME; static const struct upstream_limits default_limits = { .revive_time = DEFAULT_REVIVE_TIME, @@ -215,7 +215,7 @@ void rspamd_upstreams_library_config(struct rspamd_config *cfg, upstream = cur->data; if (!ev_can_stop(&upstream->ev) && upstream->ls && !(upstream->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) { - gdouble when; + double when; if (upstream->flags & RSPAMD_UPSTREAM_FLAG_SRV_RESOLVE) { /* Resolve them immediately ! */ @@ -278,7 +278,7 @@ rspamd_upstreams_library_init(void) return ctx; } -static gint +static int rspamd_upstream_af_to_weight(const rspamd_inet_addr_t *addr) { int ret; @@ -301,12 +301,12 @@ rspamd_upstream_af_to_weight(const rspamd_inet_addr_t *addr) /* * Select IPv4 addresses before IPv6 */ -static gint +static int rspamd_upstream_addr_sort_func(gconstpointer a, gconstpointer b) { const struct upstream_addr_elt *ip1 = *(const struct upstream_addr_elt **) a, *ip2 = *(const struct upstream_addr_elt **) b; - gint w1, w2; + int w1, w2; if (ip1->priority == 0 && ip2->priority == 0) { w1 = rspamd_upstream_af_to_weight(ip1->addr); @@ -336,7 +336,7 @@ rspamd_upstream_set_active(struct upstream_list *ls, struct upstream *upstream) } /* Start lazy (or not so lazy) names resolution */ - gdouble when; + double when; if (upstream->flags & RSPAMD_UPSTREAM_FLAG_SRV_RESOLVE) { /* Resolve them immediately ! */ @@ -371,7 +371,7 @@ rspamd_upstream_addr_elt_dtor(gpointer a) static void rspamd_upstream_update_addrs(struct upstream *upstream) { - guint addr_cnt, i, port; + unsigned int addr_cnt, i, port; gboolean seen_addr, reset_errors = FALSE; struct upstream_inet_addr_entry *cur, *tmp; GPtrArray *new_addrs; @@ -500,9 +500,9 @@ rspamd_upstream_dns_cb(struct rdns_reply *reply, void *arg) struct rspamd_upstream_srv_dns_cb { struct upstream *up; - guint priority; - guint port; - guint requests_inflight; + unsigned int priority; + unsigned int port; + unsigned int requests_inflight; }; /* Used when we have resolved SRV record and resolved addrs */ @@ -642,14 +642,14 @@ rspamd_upstream_resolve_addrs(const struct upstream_list *ls, struct upstream *upstream) { /* XXX: maybe make it configurable */ - static const gdouble min_resolve_interval = 60.0; + static const double min_resolve_interval = 60.0; if (upstream->ctx->res != NULL && upstream->ctx->configured && upstream->dns_requests == 0 && !(upstream->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) { - gdouble now = ev_now(upstream->ctx->event_loop); + double now = ev_now(upstream->ctx->event_loop); if (now - upstream->last_resolve < min_resolve_interval) { msg_info_upstream("do not resolve upstream %s as it was checked %.0f " @@ -751,8 +751,8 @@ rspamd_upstream_lazy_resolve_cb(struct ev_loop *loop, ev_timer *w, int revents) static void rspamd_upstream_set_inactive(struct upstream_list *ls, struct upstream *upstream) { - gdouble ntim; - guint i; + double ntim; + unsigned int i; struct upstream *cur; struct upstream_list_watcher *w; @@ -799,10 +799,10 @@ rspamd_upstream_set_inactive(struct upstream_list *ls, struct upstream *upstream void rspamd_upstream_fail(struct upstream *upstream, gboolean addr_failure, - const gchar *reason) + const char *reason) { - gdouble error_rate = 0, max_error_rate = 0; - gdouble sec_last, sec_cur; + double error_rate = 0, max_error_rate = 0; + double sec_last, sec_cur; struct upstream_addr_elt *addr_elt; struct upstream_list_watcher *w; @@ -847,8 +847,8 @@ void rspamd_upstream_fail(struct upstream *upstream, } if (sec_cur - sec_last >= upstream->ls->limits->error_time) { - error_rate = ((gdouble) upstream->errors) / (sec_cur - sec_last); - max_error_rate = ((gdouble) upstream->ls->limits->max_errors) / + error_rate = ((double) upstream->errors) / (sec_cur - sec_last); + max_error_rate = ((double) upstream->ls->limits->max_errors) / upstream->ls->limits->error_time; } @@ -942,7 +942,7 @@ void rspamd_upstream_ok(struct upstream *upstream) RSPAMD_UPSTREAM_UNLOCK(upstream); } -void rspamd_upstream_set_weight(struct upstream *up, guint weight) +void rspamd_upstream_set_weight(struct upstream *up, unsigned int weight) { RSPAMD_UPSTREAM_LOCK(up); up->weight = weight; @@ -1026,7 +1026,7 @@ rspamd_upstream_dtor(struct upstream *up) rspamd_inet_addr_t * rspamd_upstream_addr_next(struct upstream *up) { - guint idx, next_idx; + unsigned int idx, next_idx; struct upstream_addr_elt *e1, *e2; do { @@ -1050,13 +1050,13 @@ rspamd_upstream_addr_cur(const struct upstream *up) return elt->addr; } -const gchar * +const char * rspamd_upstream_name(struct upstream *up) { return up->name; } -gint rspamd_upstream_port(struct upstream *up) +int rspamd_upstream_port(struct upstream *up) { struct upstream_addr_elt *elt; @@ -1065,13 +1065,13 @@ gint rspamd_upstream_port(struct upstream *up) } gboolean -rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str, - guint16 def_port, enum rspamd_upstream_parse_type parse_type, +rspamd_upstreams_add_upstream(struct upstream_list *ups, const char *str, + uint16_t def_port, enum rspamd_upstream_parse_type parse_type, void *data) { struct upstream *upstream; GPtrArray *addrs = NULL; - guint i, slen; + unsigned int i, slen; rspamd_inet_addr_t *addr; enum rspamd_parse_host_port_result ret = RSPAMD_PARSE_ADDR_FAIL; @@ -1082,7 +1082,7 @@ rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str, case RSPAMD_UPSTREAM_PARSE_DEFAULT: if (slen > sizeof("service=") && RSPAMD_LEN_CHECK_STARTS_WITH(str, slen, "service=")) { - const gchar *plus_pos, *service_pos, *semicolon_pos; + const char *plus_pos, *service_pos, *semicolon_pos; /* Accept service=srv_name+hostname[:priority] */ service_pos = str + sizeof("service=") - 1; @@ -1103,17 +1103,17 @@ rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str, * where is string between semicolon_pos and plus_pos +1 * while service is a string between service_pos and plus_pos */ - guint namelen = (semicolon_pos - (plus_pos + 1)) + - (plus_pos - service_pos) + - (sizeof("tcp") - 1) + - 4; + unsigned int namelen = (semicolon_pos - (plus_pos + 1)) + + (plus_pos - service_pos) + + (sizeof("tcp") - 1) + + 4; addrs = g_ptr_array_sized_new(1); upstream->name = ups->ctx ? rspamd_mempool_alloc(ups->ctx->pool, namelen + 1) : g_malloc(namelen + 1); rspamd_snprintf(upstream->name, namelen + 1, "_%*s._tcp.%*s", - (gint) (plus_pos - service_pos), service_pos, - (gint) (semicolon_pos - (plus_pos + 1)), plus_pos + 1); + (int) (plus_pos - service_pos), service_pos, + (int) (semicolon_pos - (plus_pos + 1)), plus_pos + 1); upstream->flags |= RSPAMD_UPSTREAM_FLAG_SRV_RESOLVE; ret = RSPAMD_PARSE_ADDR_RESOLVED; } @@ -1200,10 +1200,10 @@ rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str, upstream->ctx_pos = g_queue_peek_tail_link(ups->ctx->upstreams); } - guint h = rspamd_cryptobox_fast_hash(upstream->name, - strlen(upstream->name), 0); + unsigned int h = rspamd_cryptobox_fast_hash(upstream->name, + strlen(upstream->name), 0); memset(upstream->uid, 0, sizeof(upstream->uid)); - rspamd_encode_base32_buf((const guchar *) &h, sizeof(h), + rspamd_encode_base32_buf((const unsigned char *) &h, sizeof(h), upstream->uid, sizeof(upstream->uid) - 1, RSPAMD_BASE32_DEFAULT); msg_debug_upstream("added upstream %s (%s)", upstream->name, @@ -1247,12 +1247,12 @@ rspamd_upstream_add_addr(struct upstream *up, rspamd_inet_addr_t *addr) gboolean rspamd_upstreams_parse_line_len(struct upstream_list *ups, - const gchar *str, gsize len, guint16 def_port, void *data) + const char *str, gsize len, uint16_t def_port, void *data) { - const gchar *end = str + len, *p = str; - const gchar *separators = ";, \n\r\t"; - gchar *tmp; - guint span_len; + const char *end = str + len, *p = str; + const char *separators = ";, \n\r\t"; + char *tmp; + unsigned int span_len; gboolean ret = FALSE; if (RSPAMD_LEN_CHECK_STARTS_WITH(p, len, "random:")) { @@ -1306,7 +1306,7 @@ rspamd_upstreams_parse_line_len(struct upstream_list *ups, gboolean rspamd_upstreams_parse_line(struct upstream_list *ups, - const gchar *str, guint16 def_port, void *data) + const char *str, uint16_t def_port, void *data) { return rspamd_upstreams_parse_line_len(ups, str, strlen(str), def_port, data); @@ -1314,7 +1314,7 @@ rspamd_upstreams_parse_line(struct upstream_list *ups, gboolean rspamd_upstreams_from_ucl(struct upstream_list *ups, - const ucl_object_t *in, guint16 def_port, void *data) + const ucl_object_t *in, uint16_t def_port, void *data) { gboolean ret = FALSE; const ucl_object_t *cur; @@ -1336,7 +1336,7 @@ rspamd_upstreams_from_ucl(struct upstream_list *ups, void rspamd_upstreams_destroy(struct upstream_list *ups) { - guint i; + unsigned int i; struct upstream *up; struct upstream_list_watcher *w, *tmp; @@ -1401,7 +1401,7 @@ rspamd_upstream_get_random(struct upstream_list *ups, struct upstream *except) { for (;;) { - guint idx = ottery_rand_range(ups->alive->len - 1); + unsigned int idx = ottery_rand_range(ups->alive->len - 1); struct upstream *up; up = g_ptr_array_index(ups->alive, idx); @@ -1419,9 +1419,9 @@ rspamd_upstream_get_round_robin(struct upstream_list *ups, struct upstream *except, gboolean use_cur) { - guint max_weight = 0, min_checked = G_MAXUINT; + unsigned int max_weight = 0, min_checked = G_MAXUINT; struct upstream *up = NULL, *selected = NULL, *min_checked_sel = NULL; - guint i; + unsigned int i; /* Select upstream with the maximum cur_weight */ RSPAMD_UPSTREAM_LOCK(ups); @@ -1509,11 +1509,11 @@ rspamd_consistent_hash(uint64_t key, uint32_t nbuckets) static struct upstream * rspamd_upstream_get_hashed(struct upstream_list *ups, struct upstream *except, - const guint8 *key, guint keylen) + const uint8_t *key, unsigned int keylen) { uint64_t k; uint32_t idx; - static const guint max_tries = 20; + static const unsigned int max_tries = 20; struct upstream *up = NULL; /* Generate 64 bits input key */ @@ -1524,7 +1524,7 @@ rspamd_upstream_get_hashed(struct upstream_list *ups, /* * Select new upstream from all upstreams */ - for (guint i = 0; i < max_tries; i++) { + for (unsigned int i = 0; i < max_tries; i++) { idx = rspamd_consistent_hash(k, ups->ups->len); up = g_ptr_array_index(ups->ups, idx); @@ -1554,7 +1554,7 @@ static struct upstream * rspamd_upstream_get_common(struct upstream_list *ups, struct upstream *except, enum rspamd_upstream_rotation default_type, - const guchar *key, gsize keylen, + const unsigned char *key, gsize keylen, gboolean forced) { enum rspamd_upstream_rotation type; @@ -1622,7 +1622,7 @@ end: struct upstream * rspamd_upstream_get(struct upstream_list *ups, enum rspamd_upstream_rotation default_type, - const guchar *key, gsize keylen) + const unsigned char *key, gsize keylen) { return rspamd_upstream_get_common(ups, NULL, default_type, key, keylen, FALSE); } @@ -1630,7 +1630,7 @@ rspamd_upstream_get(struct upstream_list *ups, struct upstream * rspamd_upstream_get_forced(struct upstream_list *ups, enum rspamd_upstream_rotation forced_type, - const guchar *key, gsize keylen) + const unsigned char *key, gsize keylen) { return rspamd_upstream_get_common(ups, NULL, forced_type, key, keylen, TRUE); } @@ -1638,7 +1638,7 @@ rspamd_upstream_get_forced(struct upstream_list *ups, struct upstream *rspamd_upstream_get_except(struct upstream_list *ups, struct upstream *except, enum rspamd_upstream_rotation default_type, - const guchar *key, gsize keylen) + const unsigned char *key, gsize keylen) { return rspamd_upstream_get_common(ups, except, default_type, key, keylen, FALSE); } @@ -1679,7 +1679,7 @@ void rspamd_upstreams_foreach(struct upstream_list *ups, rspamd_upstream_traverse_func cb, void *ud) { struct upstream *up; - guint i; + unsigned int i; for (i = 0; i < ups->ups->len; i++) { up = g_ptr_array_index(ups->ups, i); @@ -1689,12 +1689,12 @@ void rspamd_upstreams_foreach(struct upstream_list *ups, } void rspamd_upstreams_set_limits(struct upstream_list *ups, - gdouble revive_time, - gdouble revive_jitter, - gdouble error_time, - gdouble dns_timeout, - guint max_errors, - guint dns_retransmits) + double revive_time, + double revive_jitter, + double error_time, + double dns_timeout, + unsigned int max_errors, + unsigned int dns_retransmits) { struct upstream_limits *nlimits; g_assert(ups != NULL); diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h index 22a020c9c..60c658a6f 100644 --- a/src/libutil/upstream.h +++ b/src/libutil/upstream.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 Vsevolod Stakhov + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,7 +79,7 @@ void rspamd_upstreams_library_config(struct rspamd_config *cfg, /** * Add an error to an upstream */ -void rspamd_upstream_fail(struct upstream *upstream, gboolean addr_failure, const gchar *reason); +void rspamd_upstream_fail(struct upstream *upstream, gboolean addr_failure, const char *reason); /** * Increase upstream successes count @@ -90,7 +90,7 @@ void rspamd_upstream_ok(struct upstream *up); * Set weight for an upstream * @param up */ -void rspamd_upstream_set_weight(struct upstream *up, guint weight); +void rspamd_upstream_set_weight(struct upstream *up, unsigned int weight); /** * Create new list of upstreams @@ -119,12 +119,12 @@ void rspamd_upstreams_set_flags(struct upstream_list *ups, * @param dns_retransmits */ void rspamd_upstreams_set_limits(struct upstream_list *ups, - gdouble revive_time, - gdouble revive_jitter, - gdouble error_time, - gdouble dns_timeout, - guint max_errors, - guint dns_retransmits); + double revive_time, + double revive_jitter, + double error_time, + double dns_timeout, + unsigned int max_errors, + unsigned int dns_retransmits); /** * Sets rotation policy for upstreams list @@ -167,8 +167,8 @@ enum rspamd_upstream_parse_type { * @param data optional userdata * @return TRUE if upstream has been added */ -gboolean rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str, - guint16 def_port, enum rspamd_upstream_parse_type parse_type, +gboolean rspamd_upstreams_add_upstream(struct upstream_list *ups, const char *str, + uint16_t def_port, enum rspamd_upstream_parse_type parse_type, void *data); /** @@ -180,12 +180,12 @@ gboolean rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *s * @return TRUE if **any** of upstreams has been added */ gboolean rspamd_upstreams_parse_line(struct upstream_list *ups, - const gchar *str, guint16 def_port, void *data); + const char *str, uint16_t def_port, void *data); gboolean rspamd_upstreams_parse_line_len(struct upstream_list *ups, - const gchar *str, gsize len, - guint16 def_port, + const char *str, gsize len, + uint16_t def_port, void *data); /** @@ -197,10 +197,10 @@ gboolean rspamd_upstreams_parse_line_len(struct upstream_list *ups, * @return */ gboolean rspamd_upstreams_from_ucl(struct upstream_list *ups, - const ucl_object_t *in, guint16 def_port, void *data); + const ucl_object_t *in, uint16_t def_port, void *data); -typedef void (*rspamd_upstream_traverse_func)(struct upstream *up, guint idx, +typedef void (*rspamd_upstream_traverse_func)(struct upstream *up, unsigned int idx, void *ud); /** @@ -222,7 +222,7 @@ enum rspamd_upstreams_watch_event { typedef void (*rspamd_upstream_watch_func)(struct upstream *up, enum rspamd_upstreams_watch_event event, - guint cur_errors, + unsigned int cur_errors, void *ud); /** @@ -265,14 +265,14 @@ gboolean rspamd_upstream_add_addr(struct upstream *up, * @param up * @return */ -const gchar *rspamd_upstream_name(struct upstream *up); +const char *rspamd_upstream_name(struct upstream *up); /** * Returns the port of the current address for the upstream * @param up * @return */ -gint rspamd_upstream_port(struct upstream *up); +int rspamd_upstream_port(struct upstream *up); /** * Sets opaque user data associated with this upstream @@ -297,7 +297,7 @@ gpointer rspamd_upstream_get_data(struct upstream *up); */ struct upstream *rspamd_upstream_get(struct upstream_list *ups, enum rspamd_upstream_rotation default_type, - const guchar *key, gsize keylen); + const unsigned char *key, gsize keylen); /** * Get new upstream from the list @@ -307,7 +307,7 @@ struct upstream *rspamd_upstream_get(struct upstream_list *ups, */ struct upstream *rspamd_upstream_get_forced(struct upstream_list *ups, enum rspamd_upstream_rotation forced_type, - const guchar *key, gsize keylen); + const unsigned char *key, gsize keylen); /** * Get new upstream from the list excepting the upstream specified @@ -318,7 +318,7 @@ struct upstream *rspamd_upstream_get_forced(struct upstream_list *ups, struct upstream *rspamd_upstream_get_except(struct upstream_list *ups, struct upstream *except, enum rspamd_upstream_rotation default_type, - const guchar *key, gsize keylen); + const unsigned char *key, gsize keylen); /** * Re-resolve addresses for all upstreams registered diff --git a/src/libutil/util.c b/src/libutil/util.c index 10aeebf45..b585a2690 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -94,9 +94,9 @@ const struct rspamd_controller_pbkdf pbkdf_list[] = { .salt_len = 20, .key_len = rspamd_cryptobox_HASHBYTES / 2}}; -gint rspamd_socket_nonblocking(gint fd) +int rspamd_socket_nonblocking(int fd) { - gint ofl; + int ofl; ofl = fcntl(fd, F_GETFL, 0); @@ -106,9 +106,9 @@ gint rspamd_socket_nonblocking(gint fd) return 0; } -gint rspamd_socket_blocking(gint fd) +int rspamd_socket_blocking(int fd) { - gint ofl; + int ofl; ofl = fcntl(fd, F_GETFL, 0); @@ -118,9 +118,9 @@ gint rspamd_socket_blocking(gint fd) return 0; } -gint rspamd_socket_poll(gint fd, gint timeout, short events) +int rspamd_socket_poll(int fd, int timeout, short events) { - gint r; + int r; struct pollfd fds[1]; fds->fd = fd; @@ -135,9 +135,9 @@ gint rspamd_socket_poll(gint fd, gint timeout, short events) return r; } -gint rspamd_socket_create(gint af, gint type, gint protocol, gboolean async) +int rspamd_socket_create(int af, int type, int protocol, gboolean async) { - gint fd; + int fd; fd = socket(af, type, protocol); if (fd == -1) { @@ -159,11 +159,11 @@ gint rspamd_socket_create(gint af, gint type, gint protocol, gboolean async) return fd; } -static gint -rspamd_inet_socket_create(gint type, struct addrinfo *addr, gboolean is_server, +static int +rspamd_inet_socket_create(int type, struct addrinfo *addr, gboolean is_server, gboolean async, GList **list) { - gint fd = -1, r, on = 1, s_error; + int fd = -1, r, on = 1, s_error; struct addrinfo *cur; gpointer ptr; socklen_t optlen; @@ -178,11 +178,11 @@ rspamd_inet_socket_create(gint type, struct addrinfo *addr, gboolean is_server, if (is_server) { (void) setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, - sizeof(gint)); + sizeof(int)); #ifdef HAVE_IPV6_V6ONLY if (cur->ai_family == AF_INET6) { setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *) &on, - sizeof(gint)); + sizeof(int)); } #endif r = bind(fd, cur->ai_addr, cur->ai_addrlen); @@ -242,25 +242,25 @@ rspamd_inet_socket_create(gint type, struct addrinfo *addr, gboolean is_server, return (fd); } -gint rspamd_socket_tcp(struct addrinfo *addr, gboolean is_server, gboolean async) +int rspamd_socket_tcp(struct addrinfo *addr, gboolean is_server, gboolean async) { return rspamd_inet_socket_create(SOCK_STREAM, addr, is_server, async, NULL); } -gint rspamd_socket_udp(struct addrinfo *addr, gboolean is_server, gboolean async) +int rspamd_socket_udp(struct addrinfo *addr, gboolean is_server, gboolean async) { return rspamd_inet_socket_create(SOCK_DGRAM, addr, is_server, async, NULL); } -gint rspamd_socket_unix(const gchar *path, - struct sockaddr_un *addr, - gint type, - gboolean is_server, - gboolean async) +int rspamd_socket_unix(const char *path, + struct sockaddr_un *addr, + int type, + gboolean is_server, + gboolean async) { socklen_t optlen; - gint fd = -1, s_error, r, serrno, on = 1; + int fd = -1, s_error, r, serrno, on = 1; struct stat st; if (path == NULL) @@ -302,7 +302,7 @@ gint rspamd_socket_unix(const gchar *path, } if (is_server) { (void) setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, - sizeof(gint)); + sizeof(int)); r = bind(fd, (struct sockaddr *) addr, SUN_LEN(addr)); } else { @@ -365,14 +365,14 @@ rspamd_prefer_v4_hack(const struct addrinfo *a1, const struct addrinfo *a2) * @param is_server make this socket as server socket * @param try_resolve try name resolution for a socket (BLOCKING) */ -gint rspamd_socket(const gchar *credits, guint16 port, - gint type, gboolean async, gboolean is_server, gboolean try_resolve) +int rspamd_socket(const char *credits, uint16_t port, + int type, gboolean async, gboolean is_server, gboolean try_resolve) { struct sockaddr_un un; struct stat st; struct addrinfo hints, *res; - gint r; - gchar portbuf[8]; + int r; + char portbuf[8]; if (*credits == '/') { if (is_server) { @@ -430,9 +430,9 @@ gint rspamd_socket(const gchar *credits, guint16 port, } gboolean -rspamd_socketpair(gint pair[2], gint af) +rspamd_socketpair(int pair[2], int af) { - gint r = -1, serrno; + int r = -1, serrno; #ifdef HAVE_SOCK_SEQPACKET if (af == SOCK_SEQPACKET) { @@ -471,11 +471,11 @@ out: } #ifdef HAVE_SA_SIGINFO -void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(gint, +void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(int, siginfo_t *, void *)) #else -void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(gint)) +void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(int)) #endif { struct sigaction sigpipe_act; @@ -530,10 +530,10 @@ void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(gint)) #ifndef HAVE_SETPROCTITLE #ifdef LINUX -static gchar *title_buffer = NULL; +static char *title_buffer = NULL; static size_t title_buffer_size = 0; -static gchar *title_progname, *title_progname_full; -gchar **old_environ = NULL; +static char *title_progname, *title_progname_full; +char **old_environ = NULL; static void rspamd_title_dtor(gpointer d) @@ -543,8 +543,8 @@ rspamd_title_dtor(gpointer d) environ = old_environ; } - gchar **env = (gchar **) d; - guint i; + char **env = (char **) d; + unsigned int i; for (i = 0; env[i] != NULL; i++) { g_free(env[i]); @@ -556,12 +556,12 @@ rspamd_title_dtor(gpointer d) #endif /* ifndef HAVE_SETPROCTITLE */ -gint rspamd_init_title(rspamd_mempool_t *pool, - gint argc, gchar *argv[], gchar *envp[]) +int rspamd_init_title(rspamd_mempool_t *pool, + int argc, char *argv[], char *envp[]) { #if defined(LINUX) && !defined(HAVE_SETPROCTITLE) - gchar *begin_of_buffer = 0, *end_of_buffer = 0; - gint i; + char *begin_of_buffer = 0, *end_of_buffer = 0; + int i; for (i = 0; i < argc; ++i) { if (!begin_of_buffer) { @@ -585,7 +585,7 @@ gint rspamd_init_title(rspamd_mempool_t *pool, return 0; } - gchar **new_environ = g_malloc((i + 1) * sizeof(envp[0])); + char **new_environ = g_malloc((i + 1) * sizeof(envp[0])); for (i = 0; envp[i]; ++i) { new_environ[i] = g_strdup(envp[i]); @@ -596,7 +596,7 @@ gint rspamd_init_title(rspamd_mempool_t *pool, if (program_invocation_name) { title_progname_full = g_strdup(program_invocation_name); - gchar *p = strrchr(title_progname_full, '/'); + char *p = strrchr(title_progname_full, '/'); if (p) { title_progname = p + 1; @@ -622,7 +622,7 @@ gint rspamd_init_title(rspamd_mempool_t *pool, return 0; } -gint rspamd_setproctitle(const gchar *fmt, ...) +int rspamd_setproctitle(const char *fmt, ...) { #ifdef HAVE_SETPROCTITLE if (fmt) { @@ -697,9 +697,9 @@ gint rspamd_setproctitle(const gchar *fmt, ...) #ifndef HAVE_PIDFILE -static gint _rspamd_pidfile_remove(rspamd_pidfh_t *pfh, gint freeit); +static int _rspamd_pidfile_remove(rspamd_pidfh_t *pfh, int freeit); -static gint +static int rspamd_pidfile_verify(rspamd_pidfh_t *pfh) { struct stat sb; @@ -716,11 +716,11 @@ rspamd_pidfile_verify(rspamd_pidfh_t *pfh) return 0; } -static gint -rspamd_pidfile_read(const gchar *path, pid_t *pidptr) +static int +rspamd_pidfile_read(const char *path, pid_t *pidptr) { - gchar buf[16], *endptr; - gint error, fd, i; + char buf[16], *endptr; + int error, fd, i; fd = open(path, O_RDONLY); if (fd == -1) @@ -743,11 +743,11 @@ rspamd_pidfile_read(const gchar *path, pid_t *pidptr) } rspamd_pidfh_t * -rspamd_pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr) +rspamd_pidfile_open(const char *path, mode_t mode, pid_t *pidptr) { rspamd_pidfh_t *pfh; struct stat sb; - gint error, fd, len, count; + int error, fd, len, count; struct timespec rqtp; pfh = g_malloc(sizeof(*pfh)); @@ -761,7 +761,7 @@ rspamd_pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr) g_get_prgname()); else len = snprintf(pfh->pf_path, sizeof(pfh->pf_path), "%s", path); - if (len >= (gint) sizeof(pfh->pf_path)) { + if (len >= (int) sizeof(pfh->pf_path)) { g_free(pfh); errno = ENAMETOOLONG; return NULL; @@ -814,10 +814,10 @@ rspamd_pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr) return pfh; } -gint rspamd_pidfile_write(rspamd_pidfh_t *pfh) +int rspamd_pidfile_write(rspamd_pidfh_t *pfh) { - gchar pidstr[16]; - gint error, fd; + char pidstr[16]; + int error, fd; /* * Check remembered descriptor, so we don't overwrite some other @@ -853,9 +853,9 @@ gint rspamd_pidfile_write(rspamd_pidfh_t *pfh) return 0; } -gint rspamd_pidfile_close(rspamd_pidfh_t *pfh) +int rspamd_pidfile_close(rspamd_pidfh_t *pfh) { - gint error; + int error; error = rspamd_pidfile_verify(pfh); if (error != 0) { @@ -873,10 +873,10 @@ gint rspamd_pidfile_close(rspamd_pidfh_t *pfh) return 0; } -static gint -_rspamd_pidfile_remove(rspamd_pidfh_t *pfh, gint freeit) +static int +_rspamd_pidfile_remove(rspamd_pidfh_t *pfh, int freeit) { - gint error; + int error; error = rspamd_pidfile_verify(pfh); if (error != 0) { @@ -905,7 +905,7 @@ _rspamd_pidfile_remove(rspamd_pidfh_t *pfh, gint freeit) return 0; } -gint rspamd_pidfile_remove(rspamd_pidfh_t *pfh) +int rspamd_pidfile_remove(rspamd_pidfh_t *pfh) { return (_rspamd_pidfile_remove(pfh, 1)); @@ -913,15 +913,15 @@ gint rspamd_pidfile_remove(rspamd_pidfh_t *pfh) #endif /* Replace %r with rcpt value and %f with from value, new string is allocated in pool */ -gchar * +char * resolve_stat_filename(rspamd_mempool_t *pool, - gchar *pattern, - gchar *rcpt, - gchar *from) + char *pattern, + char *rcpt, + char *from) { - gint need_to_format = 0, len = 0; - gint rcptlen, fromlen; - gchar *c = pattern, *new, *s; + int need_to_format = 0, len = 0; + int rcptlen, fromlen; + char *c = pattern, *new, *s; if (rcpt) { rcptlen = strlen(rcpt); @@ -980,28 +980,28 @@ resolve_stat_filename(rspamd_mempool_t *pool, return new; } -const gchar * -rspamd_log_check_time(gdouble start, gdouble end, gint resolution) +const char * +rspamd_log_check_time(double start, double end, int resolution) { - gdouble diff; - static gchar res[64]; - gchar fmt[32]; + double diff; + static char res[64]; + char fmt[32]; diff = (end - start) * 1000.0; rspamd_snprintf(fmt, sizeof(fmt), "%%.%dfms", resolution); rspamd_snprintf(res, sizeof(res), fmt, diff); - return (const gchar *) res; + return (const char *) res; } #ifdef HAVE_FLOCK /* Flock version */ gboolean -rspamd_file_lock(gint fd, gboolean async) +rspamd_file_lock(int fd, gboolean async) { - gint flags; + int flags; if (async) { flags = LOCK_EX | LOCK_NB; @@ -1018,9 +1018,9 @@ rspamd_file_lock(gint fd, gboolean async) } gboolean -rspamd_file_unlock(gint fd, gboolean async) +rspamd_file_unlock(int fd, gboolean async) { - gint flags; + int flags; if (async) { flags = LOCK_UN | LOCK_NB; @@ -1042,7 +1042,7 @@ rspamd_file_unlock(gint fd, gboolean async) #else /* HAVE_FLOCK */ /* Fctnl version */ gboolean -rspamd_file_lock(gint fd, gboolean async) +rspamd_file_lock(int fd, gboolean async) { struct flock fl = { .l_type = F_WRLCK, @@ -1062,7 +1062,7 @@ rspamd_file_lock(gint fd, gboolean async) } gboolean -rspamd_file_unlock(gint fd, gboolean async) +rspamd_file_unlock(int fd, gboolean async) { struct flock fl = { .l_type = F_UNLCK, @@ -1093,11 +1093,11 @@ g_int64_equal(gconstpointer v1, gconstpointer v2) { return *((const int64_t *) v1) == *((const int64_t *) v2); } -guint g_int64_hash(gconstpointer v) +unsigned int g_int64_hash(gconstpointer v) { uint64_t v64 = *(uint64_t *) v; - return (guint) (v ^ (v >> 32)); + return (unsigned int) (v ^ (v >> 32)); } #endif #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 14)) @@ -1112,7 +1112,7 @@ void g_queue_clear(GQueue *queue) #endif #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 30)) GPtrArray * -g_ptr_array_new_full(guint reserved_size, +g_ptr_array_new_full(unsigned int reserved_size, GDestroyNotify element_free_func) { GPtrArray *array; @@ -1140,11 +1140,11 @@ void g_queue_free_full(GQueue *queue, GDestroyNotify free_func) #endif #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 40)) -void g_ptr_array_insert(GPtrArray *array, gint index_, gpointer data) +void g_ptr_array_insert(GPtrArray *array, int index_, gpointer data) { g_return_if_fail(array); g_return_if_fail(index_ >= -1); - g_return_if_fail(index_ <= (gint) array->len); + g_return_if_fail(index_ <= (int) array->len); g_ptr_array_set_size(array, array->len + 1); @@ -1162,11 +1162,11 @@ void g_ptr_array_insert(GPtrArray *array, gint index_, gpointer data) #endif #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 32)) -const gchar * -g_environ_getenv(gchar **envp, const gchar *variable) +const char * +g_environ_getenv(char **envp, const char *variable) { gsize len; - gint i; + int i; if (envp == NULL) { return NULL; @@ -1184,7 +1184,7 @@ g_environ_getenv(gchar **envp, const gchar *variable) } #endif -gint rspamd_fallocate(gint fd, off_t offset, off_t len) +int rspamd_fallocate(int fd, off_t offset, off_t len) { #if defined(HAVE_FALLOCATE) return fallocate(fd, 0, offset, len); @@ -1253,8 +1253,8 @@ void rspamd_mutex_free(rspamd_mutex_t *mtx) } struct rspamd_thread_data { - gchar *name; - gint id; + char *name; + int id; GThreadFunc func; gpointer data; }; @@ -1340,7 +1340,7 @@ read_pass_tmp_sig_handler(int s) #define _PATH_TTY "/dev/tty" #endif -gint rspamd_read_passphrase_with_prompt(const gchar *prompt, gchar *buf, gint size, bool echo, gpointer key) +int rspamd_read_passphrase_with_prompt(const char *prompt, char *buf, int size, bool echo, gpointer key) { #ifdef HAVE_READPASSPHRASE_H int flags = echo ? RPP_ECHO_ON : RPP_ECHO_OFF; @@ -1353,8 +1353,8 @@ gint rspamd_read_passphrase_with_prompt(const gchar *prompt, gchar *buf, gint si struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm; struct sigaction savetstp, savettin, savettou, savepipe; struct termios term, oterm; - gint input, output, i; - gchar *end, *p, ch; + int input, output, i; + char *end, *p, ch; restart: if ((input = output = open(_PATH_TTY, O_RDWR)) == -1) { @@ -1460,10 +1460,10 @@ restart: #endif #endif -gdouble +double rspamd_get_ticks(gboolean rdtsc_ok) { - gdouble res; + double res; #ifdef HAVE_RDTSC #ifdef __x86_64__ @@ -1480,7 +1480,7 @@ rspamd_get_ticks(gboolean rdtsc_ok) #endif #ifdef HAVE_CLOCK_GETTIME struct timespec ts; - gint clk_id = RSPAMD_FAST_MONOTONIC_CLOCK; + int clk_id = RSPAMD_FAST_MONOTONIC_CLOCK; clock_gettime(clk_id, &ts); @@ -1512,10 +1512,10 @@ rspamd_get_ticks(gboolean rdtsc_ok) return res; } -gdouble +double rspamd_get_virtual_ticks(void) { - gdouble res; + double res; #ifdef HAVE_CLOCK_GETTIME struct timespec ts; @@ -1548,7 +1548,7 @@ rspamd_get_virtual_ticks(void) } res = info.user_time.seconds + info.system_time.seconds; - res += ((gdouble) (info.user_time.microseconds + info.system_time.microseconds)) / 1e6; + res += ((double) (info.user_time.microseconds + info.system_time.microseconds)) / 1e6; mach_port_deallocate(mach_task_self(), thread); #elif defined(HAVE_RUSAGE_SELF) struct rusage rusage; @@ -1563,10 +1563,10 @@ rspamd_get_virtual_ticks(void) return res; } -gdouble +double rspamd_get_calendar_ticks(void) { - gdouble res; + double res; #ifdef HAVE_CLOCK_GETTIME struct timespec ts; @@ -1586,9 +1586,9 @@ rspamd_get_calendar_ticks(void) return res; } -void rspamd_random_hex(gchar *buf, uint64_t len) +void rspamd_random_hex(char *buf, uint64_t len) { - static const gchar hexdigests[16] = "0123456789abcdef"; + static const char hexdigests[16] = "0123456789abcdef"; int64_t i; g_assert(len > 0); @@ -1604,10 +1604,10 @@ void rspamd_random_hex(gchar *buf, uint64_t len) } } -gint rspamd_shmem_mkstemp(gchar *pattern) +int rspamd_shmem_mkstemp(char *pattern) { - gint fd = -1; - gchar *nbuf, *xpos; + int fd = -1; + char *nbuf, *xpos; gsize blen; xpos = strchr(pattern, 'X'); @@ -1718,7 +1718,7 @@ rspamd_hash_seed(void) return 0xabf9727ba290690bULL; } -static inline gdouble +static inline double rspamd_double_from_int64(uint64_t x) { const union { @@ -1730,7 +1730,7 @@ rspamd_double_from_int64(uint64_t x) return u.d - 1.0; } -gdouble +double rspamd_random_double(void) { uint64_t rnd_int; @@ -1791,14 +1791,14 @@ rspamd_random_uint64_fast_seed(uint64_t *seed) #endif } -gdouble +double rspamd_random_double_fast(void) { return rspamd_random_double_fast_seed(rspamd_fast_random_seed()); } /* xoshiro256+ */ -inline gdouble +inline double rspamd_random_double_fast_seed(uint64_t *seed) { return rspamd_double_from_int64(rspamd_random_uint64_fast_seed(seed)); @@ -1815,8 +1815,8 @@ void rspamd_random_seed_fast(void) (void) rspamd_fast_random_seed(); } -gdouble -rspamd_time_jitter(gdouble in, gdouble jitter) +double +rspamd_time_jitter(double in, double jitter) { if (jitter == 0) { jitter = in; @@ -1829,10 +1829,10 @@ gboolean rspamd_constant_memcmp(const void *a, const void *b, gsize len) { gsize lena, lenb, i; - guint16 d, r = 0, m; - guint16 v; - const guint8 *aa = (const guint8 *) a, - *bb = (const guint8 *) b; + uint16_t d, r = 0, m; + uint16_t v; + const uint8_t *aa = (const uint8_t *) a, + *bb = (const uint8_t *) b; if (len == 0) { lena = strlen((const char *) a); @@ -1846,16 +1846,16 @@ rspamd_constant_memcmp(const void *a, const void *b, gsize len) } for (i = 0; i < len; i++) { - v = ((guint16) (guint8) r) + 255; + v = ((uint16_t) (uint8_t) r) + 255; m = v / 256 - 1; - d = (guint16) ((int) aa[i] - (int) bb[i]); + d = (uint16_t) ((int) aa[i] - (int) bb[i]); r |= (d & m); } - return (((int32_t) (guint16) ((uint32_t) r + 0x8000) - 0x8000) == 0); + return (((int32_t) (uint16_t) ((uint32_t) r + 0x8000) - 0x8000) == 0); } -int rspamd_file_xopen(const char *fname, int oflags, guint mode, +int rspamd_file_xopen(const char *fname, int oflags, unsigned int mode, gboolean allow_symlink) { struct stat sb; @@ -1911,10 +1911,10 @@ int rspamd_file_xopen(const char *fname, int oflags, guint mode, } gpointer -rspamd_file_xmap(const char *fname, guint mode, gsize *size, +rspamd_file_xmap(const char *fname, unsigned int mode, gsize *size, gboolean allow_symlink) { - gint fd; + int fd; struct stat sb; gpointer map; @@ -1960,10 +1960,10 @@ rspamd_file_xmap(const char *fname, guint mode, gsize *size, gpointer -rspamd_shmem_xmap(const char *fname, guint mode, +rspamd_shmem_xmap(const char *fname, unsigned int mode, gsize *size) { - gint fd; + int fd; struct stat sb; gpointer map; @@ -2019,10 +2019,10 @@ rspamd_shmem_xmap(const char *fname, guint mode, * New approach: * y = ((x - bias)*2)^8 */ -gdouble -rspamd_normalize_probability(gdouble x, gdouble bias) +double +rspamd_normalize_probability(double x, double bias) { - gdouble xx; + double xx; xx = (x - bias) * 2.0; @@ -2037,11 +2037,11 @@ rspamd_tm_to_time(const struct tm *tm, glong tz) { uint64_t result; gboolean is_leap = FALSE; - gint leaps, y = tm->tm_year, cycles, rem, centuries; + int leaps, y = tm->tm_year, cycles, rem, centuries; glong offset = (tz / 100) * 3600 + (tz % 100) * 60; /* How many seconds in each month from the beginning of the year */ - static const gint secs_through_month[] = { + static const int secs_through_month[] = { 0, 31 * 86400, 59 * 86400, 90 * 86400, 120 * 86400, 151 * 86400, 181 * 86400, 212 * 86400, 243 * 86400, 273 * 86400, 304 * 86400, 334 * 86400}; @@ -2102,7 +2102,7 @@ rspamd_tm_to_time(const struct tm *tm, glong tz) } } - leaps += 97 * cycles + 24 * centuries - (gint) is_leap; + leaps += 97 * cycles + 24 * centuries - (int) is_leap; result = (y - 100) * 31536000LL + leaps * 86400LL + 946684800 + 86400; } @@ -2350,16 +2350,16 @@ rspamd_fstring_gunzip(rspamd_fstring_t **in) } static gboolean -rspamd_glob_dir(const gchar *full_path, const gchar *pattern, - gboolean recursive, guint rec_len, +rspamd_glob_dir(const char *full_path, const char *pattern, + gboolean recursive, unsigned int rec_len, GPtrArray *res, GError **err) { glob_t globbuf; - const gchar *path; - static gchar pathbuf[PATH_MAX]; /* Static to help recursion */ - guint i; - gint rc; - static const guint rec_lim = 16; + const char *path; + static char pathbuf[PATH_MAX]; /* Static to help recursion */ + unsigned int i; + int rc; + static const unsigned int rec_lim = 16; struct stat st; if (rec_len > rec_lim) { @@ -2425,12 +2425,12 @@ rspamd_glob_dir(const gchar *full_path, const gchar *pattern, } GPtrArray * -rspamd_glob_path(const gchar *dir, - const gchar *pattern, +rspamd_glob_path(const char *dir, + const char *pattern, gboolean recursive, GError **err) { - gchar path[PATH_MAX]; + char path[PATH_MAX]; GPtrArray *res; res = g_ptr_array_new_full(32, (GDestroyNotify) g_free); @@ -2446,9 +2446,9 @@ rspamd_glob_path(const gchar *dir, } double -rspamd_set_counter(struct rspamd_counter_data *cd, gdouble value) +rspamd_set_counter(struct rspamd_counter_data *cd, double value) { - gdouble cerr; + double cerr; /* Cumulative moving average using per-process counter data */ if (cd->number == 0) { @@ -2456,9 +2456,9 @@ rspamd_set_counter(struct rspamd_counter_data *cd, gdouble value) cd->stddev = 0; } - cd->mean += (value - cd->mean) / (gdouble) (++cd->number); + cd->mean += (value - cd->mean) / (double) (++cd->number); cerr = (value - cd->mean) * (value - cd->mean); - cd->stddev += (cerr - cd->stddev) / (gdouble) (cd->number); + cd->stddev += (cerr - cd->stddev) / (double) (cd->number); return cd->mean; } @@ -2490,10 +2490,10 @@ void rspamd_ptr_array_shuffle(GPtrArray *ar) return; } - guint n = ar->len; + unsigned int n = ar->len; - for (guint i = 0; i < n - 1; i++) { - guint j = i + rspamd_random_uint64_fast() % (n - i); + for (unsigned int i = 0; i < n - 1; i++) { + unsigned int j = i + rspamd_random_uint64_fast() % (n - i); gpointer t = g_ptr_array_index(ar, j); g_ptr_array_index(ar, j) = g_ptr_array_index(ar, i); g_ptr_array_index(ar, i) = t; @@ -2522,10 +2522,10 @@ float rspamd_sum_floats(float *ar, gsize *nelts) return sum; } -void rspamd_normalize_path_inplace(gchar *path, guint len, gsize *nlen) +void rspamd_normalize_path_inplace(char *path, unsigned int len, gsize *nlen) { - const gchar *p, *end, *slash = NULL, *dot = NULL; - gchar *o; + const char *p, *end, *slash = NULL, *dot = NULL; + char *o; enum { st_normal = 0, st_got_dot, @@ -2637,7 +2637,7 @@ void rspamd_normalize_path_inplace(gchar *path, guint len, gsize *nlen) } if (slash) { - o = (gchar *) slash; + o = (char *) slash; } /* Otherwise we keep these dots */ slash = p; @@ -2701,7 +2701,7 @@ void rspamd_normalize_path_inplace(gchar *path, guint len, gsize *nlen) if (slash) { /* Remove last / */ - o = (gchar *) slash; + o = (char *) slash; } } else { diff --git a/src/libutil/util.h b/src/libutil/util.h index 54e86d3bb..8531ce450 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -46,7 +46,7 @@ enum rspamd_exception_type { */ struct rspamd_process_exception { goffset pos; - guint len; + unsigned int len; gpointer ptr; enum rspamd_exception_type type; }; @@ -59,26 +59,26 @@ struct rspamd_process_exception { * @param async set non-blocking on a socket * @return socket FD or -1 in case of error */ -gint rspamd_socket_create(gint af, gint type, gint protocol, gboolean async); +int rspamd_socket_create(int af, int type, int protocol, gboolean async); /* * Create socket and bind or connect it to specified address and port */ -gint rspamd_socket_tcp(struct addrinfo *, gboolean is_server, gboolean async); +int rspamd_socket_tcp(struct addrinfo *, gboolean is_server, gboolean async); /* * Create socket and bind or connect it to specified address and port */ -gint rspamd_socket_udp(struct addrinfo *, gboolean is_server, gboolean async); +int rspamd_socket_udp(struct addrinfo *, gboolean is_server, gboolean async); /* * Create and bind or connect unix socket */ -gint rspamd_socket_unix(const gchar *, - struct sockaddr_un *, - gint type, - gboolean is_server, - gboolean async); +int rspamd_socket_unix(const char *, + struct sockaddr_un *, + int type, + gboolean is_server, + gboolean async); /** * Make a universal socket @@ -89,75 +89,75 @@ gint rspamd_socket_unix(const gchar *, * @param is_server make this socket as server socket * @param try_resolve try name resolution for a socket (BLOCKING) */ -gint rspamd_socket(const gchar *credits, guint16 port, gint type, - gboolean async, gboolean is_server, gboolean try_resolve); +int rspamd_socket(const char *credits, uint16_t port, int type, + gboolean async, gboolean is_server, gboolean try_resolve); /* * Create socketpair */ -gboolean rspamd_socketpair(gint pair[2], gint af); +gboolean rspamd_socketpair(int pair[2], int af); /* * Make specified socket non-blocking */ -gint rspamd_socket_nonblocking(gint); +int rspamd_socket_nonblocking(int); /* * Make specified socket blocking */ -gint rspamd_socket_blocking(gint); +int rspamd_socket_blocking(int); /* * Poll a sync socket for specified events */ -gint rspamd_socket_poll(gint fd, gint timeout, short events); +int rspamd_socket_poll(int fd, int timeout, short events); /* * Init signals */ #ifdef HAVE_SA_SIGINFO -void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(gint, +void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(int, siginfo_t *, void *)); #else -void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(gint)); +void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(int)); #endif /* * Process title utility functions */ -gint rspamd_init_title(rspamd_mempool_t *pool, gint argc, gchar *argv[], gchar *envp[]); -gint rspamd_setproctitle(const gchar *fmt, ...); +int rspamd_init_title(rspamd_mempool_t *pool, int argc, char *argv[], char *envp[]); +int rspamd_setproctitle(const char *fmt, ...); #ifndef HAVE_PIDFILE /* * Pidfile functions from FreeBSD libutil code */ typedef struct rspamd_pidfh_s { - gint pf_fd; + int pf_fd; #ifdef HAVE_PATH_MAX - gchar pf_path[PATH_MAX + 1]; + char pf_path[PATH_MAX + 1]; #elif defined(HAVE_MAXPATHLEN) - gchar pf_path[MAXPATHLEN + 1]; + char pf_path[MAXPATHLEN + 1]; #else - gchar pf_path[1024 + 1]; + char pf_path[1024 + 1]; #endif dev_t pf_dev; ino_t pf_ino; } rspamd_pidfh_t; -rspamd_pidfh_t *rspamd_pidfile_open(const gchar *path, +rspamd_pidfh_t *rspamd_pidfile_open(const char *path, mode_t mode, pid_t *pidptr); -gint rspamd_pidfile_write(rspamd_pidfh_t *pfh); +int rspamd_pidfile_write(rspamd_pidfh_t *pfh); -gint rspamd_pidfile_close(rspamd_pidfh_t *pfh); +int rspamd_pidfile_close(rspamd_pidfh_t *pfh); -gint rspamd_pidfile_remove(rspamd_pidfh_t *pfh); +int rspamd_pidfile_remove(rspamd_pidfh_t *pfh); #else typedef struct pidfh rspamd_pidfh_t; @@ -170,20 +170,20 @@ typedef struct pidfh rspamd_pidfh_t; /* * Replace %r with rcpt value and %f with from value, new string is allocated in pool */ -gchar *resolve_stat_filename(rspamd_mempool_t *pool, - gchar *pattern, - gchar *rcpt, - gchar *from); +char *resolve_stat_filename(rspamd_mempool_t *pool, + char *pattern, + char *rcpt, + char *from); -const gchar * -rspamd_log_check_time(gdouble start, gdouble end, gint resolution); +const char * +rspamd_log_check_time(double start, double end, int resolution); /* * File locking functions */ -gboolean rspamd_file_lock(gint fd, gboolean async); +gboolean rspamd_file_lock(int fd, gboolean async); -gboolean rspamd_file_unlock(gint fd, gboolean async); +gboolean rspamd_file_unlock(int fd, gboolean async); /* * Workarounds for older versions of glib @@ -191,7 +191,7 @@ gboolean rspamd_file_unlock(gint fd, gboolean async); #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 22)) void g_ptr_array_unref(GPtrArray *array); gboolean g_int64_equal(gconstpointer v1, gconstpointer v2); -guint g_int64_hash(gconstpointer v); +unsigned int g_int64_hash(gconstpointer v); #endif #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 14)) void g_queue_clear(GQueue *queue); @@ -200,14 +200,14 @@ void g_queue_clear(GQueue *queue); void g_queue_free_full(GQueue *queue, GDestroyNotify free_func); #endif #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 40)) -void g_ptr_array_insert(GPtrArray *array, gint index_, gpointer data); +void g_ptr_array_insert(GPtrArray *array, int index_, gpointer data); #endif #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 30)) -GPtrArray *g_ptr_array_new_full(guint reserved_size, +GPtrArray *g_ptr_array_new_full(unsigned int reserved_size, GDestroyNotify element_free_func); #endif #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 32)) -const gchar *g_environ_getenv(gchar **envp, const gchar *variable); +const char *g_environ_getenv(char **envp, const char *variable); #endif /* @@ -244,7 +244,7 @@ const gchar *g_environ_getenv(gchar **envp, const gchar *variable); * @param len length to allocate * @return -1 in case of failure */ -gint rspamd_fallocate(gint fd, off_t offset, off_t len); +int rspamd_fallocate(int fd, off_t offset, off_t len); /** * Utils for working with threads to be compatible with all glib versions @@ -315,25 +315,25 @@ void rspamd_hash_table_copy(GHashTable *src, GHashTable *dst, * @param key unused key * @return */ -gint rspamd_read_passphrase_with_prompt(const gchar *prompt, gchar *buf, gint size, bool echo, gpointer key); +int rspamd_read_passphrase_with_prompt(const char *prompt, char *buf, int size, bool echo, gpointer key); /** * Portably return the current clock ticks as seconds * @return */ -gdouble rspamd_get_ticks(gboolean rdtsc_ok); +double rspamd_get_ticks(gboolean rdtsc_ok); /** * Portably return the current virtual clock ticks as seconds * @return */ -gdouble rspamd_get_virtual_ticks(void); +double rspamd_get_virtual_ticks(void); /** * Return the real timestamp as unixtime */ -gdouble rspamd_get_calendar_ticks(void); +double rspamd_get_calendar_ticks(void); /** * Special utility to help array freeing in rspamd_mempool @@ -377,32 +377,32 @@ uint64_t rspamd_hash_seed(void); * @param buf * @param len */ -void rspamd_random_hex(gchar *buf, uint64_t len); +void rspamd_random_hex(char *buf, uint64_t len); /** * Returns * @param pattern pattern to create (should end with some number of X symbols), modified by this function * @return */ -gint rspamd_shmem_mkstemp(gchar *pattern); +int rspamd_shmem_mkstemp(char *pattern); /** * Return jittered time value */ -gdouble rspamd_time_jitter(gdouble in, gdouble jitter); +double rspamd_time_jitter(double in, double jitter); /** * Return random double in range [0..1) * @return */ -gdouble rspamd_random_double(void); +double rspamd_random_double(void); /** * Return random double in range [0..1) using xoroshiro128+ algorithm (not crypto secure) * @return */ -gdouble rspamd_random_double_fast(void); -gdouble rspamd_random_double_fast_seed(uint64_t *seed); +double rspamd_random_double_fast(void); +double rspamd_random_double_fast_seed(uint64_t *seed); uint64_t rspamd_random_uint64_fast_seed(uint64_t *seed); uint64_t rspamd_random_uint64_fast(void); @@ -423,7 +423,7 @@ gboolean rspamd_constant_memcmp(const void *a, const void *b, gsize len); * @param mode mode to open * @return fd or -1 in case of error */ -int rspamd_file_xopen(const char *fname, int oflags, guint mode, +int rspamd_file_xopen(const char *fname, int oflags, unsigned int mode, gboolean allow_symlink); /** @@ -433,7 +433,7 @@ int rspamd_file_xopen(const char *fname, int oflags, guint mode, * @param size target size (must NOT be NULL) * @return pointer to memory (should be freed using munmap) or NULL in case of error */ -gpointer rspamd_file_xmap(const char *fname, guint mode, gsize *size, +gpointer rspamd_file_xmap(const char *fname, unsigned int mode, gsize *size, gboolean allow_symlink); /** @@ -443,7 +443,7 @@ gpointer rspamd_file_xmap(const char *fname, guint mode, gsize *size, * @param size target size (must NOT be NULL) * @return pointer to memory (should be freed using munmap) or NULL in case of error */ -gpointer rspamd_shmem_xmap(const char *fname, guint mode, +gpointer rspamd_shmem_xmap(const char *fname, unsigned int mode, gsize *size); /** @@ -451,7 +451,7 @@ gpointer rspamd_shmem_xmap(const char *fname, guint mode, * @param x probability (bias .. 1) * @return */ -gdouble rspamd_normalize_probability(gdouble x, gdouble bias); +double rspamd_normalize_probability(double x, double bias); /** * Converts struct tm to time_t @@ -499,10 +499,10 @@ gboolean rspamd_fstring_gunzip(rspamd_fstring_t **in); * @param pattern * @param recursive * @param err - * @return GPtrArray of gchar *, elements are freed when array is freed + * @return GPtrArray of char *, elements are freed when array is freed */ -GPtrArray *rspamd_glob_path(const gchar *dir, - const gchar *pattern, +GPtrArray *rspamd_glob_path(const char *dir, + const char *pattern, gboolean recursive, GError **err); @@ -530,7 +530,7 @@ float rspamd_set_counter_ema(struct rspamd_counter_data *cd, * @return new counter value */ double rspamd_set_counter(struct rspamd_counter_data *cd, - gdouble value); + double value); /** * Shuffle elements in an array inplace @@ -549,8 +549,8 @@ struct rspamd_controller_pbkdf { const char *alias; const char *description; int type; /* enum rspamd_cryptobox_pbkdf_type */ - gint id; - guint complexity; + int id; + unsigned int complexity; gsize salt_len; gsize key_len; }; @@ -572,7 +572,7 @@ float rspamd_sum_floats(float *ar, gsize *nelts); * @param len * @param nlen */ -void rspamd_normalize_path_inplace(gchar *path, guint len, gsize *nlen); +void rspamd_normalize_path_inplace(char *path, unsigned int len, gsize *nlen); #ifdef __cplusplus } diff --git a/src/lua/lua_cdb.c b/src/lua/lua_cdb.c index 780672420..66f811cc0 100644 --- a/src/lua/lua_cdb.c +++ b/src/lua/lua_cdb.c @@ -158,12 +158,12 @@ lua_cdb_get_input(lua_State *L, int pos, gsize *olen) return NULL; } -static gint +static int lua_cdb_create(lua_State *L) { struct cdb *cdb, **pcdb; - const gchar *filename; - gint fd; + const char *filename; + int fd; struct ev_loop *ev_base = NULL; @@ -218,7 +218,7 @@ lua_cdb_create(lua_State *L) return 1; } -static gint +static int lua_cdb_get_name(lua_State *L) { struct cdb *cdb = lua_check_cdb(L, 1); @@ -231,12 +231,12 @@ lua_cdb_get_name(lua_State *L) return 1; } -static gint +static int lua_cdb_lookup(lua_State *L) { struct cdb *cdb = lua_check_cdb(L, 1); gsize klen; - const gchar *what = lua_cdb_get_input(L, 2, &klen); + const char *what = lua_cdb_get_input(L, 2, &klen); if (!cdb || what == NULL) { return lua_error(L); @@ -253,7 +253,7 @@ lua_cdb_lookup(lua_State *L) return 1; } -static gint +static int lua_cdb_destroy(lua_State *L) { struct cdb *cdb = lua_check_cdb(L, 1); @@ -270,7 +270,7 @@ lua_cdb_destroy(lua_State *L) return 0; } -static gint +static int lua_cdb_build(lua_State *L) { const char *filename = luaL_checkstring(L, 1); @@ -306,7 +306,7 @@ lua_cdb_build(lua_State *L) return 1; } -static gint +static int lua_cdb_builder_add(lua_State *L) { struct cdb_make *cdbm = lua_check_cdb_builder(L, 1); @@ -330,7 +330,7 @@ lua_cdb_builder_add(lua_State *L) return 1; } -static gint +static int lua_cdb_builder_finalize(lua_State *L) { struct cdb_make *cdbm = lua_check_cdb_builder(L, 1); @@ -354,7 +354,7 @@ lua_cdb_builder_finalize(lua_State *L) return 1; } -static gint +static int lua_cdb_builder_dtor(lua_State *L) { struct cdb_make *cdbm = lua_check_cdb_builder(L, 1); @@ -372,7 +372,7 @@ lua_cdb_builder_dtor(lua_State *L) return 0; } -static gint +static int lua_load_cdb(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c index 75bc3806d..b92e8ba45 100644 --- a/src/lua/lua_cfg_file.c +++ b/src/lua/lua_cfg_file.c @@ -23,11 +23,11 @@ /* Process a single item in 'metrics' table */ static void -lua_process_metric(lua_State *L, const gchar *name, struct rspamd_config *cfg) +lua_process_metric(lua_State *L, const char *name, struct rspamd_config *cfg) { - gchar *symbol; - const gchar *desc = NULL; - gdouble *score; + char *symbol; + const char *desc = NULL; + double *score; struct rspamd_symbol *s; /* Now iterate through module table */ @@ -91,7 +91,7 @@ lua_process_metric(lua_State *L, const gchar *name, struct rspamd_config *cfg) void rspamd_lua_post_load_config(struct rspamd_config *cfg) { lua_State *L = cfg->lua_state; - const gchar *name; + const char *name; ucl_object_t *obj; gsize keylen, i; @@ -104,7 +104,7 @@ void rspamd_lua_post_load_config(struct rspamd_config *cfg) g_free); for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) { - gchar *tmp; + char *tmp; lua_pushvalue(L, -2); name = luaL_checklstring(L, -1, &keylen); diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c index eb50f1950..0e64ca5ab 100644 --- a/src/lua/lua_classifier.c +++ b/src/lua/lua_classifier.c @@ -54,13 +54,13 @@ lua_check_classifier(lua_State *L) } /* Return table of statfiles indexed by name */ -static gint +static int lua_classifier_get_statfiles(lua_State *L) { struct rspamd_classifier_config *ccf = lua_check_classifier(L); GList *cur; struct rspamd_statfile_config *st, **pst; - gint i; + int i; if (ccf) { lua_newtable(L); @@ -83,11 +83,11 @@ lua_classifier_get_statfiles(lua_State *L) return 1; } -static gint +static int lua_classifier_get_param(lua_State *L) { struct rspamd_classifier_config *ccf = lua_check_classifier(L); - const gchar *param; + const char *param; const ucl_object_t *value; param = luaL_checkstring(L, 2); @@ -107,14 +107,14 @@ lua_classifier_get_param(lua_State *L) } /* Get statfile with specified label */ -static gint +static int lua_classifier_get_statfile_by_label(lua_State *L) { struct rspamd_classifier_config *ccf = lua_check_classifier(L); struct rspamd_statfile_config *st, **pst; - const gchar *label; + const char *label; GList *cur; - gint i; + int i; label = luaL_checkstring(L, 2); if (ccf && label) { @@ -140,7 +140,7 @@ lua_classifier_get_statfile_by_label(lua_State *L) } /* Statfile functions */ -static gint +static int lua_statfile_get_symbol(lua_State *L) { struct rspamd_statfile_config *st = lua_check_statfile(L); @@ -155,7 +155,7 @@ lua_statfile_get_symbol(lua_State *L) return 1; } -static gint +static int lua_statfile_get_label(lua_State *L) { struct rspamd_statfile_config *st = lua_check_statfile(L); @@ -170,7 +170,7 @@ lua_statfile_get_label(lua_State *L) return 1; } -static gint +static int lua_statfile_is_spam(lua_State *L) { struct rspamd_statfile_config *st = lua_check_statfile(L); @@ -185,11 +185,11 @@ lua_statfile_is_spam(lua_State *L) return 1; } -static gint +static int lua_statfile_get_param(lua_State *L) { struct rspamd_statfile_config *st = lua_check_statfile(L); - const gchar *param; + const char *param; const ucl_object_t *value; param = luaL_checkstring(L, 2); diff --git a/src/lua/lua_classnames.c b/src/lua/lua_classnames.c index 7041a8ca1..7ce2f8abc 100644 --- a/src/lua/lua_classnames.c +++ b/src/lua/lua_classnames.c @@ -139,7 +139,7 @@ RSPAMD_CONSTRUCTOR(rspamd_lua_init_classnames) } const char * -rspamd_lua_static_classname(const char *name, guint len) +rspamd_lua_static_classname(const char *name, unsigned int len) { khiter_t k; diff --git a/src/lua/lua_classnames.h b/src/lua/lua_classnames.h index 2563249b5..53db5f8c2 100644 --- a/src/lua/lua_classnames.h +++ b/src/lua/lua_classnames.h @@ -77,6 +77,6 @@ extern const char *rspamd_zstd_decompress_classname; /* * Return a static class name for a given name (only for known classes) or NULL */ -const char *rspamd_lua_static_classname(const char *name, guint len); +const char *rspamd_lua_static_classname(const char *name, unsigned int len); #endif//RSPAMD_LUA_CLASSNAMES_H diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 18aa4cd4c..d79efc308 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -80,11 +80,11 @@ rspamd_lua_ctx_by_state(lua_State *L) * @param func table of class methods */ void rspamd_lua_new_class(lua_State *L, - const gchar *classname, + const char *classname, const struct luaL_reg *methods) { khiter_t k; - gint r, nmethods = 0; + int r, nmethods = 0; gboolean seen_index = false; struct rspamd_lua_context *ctx = rspamd_lua_ctx_by_state(L); @@ -128,12 +128,12 @@ void rspamd_lua_new_class(lua_State *L, /* MT is left on stack ! */ } -static const gchar * -rspamd_lua_class_tostring_buf(lua_State *L, gboolean print_pointer, gint pos) +static const char * +rspamd_lua_class_tostring_buf(lua_State *L, gboolean print_pointer, int pos) { - static gchar buf[64]; - const gchar *ret = NULL; - gint pop = 0; + static char buf[64]; + const char *ret = NULL; + int pop = 0; if (!lua_getmetatable(L, pos)) { goto err; @@ -164,9 +164,9 @@ err: return ret; } -gint rspamd_lua_class_tostring(lua_State *L) +int rspamd_lua_class_tostring(lua_State *L) { - const gchar *p; + const char *p; p = rspamd_lua_class_tostring_buf(L, TRUE, 1); @@ -181,7 +181,7 @@ gint rspamd_lua_class_tostring(lua_State *L) } -void rspamd_lua_setclass(lua_State *L, const gchar *classname, gint objidx) +void rspamd_lua_setclass(lua_State *L, const char *classname, int objidx) { khiter_t k; struct rspamd_lua_context *ctx = rspamd_lua_ctx_by_state(L); @@ -197,7 +197,7 @@ void rspamd_lua_setclass(lua_State *L, const gchar *classname, gint objidx) lua_setmetatable(L, objidx); } -void rspamd_lua_class_metatable(lua_State *L, const gchar *classname) +void rspamd_lua_class_metatable(lua_State *L, const char *classname) { khiter_t k; struct rspamd_lua_context *ctx = rspamd_lua_ctx_by_state(L); @@ -208,7 +208,7 @@ void rspamd_lua_class_metatable(lua_State *L, const gchar *classname) lua_rawgeti(L, LUA_REGISTRYINDEX, kh_value(ctx->classes, k)); } -void rspamd_lua_add_metamethod(lua_State *L, const gchar *classname, +void rspamd_lua_add_metamethod(lua_State *L, const char *classname, luaL_Reg *meth) { khiter_t k; @@ -225,7 +225,7 @@ void rspamd_lua_add_metamethod(lua_State *L, const gchar *classname, } /* assume that table is at the top */ -void rspamd_lua_table_set(lua_State *L, const gchar *index, const gchar *value) +void rspamd_lua_table_set(lua_State *L, const char *index, const char *value) { lua_pushstring(L, index); if (value) { @@ -237,10 +237,10 @@ void rspamd_lua_table_set(lua_State *L, const gchar *index, const gchar *value) lua_settable(L, -3); } -const gchar * -rspamd_lua_table_get(lua_State *L, const gchar *index) +const char * +rspamd_lua_table_get(lua_State *L, const char *index) { - const gchar *result; + const char *result; lua_pushstring(L, index); lua_gettable(L, -2); @@ -255,7 +255,7 @@ rspamd_lua_table_get(lua_State *L, const gchar *index) static void lua_add_actions_global(lua_State *L) { - gint i; + int i; lua_newtable(L); @@ -276,14 +276,14 @@ lua_add_actions_global(lua_State *L) void rspamd_lua_set_path(lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars) { - const gchar *old_path, *additional_path = NULL; + const char *old_path, *additional_path = NULL; const ucl_object_t *opts = NULL; - const gchar *rulesdir = RSPAMD_RULESDIR, - *lualibdir = RSPAMD_LUALIBDIR, - *libdir = RSPAMD_LIBDIR; - const gchar *t; + const char *rulesdir = RSPAMD_RULESDIR, + *lualibdir = RSPAMD_LUALIBDIR, + *libdir = RSPAMD_LIBDIR; + const char *t; - gchar path_buf[PATH_MAX]; + char path_buf[PATH_MAX]; lua_getglobal(L, "package"); lua_getfield(L, -1, "path"); @@ -408,10 +408,10 @@ void rspamd_lua_set_path(lua_State *L, const ucl_object_t *cfg_obj, GHashTable * lua_pop(L, 1); } -static gint -rspamd_lua_cmp_version_components(const gchar *comp1, const gchar *comp2) +static int +rspamd_lua_cmp_version_components(const char *comp1, const char *comp2) { - guint v1, v2; + unsigned int v1, v2; v1 = strtoul(comp1, NULL, 10); v2 = strtoul(comp2, NULL, 10); @@ -422,9 +422,9 @@ rspamd_lua_cmp_version_components(const gchar *comp1, const gchar *comp2) static int rspamd_lua_rspamd_version_cmp(lua_State *L) { - const gchar *ver; - gchar **components; - gint ret = 0; + const char *ver; + char **components; + int ret = 0; if (lua_type(L, 2) == LUA_TSTRING) { ver = lua_tostring(L, 2); @@ -472,7 +472,7 @@ static int rspamd_lua_rspamd_version_numeric(lua_State *L) { static int64_t version_num = RSPAMD_VERSION_NUM; - const gchar *type; + const char *type; if (lua_gettop(L) >= 2 && lua_type(L, 1) == LUA_TSTRING) { type = lua_tostring(L, 1); @@ -505,7 +505,7 @@ rspamd_lua_rspamd_version_numeric(lua_State *L) static int rspamd_lua_rspamd_version(lua_State *L) { - const gchar *result = NULL, *type; + const char *result = NULL, *type; if (lua_gettop(L) == 0) { result = RVERSION; @@ -547,9 +547,9 @@ rspamd_lua_rspamd_version(lua_State *L) } static gboolean -rspamd_lua_load_env(lua_State *L, const char *fname, gint tbl_pos, GError **err) +rspamd_lua_load_env(lua_State *L, const char *fname, int tbl_pos, GError **err) { - gint orig_top = lua_gettop(L), err_idx; + int orig_top = lua_gettop(L), err_idx; gboolean ret = TRUE; lua_pushcfunction(L, &rspamd_lua_traceback); @@ -594,24 +594,24 @@ rspamd_lua_load_env(lua_State *L, const char *fname, gint tbl_pos, GError **err) gboolean rspamd_lua_set_env(lua_State *L, GHashTable *vars, char **lua_env, GError **err) { - gint orig_top = lua_gettop(L); - gchar **env = g_get_environ(); + int orig_top = lua_gettop(L); + char **env = g_get_environ(); /* Set known paths as rspamd_paths global */ lua_getglobal(L, "rspamd_paths"); if (lua_isnil(L, -1)) { - const gchar *confdir = RSPAMD_CONFDIR, - *local_confdir = RSPAMD_LOCAL_CONFDIR, - *rundir = RSPAMD_RUNDIR, - *dbdir = RSPAMD_DBDIR, - *logdir = RSPAMD_LOGDIR, - *wwwdir = RSPAMD_WWWDIR, - *pluginsdir = RSPAMD_PLUGINSDIR, - *rulesdir = RSPAMD_RULESDIR, - *lualibdir = RSPAMD_LUALIBDIR, - *prefix = RSPAMD_PREFIX, - *sharedir = RSPAMD_SHAREDIR; - const gchar *t; + const char *confdir = RSPAMD_CONFDIR, + *local_confdir = RSPAMD_LOCAL_CONFDIR, + *rundir = RSPAMD_RUNDIR, + *dbdir = RSPAMD_DBDIR, + *logdir = RSPAMD_LOGDIR, + *wwwdir = RSPAMD_WWWDIR, + *pluginsdir = RSPAMD_PLUGINSDIR, + *rulesdir = RSPAMD_RULESDIR, + *lualibdir = RSPAMD_LUALIBDIR, + *prefix = RSPAMD_PREFIX, + *sharedir = RSPAMD_SHAREDIR; + const char *t; /* Try environment */ t = g_environ_getenv(env, "SHAREDIR"); @@ -749,7 +749,7 @@ rspamd_lua_set_env(lua_State *L, GHashTable *vars, char **lua_env, GError **err) } } - gint hostlen = sysconf(_SC_HOST_NAME_MAX); + int hostlen = sysconf(_SC_HOST_NAME_MAX); if (hostlen <= 0) { hostlen = 256; @@ -758,7 +758,7 @@ rspamd_lua_set_env(lua_State *L, GHashTable *vars, char **lua_env, GError **err) hostlen++; } - gchar *hostbuf = g_alloca(hostlen); + char *hostbuf = g_alloca(hostlen); memset(hostbuf, 0, hostlen); gethostname(hostbuf, hostlen - 1); @@ -773,12 +773,12 @@ rspamd_lua_set_env(lua_State *L, GHashTable *vars, char **lua_env, GError **err) lua_settable(L, -3); if (env) { - gint lim = g_strv_length(env); + int lim = g_strv_length(env); - for (gint i = 0; i < lim; i++) { + for (int i = 0; i < lim; i++) { if (RSPAMD_LEN_CHECK_STARTS_WITH(env[i], strlen(env[i]), "RSPAMD_")) { const char *var = env[i] + sizeof("RSPAMD_") - 1, *value; - gint varlen; + int varlen; varlen = strcspn(var, "="); value = var + varlen; @@ -795,9 +795,9 @@ rspamd_lua_set_env(lua_State *L, GHashTable *vars, char **lua_env, GError **err) } if (lua_env) { - gint lim = g_strv_length(lua_env); + int lim = g_strv_length(lua_env); - for (gint i = 0; i < lim; i++) { + for (int i = 0; i < lim; i++) { if (!rspamd_lua_load_env(L, lua_env[i], lua_gettop(L), err)) { return FALSE; } @@ -816,7 +816,7 @@ rspamd_lua_set_env(lua_State *L, GHashTable *vars, char **lua_env, GError **err) void rspamd_lua_set_globals(struct rspamd_config *cfg, lua_State *L) { struct rspamd_config **pcfg; - gint orig_top = lua_gettop(L); + int orig_top = lua_gettop(L); /* First check for global variable 'config' */ lua_getglobal(L, "config"); @@ -867,7 +867,7 @@ void rspamd_lua_set_globals(struct rspamd_config *cfg, lua_State *L) } #ifdef WITH_LUA_TRACE -static gint +static int lua_push_trace_data(lua_State *L) { if (lua_traces) { @@ -1092,8 +1092,8 @@ void rspamd_lua_start_gc(struct rspamd_config *cfg) } -void rspamd_plugins_table_push_elt(lua_State *L, const gchar *field_name, - const gchar *new_elt) +void rspamd_plugins_table_push_elt(lua_State *L, const char *field_name, + const char *new_elt) { lua_getglobal(L, rspamd_modules_state_global); @@ -1122,7 +1122,7 @@ rspamd_init_lua_filters(struct rspamd_config *cfg, bool force_load, bool strict) struct rspamd_config **pcfg; struct script_module *module; lua_State *L = cfg->lua_state; - gint err_idx, i; + int err_idx, i; pcfg = lua_newuserdata(L, sizeof(struct rspamd_config *)); rspamd_lua_setclass(L, rspamd_config_classname, -1); @@ -1142,10 +1142,10 @@ rspamd_init_lua_filters(struct rspamd_config *cfg, bool force_load, bool strict) err_idx = lua_gettop(L); gsize fsize; - guint8 *data = rspamd_file_xmap(module->path, - PROT_READ, &fsize, TRUE); - guchar digest[rspamd_cryptobox_HASHBYTES]; - gchar *lua_fname; + uint8_t *data = rspamd_file_xmap(module->path, + PROT_READ, &fsize, TRUE); + unsigned char digest[rspamd_cryptobox_HASHBYTES]; + char *lua_fname; if (data == NULL) { msg_err_config("cannot mmap %s failed: %s", module->path, @@ -1225,9 +1225,9 @@ rspamd_init_lua_filters(struct rspamd_config *cfg, bool force_load, bool strict) void rspamd_lua_dumpstack(lua_State *L) { - gint i, t, r = 0; - gint top = lua_gettop(L); - gchar buf[BUFSIZ]; + int i, t, r = 0; + int top = lua_gettop(L); + char buf[BUFSIZ]; r += rspamd_snprintf(buf + r, sizeof(buf) - r, "lua stack: "); for (i = 1; i <= top; i++) { /* repeat for each level */ @@ -1269,7 +1269,7 @@ void rspamd_lua_dumpstack(lua_State *L) } gpointer -rspamd_lua_check_class(lua_State *L, gint index, const gchar *name) +rspamd_lua_check_class(lua_State *L, int index, const char *name) { gpointer p; khiter_t k; @@ -1309,7 +1309,7 @@ int rspamd_lua_typerror(lua_State *L, int narg, const char *tname) } -void rspamd_lua_add_preload(lua_State *L, const gchar *name, lua_CFunction func) +void rspamd_lua_add_preload(lua_State *L, const char *name, lua_CFunction func) { lua_getglobal(L, "package"); lua_pushstring(L, "preload"); @@ -1321,12 +1321,12 @@ void rspamd_lua_add_preload(lua_State *L, const gchar *name, lua_CFunction func) gboolean -rspamd_lua_parse_table_arguments(lua_State *L, gint pos, +rspamd_lua_parse_table_arguments(lua_State *L, int pos, GError **err, enum rspamd_lua_parse_arguments_flags how, - const gchar *extraction_pattern, ...) + const char *extraction_pattern, ...) { - const gchar *p, *key = NULL, *end, *cls; + const char *p, *key = NULL, *end, *cls; va_list ap; gboolean required = FALSE, failed = FALSE, is_table; enum { @@ -1337,7 +1337,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, read_semicolon } state = read_key; gsize keylen = 0, *valuelen, clslen; - gint idx = 0, t, direct_userdata = 0; + int idx = 0, t, direct_userdata = 0; g_assert(extraction_pattern != NULL); @@ -1395,16 +1395,16 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, switch (*p) { case 'S': if (t == LUA_TSTRING) { - *(va_arg(ap, const gchar **)) = lua_tostring(L, idx); + *(va_arg(ap, const char **)) = lua_tostring(L, idx); } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { - *(va_arg(ap, const gchar **)) = NULL; + *(va_arg(ap, const char **)) = NULL; } else { - (void) va_arg(ap, gchar **); + (void) va_arg(ap, char **); } } else { @@ -1413,7 +1413,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 1, "bad type for key:" " %.*s: '%s', '%s' is expected", - (gint) keylen, + (int) keylen, key, lua_typename(L, lua_type(L, idx)), "string"); va_end(ap); @@ -1445,7 +1445,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 1, "bad type for key:" " %.*s: '%s', '%s' is expected", - (gint) keylen, + (int) keylen, key, lua_typename(L, lua_type(L, idx)), "int64"); @@ -1477,7 +1477,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 1, "bad type for key:" " %.*s: '%s', '%s' is expected", - (gint) keylen, + (int) keylen, key, lua_typename(L, lua_type(L, idx)), "int64"); @@ -1496,16 +1496,16 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, lua_pushvalue(L, idx); } - *(va_arg(ap, gint *)) = luaL_ref(L, LUA_REGISTRYINDEX); + *(va_arg(ap, int *)) = luaL_ref(L, LUA_REGISTRYINDEX); } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { - *(va_arg(ap, gint *)) = -1; + *(va_arg(ap, int *)) = -1; } else { - (void) va_arg(ap, gint *); + (void) va_arg(ap, int *); } if (is_table) { @@ -1518,7 +1518,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 1, "bad type for key:" " %.*s: '%s', '%s' is expected", - (gint) keylen, + (int) keylen, key, lua_typename(L, lua_type(L, idx)), "function"); @@ -1550,7 +1550,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 1, "bad type for key:" " %.*s: '%s', '%s' is expected", - (gint) keylen, + (int) keylen, key, lua_typename(L, lua_type(L, idx)), "bool"); @@ -1566,16 +1566,16 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, case 'N': if (t == LUA_TNUMBER) { - *(va_arg(ap, gdouble *)) = lua_tonumber(L, idx); + *(va_arg(ap, double *)) = lua_tonumber(L, idx); } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { - *(va_arg(ap, gdouble *)) = 0; + *(va_arg(ap, double *)) = 0; } else { - (void) va_arg(ap, gdouble *); + (void) va_arg(ap, double *); } } else { @@ -1584,7 +1584,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 1, "bad type for key:" " %.*s: '%s', '%s' is expected", - (gint) keylen, + (int) keylen, key, lua_typename(L, lua_type(L, idx)), "double"); @@ -1600,16 +1600,16 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, case 'D': if (t == LUA_TNUMBER) { - *(va_arg(ap, gdouble *)) = lua_tonumber(L, idx); + *(va_arg(ap, double *)) = lua_tonumber(L, idx); } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) { - *(va_arg(ap, gdouble *)) = NAN; + *(va_arg(ap, double *)) = NAN; } else { - (void) va_arg(ap, gdouble *); + (void) va_arg(ap, double *); } } else { @@ -1618,7 +1618,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 1, "bad type for key:" " %.*s: '%s', '%s' is expected", - (gint) keylen, + (int) keylen, key, lua_typename(L, lua_type(L, idx)), "double"); @@ -1636,8 +1636,8 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, valuelen = va_arg(ap, gsize *); if (t == LUA_TSTRING) { - *(va_arg(ap, const gchar **)) = lua_tolstring(L, idx, - valuelen); + *(va_arg(ap, const char **)) = lua_tolstring(L, idx, + valuelen); } else if (t == LUA_TNIL || t == LUA_TNONE) { failed = TRUE; @@ -1656,7 +1656,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 1, "bad type for key:" " %.*s: '%s', '%s' is expected", - (gint) keylen, + (int) keylen, key, lua_typename(L, lua_type(L, idx)), "string"); @@ -1706,7 +1706,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 1, "bad type for key:" " %.*s: '%s', '%s' is expected", - (gint) keylen, + (int) keylen, key, lua_typename(L, lua_type(L, idx)), "int64"); @@ -1738,7 +1738,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 1, "bad type for key:" " %.*s: '%s', '%s' is expected", - (gint) keylen, + (int) keylen, key, lua_typename(L, lua_type(L, idx)), "int64"); @@ -1761,7 +1761,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, if (failed && required) { g_set_error(err, lua_error_quark(), 2, "required parameter " "%.*s is missing", - (gint) keylen, key); + (int) keylen, key); va_end(ap); return FALSE; @@ -1792,7 +1792,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, g_set_error(err, lua_error_quark(), 2, "missing classname for " "%.*s", - (gint) keylen, key); + (int) keylen, key); va_end(ap); return FALSE; @@ -1813,7 +1813,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 2, "empty classname for " "%*.s", - (gint) keylen, + (int) keylen, key); va_end(ap); @@ -1843,7 +1843,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, lua_error_quark(), 2, "invalid class for key %.*s, expected %s, got %s", - (gint) keylen, + (int) keylen, key, static_cls, rspamd_lua_class_tostring_buf(L, FALSE, idx)); @@ -1866,7 +1866,7 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, 2, "required parameter " "%.*s is missing", - (gint) keylen, + (int) keylen, key); va_end(ap); @@ -1912,9 +1912,9 @@ rspamd_lua_parse_table_arguments(lua_State *L, gint pos, static void rspamd_lua_traceback_string(lua_State *L, luaL_Buffer *buf) { - gint i = 1, r; + int i = 1, r; lua_Debug d; - gchar tmp[256]; + char tmp[256]; while (lua_getstack(L, i++, &d)) { lua_getinfo(L, "nSl", &d); @@ -1925,7 +1925,7 @@ rspamd_lua_traceback_string(lua_State *L, luaL_Buffer *buf) } } -gint rspamd_lua_traceback(lua_State *L) +int rspamd_lua_traceback(lua_State *L) { luaL_Buffer b; @@ -1938,7 +1938,7 @@ gint rspamd_lua_traceback(lua_State *L) void rspamd_lua_get_traceback_string(lua_State *L, luaL_Buffer *buf) { - const gchar *msg = lua_tostring(L, -1); + const char *msg = lua_tostring(L, -1); if (msg) { luaL_addstring(buf, msg); @@ -1952,9 +1952,9 @@ void rspamd_lua_get_traceback_string(lua_State *L, luaL_Buffer *buf) rspamd_lua_traceback_string(L, buf); } -guint rspamd_lua_table_size(lua_State *L, gint tbl_pos) +unsigned int rspamd_lua_table_size(lua_State *L, int tbl_pos) { - guint tbl_size = 0; + unsigned int tbl_size = 0; if (!lua_istable(L, tbl_pos)) { return 0; @@ -1970,11 +1970,11 @@ guint rspamd_lua_table_size(lua_State *L, gint tbl_pos) } static void * -rspamd_lua_check_udata_common(lua_State *L, gint pos, const gchar *classname, +rspamd_lua_check_udata_common(lua_State *L, int pos, const char *classname, gboolean fatal) { void *p = lua_touserdata(L, pos); - gint i, top = lua_gettop(L); + int i, top = lua_gettop(L); if (p == NULL) { goto err; @@ -2008,7 +2008,7 @@ rspamd_lua_check_udata_common(lua_State *L, gint pos, const gchar *classname, err: if (fatal) { - const gchar *actual_classname = NULL; + const char *actual_classname = NULL; if (lua_type(L, pos) == LUA_TUSERDATA && lua_getmetatable(L, pos)) { lua_pushstring(L, "__index"); @@ -2022,8 +2022,8 @@ err: } luaL_Buffer buf; - gchar tmp[512]; - gint r; + char tmp[512]; + int r; luaL_buffinit(L, &buf); r = rspamd_snprintf(tmp, sizeof(tmp), @@ -2071,19 +2071,19 @@ err: } void * -rspamd_lua_check_udata(lua_State *L, gint pos, const gchar *classname) +rspamd_lua_check_udata(lua_State *L, int pos, const char *classname) { return rspamd_lua_check_udata_common(L, pos, classname, TRUE); } void * -rspamd_lua_check_udata_maybe(lua_State *L, gint pos, const gchar *classname) +rspamd_lua_check_udata_maybe(lua_State *L, int pos, const char *classname) { return rspamd_lua_check_udata_common(L, pos, classname, FALSE); } struct rspamd_async_session * -lua_check_session(lua_State *L, gint pos) +lua_check_session(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_session_classname); luaL_argcheck(L, ud != NULL, pos, "'session' expected"); @@ -2091,7 +2091,7 @@ lua_check_session(lua_State *L, gint pos) } struct ev_loop * -lua_check_ev_base(lua_State *L, gint pos) +lua_check_ev_base(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_ev_base_classname); luaL_argcheck(L, ud != NULL, pos, "'event_base' expected"); @@ -2141,7 +2141,7 @@ void rspamd_lua_run_config_post_init(lua_State *L, struct rspamd_config *cfg) LL_FOREACH(cfg->post_init_scripts, sc) { lua_pushcfunction(L, &rspamd_lua_traceback); - gint err_idx = lua_gettop(L); + int err_idx = lua_gettop(L); lua_rawgeti(L, LUA_REGISTRYINDEX, sc->cbref); pcfg = lua_newuserdata(L, sizeof(*pcfg)); @@ -2166,7 +2166,7 @@ void rspamd_lua_run_config_unload(lua_State *L, struct rspamd_config *cfg) LL_FOREACH(cfg->config_unload_scripts, sc) { lua_pushcfunction(L, &rspamd_lua_traceback); - gint err_idx = lua_gettop(L); + int err_idx = lua_gettop(L); lua_rawgeti(L, LUA_REGISTRYINDEX, sc->cbref); pcfg = lua_newuserdata(L, sizeof(*pcfg)); @@ -2193,7 +2193,7 @@ rspamd_lua_run_postloads_error(struct thread_entry *thread, int ret, const char struct rspamd_lua_ref_cbdata { lua_State *L; - gint cbref; + int cbref; }; static void @@ -2205,7 +2205,7 @@ rspamd_lua_ref_dtor(gpointer p) } void rspamd_lua_add_ref_dtor(lua_State *L, rspamd_mempool_t *pool, - gint ref) + int ref) { struct rspamd_lua_ref_cbdata *cbdata; @@ -2219,10 +2219,10 @@ void rspamd_lua_add_ref_dtor(lua_State *L, rspamd_mempool_t *pool, } gboolean -rspamd_lua_require_function(lua_State *L, const gchar *modname, - const gchar *funcname) +rspamd_lua_require_function(lua_State *L, const char *modname, + const char *funcname) { - gint table_pos, err_pos; + int table_pos, err_pos; lua_pushcfunction(L, &rspamd_lua_traceback); err_pos = lua_gettop(L); @@ -2291,10 +2291,10 @@ rspamd_lua_require_function(lua_State *L, const gchar *modname, } } -gint rspamd_lua_function_ref_from_str(lua_State *L, const gchar *str, gsize slen, - const gchar *modname, GError **err) +int rspamd_lua_function_ref_from_str(lua_State *L, const char *str, gsize slen, + const char *modname, GError **err) { - gint err_idx, ref_idx; + int err_idx, ref_idx; lua_pushcfunction(L, &rspamd_lua_traceback); err_idx = lua_gettop(L); @@ -2347,9 +2347,9 @@ gint rspamd_lua_function_ref_from_str(lua_State *L, const gchar *str, gsize slen gboolean rspamd_lua_try_load_redis(lua_State *L, const ucl_object_t *obj, - struct rspamd_config *cfg, gint *ref_id) + struct rspamd_config *cfg, int *ref_id) { - gint err_idx; + int err_idx; struct rspamd_config **pcfg; lua_pushcfunction(L, &rspamd_lua_traceback); @@ -2402,7 +2402,7 @@ rspamd_lua_try_load_redis(lua_State *L, const ucl_object_t *obj, void rspamd_lua_push_full_word(lua_State *L, rspamd_stat_token_t *w) { - gint fl_cnt; + int fl_cnt; lua_createtable(L, 4, 0); @@ -2477,11 +2477,11 @@ void rspamd_lua_push_full_word(lua_State *L, rspamd_stat_token_t *w) lua_rawseti(L, -2, 4); } -gint rspamd_lua_push_words(lua_State *L, GArray *words, - enum rspamd_lua_words_type how) +int rspamd_lua_push_words(lua_State *L, GArray *words, + enum rspamd_lua_words_type how) { rspamd_stat_token_t *w; - guint i, cnt; + unsigned int i, cnt; lua_createtable(L, words->len, 0); @@ -2520,12 +2520,12 @@ gint rspamd_lua_push_words(lua_State *L, GArray *words, return 1; } -gchar * +char * rspamd_lua_get_module_name(lua_State *L) { lua_Debug d; - gchar *p; - gchar func_buf[128]; + char *p; + char func_buf[128]; if (lua_getstack(L, 1, &d) == 1) { (void) lua_getinfo(L, "Sl", &d); @@ -2551,12 +2551,12 @@ rspamd_lua_get_module_name(lua_State *L) return NULL; } -bool rspamd_lua_universal_pcall(lua_State *L, gint cbref, const gchar *strloc, - gint nret, const gchar *args, GError **err, ...) +bool rspamd_lua_universal_pcall(lua_State *L, int cbref, const char *strloc, + int nret, const char *args, GError **err, ...) { va_list ap; - const gchar *argp = args, *classname; - gint err_idx, nargs = 0; + const char *argp = args, *classname; + int err_idx, nargs = 0; gpointer *cls_ptr; gsize sz; @@ -2576,9 +2576,9 @@ bool rspamd_lua_universal_pcall(lua_State *L, gint cbref, const gchar *strloc, /* * Possible arguments * - i - lua_integer, argument - int64_t - * - n - lua_number, argument - gdouble - * - s - lua_string, argument - const gchar * (zero terminated) - * - l - lua_lstring, argument - (size_t + const gchar *) pair + * - n - lua_number, argument - double + * - s - lua_string, argument - const char * (zero terminated) + * - l - lua_lstring, argument - (size_t + const char *) pair * - u - lua_userdata, argument - (const char * + void *) - classname + pointer * - b - lua_boolean, argument - gboolean (not bool due to varargs promotion) * - f - lua_function, argument - int - position of the function on stack (not lua_registry) @@ -2591,16 +2591,16 @@ bool rspamd_lua_universal_pcall(lua_State *L, gint cbref, const gchar *strloc, nargs++; break; case 'n': - lua_pushnumber(L, va_arg(ap, gdouble)); + lua_pushnumber(L, va_arg(ap, double)); nargs++; break; case 's': - lua_pushstring(L, va_arg(ap, const gchar *)); + lua_pushstring(L, va_arg(ap, const char *)); nargs++; break; case 'l': sz = va_arg(ap, gsize); - lua_pushlstring(L, va_arg(ap, const gchar *), sz); + lua_pushlstring(L, va_arg(ap, const char *), sz); nargs++; break; case 'b': @@ -2608,7 +2608,7 @@ bool rspamd_lua_universal_pcall(lua_State *L, gint cbref, const gchar *strloc, nargs++; break; case 'u': - classname = va_arg(ap, const gchar *); + classname = va_arg(ap, const char *); cls_ptr = (gpointer *) lua_newuserdata(L, sizeof(gpointer)); *cls_ptr = va_arg(ap, gpointer); rspamd_lua_setclass(L, classname, -1); @@ -2616,7 +2616,7 @@ bool rspamd_lua_universal_pcall(lua_State *L, gint cbref, const gchar *strloc, break; case 'f': case 't': - lua_pushvalue(L, va_arg(ap, gint)); + lua_pushvalue(L, va_arg(ap, int)); nargs++; break; default: @@ -2649,7 +2649,7 @@ bool rspamd_lua_universal_pcall(lua_State *L, gint cbref, const gchar *strloc, } #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 502 -gint rspamd_lua_geti(lua_State *L, int pos, int i) +int rspamd_lua_geti(lua_State *L, int pos, int i) { pos = lua_absindex(L, pos); lua_pushinteger(L, i); diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 03465cc90..198735c66 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -62,7 +62,7 @@ extern "C" { #if LUA_VERSION_NUM > 501 && !defined LUA_COMPAT_MODULE static inline void -luaL_register(lua_State *L, const gchar *name, const struct luaL_reg *methods) +luaL_register(lua_State *L, const char *name, const struct luaL_reg *methods) { if (name != NULL) { lua_newtable(L); @@ -114,9 +114,9 @@ struct rspamd_lua_ip { #define RSPAMD_TEXT_FLAG_FAKE (1u << 4u) #define RSPAMD_TEXT_FLAG_BINARY (1u << 5u) struct rspamd_lua_text { - const gchar *start; - guint len; - guint flags; + const char *start; + unsigned int len; + unsigned int flags; }; struct rspamd_lua_url { @@ -125,9 +125,9 @@ struct rspamd_lua_url { struct rspamd_lua_regexp { rspamd_regexp_t *re; - gchar *module; - gchar *re_pattern; - gint re_flags; + char *module; + char *re_pattern; + int re_flags; }; struct rspamd_map; @@ -149,7 +149,7 @@ enum rspamd_lua_map_type { struct rspamd_lua_map { struct rspamd_map *map; enum rspamd_lua_map_type type; - guint flags; + unsigned int flags; union { struct rspamd_radix_map_helper *radix; @@ -162,7 +162,7 @@ struct rspamd_lua_map { struct rspamd_lua_upstream { struct upstream *up; - gint upref; + int upref; }; /* Common utility functions */ @@ -171,7 +171,7 @@ struct rspamd_lua_upstream { * Create and register new class */ void rspamd_lua_new_class(lua_State *L, - const gchar *classname, + const char *classname, const struct luaL_reg *methods); /** @@ -179,14 +179,14 @@ void rspamd_lua_new_class(lua_State *L, * @param L * @param classname **MUST BE STATIC**, direct address is used for comparisons! */ -void rspamd_lua_setclass(lua_State *L, const gchar *classname, gint objidx); +void rspamd_lua_setclass(lua_State *L, const char *classname, int objidx); /** * Pushes the metatable for specific class on top of the stack * @param L * @param classname */ -void rspamd_lua_class_metatable(lua_State *L, const gchar *classname); +void rspamd_lua_class_metatable(lua_State *L, const char *classname); /** * Adds a new field to the class (metatable) identified by `classname` @@ -194,28 +194,28 @@ void rspamd_lua_class_metatable(lua_State *L, const gchar *classname); * @param classname * @param meth */ -void rspamd_lua_add_metamethod(lua_State *L, const gchar *classname, +void rspamd_lua_add_metamethod(lua_State *L, const char *classname, luaL_Reg *meth); /** * Set index of table to value (like t['index'] = value) */ -void rspamd_lua_table_set(lua_State *L, const gchar *index, const gchar *value); +void rspamd_lua_table_set(lua_State *L, const char *index, const char *value); /** * Get string value of index in a table (return t['index']) */ -const gchar *rspamd_lua_table_get(lua_State *L, const gchar *index); +const char *rspamd_lua_table_get(lua_State *L, const char *index); /** * Convert classname to string */ -gint rspamd_lua_class_tostring(lua_State *L); +int rspamd_lua_class_tostring(lua_State *L); /** * Check whether the argument at specified index is of the specified class */ -gpointer rspamd_lua_check_class(lua_State *L, gint index, const gchar *name); +gpointer rspamd_lua_check_class(lua_State *L, int index, const char *name); /** * Initialize lua and bindings @@ -237,8 +237,8 @@ void rspamd_lua_start_gc(struct rspamd_config *cfg); * @param field_name * @param new_elt */ -void rspamd_plugins_table_push_elt(lua_State *L, const gchar *field_name, - const gchar *new_elt); +void rspamd_plugins_table_push_elt(lua_State *L, const char *field_name, + const char *new_elt); /** * Load and initialize lua plugins @@ -260,9 +260,9 @@ void rspamd_lua_task_push(lua_State *L, struct rspamd_task *task); /** * Return lua ip structure at the specified address */ -struct rspamd_lua_ip *lua_check_ip(lua_State *L, gint pos); +struct rspamd_lua_ip *lua_check_ip(lua_State *L, int pos); -struct rspamd_lua_text *lua_check_text(lua_State *L, gint pos); +struct rspamd_lua_text *lua_check_text(lua_State *L, int pos); /** * Checks for a text or a string. In case of string a pointer to static structure is returned. * So it should not be reused or placed to Lua stack anyhow! @@ -271,7 +271,7 @@ struct rspamd_lua_text *lua_check_text(lua_State *L, gint pos); * @param pos * @return */ -struct rspamd_lua_text *lua_check_text_or_string(lua_State *L, gint pos); +struct rspamd_lua_text *lua_check_text_or_string(lua_State *L, int pos); /** * Create new text object * @param L @@ -280,7 +280,7 @@ struct rspamd_lua_text *lua_check_text_or_string(lua_State *L, gint pos); * @param own * @return */ -struct rspamd_lua_text *lua_new_text(lua_State *L, const gchar *start, +struct rspamd_lua_text *lua_new_text(lua_State *L, const char *start, gsize len, gboolean own); /** * Create new text object from task pool if allocation is needed @@ -292,7 +292,7 @@ struct rspamd_lua_text *lua_new_text(lua_State *L, const gchar *start, * @return */ struct rspamd_lua_text *lua_new_text_task(lua_State *L, struct rspamd_task *task, - const gchar *start, gsize len, gboolean own); + const char *start, gsize len, gboolean own); /** * Checks if a text has binary characters (non ascii and non-utf8 characters) * @param t @@ -300,7 +300,7 @@ struct rspamd_lua_text *lua_new_text_task(lua_State *L, struct rspamd_task *task */ bool lua_is_text_binary(struct rspamd_lua_text *t); -struct rspamd_lua_regexp *lua_check_regexp(lua_State *L, gint pos); +struct rspamd_lua_regexp *lua_check_regexp(lua_State *L, int pos); struct rspamd_lua_upstream *lua_check_upstream(lua_State *L, int pos); @@ -312,32 +312,32 @@ enum rspamd_lua_task_header_type { RSPAMD_TASK_HEADER_PUSH_HAS, }; -gint rspamd_lua_push_header(lua_State *L, - struct rspamd_mime_header *h, - enum rspamd_lua_task_header_type how); +int rspamd_lua_push_header(lua_State *L, + struct rspamd_mime_header *h, + enum rspamd_lua_task_header_type how); /** * Push specific header to lua */ -gint rspamd_lua_push_header_array(lua_State *L, - const gchar *name, - struct rspamd_mime_header *rh, - enum rspamd_lua_task_header_type how, - gboolean strong); +int rspamd_lua_push_header_array(lua_State *L, + const char *name, + struct rspamd_mime_header *rh, + enum rspamd_lua_task_header_type how, + gboolean strong); /** * Check for task at the specified position */ -struct rspamd_task *lua_check_task(lua_State *L, gint pos); +struct rspamd_task *lua_check_task(lua_State *L, int pos); -struct rspamd_task *lua_check_task_maybe(lua_State *L, gint pos); +struct rspamd_task *lua_check_task_maybe(lua_State *L, int pos); -struct rspamd_lua_map *lua_check_map(lua_State *L, gint pos); +struct rspamd_lua_map *lua_check_map(lua_State *L, int pos); /** * Push ip address from a string (nil is pushed if a string cannot be converted) */ -void rspamd_lua_ip_push_fromstring(lua_State *L, const gchar *ip_str); +void rspamd_lua_ip_push_fromstring(lua_State *L, const char *ip_str); /** * Create type error @@ -350,7 +350,7 @@ int rspamd_lua_typerror(lua_State *L, int narg, const char *tname); /** * Add preload function */ -void rspamd_lua_add_preload(lua_State *L, const gchar *name, lua_CFunction func); +void rspamd_lua_add_preload(lua_State *L, const char *name, lua_CFunction func); void luaopen_task(lua_State *L); @@ -422,7 +422,7 @@ void luaopen_tensor(lua_State *L); void luaopen_parsers(lua_State *L); -void rspamd_lua_dostring(const gchar *line); +void rspamd_lua_dostring(const char *line); double rspamd_lua_normalize(struct rspamd_config *cfg, long double score, @@ -443,17 +443,17 @@ gboolean rspamd_lua_set_env(lua_State *L, GHashTable *vars, char **lua_env, void rspamd_lua_set_globals(struct rspamd_config *cfg, lua_State *L); -struct memory_pool_s *rspamd_lua_check_mempool(lua_State *L, gint pos); +struct memory_pool_s *rspamd_lua_check_mempool(lua_State *L, int pos); -struct rspamd_config *lua_check_config(lua_State *L, gint pos); +struct rspamd_config *lua_check_config(lua_State *L, int pos); -struct rspamd_async_session *lua_check_session(lua_State *L, gint pos); +struct rspamd_async_session *lua_check_session(lua_State *L, int pos); -struct ev_loop *lua_check_ev_base(lua_State *L, gint pos); +struct ev_loop *lua_check_ev_base(lua_State *L, int pos); -struct rspamd_dns_resolver *lua_check_dns_resolver(lua_State *L, gint pos); +struct rspamd_dns_resolver *lua_check_dns_resolver(lua_State *L, int pos); -struct rspamd_lua_url *lua_check_url(lua_State *L, gint pos); +struct rspamd_lua_url *lua_check_url(lua_State *L, int pos); enum rspamd_lua_parse_arguments_flags { RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT = 0, @@ -483,13 +483,13 @@ enum rspamd_lua_parse_arguments_flags { * @param extraction_pattern static pattern * @return TRUE if a table has been parsed */ -gboolean rspamd_lua_parse_table_arguments(lua_State *L, gint pos, +gboolean rspamd_lua_parse_table_arguments(lua_State *L, int pos, GError **err, enum rspamd_lua_parse_arguments_flags how, - const gchar *extraction_pattern, ...); + const char *extraction_pattern, ...); -gint rspamd_lua_traceback(lua_State *L); +int rspamd_lua_traceback(lua_State *L); /** * Returns stack trace as a string. Caller should clear memory. @@ -501,7 +501,7 @@ void rspamd_lua_get_traceback_string(lua_State *L, luaL_Buffer *buf); /** * Returns size of table at position `tbl_pos` */ -guint rspamd_lua_table_size(lua_State *L, gint tbl_pos); +unsigned int rspamd_lua_table_size(lua_State *L, int tbl_pos); void lua_push_emails_address_list(lua_State *L, GPtrArray *addrs, int flags); @@ -509,7 +509,7 @@ void lua_push_emails_address_list(lua_State *L, GPtrArray *addrs, int flags); #define TRACE_POINTS 6 struct lua_logger_trace { - gint cur_level; + int cur_level; gconstpointer traces[TRACE_POINTS]; }; @@ -531,7 +531,7 @@ enum lua_logger_escape_type { * @param len * @return */ -gsize lua_logger_out_type(lua_State *L, gint pos, gchar *outbuf, +gsize lua_logger_out_type(lua_State *L, int pos, char *outbuf, gsize len, struct lua_logger_trace *trace, enum lua_logger_escape_type esc_type); @@ -541,7 +541,7 @@ gsize lua_logger_out_type(lua_State *L, gint pos, gchar *outbuf, * @param pos * @param classname **MUST BE STATIC**, direct address is used for comparisons! */ -void *rspamd_lua_check_udata(lua_State *L, gint pos, const gchar *classname); +void *rspamd_lua_check_udata(lua_State *L, int pos, const char *classname); #define RSPAMD_LUA_CHECK_UDATA_PTR_OR_RETURN(L, pos, classname, type, dest) \ do { \ @@ -558,7 +558,7 @@ void *rspamd_lua_check_udata(lua_State *L, gint pos, const gchar *classname); * @param pos * @param classname **MUST BE STATIC**, direct address is used for comparisons! */ -void *rspamd_lua_check_udata_maybe(lua_State *L, gint pos, const gchar *classname); +void *rspamd_lua_check_udata_maybe(lua_State *L, int pos, const char *classname); /** * Call finishing script with the specified task @@ -588,7 +588,7 @@ void rspamd_lua_run_config_unload(lua_State *L, struct rspamd_config *cfg); * @param ref */ void rspamd_lua_add_ref_dtor(lua_State *L, rspamd_mempool_t *pool, - gint ref); + int ref); /** * Returns a lua reference from a function like string, e.g. `return function(...) end` @@ -596,8 +596,8 @@ void rspamd_lua_add_ref_dtor(lua_State *L, rspamd_mempool_t *pool, * @param str * @return */ -gint rspamd_lua_function_ref_from_str(lua_State *L, const gchar *str, gsize slen, - const gchar *modname, GError **err); +int rspamd_lua_function_ref_from_str(lua_State *L, const char *str, gsize slen, + const char *modname, GError **err); /** * Tries to load some module using `require` and get some method from it @@ -606,8 +606,8 @@ gint rspamd_lua_function_ref_from_str(lua_State *L, const gchar *str, gsize slen * @param funcname * @return TRUE if function exists in that module, the function is pushed in stack, otherwise stack is unchanged and FALSE is returned */ -gboolean rspamd_lua_require_function(lua_State *L, const gchar *modname, - const gchar *funcname); +gboolean rspamd_lua_require_function(lua_State *L, const char *modname, + const char *funcname); /** * Tries to load redis server definition from ucl object specified @@ -617,7 +617,7 @@ gboolean rspamd_lua_require_function(lua_State *L, const gchar *modname, * @return */ gboolean rspamd_lua_try_load_redis(lua_State *L, const ucl_object_t *obj, - struct rspamd_config *cfg, gint *ref_id); + struct rspamd_config *cfg, int *ref_id); struct rspamd_stat_token_s; @@ -642,22 +642,22 @@ enum rspamd_lua_words_type { * @param words * @param how */ -gint rspamd_lua_push_words(lua_State *L, GArray *words, - enum rspamd_lua_words_type how); +int rspamd_lua_push_words(lua_State *L, GArray *words, + enum rspamd_lua_words_type how); /** * Returns newly allocated name for caller module name * @param L * @return */ -gchar *rspamd_lua_get_module_name(lua_State *L); +char *rspamd_lua_get_module_name(lua_State *L); /** * Call Lua function in a universal way. Arguments string: * - i - lua_integer, argument - int64_t -* - n - lua_number, argument - gdouble -* - s - lua_string, argument - const gchar * (zero terminated) -* - l - lua_lstring, argument - (size_t + const gchar *) pair +* - n - lua_number, argument - double +* - s - lua_string, argument - const char * (zero terminated) +* - l - lua_lstring, argument - (size_t + const char *) pair * - u - lua_userdata, argument - (const char * + void *) - classname + pointer * - b - lua_boolean, argument - gboolean (not bool due to varargs promotion) * - f - lua_function, argument - int - position of the function on stack (not lua_registry) @@ -671,8 +671,8 @@ gchar *rspamd_lua_get_module_name(lua_State *L); * @param ... arguments * @return true of pcall returned 0, false + err otherwise */ -bool rspamd_lua_universal_pcall(lua_State *L, gint cbref, const gchar *strloc, - gint nret, const gchar *args, GError **err, ...); +bool rspamd_lua_universal_pcall(lua_State *L, int cbref, const char *strloc, + int nret, const char *args, GError **err, ...); /** * Returns true if lua is initialised @@ -688,7 +688,7 @@ bool rspamd_lua_is_initialised(void); * @return */ #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 502 -gint rspamd_lua_geti(lua_State *L, int index, int i); +int rspamd_lua_geti(lua_State *L, int index, int i); #else #define rspamd_lua_geti lua_geti #endif diff --git a/src/lua/lua_compress.c b/src/lua/lua_compress.c index 39776ccf6..4a348404c 100644 --- a/src/lua/lua_compress.c +++ b/src/lua/lua_compress.c @@ -67,7 +67,7 @@ static const struct luaL_reg zstd_decompress_lib_m[] = { {NULL, NULL}}; static ZSTD_CStream * -lua_check_zstd_compress_ctx(lua_State *L, gint pos) +lua_check_zstd_compress_ctx(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_zstd_compress_classname); luaL_argcheck(L, ud != NULL, pos, "'zstd_compress' expected"); @@ -75,7 +75,7 @@ lua_check_zstd_compress_ctx(lua_State *L, gint pos) } static ZSTD_DStream * -lua_check_zstd_decompress_ctx(lua_State *L, gint pos) +lua_check_zstd_decompress_ctx(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_zstd_decompress_classname); luaL_argcheck(L, ud != NULL, pos, "'zstd_decompress' expected"); @@ -90,12 +90,12 @@ int lua_zstd_push_error(lua_State *L, int err) return 2; } -gint lua_compress_zstd_compress(lua_State *L) +int lua_compress_zstd_compress(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t = NULL, *res; gsize sz, r; - gint comp_level = 1; + int comp_level = 1; t = lua_check_text_or_string(L, 1); @@ -135,7 +135,7 @@ gint lua_compress_zstd_compress(lua_State *L) return 1; } -gint lua_compress_zstd_decompress(lua_State *L) +int lua_compress_zstd_decompress(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t = NULL, *res; @@ -143,7 +143,7 @@ gint lua_compress_zstd_decompress(lua_State *L) ZSTD_DStream *zstream; ZSTD_inBuffer zin; ZSTD_outBuffer zout; - gchar *out; + char *out; t = lua_check_text_or_string(L, 1); @@ -200,14 +200,14 @@ gint lua_compress_zstd_decompress(lua_State *L) return 2; } -gint lua_compress_zlib_decompress(lua_State *L, bool is_gzip) +int lua_compress_zlib_decompress(lua_State *L, bool is_gzip) { LUA_TRACE_POINT; struct rspamd_lua_text *t = NULL, *res; gsize sz; z_stream strm; - gint rc; - guchar *p; + int rc; + unsigned char *p; gsize remain; gssize size_limit = -1; @@ -249,14 +249,14 @@ gint lua_compress_zlib_decompress(lua_State *L, bool is_gzip) } strm.avail_in = t->len; - strm.next_in = (guchar *) t->start; + strm.next_in = (unsigned char *) t->start; res = lua_newuserdata(L, sizeof(*res)); res->start = g_malloc(sz); res->flags = RSPAMD_TEXT_FLAG_OWN; rspamd_lua_setclass(L, rspamd_text_classname, -1); - p = (guchar *) res->start; + p = (unsigned char *) res->start; remain = sz; while (strm.avail_in != 0) { @@ -298,7 +298,7 @@ gint lua_compress_zlib_decompress(lua_State *L, bool is_gzip) remain = res->len; res->start = g_realloc((gpointer) res->start, res->len * 2); sz = res->len * 2; - p = (guchar *) res->start + remain; + p = (unsigned char *) res->start + remain; remain = sz - remain; } } @@ -309,14 +309,14 @@ gint lua_compress_zlib_decompress(lua_State *L, bool is_gzip) return 1; } -gint lua_compress_zlib_compress(lua_State *L) +int lua_compress_zlib_compress(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t = NULL, *res; gsize sz; z_stream strm; - gint rc, comp_level = Z_DEFAULT_COMPRESSION; - guchar *p; + int rc, comp_level = Z_DEFAULT_COMPRESSION; + unsigned char *p; gsize remain; t = lua_check_text_or_string(L, 1); @@ -346,14 +346,14 @@ gint lua_compress_zlib_compress(lua_State *L) sz = deflateBound(&strm, t->len); strm.avail_in = t->len; - strm.next_in = (guchar *) t->start; + strm.next_in = (unsigned char *) t->start; res = lua_newuserdata(L, sizeof(*res)); res->start = g_malloc(sz); res->flags = RSPAMD_TEXT_FLAG_OWN; rspamd_lua_setclass(L, rspamd_text_classname, -1); - p = (guchar *) res->start; + p = (unsigned char *) res->start; remain = sz; while (strm.avail_in != 0) { @@ -384,7 +384,7 @@ gint lua_compress_zlib_compress(lua_State *L) remain = res->len; res->start = g_realloc((gpointer) res->start, strm.avail_in + sz); sz = strm.avail_in + sz; - p = (guchar *) res->start + remain; + p = (unsigned char *) res->start + remain; remain = sz - remain; } } @@ -404,7 +404,7 @@ static const char *const zstd_stream_op[] = { "end", NULL}; -static gint +static int lua_zstd_compress_ctx(lua_State *L) { ZSTD_CCtx *ctx, **pctx; @@ -421,7 +421,7 @@ lua_zstd_compress_ctx(lua_State *L) return 1; } -static gint +static int lua_zstd_compress_dtor(lua_State *L) { ZSTD_CCtx *ctx = lua_check_zstd_compress_ctx(L, 1); @@ -433,7 +433,7 @@ lua_zstd_compress_dtor(lua_State *L) return 0; } -static gint +static int lua_zstd_compress_reset(lua_State *L) { ZSTD_CCtx *ctx = lua_check_zstd_compress_ctx(L, 1); @@ -448,7 +448,7 @@ lua_zstd_compress_reset(lua_State *L) return 0; } -static gint +static int lua_zstd_compress_stream(lua_State *L) { ZSTD_CStream *ctx = lua_check_zstd_compress_ctx(L, 1); @@ -509,7 +509,7 @@ lua_zstd_compress_stream(lua_State *L) return 1; } -static gint +static int lua_zstd_decompress_dtor(lua_State *L) { ZSTD_DStream *ctx = lua_check_zstd_decompress_ctx(L, 1); @@ -522,7 +522,7 @@ lua_zstd_decompress_dtor(lua_State *L) } -static gint +static int lua_zstd_decompress_ctx(lua_State *L) { ZSTD_DStream *ctx, **pctx; @@ -539,7 +539,7 @@ lua_zstd_decompress_ctx(lua_State *L) return 1; } -static gint +static int lua_zstd_decompress_stream(lua_State *L) { ZSTD_DStream *ctx = lua_check_zstd_decompress_ctx(L, 1); @@ -603,7 +603,7 @@ lua_zstd_decompress_stream(lua_State *L) return 1; } -static gint +static int lua_load_zstd(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_compress.h b/src/lua/lua_compress.h index 34234de34..47e733d6d 100644 --- a/src/lua/lua_compress.h +++ b/src/lua/lua_compress.h @@ -23,10 +23,10 @@ extern "C" { #endif -gint lua_compress_zstd_compress(lua_State *L); -gint lua_compress_zstd_decompress(lua_State *L); -gint lua_compress_zlib_compress(lua_State *L); -gint lua_compress_zlib_decompress(lua_State *L, bool is_gzip); +int lua_compress_zstd_compress(lua_State *L); +int lua_compress_zstd_decompress(lua_State *L); +int lua_compress_zlib_compress(lua_State *L); +int lua_compress_zlib_decompress(lua_State *L, bool is_gzip); void luaopen_compress(lua_State *L); diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 1a3c1db20..f9a79eef1 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -945,7 +945,7 @@ static const struct luaL_reg monitoredlib_m[] = { static const uint64_t rspamd_lua_callback_magic = 0x32c118af1e3263c7ULL; struct rspamd_config * -lua_check_config(lua_State *L, gint pos) +lua_check_config(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_config_classname); luaL_argcheck(L, ud != NULL, pos, "'config' expected"); @@ -953,7 +953,7 @@ lua_check_config(lua_State *L, gint pos) } static struct rspamd_monitored * -lua_check_monitored(lua_State *L, gint pos) +lua_check_monitored(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_monitored_classname); luaL_argcheck(L, ud != NULL, pos, "'monitored' expected"); @@ -961,7 +961,7 @@ lua_check_monitored(lua_State *L, gint pos) } /*** Config functions ***/ -static gint +static int lua_config_get_api_version(lua_State *L) { msg_warn("get_api_version is deprecated, do not use it"); @@ -970,12 +970,12 @@ lua_config_get_api_version(lua_State *L) return 1; } -static gint +static int lua_config_get_module_opt(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *mname, *optname; + const char *mname, *optname; const ucl_object_t *obj; if (cfg) { @@ -1030,15 +1030,15 @@ lua_config_get_resolver(lua_State *L) return 1; } -static gint +static int lua_config_get_all_opt(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *mname; + const char *mname; const ucl_object_t *obj, *cur, *cur_elt; ucl_object_iter_t it = NULL; - gint i; + int i; if (cfg) { mname = luaL_checkstring(L, 2); @@ -1089,7 +1089,7 @@ lua_config_get_all_opt(lua_State *L) struct rspamd_lua_cached_config { lua_State *L; - gint ref; + int ref; }; static void @@ -1100,7 +1100,7 @@ lua_config_ucl_dtor(gpointer p) luaL_unref(cached->L, LUA_REGISTRYINDEX, cached->ref); } -static gint +static int lua_config_get_ucl(lua_State *L) { LUA_TRACE_POINT; @@ -1136,13 +1136,13 @@ lua_config_get_ucl(lua_State *L) } -static gint +static int lua_config_get_classifier(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); struct rspamd_classifier_config *clc = NULL, **pclc = NULL; - const gchar *name; + const char *name; GList *cur; if (cfg) { @@ -1173,17 +1173,17 @@ lua_config_get_classifier(lua_State *L) struct lua_callback_data { uint64_t magic; lua_State *L; - gchar *symbol; + char *symbol; union { - gchar *name; - gint ref; + char *name; + int ref; } callback; gboolean cb_is_ref; /* Dynamic data */ - gint stack_level; - gint order; + int stack_level; + int order; struct rspamd_symcache_dynamic_item *item; }; @@ -1201,13 +1201,13 @@ lua_destroy_cfg_symbol(gpointer ud) } } -static gint +static int lua_config_register_module_option(lua_State *L) { return 0; } -static gint +static int rspamd_compare_order_func(gconstpointer a, gconstpointer b) { const struct lua_callback_data *cb1 = a, *cb2 = b; @@ -1223,7 +1223,7 @@ lua_metric_symbol_callback(struct rspamd_task *task, { struct lua_callback_data *cd = ud; struct rspamd_task **ptask; - gint level = lua_gettop(cd->L), nresults, err_idx, ret; + int level = lua_gettop(cd->L), nresults, err_idx, ret; lua_State *L = cd->L; struct rspamd_symbol_result *s; @@ -1255,10 +1255,10 @@ lua_metric_symbol_callback(struct rspamd_task *task, if (nresults >= 1) { /* Function returned boolean, so maybe we need to insert result? */ - gint res = 0; - gint i; - gdouble flag = 1.0; - gint type; + int res = 0; + int i; + double flag = 1.0; + int type; type = lua_type(cd->L, level + 1); @@ -1280,7 +1280,7 @@ lua_metric_symbol_callback(struct rspamd_task *task, } if (res) { - gint first_opt = 2; + int first_opt = 2; if (lua_type(L, level + 2) == LUA_TNUMBER) { flag = lua_tonumber(L, level + 2); @@ -1294,7 +1294,7 @@ lua_metric_symbol_callback(struct rspamd_task *task, s = rspamd_task_insert_result(task, cd->symbol, flag, NULL); if (s) { - guint last_pos = lua_gettop(L); + unsigned int last_pos = lua_gettop(L); for (i = level + first_opt; i <= last_pos; i++) { if (lua_type(L, i) == LUA_TSTRING) { @@ -1314,7 +1314,7 @@ lua_metric_symbol_callback(struct rspamd_task *task, else if (lua_type(L, i) == LUA_TTABLE) { gsize objlen = rspamd_lua_table_size(L, i); - for (guint j = 1; j <= objlen; j++) { + for (unsigned int j = 1; j <= objlen; j++) { lua_rawgeti(L, i, j); if (lua_type(L, -1) == LUA_TSTRING) { @@ -1419,10 +1419,10 @@ lua_metric_symbol_callback_return(struct thread_entry *thread_entry, int ret) if (nresults >= 1) { /* Function returned boolean, so maybe we need to insert result? */ - gint res = 0; - gint i; - gdouble flag = 1.0; - gint type; + int res = 0; + int i; + double flag = 1.0; + int type; type = lua_type(L, cd->stack_level + 1); @@ -1437,7 +1437,7 @@ lua_metric_symbol_callback_return(struct thread_entry *thread_entry, int ret) } if (res) { - gint first_opt = 2; + int first_opt = 2; if (lua_type(L, cd->stack_level + 2) == LUA_TNUMBER) { flag = lua_tonumber(L, cd->stack_level + 2); @@ -1451,7 +1451,7 @@ lua_metric_symbol_callback_return(struct thread_entry *thread_entry, int ret) s = rspamd_task_insert_result(task, cd->symbol, flag, NULL); if (s) { - guint last_pos = lua_gettop(L); + unsigned int last_pos = lua_gettop(L); for (i = cd->stack_level + first_opt; i <= last_pos; i++) { if (lua_type(L, i) == LUA_TSTRING) { @@ -1471,7 +1471,7 @@ lua_metric_symbol_callback_return(struct thread_entry *thread_entry, int ret) else if (lua_type(L, i) == LUA_TTABLE) { gsize objlen = rspamd_lua_table_size(L, i); - for (guint j = 1; j <= objlen; j++) { + for (unsigned int j = 1; j <= objlen; j++) { lua_rawgeti(L, i, j); if (lua_type(L, -1) == LUA_TSTRING) { @@ -1506,16 +1506,16 @@ lua_metric_symbol_callback_return(struct thread_entry *thread_entry, int ret) } static GArray * -rspamd_process_id_list(const gchar *entries) +rspamd_process_id_list(const char *entries) { - gchar **sym_elts; + char **sym_elts; GArray *ret; sym_elts = g_strsplit_set(entries, ",;", -1); - guint nids = g_strv_length(sym_elts); + unsigned int nids = g_strv_length(sym_elts); ret = g_array_sized_new(FALSE, FALSE, sizeof(uint32_t), nids); - for (guint i = 0; i < nids; i++) { + for (unsigned int i = 0; i < nids; i++) { uint32_t v = rspamd_config_name_to_id(sym_elts[i], strlen(sym_elts[i])); g_array_append_val(ret, v); } @@ -1525,21 +1525,21 @@ rspamd_process_id_list(const gchar *entries) return ret; } -static gint +static int rspamd_register_symbol_fromlua(lua_State *L, struct rspamd_config *cfg, - const gchar *name, - gint ref, - gdouble weight, - gint priority, + const char *name, + int ref, + double weight, + int priority, enum rspamd_symbol_type type, - gint parent, + int parent, GArray *allowed_ids, GArray *forbidden_ids, gboolean optional) { struct lua_callback_data *cd; - gint ret = -1; + int ret = -1; if (priority == 0 && weight < 0) { priority = 1; @@ -1624,12 +1624,12 @@ rspamd_register_symbol_fromlua(lua_State *L, return ret; } -static gint +static int lua_config_register_post_filter(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - gint order = 0, cbref, ret; + int order = 0, cbref, ret; if (cfg) { if (lua_type(L, 3) == LUA_TNUMBER) { @@ -1669,12 +1669,12 @@ lua_config_register_post_filter(lua_State *L) return 1; } -static gint +static int lua_config_register_pre_filter(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - gint order = 0, cbref, ret; + int order = 0, cbref, ret; if (cfg) { if (lua_type(L, 3) == LUA_TNUMBER) { @@ -1714,12 +1714,12 @@ lua_config_register_pre_filter(lua_State *L) return 1; } -static gint +static int lua_config_get_key(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *name; + const char *name; size_t namelen; const ucl_object_t *val; @@ -1740,10 +1740,10 @@ lua_config_get_key(lua_State *L) return 1; } -static guint -lua_parse_symbol_flags(const gchar *str) +static unsigned int +lua_parse_symbol_flags(const char *str) { - guint ret = 0; + unsigned int ret = 0; if (str) { if (strstr(str, "fine") != NULL) { @@ -1790,12 +1790,12 @@ lua_parse_symbol_flags(const gchar *str) return ret; } -static guint -lua_parse_symbol_type(const gchar *str) +static unsigned int +lua_parse_symbol_type(const char *str) { - guint ret = SYMBOL_TYPE_NORMAL; - gchar **vec; - guint i, l; + unsigned int ret = SYMBOL_TYPE_NORMAL; + char **vec; + unsigned int i, l; if (str) { vec = g_strsplit_set(str, ",;", -1); @@ -1837,7 +1837,7 @@ lua_parse_symbol_type(const gchar *str) SYMBOL_TYPE_IDEMPOTENT | SYMBOL_TYPE_CALLBACK; } else { - gint fl = 0; + int fl = 0; fl = lua_parse_symbol_flags(str); @@ -1879,9 +1879,9 @@ enum lua_push_symbol_flags_opts { } while (0) static void -lua_push_symbol_flags(lua_State *L, guint flags, enum lua_push_symbol_flags_opts fl) +lua_push_symbol_flags(lua_State *L, unsigned int flags, enum lua_push_symbol_flags_opts fl) { - guint i = 1; + unsigned int i = 1; if (LUA_SYMOPT_IS_CREATE(fl)) { lua_newtable(L); @@ -1932,12 +1932,12 @@ lua_push_symbol_flags(lua_State *L, guint flags, enum lua_push_symbol_flags_opts } } -static gint +static int lua_config_get_symbol_flags(lua_State *L) { struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *name = luaL_checkstring(L, 2); - guint flags; + const char *name = luaL_checkstring(L, 2); + unsigned int flags; if (cfg && name) { flags = rspamd_symcache_get_symbol_flags(cfg->cache, @@ -1957,17 +1957,17 @@ lua_config_get_symbol_flags(lua_State *L) return 1; } -static gint +static int lua_config_register_symbol(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *name = NULL, *type_str = NULL, - *description = NULL, *group = NULL; + const char *name = NULL, *type_str = NULL, + *description = NULL, *group = NULL; double weight = 0, score = NAN, parent_float = NAN; gboolean one_shot = FALSE; - gint ret = -1, cbref = -1; - guint type = 0, flags = 0; + int ret = -1, cbref = -1; + unsigned int type = 0, flags = 0; int64_t parent = 0, priority = 0, nshots = 0; GArray *allowed_ids = NULL, *forbidden_ids = NULL; GError *err = NULL; @@ -2163,14 +2163,14 @@ lua_config_register_symbol(lua_State *L) return 1; } -static gint +static int lua_config_register_symbols(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - gint i, top, idx, ret = -1; - const gchar *sym; - gdouble weight = 1.0; + int i, top, idx, ret = -1; + const char *sym; + double weight = 1.0; if (lua_gettop(L) < 3) { if (cfg) { @@ -2237,14 +2237,14 @@ lua_config_register_symbols(lua_State *L) return 1; } -static gint +static int lua_config_register_virtual_symbol(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *name; + const char *name; double weight; - gint ret = -1, parent = -1; + int ret = -1, parent = -1; if (cfg) { name = luaL_checkstring(L, 2); @@ -2266,14 +2266,14 @@ lua_config_register_virtual_symbol(lua_State *L) return 1; } -static gint +static int lua_config_register_callback_symbol(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *name = NULL; + const char *name = NULL; double weight; - gint ret = -1, top = 2; + int ret = -1, top = 2; if (cfg) { if (lua_type(L, 2) == LUA_TSTRING) { @@ -2307,14 +2307,14 @@ lua_config_register_callback_symbol(lua_State *L) return 1; } -static gint +static int lua_config_register_callback_symbol_priority(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *name = NULL; + const char *name = NULL; double weight; - gint priority, ret = -1, top = 2; + int priority, ret = -1, top = 2; if (cfg) { if (lua_type(L, 2) == LUA_TSTRING) { @@ -2351,13 +2351,13 @@ lua_config_register_callback_symbol_priority(lua_State *L) } -static gint +static int lua_config_register_dependency(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *parent = NULL, *child = NULL; - gint child_id; + const char *parent = NULL, *child = NULL; + int child_id; if (cfg == NULL) { lua_error(L); @@ -2384,18 +2384,18 @@ lua_config_register_dependency(lua_State *L) return 0; } -static gint +static int lua_config_set_metric_symbol(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *description = NULL, - *group = NULL, *name = NULL, *flags_str = NULL; + const char *description = NULL, + *group = NULL, *name = NULL, *flags_str = NULL; double score; gboolean one_shot = FALSE, one_param = FALSE; GError *err = NULL; - gdouble priority = 0.0; - guint flags = 0; + double priority = 0.0; + unsigned int flags = 0; int64_t nshots = 0; if (cfg) { @@ -2457,7 +2457,7 @@ lua_config_set_metric_symbol(lua_State *L) } rspamd_config_add_symbol(cfg, name, - score, description, group, flags, (guint) priority, nshots); + score, description, group, flags, (unsigned int) priority, nshots); if (lua_type(L, 2) == LUA_TTABLE) { @@ -2486,15 +2486,15 @@ lua_config_set_metric_symbol(lua_State *L) return 0; } -static gint +static int lua_config_set_metric_action(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *name = NULL; + const char *name = NULL; double threshold = NAN; GError *err = NULL; - gdouble priority = 0.0; + double priority = 0.0; ucl_object_t *obj_tbl = NULL; if (cfg) { @@ -2551,12 +2551,12 @@ lua_config_set_metric_action(lua_State *L) return 0; } -static gint +static int lua_config_get_metric_action(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *act_name = luaL_checkstring(L, 2); + const char *act_name = luaL_checkstring(L, 2); struct rspamd_action *act; if (cfg && act_name) { @@ -2593,7 +2593,7 @@ lua_config_actions_cb(struct rspamd_action *act, void *cbd) } } -static gint +static int lua_config_get_all_actions(lua_State *L) { LUA_TRACE_POINT; @@ -2610,13 +2610,13 @@ lua_config_get_all_actions(lua_State *L) return 1; } -static gint +static int lua_config_add_composite(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - gchar *name; - const gchar *expr_str; + char *name; + const char *expr_str; struct rspamd_composite *composite; gboolean ret = FALSE; @@ -2641,15 +2641,15 @@ lua_config_add_composite(lua_State *L) return 1; } -static gint +static int lua_config_newindex(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *name; + const char *name; GArray *allowed_ids = NULL, *forbidden_ids = NULL; - gint id, nshots; - guint flags = 0; + int id, nshots; + unsigned int flags = 0; gboolean optional = FALSE; name = luaL_checkstring(L, 2); @@ -2671,9 +2671,9 @@ lua_config_newindex(lua_State *L) FALSE); } else if (lua_type(L, 3) == LUA_TTABLE) { - guint type = SYMBOL_TYPE_NORMAL, priority = 0; - gint idx; - gdouble weight = 1.0, score = NAN; + unsigned int type = SYMBOL_TYPE_NORMAL, priority = 0; + int idx; + double weight = 1.0, score = NAN; const char *type_str, *group = NULL, *description = NULL; /* @@ -2803,7 +2803,7 @@ lua_config_newindex(lua_State *L) lua_gettable(L, -2); if (lua_type(L, -1) == LUA_TFUNCTION) { - gint condref; + int condref; /* Here we pop function from the stack, so no lua_pop is required */ condref = luaL_ref(L, LUA_REGISTRYINDEX); @@ -2965,14 +2965,14 @@ lua_config_newindex(lua_State *L) return 0; } -static gint +static int lua_config_add_condition(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *sym = luaL_checkstring(L, 2); + const char *sym = luaL_checkstring(L, 2); gboolean ret = FALSE; - gint condref; + int condref; if (cfg && sym && lua_type(L, 3) == LUA_TFUNCTION) { lua_pushvalue(L, 3); @@ -2990,12 +2990,12 @@ lua_config_add_condition(lua_State *L) return 1; } -static gint +static int lua_config_set_peak_cb(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - gint condref; + int condref; if (cfg && lua_type(L, 2) == LUA_TFUNCTION) { lua_pushvalue(L, 2); @@ -3007,7 +3007,7 @@ lua_config_set_peak_cb(lua_State *L) return 0; } -static gint +static int lua_config_enable_symbol(lua_State *L) { struct rspamd_config *cfg = lua_check_config(L, 1); @@ -3022,7 +3022,7 @@ lua_config_enable_symbol(lua_State *L) return 0; } -static gint +static int lua_config_disable_symbol(lua_State *L) { struct rspamd_config *cfg = lua_check_config(L, 1); @@ -3037,14 +3037,14 @@ lua_config_disable_symbol(lua_State *L) return 0; } -static gint +static int lua_config_register_regexp(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); struct rspamd_lua_regexp *re = NULL; rspamd_regexp_t *cache_re; - const gchar *type_str = NULL, *header_str = NULL; + const char *type_str = NULL, *header_str = NULL; gsize header_len = 0; GError *err = NULL; enum rspamd_re_type type = RSPAMD_RE_BODY; @@ -3125,7 +3125,7 @@ lua_config_register_regexp(lua_State *L) return 0; } -static gint +static int lua_config_replace_regexp(lua_State *L) { LUA_TRACE_POINT; @@ -3139,8 +3139,8 @@ lua_config_replace_regexp(lua_State *L) RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "*old_re=U{regexp};*new_re=U{regexp};pcre_only=B", &old_re, &new_re, &pcre_only)) { - gint ret = luaL_error(L, "cannot get parameters list: %s", - err ? err->message : "invalid arguments"); + int ret = luaL_error(L, "cannot get parameters list: %s", + err ? err->message : "invalid arguments"); if (err) { g_error_free(err); @@ -3162,12 +3162,12 @@ lua_config_replace_regexp(lua_State *L) return 0; } -static gint +static int lua_config_register_worker_script(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *worker_type = luaL_checkstring(L, 2), *wtype; + const char *worker_type = luaL_checkstring(L, 2), *wtype; struct rspamd_worker_conf *cf; GList *cur; struct rspamd_worker_lua_script *sc; @@ -3195,7 +3195,7 @@ lua_config_register_worker_script(lua_State *L) return 1; } -static gint +static int lua_config_add_on_load(lua_State *L) { LUA_TRACE_POINT; @@ -3222,15 +3222,15 @@ rspamd_post_init_sc_sort(const struct rspamd_config_cfg_lua_script *pra, return prb->priority - pra->priority; } -static gint +static int lua_config_add_post_init(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); struct rspamd_config_cfg_lua_script *sc; - guint priority = 0; + unsigned int priority = 0; lua_Debug d; - gchar tmp[256], *p; + char tmp[256], *p; if (cfg == NULL || lua_type(L, 2) != LUA_TFUNCTION) { return luaL_error(L, "invalid arguments"); @@ -3270,14 +3270,14 @@ lua_config_add_post_init(lua_State *L) return 0; } -static gint +static int lua_config_add_config_unload(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); struct rspamd_config_cfg_lua_script *sc; lua_Debug d; - gchar tmp[256], *p; + char tmp[256], *p; if (cfg == NULL || lua_type(L, 2) != LUA_TFUNCTION) { return luaL_error(L, "invalid arguments"); @@ -3318,11 +3318,11 @@ static void lua_periodic_callback_error(struct thread_entry *thread, int ret, co struct rspamd_lua_periodic { struct ev_loop *event_loop; struct rspamd_config *cfg; - gchar *lua_src_pos; + char *lua_src_pos; lua_State *L; - gdouble timeout; + double timeout; ev_timer ev; - gint cbref; + int cbref; gboolean need_jitter; ref_entry_t ref; }; @@ -3378,7 +3378,7 @@ lua_periodic_callback_finish(struct thread_entry *thread, int ret) lua_State *L; struct rspamd_lua_periodic *periodic = thread->cd; gboolean plan_more = FALSE; - gdouble timeout = 0.0; + double timeout = 0.0; L = thread->lua_state; @@ -3433,17 +3433,17 @@ lua_periodic_callback_error(struct thread_entry *thread, int ret, const char *ms } -static gint +static int lua_config_add_periodic(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); struct ev_loop *ev_base = lua_check_ev_base(L, 2); - gdouble timeout = lua_tonumber(L, 3); + double timeout = lua_tonumber(L, 3); struct rspamd_lua_periodic *periodic; gboolean need_jitter = FALSE; lua_Debug d; - gchar tmp[256], *p; + char tmp[256], *p; if (cfg == NULL || timeout < 0 || lua_type(L, 4) != LUA_TFUNCTION) { return luaL_error(L, "invalid arguments"); @@ -3497,12 +3497,12 @@ lua_config_add_periodic(lua_State *L) return 0; } -static gint +static int lua_config_get_symbols_count(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - guint res = 0; + unsigned int res = 0; if (cfg != NULL) { res = rspamd_symcache_stats_symbols_count(cfg->cache); @@ -3516,7 +3516,7 @@ lua_config_get_symbols_count(lua_State *L) return 1; } -static gint +static int lua_config_get_symbols_cksum(lua_State *L) { LUA_TRACE_POINT; @@ -3537,7 +3537,7 @@ lua_config_get_symbols_cksum(lua_State *L) return 1; } -static gint +static int lua_config_get_symbols_counters(lua_State *L) { LUA_TRACE_POINT; @@ -3567,10 +3567,10 @@ lua_metric_symbol_inserter(gpointer k, gpointer v, gpointer ud) { struct lua_metric_symbols_cbdata *cbd = (struct lua_metric_symbols_cbdata *) ud; lua_State *L; - const gchar *sym = k; + const char *sym = k; struct rspamd_symbol *s = (struct rspamd_symbol *) v; struct rspamd_symbols_group *gr; - gint i; + int i; L = cbd->L; @@ -3611,13 +3611,13 @@ lua_metric_symbol_inserter(gpointer k, gpointer v, gpointer ud) } if (s->cache_item) { - guint sflags = rspamd_symcache_get_symbol_flags(cbd->cfg->cache, sym); + unsigned int sflags = rspamd_symcache_get_symbol_flags(cbd->cfg->cache, sym); lua_push_symbol_flags(L, sflags, LUA_SYMOPT_FLAG_USE_MAP); - guint nids; - const guint *allowed_ids = rspamd_symcache_get_allowed_settings_ids(cbd->cfg->cache, - sym, &nids); + unsigned int nids; + const unsigned int *allowed_ids = rspamd_symcache_get_allowed_settings_ids(cbd->cfg->cache, + sym, &nids); if (allowed_ids && nids > 0) { lua_createtable(L, nids, 0); @@ -3630,7 +3630,7 @@ lua_metric_symbol_inserter(gpointer k, gpointer v, gpointer ud) lua_setfield(L, -2, "allowed_ids"); } - const guint *forbidden_ids = rspamd_symcache_get_forbidden_settings_ids( + const unsigned int *forbidden_ids = rspamd_symcache_get_forbidden_settings_ids( cbd->cfg->cache, sym, &nids); @@ -3680,7 +3680,7 @@ lua_metric_symbol_inserter(gpointer k, gpointer v, gpointer ud) } } -static gint +static int lua_config_get_symbols(lua_State *L) { LUA_TRACE_POINT; @@ -3705,12 +3705,12 @@ lua_config_get_symbols(lua_State *L) return 1; } -static gint +static int lua_config_get_symbol(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *sym_name = luaL_checkstring(L, 2); + const char *sym_name = luaL_checkstring(L, 2); if (cfg != NULL && sym_name != NULL) { struct lua_metric_symbols_cbdata cbd; @@ -3734,12 +3734,12 @@ lua_config_get_symbol(lua_State *L) return 1; } -static gint +static int lua_config_get_symbol_callback(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *sym = luaL_checkstring(L, 2); + const char *sym = luaL_checkstring(L, 2); struct rspamd_abstract_callback_data *abs_cbdata; struct lua_callback_data *cbd; @@ -3767,12 +3767,12 @@ lua_config_get_symbol_callback(lua_State *L) return 1; } -static gint +static int lua_config_set_symbol_callback(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *sym = luaL_checkstring(L, 2); + const char *sym = luaL_checkstring(L, 2); struct rspamd_abstract_callback_data *abs_cbdata; struct lua_callback_data *cbd; @@ -3804,14 +3804,14 @@ lua_config_set_symbol_callback(lua_State *L) return 1; } -static gint +static int lua_config_get_symbol_stat(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *sym = luaL_checkstring(L, 2); - gdouble freq, stddev, tm; - guint hits; + const char *sym = luaL_checkstring(L, 2); + double freq, stddev, tm; + unsigned int hits; if (cfg != NULL && sym != NULL) { if (!rspamd_symcache_stat_symbol(cfg->cache, sym, &freq, @@ -3841,12 +3841,12 @@ lua_config_get_symbol_stat(lua_State *L) return 1; } -static gint +static int lua_config_get_symbol_parent(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *sym = luaL_checkstring(L, 2), *parent; + const char *sym = luaL_checkstring(L, 2), *parent; if (cfg != NULL && sym != NULL) { parent = rspamd_symcache_get_parent(cfg->cache, sym); @@ -3865,12 +3865,12 @@ lua_config_get_symbol_parent(lua_State *L) return 1; } -static gint +static int lua_config_get_group_symbols(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *gr_name = luaL_checkstring(L, 2); + const char *gr_name = luaL_checkstring(L, 2); if (cfg != NULL && gr_name != NULL) { struct rspamd_symbols_group *group; @@ -3881,7 +3881,7 @@ lua_config_get_group_symbols(lua_State *L) lua_pushnil(L); } else { - guint i = 1; + unsigned int i = 1; gpointer k, v; GHashTableIter it; @@ -3902,7 +3902,7 @@ lua_config_get_group_symbols(lua_State *L) return 1; } -static gint +static int lua_config_get_groups(lua_State *L) { LUA_TRACE_POINT; @@ -3949,7 +3949,7 @@ lua_config_get_groups(lua_State *L) return 1; } -static gint +static int lua_config_register_finish_script(lua_State *L) { LUA_TRACE_POINT; @@ -3993,12 +3993,12 @@ rspamd_lua_config_check_settings_symbols_object(const ucl_object_t *obj) return false; } -static gint +static int lua_config_register_settings_id(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *settings_name = luaL_checkstring(L, 2); + const char *settings_name = luaL_checkstring(L, 2); if (cfg != NULL && settings_name) { ucl_object_t *sym_enabled, *sym_disabled; @@ -4023,7 +4023,7 @@ lua_config_register_settings_id(lua_State *L) /* Check policy */ if (lua_isstring(L, 5)) { - const gchar *policy_str = lua_tostring(L, 5); + const char *policy_str = lua_tostring(L, 5); if (strcmp(policy_str, "default") == 0) { policy = RSPAMD_SETTINGS_POLICY_DEFAULT; @@ -4063,13 +4063,13 @@ lua_config_register_settings_id(lua_State *L) return 0; } -static gint +static int lua_config_register_monitored(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); struct rspamd_monitored *m, **pm; - const gchar *url, *type; + const char *url, *type; ucl_object_t *params = NULL; url = lua_tostring(L, 2); @@ -4115,13 +4115,13 @@ lua_config_register_monitored(lua_State *L) return 1; } -static gint +static int lua_config_add_doc(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg; - const gchar *path = NULL, *option, *doc_string; - const gchar *type_str = NULL, *default_value = NULL; + const char *path = NULL, *option, *doc_string; + const char *type_str = NULL, *default_value = NULL; ucl_type_t type = UCL_NULL; gboolean required = FALSE; GError *err = NULL; @@ -4165,12 +4165,12 @@ lua_config_add_doc(lua_State *L) return 0; } -static gint +static int lua_config_add_example(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg; - const gchar *path = NULL, *option, *doc_string, *example; + const char *path = NULL, *option, *doc_string, *example; gsize example_len; cfg = lua_check_config(L, 1); @@ -4195,7 +4195,7 @@ lua_config_add_example(lua_State *L) return 0; } -static gint +static int lua_config_get_cpu_flags(lua_State *L) { LUA_TRACE_POINT; @@ -4249,7 +4249,7 @@ lua_config_get_cpu_flags(lua_State *L) return 1; } -static gint +static int lua_config_has_torch(lua_State *L) { msg_warn("use of the obsoleted `has_torch` function"); @@ -4258,7 +4258,7 @@ lua_config_has_torch(lua_State *L) return 1; } -static gint +static int lua_config_experimental_enabled(lua_State *L) { LUA_TRACE_POINT; @@ -4276,7 +4276,7 @@ lua_config_experimental_enabled(lua_State *L) struct rspamd_lua_include_trace_cbdata { lua_State *L; - gint cbref; + int cbref; }; static void @@ -4289,7 +4289,7 @@ lua_include_trace_cb(struct ucl_parser *parser, { struct rspamd_lua_include_trace_cbdata *cbdata = (struct rspamd_lua_include_trace_cbdata *) user_data; - gint err_idx; + int err_idx; lua_State *L; L = cbdata->L; @@ -4333,11 +4333,11 @@ lua_include_trace_cb(struct ucl_parser *parser, lua_pop(L, 1); \ } while (0) -static gint +static int lua_config_load_ucl(lua_State *L) { struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *filename; + const char *filename; GHashTable *paths = g_hash_table_new_full(rspamd_str_hash, rspamd_str_equal, NULL, g_free); GError *err = NULL; @@ -4415,7 +4415,7 @@ lua_config_load_ucl(lua_State *L) #undef IDX_TO_HASH -static gint +static int lua_config_parse_rcl(lua_State *L) { LUA_TRACE_POINT; @@ -4460,7 +4460,7 @@ lua_config_parse_rcl(lua_State *L) return 1; } -static gint +static int lua_config_init_modules(lua_State *L) { LUA_TRACE_POINT; @@ -4477,14 +4477,14 @@ lua_config_init_modules(lua_State *L) return 1; } -static gint +static int lua_config_init_subsystem(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *subsystem = luaL_checkstring(L, 2); - gchar **parts; - guint nparts, i; + const char *subsystem = luaL_checkstring(L, 2); + char **parts; + unsigned int nparts, i; if (cfg != NULL && subsystem != NULL) { parts = g_strsplit_set(subsystem, ";,", -1); @@ -4540,16 +4540,16 @@ lua_config_init_subsystem(lua_State *L) return 0; } -static gint +static int lua_config_register_re_selector(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *name = luaL_checkstring(L, 2); - const gchar *selector_str = luaL_checkstring(L, 3); - const gchar *delimiter = ""; + const char *name = luaL_checkstring(L, 2); + const char *selector_str = luaL_checkstring(L, 3); + const char *delimiter = ""; bool flatten = false; - gint top = lua_gettop(L); + int top = lua_gettop(L); bool res = false; if (cfg && name && selector_str) { @@ -4581,7 +4581,7 @@ lua_config_register_re_selector(lua_State *L) lua_typename(L, lua_type(L, -1))); } else { - gint err_idx, ret; + int err_idx, ret; struct rspamd_config **pcfg; lua_pushcfunction(L, &rspamd_lua_traceback); @@ -4635,7 +4635,7 @@ lua_config_register_re_selector(lua_State *L) return 1; } -static gint +static int lua_config_get_tld_path(lua_State *L) { LUA_TRACE_POINT; @@ -4651,7 +4651,7 @@ lua_config_get_tld_path(lua_State *L) return 1; } -static gint +static int lua_config_get_dns_max_requests(lua_State *L) { LUA_TRACE_POINT; @@ -4667,7 +4667,7 @@ lua_config_get_dns_max_requests(lua_State *L) return 1; } -static gint +static int lua_config_get_dns_timeout(lua_State *L) { LUA_TRACE_POINT; @@ -4683,7 +4683,7 @@ lua_config_get_dns_timeout(lua_State *L) return 1; } -static gint +static int lua_monitored_alive(lua_State *L) { LUA_TRACE_POINT; @@ -4699,7 +4699,7 @@ lua_monitored_alive(lua_State *L) return 1; } -static gint +static int lua_monitored_offline(lua_State *L) { LUA_TRACE_POINT; @@ -4715,7 +4715,7 @@ lua_monitored_offline(lua_State *L) return 1; } -static gint +static int lua_monitored_total_offline(lua_State *L) { LUA_TRACE_POINT; @@ -4731,7 +4731,7 @@ lua_monitored_total_offline(lua_State *L) return 1; } -static gint +static int lua_monitored_latency(lua_State *L) { LUA_TRACE_POINT; diff --git a/src/lua/lua_cryptobox.c b/src/lua/lua_cryptobox.c index 35f5986f1..bad7d7024 100644 --- a/src/lua/lua_cryptobox.c +++ b/src/lua/lua_cryptobox.c @@ -204,7 +204,7 @@ static const struct luaL_reg cryptoboxsecretboxlib_m[] = { }; struct rspamd_lua_cryptobox_secretbox { - guchar sk[crypto_secretbox_KEYBYTES]; + unsigned char sk[crypto_secretbox_KEYBYTES]; }; static struct rspamd_cryptobox_pubkey * @@ -260,15 +260,15 @@ lua_check_cryptobox_secretbox(lua_State *L, int pos) * @param {string} alg optional 'default' or 'nist' for curve25519/nistp256 keys * @return {cryptobox_pubkey} new public key */ -static gint +static int lua_cryptobox_pubkey_load(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_pubkey *pkey = NULL, **ppkey; - const gchar *filename, *arg; - gint type = RSPAMD_KEYPAIR_SIGN; - gint alg = RSPAMD_CRYPTOBOX_MODE_25519; - guchar *map; + const char *filename, *arg; + int type = RSPAMD_KEYPAIR_SIGN; + int alg = RSPAMD_CRYPTOBOX_MODE_25519; + unsigned char *map; gsize len; filename = luaL_checkstring(L, 1); @@ -336,15 +336,15 @@ lua_cryptobox_pubkey_load(lua_State *L) * @param {string} alg optional 'default' or 'nist' for curve25519/nistp256 keys * @return {cryptobox_pubkey} new public key */ -static gint +static int lua_cryptobox_pubkey_create(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_pubkey *pkey = NULL, **ppkey; - const gchar *buf, *arg; + const char *buf, *arg; gsize len; - gint type = RSPAMD_KEYPAIR_SIGN; - gint alg = RSPAMD_CRYPTOBOX_MODE_25519; + int type = RSPAMD_KEYPAIR_SIGN; + int alg = RSPAMD_CRYPTOBOX_MODE_25519; buf = luaL_checklstring(L, 1, &len); if (buf != NULL) { @@ -390,7 +390,7 @@ lua_cryptobox_pubkey_create(lua_State *L) return 1; } -static gint +static int lua_cryptobox_pubkey_gc(lua_State *L) { LUA_TRACE_POINT; @@ -409,12 +409,12 @@ lua_cryptobox_pubkey_gc(lua_State *L) * @param {string} file filename to load * @return {cryptobox_keypair} new keypair */ -static gint +static int lua_cryptobox_keypair_load(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_keypair *kp, **pkp; - const gchar *buf; + const char *buf; gsize len; struct ucl_parser *parser; ucl_object_t *obj; @@ -480,7 +480,7 @@ lua_cryptobox_keypair_load(lua_State *L) * @param {string} alg algorithm of keypair: 'curve25519' (default) or 'nist' * @return {cryptobox_keypair} new keypair */ -static gint +static int lua_cryptobox_keypair_create(lua_State *L) { LUA_TRACE_POINT; @@ -489,7 +489,7 @@ lua_cryptobox_keypair_create(lua_State *L) enum rspamd_cryptobox_mode alg = RSPAMD_CRYPTOBOX_MODE_25519; if (lua_isstring(L, 1)) { - const gchar *str = lua_tostring(L, 1); + const char *str = lua_tostring(L, 1); if (strcmp(str, "sign") == 0) { type = RSPAMD_KEYPAIR_SIGN; @@ -503,7 +503,7 @@ lua_cryptobox_keypair_create(lua_State *L) } if (lua_isstring(L, 2)) { - const gchar *str = lua_tostring(L, 2); + const char *str = lua_tostring(L, 2); if (strcmp(str, "nist") == 0 || strcmp(str, "openssl") == 0) { alg = RSPAMD_CRYPTOBOX_MODE_NIST; @@ -525,7 +525,7 @@ lua_cryptobox_keypair_create(lua_State *L) return 1; } -static gint +static int lua_cryptobox_keypair_gc(lua_State *L) { LUA_TRACE_POINT; @@ -542,14 +542,14 @@ lua_cryptobox_keypair_gc(lua_State *L) * @method keypair:totable([hex=false]]) * Converts keypair to table (not very safe due to memory leftovers) */ -static gint +static int lua_cryptobox_keypair_totable(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_keypair *kp = lua_check_cryptobox_keypair(L, 1); ucl_object_t *obj; gboolean hex = FALSE; - gint ret = 1; + int ret = 1; if (kp != NULL) { @@ -573,7 +573,7 @@ lua_cryptobox_keypair_totable(lua_State *L) * Returns type of keypair as a string: 'encryption' or 'sign' * @return {string} type of keypair as a string */ -static gint +static int lua_cryptobox_keypair_get_type(lua_State *L) { LUA_TRACE_POINT; @@ -599,7 +599,7 @@ lua_cryptobox_keypair_get_type(lua_State *L) * Returns algorithm of keypair as a string: 'encryption' or 'sign' * @return {string} type of keypair as a string */ -static gint +static int lua_cryptobox_keypair_get_alg(lua_State *L) { LUA_TRACE_POINT; @@ -625,14 +625,14 @@ lua_cryptobox_keypair_get_alg(lua_State *L) * Returns pubkey for a specific keypair * @return {rspamd_pubkey} pubkey for a keypair */ -static gint +static int lua_cryptobox_keypair_get_pk(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_keypair *kp = lua_check_cryptobox_keypair(L, 1); struct rspamd_cryptobox_pubkey *pk, **ppk; - const guchar *data; - guint dlen; + const unsigned char *data; + unsigned int dlen; if (kp) { data = rspamd_keypair_component(kp, RSPAMD_KEYPAIR_COMPONENT_PK, &dlen); @@ -659,12 +659,12 @@ lua_cryptobox_keypair_get_pk(lua_State *L) * @param {string} file filename to load * @return {cryptobox_signature} new signature */ -static gint +static int lua_cryptobox_signature_load(lua_State *L) { LUA_TRACE_POINT; rspamd_fstring_t *sig, **psig; - const gchar *filename; + const char *filename; gpointer data; int fd; struct stat st; @@ -687,7 +687,7 @@ lua_cryptobox_signature_load(lua_State *L) } else { if (lua_isstring(L, 2)) { - const gchar *str = lua_tostring(L, 2); + const char *str = lua_tostring(L, 2); if (strcmp(str, "nist") == 0 || strcmp(str, "openssl") == 0) { alg = RSPAMD_CRYPTOBOX_MODE_NIST; @@ -733,13 +733,13 @@ lua_cryptobox_signature_load(lua_State *L) * @param {string} file filename to use * @return {boolean} true if signature has been saved */ -static gint +static int lua_cryptobox_signature_save(lua_State *L) { LUA_TRACE_POINT; rspamd_fstring_t *sig; - gint fd, flags; - const gchar *filename; + int fd, flags; + const char *filename; gboolean forced = FALSE, res = TRUE; sig = lua_check_cryptobox_sign(L, 1); @@ -797,13 +797,13 @@ lua_cryptobox_signature_save(lua_State *L) * @param {data} raw signature data * @return {cryptobox_signature} signature object */ -static gint +static int lua_cryptobox_signature_create(lua_State *L) { LUA_TRACE_POINT; rspamd_fstring_t *sig, **psig; struct rspamd_lua_text *t; - const gchar *data; + const char *data; gsize dlen; if (lua_isuserdata(L, 1)) { @@ -840,12 +840,12 @@ lua_cryptobox_signature_create(lua_State *L) * Return hex encoded signature string * @return {string} raw value of signature */ -static gint +static int lua_cryptobox_signature_hex(lua_State *L) { LUA_TRACE_POINT; rspamd_fstring_t *sig = lua_check_cryptobox_sign(L, 1); - gchar *encoded; + char *encoded; if (sig) { encoded = rspamd_encode_hex(sig->str, sig->len); @@ -865,12 +865,12 @@ lua_cryptobox_signature_hex(lua_State *L) * @param {string} b32type base32 type (default, bleach, rfc) * @return {string} raw value of signature */ -static gint +static int lua_cryptobox_signature_base32(lua_State *L) { LUA_TRACE_POINT; rspamd_fstring_t *sig = lua_check_cryptobox_sign(L, 1); - gchar *encoded; + char *encoded; enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT; if (lua_type(L, 2) == LUA_TSTRING) { @@ -898,13 +898,13 @@ lua_cryptobox_signature_base32(lua_State *L) * Return base64 encoded signature string * @return {string} raw value of signature */ -static gint +static int lua_cryptobox_signature_base64(lua_State *L) { LUA_TRACE_POINT; rspamd_fstring_t *sig = lua_check_cryptobox_sign(L, 1); gsize dlen; - gchar *encoded; + char *encoded; if (sig) { encoded = rspamd_encode_base64(sig->str, sig->len, 0, &dlen); @@ -923,7 +923,7 @@ lua_cryptobox_signature_base64(lua_State *L) * Return raw signature string * @return {string} raw value of signature */ -static gint +static int lua_cryptobox_signature_bin(lua_State *L) { LUA_TRACE_POINT; @@ -939,7 +939,7 @@ lua_cryptobox_signature_bin(lua_State *L) return 1; } -static gint +static int lua_cryptobox_signature_gc(lua_State *L) { LUA_TRACE_POINT; @@ -1011,7 +1011,7 @@ lua_cryptobox_hash_dtor(struct rspamd_lua_cryptobox_hash *h) static inline void rspamd_lua_hash_init_default(struct rspamd_lua_cryptobox_hash *h, - const gchar *key, gsize keylen) + const char *key, gsize keylen) { h->type = LUA_CRYPTOBOX_HASH_BLAKE2; if (posix_memalign((void **) &h->content.h, @@ -1044,7 +1044,7 @@ rspamd_lua_ssl_hash_create(struct rspamd_lua_cryptobox_hash *h, const EVP_MD *ht static void rspamd_lua_ssl_hmac_create(struct rspamd_lua_cryptobox_hash *h, const EVP_MD *htype, - const gchar *key, gsize keylen, + const char *key, gsize keylen, bool insecure) { h->type = LUA_CRYPTOBOX_HASH_HMAC; @@ -1070,7 +1070,7 @@ rspamd_lua_ssl_hmac_create(struct rspamd_lua_cryptobox_hash *h, const EVP_MD *ht } static struct rspamd_lua_cryptobox_hash * -rspamd_lua_hash_create(const gchar *type, const gchar *key, gsize keylen) +rspamd_lua_hash_create(const char *type, const char *key, gsize keylen) { struct rspamd_lua_cryptobox_hash *h; @@ -1177,12 +1177,12 @@ rspamd_lua_hash_create(const gchar *type, const gchar *key, gsize keylen) * @param {string} data optional string to hash * @return {cryptobox_hash} hash object */ -static gint +static int lua_cryptobox_hash_create(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_cryptobox_hash *h, **ph; - const gchar *s = NULL; + const char *s = NULL; struct rspamd_lua_text *t; gsize len = 0; @@ -1221,12 +1221,12 @@ lua_cryptobox_hash_create(lua_State *L) * @param {string} string initial data * @return {cryptobox_hash} hash object */ -static gint +static int lua_cryptobox_hash_create_specific(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_cryptobox_hash *h, **ph; - const gchar *s = NULL, *type = luaL_checkstring(L, 1); + const char *s = NULL, *type = luaL_checkstring(L, 1); gsize len = 0; struct rspamd_lua_text *t; @@ -1272,12 +1272,12 @@ lua_cryptobox_hash_create_specific(lua_State *L) * @param {string} key key * @return {cryptobox_hash} hash object */ -static gint +static int lua_cryptobox_hash_create_keyed(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_cryptobox_hash *h, **ph; - const gchar *key, *s = NULL; + const char *key, *s = NULL; struct rspamd_lua_text *t; gsize len = 0; gsize keylen; @@ -1323,12 +1323,12 @@ lua_cryptobox_hash_create_keyed(lua_State *L) * @param {string} key key * @return {cryptobox_hash} hash object */ -static gint +static int lua_cryptobox_hash_create_specific_keyed(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_cryptobox_hash *h, **ph; - const gchar *key, *s = NULL, *type = luaL_checkstring(L, 2); + const char *key, *s = NULL, *type = luaL_checkstring(L, 2); struct rspamd_lua_text *t; gsize len = 0; gsize keylen; @@ -1378,12 +1378,12 @@ lua_cryptobox_hash_create_specific_keyed(lua_State *L) * Updates hash with the specified data (hash should not be finalized using `hex` or `bin` methods) * @param {string} data data to hash */ -static gint +static int lua_cryptobox_hash_update(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash(L, 1), **ph; - const gchar *data; + const char *data; struct rspamd_lua_text *t; gsize len; @@ -1436,7 +1436,7 @@ lua_cryptobox_hash_update(lua_State *L) * @method cryptobox_hash:reset() * Resets hash to the initial state */ -static gint +static int lua_cryptobox_hash_reset(lua_State *L) { LUA_TRACE_POINT; @@ -1501,8 +1501,8 @@ static void lua_cryptobox_hash_finish(struct rspamd_lua_cryptobox_hash *h) { uint64_t ll; - guchar out[rspamd_cryptobox_HASHBYTES]; - guint ssl_outlen = sizeof(out); + unsigned char out[rspamd_cryptobox_HASHBYTES]; + unsigned int ssl_outlen = sizeof(out); switch (h->type) { case LUA_CRYPTOBOX_HASH_BLAKE2: @@ -1541,13 +1541,13 @@ lua_cryptobox_hash_finish(struct rspamd_lua_cryptobox_hash *h) * Finalizes hash and return it as hex string * @return {string} hex value of hash */ -static gint +static int lua_cryptobox_hash_hex(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash(L, 1); - guchar out_hex[rspamd_cryptobox_HASHBYTES * 2 + 1], *r; - guint dlen; + unsigned char out_hex[rspamd_cryptobox_HASHBYTES * 2 + 1], *r; + unsigned int dlen; if (h) { if (!h->is_finished) { @@ -1559,7 +1559,7 @@ lua_cryptobox_hash_hex(lua_State *L) dlen = h->out_len; if (lua_isnumber(L, 2)) { - guint lim = lua_tonumber(L, 2); + unsigned int lim = lua_tonumber(L, 2); if (lim < dlen) { r += dlen - lim; @@ -1583,13 +1583,13 @@ lua_cryptobox_hash_hex(lua_State *L) * @param {string} b32type base32 type (default, bleach, rfc) * @return {string} base32 value of hash */ -static gint +static int lua_cryptobox_hash_base32(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash(L, 1); - guchar out_b32[rspamd_cryptobox_HASHBYTES * 2], *r; - guint dlen; + unsigned char out_b32[rspamd_cryptobox_HASHBYTES * 2], *r; + unsigned int dlen; if (h) { enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT; @@ -1611,7 +1611,7 @@ lua_cryptobox_hash_base32(lua_State *L) dlen = h->out_len; if (lua_isnumber(L, 2)) { - guint lim = lua_tonumber(L, 2); + unsigned int lim = lua_tonumber(L, 2); if (lim < dlen) { r += dlen - lim; @@ -1634,14 +1634,14 @@ lua_cryptobox_hash_base32(lua_State *L) * Finalizes hash and return it as base64 string * @return {string} base64 value of hash */ -static gint +static int lua_cryptobox_hash_base64(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash(L, 1); - guchar *b64, *r; + unsigned char *b64, *r; gsize len; - guint dlen; + unsigned int dlen; if (h) { if (!h->is_finished) { @@ -1652,7 +1652,7 @@ lua_cryptobox_hash_base64(lua_State *L) dlen = h->out_len; if (lua_isnumber(L, 2)) { - guint lim = lua_tonumber(L, 2); + unsigned int lim = lua_tonumber(L, 2); if (lim < dlen) { r += dlen - lim; @@ -1676,13 +1676,13 @@ lua_cryptobox_hash_base64(lua_State *L) * Finalizes hash and return it as raw string * @return {string} raw value of hash */ -static gint +static int lua_cryptobox_hash_bin(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash(L, 1); - guchar *r; - guint dlen; + unsigned char *r; + unsigned int dlen; if (h) { if (!h->is_finished) { @@ -1693,7 +1693,7 @@ lua_cryptobox_hash_bin(lua_State *L) dlen = h->out_len; if (lua_isnumber(L, 2)) { - guint lim = lua_tonumber(L, 2); + unsigned int lim = lua_tonumber(L, 2); if (lim < dlen) { r += dlen - lim; @@ -1711,7 +1711,7 @@ lua_cryptobox_hash_bin(lua_State *L) return 1; } -static gint +static int lua_cryptobox_hash_gc(lua_State *L) { LUA_TRACE_POINT; @@ -1730,17 +1730,17 @@ lua_cryptobox_hash_gc(lua_State *L) * @param {string} data data to check signature against * @return {boolean} `true` - if string matches cryptobox signature */ -static gint +static int lua_cryptobox_verify_memory(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_pubkey *pk; rspamd_fstring_t *signature; struct rspamd_lua_text *t; - const gchar *data; + const char *data; enum rspamd_cryptobox_mode alg = RSPAMD_CRYPTOBOX_MODE_25519; gsize len; - gint ret; + int ret; pk = lua_check_cryptobox_pubkey(L, 1); signature = lua_check_cryptobox_sign(L, 2); @@ -1760,7 +1760,7 @@ lua_cryptobox_verify_memory(lua_State *L) } if (lua_isstring(L, 4)) { - const gchar *str = lua_tostring(L, 4); + const char *str = lua_tostring(L, 4); if (strcmp(str, "nist") == 0 || strcmp(str, "openssl") == 0) { alg = RSPAMD_CRYPTOBOX_MODE_NIST; @@ -1799,24 +1799,24 @@ lua_cryptobox_verify_memory(lua_State *L) * @param {string} file to load data from * @return {boolean} `true` - if string matches cryptobox signature */ -static gint +static int lua_cryptobox_verify_file(lua_State *L) { LUA_TRACE_POINT; - const gchar *fname; + const char *fname; struct rspamd_cryptobox_pubkey *pk; rspamd_fstring_t *signature; - guchar *map = NULL; + unsigned char *map = NULL; enum rspamd_cryptobox_mode alg = RSPAMD_CRYPTOBOX_MODE_25519; gsize len; - gint ret; + int ret; pk = lua_check_cryptobox_pubkey(L, 1); signature = lua_check_cryptobox_sign(L, 2); fname = luaL_checkstring(L, 3); if (lua_isstring(L, 4)) { - const gchar *str = lua_tostring(L, 4); + const char *str = lua_tostring(L, 4); if (strcmp(str, "nist") == 0 || strcmp(str, "openssl") == 0) { alg = RSPAMD_CRYPTOBOX_MODE_NIST; @@ -1865,12 +1865,12 @@ lua_cryptobox_verify_file(lua_State *L) * @param {string} data * @return {cryptobox_signature} signature object */ -static gint +static int lua_cryptobox_sign_memory(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_keypair *kp; - const gchar *data; + const char *data; struct rspamd_lua_text *t; gsize len = 0; rspamd_fstring_t *sig, **psig; @@ -1918,13 +1918,13 @@ lua_cryptobox_sign_memory(lua_State *L) * @param {string} filename * @return {cryptobox_signature} signature object */ -static gint +static int lua_cryptobox_sign_file(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_keypair *kp; - const gchar *filename; - gchar *data; + const char *filename; + char *data; gsize len = 0; rspamd_fstring_t *sig, **psig; @@ -1967,14 +1967,14 @@ lua_cryptobox_sign_file(lua_State *L) * @param {string|text} data * @return {rspamd_text} encrypted text */ -static gint +static int lua_cryptobox_encrypt_memory(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_keypair *kp = NULL; struct rspamd_cryptobox_pubkey *pk = NULL; - const gchar *data; - guchar *out = NULL; + const char *data; + unsigned char *out = NULL; struct rspamd_lua_text *t, *res; gsize len = 0, outlen = 0; GError *err = NULL; @@ -1989,7 +1989,7 @@ lua_cryptobox_encrypt_memory(lua_State *L) } } else if (lua_type(L, 1) == LUA_TSTRING) { - const gchar *b32; + const char *b32; gsize blen; b32 = lua_tolstring(L, 1, &blen); @@ -2019,7 +2019,7 @@ lua_cryptobox_encrypt_memory(lua_State *L) if (kp) { if (!rspamd_keypair_encrypt(kp, data, len, &out, &outlen, &err)) { - gint ret = luaL_error(L, "cannot encrypt data: %s", err->message); + int ret = luaL_error(L, "cannot encrypt data: %s", err->message); g_error_free(err); if (owned_pk) { @@ -2031,7 +2031,7 @@ lua_cryptobox_encrypt_memory(lua_State *L) } else { if (!rspamd_pubkey_encrypt(pk, data, len, &out, &outlen, &err)) { - gint ret = luaL_error(L, "cannot encrypt data: %s", err->message); + int ret = luaL_error(L, "cannot encrypt data: %s", err->message); g_error_free(err); if (owned_pk) { @@ -2069,15 +2069,15 @@ err: * @param {string} filename * @return {rspamd_text} encrypted text */ -static gint +static int lua_cryptobox_encrypt_file(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_keypair *kp = NULL; struct rspamd_cryptobox_pubkey *pk = NULL; - const gchar *filename; - gchar *data = NULL; - guchar *out = NULL; + const char *filename; + char *data = NULL; + unsigned char *out = NULL; struct rspamd_lua_text *res; gsize len = 0, outlen = 0; GError *err = NULL; @@ -2092,7 +2092,7 @@ lua_cryptobox_encrypt_file(lua_State *L) } } else if (lua_type(L, 1) == LUA_TSTRING) { - const gchar *b32; + const char *b32; gsize blen; b32 = lua_tolstring(L, 1, &blen); @@ -2110,8 +2110,8 @@ lua_cryptobox_encrypt_file(lua_State *L) if (kp) { if (!rspamd_keypair_encrypt(kp, data, len, &out, &outlen, &err)) { - gint ret = luaL_error(L, "cannot encrypt file %s: %s", filename, - err->message); + int ret = luaL_error(L, "cannot encrypt file %s: %s", filename, + err->message); g_error_free(err); munmap(data, len); if (own_pk) { @@ -2123,8 +2123,8 @@ lua_cryptobox_encrypt_file(lua_State *L) } else if (pk) { if (!rspamd_pubkey_encrypt(pk, data, len, &out, &outlen, &err)) { - gint ret = luaL_error(L, "cannot encrypt file %s: %s", filename, - err->message); + int ret = luaL_error(L, "cannot encrypt file %s: %s", filename, + err->message); g_error_free(err); munmap(data, len); @@ -2165,13 +2165,13 @@ err: * @param {string} data * @return status,{rspamd_text}|error status is boolean variable followed by either unencrypted data or an error message */ -static gint +static int lua_cryptobox_decrypt_memory(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_keypair *kp; - const gchar *data; - guchar *out; + const char *data; + unsigned char *out; struct rspamd_lua_text *t, *res; gsize len = 0, outlen; GError *err = NULL; @@ -2221,14 +2221,14 @@ lua_cryptobox_decrypt_memory(lua_State *L) * @param {string} filename * @return status,{rspamd_text}|error status is boolean variable followed by either unencrypted data or an error message */ -static gint +static int lua_cryptobox_decrypt_file(lua_State *L) { LUA_TRACE_POINT; struct rspamd_cryptobox_keypair *kp; - const gchar *filename; - gchar *data; - guchar *out; + const char *filename; + char *data; + unsigned char *out; struct rspamd_lua_text *res; gsize len = 0, outlen; GError *err = NULL; @@ -2280,19 +2280,19 @@ lua_cryptobox_decrypt_file(lua_State *L) * @param {string} secret_cookie secret cookie as a string for up to 31 character * @return {string} e function value for this sk and cookie */ -static gint +static int lua_cryptobox_encrypt_cookie(lua_State *L) { - guchar aes_block[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE], *blk; - guchar padded_cookie[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE]; - guchar nonce[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE]; - guchar aes_key[RSPAMD_CRYPTOBOX_AES_KEYSIZE]; - guchar result[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE * 2]; + unsigned char aes_block[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE], *blk; + unsigned char padded_cookie[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE]; + unsigned char nonce[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE]; + unsigned char aes_key[RSPAMD_CRYPTOBOX_AES_KEYSIZE]; + unsigned char result[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE * 2]; uint32_t ts; - const gchar *sk, *cookie; + const char *sk, *cookie; gsize sklen, cookie_len; - gint bklen; + int bklen; sk = lua_tolstring(L, 1, &sklen); cookie = lua_tolstring(L, 2, &cookie_len); @@ -2307,11 +2307,11 @@ lua_cryptobox_encrypt_cookie(lua_State *L) memcpy(aes_key, sk, sizeof(aes_key)); } else { - return luaL_error(L, "invalid keysize %d", (gint) sklen); + return luaL_error(L, "invalid keysize %d", (int) sklen); } if (cookie_len > sizeof(padded_cookie) - 1) { - return luaL_error(L, "cookie is too long %d", (gint) cookie_len); + return luaL_error(L, "cookie is too long %d", (int) cookie_len); } /* Fill nonce */ @@ -2339,13 +2339,13 @@ lua_cryptobox_encrypt_cookie(lua_State *L) /* Encode result */ memcpy(result, nonce, sizeof(nonce)); - for (guint i = 0; i < sizeof(aes_block); i++) { + for (unsigned int i = 0; i < sizeof(aes_block); i++) { result[i + sizeof(nonce)] = padded_cookie[i] ^ aes_block[i]; } gsize rlen; - gchar *res = rspamd_encode_base64(result, sizeof(result), - 0, &rlen); + char *res = rspamd_encode_base64(result, sizeof(result), + 0, &rlen); lua_pushlstring(L, res, rlen); g_free(res); @@ -2372,18 +2372,18 @@ lua_cryptobox_encrypt_cookie(lua_State *L) * @param {string} encrypted_cookie encrypted cookie as a base64 encoded string * @return {string+number} decrypted value of the cookie and the cookie timestamp */ -static gint +static int lua_cryptobox_decrypt_cookie(lua_State *L) { - guchar *blk; - guchar nonce[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE]; - guchar aes_key[RSPAMD_CRYPTOBOX_AES_KEYSIZE]; - guchar *src; + unsigned char *blk; + unsigned char nonce[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE]; + unsigned char aes_key[RSPAMD_CRYPTOBOX_AES_KEYSIZE]; + unsigned char *src; uint32_t ts; - const gchar *sk, *cookie; + const char *sk, *cookie; gsize sklen, cookie_len; - gint bklen; + int bklen; sk = lua_tolstring(L, 1, &sklen); cookie = lua_tolstring(L, 2, &cookie_len); @@ -2398,7 +2398,7 @@ lua_cryptobox_decrypt_cookie(lua_State *L) memcpy(aes_key, sk, sizeof(aes_key)); } else { - return luaL_error(L, "invalid keysize %d", (gint) sklen); + return luaL_error(L, "invalid keysize %d", (int) sklen); } src = g_malloc(cookie_len); @@ -2431,7 +2431,7 @@ lua_cryptobox_decrypt_cookie(lua_State *L) EVP_CIPHER_CTX_free(ctx); /* Decode result */ - for (guint i = 0; i < RSPAMD_CRYPTOBOX_AES_BLOCKSIZE; i++) { + for (unsigned int i = 0; i < RSPAMD_CRYPTOBOX_AES_BLOCKSIZE; i++) { src[i + sizeof(nonce)] ^= nonce[i]; } @@ -2465,19 +2465,19 @@ lua_cryptobox_decrypt_cookie(lua_State *L) * @param {string} kdf_alg algorithm to use (catena or pbkdf2) * @return {string} encrypted password or nil if error occurs */ -static gint +static int lua_cryptobox_pbkdf(lua_State *L) { const struct rspamd_controller_pbkdf *pbkdf = NULL; - const gchar *pbkdf_str = "catena"; - gchar *password; + const char *pbkdf_str = "catena"; + char *password; gsize pwlen; if (lua_type(L, 2) == LUA_TSTRING) { pbkdf_str = lua_tostring(L, 2); } - for (guint i = 0; i < RSPAMD_PBKDF_ID_MAX - 1; i++) { + for (unsigned int i = 0; i < RSPAMD_PBKDF_ID_MAX - 1; i++) { pbkdf = &pbkdf_list[i]; if (g_ascii_strcasecmp(pbkdf_str, pbkdf->alias) == 0) { @@ -2510,8 +2510,8 @@ lua_cryptobox_pbkdf(lua_State *L) return 1; } - guchar *salt, *key; - gchar *encoded_salt, *encoded_key; + unsigned char *salt, *key; + char *encoded_salt, *encoded_key; GString *result; salt = g_alloca(pbkdf->salt_len); @@ -2546,11 +2546,11 @@ lua_cryptobox_pbkdf(lua_State *L) * @param {number} nbits optional number of bits for rsa (default 1024) * @return {rspamd_text,rspamd_text} private key and public key as base64 encoded strings */ -static gint +static int lua_cryptobox_gen_dkim_keypair(lua_State *L) { - const gchar *alg_str = "rsa"; - guint nbits = 1024; + const char *alg_str = "rsa"; + unsigned int nbits = 1024; struct rspamd_lua_text *priv_out, *pub_out; if (lua_type(L, 1) == LUA_TSTRING) { @@ -2595,9 +2595,9 @@ lua_cryptobox_gen_dkim_keypair(lua_State *L) } BIO *mbio; - gint rc, len; - guchar *data; - gchar *b64_data; + int rc, len; + unsigned char *data; + char *b64_data; gsize b64_len; mbio = BIO_new(BIO_s_mem()); @@ -2655,7 +2655,7 @@ lua_cryptobox_gen_dkim_keypair(lua_State *L) else if (strcmp(alg_str, "ed25519") == 0) { rspamd_sig_pk_t pk; rspamd_sig_sk_t sk; - gchar *b64_data; + char *b64_data; gsize b64_len; rspamd_cryptobox_keypair_sig(pk, sk, RSPAMD_CRYPTOBOX_MODE_25519); @@ -2688,7 +2688,7 @@ lua_cryptobox_gen_dkim_keypair(lua_State *L) else if (strcmp(alg_str, "ed25519-seed") == 0) { rspamd_sig_pk_t pk; rspamd_sig_sk_t sk; - gchar *b64_data; + char *b64_data; gsize b64_len; rspamd_cryptobox_keypair_sig(pk, sk, RSPAMD_CRYPTOBOX_MODE_25519); @@ -2740,10 +2740,10 @@ G_STATIC_ASSERT(crypto_secretbox_KEYBYTES >= crypto_generichash_BYTES_MIN); * @param {table} params optional parameters - NYI * @return {rspamd_cryptobox_secretbox} opaque object with the key expanded */ -static gint +static int lua_cryptobox_secretbox_create(lua_State *L) { - const gchar *in; + const char *in; gsize inlen; @@ -2780,7 +2780,7 @@ lua_cryptobox_secretbox_create(lua_State *L) } -static gint +static int lua_cryptobox_secretbox_gc(lua_State *L) { struct rspamd_lua_cryptobox_secretbox *sbox = @@ -2805,10 +2805,10 @@ lua_cryptobox_secretbox_gc(lua_State *L) * @param {table} params optional parameters - NYI * @return {rspamd_text},{rspamd_text} output with mac + nonce or just output if nonce is there */ -static gint +static int lua_cryptobox_secretbox_encrypt(lua_State *L) { - const gchar *in, *nonce; + const char *in, *nonce; gsize inlen, nlen; struct rspamd_lua_cryptobox_secretbox *sbox = lua_check_cryptobox_secretbox(L, 1); @@ -2858,14 +2858,14 @@ lua_cryptobox_secretbox_encrypt(lua_State *L) return luaL_error(L, "bad nonce"); } - guchar real_nonce[crypto_secretbox_NONCEBYTES]; + unsigned char real_nonce[crypto_secretbox_NONCEBYTES]; memset(real_nonce, 0, sizeof(real_nonce)); memcpy(real_nonce, nonce, nlen); out = lua_new_text(L, NULL, inlen + crypto_secretbox_MACBYTES, TRUE); - crypto_secretbox_easy((guchar *) out->start, in, inlen, + crypto_secretbox_easy((unsigned char *) out->start, in, inlen, nonce, sbox->sk); return 1; @@ -2878,8 +2878,8 @@ lua_cryptobox_secretbox_encrypt(lua_State *L) TRUE); random_nonce = lua_new_text(L, NULL, crypto_secretbox_NONCEBYTES, TRUE); - randombytes_buf((guchar *) random_nonce->start, random_nonce->len); - crypto_secretbox_easy((guchar *) out->start, in, inlen, + randombytes_buf((unsigned char *) random_nonce->start, random_nonce->len); + crypto_secretbox_easy((unsigned char *) out->start, in, inlen, random_nonce->start, sbox->sk); return 2; /* output + random nonce */ @@ -2894,10 +2894,10 @@ lua_cryptobox_secretbox_encrypt(lua_State *L) * @param {table} params optional parameters - NYI * @return {boolean},{rspamd_text} decryption result + decrypted text */ -static gint +static int lua_cryptobox_secretbox_decrypt(lua_State *L) { - const gchar *in, *nonce; + const char *in, *nonce; gsize inlen, nlen; struct rspamd_lua_cryptobox_secretbox *sbox = lua_check_cryptobox_secretbox(L, 1); @@ -2956,16 +2956,16 @@ lua_cryptobox_secretbox_decrypt(lua_State *L) return 2; } - guchar real_nonce[crypto_secretbox_NONCEBYTES]; + unsigned char real_nonce[crypto_secretbox_NONCEBYTES]; memset(real_nonce, 0, sizeof(real_nonce)); memcpy(real_nonce, nonce, nlen); out = lua_new_text(L, NULL, inlen - crypto_secretbox_MACBYTES, TRUE); - gint text_pos = lua_gettop(L); + int text_pos = lua_gettop(L); - if (crypto_secretbox_open_easy((guchar *) out->start, in, inlen, + if (crypto_secretbox_open_easy((unsigned char *) out->start, in, inlen, nonce, sbox->sk) == 0) { lua_pushboolean(L, true); lua_pushvalue(L, text_pos); /* Prevent gc by copying in stack */ @@ -2981,7 +2981,7 @@ lua_cryptobox_secretbox_decrypt(lua_State *L) return 2; } -static gint +static int lua_load_pubkey(lua_State *L) { lua_newtable(L); @@ -2990,7 +2990,7 @@ lua_load_pubkey(lua_State *L) return 1; } -static gint +static int lua_load_keypair(lua_State *L) { lua_newtable(L); @@ -2999,7 +2999,7 @@ lua_load_keypair(lua_State *L) return 1; } -static gint +static int lua_load_signature(lua_State *L) { lua_newtable(L); @@ -3008,7 +3008,7 @@ lua_load_signature(lua_State *L) return 1; } -static gint +static int lua_load_hash(lua_State *L) { lua_newtable(L); @@ -3017,7 +3017,7 @@ lua_load_hash(lua_State *L) return 1; } -static gint +static int lua_load_cryptobox_secretbox(lua_State *L) { lua_newtable(L); @@ -3026,7 +3026,7 @@ lua_load_cryptobox_secretbox(lua_State *L) return 1; } -static gint +static int lua_load_cryptobox(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c index cffa31259..2f20b6f5e 100644 --- a/src/lua/lua_dns.c +++ b/src/lua/lua_dns.c @@ -22,7 +22,7 @@ static const struct luaL_reg dns_f[] = { {"__tostring", rspamd_lua_class_tostring}, {NULL, NULL}}; -static const gchar *M = "rspamd lua dns"; +static const char *M = "rspamd lua dns"; void lua_dns_callback(struct rdns_reply *reply, void *arg); @@ -34,18 +34,18 @@ struct lua_rspamd_dns_cbdata { struct rspamd_async_session *s; }; -static gint +static int lua_dns_request(lua_State *L) { GError *err = NULL; struct rspamd_async_session *session = NULL; struct rspamd_config *cfg = NULL; struct lua_rspamd_dns_cbdata *cbdata = NULL; - const gchar *to_resolve = NULL; - const gchar *type_str = NULL; + const char *to_resolve = NULL; + const char *type_str = NULL; struct rspamd_task *task = NULL; rspamd_mempool_t *pool = NULL; - gint ret = 0; + int ret = 0; gboolean forced = FALSE; /* Check arguments */ @@ -183,7 +183,7 @@ void lua_dns_callback(struct rdns_reply *reply, void *arg) } } -static gint +static int lua_load_dns(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_dns_resolver.c b/src/lua/lua_dns_resolver.c index 6c2d4f672..605fdd4fd 100644 --- a/src/lua/lua_dns_resolver.c +++ b/src/lua/lua_dns_resolver.c @@ -41,7 +41,7 @@ local function symbol_callback(task) end */ -static const gchar *M = "rspamd lua dns resolver"; +static const char *M = "rspamd lua dns resolver"; /* Lua bindings */ LUA_FUNCTION_DEF(dns_resolver, init); @@ -71,7 +71,7 @@ static const struct luaL_reg dns_resolverlib_m[] = { {NULL, NULL}}; struct rspamd_dns_resolver * -lua_check_dns_resolver(lua_State *L, gint pos) +lua_check_dns_resolver(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_resolver_classname); luaL_argcheck(L, ud != NULL, pos, "'resolver' expected"); @@ -82,9 +82,9 @@ struct lua_dns_cbdata { struct rspamd_task *task; rspamd_mempool_t *pool; struct rspamd_dns_resolver *resolver; - gint cbref; - gchar *to_resolve; - gchar *user_str; + int cbref; + char *to_resolve; + char *user_str; struct rspamd_symcache_dynamic_item *item; struct rspamd_async_session *s; }; @@ -93,7 +93,7 @@ static int lua_dns_get_type(lua_State *L, int argno) { int type = RDNS_REQUEST_A; - const gchar *strtype; + const char *strtype; if (lua_type(L, argno) != LUA_TSTRING) { lua_pushvalue(L, argno); @@ -121,7 +121,7 @@ lua_dns_resolver_callback(struct rdns_reply *reply, gpointer arg) lua_State *L; struct lua_callback_state cbs; rspamd_mempool_t *pool; - gint err_idx; + int err_idx; pool = cd->pool; lua_thread_pool_prepare_callback(cd->resolver->cfg->lua_thread_pool, &cbs); @@ -162,7 +162,7 @@ lua_dns_resolver_callback(struct rdns_reply *reply, gpointer arg) lua_pushboolean(L, reply->flags & RDNS_AUTH); - const gchar *servname = rdns_request_get_server(reply->request); + const char *servname = rdns_request_get_server(reply->request); if (servname) { lua_pushstring(L, servname); @@ -200,7 +200,7 @@ lua_dns_resolver_callback(struct rdns_reply *reply, gpointer arg) void lua_push_dns_reply(lua_State *L, const struct rdns_reply *reply) { - gint i = 0, naddrs = 0; + int i = 0, naddrs = 0; struct rdns_reply_entry *elt; rspamd_inet_addr_t *addr; @@ -338,9 +338,9 @@ lua_dns_resolver_resolve_common(lua_State *L, LUA_TRACE_POINT; struct rspamd_async_session *session = NULL; rspamd_mempool_t *pool = NULL; - const gchar *to_resolve = NULL, *user_str = NULL; + const char *to_resolve = NULL, *user_str = NULL; struct lua_dns_cbdata *cbdata; - gint cbref = -1, ret; + int cbref = -1, ret; struct rspamd_task *task = NULL; GError *err = NULL; gboolean forced = FALSE; @@ -689,9 +689,9 @@ lua_dns_resolver_idna_convert_utf8(lua_State *L) { struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver(L, 1); gsize hlen; - guint conv_len = 0; - const gchar *hname = luaL_checklstring(L, 2, &hlen); - gchar *converted; + unsigned int conv_len = 0; + const char *hname = luaL_checklstring(L, 2, &hlen); + char *converted; rspamd_mempool_t *pool = rspamd_lua_check_udata_maybe(L, 3, rspamd_mempool_classname); @@ -723,7 +723,7 @@ lua_dns_resolver_idna_convert_utf8(lua_State *L) return 1; } -static gint +static int lua_load_dns_resolver(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_expression.c b/src/lua/lua_expression.c index b3c725376..61e199b6d 100644 --- a/src/lua/lua_expression.c +++ b/src/lua/lua_expression.c @@ -96,9 +96,9 @@ static const struct luaL_reg exprlib_f[] = { LUA_INTERFACE_DEF(expr, create), {NULL, NULL}}; -static rspamd_expression_atom_t *lua_atom_parse(const gchar *line, gsize len, +static rspamd_expression_atom_t *lua_atom_parse(const char *line, gsize len, rspamd_mempool_t *pool, gpointer ud, GError **err); -static gdouble lua_atom_process(gpointer runtime_ud, rspamd_expression_atom_t *atom); +static double lua_atom_process(gpointer runtime_ud, rspamd_expression_atom_t *atom); static const struct rspamd_atom_subr lua_atom_subr = { .parse = lua_atom_parse, @@ -108,8 +108,8 @@ static const struct rspamd_atom_subr lua_atom_subr = { struct lua_expression { struct rspamd_expression *expr; - gint parse_idx; - gint process_idx; + int parse_idx; + int process_idx; lua_State *L; rspamd_mempool_t *pool; }; @@ -121,7 +121,7 @@ lua_expr_quark(void) } struct lua_expression * -rspamd_lua_expression(lua_State *L, gint pos) +rspamd_lua_expression(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_expr_classname); luaL_argcheck(L, ud != NULL, pos, "'expr' expected"); @@ -143,13 +143,13 @@ lua_expr_dtor(gpointer p) } static rspamd_expression_atom_t * -lua_atom_parse(const gchar *line, gsize len, +lua_atom_parse(const char *line, gsize len, rspamd_mempool_t *pool, gpointer ud, GError **err) { struct lua_expression *e = (struct lua_expression *) ud; rspamd_expression_atom_t *atom; gsize rlen; - const gchar *tok; + const char *tok; lua_rawgeti(e->L, LUA_REGISTRYINDEX, e->parse_idx); lua_pushlstring(e->L, line, len); @@ -180,17 +180,17 @@ lua_atom_parse(const gchar *line, gsize len, struct lua_atom_process_data { lua_State *L; struct lua_expression *e; - gint process_cb_pos; - gint stack_item; + int process_cb_pos; + int stack_item; }; -static gdouble +static double lua_atom_process(gpointer runtime_ud, rspamd_expression_atom_t *atom) { struct lua_atom_process_data *pd = (struct lua_atom_process_data *) runtime_ud; - gdouble ret = 0; - guint nargs; - gint err_idx; + double ret = 0; + unsigned int nargs; + int err_idx; if (pd->stack_item != -1) { nargs = 2; @@ -224,14 +224,14 @@ lua_atom_process(gpointer runtime_ud, rspamd_expression_atom_t *atom) return ret; } -static gint +static int lua_expr_process(lua_State *L) { LUA_TRACE_POINT; struct lua_expression *e = rspamd_lua_expression(L, 1); struct lua_atom_process_data pd; - gdouble res; - gint flags = 0, old_top; + double res; + int flags = 0, old_top; pd.L = L; pd.e = e; @@ -279,14 +279,14 @@ lua_expr_process(lua_State *L) return 1; } -static gint +static int lua_expr_process_traced(lua_State *L) { LUA_TRACE_POINT; struct lua_expression *e = rspamd_lua_expression(L, 1); struct lua_atom_process_data pd; - gdouble res; - gint flags = 0, old_top; + double res; + int flags = 0, old_top; GPtrArray *trace; pd.L = L; @@ -322,7 +322,7 @@ lua_expr_process_traced(lua_State *L) lua_createtable(L, trace->len, 0); - for (guint i = 0; i < trace->len; i++) { + for (unsigned int i = 0; i < trace->len; i++) { struct rspamd_expression_atom_s *atom = g_ptr_array_index(trace, i); lua_pushlstring(L, atom->str, atom->len); @@ -334,7 +334,7 @@ lua_expr_process_traced(lua_State *L) return 2; } -static gint +static int lua_expr_create(lua_State *L) { LUA_TRACE_POINT; @@ -437,7 +437,7 @@ lua_expr_create(lua_State *L) return 2; } -static gint +static int lua_expr_to_string(lua_State *L) { LUA_TRACE_POINT; @@ -463,7 +463,7 @@ lua_expr_to_string(lua_State *L) struct lua_expr_atoms_cbdata { lua_State *L; - gint idx; + int idx; }; static void @@ -475,7 +475,7 @@ lua_exr_atom_cb(const rspamd_ftok_t *tok, gpointer ud) lua_rawseti(cbdata->L, -2, cbdata->idx++); } -static gint +static int lua_expr_atoms(lua_State *L) { LUA_TRACE_POINT; @@ -495,7 +495,7 @@ lua_expr_atoms(lua_State *L) return 1; } -static gint +static int lua_load_expression(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_html.cxx b/src/lua/lua_html.cxx index 67dbe9738..090e2af55 100644 --- a/src/lua/lua_html.cxx +++ b/src/lua/lua_html.cxx @@ -192,7 +192,7 @@ static const struct luaL_reg taglib_m[] = { {NULL, NULL}}; static struct rspamd::html::html_content * -lua_check_html(lua_State *L, gint pos) +lua_check_html(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_html_classname); luaL_argcheck(L, ud != NULL, pos, "'html' expected"); @@ -205,19 +205,19 @@ struct lua_html_tag { }; static struct lua_html_tag * -lua_check_html_tag(lua_State *L, gint pos) +lua_check_html_tag(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_html_tag_classname); luaL_argcheck(L, ud != NULL, pos, "'html_tag' expected"); return ud ? ((struct lua_html_tag *) ud) : NULL; } -static gint +static int lua_html_has_tag(lua_State *L) { LUA_TRACE_POINT; auto *hc = lua_check_html(L, 1); - const gchar *tagname = luaL_checkstring(L, 2); + const char *tagname = luaL_checkstring(L, 2); gboolean ret = FALSE; if (hc && tagname) { @@ -245,12 +245,12 @@ constexpr const auto prop_map = frozen::make_unordered_map( {"data_urls", RSPAMD_HTML_FLAG_HAS_DATA_URLS}, }); -static gint +static int lua_html_has_property(lua_State *L) { LUA_TRACE_POINT; auto *hc = lua_check_html(L, 1); - const gchar *propname = luaL_checkstring(L, 2); + const char *propname = luaL_checkstring(L, 2); gboolean ret = FALSE; if (hc && propname) { @@ -326,12 +326,12 @@ lua_html_push_image(lua_State *L, const struct html_image *img) lua_settable(L, -3); } -static gint +static int lua_html_get_images(lua_State *L) { LUA_TRACE_POINT; auto *hc = lua_check_html(L, 1); - guint i = 1; + unsigned int i = 1; if (hc != NULL) { lua_createtable(L, hc->images.size(), 0); @@ -397,13 +397,13 @@ lua_html_push_block(lua_State *L, const struct rspamd::html::html_block *bl) lua_settable(L, -3); } -static gint +static int lua_html_foreach_tag(lua_State *L) { LUA_TRACE_POINT; auto *hc = lua_check_html(L, 1); - const gchar *tagname; - gint id; + const char *tagname; + int id; auto any = false; ankerl::unordered_dense::set tags; @@ -491,7 +491,7 @@ lua_html_foreach_tag(lua_State *L) return 0; } -static gint +static int lua_html_get_invisible(lua_State *L) { LUA_TRACE_POINT; @@ -507,12 +507,12 @@ lua_html_get_invisible(lua_State *L) return 1; } -static gint +static int lua_html_tag_get_type(lua_State *L) { LUA_TRACE_POINT; struct lua_html_tag *ltag = lua_check_html_tag(L, 1); - const gchar *tagname; + const char *tagname; if (ltag != NULL) { tagname = rspamd_html_tag_by_id(ltag->tag->id); @@ -531,7 +531,7 @@ lua_html_tag_get_type(lua_State *L) return 1; } -static gint +static int lua_html_tag_get_parent(lua_State *L) { LUA_TRACE_POINT; @@ -557,12 +557,12 @@ lua_html_tag_get_parent(lua_State *L) return 1; } -static gint +static int lua_html_tag_get_flags(lua_State *L) { LUA_TRACE_POINT; struct lua_html_tag *ltag = lua_check_html_tag(L, 1); - gint i = 1; + int i = 1; if (ltag && ltag->tag) { /* Push flags */ @@ -595,7 +595,7 @@ lua_html_tag_get_flags(lua_State *L) return 1; } -static gint +static int lua_html_tag_get_content(lua_State *L) { LUA_TRACE_POINT; @@ -628,7 +628,7 @@ lua_html_tag_get_content(lua_State *L) return 1; } -static gint +static int lua_html_tag_get_content_length(lua_State *L) { LUA_TRACE_POINT; @@ -650,7 +650,7 @@ lua_html_tag_get_content_length(lua_State *L) return 1; } -static gint +static int lua_html_tag_get_extra(lua_State *L) { LUA_TRACE_POINT; @@ -685,7 +685,7 @@ lua_html_tag_get_extra(lua_State *L) return 1; } -static gint +static int lua_html_tag_get_style(lua_State *L) { LUA_TRACE_POINT; @@ -703,13 +703,13 @@ lua_html_tag_get_style(lua_State *L) return 1; } -static gint +static int lua_html_tag_get_attribute(lua_State *L) { LUA_TRACE_POINT; struct lua_html_tag *ltag = lua_check_html_tag(L, 1); gsize slen; - const gchar *attr_name = luaL_checklstring(L, 2, &slen); + const char *attr_name = luaL_checklstring(L, 2, &slen); if (ltag && attr_name) { auto maybe_attr = ltag->tag->find_component( diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 4c0596885..2032f7dc1 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -48,7 +48,7 @@ local function symbol_callback(task) #define MAX_HEADERS_SIZE 8192 -static const gchar *M = "rspamd lua http"; +static const char *M = "rspamd lua http"; LUA_FUNCTION_DEF(http, request); @@ -75,20 +75,20 @@ struct lua_http_cbdata { struct rspamd_cryptobox_keypair *local_kp; struct rspamd_cryptobox_pubkey *peer_pk; rspamd_inet_addr_t *addr; - gchar *mime_type; - gchar *host; - gchar *auth; + char *mime_type; + char *host; + char *auth; struct upstream *up; - const gchar *url; + const char *url; gsize max_size; - gint flags; - gint fd; - gint cbref; + int flags; + int fd; + int cbref; struct thread_entry *thread; ref_entry_t ref; }; -static const gdouble default_http_timeout = 5.0; +static const double default_http_timeout = 5.0; static struct rspamd_dns_resolver * lua_http_global_resolver(struct ev_loop *ev_base) @@ -237,7 +237,7 @@ lua_http_finish_handler(struct rspamd_http_connection *conn, { struct lua_http_cbdata *cbd = (struct lua_http_cbdata *) conn->ud; struct rspamd_http_header *h; - const gchar *body; + const char *body; gsize body_len; struct lua_callback_state lcbd; @@ -330,7 +330,7 @@ lua_http_resume_handler(struct rspamd_http_connection *conn, { struct lua_http_cbdata *cbd = (struct lua_http_cbdata *) conn->ud; lua_State *L = cbd->thread->lua_state; - const gchar *body; + const char *body; gsize body_len; struct rspamd_http_header *h; @@ -557,7 +557,7 @@ static void lua_http_push_headers(lua_State *L, struct rspamd_http_message *msg) { const char *name, *value; - gint i, sz; + int i, sz; lua_pushnil(L); while (lua_next(L, -2) != 0) { @@ -614,7 +614,7 @@ lua_http_push_headers(lua_State *L, struct rspamd_http_message *msg) * @return {boolean} `true`, in **async** mode, if a request has been successfully scheduled. If this value is `false` then some error occurred, the callback thus will not be called. * @return In **sync** mode `string|nil, nil|table` In sync mode error message if any and response as table: `int` _code_, `string` _content_ and `table` _headers_ (header -> value) */ -static gint +static int lua_http_request(lua_State *L) { LUA_TRACE_POINT; @@ -629,14 +629,14 @@ lua_http_request(lua_State *L) struct rspamd_cryptobox_pubkey *peer_key = NULL; struct rspamd_cryptobox_keypair *local_kp = NULL; struct upstream *up = NULL; - const gchar *url, *lua_body; + const char *url, *lua_body; rspamd_fstring_t *body = NULL; - gint cbref = -1; + int cbref = -1; gsize bodylen; - gdouble timeout = default_http_timeout; - gint flags = 0; - gchar *mime_type = NULL; - gchar *auth = NULL; + double timeout = default_http_timeout; + int flags = 0; + char *mime_type = NULL; + char *auth = NULL; gsize max_size = 0; gboolean gzip = FALSE; @@ -903,7 +903,7 @@ lua_http_request(lua_State *L) lua_gettable(L, 1); if (lua_type(L, -1) == LUA_TSTRING) { - const gchar *in; + const char *in; gsize inlen; in = lua_tolstring(L, -1, &inlen); @@ -997,14 +997,14 @@ lua_http_request(lua_State *L) lua_gettable(L, 1); if (lua_type(L, -1) == LUA_TSTRING) { - const gchar *user = lua_tostring(L, -1); + const char *user = lua_tostring(L, -1); lua_pushstring(L, "password"); lua_gettable(L, 1); if (lua_type(L, -1) == LUA_TSTRING) { - const gchar *password = lua_tostring(L, -1); - gchar *tmpbuf; + const char *password = lua_tostring(L, -1); + char *tmpbuf; gsize tlen; tlen = strlen(user) + strlen(password) + 1; @@ -1124,7 +1124,7 @@ lua_http_request(lua_State *L) /* Check if we can skip resolving */ gsize hostlen = 0; - const gchar *host = rspamd_http_message_get_http_host(msg, &hostlen); + const char *host = rspamd_http_message_get_http_host(msg, &hostlen); if (host) { cbd->host = g_malloc(hostlen + 1); @@ -1255,7 +1255,7 @@ lua_http_request(lua_State *L) return 1; } -static gint +static int lua_load_http(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c index 5b547b3b6..1cfb297a4 100644 --- a/src/lua/lua_ip.c +++ b/src/lua/lua_ip.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -220,7 +220,7 @@ lua_ip_new(lua_State *L, struct rspamd_lua_ip *old) } struct rspamd_lua_ip * -lua_check_ip(lua_State *L, gint pos) +lua_check_ip(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_ip_classname); @@ -228,13 +228,13 @@ lua_check_ip(lua_State *L, gint pos) return ud ? *((struct rspamd_lua_ip **) ud) : NULL; } -static gint +static int lua_ip_to_table(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_ip *ip = lua_check_ip(L, 1); - guint max, i; - guint8 *ptr; + unsigned int max, i; + uint8_t *ptr; if (ip != NULL && ip->addr) { ptr = rspamd_inet_address_get_hash_key(ip->addr, &max); @@ -252,14 +252,14 @@ lua_ip_to_table(lua_State *L) return 1; } -static gint +static int lua_ip_str_octets(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_ip *ip = lua_check_ip(L, 1); - guint max, i; - guint8 *ptr; - gint af; + unsigned int max, i; + uint8_t *ptr; + int af; char numbuf[8]; if (ip != NULL && ip->addr) { @@ -293,15 +293,15 @@ lua_ip_str_octets(lua_State *L) return 1; } -static gint +static int lua_ip_inversed_str_octets(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_ip *ip = lua_check_ip(L, 1); - guint max, i; - guint8 *ptr; + unsigned int max, i; + uint8_t *ptr; char numbuf[4]; - gint af; + int af; if (ip != NULL && ip->addr) { ptr = rspamd_inet_address_get_hash_key(ip->addr, &max); @@ -335,7 +335,7 @@ lua_ip_inversed_str_octets(lua_State *L) return 1; } -static gint +static int lua_ip_to_string(lua_State *L) { LUA_TRACE_POINT; @@ -356,7 +356,7 @@ lua_ip_to_string(lua_State *L) return 1; } -static gint +static int lua_ip_get_port(lua_State *L) { LUA_TRACE_POINT; @@ -372,12 +372,12 @@ lua_ip_get_port(lua_State *L) return 1; } -static gint +static int lua_ip_from_string(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_ip *ip; - const gchar *ip_str; + const char *ip_str; gsize len; ip_str = luaL_checklstring(L, 1, &len); @@ -386,7 +386,7 @@ lua_ip_from_string(lua_State *L) if (!rspamd_parse_inet_address(&ip->addr, ip_str, len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) { - msg_warn("cannot parse ip: %*s", (gint) len, ip_str); + msg_warn("cannot parse ip: %*s", (int) len, ip_str); ip->addr = NULL; } } @@ -397,14 +397,14 @@ lua_ip_from_string(lua_State *L) return 1; } -static gint +static int lua_ip_to_number(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_ip *ip = lua_check_ip(L, 1); uint32_t c; - guint max, i; - guchar *ptr; + unsigned int max, i; + unsigned char *ptr; if (ip != NULL && ip->addr) { ptr = rspamd_inet_address_get_hash_key(ip->addr, &max); @@ -424,7 +424,7 @@ lua_ip_to_number(lua_State *L) } -static gint +static int lua_ip_destroy(lua_State *L) { LUA_TRACE_POINT; @@ -440,7 +440,7 @@ lua_ip_destroy(lua_State *L) return 0; } -static gint +static int lua_ip_get_version(lua_State *L) { LUA_TRACE_POINT; @@ -456,7 +456,7 @@ lua_ip_get_version(lua_State *L) return 1; } -static gint +static int lua_ip_is_valid(lua_State *L) { LUA_TRACE_POINT; @@ -472,12 +472,12 @@ lua_ip_is_valid(lua_State *L) return 1; } -static gint +static int lua_ip_apply_mask(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_ip *ip = lua_check_ip(L, 1), *nip; - gint mask; + int mask; mask = lua_tonumber(L, 2); if (mask > 0 && ip != NULL && ip->addr) { @@ -491,7 +491,7 @@ lua_ip_apply_mask(lua_State *L) return 1; } -static gint +static int lua_ip_equal(lua_State *L) { LUA_TRACE_POINT; @@ -508,7 +508,7 @@ lua_ip_equal(lua_State *L) return 1; } -static gint +static int lua_ip_copy(lua_State *L) { LUA_TRACE_POINT; @@ -524,7 +524,7 @@ lua_ip_copy(lua_State *L) return 1; } -static gint +static int lua_ip_is_local(lua_State *L) { struct rspamd_lua_ip *ip = lua_check_ip(L, 1); @@ -562,7 +562,7 @@ lua_ip_is_local(lua_State *L) return 1; } -static gint +static int lua_ip_less_than(lua_State *L) { LUA_TRACE_POINT; @@ -596,7 +596,7 @@ void rspamd_lua_ip_push(lua_State *L, rspamd_inet_addr_t *addr) } } -void rspamd_lua_ip_push_fromstring(lua_State *L, const gchar *ip_str) +void rspamd_lua_ip_push_fromstring(lua_State *L, const char *ip_str) { struct rspamd_lua_ip *ip, **pip; @@ -620,7 +620,7 @@ void rspamd_lua_ip_push_fromstring(lua_State *L, const gchar *ip_str) } } -static gint +static int lua_load_ip(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_kann.c b/src/lua/lua_kann.c index 09228387a..eadc8b06c 100644 --- a/src/lua/lua_kann.c +++ b/src/lua/lua_kann.c @@ -185,7 +185,7 @@ rspamd_kann_table_to_flags(lua_State *L, int table_pos) return result; } -static gint +static int lua_load_kann(lua_State *L) { lua_newtable(L); @@ -326,7 +326,7 @@ void luaopen_kann(lua_State *L) static int lua_kann_layer_input(lua_State *L) { - gint nnodes = luaL_checkinteger(L, 1); + int nnodes = luaL_checkinteger(L, 1); if (nnodes > 0) { kad_node_t *t; @@ -355,7 +355,7 @@ static int lua_kann_layer_dense(lua_State *L) { kad_node_t *in = lua_check_kann_node(L, 1); - gint nnodes = luaL_checkinteger(L, 2); + int nnodes = luaL_checkinteger(L, 2); if (in != NULL && nnodes > 0) { kad_node_t *t; @@ -441,8 +441,8 @@ static int lua_kann_layer_rnn(lua_State *L) { kad_node_t *in = lua_check_kann_node(L, 1); - gint nnodes = luaL_checkinteger(L, 2); - gint rnnflags = 0; + int nnodes = luaL_checkinteger(L, 2); + int rnnflags = 0; if (in != NULL && nnodes > 0) { kad_node_t *t; @@ -476,8 +476,8 @@ static int lua_kann_layer_lstm(lua_State *L) { kad_node_t *in = lua_check_kann_node(L, 1); - gint nnodes = luaL_checkinteger(L, 2); - gint rnnflags = 0; + int nnodes = luaL_checkinteger(L, 2); + int rnnflags = 0; if (in != NULL && nnodes > 0) { kad_node_t *t; @@ -511,8 +511,8 @@ static int lua_kann_layer_gru(lua_State *L) { kad_node_t *in = lua_check_kann_node(L, 1); - gint nnodes = luaL_checkinteger(L, 2); - gint rnnflags = 0; + int nnodes = luaL_checkinteger(L, 2); + int rnnflags = 0; if (in != NULL && nnodes > 0) { kad_node_t *t; @@ -743,7 +743,7 @@ lua_kann_loss_ce_multi_weighted(lua_State *L) static int lua_kann_new_scalar(lua_State *L) { - gint flag = luaL_checkinteger(L, 1); + int flag = luaL_checkinteger(L, 1); double x = luaL_checknumber(L, 2); kad_node_t *t; @@ -758,8 +758,8 @@ lua_kann_new_scalar(lua_State *L) static int lua_kann_new_weight(lua_State *L) { - gint nrow = luaL_checkinteger(L, 1); - gint ncol = luaL_checkinteger(L, 2); + int nrow = luaL_checkinteger(L, 1); + int ncol = luaL_checkinteger(L, 2); kad_node_t *t; t = kann_new_weight(nrow, ncol); @@ -773,7 +773,7 @@ lua_kann_new_weight(lua_State *L) static int lua_kann_new_bias(lua_State *L) { - gint n = luaL_checkinteger(L, 1); + int n = luaL_checkinteger(L, 1); kad_node_t *t; t = kann_new_bias(n); @@ -787,10 +787,10 @@ lua_kann_new_bias(lua_State *L) static int lua_kann_new_weight_conv2d(lua_State *L) { - gint nout = luaL_checkinteger(L, 1); - gint nin = luaL_checkinteger(L, 2); - gint krow = luaL_checkinteger(L, 3); - gint kcol = luaL_checkinteger(L, 4); + int nout = luaL_checkinteger(L, 1); + int nin = luaL_checkinteger(L, 2); + int krow = luaL_checkinteger(L, 3); + int kcol = luaL_checkinteger(L, 4); kad_node_t *t; t = kann_new_weight_conv2d(nout, nin, krow, kcol); @@ -804,9 +804,9 @@ lua_kann_new_weight_conv2d(lua_State *L) static int lua_kann_new_weight_conv1d(lua_State *L) { - gint nout = luaL_checkinteger(L, 1); - gint nin = luaL_checkinteger(L, 2); - gint klen = luaL_checkinteger(L, 3); + int nout = luaL_checkinteger(L, 1); + int nin = luaL_checkinteger(L, 2); + int klen = luaL_checkinteger(L, 3); kad_node_t *t; t = kann_new_weight_conv1d(nout, nin, klen); @@ -886,7 +886,7 @@ lua_kann_save(lua_State *L) lua_getfield(L, 2, "filename"); if (lua_isstring(L, -1)) { - const gchar *fname = lua_tostring(L, -1); + const char *fname = lua_tostring(L, -1); FILE *f; f = fopen(fname, "w"); @@ -930,7 +930,7 @@ lua_kann_save(lua_State *L) t = lua_newuserdata(L, sizeof(*t)); rspamd_lua_setclass(L, rspamd_text_classname, -1); t->flags = RSPAMD_TEXT_FLAG_OWN; - t->start = (const gchar *) buf; + t->start = (const char *) buf; t->len = buflen; } } @@ -951,7 +951,7 @@ lua_kann_load(lua_State *L) lua_getfield(L, 2, "filename"); if (lua_isstring(L, -1)) { - const gchar *fname = lua_tostring(L, -1); + const char *fname = lua_tostring(L, -1); f = fopen(fname, "rb"); } @@ -965,7 +965,7 @@ lua_kann_load(lua_State *L) } else if (lua_isstring(L, 1)) { gsize dlen; - const gchar *data; + const char *data; data = lua_tolstring(L, 1, &dlen); @@ -1009,7 +1009,7 @@ lua_kann_load(lua_State *L) struct rspamd_kann_train_cbdata { lua_State *L; kann_t *k; - gint cbref; + int cbref; }; static void @@ -1018,7 +1018,7 @@ lua_kann_train_cb(int iter, float train_cost, float val_cost, void *ud) struct rspamd_kann_train_cbdata *cbd = (struct rspamd_kann_train_cbdata *) ud; if (cbd->cbref != -1) { - gint err_idx; + int err_idx; lua_State *L = cbd->L; lua_pushcfunction(L, &rspamd_lua_traceback); @@ -1056,7 +1056,7 @@ lua_kann_train1(lua_State *L) int64_t max_epoch = 25; int64_t max_drop_streak = 10; double frac_val = 0.1; - gint cbref = -1; + int cbref = -1; if (k && lua_istable(L, 2) && lua_istable(L, 3)) { int n = rspamd_lua_table_size(L, 2); @@ -1338,7 +1338,7 @@ lua_kann_apply1(lua_State *L) kann_feed_bind(k, KANN_F_IN, 0, &t->data); kad_eval_at(k->n, k->v, i_out); - gint outlen = kad_len(k->v[i_out]); + int outlen = kad_len(k->v[i_out]); struct rspamd_lua_tensor *out; out = lua_newtensor(L, 1, &outlen, false, false); /* Ensure that kann and tensor have the same understanding of floats */ diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c index 9a0dacf46..21aad8136 100644 --- a/src/lua/lua_logger.c +++ b/src/lua/lua_logger.c @@ -177,13 +177,13 @@ static const struct luaL_reg loggerlib_f[] = { static void lua_common_log_line(GLogLevelFlags level, lua_State *L, - const gchar *msg, - const gchar *uid, - const gchar *module, - gint stack_level) + const char *msg, + const char *uid, + const char *module, + int stack_level) { lua_Debug d; - gchar func_buf[128], *p; + char func_buf[128], *p; if (lua_getstack(L, stack_level, &d) == 1) { (void) lua_getinfo(L, "Sl", &d); @@ -223,31 +223,31 @@ lua_common_log_line(GLogLevelFlags level, } /*** Logger interface ***/ -static gint +static int lua_logger_err(lua_State *L) { return lua_logger_errx(L); } -static gint +static int lua_logger_warn(lua_State *L) { return lua_logger_warnx(L); } -static gint +static int lua_logger_info(lua_State *L) { return lua_logger_infox(L); } -static gint +static int lua_logger_message(lua_State *L) { return lua_logger_messagex(L); } -static gint +static int lua_logger_debug(lua_State *L) { return lua_logger_debugx(L); @@ -280,14 +280,14 @@ lua_logger_char_safe(int t, unsigned int esc_type) } static gsize -lua_logger_out_str(lua_State *L, gint pos, - gchar *outbuf, gsize len, +lua_logger_out_str(lua_State *L, int pos, + char *outbuf, gsize len, struct lua_logger_trace *trace, enum lua_logger_escape_type esc_type) { gsize slen, flen; - const gchar *str = lua_tolstring(L, pos, &slen); - static const gchar hexdigests[16] = "0123456789abcdef"; + const char *str = lua_tolstring(L, pos, &slen); + static const char hexdigests[16] = "0123456789abcdef"; gsize r = 0, s; if (str) { @@ -339,14 +339,14 @@ lua_logger_out_str(lua_State *L, gint pos, } static gsize -lua_logger_out_num(lua_State *L, gint pos, gchar *outbuf, gsize len, +lua_logger_out_num(lua_State *L, int pos, char *outbuf, gsize len, struct lua_logger_trace *trace) { - gdouble num = lua_tonumber(L, pos); + double num = lua_tonumber(L, pos); glong inum; gsize r = 0; - if ((gdouble) (glong) num == num) { + if ((double) (glong) num == num) { inum = num; r = rspamd_snprintf(outbuf, len + 1, "%l", inum); } @@ -358,7 +358,7 @@ lua_logger_out_num(lua_State *L, gint pos, gchar *outbuf, gsize len, } static gsize -lua_logger_out_boolean(lua_State *L, gint pos, gchar *outbuf, gsize len, +lua_logger_out_boolean(lua_State *L, int pos, char *outbuf, gsize len, struct lua_logger_trace *trace) { gboolean val = lua_toboolean(L, pos); @@ -370,11 +370,11 @@ lua_logger_out_boolean(lua_State *L, gint pos, gchar *outbuf, gsize len, } static gsize -lua_logger_out_userdata(lua_State *L, gint pos, gchar *outbuf, gsize len, +lua_logger_out_userdata(lua_State *L, int pos, char *outbuf, gsize len, struct lua_logger_trace *trace) { - gint r = 0, top; - const gchar *str = NULL; + int r = 0, top; + const char *str = NULL; gboolean converted_to_str = FALSE; top = lua_gettop(L); @@ -469,15 +469,15 @@ lua_logger_out_userdata(lua_State *L, gint pos, gchar *outbuf, gsize len, } static gsize -lua_logger_out_table(lua_State *L, gint pos, gchar *outbuf, gsize len, +lua_logger_out_table(lua_State *L, int pos, char *outbuf, gsize len, struct lua_logger_trace *trace, enum lua_logger_escape_type esc_type) { - gchar *d = outbuf; + char *d = outbuf; gsize remain = len, r; gboolean first = TRUE; gconstpointer self = NULL; - gint i, tpos, last_seq = -1, old_top; + int i, tpos, last_seq = -1, old_top; if (!lua_istable(L, pos) || remain == 0) { return 0; @@ -587,12 +587,12 @@ lua_logger_out_table(lua_State *L, gint pos, gchar *outbuf, gsize len, #undef MOVE_BUF -gsize lua_logger_out_type(lua_State *L, gint pos, - gchar *outbuf, gsize len, +gsize lua_logger_out_type(lua_State *L, int pos, + char *outbuf, gsize len, struct lua_logger_trace *trace, enum lua_logger_escape_type esc_type) { - gint type; + int type; gsize r = 0; if (len == 0) { @@ -638,10 +638,10 @@ gsize lua_logger_out_type(lua_State *L, gint pos, return r; } -static const gchar * -lua_logger_get_id(lua_State *L, gint pos, GError **err) +static const char * +lua_logger_get_id(lua_State *L, int pos, GError **err) { - const gchar *uid = NULL, *clsname; + const char *uid = NULL, *clsname; if (lua_getmetatable(L, pos) != 0) { uid = ""; @@ -728,13 +728,13 @@ lua_logger_get_id(lua_State *L, gint pos, GError **err) } static gboolean -lua_logger_log_format(lua_State *L, gint fmt_pos, gboolean is_string, - gchar *logbuf, gsize remain) +lua_logger_log_format(lua_State *L, int fmt_pos, gboolean is_string, + char *logbuf, gsize remain) { - gchar *d; - const gchar *s, *c; + char *d; + const char *s, *c; gsize r, cpylen = 0; - guint arg_num = 0, cur_arg; + unsigned int arg_num = 0, cur_arg; bool num_arg = false; struct lua_logger_trace tr; enum { @@ -799,7 +799,7 @@ lua_logger_log_format(lua_State *L, gint fmt_pos, gboolean is_string, s++; } - if (arg_num < 1 || arg_num > (guint) lua_gettop(L) + 1) { + if (arg_num < 1 || arg_num > (unsigned int) lua_gettop(L) + 1) { msg_err("wrong argument number: %ud", arg_num); return FALSE; @@ -828,7 +828,7 @@ lua_logger_log_format(lua_State *L, gint fmt_pos, gboolean is_string, arg_num = cur_arg; } - if (arg_num < 1 || arg_num > (guint) lua_gettop(L) + 1) { + if (arg_num < 1 || arg_num > (unsigned int) lua_gettop(L) + 1) { msg_err("wrong argument number: %ud", arg_num); return FALSE; @@ -854,16 +854,16 @@ lua_logger_log_format(lua_State *L, gint fmt_pos, gboolean is_string, return TRUE; } -static gint +static int lua_logger_do_log(lua_State *L, GLogLevelFlags level, gboolean is_string, - gint start_pos) + int start_pos) { - gchar logbuf[RSPAMD_LOGBUF_SIZE - 128]; - const gchar *uid = NULL; - gint fmt_pos = start_pos; - gint ret; + char logbuf[RSPAMD_LOGBUF_SIZE - 128]; + const char *uid = NULL; + int fmt_pos = start_pos; + int ret; GError *err = NULL; if (lua_type(L, start_pos) == LUA_TSTRING) { @@ -914,50 +914,50 @@ lua_logger_do_log(lua_State *L, return 0; } -static gint +static int lua_logger_errx(lua_State *L) { LUA_TRACE_POINT; return lua_logger_do_log(L, G_LOG_LEVEL_CRITICAL, FALSE, 1); } -static gint +static int lua_logger_warnx(lua_State *L) { LUA_TRACE_POINT; return lua_logger_do_log(L, G_LOG_LEVEL_WARNING, FALSE, 1); } -static gint +static int lua_logger_infox(lua_State *L) { LUA_TRACE_POINT; return lua_logger_do_log(L, G_LOG_LEVEL_INFO, FALSE, 1); } -static gint +static int lua_logger_messagex(lua_State *L) { LUA_TRACE_POINT; return lua_logger_do_log(L, G_LOG_LEVEL_MESSAGE, FALSE, 1); } -static gint +static int lua_logger_debugx(lua_State *L) { LUA_TRACE_POINT; return lua_logger_do_log(L, G_LOG_LEVEL_DEBUG, FALSE, 1); } -static gint +static int lua_logger_logx(lua_State *L) { LUA_TRACE_POINT; GLogLevelFlags flags = lua_tonumber(L, 1); - const gchar *modname = lua_tostring(L, 2), *uid = NULL; - gchar logbuf[RSPAMD_LOGBUF_SIZE - 128]; + const char *modname = lua_tostring(L, 2), *uid = NULL; + char logbuf[RSPAMD_LOGBUF_SIZE - 128]; gboolean ret; - gint stack_pos = 1; + int stack_pos = 1; if (lua_type(L, 3) == LUA_TSTRING) { uid = luaL_checkstring(L, 3); @@ -993,13 +993,13 @@ lua_logger_logx(lua_State *L) } -static gint +static int lua_logger_debugm(lua_State *L) { LUA_TRACE_POINT; - gchar logbuf[RSPAMD_LOGBUF_SIZE - 128]; - const gchar *uid = NULL, *module = NULL; - gint stack_pos = 1; + char logbuf[RSPAMD_LOGBUF_SIZE - 128]; + const char *uid = NULL, *module = NULL; + int stack_pos = 1; gboolean ret; module = luaL_checkstring(L, 1); @@ -1035,16 +1035,16 @@ lua_logger_debugm(lua_State *L) } -static gint +static int lua_logger_slog(lua_State *L) { return lua_logger_do_log(L, 0, TRUE, 1); } -static gint +static int lua_logger_log_level(lua_State *L) { - gint log_level = rspamd_log_get_log_level(NULL); + int log_level = rspamd_log_get_log_level(NULL); lua_pushstring(L, rspamd_get_log_severity_string(log_level)); @@ -1053,7 +1053,7 @@ lua_logger_log_level(lua_State *L) /*** Init functions ***/ -static gint +static int lua_load_logger(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index b68665b3c..cce78ff2c 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -174,25 +174,25 @@ static const struct luaL_reg maplib_m[] = { struct lua_map_callback_data { lua_State *L; - gint ref; + int ref; gboolean opaque; rspamd_fstring_t *data; struct rspamd_lua_map *lua_map; }; struct rspamd_lua_map * -lua_check_map(lua_State *L, gint pos) +lua_check_map(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_map_classname); luaL_argcheck(L, ud != NULL, pos, "'map' expected"); return ud ? *((struct rspamd_lua_map **) ud) : NULL; } -gint lua_config_add_radix_map(lua_State *L) +int lua_config_add_radix_map(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *map_line, *description; + const char *map_line, *description; struct rspamd_lua_map *map, **pmap; struct rspamd_map *m; @@ -228,11 +228,11 @@ gint lua_config_add_radix_map(lua_State *L) return 1; } -gint lua_config_radix_from_config(lua_State *L) +int lua_config_radix_from_config(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *mname, *optname; + const char *mname, *optname; const ucl_object_t *obj; struct rspamd_lua_map *map, **pmap; ucl_object_t *fake_obj; @@ -293,7 +293,7 @@ gint lua_config_radix_from_config(lua_State *L) } -gint lua_config_radix_from_ucl(lua_State *L) +int lua_config_radix_from_ucl(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); @@ -348,11 +348,11 @@ gint lua_config_radix_from_ucl(lua_State *L) return 1; } -gint lua_config_add_hash_map(lua_State *L) +int lua_config_add_hash_map(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *map_line, *description; + const char *map_line, *description; struct rspamd_lua_map *map, **pmap; struct rspamd_map *m; @@ -387,11 +387,11 @@ gint lua_config_add_hash_map(lua_State *L) return 1; } -gint lua_config_add_kv_map(lua_State *L) +int lua_config_add_kv_map(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *map_line, *description; + const char *map_line, *description; struct rspamd_lua_map *map, **pmap; struct rspamd_map *m; @@ -428,8 +428,8 @@ gint lua_config_add_kv_map(lua_State *L) } -static gchar * -lua_map_read(gchar *chunk, gint len, +static char * +lua_map_read(char *chunk, int len, struct map_cb_data *data, gboolean final) { @@ -517,7 +517,7 @@ lua_map_fin(struct map_cb_data *data, void **target) *pmap = cbdata->lua_map; rspamd_lua_setclass(cbdata->L, rspamd_map_classname, -1); - gint ret = lua_pcall(cbdata->L, 2, 0, err_idx); + int ret = lua_pcall(cbdata->L, 2, 0, err_idx); if (ret != 0) { msg_info_map("call to %s failed (%d): %s", "map fin function", @@ -557,12 +557,12 @@ lua_map_dtor(struct map_cb_data *data) } } -gint lua_config_add_map(lua_State *L) +int lua_config_add_map(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); const char *description = NULL; - const gchar *type = NULL; + const char *type = NULL; ucl_object_t *map_obj = NULL; struct lua_map_callback_data *cbdata; struct rspamd_lua_map *map, **pmap; @@ -792,13 +792,13 @@ gint lua_config_add_map(lua_State *L) return 1; } -gint lua_config_get_maps(lua_State *L) +int lua_config_get_maps(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); struct rspamd_lua_map *map, **pmap; struct rspamd_map *m; - gint i = 1; + int i = 1; GList *cur; if (cfg) { @@ -847,8 +847,8 @@ gint lua_config_get_maps(lua_State *L) return 1; } -static const gchar * -lua_map_process_string_key(lua_State *L, gint pos, gsize *len) +static const char * +lua_map_process_string_key(lua_State *L, int pos, gsize *len) { struct rspamd_lua_text *t; @@ -868,14 +868,14 @@ lua_map_process_string_key(lua_State *L, gint pos, gsize *len) } /* Radix and hash table functions */ -static gint +static int lua_map_get_key(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_map *map = lua_check_map(L, 1); struct rspamd_radix_map_helper *radix; struct rspamd_lua_ip *addr = NULL; - const gchar *key, *value = NULL; + const char *key, *value = NULL; gpointer ud; gsize len; uint32_t key_num = 0; @@ -886,7 +886,7 @@ lua_map_get_key(lua_State *L) radix = map->data.radix; if (lua_type(L, 2) == LUA_TSTRING) { - const gchar *addr_str; + const char *addr_str; addr_str = luaL_checklstring(L, 2, &len); addr = g_alloca(sizeof(*addr)); @@ -927,7 +927,7 @@ lua_map_get_key(lua_State *L) } else if (key_num != 0) { if ((p = rspamd_match_radix_map(radix, - (guint8 *) &key_num, sizeof(key_num))) != NULL) { + (uint8_t *) &key_num, sizeof(key_num))) != NULL) { ret = TRUE; } else { @@ -965,8 +965,8 @@ lua_map_get_key(lua_State *L) } else if (map->type == RSPAMD_LUA_MAP_REGEXP_MULTIPLE) { GPtrArray *ar; - guint i; - const gchar *val; + unsigned int i; + const char *val; key = lua_map_process_string_key(L, 2, &len); @@ -1044,7 +1044,7 @@ lua_map_traverse_cb(gconstpointer key, return TRUE; } -static gint +static int lua_map_get_stats(lua_State *L) { LUA_TRACE_POINT; @@ -1071,7 +1071,7 @@ lua_map_get_stats(lua_State *L) struct lua_map_traverse_cbdata { lua_State *L; - gint cbref; + int cbref; gboolean use_text; }; @@ -1111,7 +1111,7 @@ lua_map_foreach_cb(gconstpointer key, gconstpointer value, gsize _hits, gpointer return TRUE; } -static gint +static int lua_map_foreach(lua_State *L) { LUA_TRACE_POINT; @@ -1143,12 +1143,12 @@ lua_map_foreach(lua_State *L) return 1; } -static gint +static int lua_map_get_data_digest(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_map *map = lua_check_map(L, 1); - gchar numbuf[64]; + char numbuf[64]; if (map != NULL) { rspamd_snprintf(numbuf, sizeof(numbuf), "%uL", map->map->digest); @@ -1161,7 +1161,7 @@ lua_map_get_data_digest(lua_State *L) return 1; } -static gint +static int lua_map_get_nelts(lua_State *L) { LUA_TRACE_POINT; @@ -1184,7 +1184,7 @@ lua_map_is_signed(lua_State *L) struct rspamd_lua_map *map = lua_check_map(L, 1); gboolean ret = FALSE; struct rspamd_map_backend *bk; - guint i; + unsigned int i; if (map != NULL) { if (map->map) { @@ -1210,9 +1210,9 @@ lua_map_get_proto(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_map *map = lua_check_map(L, 1); - const gchar *ret = "undefined"; + const char *ret = "undefined"; struct rspamd_map_backend *bk; - guint i; + unsigned int i; if (map != NULL) { for (i = 0; i < map->map->backends->len; i++) { @@ -1248,7 +1248,7 @@ lua_map_get_sign_key(lua_State *L) LUA_TRACE_POINT; struct rspamd_lua_map *map = lua_check_map(L, 1); struct rspamd_map_backend *bk; - guint i; + unsigned int i; GString *ret = NULL; if (map != NULL) { @@ -1285,10 +1285,10 @@ lua_map_set_sign_key(lua_State *L) LUA_TRACE_POINT; struct rspamd_lua_map *map = lua_check_map(L, 1); struct rspamd_map_backend *bk; - const gchar *pk_str; + const char *pk_str; struct rspamd_cryptobox_pubkey *pk; gsize len; - guint i; + unsigned int i; pk_str = lua_tolstring(L, 2, &len); @@ -1346,7 +1346,7 @@ lua_map_get_uri(lua_State *L) LUA_TRACE_POINT; struct rspamd_lua_map *map = lua_check_map(L, 1); struct rspamd_map_backend *bk; - guint i; + unsigned int i; if (map != NULL) { for (i = 0; i < map->map->backends->len; i++) { @@ -1363,7 +1363,7 @@ lua_map_get_uri(lua_State *L) struct lua_map_on_load_cbdata { lua_State *L; - gint ref; + int ref; }; static void @@ -1388,7 +1388,7 @@ lua_map_on_load_handler(struct rspamd_map *map, gpointer ud) } } -static gint +static int lua_map_on_load(lua_State *L) { LUA_TRACE_POINT; diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c index f272b5173..ddc9b25e9 100644 --- a/src/lua/lua_mempool.c +++ b/src/lua/lua_mempool.c @@ -142,12 +142,12 @@ static const struct luaL_reg mempoollib_f[] = { struct lua_mempool_udata { lua_State *L; - gint cbref; + int cbref; rspamd_mempool_t *mempool; }; struct memory_pool_s * -rspamd_lua_check_mempool(lua_State *L, gint pos) +rspamd_lua_check_mempool(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_mempool_classname); luaL_argcheck(L, ud != NULL, pos, "'mempool' expected"); @@ -269,8 +269,8 @@ lua_mempool_suggest_size(lua_State *L) } struct lua_numbers_bucket { - guint nelts; - gdouble elts[0]; + unsigned int nelts; + double elts[0]; }; static int @@ -278,13 +278,13 @@ lua_mempool_set_bucket(lua_State *L) { LUA_TRACE_POINT; struct memory_pool_s *mempool = rspamd_lua_check_mempool(L, 1); - const gchar *var = luaL_checkstring(L, 2); + const char *var = luaL_checkstring(L, 2); struct lua_numbers_bucket *bucket; - gint nelts = luaL_checknumber(L, 3), i; + int nelts = luaL_checknumber(L, 3), i; if (var && nelts > 0) { bucket = rspamd_mempool_alloc(mempool, - sizeof(*bucket) + sizeof(gdouble) * nelts); + sizeof(*bucket) + sizeof(double) * nelts); bucket->nelts = nelts; if (lua_type(L, 4) == LUA_TTABLE) { @@ -315,17 +315,17 @@ lua_mempool_set_variable(lua_State *L) { LUA_TRACE_POINT; struct memory_pool_s *mempool = rspamd_lua_check_mempool(L, 1); - const gchar *var = luaL_checkstring(L, 2); + const char *var = luaL_checkstring(L, 2); gpointer value; struct lua_numbers_bucket *bucket; - gchar *vp; + char *vp; union { - gdouble d; - const gchar *s; + double d; + const char *s; gboolean b; } val; gsize slen; - gint i, j, len = 0, type; + int i, j, len = 0, type; if (mempool && var) { @@ -334,7 +334,7 @@ lua_mempool_set_variable(lua_State *L) if (type == LUA_TNUMBER) { /* We have some ambiguity here between integer and double */ - len += sizeof(gdouble); + len += sizeof(double); } else if (type == LUA_TBOOLEAN) { len += sizeof(gboolean); @@ -346,7 +346,7 @@ lua_mempool_set_variable(lua_State *L) else if (type == LUA_TTABLE) { /* We assume it as a bucket of numbers so far */ slen = rspamd_lua_table_size(L, i); - len += sizeof(gdouble) * slen + sizeof(*bucket); + len += sizeof(double) * slen + sizeof(*bucket); } else { msg_err("cannot handle lua type %s", lua_typename(L, type)); @@ -365,8 +365,8 @@ lua_mempool_set_variable(lua_State *L) if (type == LUA_TNUMBER) { val.d = lua_tonumber(L, i); - memcpy(vp, &val, sizeof(gdouble)); - vp += sizeof(gdouble); + memcpy(vp, &val, sizeof(double)); + vp += sizeof(double); } else if (type == LUA_TBOOLEAN) { val.b = lua_toboolean(L, i); @@ -390,7 +390,7 @@ lua_mempool_set_variable(lua_State *L) lua_pop(L, 1); } - vp += sizeof(gdouble) * slen + sizeof(*bucket); + vp += sizeof(double) * slen + sizeof(*bucket); } else { msg_err("cannot handle lua type %s", lua_typename(L, type)); @@ -415,11 +415,11 @@ lua_mempool_get_variable(lua_State *L) { LUA_TRACE_POINT; struct memory_pool_s *mempool = rspamd_lua_check_mempool(L, 1); - const gchar *var = luaL_checkstring(L, 2); - const gchar *type = NULL, *pt; + const char *var = luaL_checkstring(L, 2); + const char *type = NULL, *pt; struct lua_numbers_bucket bucket; - const gchar *value, *pv; - guint len, nvar, slen, i; + const char *value, *pv; + unsigned int len, nvar, slen, i; if (mempool && var) { value = rspamd_mempool_get_variable(mempool, var); @@ -438,17 +438,17 @@ lua_mempool_get_variable(lua_State *L) while ((len = strcspn(pt, ", ")) > 0) { if (len == sizeof("double") - 1 && g_ascii_strncasecmp(pt, "double", len) == 0) { - gdouble num; - memcpy(&num, pv, sizeof(gdouble)); + double num; + memcpy(&num, pv, sizeof(double)); lua_pushnumber(L, num); - pv += sizeof(gdouble); + pv += sizeof(double); } else if (len == sizeof("int") - 1 && g_ascii_strncasecmp(pt, "int", len) == 0) { - gint num; - memcpy(&num, pv, sizeof(gint)); + int num; + memcpy(&num, pv, sizeof(int)); lua_pushinteger(L, num); - pv += sizeof(gint); + pv += sizeof(int); } else if (len == sizeof("int64") - 1 && g_ascii_strncasecmp(pt, "int64", len) == 0) { @@ -466,8 +466,8 @@ lua_mempool_get_variable(lua_State *L) } else if (len == sizeof("string") - 1 && g_ascii_strncasecmp(pt, "string", len) == 0) { - slen = strlen((const gchar *) pv); - lua_pushlstring(L, (const gchar *) pv, slen); + slen = strlen((const char *) pv); + lua_pushlstring(L, (const char *) pv, slen); pv += slen + 1; } else if (len == sizeof("gstring") - 1 && @@ -483,7 +483,7 @@ lua_mempool_get_variable(lua_State *L) pv += sizeof(struct lua_numbers_bucket); for (i = 0; i < bucket.nelts; i++) { - gdouble num; + double num; memcpy(&num, pv, sizeof(num)); lua_pushnumber(L, num); lua_rawseti(L, -2, i + 1); @@ -543,7 +543,7 @@ lua_mempool_has_variable(lua_State *L) { LUA_TRACE_POINT; struct memory_pool_s *mempool = rspamd_lua_check_mempool(L, 1); - const gchar *var = luaL_checkstring(L, 2); + const char *var = luaL_checkstring(L, 2); gboolean ret = FALSE; if (mempool && var) { @@ -562,7 +562,7 @@ lua_mempool_delete_variable(lua_State *L) { LUA_TRACE_POINT; struct memory_pool_s *mempool = rspamd_lua_check_mempool(L, 1); - const gchar *var = luaL_checkstring(L, 2); + const char *var = luaL_checkstring(L, 2); gboolean ret = FALSE; if (mempool && var) { @@ -578,7 +578,7 @@ lua_mempool_delete_variable(lua_State *L) return 1; } -static gint +static int lua_mempool_topointer(lua_State *L) { LUA_TRACE_POINT; @@ -595,7 +595,7 @@ lua_mempool_topointer(lua_State *L) return 1; } -static gint +static int lua_load_mempool(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 41609848a..07dba9c93 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -623,7 +623,7 @@ lua_check_mimepart(lua_State *L) } -static gint +static int lua_textpart_is_utf(lua_State *L) { LUA_TRACE_POINT; @@ -640,7 +640,7 @@ lua_textpart_is_utf(lua_State *L) } -static gint +static int lua_textpart_has_8bit_raw(lua_State *L) { LUA_TRACE_POINT; @@ -661,7 +661,7 @@ lua_textpart_has_8bit_raw(lua_State *L) return 1; } -static gint +static int lua_textpart_has_8bit(lua_State *L) { LUA_TRACE_POINT; @@ -683,14 +683,14 @@ lua_textpart_has_8bit(lua_State *L) } -static gint +static int lua_textpart_get_content(lua_State *L) { LUA_TRACE_POINT; struct rspamd_mime_text_part *part = lua_check_textpart(L); struct rspamd_lua_text *t; gsize len; - const gchar *start, *type = NULL; + const char *start, *type = NULL; if (part == NULL) { lua_pushnil(L); @@ -768,7 +768,7 @@ lua_textpart_get_content(lua_State *L) return 1; } -static gint +static int lua_textpart_get_raw_content(lua_State *L) { LUA_TRACE_POINT; @@ -789,7 +789,7 @@ lua_textpart_get_raw_content(lua_State *L) return 1; } -static gint +static int lua_textpart_get_content_oneline(lua_State *L) { LUA_TRACE_POINT; @@ -805,7 +805,7 @@ lua_textpart_get_content_oneline(lua_State *L) return 1; } -static gint +static int lua_textpart_get_length(lua_State *L) { LUA_TRACE_POINT; @@ -826,7 +826,7 @@ lua_textpart_get_length(lua_State *L) return 1; } -static gint +static int lua_textpart_get_raw_length(lua_State *L) { LUA_TRACE_POINT; @@ -842,13 +842,13 @@ lua_textpart_get_raw_length(lua_State *L) return 1; } -static gint +static int lua_textpart_get_urls_length(lua_State *L) { LUA_TRACE_POINT; struct rspamd_mime_text_part *part = lua_check_textpart(L); GList *cur; - guint total = 0; + unsigned int total = 0; struct rspamd_process_exception *ex; if (part == NULL) { @@ -869,7 +869,7 @@ lua_textpart_get_urls_length(lua_State *L) return 1; } -static gint +static int lua_textpart_get_lines_count(lua_State *L) { LUA_TRACE_POINT; @@ -890,7 +890,7 @@ lua_textpart_get_lines_count(lua_State *L) return 1; } -static gint +static int lua_textpart_get_words_count(lua_State *L) { LUA_TRACE_POINT; @@ -912,7 +912,7 @@ lua_textpart_get_words_count(lua_State *L) } static inline enum rspamd_lua_words_type -word_extract_type_from_string(const gchar *how_str) +word_extract_type_from_string(const char *how_str) { enum rspamd_lua_words_type how = RSPAMD_LUA_WORDS_MAX; @@ -932,7 +932,7 @@ word_extract_type_from_string(const gchar *how_str) return how; } -static gint +static int lua_textpart_get_words(lua_State *L) { LUA_TRACE_POINT; @@ -948,7 +948,7 @@ lua_textpart_get_words(lua_State *L) } else { if (lua_type(L, 2) == LUA_TSTRING) { - const gchar *how_str = lua_tostring(L, 2); + const char *how_str = lua_tostring(L, 2); how = word_extract_type_from_string(how_str); @@ -963,13 +963,13 @@ lua_textpart_get_words(lua_State *L) return 1; } -static gint +static int lua_textpart_filter_words(lua_State *L) { LUA_TRACE_POINT; struct rspamd_mime_text_part *part = lua_check_textpart(L); struct rspamd_lua_regexp *re = lua_check_regexp(L, 2); - gint lim = -1; + int lim = -1; enum rspamd_lua_words_type how = RSPAMD_LUA_WORDS_STEM; if (part == NULL || re == NULL) { @@ -981,7 +981,7 @@ lua_textpart_filter_words(lua_State *L) } else { if (lua_type(L, 3) == LUA_TSTRING) { - const gchar *how_str = lua_tostring(L, 3); + const char *how_str = lua_tostring(L, 3); how = word_extract_type_from_string(how_str); @@ -994,7 +994,7 @@ lua_textpart_filter_words(lua_State *L) lim = lua_tointeger(L, 4); } - guint cnt, i; + unsigned int cnt, i; lua_createtable(L, 8, 0); @@ -1051,7 +1051,7 @@ lua_textpart_filter_words(lua_State *L) return 1; } -static gint +static int lua_textpart_is_empty(lua_State *L) { LUA_TRACE_POINT; @@ -1067,7 +1067,7 @@ lua_textpart_is_empty(lua_State *L) return 1; } -static gint +static int lua_textpart_is_html(lua_State *L) { LUA_TRACE_POINT; @@ -1083,7 +1083,7 @@ lua_textpart_is_html(lua_State *L) return 1; } -static gint +static int lua_textpart_get_html(lua_State *L) { LUA_TRACE_POINT; @@ -1102,7 +1102,7 @@ lua_textpart_get_html(lua_State *L) return 1; } -static gint +static int lua_textpart_get_language(lua_State *L) { LUA_TRACE_POINT; @@ -1124,7 +1124,7 @@ lua_textpart_get_language(lua_State *L) return 1; } -static gint +static int lua_textpart_get_charset(lua_State *L) { LUA_TRACE_POINT; @@ -1146,12 +1146,12 @@ lua_textpart_get_charset(lua_State *L) return 1; } -static gint +static int lua_textpart_get_languages(lua_State *L) { LUA_TRACE_POINT; struct rspamd_mime_text_part *part = lua_check_textpart(L); - guint i; + unsigned int i; struct rspamd_lang_detector_res *cur; if (part != NULL) { @@ -1205,7 +1205,7 @@ struct lua_shingle_filter_cbdata { static uint64_t lua_shingles_filter(uint64_t *input, gsize count, - gint shno, const guchar *key, gpointer ud) + int shno, const unsigned char *key, gpointer ud) { uint64_t minimal = G_MAXUINT64; gsize i, min_idx = 0; @@ -1236,16 +1236,16 @@ lua_shingles_filter(uint64_t *input, gsize count, #undef STORE_TOKEN -static gint +static int lua_textpart_get_fuzzy_hashes(lua_State *L) { LUA_TRACE_POINT; struct rspamd_mime_text_part *part = lua_check_textpart(L); rspamd_mempool_t *pool = rspamd_lua_check_mempool(L, 2); - guchar key[rspamd_cryptobox_HASHBYTES], digest[rspamd_cryptobox_HASHBYTES], + unsigned char key[rspamd_cryptobox_HASHBYTES], digest[rspamd_cryptobox_HASHBYTES], hexdigest[rspamd_cryptobox_HASHBYTES * 2 + 1], numbuf[64]; struct rspamd_shingle *sgl; - guint i; + unsigned int i; struct lua_shingle_data *sd; rspamd_cryptobox_hash_state_t st; rspamd_stat_token_t *word; @@ -1318,7 +1318,7 @@ lua_textpart_get_fuzzy_hashes(lua_State *L) return 2; } -static gint +static int lua_textpart_get_mimepart(lua_State *L) { LUA_TRACE_POINT; @@ -1351,7 +1351,7 @@ lua_textpart_get_mimepart(lua_State *L) * - `ascii_characters`: number of ascii characters * @return {table} table of stats */ -static gint +static int lua_textpart_get_stats(lua_State *L) { LUA_TRACE_POINT; @@ -1397,7 +1397,7 @@ lua_textpart_get_stats(lua_State *L) /* Mimepart implementation */ -static gint +static int lua_mimepart_get_content(lua_State *L) { LUA_TRACE_POINT; @@ -1422,7 +1422,7 @@ lua_mimepart_get_content(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_raw_content(lua_State *L) { LUA_TRACE_POINT; @@ -1443,7 +1443,7 @@ lua_mimepart_get_raw_content(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_length(lua_State *L) { LUA_TRACE_POINT; @@ -1459,7 +1459,7 @@ lua_mimepart_get_length(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_type_common(lua_State *L, struct rspamd_content_type *ct, gboolean full) { @@ -1513,7 +1513,7 @@ lua_mimepart_get_type_common(lua_State *L, struct rspamd_content_type *ct, return 3; } -static gint +static int lua_mimepart_get_type(lua_State *L) { LUA_TRACE_POINT; @@ -1526,7 +1526,7 @@ lua_mimepart_get_type(lua_State *L) return lua_mimepart_get_type_common(L, part->ct, FALSE); } -static gint +static int lua_mimepart_get_type_full(lua_State *L) { LUA_TRACE_POINT; @@ -1539,7 +1539,7 @@ lua_mimepart_get_type_full(lua_State *L) return lua_mimepart_get_type_common(L, part->ct, TRUE); } -static gint +static int lua_mimepart_get_detected_type(lua_State *L) { LUA_TRACE_POINT; @@ -1552,7 +1552,7 @@ lua_mimepart_get_detected_type(lua_State *L) return lua_mimepart_get_type_common(L, part->detected_ct, FALSE); } -static gint +static int lua_mimepart_get_detected_type_full(lua_State *L) { LUA_TRACE_POINT; @@ -1565,7 +1565,7 @@ lua_mimepart_get_detected_type_full(lua_State *L) return lua_mimepart_get_type_common(L, part->detected_ct, TRUE); } -static gint +static int lua_mimepart_get_detected_ext(lua_State *L) { LUA_TRACE_POINT; @@ -1585,7 +1585,7 @@ lua_mimepart_get_detected_ext(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_cte(lua_State *L) { LUA_TRACE_POINT; @@ -1601,7 +1601,7 @@ lua_mimepart_get_cte(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_filename(lua_State *L) { LUA_TRACE_POINT; @@ -1617,7 +1617,7 @@ lua_mimepart_get_filename(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_boundary(lua_State *L) { LUA_TRACE_POINT; @@ -1646,7 +1646,7 @@ lua_mimepart_get_boundary(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_enclosing_boundary(lua_State *L) { LUA_TRACE_POINT; @@ -1669,11 +1669,11 @@ lua_mimepart_get_enclosing_boundary(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_header_common(lua_State *L, enum rspamd_lua_task_header_type how) { struct rspamd_mime_part *part = lua_check_mimepart(L); - const gchar *name; + const char *name; gboolean strong = FALSE; name = luaL_checkstring(L, 2); @@ -1696,35 +1696,35 @@ lua_mimepart_get_header_common(lua_State *L, enum rspamd_lua_task_header_type ho return 1; } -static gint +static int lua_mimepart_get_header_full(lua_State *L) { LUA_TRACE_POINT; return lua_mimepart_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_FULL); } -static gint +static int lua_mimepart_get_header(lua_State *L) { LUA_TRACE_POINT; return lua_mimepart_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_SIMPLE); } -static gint +static int lua_mimepart_get_header_raw(lua_State *L) { LUA_TRACE_POINT; return lua_mimepart_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_RAW); } -static gint +static int lua_mimepart_get_header_count(lua_State *L) { LUA_TRACE_POINT; return lua_mimepart_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_COUNT); } -static gint +static int lua_mimepart_get_raw_headers(lua_State *L) { LUA_TRACE_POINT; @@ -1746,7 +1746,7 @@ lua_mimepart_get_raw_headers(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_headers(lua_State *L) { LUA_TRACE_POINT; @@ -1784,7 +1784,7 @@ lua_mimepart_get_headers(lua_State *L) } -static gint +static int lua_mimepart_is_image(lua_State *L) { LUA_TRACE_POINT; @@ -1799,7 +1799,7 @@ lua_mimepart_is_image(lua_State *L) return 1; } -static gint +static int lua_mimepart_is_archive(lua_State *L) { LUA_TRACE_POINT; @@ -1814,7 +1814,7 @@ lua_mimepart_is_archive(lua_State *L) return 1; } -static gint +static int lua_mimepart_is_multipart(lua_State *L) { LUA_TRACE_POINT; @@ -1829,7 +1829,7 @@ lua_mimepart_is_multipart(lua_State *L) return 1; } -static gint +static int lua_mimepart_is_message(lua_State *L) { LUA_TRACE_POINT; @@ -1844,7 +1844,7 @@ lua_mimepart_is_message(lua_State *L) return 1; } -static gint +static int lua_mimepart_is_attachment(lua_State *L) { LUA_TRACE_POINT; @@ -1880,7 +1880,7 @@ lua_mimepart_is_attachment(lua_State *L) return 1; } -static gint +static int lua_mimepart_is_text(lua_State *L) { LUA_TRACE_POINT; @@ -1895,7 +1895,7 @@ lua_mimepart_is_text(lua_State *L) return 1; } -static gint +static int lua_mimepart_is_broken(lua_State *L) { LUA_TRACE_POINT; @@ -1915,7 +1915,7 @@ lua_mimepart_is_broken(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_image(lua_State *L) { LUA_TRACE_POINT; @@ -1938,7 +1938,7 @@ lua_mimepart_get_image(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_archive(lua_State *L) { LUA_TRACE_POINT; @@ -1961,13 +1961,13 @@ lua_mimepart_get_archive(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_children(lua_State *L) { LUA_TRACE_POINT; struct rspamd_mime_part *part = lua_check_mimepart(L); struct rspamd_mime_part **pcur, *cur; - guint i; + unsigned int i; if (part == NULL) { return luaL_error(L, "invalid arguments"); @@ -1991,7 +1991,7 @@ lua_mimepart_get_children(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_parent(lua_State *L) { LUA_TRACE_POINT; @@ -2015,7 +2015,7 @@ lua_mimepart_get_parent(lua_State *L) } -static gint +static int lua_mimepart_get_text(lua_State *L) { LUA_TRACE_POINT; @@ -2038,12 +2038,12 @@ lua_mimepart_get_text(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_digest(lua_State *L) { LUA_TRACE_POINT; struct rspamd_mime_part *part = lua_check_mimepart(L); - gchar digestbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; + char digestbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; if (part == NULL) { return luaL_error(L, "invalid arguments"); @@ -2057,7 +2057,7 @@ lua_mimepart_get_digest(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_id(lua_State *L) { LUA_TRACE_POINT; @@ -2072,7 +2072,7 @@ lua_mimepart_get_id(lua_State *L) return 1; } -static gint +static int lua_mimepart_headers_foreach(lua_State *L) { LUA_TRACE_POINT; @@ -2080,7 +2080,7 @@ lua_mimepart_headers_foreach(lua_State *L) enum rspamd_lua_task_header_type how = RSPAMD_TASK_HEADER_PUSH_SIMPLE; struct rspamd_lua_regexp *re = NULL; struct rspamd_mime_header *hdr, *cur; - gint old_top; + int old_top; if (part && lua_isfunction(L, 2)) { if (lua_istable(L, 3)) { @@ -2155,7 +2155,7 @@ lua_mimepart_headers_foreach(lua_State *L) return 0; } -static gint +static int lua_mimepart_get_specific(lua_State *L) { LUA_TRACE_POINT; @@ -2175,7 +2175,7 @@ lua_mimepart_get_specific(lua_State *L) return 1; } -static gint +static int lua_mimepart_get_urls(lua_State *L) { LUA_TRACE_POINT; @@ -2187,8 +2187,8 @@ lua_mimepart_get_urls(lua_State *L) struct lua_tree_cb_data cb; struct rspamd_url *u; - static const gint default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS | - PROTOCOL_FILE | PROTOCOL_FTP; + static const int default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS | + PROTOCOL_FILE | PROTOCOL_FTP; gsize sz, max_urls = 0, i; if (part->urls == NULL) { @@ -2216,7 +2216,7 @@ lua_mimepart_get_urls(lua_State *L) return 1; } -static gint +static int lua_mimepart_is_specific(lua_State *L) { LUA_TRACE_POINT; @@ -2231,7 +2231,7 @@ lua_mimepart_is_specific(lua_State *L) return 1; } -static gint +static int lua_mimepart_set_specific(lua_State *L) { LUA_TRACE_POINT; @@ -2263,7 +2263,7 @@ lua_mimepart_set_specific(lua_State *L) part->specific.lua_specific.cbref = luaL_ref(L, LUA_REGISTRYINDEX); /* Now stack has just a return value as luaL_ref removes value from stack */ - gint ltype = lua_type(L, 2); + int ltype = lua_type(L, 2); switch (ltype) { case LUA_TTABLE: diff --git a/src/lua/lua_parsers.c b/src/lua/lua_parsers.c index 1fc71db33..f77b36952 100644 --- a/src/lua/lua_parsers.c +++ b/src/lua/lua_parsers.c @@ -99,10 +99,10 @@ static const struct luaL_reg parserslib_f[] = { {NULL, NULL}}; -gint lua_parsers_tokenize_text(lua_State *L) +int lua_parsers_tokenize_text(lua_State *L) { LUA_TRACE_POINT; - const gchar *in = NULL; + const char *in = NULL; gsize len = 0, pos, ex_len, i; GList *exceptions = NULL, *cur; struct rspamd_lua_text *t; @@ -165,7 +165,7 @@ gint lua_parsers_tokenize_text(lua_State *L) len, &uc_err); - res = rspamd_tokenize_text((gchar *) in, len, + res = rspamd_tokenize_text((char *) in, len, &utxt, RSPAMD_TOKENIZE_UTF, NULL, exceptions, @@ -197,11 +197,11 @@ gint lua_parsers_tokenize_text(lua_State *L) return 1; } -gint lua_parsers_parse_html(lua_State *L) +int lua_parsers_parse_html(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t; - const gchar *start = NULL; + const char *start = NULL; gsize len; GByteArray *in; rspamd_mempool_t *pool; @@ -240,13 +240,13 @@ gint lua_parsers_parse_html(lua_State *L) return 1; } -gint lua_parsers_parse_mail_address(lua_State *L) +int lua_parsers_parse_mail_address(lua_State *L) { LUA_TRACE_POINT; GPtrArray *addrs; gsize len; - const gchar *str = luaL_checklstring(L, 1, &len); - gint max_addrs = luaL_optinteger(L, 3, 10240); + const char *str = luaL_checklstring(L, 1, &len); + int max_addrs = luaL_optinteger(L, 3, 10240); rspamd_mempool_t *pool; gboolean own_pool = FALSE; @@ -285,11 +285,11 @@ gint lua_parsers_parse_mail_address(lua_State *L) return 1; } -gint lua_parsers_parse_content_type(lua_State *L) +int lua_parsers_parse_content_type(lua_State *L) { LUA_TRACE_POINT; gsize len; - const gchar *ct_str = luaL_checklstring(L, 1, &len); + const char *ct_str = luaL_checklstring(L, 1, &len); rspamd_mempool_t *pool = rspamd_lua_check_mempool(L, 2); struct rspamd_content_type *ct; @@ -339,7 +339,7 @@ gint lua_parsers_parse_content_type(lua_State *L) struct rspamd_content_type_param *param = (struct rspamd_content_type_param *) v, *cur; - guint i = 1; + unsigned int i = 1; lua_pushlstring(L, param->name.begin, param->name.len); lua_createtable(L, 1, 0); @@ -361,7 +361,7 @@ gint lua_parsers_parse_content_type(lua_State *L) int lua_parsers_parse_smtp_date(lua_State *L) { gsize slen; - const gchar *str = lua_tolstring(L, 1, &slen); + const char *str = lua_tolstring(L, 1, &slen); GError *err = NULL; if (str == NULL) { @@ -395,7 +395,7 @@ int lua_parsers_parse_smtp_date(lua_State *L) return 1; } -static gint +static int lua_load_parsers(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index a6a23ce05..f95abb577 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -22,7 +22,7 @@ #define REDIS_DEFAULT_TIMEOUT 1.0 -static const gchar *M = "rspamd lua redis"; +static const char *M = "rspamd lua redis"; static void *redis_null; /*** @@ -101,12 +101,12 @@ struct lua_redis_userdata { struct ev_loop *event_loop; struct rspamd_config *cfg; struct rspamd_redis_pool *pool; - gchar *server; - gchar log_tag[RSPAMD_LOG_ID_LEN + 1]; + char *server; + char log_tag[RSPAMD_LOG_ID_LEN + 1]; struct lua_redis_request_specific_userdata *specific; - gdouble timeout; - guint16 port; - guint16 terminated; + double timeout; + uint16_t port; + uint16_t terminated; }; #define msg_debug_lua_redis(...) rspamd_conditional_debug_fast(NULL, NULL, \ @@ -126,21 +126,21 @@ INIT_LOG_MODULE(lua_redis) #define IS_ASYNC(ctx) ((ctx)->flags & LUA_REDIS_ASYNC) struct lua_redis_request_specific_userdata { - gint cbref; - guint nargs; - gchar **args; + int cbref; + unsigned int nargs; + char **args; gsize *arglens; struct lua_redis_userdata *c; struct lua_redis_ctx *ctx; struct lua_redis_request_specific_userdata *next; ev_timer timeout_ev; - guint flags; + unsigned int flags; }; struct lua_redis_ctx { - guint flags; + unsigned int flags; struct lua_redis_userdata async; - guint cmds_pending; + unsigned int cmds_pending; ref_entry_t ref; GQueue *replies; /* for sync connection only */ GQueue *events_cleanup; /* for sync connection only */ @@ -149,7 +149,7 @@ struct lua_redis_ctx { struct lua_redis_result { gboolean is_error; - gint result_ref; + int result_ref; struct rspamd_symcache_dynamic_item *item; struct rspamd_async_session *s; struct rspamd_task *task; @@ -157,7 +157,7 @@ struct lua_redis_result { }; static struct lua_redis_ctx * -lua_check_redis(lua_State *L, gint pos) +lua_check_redis(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_redis_classname); luaL_argcheck(L, ud != NULL, pos, "'redis' expected"); @@ -165,9 +165,9 @@ lua_check_redis(lua_State *L, gint pos) } static void -lua_redis_free_args(char **args, gsize *arglens, guint nargs) +lua_redis_free_args(char **args, gsize *arglens, unsigned int nargs) { - guint i; + unsigned int i; if (args) { for (i = 0; i < nargs; i++) { @@ -242,7 +242,7 @@ lua_redis_dtor(struct lua_redis_ctx *ctx) g_free(ctx); } -static gint +static int lua_redis_gc(lua_State *L) { struct lua_redis_ctx *ctx = lua_check_redis(L, 1); @@ -281,7 +281,7 @@ lua_redis_fin(void *arg) * @param ud */ static void -lua_redis_push_error(const gchar *err, +lua_redis_push_error(const char *err, struct lua_redis_ctx *ctx, struct lua_redis_request_specific_userdata *sp_ud, gboolean connected) @@ -336,7 +336,7 @@ lua_redis_push_error(const gchar *err, static void lua_redis_push_reply(lua_State *L, const redisReply *r, gboolean text_data) { - guint i; + unsigned int i; struct rspamd_lua_text *t; switch (r->type) { @@ -404,7 +404,7 @@ lua_redis_push_data(const redisReply *r, struct lua_redis_ctx *ctx, rspamd_symcache_set_cur_item(ud->task, ud->item); } - gint ret = lua_pcall(cbs.L, 2, 0, err_idx); + int ret = lua_pcall(cbs.L, 2, 0, err_idx); if (ret != 0) { msg_info("call to lua_redis callback failed (%d): %s", @@ -517,11 +517,11 @@ lua_redis_callback(redisAsyncContext *c, gpointer r, gpointer priv) REDIS_RELEASE(ctx); } -static gint +static int lua_redis_push_results(struct lua_redis_ctx *ctx, lua_State *L) { - gint results = g_queue_get_length(ctx->replies); - gint i; + int results = g_queue_get_length(ctx->replies); + int i; gboolean can_use_lua = TRUE; results = g_queue_get_length(ctx->replies); @@ -589,7 +589,7 @@ lua_redis_callback_sync(redisAsyncContext *ac, gpointer r, gpointer priv) struct lua_redis_ctx *ctx; struct lua_redis_userdata *ud; struct thread_entry *thread; - gint results; + int results; ctx = sp_ud->ctx; ud = sp_ud->c; @@ -771,12 +771,12 @@ lua_redis_timeout(EV_P_ ev_timer *w, int revents) static void -lua_redis_parse_args(lua_State *L, gint idx, const gchar *cmd, - gchar ***pargs, gsize **parglens, guint *nargs) +lua_redis_parse_args(lua_State *L, int idx, const char *cmd, + char ***pargs, gsize **parglens, unsigned int *nargs) { - gchar **args = NULL; + char **args = NULL; gsize *arglens; - gint top; + int top; if (idx != 0 && lua_type(L, idx) == LUA_TTABLE) { /* Get all arguments */ @@ -785,7 +785,7 @@ lua_redis_parse_args(lua_State *L, gint idx, const gchar *cmd, top = 0; while (lua_next(L, -2) != 0) { - gint type = lua_type(L, -1); + int type = lua_type(L, -1); if (type == LUA_TNUMBER || type == LUA_TSTRING || type == LUA_TUSERDATA) { @@ -794,7 +794,7 @@ lua_redis_parse_args(lua_State *L, gint idx, const gchar *cmd, lua_pop(L, 1); } - args = g_malloc((top + 1) * sizeof(gchar *)); + args = g_malloc((top + 1) * sizeof(char *)); arglens = g_malloc((top + 1) * sizeof(gsize)); arglens[0] = strlen(cmd); args[0] = g_malloc(arglens[0]); @@ -803,10 +803,10 @@ lua_redis_parse_args(lua_State *L, gint idx, const gchar *cmd, lua_pushnil(L); while (lua_next(L, -2) != 0) { - gint type = lua_type(L, -1); + int type = lua_type(L, -1); if (type == LUA_TSTRING) { - const gchar *s; + const char *s; s = lua_tolstring(L, -1, &arglens[top]); args[top] = g_malloc(arglens[top]); @@ -826,11 +826,11 @@ lua_redis_parse_args(lua_State *L, gint idx, const gchar *cmd, } } else if (type == LUA_TNUMBER) { - gdouble val = lua_tonumber(L, -1); - gint r; - gchar numbuf[64]; + double val = lua_tonumber(L, -1); + int r; + char numbuf[64]; - if (val == (gdouble) ((int64_t) val)) { + if (val == (double) ((int64_t) val)) { r = rspamd_snprintf(numbuf, sizeof(numbuf), "%L", (int64_t) val); } @@ -853,7 +853,7 @@ lua_redis_parse_args(lua_State *L, gint idx, const gchar *cmd, else { /* Use merely cmd */ - args = g_malloc(sizeof(gchar *)); + args = g_malloc(sizeof(char *)); arglens = g_malloc(sizeof(gsize)); arglens[0] = strlen(cmd); args[0] = g_malloc(arglens[0]); @@ -867,21 +867,21 @@ lua_redis_parse_args(lua_State *L, gint idx, const gchar *cmd, } static struct lua_redis_ctx * -rspamd_lua_redis_prepare_connection(lua_State *L, gint *pcbref, gboolean is_async) +rspamd_lua_redis_prepare_connection(lua_State *L, int *pcbref, gboolean is_async) { struct lua_redis_ctx *ctx = NULL; rspamd_inet_addr_t *ip = NULL; struct lua_redis_userdata *ud = NULL; struct rspamd_lua_ip *addr = NULL; struct rspamd_task *task = NULL; - const gchar *host = NULL; - const gchar *username = NULL, *password = NULL, *dbname = NULL, *log_tag = NULL; - gint cbref = -1; + const char *host = NULL; + const char *username = NULL, *password = NULL, *dbname = NULL, *log_tag = NULL; + int cbref = -1; struct rspamd_config *cfg = NULL; struct rspamd_async_session *session = NULL; struct ev_loop *ev_base = NULL; gboolean ret = FALSE; - guint flags = 0; + unsigned int flags = 0; if (lua_istable(L, 1)) { /* Table version */ @@ -1117,9 +1117,9 @@ lua_redis_make_request(lua_State *L) struct lua_redis_request_specific_userdata *sp_ud; struct lua_redis_userdata *ud; struct lua_redis_ctx *ctx, **pctx; - const gchar *cmd = NULL; - gdouble timeout = REDIS_DEFAULT_TIMEOUT; - gint cbref = -1; + const char *cmd = NULL; + double timeout = REDIS_DEFAULT_TIMEOUT; + int cbref = -1; gboolean ret = FALSE; ctx = rspamd_lua_redis_prepare_connection(L, &cbref, TRUE); @@ -1156,7 +1156,7 @@ lua_redis_make_request(lua_State *L) lua_redis_callback, sp_ud, sp_ud->nargs, - (const gchar **) sp_ud->args, + (const char **) sp_ud->args, sp_ud->arglens); if (ret == REDIS_OK) { @@ -1230,13 +1230,13 @@ lua_redis_make_request_sync(lua_State *L) LUA_TRACE_POINT; struct rspamd_lua_ip *addr = NULL; rspamd_inet_addr_t *ip = NULL; - const gchar *cmd = NULL, *host; + const char *cmd = NULL, *host; struct timeval tv; gboolean ret = FALSE; - gdouble timeout = REDIS_DEFAULT_TIMEOUT; - gchar **args = NULL; + double timeout = REDIS_DEFAULT_TIMEOUT; + char **args = NULL; gsize *arglens = NULL; - guint nargs = 0, flags = 0; + unsigned int nargs = 0, flags = 0; redisContext *ctx; redisReply *r; @@ -1323,7 +1323,7 @@ lua_redis_make_request_sync(lua_State *L) r = redisCommandArgv(ctx, nargs, - (const gchar **) args, + (const char **) args, arglens); if (r != NULL) { @@ -1376,7 +1376,7 @@ lua_redis_connect(lua_State *L) LUA_TRACE_POINT; struct lua_redis_userdata *ud; struct lua_redis_ctx *ctx, **pctx; - gdouble timeout = REDIS_DEFAULT_TIMEOUT; + double timeout = REDIS_DEFAULT_TIMEOUT; ctx = rspamd_lua_redis_prepare_connection(L, NULL, TRUE); @@ -1418,7 +1418,7 @@ static int lua_redis_connect_sync(lua_State *L) { LUA_TRACE_POINT; - gdouble timeout = REDIS_DEFAULT_TIMEOUT; + double timeout = REDIS_DEFAULT_TIMEOUT; struct lua_redis_ctx *ctx, **pctx; ctx = rspamd_lua_redis_prepare_connection(L, NULL, FALSE); @@ -1463,9 +1463,9 @@ lua_redis_add_cmd(lua_State *L) struct lua_redis_ctx *ctx = lua_check_redis(L, 1); struct lua_redis_request_specific_userdata *sp_ud; struct lua_redis_userdata *ud; - const gchar *cmd = NULL; - gint args_pos = 2; - gint cbref = -1, ret; + const char *cmd = NULL; + int args_pos = 2; + int cbref = -1, ret; if (ctx) { if (ctx->flags & LUA_REDIS_TERMINATED) { @@ -1520,7 +1520,7 @@ lua_redis_add_cmd(lua_State *L) lua_redis_callback, sp_ud, sp_ud->nargs, - (const gchar **) sp_ud->args, + (const char **) sp_ud->args, sp_ud->arglens); } else { @@ -1528,7 +1528,7 @@ lua_redis_add_cmd(lua_State *L) lua_redis_callback_sync, sp_ud, sp_ud->nargs, - (const gchar **) sp_ud->args, + (const char **) sp_ud->args, sp_ud->arglens); } @@ -1602,7 +1602,7 @@ lua_redis_exec(lua_State *L) lua_error(L); } if (ctx->cmds_pending == 0 && g_queue_get_length(ctx->replies) > 0) { - gint results = lua_redis_push_results(ctx, L); + int results = lua_redis_push_results(ctx, L); return results; } else { @@ -1612,7 +1612,7 @@ lua_redis_exec(lua_State *L) } } -static gint +static int lua_load_redis(lua_State *L) { lua_newtable(L); @@ -1621,7 +1621,7 @@ lua_load_redis(lua_State *L) return 1; } -static gint +static int lua_redis_null_idx(lua_State *L) { lua_pushnil(L); diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index 889e0aad8..6e2b0dc22 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -71,7 +71,7 @@ static const struct luaL_reg regexplib_f[] = { rspamd_mempool_t *regexp_static_pool = NULL; struct rspamd_lua_regexp * -lua_check_regexp(lua_State *L, gint pos) +lua_check_regexp(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_regexp_classname); @@ -96,7 +96,7 @@ lua_regexp_create(lua_State *L) LUA_TRACE_POINT; rspamd_regexp_t *re; struct rspamd_lua_regexp *new, **pnew; - const gchar *string, *flags_str = NULL; + const char *string, *flags_str = NULL; GError *err = NULL; string = luaL_checkstring(L, 1); @@ -147,8 +147,8 @@ lua_regexp_import_glob(lua_State *L) LUA_TRACE_POINT; rspamd_regexp_t *re; struct rspamd_lua_regexp *new, **pnew; - const gchar *string, *flags_str = NULL; - gchar *escaped; + const char *string, *flags_str = NULL; + char *escaped; gsize pat_len; GError *err = NULL; @@ -206,8 +206,8 @@ lua_regexp_import_plain(lua_State *L) LUA_TRACE_POINT; rspamd_regexp_t *re; struct rspamd_lua_regexp *new, **pnew; - const gchar *string, *flags_str = NULL; - gchar *escaped; + const char *string, *flags_str = NULL; + char *escaped; gsize pat_len; GError *err = NULL; @@ -262,7 +262,7 @@ lua_regexp_get_cached(lua_State *L) LUA_TRACE_POINT; rspamd_regexp_t *re; struct rspamd_lua_regexp *new, **pnew; - const gchar *string, *flags_str = NULL; + const char *string, *flags_str = NULL; string = luaL_checkstring(L, 1); if (lua_gettop(L) == 2) { @@ -313,7 +313,7 @@ lua_regexp_create_cached(lua_State *L) LUA_TRACE_POINT; rspamd_regexp_t *re; struct rspamd_lua_regexp *new, **pnew; - const gchar *string, *flags_str = NULL; + const char *string, *flags_str = NULL; GError *err = NULL; string = luaL_checkstring(L, 1); @@ -420,7 +420,7 @@ lua_regexp_set_max_hits(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_regexp *re = lua_check_regexp(L, 1); - guint lim; + unsigned int lim; lim = luaL_checkinteger(L, 2); @@ -487,10 +487,10 @@ lua_regexp_search(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_regexp *re = lua_check_regexp(L, 1); - const gchar *data = NULL; + const char *data = NULL; struct rspamd_lua_text *t; - const gchar *start = NULL, *end = NULL; - gint i; + const char *start = NULL, *end = NULL; + int i; gsize len = 0, capn; gboolean matched = FALSE, capture = FALSE, raw = FALSE; GArray *captures = NULL; @@ -580,7 +580,7 @@ lua_regexp_match(lua_State *L) LUA_TRACE_POINT; struct rspamd_lua_regexp *re = lua_check_regexp(L, 1); struct rspamd_lua_text *t; - const gchar *data = NULL; + const char *data = NULL; gsize len = 0; gboolean raw = FALSE; @@ -637,8 +637,8 @@ lua_regexp_matchn(lua_State *L) LUA_TRACE_POINT; struct rspamd_lua_regexp *re = lua_check_regexp(L, 1); struct rspamd_lua_text *t; - const gchar *data = NULL, *start = NULL, *end = NULL; - gint max_matches, matches; + const char *data = NULL, *start = NULL, *end = NULL; + int max_matches, matches; gsize len = 0; gboolean raw = FALSE; @@ -703,12 +703,12 @@ lua_regexp_split(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_regexp *re = lua_check_regexp(L, 1); - const gchar *data = NULL; + const char *data = NULL; struct rspamd_lua_text *t; gboolean matched = FALSE, is_text = FALSE; gsize len = 0; - const gchar *start = NULL, *end = NULL, *old_start; - gint i; + const char *start = NULL, *end = NULL, *old_start; + int i; if (re && !IS_DESTROYED(re)) { if (lua_type(L, 2) == LUA_TSTRING) { @@ -794,7 +794,7 @@ lua_regexp_split(lua_State *L) * @method re:destroy() * Destroy regexp from caches if needed (the pointer is removed by garbage collector) */ -static gint +static int lua_regexp_destroy(lua_State *L) { LUA_TRACE_POINT; @@ -810,7 +810,7 @@ lua_regexp_destroy(lua_State *L) return 0; } -static gint +static int lua_regexp_gc(lua_State *L) { LUA_TRACE_POINT; @@ -829,7 +829,7 @@ lua_regexp_gc(lua_State *L) return 0; } -static gint +static int lua_load_regexp(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_rsa.c b/src/lua/lua_rsa.c index c2ea39fa5..0f67e91d1 100644 --- a/src/lua/lua_rsa.c +++ b/src/lua/lua_rsa.c @@ -118,11 +118,11 @@ lua_check_rsa_sign(lua_State *L, int pos) return ud ? *((rspamd_fstring_t **) ud) : NULL; } -static gint +static int lua_rsa_pubkey_load(lua_State *L) { RSA *rsa = NULL, **prsa; - const gchar *filename; + const char *filename; FILE *f; filename = luaL_checkstring(L, 1); @@ -154,11 +154,11 @@ lua_rsa_pubkey_load(lua_State *L) return 1; } -static gint +static int lua_rsa_privkey_save(lua_State *L) { - const gchar *filename; - const gchar *type = "pem"; + const char *filename; + const char *type = "pem"; FILE *f; int ret; @@ -220,11 +220,11 @@ lua_rsa_privkey_save(lua_State *L) } -static gint +static int lua_rsa_pubkey_create(lua_State *L) { RSA *rsa = NULL, **prsa; - const gchar *buf; + const char *buf; BIO *bp; buf = luaL_checkstring(L, 1); @@ -249,7 +249,7 @@ lua_rsa_pubkey_create(lua_State *L) return 1; } -static gint +static int lua_rsa_pubkey_gc(lua_State *L) { RSA *rsa = lua_check_rsa_pubkey(L, 1); @@ -261,14 +261,14 @@ lua_rsa_pubkey_gc(lua_State *L) return 0; } -static gint +static int lua_rsa_pubkey_tostring(lua_State *L) { RSA *rsa = lua_check_rsa_pubkey(L, 1); if (rsa != NULL) { BIO *pubout = BIO_new(BIO_s_mem()); - const gchar *pubdata; + const char *pubdata; gsize publen; int rc = i2d_RSA_PUBKEY_bio(pubout, rsa); @@ -289,11 +289,11 @@ lua_rsa_pubkey_tostring(lua_State *L) return 1; } -static gint +static int lua_rsa_privkey_load_file(lua_State *L) { RSA *rsa = NULL, **prsa; - const gchar *filename; + const char *filename; FILE *f; filename = luaL_checkstring(L, 1); @@ -325,13 +325,13 @@ lua_rsa_privkey_load_file(lua_State *L) return 1; } -static gint +static int lua_rsa_privkey_load_pem(lua_State *L) { RSA *rsa = NULL, **prsa; BIO *b; struct rspamd_lua_text *t; - const gchar *data; + const char *data; gsize len; if (lua_isuserdata(L, 1)) { @@ -371,13 +371,13 @@ lua_rsa_privkey_load_pem(lua_State *L) return 1; } -static gint +static int lua_rsa_privkey_load_raw(lua_State *L) { RSA *rsa = NULL, **prsa; BIO *b; struct rspamd_lua_text *t; - const gchar *data; + const char *data; gsize len; if (lua_isuserdata(L, 1)) { @@ -418,15 +418,15 @@ lua_rsa_privkey_load_raw(lua_State *L) return 1; } -static gint +static int lua_rsa_privkey_load_base64(lua_State *L) { RSA *rsa = NULL, **prsa; BIO *b; EVP_PKEY *evp = NULL; struct rspamd_lua_text *t; - const gchar *data; - guchar *decoded; + const char *data; + unsigned char *decoded; gsize len, dec_len; if (lua_isuserdata(L, 1)) { @@ -486,11 +486,11 @@ lua_rsa_privkey_load_base64(lua_State *L) return 1; } -static gint +static int lua_rsa_privkey_create(lua_State *L) { RSA *rsa = NULL, **prsa; - const gchar *buf; + const char *buf; BIO *bp; buf = luaL_checkstring(L, 1); @@ -515,7 +515,7 @@ lua_rsa_privkey_create(lua_State *L) return 1; } -static gint +static int lua_rsa_privkey_gc(lua_State *L) { RSA *rsa = lua_check_rsa_privkey(L, 1); @@ -527,11 +527,11 @@ lua_rsa_privkey_gc(lua_State *L) return 0; } -static gint +static int lua_rsa_signature_load(lua_State *L) { rspamd_fstring_t *sig, **psig; - const gchar *filename; + const char *filename; gpointer data; int fd; struct stat st; @@ -567,12 +567,12 @@ lua_rsa_signature_load(lua_State *L) return 1; } -static gint +static int lua_rsa_signature_save(lua_State *L) { rspamd_fstring_t *sig; - gint fd, flags; - const gchar *filename; + int fd, flags; + const char *filename; gboolean forced = FALSE, res = TRUE; sig = lua_check_rsa_sign(L, 1); @@ -618,11 +618,11 @@ lua_rsa_signature_save(lua_State *L) return 1; } -static gint +static int lua_rsa_signature_create(lua_State *L) { rspamd_fstring_t *sig, **psig; - const gchar *data; + const char *data; gsize dlen; data = luaL_checklstring(L, 1, &dlen); @@ -636,7 +636,7 @@ lua_rsa_signature_create(lua_State *L) return 1; } -static gint +static int lua_rsa_signature_gc(lua_State *L) { rspamd_fstring_t *sig = lua_check_rsa_sign(L, 1); @@ -646,12 +646,12 @@ lua_rsa_signature_gc(lua_State *L) return 0; } -static gint +static int lua_rsa_signature_base64(lua_State *L) { rspamd_fstring_t *sig = lua_check_rsa_sign(L, 1); - guint boundary = 0; - gchar *b64; + unsigned int boundary = 0; + char *b64; gsize outlen; enum rspamd_newlines_type how = RSPAMD_TASK_NEWLINES_CRLF; @@ -660,7 +660,7 @@ lua_rsa_signature_base64(lua_State *L) } if (lua_isstring(L, 3)) { - const gchar *how_str = lua_tostring(L, 3); + const char *how_str = lua_tostring(L, 3); if (strcmp(how_str, "cr") == 0) { how = RSPAMD_TASK_NEWLINES_CR; @@ -696,14 +696,14 @@ lua_rsa_signature_base64(lua_State *L) * true - if string match rsa signature * false - otherwise */ -static gint +static int lua_rsa_verify_memory(lua_State *L) { RSA *rsa; rspamd_fstring_t *signature; - const gchar *data; + const char *data; gsize sz; - gint ret; + int ret; rsa = lua_check_rsa_pubkey(L, 1); signature = lua_check_rsa_sign(L, 2); @@ -740,14 +740,14 @@ lua_rsa_verify_memory(lua_State *L) * rspamd_signature object * nil - otherwise */ -static gint +static int lua_rsa_sign_memory(lua_State *L) { RSA *rsa; rspamd_fstring_t *signature, **psig; - const gchar *data; + const char *data; gsize sz; - gint ret; + int ret; rsa = lua_check_rsa_privkey(L, 1); data = luaL_checklstring(L, 2, &sz); @@ -755,7 +755,7 @@ lua_rsa_sign_memory(lua_State *L) if (rsa != NULL && data != NULL) { signature = rspamd_fstring_sized_new(RSA_size(rsa)); - guint siglen = signature->len; + unsigned int siglen = signature->len; ret = RSA_sign(NID_sha256, data, sz, signature->str, &siglen, rsa); @@ -779,12 +779,12 @@ lua_rsa_sign_memory(lua_State *L) return 1; } -static gint +static int lua_rsa_keypair(lua_State *L) { BIGNUM *e; RSA *rsa, *pub_rsa, *priv_rsa, **prsa; - gint bits = lua_gettop(L) > 0 ? lua_tointeger(L, 1) : 1024; + int bits = lua_gettop(L) > 0 ? lua_tointeger(L, 1) : 1024; if (bits > 4096 || bits < 512) { return luaL_error(L, "invalid bits count"); @@ -811,7 +811,7 @@ lua_rsa_keypair(lua_State *L) return 2; } -static gint +static int lua_load_pubkey(lua_State *L) { lua_newtable(L); @@ -820,7 +820,7 @@ lua_load_pubkey(lua_State *L) return 1; } -static gint +static int lua_load_privkey(lua_State *L) { lua_newtable(L); @@ -829,7 +829,7 @@ lua_load_privkey(lua_State *L) return 1; } -static gint +static int lua_load_signature(lua_State *L) { lua_newtable(L); @@ -838,7 +838,7 @@ lua_load_signature(lua_State *L) return 1; } -static gint +static int lua_load_rsa(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_spf.c b/src/lua/lua_spf.c index caea3e3b9..46e72202f 100644 --- a/src/lua/lua_spf.c +++ b/src/lua/lua_spf.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2019 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -56,11 +56,11 @@ struct rspamd_lua_spf_cbdata { struct rspamd_task *task; lua_State *L; struct rspamd_symcache_dynamic_item *item; - gint cbref; + int cbref; ref_entry_t ref; }; -static gint +static int lua_load_spf(lua_State *L) { lua_newtable(L); @@ -107,14 +107,14 @@ void luaopen_spf(lua_State *L) } static void -lua_spf_push_result(struct rspamd_lua_spf_cbdata *cbd, gint code_flags, - struct spf_resolved *resolved, const gchar *err) +lua_spf_push_result(struct rspamd_lua_spf_cbdata *cbd, int code_flags, + struct spf_resolved *resolved, const char *err) { g_assert(cbd != NULL); REF_RETAIN(cbd); lua_pushcfunction(cbd->L, &rspamd_lua_traceback); - gint err_idx = lua_gettop(cbd->L); + int err_idx = lua_gettop(cbd->L); lua_rawgeti(cbd->L, LUA_REGISTRYINDEX, cbd->cbref); @@ -211,7 +211,7 @@ spf_lua_lib_callback(struct spf_resolved *record, struct rspamd_task *task, * @param {rspamd_task} task task * @param {function} callback callback that is called on spf resolution */ -gint lua_spf_resolve(lua_State *L) +int lua_spf_resolve(lua_State *L) { struct rspamd_task *task = lua_check_task(L, 1); @@ -254,7 +254,7 @@ gint lua_spf_resolve(lua_State *L) return 0; } -static gint +static int lua_spf_record_dtor(lua_State *L) { struct spf_resolved *record; @@ -273,7 +273,7 @@ lua_spf_record_dtor(lua_State *L) static void lua_spf_push_spf_addr(lua_State *L, struct spf_addr *addr) { - gchar *addr_mask; + char *addr_mask; lua_createtable(L, 0, 4); @@ -296,13 +296,13 @@ lua_spf_push_spf_addr(lua_State *L, struct spf_addr *addr) } } -static gint +static int spf_check_element(lua_State *L, struct spf_resolved *rec, struct spf_addr *addr, struct rspamd_lua_ip *ip) { gboolean res = FALSE; - const guint8 *s, *d; - guint af, mask, bmask, addrlen; + const uint8_t *s, *d; + unsigned int af, mask, bmask, addrlen; if (addr->flags & RSPAMD_SPF_FLAG_TEMPFAIL) { @@ -318,11 +318,11 @@ spf_check_element(lua_State *L, struct spf_resolved *rec, struct spf_addr *addr, d = rspamd_inet_address_get_hash_key(ip->addr, &addrlen); if (af == AF_INET6) { - s = (const guint8 *) addr->addr6; + s = (const uint8_t *) addr->addr6; mask = addr->m.dual.mask_v6; } else { - s = (const guint8 *) addr->addr4; + s = (const uint8_t *) addr->addr4; mask = addr->m.dual.mask_v4; } @@ -396,7 +396,7 @@ spf_check_element(lua_State *L, struct spf_resolved *rec, struct spf_addr *addr, * @param {rspamd_ip|string} ip address * @return {result,flag_or_policy,error_or_addr} - triplet */ -static gint +static int lua_spf_record_check_ip(lua_State *L) { struct spf_resolved *record; @@ -404,14 +404,14 @@ lua_spf_record_check_ip(lua_State *L) struct spf_resolved, record); struct rspamd_lua_ip *ip = NULL; - gint nres = 0; + int nres = 0; gboolean need_free_ip = FALSE; if (lua_type(L, 2) == LUA_TUSERDATA) { ip = lua_check_ip(L, 2); } else if (lua_type(L, 2) == LUA_TSTRING) { - const gchar *ip_str; + const char *ip_str; gsize iplen; ip = g_malloc0(sizeof(struct rspamd_lua_ip)); @@ -428,7 +428,7 @@ lua_spf_record_check_ip(lua_State *L) } if (record && ip && ip->addr) { - for (guint i = 0; i < record->elts->len; i++) { + for (unsigned int i = 0; i < record->elts->len; i++) { struct spf_addr *addr = &g_array_index(record->elts, struct spf_addr, i); if ((nres = spf_check_element(L, record, addr, ip)) > 0) { if (need_free_ip) { @@ -473,7 +473,7 @@ lua_spf_record_check_ip(lua_State *L) * @method rspamd_spf_record:get_domain() * Returns domain for the specific spf record */ -static gint +static int lua_spf_record_get_domain(lua_State *L) { struct spf_resolved *record; @@ -495,7 +495,7 @@ lua_spf_record_get_domain(lua_State *L) * @method rspamd_spf_record:get_ttl() * Returns ttl for the specific spf record */ -static gint +static int lua_spf_record_get_ttl(lua_State *L) { struct spf_resolved *record; @@ -517,7 +517,7 @@ lua_spf_record_get_ttl(lua_State *L) * @method rspamd_spf_record:get_timestamp() * Returns ttl for the specific spf record */ -static gint +static int lua_spf_record_get_timestamp(lua_State *L) { struct spf_resolved *record; @@ -539,7 +539,7 @@ lua_spf_record_get_timestamp(lua_State *L) * @method rspamd_spf_record:get_digest() * Returns string hex representation of the record digest (fast hash function) */ -static gint +static int lua_spf_record_get_digest(lua_State *L) { struct spf_resolved *record; @@ -548,7 +548,7 @@ lua_spf_record_get_digest(lua_State *L) record); if (record) { - gchar hexbuf[64]; + char hexbuf[64]; rspamd_snprintf(hexbuf, sizeof(hexbuf), "%xuL", record->digest); lua_pushstring(L, hexbuf); @@ -570,7 +570,7 @@ lua_spf_record_get_digest(lua_State *L) * - addr - address and mask as a string * - str - string representation (if available) */ -static gint +static int lua_spf_record_get_elts(lua_State *L) { struct spf_resolved *record; @@ -579,7 +579,7 @@ lua_spf_record_get_elts(lua_State *L) record); if (record) { - guint i; + unsigned int i; struct spf_addr *addr; lua_createtable(L, record->elts->len, 0); @@ -604,7 +604,7 @@ lua_spf_record_get_elts(lua_State *L) * Configures SPF library according to the UCL config * @param {table} object configuration object */ -gint lua_spf_config(lua_State *L) +int lua_spf_config(lua_State *L) { ucl_object_t *config_obj = ucl_object_lua_import(L, 1); diff --git a/src/lua/lua_sqlite3.c b/src/lua/lua_sqlite3.c index 6926f8081..784a3ba1a 100644 --- a/src/lua/lua_sqlite3.c +++ b/src/lua/lua_sqlite3.c @@ -62,7 +62,7 @@ static const struct luaL_reg sqlitestmtlib_m[] = { static void lua_sqlite3_push_row(lua_State *L, sqlite3_stmt *stmt); static sqlite3 * -lua_check_sqlite3(lua_State *L, gint pos) +lua_check_sqlite3(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_sqlite3_classname); luaL_argcheck(L, ud != NULL, pos, "'sqlite3' expected"); @@ -70,7 +70,7 @@ lua_check_sqlite3(lua_State *L, gint pos) } static sqlite3_stmt * -lua_check_sqlite3_stmt(lua_State *L, gint pos) +lua_check_sqlite3_stmt(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_sqlite3_stmt_classname); luaL_argcheck(L, ud != NULL, pos, "'sqlite3_stmt' expected"); @@ -84,10 +84,10 @@ lua_check_sqlite3_stmt(lua_State *L, gint pos) * @param {string} path path to db * @return {sqlite3} sqlite3 handle */ -static gint +static int lua_sqlite3_open(lua_State *L) { - const gchar *path = luaL_checkstring(L, 1); + const char *path = luaL_checkstring(L, 1); sqlite3 *db, **pdb; GError *err = NULL; @@ -116,13 +116,13 @@ lua_sqlite3_open(lua_State *L) } static void -lua_sqlite3_bind_statements(lua_State *L, gint start, gint end, +lua_sqlite3_bind_statements(lua_State *L, int start, int end, sqlite3_stmt *stmt) { - gint i, type, num = 1; - const gchar *str; + int i, type, num = 1; + const char *str; gsize slen; - gdouble n; + double n; g_assert(start <= end && start > 0 && end > 0); @@ -133,7 +133,7 @@ lua_sqlite3_bind_statements(lua_State *L, gint start, gint end, case LUA_TNUMBER: n = lua_tonumber(L, i); - if (n == (gdouble) ((int64_t) n)) { + if (n == (double) ((int64_t) n)) { sqlite3_bind_int64(stmt, num, n); } else { @@ -162,15 +162,15 @@ lua_sqlite3_bind_statements(lua_State *L, gint start, gint end, * @param {string|number} args... variable number of arguments * @return {boolean} `true` if a statement has been successfully executed */ -static gint +static int lua_sqlite3_sql(lua_State *L) { LUA_TRACE_POINT; sqlite3 *db = lua_check_sqlite3(L, 1); - const gchar *query = luaL_checkstring(L, 2); + const char *query = luaL_checkstring(L, 2); sqlite3_stmt *stmt; gboolean ret = FALSE; - gint top = 1, rc; + int top = 1, rc; if (db && query) { if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) { @@ -212,11 +212,11 @@ lua_sqlite3_sql(lua_State *L) static void lua_sqlite3_push_row(lua_State *L, sqlite3_stmt *stmt) { - const gchar *str; + const char *str; gsize slen; int64_t num; - gchar numbuf[32]; - gint nresults, i, type; + char numbuf[32]; + int nresults, i, type; nresults = sqlite3_column_count(stmt); lua_createtable(L, 0, nresults); @@ -257,12 +257,12 @@ lua_sqlite3_push_row(lua_State *L, sqlite3_stmt *stmt) } } -static gint +static int lua_sqlite3_next_row(lua_State *L) { LUA_TRACE_POINT; sqlite3_stmt *stmt = *(sqlite3_stmt **) lua_touserdata(L, lua_upvalueindex(1)); - gint rc; + int rc; if (stmt != NULL) { rc = sqlite3_step(stmt); @@ -291,14 +291,14 @@ for row in db:rows([[ SELECT * FROM x ]]) do print(string.format('%d -> %s', row.id, row.value)) end */ -static gint +static int lua_sqlite3_rows(lua_State *L) { LUA_TRACE_POINT; sqlite3 *db = lua_check_sqlite3(L, 1); - const gchar *query = luaL_checkstring(L, 2); + const char *query = luaL_checkstring(L, 2); sqlite3_stmt *stmt, **pstmt; - gint top; + int top; if (db && query) { if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) { @@ -329,7 +329,7 @@ lua_sqlite3_rows(lua_State *L) return 1; } -static gint +static int lua_sqlite3_close(lua_State *L) { LUA_TRACE_POINT; @@ -342,7 +342,7 @@ lua_sqlite3_close(lua_State *L) return 0; } -static gint +static int lua_sqlite3_stmt_close(lua_State *L) { sqlite3_stmt *stmt = lua_check_sqlite3_stmt(L, 1); @@ -354,7 +354,7 @@ lua_sqlite3_stmt_close(lua_State *L) return 0; } -static gint +static int lua_load_sqlite3(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index bb2f71faf..e37c6838d 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1380,7 +1380,7 @@ static const struct luaL_reg archivelib_m[] = { /* Utility functions */ struct rspamd_task * -lua_check_task(lua_State *L, gint pos) +lua_check_task(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_task_classname); luaL_argcheck(L, ud != NULL, pos, "'task' expected"); @@ -1388,7 +1388,7 @@ lua_check_task(lua_State *L, gint pos) } struct rspamd_task * -lua_check_task_maybe(lua_State *L, gint pos) +lua_check_task_maybe(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata_maybe(L, pos, rspamd_task_classname); @@ -1412,8 +1412,8 @@ lua_check_archive(lua_State *L) } static void -lua_task_set_cached(lua_State *L, struct rspamd_task *task, const gchar *key, - gint pos) +lua_task_set_cached(lua_State *L, struct rspamd_task *task, const char *key, + int pos) { LUA_TRACE_POINT; khiter_t k; @@ -1438,7 +1438,7 @@ lua_task_set_cached(lua_State *L, struct rspamd_task *task, const gchar *key, static gboolean -lua_task_get_cached(lua_State *L, struct rspamd_task *task, const gchar *key) +lua_task_get_cached(lua_State *L, struct rspamd_task *task, const char *key) { LUA_TRACE_POINT; khiter_t k; @@ -1577,14 +1577,14 @@ lua_task_set_message(lua_State *L) if (task) { gsize final_len = 0; - gchar *buf = NULL; + char *buf = NULL; if (lua_type(L, 2) == LUA_TTABLE) { /* Piecewise construct */ - guint vec_len = rspamd_lua_table_size(L, 2); + unsigned int vec_len = rspamd_lua_table_size(L, 2); - for (guint i = 0; i < vec_len; i++) { + for (unsigned int i = 0; i < vec_len; i++) { lua_rawgeti(L, 2, i + 1); if (lua_type(L, -1) == LUA_TSTRING) { @@ -1605,17 +1605,17 @@ lua_task_set_message(lua_State *L) } if (final_len > 0) { - gchar *pos; + char *pos; buf = rspamd_mempool_alloc(task->task_pool, final_len); pos = buf; - for (guint i = 0; i < vec_len; i++) { + for (unsigned int i = 0; i < vec_len; i++) { lua_rawgeti(L, 2, i + 1); if (lua_type(L, -1) == LUA_TSTRING) { gsize l; - const gchar *s; + const char *s; s = lua_tolstring(L, -1, &l); memcpy(pos, s, l); @@ -1641,7 +1641,7 @@ lua_task_set_message(lua_State *L) } else { if (lua_type(L, 2) == LUA_TSTRING) { - const gchar *s; + const char *s; s = lua_tolstring(L, -1, &final_len); buf = rspamd_mempool_alloc(task->task_pool, final_len); @@ -1704,12 +1704,12 @@ lua_task_free_dtor(gpointer p) g_free(p); } -static gint +static int lua_task_load_from_file(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = NULL, **ptask; - const gchar *fname = luaL_checkstring(L, 1), *err = NULL; + const char *fname = luaL_checkstring(L, 1), *err = NULL; struct rspamd_config *cfg = NULL; gboolean res = FALSE; gpointer map; @@ -1728,9 +1728,9 @@ lua_task_load_from_file(lua_State *L) if (strcmp(fname, "-") == 0) { /* Read from stdin */ - gint fd = STDIN_FILENO; + int fd = STDIN_FILENO; GString *data = g_string_sized_new(BUFSIZ); - gchar buf[BUFSIZ]; + char buf[BUFSIZ]; gssize r; for (;;) { @@ -1795,12 +1795,12 @@ lua_task_load_from_file(lua_State *L) return 2; } -static gint +static int lua_task_load_from_string(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = NULL, **ptask; - const gchar *str_message; + const char *str_message; gsize message_len; struct rspamd_config *cfg = NULL; @@ -1819,7 +1819,7 @@ lua_task_load_from_string(lua_State *L) task = rspamd_task_new(NULL, cfg, NULL, NULL, NULL, FALSE); task->msg.begin = g_malloc(message_len); - memcpy((gchar *) task->msg.begin, str_message, message_len); + memcpy((char *) task->msg.begin, str_message, message_len); task->msg.len = message_len; rspamd_mempool_add_destructor(task->task_pool, lua_task_free_dtor, (gpointer) task->msg.begin); @@ -1837,7 +1837,7 @@ lua_task_load_from_string(lua_State *L) return 2; } -static gint +static int lua_task_create(lua_State *L) { LUA_TRACE_POINT; @@ -1968,17 +1968,17 @@ lua_task_get_worker(lua_State *L) } -static gint +static int lua_task_insert_result_common(lua_State *L, struct rspamd_scan_result *result, - gint common_args_pos) + int common_args_pos) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *symbol_name; + const char *symbol_name; double weight; struct rspamd_symbol_result *s; enum rspamd_symbol_insert_flags flags = RSPAMD_SYMBOL_INSERT_DEFAULT; - gint i, top, args_start; + int i, top, args_start; if (task != NULL) { if (lua_isboolean(L, common_args_pos)) { @@ -2011,7 +2011,7 @@ lua_task_insert_result_common(lua_State *L, struct rspamd_scan_result *result, lua_pop(L, 1); /* Traceback string */ } for (i = args_start + 2; i <= top; i++) { - gint ltype = lua_type(L, i); + int ltype = lua_type(L, i); if (ltype == LUA_TSTRING) { gsize optlen; @@ -2030,7 +2030,7 @@ lua_task_insert_result_common(lua_State *L, struct rspamd_scan_result *result, else if (ltype == LUA_TTABLE) { gsize objlen = rspamd_lua_table_size(L, i); - for (guint j = 1; j <= objlen; j++) { + for (unsigned int j = 1; j <= objlen; j++) { lua_rawgeti(L, i, j); if (lua_type(L, -1) == LUA_TSTRING) { @@ -2053,7 +2053,7 @@ lua_task_insert_result_common(lua_State *L, struct rspamd_scan_result *result, } } else { - const gchar *tname = lua_typename(L, lua_type(L, -1)); + const char *tname = lua_typename(L, lua_type(L, -1)); lua_pop(L, 2); return luaL_error(L, "not a string option in a table " @@ -2071,7 +2071,7 @@ lua_task_insert_result_common(lua_State *L, struct rspamd_scan_result *result, continue; } else { - const gchar *tname = lua_typename(L, ltype); + const char *tname = lua_typename(L, ltype); return luaL_error(L, "not a string/table option " "when adding symbol %s: %s type", @@ -2098,17 +2098,17 @@ lua_task_insert_result_common(lua_State *L, struct rspamd_scan_result *result, return 0; } -static gint +static int lua_task_insert_result(lua_State *L) { return lua_task_insert_result_common(L, NULL, 2); } -static gint +static int lua_task_insert_result_named(lua_State *L) { struct rspamd_task *task = lua_check_task(L, 1); - const gchar *named_result = luaL_checkstring(L, 2); + const char *named_result = luaL_checkstring(L, 2); struct rspamd_scan_result *res; if (task && named_result) { @@ -2125,16 +2125,16 @@ lua_task_insert_result_named(lua_State *L) return luaL_error(L, "invalid arguments"); } -static gint +static int lua_task_adjust_result(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *symbol_name; + const char *symbol_name; struct rspamd_scan_result *metric_res; struct rspamd_symbol_result *s = NULL; double weight; - gint i, top; + int i, top; if (task != NULL) { @@ -2181,7 +2181,7 @@ lua_task_adjust_result(lua_State *L) else if (lua_type(L, i) == LUA_TTABLE) { gsize objlen = rspamd_lua_table_size(L, i); - for (guint j = 1; j <= objlen; j++) { + for (unsigned int j = 1; j <= objlen; j++) { lua_rawgeti(L, i, j); if (lua_type(L, -1) == LUA_TSTRING) { @@ -2212,14 +2212,14 @@ lua_task_adjust_result(lua_State *L) return 0; } -static gint +static int lua_task_remove_result(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *symbol_name = luaL_checkstring(L, 2); + const char *symbol_name = luaL_checkstring(L, 2); struct rspamd_scan_result *metric_res; - const gchar *named_result = luaL_optstring(L, 3, NULL); + const char *named_result = luaL_optstring(L, 3, NULL); if (task != NULL) { metric_res = rspamd_find_metric_result(task, named_result); @@ -2239,16 +2239,16 @@ lua_task_remove_result(lua_State *L) return 1; } -static gint +static int lua_task_set_pre_result(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *message = NULL, *module = NULL, *fl_str = NULL, *act_str = NULL, - *res_name = NULL; - gdouble score = NAN; + const char *message = NULL, *module = NULL, *fl_str = NULL, *act_str = NULL, + *res_name = NULL; + double score = NAN; struct rspamd_action *action; - guint priority = RSPAMD_PASSTHROUGH_NORMAL, flags = 0; + unsigned int priority = RSPAMD_PASSTHROUGH_NORMAL, flags = 0; if (task != NULL) { @@ -2264,7 +2264,7 @@ lua_task_set_pre_result(lua_State *L) RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, "*action=S;message=S;module=S;score=D;priority=i;flags=S;result=S", &act_str, &message, &module, &score, &priority, &fl_str, &res_name)) { - gint ret = luaL_error(L, "invalid arguments: %s", err->message); + int ret = luaL_error(L, "invalid arguments: %s", err->message); g_error_free(err); return ret; @@ -2368,12 +2368,12 @@ lua_task_set_pre_result(lua_State *L) return 0; } -static gint +static int lua_task_has_pre_result(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - gint nret = 1; + int nret = 1; if (task) { if (task->result->passthrough_result) { @@ -2414,12 +2414,12 @@ lua_task_has_pre_result(lua_State *L) return nret; } -static gint +static int lua_task_append_message(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *category; + const char *category; if (task != NULL) { if (lua_type(L, 3) == LUA_TSTRING) { @@ -2442,15 +2442,15 @@ lua_task_append_message(lua_State *L) } -static gint +static int lua_task_get_urls(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); struct lua_tree_cb_data cb; struct rspamd_url *u; - static const gint default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS | - PROTOCOL_FILE | PROTOCOL_FTP; + static const int default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS | + PROTOCOL_FILE | PROTOCOL_FTP; gsize sz, max_urls = 0; if (task) { @@ -2479,7 +2479,7 @@ lua_task_get_urls(lua_State *L) if (cb.sort) { struct rspamd_url **urls_sorted; - gint i = 0; + int i = 0; urls_sorted = g_new0(struct rspamd_url *, sz); @@ -2513,15 +2513,15 @@ lua_task_get_urls(lua_State *L) return 1; } -static gint +static int lua_task_get_urls_filtered(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); struct lua_tree_cb_data cb; struct rspamd_url *u; - static const gint default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS | - PROTOCOL_FILE | PROTOCOL_FTP; + static const int default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS | + PROTOCOL_FILE | PROTOCOL_FTP; gsize sz, max_urls = 0; if (task) { @@ -2547,7 +2547,7 @@ lua_task_get_urls_filtered(lua_State *L) if (cb.sort) { struct rspamd_url **urls_sorted; - gint i = 0; + int i = 0; urls_sorted = g_new0(struct rspamd_url *, sz); @@ -2581,7 +2581,7 @@ lua_task_get_urls_filtered(lua_State *L) return 1; } -static gint +static int lua_task_has_urls(lua_State *L) { LUA_TRACE_POINT; @@ -2625,7 +2625,7 @@ lua_task_has_urls(lua_State *L) return 2; } -static gint +static int lua_task_inject_url(lua_State *L) { LUA_TRACE_POINT; @@ -2654,7 +2654,7 @@ lua_task_inject_url(lua_State *L) return 0; } -static gint +static int lua_task_get_content(lua_State *L) { LUA_TRACE_POINT; @@ -2679,7 +2679,7 @@ lua_task_get_content(lua_State *L) return 1; } -static gint +static int lua_task_get_filename(lua_State *L) { LUA_TRACE_POINT; @@ -2700,7 +2700,7 @@ lua_task_get_filename(lua_State *L) return 1; } -static gint +static int lua_task_get_rawbody(lua_State *L) { LUA_TRACE_POINT; @@ -2740,7 +2740,7 @@ lua_task_get_rawbody(lua_State *L) return 1; } -static gint +static int lua_task_get_emails(lua_State *L) { LUA_TRACE_POINT; @@ -2784,11 +2784,11 @@ lua_task_get_emails(lua_State *L) return 1; } -static gint +static int lua_task_get_text_parts(lua_State *L) { LUA_TRACE_POINT; - guint i; + unsigned int i; struct rspamd_task *task = lua_check_task(L, 1); struct rspamd_mime_text_part *part, **ppart; @@ -2821,11 +2821,11 @@ lua_task_get_text_parts(lua_State *L) return 1; } -static gint +static int lua_task_get_parts(lua_State *L) { LUA_TRACE_POINT; - guint i; + unsigned int i; struct rspamd_task *task = lua_check_task(L, 1); struct rspamd_mime_part *part, **ppart; @@ -2853,13 +2853,13 @@ lua_task_get_parts(lua_State *L) return 1; } -static gint +static int lua_task_get_request_header(lua_State *L) { LUA_TRACE_POINT; rspamd_ftok_t *hdr; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *s; + const char *s; struct rspamd_lua_text *t; s = luaL_checkstring(L, 2); @@ -2887,12 +2887,12 @@ lua_task_get_request_header(lua_State *L) return 1; } -static gint +static int lua_task_set_request_header(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *s, *v = NULL; + const char *s, *v = NULL; rspamd_fstring_t *buf; struct rspamd_lua_text *t; rspamd_ftok_t *hdr, *new_name; @@ -2931,8 +2931,8 @@ lua_task_set_request_header(lua_State *L) } -gint rspamd_lua_push_header(lua_State *L, struct rspamd_mime_header *rh, - enum rspamd_lua_task_header_type how) +int rspamd_lua_push_header(lua_State *L, struct rspamd_mime_header *rh, + enum rspamd_lua_task_header_type how) { LUA_TRACE_POINT; switch (how) { @@ -2991,16 +2991,16 @@ gint rspamd_lua_push_header(lua_State *L, struct rspamd_mime_header *rh, return 1; } -gint rspamd_lua_push_header_array(lua_State *L, - const gchar *name, - struct rspamd_mime_header *rh, - enum rspamd_lua_task_header_type how, - gboolean strong) +int rspamd_lua_push_header_array(lua_State *L, + const char *name, + struct rspamd_mime_header *rh, + enum rspamd_lua_task_header_type how, + gboolean strong) { LUA_TRACE_POINT; struct rspamd_mime_header *cur; - guint i; - gint nret = 1; + unsigned int i; + int nret = 1; if (rh == NULL) { if (how == RSPAMD_TASK_HEADER_PUSH_HAS) { @@ -3076,14 +3076,14 @@ gint rspamd_lua_push_header_array(lua_State *L, return nret; } -static gint +static int lua_task_get_header_common(lua_State *L, enum rspamd_lua_task_header_type how) { LUA_TRACE_POINT; gboolean strong = FALSE, need_modified = FALSE; struct rspamd_task *task = lua_check_task(L, 1); struct rspamd_mime_header *rh; - const gchar *name; + const char *name; name = luaL_checkstring(L, 2); @@ -3105,37 +3105,37 @@ lua_task_get_header_common(lua_State *L, enum rspamd_lua_task_header_type how) } } -static gint +static int lua_task_get_header_full(lua_State *L) { return lua_task_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_FULL); } -static gint +static int lua_task_get_header(lua_State *L) { return lua_task_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_SIMPLE); } -static gint +static int lua_task_get_header_raw(lua_State *L) { return lua_task_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_RAW); } -static gint +static int lua_task_get_header_count(lua_State *L) { return lua_task_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_COUNT); } -static gint +static int lua_task_has_header(lua_State *L) { return lua_task_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_HAS); } -static gint +static int lua_task_get_headers(lua_State *L) { LUA_TRACE_POINT; @@ -3172,7 +3172,7 @@ lua_task_get_headers(lua_State *L) return 1; } -static gint +static int lua_task_get_raw_headers(lua_State *L) { LUA_TRACE_POINT; @@ -3194,7 +3194,7 @@ lua_task_get_raw_headers(lua_State *L) return 1; } -static gint +static int lua_task_get_received_headers(lua_State *L) { LUA_TRACE_POINT; @@ -3226,7 +3226,7 @@ lua_task_get_received_headers(lua_State *L) return 1; } -static gint +static int lua_task_get_queue_id(lua_State *L) { LUA_TRACE_POINT; @@ -3247,7 +3247,7 @@ lua_task_get_queue_id(lua_State *L) return 1; } -static gint +static int lua_task_get_uid(lua_State *L) { LUA_TRACE_POINT; @@ -3263,7 +3263,7 @@ lua_task_get_uid(lua_State *L) return 1; } -static gint +static int lua_task_get_resolver(lua_State *L) { LUA_TRACE_POINT; @@ -3282,7 +3282,7 @@ lua_task_get_resolver(lua_State *L) return 1; } -static gint +static int lua_task_set_resolver(lua_State *L) { LUA_TRACE_POINT; @@ -3299,12 +3299,12 @@ lua_task_set_resolver(lua_State *L) return 0; } -static gint +static int lua_task_inc_dns_req(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - static guint warning_shown = 0; + static unsigned int warning_shown = 0; if (warning_shown < 100) { warning_shown++; @@ -3321,7 +3321,7 @@ lua_task_inc_dns_req(lua_State *L) return 0; } -static gint +static int lua_task_get_dns_req(lua_State *L) { LUA_TRACE_POINT; @@ -3352,10 +3352,10 @@ enum lua_email_address_type { * for get_from/get_recipients */ static enum lua_email_address_type -lua_task_str_to_get_type(lua_State *L, struct rspamd_task *task, gint pos, gint last_pos) +lua_task_str_to_get_type(lua_State *L, struct rspamd_task *task, int pos, int last_pos) { - const gchar *type = NULL; - gint ret = LUA_ADDRESS_ANY; + const char *type = NULL; + int ret = LUA_ADDRESS_ANY; uint64_t h; gsize sz; @@ -3389,7 +3389,7 @@ lua_task_str_to_get_type(lua_State *L, struct rspamd_task *task, gint pos, gint ret = LUA_ADDRESS_SMTP; break; default: - msg_err_task("invalid email type: %*s", (gint) sz, type); + msg_err_task("invalid email type: %*s", (int) sz, type); break; } } @@ -3421,7 +3421,7 @@ lua_task_str_to_get_type(lua_State *L, struct rspamd_task *task, gint pos, gint ret |= LUA_ADDRESS_ORIGINAL; break; default: - msg_err_task("invalid email type: %*s", (gint) sz, type); + msg_err_task("invalid email type: %*s", (int) sz, type); break; } } @@ -3518,7 +3518,7 @@ lua_push_email_address(lua_State *L, struct rspamd_email_address *addr) void lua_push_emails_address_list(lua_State *L, GPtrArray *addrs, int flags) { struct rspamd_email_address *addr; - guint i, pos = 1; + unsigned int i, pos = 1; lua_createtable(L, addrs->len, 0); @@ -3542,12 +3542,12 @@ void lua_push_emails_address_list(lua_State *L, GPtrArray *addrs, int flags) static gboolean lua_import_email_address(lua_State *L, struct rspamd_task *task, - gint pos, + int pos, struct rspamd_email_address **paddr) { struct rspamd_email_address *addr; - const gchar *p; - gchar *dst; + const char *p; + char *dst; gsize len; g_assert(paddr != NULL); @@ -3575,8 +3575,8 @@ lua_import_email_address(lua_State *L, struct rspamd_task *task, if (lua_type(L, -1) == LUA_TSTRING) { p = lua_tolstring(L, -1, &len); - addr->user = (const gchar *) rspamd_mempool_alloc(task->task_pool, len); - memcpy((gchar *) addr->user, p, len); + addr->user = (const char *) rspamd_mempool_alloc(task->task_pool, len); + memcpy((char *) addr->user, p, len); addr->user_len = len; } @@ -3587,8 +3587,8 @@ lua_import_email_address(lua_State *L, struct rspamd_task *task, if (lua_type(L, -1) == LUA_TSTRING) { p = lua_tolstring(L, -1, &len); - addr->domain = (const gchar *) rspamd_mempool_alloc(task->task_pool, len); - memcpy((gchar *) addr->domain, p, len); + addr->domain = (const char *) rspamd_mempool_alloc(task->task_pool, len); + memcpy((char *) addr->domain, p, len); addr->domain_len = len; } @@ -3599,15 +3599,15 @@ lua_import_email_address(lua_State *L, struct rspamd_task *task, if (lua_type(L, -1) == LUA_TSTRING) { p = lua_tolstring(L, -1, &len); - addr->addr = (const gchar *) rspamd_mempool_alloc(task->task_pool, len); - memcpy((gchar *) addr->addr, p, len); + addr->addr = (const char *) rspamd_mempool_alloc(task->task_pool, len); + memcpy((char *) addr->addr, p, len); addr->addr_len = len; } else { /* Construct addr */ len = addr->domain_len + addr->user_len + 1; - addr->addr = (const gchar *) rspamd_mempool_alloc(task->task_pool, len); - addr->addr_len = rspamd_snprintf((gchar *) addr->addr, len, "%*s@%*s", + addr->addr = (const char *) rspamd_mempool_alloc(task->task_pool, len); + addr->addr_len = rspamd_snprintf((char *) addr->addr, len, "%*s@%*s", (int) addr->user_len, addr->user, (int) addr->domain_len, addr->domain); } @@ -3618,7 +3618,7 @@ lua_import_email_address(lua_State *L, struct rspamd_task *task, lua_gettable(L, pos); if (lua_type(L, -1) == LUA_TSTRING) { - gchar *cpy; + char *cpy; p = lua_tolstring(L, -1, &len); cpy = rspamd_mempool_alloc(task->task_pool, len + 1); memcpy(cpy, p, len); @@ -3657,13 +3657,13 @@ lua_import_email_address(lua_State *L, struct rspamd_task *task, return TRUE; } -static gint +static int lua_task_get_recipients(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); GPtrArray *ptrs = NULL; - gint what = 0; + int what = 0; if (task) { if (lua_gettop(L) == 2) { @@ -3704,15 +3704,15 @@ lua_task_get_recipients(lua_State *L) return 1; } -static gint +static int lua_task_set_recipients(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); GPtrArray *ptrs = NULL; struct rspamd_email_address *addr = NULL; - gint what = 0, pos = 3; - const gchar *how = "add"; + int what = 0, pos = 3; + const char *how = "add"; gboolean need_update_digest = FALSE; if (task && lua_gettop(L) >= 3) { @@ -3758,7 +3758,7 @@ lua_task_set_recipients(lua_State *L) break; } if (ptrs) { - guint i, flags_existing = RSPAMD_EMAIL_ADDR_ORIGINAL, flags_add = 0; + unsigned int i, flags_existing = RSPAMD_EMAIL_ADDR_ORIGINAL, flags_add = 0; struct rspamd_email_address *tmp; if (strcmp(how, "alias") == 0) { @@ -3830,12 +3830,12 @@ lua_task_set_recipients(lua_State *L) } \ } while (0) -static gint +static int lua_task_has_from(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - gint what = 0, nrcpt = 0; + int what = 0, nrcpt = 0; gboolean ret = FALSE; if (task) { @@ -3876,7 +3876,7 @@ lua_task_has_from(lua_State *L) static inline int rspamd_check_real_recipients_array_size(GPtrArray *ar) { - gint ret = 0, i; + int ret = 0, i; struct rspamd_email_address *addr; PTR_ARRAY_FOREACH(ar, i, addr) @@ -3889,12 +3889,12 @@ rspamd_check_real_recipients_array_size(GPtrArray *ar) return ret; } -static gint +static int lua_task_has_recipients(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - gint what = 0, nrcpt = 0; + int what = 0, nrcpt = 0; gboolean ret = FALSE; if (task) { @@ -3936,14 +3936,14 @@ lua_task_has_recipients(lua_State *L) return 2; } -static gint +static int lua_task_get_from(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); GPtrArray *addrs = NULL; struct rspamd_email_address *addr = NULL; - gint what = 0; + int what = 0; if (task) { if (lua_gettop(L) == 2) { @@ -4007,16 +4007,16 @@ lua_task_get_from(lua_State *L) return 1; } -static gint +static int lua_task_set_from(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *how = "rewrite"; + const char *how = "rewrite"; GPtrArray *addrs = NULL; struct rspamd_email_address **paddr = NULL, *addr; gboolean need_update_digest = FALSE; - gint what = 0; + int what = 0; if (task && lua_gettop(L) >= 3) { what = lua_task_str_to_get_type(L, task, 2, -1); @@ -4049,7 +4049,7 @@ lua_task_set_from(lua_State *L) if (addrs) { if (lua_import_email_address(L, task, 3, &addr)) { - guint i, flags_add = RSPAMD_EMAIL_ADDR_ORIGINAL; + unsigned int i, flags_add = RSPAMD_EMAIL_ADDR_ORIGINAL; struct rspamd_email_address *tmp; if (strcmp(how, "alias") == 0) { @@ -4095,12 +4095,12 @@ lua_task_set_from(lua_State *L) return 1; } -static gint +static int lua_task_get_principal_recipient(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *r; + const char *r; if (task) { r = rspamd_task_get_principal_recipient(task); @@ -4118,7 +4118,7 @@ lua_task_get_principal_recipient(lua_State *L) return 1; } -static gint +static int lua_task_get_reply_sender(lua_State *L) { LUA_TRACE_POINT; @@ -4169,7 +4169,7 @@ lua_task_get_reply_sender(lua_State *L) return 1; } -static gint +static int lua_task_get_user(lua_State *L) { LUA_TRACE_POINT; @@ -4190,12 +4190,12 @@ lua_task_get_user(lua_State *L) return 1; } -static gint +static int lua_task_set_user(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *new_user; + const char *new_user; if (task) { @@ -4232,7 +4232,7 @@ lua_task_set_user(lua_State *L) return 1; } -static gint +static int lua_task_get_from_ip(lua_State *L) { LUA_TRACE_POINT; @@ -4253,7 +4253,7 @@ lua_task_get_from_ip(lua_State *L) return 1; } -static gint +static int lua_task_set_from_ip(lua_State *L) { LUA_TRACE_POINT; @@ -4266,7 +4266,7 @@ lua_task_set_from_ip(lua_State *L) else { if (lua_type(L, 2) == LUA_TSTRING) { gsize len; - const gchar *ip_str = lua_tolstring(L, 2, &len); + const char *ip_str = lua_tolstring(L, 2, &len); if (!rspamd_parse_inet_address(&addr, ip_str, @@ -4304,7 +4304,7 @@ lua_task_set_from_ip(lua_State *L) return 0; } -static gint +static int lua_task_get_from_ip_num(lua_State *L) { LUA_TRACE_POINT; @@ -4313,7 +4313,7 @@ lua_task_get_from_ip_num(lua_State *L) return 1; } -static gint +static int lua_task_get_client_ip(lua_State *L) { LUA_TRACE_POINT; @@ -4334,7 +4334,7 @@ lua_task_get_client_ip(lua_State *L) return 1; } -static gint +static int lua_task_get_helo(lua_State *L) { LUA_TRACE_POINT; @@ -4356,7 +4356,7 @@ lua_task_get_helo(lua_State *L) return 1; } -static gint +static int lua_task_get_subject(lua_State *L) { LUA_TRACE_POINT; @@ -4378,12 +4378,12 @@ lua_task_get_subject(lua_State *L) return 1; } -static gint +static int lua_task_set_helo(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *new_helo; + const char *new_helo; if (task) { new_helo = luaL_checkstring(L, 2); @@ -4398,7 +4398,7 @@ lua_task_set_helo(lua_State *L) return 0; } -static gint +static int lua_task_get_hostname(lua_State *L) { LUA_TRACE_POINT; @@ -4433,12 +4433,12 @@ lua_task_get_hostname(lua_State *L) return 1; } -static gint +static int lua_task_set_hostname(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *new_hostname; + const char *new_hostname; if (task) { new_hostname = luaL_checkstring(L, 2); @@ -4454,12 +4454,12 @@ lua_task_set_hostname(lua_State *L) return 0; } -static gint +static int lua_task_get_images(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - guint nelt = 0, i; + unsigned int nelt = 0, i; struct rspamd_mime_part *part; struct rspamd_image **pimg; @@ -4492,12 +4492,12 @@ lua_task_get_images(lua_State *L) return 1; } -static gint +static int lua_task_get_archives(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - guint nelt = 0, i; + unsigned int nelt = 0, i; struct rspamd_mime_part *part; struct rspamd_archive **parch; @@ -4530,12 +4530,12 @@ lua_task_get_archives(lua_State *L) return 1; } -static gint +static int lua_task_get_dkim_results(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - guint nelt = 0, i; + unsigned int nelt = 0, i; struct rspamd_dkim_check_result **pres, **cur; if (task) { @@ -4555,7 +4555,7 @@ lua_task_get_dkim_results(lua_State *L) for (i = 0; i < nelt; i++) { struct rspamd_dkim_check_result *res = pres[i]; - const gchar *result_str = "unknown"; + const char *result_str = "unknown"; lua_createtable(L, 0, 4); @@ -4617,7 +4617,7 @@ lua_task_get_dkim_results(lua_State *L) static inline gboolean lua_push_symbol_result(lua_State *L, struct rspamd_task *task, - const gchar *symbol, + const char *symbol, struct rspamd_symbol_result *symbol_result, struct rspamd_scan_result *metric_res, gboolean add_metric, @@ -4627,8 +4627,8 @@ lua_push_symbol_result(lua_State *L, struct rspamd_symbol_result *s = NULL; struct rspamd_symbol_option *opt; struct rspamd_symbols_group *sym_group; - guint i; - gint j = 1, table_fields_cnt = 4; + unsigned int i; + int j = 1, table_fields_cnt = 4; if (!metric_res) { metric_res = task->result; @@ -4701,12 +4701,12 @@ lua_push_symbol_result(lua_State *L, return FALSE; } -static gint +static int lua_task_get_symbol(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *symbol; + const char *symbol; gboolean found = FALSE; symbol = luaL_checkstring(L, 2); @@ -4746,13 +4746,13 @@ lua_task_get_symbol(lua_State *L) return 1; } -static gint +static int lua_task_has_symbol(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); struct rspamd_symbol_result *s; - const gchar *symbol; + const char *symbol; gboolean found = FALSE; symbol = luaL_checkstring(L, 2); @@ -4782,12 +4782,12 @@ lua_task_has_symbol(lua_State *L) return 1; } -static gint +static int lua_task_enable_symbol(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *symbol; + const char *symbol; gboolean found = FALSE; symbol = luaL_checkstring(L, 2); @@ -4803,12 +4803,12 @@ lua_task_enable_symbol(lua_State *L) return 1; } -static gint +static int lua_task_disable_symbol(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *symbol; + const char *symbol; gboolean found = FALSE; symbol = luaL_checkstring(L, 2); @@ -4824,13 +4824,13 @@ lua_task_disable_symbol(lua_State *L) return 1; } -static gint +static int lua_task_get_symbols(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); struct rspamd_scan_result *mres; - gint i = 1; + int i = 1; struct rspamd_symbol_result *s; if (task) { @@ -4866,7 +4866,7 @@ lua_task_get_symbols(lua_State *L) return 2; } -static gint +static int lua_task_get_symbols_all(lua_State *L) { LUA_TRACE_POINT; @@ -4874,7 +4874,7 @@ lua_task_get_symbols_all(lua_State *L) struct rspamd_scan_result *mres; struct rspamd_symbol_result *s; gboolean found = FALSE; - gint i = 1; + int i = 1; if (task) { mres = task->result; @@ -4907,13 +4907,13 @@ lua_task_get_symbols_all(lua_State *L) } -static gint +static int lua_task_get_symbols_numeric(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); struct rspamd_scan_result *mres; - gint i = 1, id; + int i = 1, id; struct rspamd_symbol_result *s; if (task) { @@ -4953,7 +4953,7 @@ lua_task_get_symbols_numeric(lua_State *L) return 2; } -static gint +static int lua_task_get_groups(lua_State *L) { LUA_TRACE_POINT; @@ -4961,7 +4961,7 @@ lua_task_get_groups(lua_State *L) gboolean need_private; struct rspamd_scan_result *mres; struct rspamd_symbols_group *gr; - gdouble gr_score; + double gr_score; if (task) { mres = task->result; @@ -5006,7 +5006,7 @@ lua_task_get_groups(lua_State *L) struct tokens_foreach_cbdata { struct rspamd_task *task; lua_State *L; - gint idx; + int idx; gboolean normalize; }; @@ -5015,8 +5015,8 @@ tokens_foreach_cb(struct rspamd_symcache_item *item, gpointer ud) { struct tokens_foreach_cbdata *cbd = ud; struct rspamd_symbol_result *s; - gint flags; - const gchar *sym; + int flags; + const char *sym; sym = rspamd_symcache_item_name(item); flags = rspamd_symcache_item_flags(item); @@ -5045,7 +5045,7 @@ tokens_foreach_cb(struct rspamd_symcache_item *item, gpointer ud) lua_rawseti(cbd->L, -2, cbd->idx++); } -static gint +static int lua_task_get_symbols_tokens(lua_State *L) { LUA_TRACE_POINT; @@ -5077,22 +5077,22 @@ lua_task_get_symbols_tokens(lua_State *L) return 1; } -static gint +static int lua_task_process_ann_tokens(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - gint offset = luaL_checkinteger(L, 4); - gdouble min_score = 0.0; + int offset = luaL_checkinteger(L, 4); + double min_score = 0.0; if (task && lua_istable(L, 2) && lua_istable(L, 3)) { - guint symlen = rspamd_lua_table_size(L, 2); + unsigned int symlen = rspamd_lua_table_size(L, 2); if (lua_isnumber(L, 5)) { min_score = lua_tonumber(L, 5); } - for (guint i = 1; i <= symlen; i++, offset++) { - const gchar *sym; + for (unsigned int i = 1; i <= symlen; i++, offset++) { + const char *sym; struct rspamd_symbol_result *sres; lua_rawgeti(L, 2, i); @@ -5116,7 +5116,7 @@ lua_task_process_ann_tokens(lua_State *L) (!sres->sym || !(rspamd_symcache_item_flags(sres->sym->cache_item) & SYMBOL_TYPE_NOSTAT))) { - gdouble norm_score; + double norm_score; if (sres->sym && !isnan(sres->sym->score)) { if (sres->sym->score == 0) { @@ -5166,18 +5166,18 @@ enum lua_date_type { static enum lua_date_type lua_task_detect_date_type(struct rspamd_task *task, - lua_State *L, gint idx, gboolean *gmt) + lua_State *L, int idx, gboolean *gmt) { enum lua_date_type type = DATE_CONNECT; if (lua_type(L, idx) == LUA_TNUMBER) { - gint num = lua_tonumber(L, idx); + int num = lua_tonumber(L, idx); if (num >= DATE_CONNECT && num < DATE_INVALID) { return num; } } else if (lua_type(L, idx) == LUA_TTABLE) { - const gchar *str; + const char *str; lua_pushvalue(L, idx); lua_pushstring(L, "format"); @@ -5210,13 +5210,13 @@ lua_task_detect_date_type(struct rspamd_task *task, return type; } -static gint +static int lua_task_get_date(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); struct rspamd_mime_header *h; - gdouble tim; + double tim; enum lua_date_type type = DATE_CONNECT; gboolean gmt = TRUE; @@ -5285,7 +5285,7 @@ lua_task_get_date(lua_State *L) return 1; } -static gint +static int lua_task_get_message_id(lua_State *L) { LUA_TRACE_POINT; @@ -5306,7 +5306,7 @@ lua_task_get_message_id(lua_State *L) return 1; } -static gint +static int lua_task_get_timeval(lua_State *L) { LUA_TRACE_POINT; @@ -5335,7 +5335,7 @@ lua_task_get_timeval(lua_State *L) return 1; } -static gint +static int lua_task_get_scan_time(lua_State *L) { LUA_TRACE_POINT; @@ -5348,7 +5348,7 @@ lua_task_get_scan_time(lua_State *L) } rspamd_task_set_finish_time(task); - gdouble diff = task->time_real_finish - task->task_timestamp; + double diff = task->time_real_finish - task->task_timestamp; lua_pushnumber(L, diff); lua_pushnumber(L, diff); @@ -5364,7 +5364,7 @@ lua_task_get_scan_time(lua_State *L) return 2; } -static gint +static int lua_task_get_size(lua_State *L) { LUA_TRACE_POINT; @@ -5427,12 +5427,12 @@ lua_task_get_size(lua_State *L) } \ } while (0) -static gint +static int lua_task_set_flag(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *flag = luaL_checkstring(L, 2); + const char *flag = luaL_checkstring(L, 2); gboolean set = TRUE, found = FALSE; if (lua_gettop(L) >= 3) { @@ -5463,12 +5463,12 @@ lua_task_set_flag(lua_State *L) return 0; } -static gint +static int lua_task_has_flag(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *flag = luaL_checkstring(L, 2); + const char *flag = luaL_checkstring(L, 2); gboolean found = FALSE; if (task != NULL && flag != NULL) { @@ -5504,13 +5504,13 @@ lua_task_has_flag(lua_State *L) return 1; } -static gint +static int lua_task_get_flags(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - gint idx = 1; - guint flags, bit, i; + int idx = 1; + unsigned int flags, bit, i; if (task) { lua_createtable(L, 8, 0); @@ -5584,13 +5584,13 @@ lua_task_get_flags(lua_State *L) return 1; } -static gint +static int lua_task_get_digest(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - gchar hexbuf[sizeof(MESSAGE_FIELD(task, digest)) * 2 + 1]; - gint r; + char hexbuf[sizeof(MESSAGE_FIELD(task, digest)) * 2 + 1]; + int r; if (task) { if (task->message) { @@ -5617,13 +5617,13 @@ lua_task_get_digest(lua_State *L) return 1; } -static gint +static int lua_task_learn(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); gboolean is_spam = FALSE; - const gchar *clname = NULL; + const char *clname = NULL; GError *err = NULL; int ret = 1; @@ -5650,7 +5650,7 @@ lua_task_learn(lua_State *L) return ret; } -static gint +static int lua_task_set_settings(lua_State *L) { LUA_TRACE_POINT; @@ -5659,7 +5659,7 @@ lua_task_set_settings(lua_State *L) const ucl_object_t *act, *metric_elt, *vars, *cur; ucl_object_iter_t it = NULL; struct rspamd_scan_result *mres; - guint i; + unsigned int i; settings = ucl_object_lua_import(L, 2); @@ -5691,7 +5691,7 @@ lua_task_set_settings(lua_State *L) it = NULL; while ((cur = ucl_object_iterate(act, &it, true)) != NULL) { - const gchar *act_name = ucl_object_key(cur); + const char *act_name = ucl_object_key(cur); struct rspamd_action_config *action_config = NULL; double act_score; enum rspamd_action_type act_type; @@ -5810,7 +5810,7 @@ lua_task_set_settings(lua_State *L) return 0; } -static gint +static int lua_task_set_milter_reply(lua_State *L) { LUA_TRACE_POINT; @@ -5856,7 +5856,7 @@ lua_task_set_milter_reply(lua_State *L) while ((cur = ucl_object_iterate(nadd_hdrs, &it, true)) != NULL) { gsize klen; - const gchar *key = ucl_object_keyl(cur, &klen); + const char *key = ucl_object_keyl(cur, &klen); const ucl_object_t *existing; existing = ucl_object_lookup_len(add_hdrs, key, klen); @@ -5893,7 +5893,7 @@ lua_task_set_milter_reply(lua_State *L) return 0; } -static gint +static int lua_task_get_settings(lua_State *L) { LUA_TRACE_POINT; @@ -5915,12 +5915,12 @@ lua_task_get_settings(lua_State *L) return 1; } -static gint +static int lua_task_lookup_settings(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *key = NULL; + const char *key = NULL; const ucl_object_t *elt; if (task != NULL) { @@ -5955,7 +5955,7 @@ lua_task_lookup_settings(lua_State *L) return 1; } -static gint +static int lua_task_get_settings_id(lua_State *L) { LUA_TRACE_POINT; @@ -5977,7 +5977,7 @@ lua_task_get_settings_id(lua_State *L) return 1; } -static gint +static int lua_task_set_settings_id(lua_State *L) { LUA_TRACE_POINT; @@ -6010,12 +6010,12 @@ lua_task_set_settings_id(lua_State *L) return 1; } -static gint +static int lua_task_cache_get(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *key = luaL_checkstring(L, 2); + const char *key = luaL_checkstring(L, 2); if (task && key) { if (!lua_task_get_cached(L, task, key)) { @@ -6029,12 +6029,12 @@ lua_task_cache_get(lua_State *L) return 1; } -static gint +static int lua_task_cache_set(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *key = luaL_checkstring(L, 2); + const char *key = luaL_checkstring(L, 2); if (task && key && lua_gettop(L) >= 3) { lua_task_set_cached(L, task, key, 3); @@ -6047,8 +6047,8 @@ lua_task_cache_set(lua_State *L) } struct lua_file_cbdata { - gchar *fname; - gint fd; + char *fname; + int fd; gboolean keep; }; @@ -6064,16 +6064,16 @@ lua_tmp_file_dtor(gpointer p) close(cbdata->fd); } -static gint +static int lua_task_store_in_file(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); gboolean force_new = FALSE, keep = FALSE; - gchar fpath[PATH_MAX]; - const gchar *tmpmask = NULL, *fname = NULL; - guint mode = 00600; - gint fd; + char fpath[PATH_MAX]; + const char *tmpmask = NULL, *fname = NULL; + unsigned int mode = 00600; + int fd; struct lua_file_cbdata *cbdata; GError *err = NULL; @@ -6120,7 +6120,7 @@ lua_task_store_in_file(lua_State *L) } else { fd = rspamd_file_xopen(fname, O_WRONLY | O_CREAT | O_EXCL, - (guint) mode, FALSE); + (unsigned int) mode, FALSE); } if (fd == -1) { @@ -6155,17 +6155,17 @@ lua_task_store_in_file(lua_State *L) return 1; } -static gint +static int lua_task_process_regexp(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); struct rspamd_lua_regexp *re = NULL; gboolean strong = FALSE; - const gchar *type_str = NULL, *header_str = NULL; + const char *type_str = NULL, *header_str = NULL; gsize header_len = 0; GError *err = NULL; - gint ret = 0; + int ret = 0; enum rspamd_re_type type = RSPAMD_RE_BODY; /* @@ -6216,7 +6216,7 @@ lua_task_process_regexp(lua_State *L) return 1; } -static gint +static int lua_task_get_metric_result(lua_State *L) { LUA_TRACE_POINT; @@ -6287,12 +6287,12 @@ lua_task_get_metric_result(lua_State *L) return 1; } -static gint +static int lua_task_get_metric_score(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - gdouble rs; + double rs; struct rspamd_scan_result *metric_res; if (task) { @@ -6321,7 +6321,7 @@ lua_task_get_metric_score(lua_State *L) return 1; } -static gint +static int lua_task_get_metric_action(lua_State *L) { LUA_TRACE_POINT; @@ -6351,13 +6351,13 @@ lua_task_get_metric_action(lua_State *L) return 1; } -static gint +static int lua_task_set_metric_score(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); struct rspamd_scan_result *metric_res; - gdouble nscore; + double nscore; if (lua_isnumber(L, 2)) { nscore = luaL_checknumber(L, 2); @@ -6390,19 +6390,19 @@ lua_task_set_metric_score(lua_State *L) return 1; } -static gint +static int lua_task_disable_action(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *action_name; + const char *action_name; struct rspamd_action_config *action_res; action_name = luaL_checkstring(L, 2); if (task && action_name) { - for (guint i = 0; i < task->result->nactions; i++) { + for (unsigned int i = 0; i < task->result->nactions; i++) { action_res = &task->result->actions_config[i]; if (strcmp(action_name, action_res->action->name) == 0) { @@ -6425,7 +6425,7 @@ lua_task_disable_action(lua_State *L) return 1; } -static gint +static int lua_task_get_newlines_type(lua_State *L) { LUA_TRACE_POINT; @@ -6460,7 +6460,7 @@ lua_task_get_newlines_type(lua_State *L) static void lua_push_stat_token(lua_State *L, rspamd_token_t *tok) { - gchar numbuf[64]; + char numbuf[64]; /* Table values * - `data`: 64 bit number encoded as a string @@ -6532,12 +6532,12 @@ lua_push_stat_token(lua_State *L, rspamd_token_t *tok) lua_settable(L, -3); } -static gint +static int lua_task_get_stat_tokens(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - guint i; + unsigned int i; rspamd_token_t *tok; if (task) { @@ -6565,12 +6565,12 @@ lua_task_get_stat_tokens(lua_State *L) return 1; } -static gint +static int lua_task_set_metric_subject(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *subject; + const char *subject; subject = luaL_checkstring(L, 2); @@ -6586,12 +6586,12 @@ lua_task_set_metric_subject(lua_State *L) return 1; } -static gint +static int lua_task_get_protocol_reply(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - guint flags = 0; + unsigned int flags = 0; ucl_object_t *obj; if (!task) { @@ -6605,7 +6605,7 @@ lua_task_get_protocol_reply(lua_State *L) if (lua_istable(L, 2)) { for (lua_pushnil(L); lua_next(L, 2); lua_pop(L, 1)) { if (lua_isstring(L, -1)) { - const gchar *str = lua_tostring(L, -1); + const char *str = lua_tostring(L, -1); if (strcmp(str, "default") == 0) { flags |= RSPAMD_PROTOCOL_DEFAULT; @@ -6650,7 +6650,7 @@ lua_task_get_protocol_reply(lua_State *L) return 1; } -static gint +static int lua_task_headers_foreach(lua_State *L) { LUA_TRACE_POINT; @@ -6658,7 +6658,7 @@ lua_task_headers_foreach(lua_State *L) enum rspamd_lua_task_header_type how = RSPAMD_TASK_HEADER_PUSH_SIMPLE; struct rspamd_lua_regexp *re = NULL; struct rspamd_mime_header *hdr, *cur; - gint old_top; + int old_top; if (task && lua_isfunction(L, 2)) { if (task->message) { @@ -6738,12 +6738,12 @@ lua_task_headers_foreach(lua_State *L) return 0; } -static gint +static int lua_task_modify_header(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *hname = luaL_checkstring(L, 2); + const char *hname = luaL_checkstring(L, 2); if (hname && task && lua_type(L, 3) == LUA_TTABLE) { if (task->message) { @@ -6769,7 +6769,7 @@ lua_task_modify_header(lua_State *L) return 1; } -static gint +static int lua_task_get_meta_words(lua_State *L) { LUA_TRACE_POINT; @@ -6785,7 +6785,7 @@ lua_task_get_meta_words(lua_State *L) } else { if (lua_type(L, 2) == LUA_TSTRING) { - const gchar *how_str = lua_tostring(L, 2); + const char *how_str = lua_tostring(L, 2); if (strcmp(how_str, "stem") == 0) { how = RSPAMD_LUA_WORDS_STEM; @@ -6810,18 +6810,18 @@ lua_task_get_meta_words(lua_State *L) return 1; } -static guint +static unsigned int lua_lookup_words_array(lua_State *L, - gint cbpos, + int cbpos, struct rspamd_task *task, struct rspamd_lua_map *map, GArray *words) { rspamd_stat_token_t *tok; - guint i, nmatched = 0; - gint err_idx; + unsigned int i, nmatched = 0; + int err_idx; gboolean matched; - const gchar *key; + const char *key; gsize keylen; for (i = 0; i < words->len; i++) { @@ -6876,7 +6876,7 @@ lua_lookup_words_array(lua_State *L, return nmatched; } -static gint +static int lua_task_lookup_words(lua_State *L) { LUA_TRACE_POINT; @@ -6884,7 +6884,7 @@ lua_task_lookup_words(lua_State *L) struct rspamd_lua_map *map = lua_check_map(L, 2); struct rspamd_mime_text_part *tp; - guint i, matches = 0; + unsigned int i, matches = 0; if (task == NULL || map == NULL || task->message == NULL || lua_type(L, 3) != LUA_TFUNCTION) { return luaL_error(L, "invalid arguments"); @@ -6913,7 +6913,7 @@ lua_task_lookup_words(lua_State *L) return 1; } -static gint +static int lua_task_topointer(lua_State *L) { LUA_TRACE_POINT; @@ -6930,13 +6930,13 @@ lua_task_topointer(lua_State *L) return 1; } -static gint +static int lua_task_add_named_result(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - const gchar *name = luaL_checkstring(L, 2); - gint cbref; + const char *name = luaL_checkstring(L, 2); + int cbref; if (task && name && lua_isfunction(L, 3)) { lua_pushvalue(L, 3); @@ -6950,14 +6950,14 @@ lua_task_add_named_result(lua_State *L) return 0; } -static gint +static int lua_task_get_all_named_results(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); if (task) { - gint n = 0; + int n = 0; struct rspamd_scan_result *res; DL_COUNT(task->result, res, n); @@ -6985,7 +6985,7 @@ lua_task_get_all_named_results(lua_State *L) /* Image functions */ -static gint +static int lua_image_get_width(lua_State *L) { LUA_TRACE_POINT; @@ -7001,7 +7001,7 @@ lua_image_get_width(lua_State *L) return 1; } -static gint +static int lua_image_get_height(lua_State *L) { LUA_TRACE_POINT; @@ -7017,7 +7017,7 @@ lua_image_get_height(lua_State *L) return 1; } -static gint +static int lua_image_get_type(lua_State *L) { LUA_TRACE_POINT; @@ -7033,7 +7033,7 @@ lua_image_get_type(lua_State *L) return 1; } -static gint +static int lua_image_get_size(lua_State *L) { LUA_TRACE_POINT; @@ -7049,7 +7049,7 @@ lua_image_get_size(lua_State *L) return 1; } -static gint +static int lua_image_get_filename(lua_State *L) { LUA_TRACE_POINT; @@ -7071,7 +7071,7 @@ lua_image_get_filename(lua_State *L) } /* Archive methods */ -static gint +static int lua_archive_get_type(lua_State *L) { LUA_TRACE_POINT; @@ -7087,12 +7087,12 @@ lua_archive_get_type(lua_State *L) return 1; } -static gint +static int lua_archive_get_files(lua_State *L) { LUA_TRACE_POINT; struct rspamd_archive *arch = lua_check_archive(L); - guint i, max_files = 0; + unsigned int i, max_files = 0; struct rspamd_archive_file *f; if (arch != NULL) { @@ -7120,12 +7120,12 @@ lua_archive_get_files(lua_State *L) return 1; } -static gint +static int lua_archive_get_files_full(lua_State *L) { LUA_TRACE_POINT; struct rspamd_archive *arch = lua_check_archive(L); - guint i, max_files = 0; + unsigned int i, max_files = 0; struct rspamd_archive_file *f; if (arch != NULL) { @@ -7170,7 +7170,7 @@ lua_archive_get_files_full(lua_State *L) return 1; } -static gint +static int lua_archive_is_encrypted(lua_State *L) { LUA_TRACE_POINT; @@ -7186,7 +7186,7 @@ lua_archive_is_encrypted(lua_State *L) return 1; } -static gint +static int lua_archive_is_obfuscated(lua_State *L) { LUA_TRACE_POINT; @@ -7203,7 +7203,7 @@ lua_archive_is_obfuscated(lua_State *L) return 1; } -static gint +static int lua_archive_is_unreadable(lua_State *L) { LUA_TRACE_POINT; @@ -7219,7 +7219,7 @@ lua_archive_is_unreadable(lua_State *L) return 1; } -static gint +static int lua_archive_get_size(lua_State *L) { LUA_TRACE_POINT; @@ -7235,7 +7235,7 @@ lua_archive_get_size(lua_State *L) return 1; } -static gint +static int lua_archive_get_filename(lua_State *L) { LUA_TRACE_POINT; @@ -7253,7 +7253,7 @@ lua_archive_get_filename(lua_State *L) /* Init part */ -static gint +static int lua_load_task(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index e0595c5c4..f498f9598 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -20,7 +20,7 @@ #include "unix-std.h" #include -static const gchar *M = "rspamd lua tcp"; +static const char *M = "rspamd lua tcp"; /*** * @module rspamd_tcp @@ -262,15 +262,15 @@ static const struct luaL_reg tcp_sync_libm[] = { {NULL, NULL}}; struct lua_tcp_read_handler { - gchar *stop_pattern; - guint plen; - gint cbref; + char *stop_pattern; + unsigned int plen; + int cbref; }; struct lua_tcp_write_handler { struct iovec *iov; - guint iovlen; - gint cbref; + unsigned int iovlen; + int cbref; gsize pos; gsize total_bytes; }; @@ -329,11 +329,11 @@ struct lua_tcp_cbdata { rspamd_inet_addr_t *addr; GByteArray *in; GQueue *handlers; - gint fd; - gint connect_cb; - guint port; - guint flags; - gchar tag[7]; + int fd; + int connect_cb; + unsigned int port; + unsigned int flags; + char tag[7]; struct rspamd_io_ev ev; struct lua_tcp_dtor *dtors; ref_entry_t ref; @@ -342,7 +342,7 @@ struct lua_tcp_cbdata { struct thread_entry *thread; struct rspamd_config *cfg; struct rspamd_ssl_connection *ssl_conn; - gchar *hostname; + char *hostname; struct upstream *up; gboolean eof; }; @@ -366,7 +366,7 @@ lua_tcp_void_finalyser(gpointer arg) { } -static const gdouble default_tcp_timeout = 5.0; +static const double default_tcp_timeout = 5.0; static struct rspamd_dns_resolver * lua_tcp_global_resolver(struct ev_loop *ev_base, @@ -482,7 +482,7 @@ lua_tcp_fin(gpointer arg) } static struct lua_tcp_cbdata * -lua_check_tcp(lua_State *L, gint pos) +lua_check_tcp(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_tcp_classname); luaL_argcheck(L, ud != NULL, pos, "'tcp' expected"); @@ -530,7 +530,7 @@ lua_tcp_push_error(struct lua_tcp_cbdata *cbd, gboolean is_fatal, const char *err, ...) __attribute__((format(printf, 3, 4))); #endif -static void lua_tcp_resume_thread_error_argp(struct lua_tcp_cbdata *cbd, const gchar *error, va_list argp); +static void lua_tcp_resume_thread_error_argp(struct lua_tcp_cbdata *cbd, const char *error, va_list argp); static void lua_tcp_push_error(struct lua_tcp_cbdata *cbd, gboolean is_fatal, @@ -539,7 +539,7 @@ lua_tcp_push_error(struct lua_tcp_cbdata *cbd, gboolean is_fatal, va_list ap, ap_copy; struct lua_tcp_cbdata **pcbd; struct lua_tcp_handler *hdl; - gint cbref, top; + int cbref, top; struct lua_callback_state cbs; lua_State *L; gboolean callback_called = FALSE; @@ -636,15 +636,15 @@ lua_tcp_push_error(struct lua_tcp_cbdata *cbd, gboolean is_fatal, lua_thread_pool_restore_callback(&cbs); } -static void lua_tcp_resume_thread(struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len); +static void lua_tcp_resume_thread(struct lua_tcp_cbdata *cbd, const uint8_t *str, gsize len); static void -lua_tcp_push_data(struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) +lua_tcp_push_data(struct lua_tcp_cbdata *cbd, const uint8_t *str, gsize len) { struct rspamd_lua_text *t; struct lua_tcp_cbdata **pcbd; struct lua_tcp_handler *hdl; - gint cbref, arg_cnt, top; + int cbref, arg_cnt, top; struct lua_callback_state cbs; lua_State *L; @@ -677,7 +677,7 @@ lua_tcp_push_data(struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) if (hdl->type == LUA_WANT_READ) { t = lua_newuserdata(L, sizeof(*t)); rspamd_lua_setclass(L, rspamd_text_classname, -1); - t->start = (const gchar *) str; + t->start = (const char *) str; t->len = len; t->flags = 0; arg_cnt = 3; @@ -714,7 +714,7 @@ lua_tcp_push_data(struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) } static void -lua_tcp_resume_thread_error_argp(struct lua_tcp_cbdata *cbd, const gchar *error, va_list argp) +lua_tcp_resume_thread_error_argp(struct lua_tcp_cbdata *cbd, const char *error, va_list argp) { struct thread_entry *thread = cbd->thread; lua_State *L = thread->lua_state; @@ -730,7 +730,7 @@ lua_tcp_resume_thread_error_argp(struct lua_tcp_cbdata *cbd, const gchar *error, } static void -lua_tcp_resume_thread(struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) +lua_tcp_resume_thread(struct lua_tcp_cbdata *cbd, const uint8_t *str, gsize len) { /* * typical call returns: @@ -806,8 +806,8 @@ static void lua_tcp_write_helper(struct lua_tcp_cbdata *cbd) { struct iovec *start; - guint niov, i; - gint flags = 0; + unsigned int niov, i; + int flags = 0; bool allocated_iov = false; gsize remain; gssize r; @@ -887,7 +887,7 @@ lua_tcp_write_helper(struct lua_tcp_cbdata *cbd) else { lua_tcp_push_error(cbd, TRUE, "IO write error while trying to write %d bytes: %s", - (gint) remain, strerror(errno)); + (int) remain, strerror(errno)); msg_debug_tcp("write error, terminate connection"); TCP_RELEASE(cbd); @@ -945,7 +945,7 @@ static gboolean lua_tcp_process_read_handler(struct lua_tcp_cbdata *cbd, struct lua_tcp_read_handler *rh, gboolean eof) { - guint slen; + unsigned int slen; goffset pos; if (rh->stop_pattern) { @@ -1006,7 +1006,7 @@ lua_tcp_process_read_handler(struct lua_tcp_cbdata *cbd, static void lua_tcp_process_read(struct lua_tcp_cbdata *cbd, - guchar *in, gssize r) + unsigned char *in, gssize r) { struct lua_tcp_handler *hdl; struct lua_tcp_read_handler *rh; @@ -1089,9 +1089,9 @@ static void lua_tcp_handler(int fd, short what, gpointer ud) { struct lua_tcp_cbdata *cbd = ud; - guchar inbuf[8192]; + unsigned char inbuf[8192]; gssize r; - gint so_error = 0; + int so_error = 0; socklen_t so_len = sizeof(so_error); struct lua_callback_state cbs; lua_State *L; @@ -1135,7 +1135,7 @@ lua_tcp_handler(int fd, short what, gpointer ud) if (cbd->connect_cb != -1) { struct lua_tcp_cbdata **pcbd; - gint top; + int top; lua_thread_pool_prepare_callback(cbd->cfg->lua_thread_pool, &cbs); L = cbs.L; @@ -1450,12 +1450,12 @@ lua_tcp_dns_handler(struct rdns_reply *reply, gpointer ud) } static gboolean -lua_tcp_arg_toiovec(lua_State *L, gint pos, struct lua_tcp_cbdata *cbd, +lua_tcp_arg_toiovec(lua_State *L, int pos, struct lua_tcp_cbdata *cbd, struct iovec *vec) { struct rspamd_lua_text *t; gsize len; - const gchar *str; + const char *str; struct lua_tcp_dtor *dtor; if (lua_type(L, pos) == LUA_TUSERDATA) { @@ -1521,14 +1521,14 @@ lua_tcp_arg_toiovec(lua_State *L, gint pos, struct lua_tcp_cbdata *cbd, * - `upstream`: optional upstream object that would be used to get an address * @return {boolean} true if request has been sent */ -static gint +static int lua_tcp_request(lua_State *L) { LUA_TRACE_POINT; - const gchar *host; - gchar *stop_pattern = NULL; - guint port; - gint cbref, tp, conn_cbref = -1; + const char *host; + char *stop_pattern = NULL; + unsigned int port; + int cbref, tp, conn_cbref = -1; gsize plen = 0; struct ev_loop *event_loop = NULL; struct lua_tcp_cbdata *cbd; @@ -1538,9 +1538,9 @@ lua_tcp_request(lua_State *L) struct rspamd_config *cfg = NULL; struct iovec *iov = NULL; struct upstream *up = NULL; - guint niov = 0, total_out; + unsigned int niov = 0, total_out; uint64_t h; - gdouble timeout = default_tcp_timeout; + double timeout = default_tcp_timeout; gboolean partial = FALSE, do_shutdown = FALSE, do_read = TRUE, ssl = FALSE, ssl_noverify = FALSE; @@ -1639,7 +1639,7 @@ lua_tcp_request(lua_State *L) lua_pushstring(L, "stop_pattern"); lua_gettable(L, -2); if (lua_type(L, -1) == LUA_TSTRING) { - const gchar *p; + const char *p; p = lua_tolstring(L, -1, &plen); @@ -1967,16 +1967,16 @@ lua_tcp_request(lua_State *L) * - `timeout`: floating point value that specifies timeout for IO operations in **seconds** * @return {boolean} true if request has been sent */ -static gint +static int lua_tcp_connect_sync(lua_State *L) { LUA_TRACE_POINT; GError *err = NULL; int64_t port = -1; - gdouble timeout = default_tcp_timeout; - const gchar *host = NULL; - gint ret; + double timeout = default_tcp_timeout; + const char *host = NULL; + int ret; uint64_t h; struct rspamd_task *task = NULL; @@ -2021,7 +2021,7 @@ lua_tcp_connect_sync(lua_State *L) cbd = g_new0(struct lua_tcp_cbdata, 1); if (task) { - static const gchar hexdigests[16] = "0123456789abcdef"; + static const char hexdigests[16] = "0123456789abcdef"; cfg = task->cfg; ev_base = task->event_loop; @@ -2055,7 +2055,7 @@ lua_tcp_connect_sync(lua_State *L) cbd->event_loop = ev_base; cbd->flags |= LUA_TCP_FLAG_SYNC; cbd->fd = -1; - cbd->port = (guint16) port; + cbd->port = (uint16_t) port; cbd->in = g_byte_array_new(); @@ -2088,7 +2088,7 @@ lua_tcp_connect_sync(lua_State *L) if (rspamd_parse_inet_address(&cbd->addr, host, strlen(host), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) { - rspamd_inet_address_set_port(cbd->addr, (guint16) port); + rspamd_inet_address_set_port(cbd->addr, (uint16_t) port); /* Host is numeric IP, no need to resolve */ if (!lua_tcp_make_connection(cbd)) { lua_pushboolean(L, FALSE); @@ -2135,7 +2135,7 @@ lua_tcp_connect_sync(lua_State *L) return lua_thread_yield(cbd->thread, 0); } -static gint +static int lua_tcp_close(lua_State *L) { LUA_TRACE_POINT; @@ -2174,16 +2174,16 @@ lua_tcp_close(lua_State *L) return 0; } -static gint +static int lua_tcp_add_read(lua_State *L) { LUA_TRACE_POINT; struct lua_tcp_cbdata *cbd = lua_check_tcp(L, 1); struct lua_tcp_handler *rh; - gchar *stop_pattern = NULL; - const gchar *p; + char *stop_pattern = NULL; + const char *p; gsize plen = 0; - gint cbref = -1; + int cbref = -1; if (cbd == NULL) { return luaL_error(L, "invalid arguments"); @@ -2215,15 +2215,15 @@ lua_tcp_add_read(lua_State *L) return 0; } -static gint +static int lua_tcp_add_write(lua_State *L) { LUA_TRACE_POINT; struct lua_tcp_cbdata *cbd = lua_check_tcp(L, 1); struct lua_tcp_handler *wh; - gint cbref = -1, tp; + int cbref = -1, tp; struct iovec *iov = NULL; - guint niov = 0, total_out = 0; + unsigned int niov = 0, total_out = 0; if (cbd == NULL) { return luaL_error(L, "invalid arguments"); @@ -2299,7 +2299,7 @@ lua_tcp_add_write(lua_State *L) return 1; } -static gint +static int lua_tcp_shift_callback(lua_State *L) { LUA_TRACE_POINT; @@ -2316,7 +2316,7 @@ lua_tcp_shift_callback(lua_State *L) } static struct lua_tcp_cbdata * -lua_check_sync_tcp(lua_State *L, gint pos) +lua_check_sync_tcp(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_tcp_sync_classname); luaL_argcheck(L, ud != NULL, pos, "'tcp' expected"); @@ -2396,9 +2396,9 @@ lua_tcp_sync_write(lua_State *L) LUA_TRACE_POINT; struct lua_tcp_cbdata *cbd = lua_check_sync_tcp(L, 1); struct lua_tcp_handler *wh; - gint tp; + int tp; struct iovec *iov = NULL; - guint niov = 0; + unsigned int niov = 0; gsize total_out = 0; if (cbd == NULL) { @@ -2471,7 +2471,7 @@ lua_tcp_sync_write(lua_State *L) return lua_thread_yield(thread, 0); } -static gint +static int lua_tcp_sync_eof(lua_State *L) { LUA_TRACE_POINT; @@ -2485,7 +2485,7 @@ lua_tcp_sync_eof(lua_State *L) return 1; } -static gint +static int lua_tcp_sync_shutdown(lua_State *L) { LUA_TRACE_POINT; @@ -2499,7 +2499,7 @@ lua_tcp_sync_shutdown(lua_State *L) return 0; } -static gint +static int lua_tcp_starttls(lua_State *L) { LUA_TRACE_POINT; @@ -2534,7 +2534,7 @@ lua_tcp_starttls(lua_State *L) return 0; } -static gint +static int lua_tcp_sync_gc(lua_State *L) { struct lua_tcp_cbdata *cbd = lua_check_sync_tcp(L, 1); @@ -2548,7 +2548,7 @@ lua_tcp_sync_gc(lua_State *L) return 0; } -static gint +static int lua_load_tcp(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_tensor.c b/src/lua/lua_tensor.c index d4ee3dcca..fef1576e3 100644 --- a/src/lua/lua_tensor.c +++ b/src/lua/lua_tensor.c @@ -78,7 +78,7 @@ lua_newtensor(lua_State *L, int ndims, const int *dim, bool zero_fill, bool own) res->ndims = ndims; res->size = 1; - for (guint i = 0; i < ndims; i++) { + for (unsigned int i = 0; i < ndims; i++) { res->size *= dim[i]; res->dim[i] = dim[i]; } @@ -106,15 +106,15 @@ lua_newtensor(lua_State *L, int ndims, const int *dim, bool zero_fill, bool own) * Creates a new zero filled tensor with the specific number of dimensions * @return */ -static gint +static int lua_tensor_new(lua_State *L) { - gint ndims = luaL_checkinteger(L, 1); + int ndims = luaL_checkinteger(L, 1); if (ndims > 0 && ndims <= 2) { - gint *dims = g_alloca(sizeof(gint) * ndims); + int *dims = g_alloca(sizeof(int) * ndims); - for (guint i = 0; i < ndims; i++) { + for (unsigned int i = 0; i < ndims; i++) { dims[i] = lua_tointeger(L, i + 2); } @@ -132,7 +132,7 @@ lua_tensor_new(lua_State *L) * Creates a new zero filled tensor with the specific number of dimensions * @return */ -static gint +static int lua_tensor_fromtable(lua_State *L) { if (lua_istable(L, 1)) { @@ -141,14 +141,14 @@ lua_tensor_fromtable(lua_State *L) if (lua_isnumber(L, -1)) { lua_pop(L, 1); /* Input vector */ - gint dims[2]; + int dims[2]; dims[0] = 1; dims[1] = rspamd_lua_table_size(L, 1); struct rspamd_lua_tensor *res = lua_newtensor(L, 2, dims, false, true); - for (guint i = 0; i < dims[1]; i++) { + for (unsigned int i = 0; i < dims[1]; i++) { lua_rawgeti(L, 1, i + 1); res->data[i] = lua_tonumber(L, -1); lua_pop(L, 1); @@ -159,10 +159,10 @@ lua_tensor_fromtable(lua_State *L) lua_pop(L, 1); /* Calculate the overall size */ - gint nrows = rspamd_lua_table_size(L, 1), ncols = 0; - gint err; + int nrows = rspamd_lua_table_size(L, 1), ncols = 0; + int err; - for (gint i = 0; i < nrows; i++) { + for (int i = 0; i < nrows; i++) { lua_rawgeti(L, 1, i + 1); if (ncols == 0) { @@ -180,7 +180,7 @@ lua_tensor_fromtable(lua_State *L) } else { if (ncols != rspamd_lua_table_size(L, -1)) { - gint t = rspamd_lua_table_size(L, -1); + int t = rspamd_lua_table_size(L, -1); lua_pop(L, 1); err = luaL_error(L, "invalid params at pos %d: " @@ -196,17 +196,17 @@ lua_tensor_fromtable(lua_State *L) lua_pop(L, 1); } - gint dims[2]; + int dims[2]; dims[0] = nrows; dims[1] = ncols; struct rspamd_lua_tensor *res = lua_newtensor(L, 2, dims, false, true); - for (gint i = 0; i < nrows; i++) { + for (int i = 0; i < nrows; i++) { lua_rawgeti(L, 1, i + 1); - for (gint j = 0; j < ncols; j++) { + for (int j = 0; j < ncols; j++) { lua_rawgeti(L, -1, j + 1); res->data[i * ncols + j] = lua_tonumber(L, -1); @@ -235,7 +235,7 @@ lua_tensor_fromtable(lua_State *L) * Tensor destructor * @return */ -static gint +static int lua_tensor_destroy(lua_State *L) { struct rspamd_lua_tensor *t = lua_check_tensor(L, 1); @@ -254,11 +254,11 @@ lua_tensor_destroy(lua_State *L) * Tensor serialisation function * @return */ -static gint +static int lua_tensor_save(lua_State *L) { struct rspamd_lua_tensor *t = lua_check_tensor(L, 1); - gint size; + int size; if (t) { if (t->size > 0) { @@ -268,8 +268,8 @@ lua_tensor_save(lua_State *L) size = -(t->size); } - gsize sz = sizeof(gint) * 4 + size * sizeof(rspamd_tensor_num_t); - guchar *data; + gsize sz = sizeof(int) * 4 + size * sizeof(rspamd_tensor_num_t); + unsigned char *data; struct rspamd_lua_text *out = lua_new_text(L, NULL, 0, TRUE); @@ -280,7 +280,7 @@ lua_tensor_save(lua_State *L) memcpy(data + 4 * sizeof(int), t->data, size * sizeof(rspamd_tensor_num_t)); - out->start = (const gchar *) data; + out->start = (const char *) data; out->len = sz; } else { @@ -290,7 +290,7 @@ lua_tensor_save(lua_State *L) return 1; } -static gint +static int lua_tensor_tostring(lua_State *L) { struct rspamd_lua_tensor *t = lua_check_tensor(L, 1); @@ -300,15 +300,15 @@ lua_tensor_tostring(lua_State *L) if (t->ndims == 1) { /* Print as a vector */ - for (gint i = 0; i < t->dim[0]; i++) { + for (int i = 0; i < t->dim[0]; i++) { rspamd_printf_gstring(out, "%.4f ", t->data[i]); } /* Trim last space */ out->len--; } else { - for (gint i = 0; i < t->dim[0]; i++) { - for (gint j = 0; j < t->dim[1]; j++) { + for (int i = 0; i < t->dim[0]; i++) { + for (int j = 0; j < t->dim[1]; j++) { rspamd_printf_gstring(out, "%.4f ", t->data[i * t->dim[1] + j]); } @@ -331,11 +331,11 @@ lua_tensor_tostring(lua_State *L) return 1; } -static gint +static int lua_tensor_index(lua_State *L) { struct rspamd_lua_tensor *t = lua_check_tensor(L, 1); - gint idx; + int idx; if (t) { if (lua_isnumber(L, 2)) { @@ -352,7 +352,7 @@ lua_tensor_index(lua_State *L) } else { /* Push row */ - gint dim = t->dim[1]; + int dim = t->dim[1]; if (idx <= t->dim[0]) { @@ -376,11 +376,11 @@ lua_tensor_index(lua_State *L) return 1; } -static gint +static int lua_tensor_newindex(lua_State *L) { struct rspamd_lua_tensor *t = lua_check_tensor(L, 1); - gint idx; + int idx; if (t) { if (lua_isnumber(L, 2)) { @@ -451,7 +451,7 @@ lua_tensor_newindex(lua_State *L) * Multiply two tensors (optionally transposed) and return a new tensor * @return */ -static gint +static int lua_tensor_mul(lua_State *L) { struct rspamd_lua_tensor *t1 = lua_check_tensor(L, 1), @@ -467,7 +467,7 @@ lua_tensor_mul(lua_State *L) } if (t1 && t2) { - gint dims[2], shadow_dims[2]; + int dims[2], shadow_dims[2]; dims[0] = abs(transA ? t1->dim[1] : t1->dim[0]); shadow_dims[0] = abs(transB ? t2->dim[1] : t2->dim[0]); dims[1] = abs(transB ? t2->dim[0] : t2->dim[1]); @@ -517,10 +517,10 @@ lua_tensor_mul(lua_State *L) * Deserialize tensor * @return */ -static gint +static int lua_tensor_load(lua_State *L) { - const guchar *data; + const unsigned char *data; gsize sz; if (lua_type(L, 1) == LUA_TUSERDATA) { @@ -530,14 +530,14 @@ lua_tensor_load(lua_State *L) return luaL_error(L, "invalid argument"); } - data = (const guchar *) t->start; + data = (const unsigned char *) t->start; sz = t->len; } else { - data = (const guchar *) lua_tolstring(L, 1, &sz); + data = (const unsigned char *) lua_tolstring(L, 1, &sz); } - if (sz >= sizeof(gint) * 4) { + if (sz >= sizeof(int) * 4) { int ndims, nelts, dims[2]; memcpy(&ndims, data, sizeof(int)); @@ -582,11 +582,11 @@ lua_tensor_load(lua_State *L) return 1; } -static gint +static int lua_tensor_len(lua_State *L) { struct rspamd_lua_tensor *t = lua_check_tensor(L, 1); - gint nret = 1; + int nret = 1; if (t) { /* Return the main dimension first */ @@ -606,7 +606,7 @@ lua_tensor_len(lua_State *L) return nret; } -static gint +static int lua_tensor_eigen(lua_State *L) { struct rspamd_lua_tensor *t = lua_check_tensor(L, 1), *eigen; @@ -638,7 +638,7 @@ mean_vec(rspamd_tensor_num_t *x, gsize n) return sum / (rspamd_tensor_num_t) n; } -static gint +static int lua_tensor_mean(lua_State *L) { struct rspamd_lua_tensor *t = lua_check_tensor(L, 1); @@ -666,7 +666,7 @@ lua_tensor_mean(lua_State *L) return 1; } -static gint +static int lua_tensor_transpose(lua_State *L) { struct rspamd_lua_tensor *t = lua_check_tensor(L, 1), *res; @@ -707,7 +707,7 @@ lua_tensor_transpose(lua_State *L) return 1; } -static gint +static int lua_tensor_has_blas(lua_State *L) { #ifdef HAVE_CBLAS @@ -719,7 +719,7 @@ lua_tensor_has_blas(lua_State *L) return 1; } -static gint +static int lua_tensor_scatter_matrix(lua_State *L) { struct rspamd_lua_tensor *t = lua_check_tensor(L, 1), *res; @@ -789,7 +789,7 @@ lua_tensor_scatter_matrix(lua_State *L) return 1; } -static gint +static int lua_load_tensor(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c index 92dfadce6..4478314f1 100644 --- a/src/lua/lua_text.c +++ b/src/lua/lua_text.c @@ -268,7 +268,7 @@ static const struct luaL_reg textlib_m[] = { {NULL, NULL}}; struct rspamd_lua_text * -lua_check_text(lua_State *L, gint pos) +lua_check_text(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_text_classname); luaL_argcheck(L, ud != NULL, pos, "'text' expected"); @@ -276,9 +276,9 @@ lua_check_text(lua_State *L, gint pos) } struct rspamd_lua_text * -lua_check_text_or_string(lua_State *L, gint pos) +lua_check_text_or_string(lua_State *L, int pos) { - gint pos_type = lua_type(L, pos); + int pos_type = lua_type(L, pos); if (pos_type == LUA_TUSERDATA) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_text_classname); @@ -312,7 +312,7 @@ lua_check_text_or_string(lua_State *L, gint pos) } struct rspamd_lua_text * -lua_new_text(lua_State *L, const gchar *start, gsize len, gboolean own) +lua_new_text(lua_State *L, const char *start, gsize len, gboolean own) { struct rspamd_lua_text *t; @@ -320,7 +320,7 @@ lua_new_text(lua_State *L, const gchar *start, gsize len, gboolean own) t->flags = 0; if (own) { - gchar *storage; + char *storage; if (len > 0) { storage = g_malloc(len); @@ -348,7 +348,7 @@ lua_new_text(lua_State *L, const gchar *start, gsize len, gboolean own) struct rspamd_lua_text * lua_new_text_task(lua_State *L, struct rspamd_task *task, - const gchar *start, gsize len, gboolean own) + const char *start, gsize len, gboolean own) { struct rspamd_lua_text *t; @@ -356,7 +356,7 @@ lua_new_text_task(lua_State *L, struct rspamd_task *task, t->flags = 0; if (own) { - gchar *storage; + char *storage; if (len > 0) { storage = rspamd_mempool_alloc(task->task_pool, len); @@ -398,11 +398,11 @@ bool lua_is_text_binary(struct rspamd_lua_text *t) } -static gint +static int lua_text_fromstring(lua_State *L) { LUA_TRACE_POINT; - const gchar *str; + const char *str; gsize l = 0; gboolean transparent = FALSE; @@ -423,7 +423,7 @@ lua_text_fromstring(lua_State *L) return 1; } -static gint +static int lua_text_null(lua_State *L) { LUA_TRACE_POINT; @@ -433,11 +433,11 @@ lua_text_null(lua_State *L) return 1; } -static gint +static int lua_text_randombytes(lua_State *L) { LUA_TRACE_POINT; - guint nbytes = luaL_checkinteger(L, 1); + unsigned int nbytes = luaL_checkinteger(L, 1); struct rspamd_lua_text *out; out = lua_new_text(L, NULL, nbytes, TRUE); @@ -450,7 +450,7 @@ lua_text_randombytes(lua_State *L) #define MAX_REC 10 static void -lua_text_tbl_length(lua_State *L, gsize dlen, gsize *dest, guint rec) +lua_text_tbl_length(lua_State *L, gsize dlen, gsize *dest, unsigned int rec) { gsize tblen, stlen; struct rspamd_lua_text *elt; @@ -495,12 +495,12 @@ lua_text_tbl_length(lua_State *L, gsize dlen, gsize *dest, guint rec) static void lua_text_tbl_append(lua_State *L, - const gchar *delim, + const char *delim, gsize dlen, - gchar **dest, - guint rec) + char **dest, + unsigned int rec) { - const gchar *st; + const char *st; gsize tblen, stlen; struct rspamd_lua_text *elt; @@ -512,7 +512,7 @@ lua_text_tbl_append(lua_State *L, tblen = rspamd_lua_table_size(L, -1); - for (guint i = 0; i < tblen; i++) { + for (unsigned int i = 0; i < tblen; i++) { lua_rawgeti(L, -1, i + 1); if (lua_type(L, -1) == LUA_TSTRING) { @@ -541,14 +541,14 @@ lua_text_tbl_append(lua_State *L, } } -static gint +static int lua_text_fromtable(lua_State *L) { LUA_TRACE_POINT; - const gchar *delim = ""; + const char *delim = ""; struct rspamd_lua_text *t; gsize textlen = 0, dlen, oldtop = lua_gettop(L); - gchar *dest; + char *dest; if (!lua_istable(L, 1)) { return luaL_error(L, "invalid arguments"); @@ -578,13 +578,13 @@ lua_text_fromtable(lua_State *L) lua_text_tbl_append(L, delim, dlen, &dest, 0); lua_pop(L, 1); /* Table arg */ - gint newtop = lua_gettop(L); + int newtop = lua_gettop(L); g_assert(newtop == oldtop + 1); return 1; } -static gint +static int lua_text_len(lua_State *L) { LUA_TRACE_POINT; @@ -603,7 +603,7 @@ lua_text_len(lua_State *L) return 1; } -static gint +static int lua_text_str(lua_State *L) { LUA_TRACE_POINT; @@ -619,7 +619,7 @@ lua_text_str(lua_State *L) return 1; } -static gint +static int lua_text_ptr(lua_State *L) { LUA_TRACE_POINT; @@ -635,12 +635,12 @@ lua_text_ptr(lua_State *L) return 1; } -static gint +static int lua_text_take_ownership(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t = lua_check_text(L, 1); - gchar *dest; + char *dest; if (t != NULL) { if (t->flags & RSPAMD_TEXT_FLAG_OWN) { @@ -662,7 +662,7 @@ lua_text_take_ownership(lua_State *L) return 1; } -static gint +static int lua_text_span(lua_State *L) { LUA_TRACE_POINT; @@ -700,7 +700,7 @@ lua_text_span(lua_State *L) /* Helpers to behave exactly as Lua does */ static inline gsize -relative_pos_start(gint pos, gsize len) +relative_pos_start(int pos, gsize len) { if (pos > 0) { return pos; @@ -708,7 +708,7 @@ relative_pos_start(gint pos, gsize len) else if (pos == 0) { return 1; } - else if (pos < -((gint) len)) { + else if (pos < -((int) len)) { return 1; } @@ -717,22 +717,22 @@ relative_pos_start(gint pos, gsize len) } static inline gsize -relative_pos_end(gint pos, gsize len) +relative_pos_end(int pos, gsize len) { - if (pos > (gint) len) { + if (pos > (int) len) { return len; } else if (pos >= 0) { return (size_t) pos; } - else if (pos < -((gint) len)) { + else if (pos < -((int) len)) { return 0; } return len + ((gsize) pos) + 1; } -static gint +static int lua_text_sub(lua_State *L) { LUA_TRACE_POINT; @@ -764,10 +764,10 @@ static int64_t rspamd_lua_text_push_line(lua_State *L, struct rspamd_lua_text *t, int64_t start_offset, - const gchar *sep_pos, + const char *sep_pos, gboolean stringify) { - const gchar *start; + const char *start; gsize len; int64_t ret; @@ -801,7 +801,7 @@ rspamd_lua_text_push_line(lua_State *L, return ret; } -static gint +static int rspamd_lua_text_readline(lua_State *L) { struct rspamd_lua_text *t = lua_touserdata(L, lua_upvalueindex(1)); @@ -809,7 +809,7 @@ rspamd_lua_text_readline(lua_State *L) int64_t pos = lua_tointeger(L, lua_upvalueindex(3)); if (pos < 0) { - return luaL_error(L, "invalid pos: %d", (gint) pos); + return luaL_error(L, "invalid pos: %d", (int) pos); } if (pos >= t->len) { @@ -817,7 +817,7 @@ rspamd_lua_text_readline(lua_State *L) return 0; } - const gchar *sep_pos; + const char *sep_pos; /* We look just for `\n` ignoring `\r` as it is very rare nowadays */ sep_pos = memchr(t->start + pos, '\n', t->len - pos); @@ -846,7 +846,7 @@ rspamd_lua_text_readline(lua_State *L) return 1; } -static gint +static int lua_text_lines(lua_State *L) { LUA_TRACE_POINT; @@ -870,7 +870,7 @@ lua_text_lines(lua_State *L) return 1; } -static gint +static int rspamd_lua_text_regexp_split(lua_State *L) { struct rspamd_lua_text *t = lua_touserdata(L, lua_upvalueindex(1)), @@ -882,7 +882,7 @@ rspamd_lua_text_regexp_split(lua_State *L) gboolean matched; if (pos < 0) { - return luaL_error(L, "invalid pos: %d", (gint) pos); + return luaL_error(L, "invalid pos: %d", (int) pos); } if (pos >= t->len) { @@ -890,7 +890,7 @@ rspamd_lua_text_regexp_split(lua_State *L) return 0; } - const gchar *start, *end, *old_start; + const char *start, *end, *old_start; end = t->start + pos; @@ -963,7 +963,7 @@ rspamd_lua_text_regexp_split(lua_State *L) return 1; } -static gint +static int lua_text_split(lua_State *L) { LUA_TRACE_POINT; @@ -985,9 +985,9 @@ lua_text_split(lua_State *L) c_re = rspamd_regexp_new(lua_tostring(L, 2), NULL, &err); if (c_re == NULL) { - gint ret = luaL_error(L, "cannot parse regexp: %s, error: %s", - lua_tostring(L, 2), - err == NULL ? "undefined" : err->message); + int ret = luaL_error(L, "cannot parse regexp: %s, error: %s", + lua_tostring(L, 2), + err == NULL ? "undefined" : err->message); if (err) { g_error_free(err); } @@ -1032,13 +1032,13 @@ lua_text_split(lua_State *L) } -static gint +static int lua_text_at(lua_State *L) { return lua_text_byte(L); } -static gint +static int lua_text_byte(lua_State *L) { LUA_TRACE_POINT; @@ -1061,7 +1061,7 @@ lua_text_byte(lua_State *L) return end - start; } -static gint +static int lua_text_memchr(lua_State *L) { LUA_TRACE_POINT; @@ -1074,7 +1074,7 @@ lua_text_memchr(lua_State *L) } else { gsize l; - const gchar *str = lua_tolstring(L, 2, &l); + const char *str = lua_tolstring(L, 2, &l); if (str) { c = str[0]; @@ -1116,7 +1116,7 @@ lua_text_memchr(lua_State *L) return 1; } -static gint +static int lua_text_bytes(lua_State *L) { LUA_TRACE_POINT; @@ -1126,7 +1126,7 @@ lua_text_bytes(lua_State *L) lua_createtable(L, t->len, 0); for (gsize i = 0; i < t->len; i++) { - lua_pushinteger(L, (guchar) t->start[i]); + lua_pushinteger(L, (unsigned char) t->start[i]); lua_rawseti(L, -2, i + 1); } } @@ -1137,14 +1137,14 @@ lua_text_bytes(lua_State *L) return 1; } -static gint +static int lua_text_save_in_file(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t = lua_check_text(L, 1); - const gchar *fname = NULL; - guint mode = 00644; - gint fd = -1; + const char *fname = NULL; + unsigned int mode = 00644; + int fd = -1; gboolean need_close = FALSE; if (t != NULL) { @@ -1201,7 +1201,7 @@ lua_text_save_in_file(lua_State *L) return 1; } -static gint +static int lua_text_gc(lua_State *L) { LUA_TRACE_POINT; @@ -1212,7 +1212,7 @@ lua_text_gc(lua_State *L) if (t->flags & RSPAMD_TEXT_FLAG_OWN) { if (t->flags & RSPAMD_TEXT_FLAG_WIPE) { - rspamd_explicit_memzero((guchar *) t->start, t->len); + rspamd_explicit_memzero((unsigned char *) t->start, t->len); } if (t->flags & RSPAMD_TEXT_FLAG_MMAPED) { @@ -1232,7 +1232,7 @@ lua_text_gc(lua_State *L) return 0; } -static gint +static int lua_text_eq(lua_State *L) { LUA_TRACE_POINT; @@ -1249,7 +1249,7 @@ lua_text_eq(lua_State *L) return 1; } -static gint +static int lua_text_lt(lua_State *L) { LUA_TRACE_POINT; @@ -1268,7 +1268,7 @@ lua_text_lt(lua_State *L) return 1; } -static gint +static int lua_text_concat(lua_State *L) { LUA_TRACE_POINT; @@ -1286,7 +1286,7 @@ lua_text_concat(lua_State *L) return 1; } -static gint +static int lua_text_wipe(lua_State *L) { LUA_TRACE_POINT; @@ -1294,7 +1294,7 @@ lua_text_wipe(lua_State *L) if (t != NULL) { if (t->flags & RSPAMD_TEXT_FLAG_OWN) { - rspamd_explicit_memzero((guchar *) t->start, t->len); + rspamd_explicit_memzero((unsigned char *) t->start, t->len); } else { return luaL_error(L, "cannot wipe not owned text"); @@ -1307,7 +1307,7 @@ lua_text_wipe(lua_State *L) return 0; } -static gint +static int lua_text_base32(lua_State *L) { LUA_TRACE_POINT; @@ -1324,7 +1324,7 @@ lua_text_base32(lua_State *L) } out = lua_new_text(L, NULL, t->len * 8 / 5 + 2, TRUE); - out->len = rspamd_encode_base32_buf(t->start, t->len, (gchar *) out->start, + out->len = rspamd_encode_base32_buf(t->start, t->len, (char *) out->start, out->len, btype); } else { @@ -1334,7 +1334,7 @@ lua_text_base32(lua_State *L) return 1; } -static gint +static int lua_text_base64(lua_State *L) { LUA_TRACE_POINT; @@ -1354,7 +1354,7 @@ lua_text_base64(lua_State *L) enum rspamd_newlines_type how = RSPAMD_TASK_NEWLINES_CRLF; if (lua_type(L, 3) == LUA_TSTRING) { - const gchar *how_str = lua_tostring(L, 3); + const char *how_str = lua_tostring(L, 3); if (g_ascii_strcasecmp(how_str, "cr") == 0) { how = RSPAMD_TASK_NEWLINES_CR; @@ -1387,7 +1387,7 @@ lua_text_base64(lua_State *L) return 1; } -static gint +static int lua_text_hex(lua_State *L) { LUA_TRACE_POINT; @@ -1396,7 +1396,7 @@ lua_text_hex(lua_State *L) if (t != NULL) { out = lua_new_text(L, NULL, t->len * 2, TRUE); - out->len = rspamd_encode_hex_buf(t->start, t->len, (gchar *) out->start, + out->len = rspamd_encode_hex_buf(t->start, t->len, (char *) out->start, out->len); } else { @@ -1406,13 +1406,13 @@ lua_text_hex(lua_State *L) return 1; } -static gint +static int lua_text_find(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t = lua_check_text(L, 1); gsize patlen, init = 1; - const gchar *pat = luaL_checklstring(L, 2, &patlen); + const char *pat = luaL_checklstring(L, 2, &patlen); if (t != NULL && pat != NULL) { @@ -1449,17 +1449,17 @@ lua_text_find(lua_State *L) #define BITOP(a, b, op) \ ((a)[(uint64_t) (b) / (8u * sizeof *(a))] op(uint64_t) 1 << ((uint64_t) (b) % (8u * sizeof *(a)))) -static gint +static int lua_text_exclude_chars(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t = lua_check_text(L, 1); gssize patlen; - const gchar *pat = lua_tolstring(L, 2, &patlen), *p, *end; - gchar *dest, *d; + const char *pat = lua_tolstring(L, 2, &patlen), *p, *end; + char *dest, *d; uint64_t byteset[32 / sizeof(uint64_t)]; /* Bitset for ascii */ gboolean copy = TRUE; - guint *plen; + unsigned int *plen; if (t != NULL && pat && patlen > 0) { if (lua_isboolean(L, 3)) { @@ -1470,7 +1470,7 @@ lua_text_exclude_chars(lua_State *L) } if (!copy) { - dest = (gchar *) t->start; + dest = (char *) t->start; plen = &t->len; lua_pushvalue(L, 1); /* Push text as a result */ } @@ -1503,7 +1503,7 @@ lua_text_exclude_chars(lua_State *L) */ switch (*pat) { case '%': - BITOP(byteset, *(guchar *) pat, |=); + BITOP(byteset, *(unsigned char *) pat, |=); break; case 's': /* "\r\n\t\f " */ @@ -1528,17 +1528,17 @@ lua_text_exclude_chars(lua_State *L) } else { /* Last '%' */ - BITOP(byteset, (guchar) '%', |=); + BITOP(byteset, (unsigned char) '%', |=); } } else { - BITOP(byteset, *(guchar *) pat, |=); + BITOP(byteset, *(unsigned char *) pat, |=); } pat++; patlen--; } - for (; patlen > 0 && BITOP(byteset, *(guchar *) pat, |=); pat++, patlen--) + for (; patlen > 0 && BITOP(byteset, *(unsigned char *) pat, |=); pat++, patlen--) ; p = t->start; @@ -1546,7 +1546,7 @@ lua_text_exclude_chars(lua_State *L) d = dest; while (p < end) { - if (!BITOP(byteset, *(guchar *) p, &)) { + if (!BITOP(byteset, *(unsigned char *) p, &)) { *d++ = *p; } @@ -1562,16 +1562,16 @@ lua_text_exclude_chars(lua_State *L) return 1; } -static gint +static int lua_text_oneline(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t = lua_check_text(L, 1); - const gchar *p, *end; - gchar *dest, *d; + const char *p, *end; + char *dest, *d; uint64_t byteset[32 / sizeof(uint64_t)]; /* Bitset for ascii */ gboolean copy = TRUE, seen_8bit = FALSE; - guint *plen; + unsigned int *plen; if (t != NULL) { if (lua_isboolean(L, 2)) { @@ -1582,7 +1582,7 @@ lua_text_oneline(lua_State *L) } if (!copy) { - dest = (gchar *) t->start; + dest = (char *) t->start; plen = &t->len; lua_pushvalue(L, 1); /* Push text as a result */ } @@ -1617,11 +1617,11 @@ lua_text_oneline(lua_State *L) d = dest; while (p < end) { - if (!BITOP(byteset, *(guchar *) p, &)) { + if (!BITOP(byteset, *(unsigned char *) p, &)) { *d++ = *p; } else { - if ((*(guchar *) p) & 0x80) { + if ((*(unsigned char *) p) & 0x80) { seen_8bit = TRUE; *d++ = *p; } @@ -1665,10 +1665,10 @@ lua_text_oneline(lua_State *L) UChar32 uc; goffset err_offset; gsize remain = d - dest; - gchar *nd = dest; + char *nd = dest; while (remain > 0 && (err_offset = rspamd_fast_utf8_validate(nd, remain)) > 0) { - gint i = 0; + int i = 0; err_offset--; /* As it returns it 1 indexed */ nd += err_offset; @@ -1676,7 +1676,7 @@ lua_text_oneline(lua_State *L) /* Each invalid character of input requires 3 bytes of output (+2 bytes) */ while (i < remain) { - gint old_pos = i; + int old_pos = i; U8_NEXT(nd, i, remain, uc); if (uc < 0) { @@ -1702,7 +1702,7 @@ lua_text_oneline(lua_State *L) return 1; } -static gint +static int lua_text_lower(lua_State *L) { LUA_TRACE_POINT; @@ -1726,10 +1726,10 @@ lua_text_lower(lua_State *L) } if (!is_utf8) { - rspamd_str_lc((gchar *) nt->start, nt->len); + rspamd_str_lc((char *) nt->start, nt->len); } else { - rspamd_str_lc_utf8((gchar *) nt->start, nt->len); + rspamd_str_lc_utf8((char *) nt->start, nt->len); } } else { @@ -1739,7 +1739,7 @@ lua_text_lower(lua_State *L) return 1; } -static gint +static int lua_text_strtoul(lua_State *L) { LUA_TRACE_POINT; @@ -1763,9 +1763,9 @@ lua_text_strtoul(lua_State *L) } /* Used to distinguish lua text metatable */ -static const guint rspamd_lua_text_cookie = 0x2b21ef6fU; +static const unsigned int rspamd_lua_text_cookie = 0x2b21ef6fU; -static gint +static int lua_load_text(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_thread_pool.cxx b/src/lua/lua_thread_pool.cxx index 295f33d07..e1eabe60b 100644 --- a/src/lua/lua_thread_pool.cxx +++ b/src/lua/lua_thread_pool.cxx @@ -37,11 +37,11 @@ static void thread_entry_free(lua_State *L, struct thread_entry *ent); struct lua_thread_pool { std::vector available_items; lua_State *L; - gint max_items; + int max_items; struct thread_entry *running_entry; static const int default_max_items = 100; - lua_thread_pool(lua_State *L, gint max_items = default_max_items) + lua_thread_pool(lua_State *L, int max_items = default_max_items) : L(L), max_items(max_items) { running_entry = nullptr; @@ -77,7 +77,7 @@ struct lua_thread_pool { return ent; } - auto return_thread(struct thread_entry *thread_entry, const gchar *loc) -> void + auto return_thread(struct thread_entry *thread_entry, const char *loc) -> void { /* we can't return a running/yielded thread into the pool */ g_assert(lua_status(thread_entry->lua_state) == 0); @@ -108,7 +108,7 @@ struct lua_thread_pool { } auto terminate_thread(struct thread_entry *thread_entry, - const gchar *loc, + const char *loc, bool enforce) -> void { struct thread_entry *ent = NULL; @@ -197,13 +197,13 @@ lua_thread_pool_get_for_config(struct rspamd_config *cfg) } void lua_thread_pool_return_full(struct lua_thread_pool *pool, - struct thread_entry *thread_entry, const gchar *loc) + struct thread_entry *thread_entry, const char *loc) { pool->return_thread(thread_entry, loc); } void lua_thread_pool_terminate_entry_full(struct lua_thread_pool *pool, - struct thread_entry *thread_entry, const gchar *loc, + struct thread_entry *thread_entry, const char *loc, bool enforce) { pool->terminate_thread(thread_entry, loc, enforce); @@ -211,7 +211,7 @@ void lua_thread_pool_terminate_entry_full(struct lua_thread_pool *pool, struct thread_entry * lua_thread_pool_get_running_entry_full(struct lua_thread_pool *pool, - const gchar *loc) + const char *loc) { msg_debug_lua_threads("%s: lua_thread_pool_get_running_entry_full", loc); return pool->get_running_entry(); @@ -219,7 +219,7 @@ lua_thread_pool_get_running_entry_full(struct lua_thread_pool *pool, void lua_thread_pool_set_running_entry_full(struct lua_thread_pool *pool, struct thread_entry *thread_entry, - const gchar *loc) + const char *loc) { msg_debug_lua_threads("%s: lua_thread_pool_set_running_entry_full", loc); pool->set_running_entry(thread_entry); @@ -227,7 +227,7 @@ void lua_thread_pool_set_running_entry_full(struct lua_thread_pool *pool, static void lua_thread_pool_set_running_entry_for_thread(struct thread_entry *thread_entry, - const gchar *loc) + const char *loc) { struct lua_thread_pool *pool; @@ -243,7 +243,7 @@ lua_thread_pool_set_running_entry_for_thread(struct thread_entry *thread_entry, void lua_thread_pool_prepare_callback_full(struct lua_thread_pool *pool, struct lua_callback_state *cbs, - const gchar *loc) + const char *loc) { msg_debug_lua_threads("%s: lua_thread_pool_prepare_callback_full", loc); cbs->thread_pool = pool; @@ -253,15 +253,15 @@ void lua_thread_pool_prepare_callback_full(struct lua_thread_pool *pool, } void lua_thread_pool_restore_callback_full(struct lua_callback_state *cbs, - const gchar *loc) + const char *loc) { lua_thread_pool_return_full(cbs->thread_pool, cbs->my_thread, loc); lua_thread_pool_set_running_entry_full(cbs->thread_pool, cbs->previous_thread, loc); } -static gint -lua_do_resume_full(lua_State *L, gint narg, const gchar *loc) +static int +lua_do_resume_full(lua_State *L, int narg, const char *loc) { #if LUA_VERSION_NUM >= 504 int nres; @@ -280,9 +280,9 @@ lua_do_resume_full(lua_State *L, gint narg, const gchar *loc) static void lua_resume_thread_internal_full(struct thread_entry *thread_entry, - gint narg, const gchar *loc) + int narg, const char *loc) { - gint ret; + int ret; struct lua_thread_pool *pool; struct rspamd_task *task; @@ -335,8 +335,8 @@ lua_resume_thread_internal_full(struct thread_entry *thread_entry, } } -void lua_thread_resume_full(struct thread_entry *thread_entry, gint narg, - const gchar *loc) +void lua_thread_resume_full(struct thread_entry *thread_entry, int narg, + const char *loc) { /* * The only state where we can resume from is LUA_YIELD @@ -350,7 +350,7 @@ void lua_thread_resume_full(struct thread_entry *thread_entry, gint narg, } void lua_thread_call_full(struct thread_entry *thread_entry, - int narg, const gchar *loc) + int narg, const char *loc) { g_assert(lua_status(thread_entry->lua_state) == 0); /* we can't call running/yielded thread */ g_assert(thread_entry->task != NULL || thread_entry->cfg != NULL); /* we can't call without pool */ @@ -358,9 +358,9 @@ void lua_thread_call_full(struct thread_entry *thread_entry, lua_resume_thread_internal_full(thread_entry, narg, loc); } -gint lua_thread_yield_full(struct thread_entry *thread_entry, - gint nresults, - const gchar *loc) +int lua_thread_yield_full(struct thread_entry *thread_entry, + int nresults, + const char *loc) { g_assert(lua_status(thread_entry->lua_state) == 0); diff --git a/src/lua/lua_thread_pool.h b/src/lua/lua_thread_pool.h index b612ac3a5..c6ad31847 100644 --- a/src/lua/lua_thread_pool.h +++ b/src/lua/lua_thread_pool.h @@ -16,7 +16,7 @@ typedef void (*lua_thread_error_t)(struct thread_entry *thread, int ret, const c struct thread_entry { lua_State *lua_state; - gint thread_index; + int thread_index; gpointer cd; /* function to handle result of called method, can be NULL */ @@ -82,7 +82,7 @@ lua_thread_pool_get_for_config(struct rspamd_config *cfg); */ void lua_thread_pool_return_full(struct lua_thread_pool *pool, struct thread_entry *thread_entry, - const gchar *loc); + const char *loc); #define lua_thread_pool_return(pool, thread_entry) \ lua_thread_pool_return_full(pool, thread_entry, G_STRLOC) @@ -95,7 +95,7 @@ void lua_thread_pool_return_full(struct lua_thread_pool *pool, */ struct thread_entry * lua_thread_pool_get_running_entry_full(struct lua_thread_pool *pool, - const gchar *loc); + const char *loc); #define lua_thread_pool_get_running_entry(pool) \ lua_thread_pool_get_running_entry_full(pool, G_STRLOC) @@ -108,7 +108,7 @@ lua_thread_pool_get_running_entry_full(struct lua_thread_pool *pool, */ void lua_thread_pool_set_running_entry_full(struct lua_thread_pool *pool, struct thread_entry *thread_entry, - const gchar *loc); + const char *loc); #define lua_thread_pool_set_running_entry(pool, thread_entry) \ lua_thread_pool_set_running_entry_full(pool, thread_entry, G_STRLOC) @@ -120,7 +120,7 @@ void lua_thread_pool_set_running_entry_full(struct lua_thread_pool *pool, * @param cbs */ void lua_thread_pool_prepare_callback_full(struct lua_thread_pool *pool, - struct lua_callback_state *cbs, const gchar *loc); + struct lua_callback_state *cbs, const char *loc); #define lua_thread_pool_prepare_callback(pool, cbs) \ lua_thread_pool_prepare_callback_full(pool, cbs, G_STRLOC) @@ -131,7 +131,7 @@ void lua_thread_pool_prepare_callback_full(struct lua_thread_pool *pool, * @param cbs */ void lua_thread_pool_restore_callback_full(struct lua_callback_state *cbs, - const gchar *loc); + const char *loc); #define lua_thread_pool_restore_callback(cbs) \ lua_thread_pool_restore_callback_full(cbs, G_STRLOC) @@ -145,7 +145,7 @@ void lua_thread_pool_restore_callback_full(struct lua_callback_state *cbs, */ void lua_thread_call_full(struct thread_entry *thread_entry, int narg, - const gchar *loc); + const char *loc); #define lua_thread_call(thread_entry, narg) \ lua_thread_call_full(thread_entry, narg, G_STRLOC) @@ -157,7 +157,7 @@ void lua_thread_call_full(struct thread_entry *thread_entry, * @return */ int lua_thread_yield_full(struct thread_entry *thread_entry, int nresults, - const gchar *loc); + const char *loc); #define lua_thread_yield(thread_entry, narg) \ lua_thread_yield_full(thread_entry, narg, G_STRLOC) @@ -170,7 +170,7 @@ int lua_thread_yield_full(struct thread_entry *thread_entry, int nresults, */ void lua_thread_resume_full(struct thread_entry *thread_entry, int narg, - const gchar *loc); + const char *loc); #define lua_thread_resume(thread_entry, narg) \ lua_thread_resume_full(thread_entry, narg, G_STRLOC) @@ -183,7 +183,7 @@ void lua_thread_resume_full(struct thread_entry *thread_entry, */ void lua_thread_pool_terminate_entry_full(struct lua_thread_pool *pool, struct thread_entry *thread_entry, - const gchar *loc, bool enforce); + const char *loc, bool enforce); #define lua_thread_pool_terminate_entry(pool, thread_entry) \ lua_thread_pool_terminate_entry_full(pool, thread_entry, G_STRLOC, false) diff --git a/src/lua/lua_trie.c b/src/lua/lua_trie.c index 70a685da2..210b089bb 100644 --- a/src/lua/lua_trie.c +++ b/src/lua/lua_trie.c @@ -60,7 +60,7 @@ static const struct luaL_reg trielib_f[] = { {NULL, NULL}}; static struct rspamd_multipattern * -lua_check_trie(lua_State *L, gint idx) +lua_check_trie(lua_State *L, int idx) { void *ud = rspamd_lua_check_udata(L, 1, rspamd_trie_classname); @@ -68,7 +68,7 @@ lua_check_trie(lua_State *L, gint idx) return ud ? *((struct rspamd_multipattern **) ud) : NULL; } -static gint +static int lua_trie_destroy(lua_State *L) { struct rspamd_multipattern *trie = lua_check_trie(L, 1); @@ -86,7 +86,7 @@ lua_trie_destroy(lua_State *L) * * @return {bool} true if hyperscan is supported */ -static gint +static int lua_trie_has_hyperscan(lua_State *L) { lua_pushboolean(L, rspamd_multipattern_has_hyperscan()); @@ -99,11 +99,11 @@ lua_trie_has_hyperscan(lua_State *L) * @param {table} array of string patterns * @return {trie} new trie object */ -static gint +static int lua_trie_create(lua_State *L) { struct rspamd_multipattern *trie, **ptrie; - gint npat = 0, flags = RSPAMD_MULTIPATTERN_ICASE | RSPAMD_MULTIPATTERN_GLOB; + int npat = 0, flags = RSPAMD_MULTIPATTERN_ICASE | RSPAMD_MULTIPATTERN_GLOB; GError *err = NULL; if (lua_isnumber(L, 2)) { @@ -130,7 +130,7 @@ lua_trie_create(lua_State *L) while (lua_next(L, -2) != 0) { if (lua_isstring(L, -1)) { - const gchar *pat; + const char *pat; gsize patlen; pat = lua_tolstring(L, -1, &patlen); @@ -173,17 +173,17 @@ lua_trie_create(lua_State *L) } while (0) /* Normal callback type */ -static gint +static int lua_trie_lua_cb_callback(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint textpos, - const gchar *text, + unsigned int strnum, + int match_start, + int textpos, + const char *text, gsize len, void *context) { lua_State *L = context; - gint ret; + int ret; gboolean report_start = lua_toboolean(L, -1); @@ -208,18 +208,18 @@ lua_trie_lua_cb_callback(struct rspamd_multipattern *mp, } /* Table like callback, expect result table on top of the stack */ -static gint +static int lua_trie_table_callback(struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint textpos, - const gchar *text, + unsigned int strnum, + int match_start, + int textpos, + const char *text, gsize len, void *context) { lua_State *L = context; - gint report_start = lua_toboolean(L, -2); + int report_start = lua_toboolean(L, -2); /* Set table, indexed by pattern number */ lua_rawgeti(L, -1, strnum + 1); @@ -247,12 +247,12 @@ lua_trie_table_callback(struct rspamd_multipattern *mp, /* * We assume that callback argument is at pos 3 and icase is in position 4 */ -static gint +static int lua_trie_search_str(lua_State *L, struct rspamd_multipattern *trie, - const gchar *str, gsize len, rspamd_multipattern_cb_t cb) + const char *str, gsize len, rspamd_multipattern_cb_t cb) { - gint ret; - guint nfound = 0; + int ret; + unsigned int nfound = 0; if ((ret = rspamd_multipattern_lookup(trie, str, len, cb, L, &nfound)) == 0) { @@ -270,18 +270,18 @@ lua_trie_search_str(lua_State *L, struct rspamd_multipattern *trie, * @param {boolean} report_start report both start and end offset when matching patterns * @return {boolean} `true` if any pattern has been found (`cb` might be called multiple times however). If `cb` is not defined then it returns a table of match positions indexed by pattern number */ -static gint +static int lua_trie_match(lua_State *L) { LUA_TRACE_POINT; struct rspamd_multipattern *trie = lua_check_trie(L, 1); - const gchar *text; + const char *text; gsize len; gboolean found = FALSE, report_start = FALSE; struct rspamd_lua_text *t; rspamd_multipattern_cb_t cb = lua_trie_lua_cb_callback; - gint old_top = lua_gettop(L); + int old_top = lua_gettop(L); if (trie) { if (lua_type(L, 3) != LUA_TFUNCTION) { @@ -360,14 +360,14 @@ lua_trie_match(lua_State *L) * @param {boolean} caseless if `true` then match ignores symbols case (ASCII only) * @return {boolean} `true` if any pattern has been found (`cb` might be called multiple times however) */ -static gint +static int lua_trie_search_mime(lua_State *L) { LUA_TRACE_POINT; struct rspamd_multipattern *trie = lua_check_trie(L, 1); struct rspamd_task *task = lua_check_task(L, 2); struct rspamd_mime_text_part *part; - const gchar *text; + const char *text; gsize len, i; gboolean found = FALSE; rspamd_multipattern_cb_t cb = lua_trie_lua_cb_callback; @@ -398,13 +398,13 @@ lua_trie_search_mime(lua_State *L) * @param {boolean} caseless if `true` then match ignores symbols case (ASCII only) * @return {boolean} `true` if any pattern has been found (`cb` might be called multiple times however) */ -static gint +static int lua_trie_search_rawmsg(lua_State *L) { LUA_TRACE_POINT; struct rspamd_multipattern *trie = lua_check_trie(L, 1); struct rspamd_task *task = lua_check_task(L, 2); - const gchar *text; + const char *text; gsize len; gboolean found = FALSE; @@ -429,13 +429,13 @@ lua_trie_search_rawmsg(lua_State *L) * @param {boolean} caseless if `true` then match ignores symbols case (ASCII only) * @return {boolean} `true` if any pattern has been found (`cb` might be called multiple times however) */ -static gint +static int lua_trie_search_rawbody(lua_State *L) { LUA_TRACE_POINT; struct rspamd_multipattern *trie = lua_check_trie(L, 1); struct rspamd_task *task = lua_check_task(L, 2); - const gchar *text; + const char *text; gsize len; gboolean found = FALSE; @@ -459,7 +459,7 @@ lua_trie_search_rawbody(lua_State *L) return 1; } -static gint +static int lua_load_trie(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_udp.c b/src/lua/lua_udp.c index d20475933..392c47f52 100644 --- a/src/lua/lua_udp.c +++ b/src/lua/lua_udp.c @@ -20,7 +20,7 @@ #include #include -static const gchar *M = "rspamd lua udp"; +static const char *M = "rspamd lua udp"; /*** * @module rspamd_udp @@ -69,10 +69,10 @@ struct lua_udp_cbdata { struct rspamd_async_session *s; struct iovec *iov; lua_State *L; - guint retransmits; - guint iovlen; - gint sock; - gint cbref; + unsigned int retransmits; + unsigned int iovlen; + int sock; + int cbref; gboolean sent; }; @@ -85,7 +85,7 @@ INIT_LOG_MODULE(lua_udp) static inline void lua_fill_iov(lua_State *L, rspamd_mempool_t *pool, - struct iovec *iov, gint pos) + struct iovec *iov, int pos) { if (lua_type(L, pos) == LUA_TUSERDATA) { struct rspamd_lua_text *t = lua_check_text(L, pos); @@ -97,7 +97,7 @@ lua_fill_iov(lua_State *L, rspamd_mempool_t *pool, } } else { - const gchar *s; + const char *s; gsize len; s = lua_tolstring(L, pos, &len); @@ -154,7 +154,7 @@ static enum rspamd_udp_send_result lua_try_send_request(struct lua_udp_cbdata *cbd) { struct msghdr msg; - gint r; + int r; memset(&msg, 0, sizeof(msg)); msg.msg_iov = cbd->iov; @@ -175,10 +175,10 @@ lua_try_send_request(struct lua_udp_cbdata *cbd) } static void -lua_udp_maybe_push_error(struct lua_udp_cbdata *cbd, const gchar *err) +lua_udp_maybe_push_error(struct lua_udp_cbdata *cbd, const char *err) { if (cbd->cbref != -1) { - gint top; + int top; lua_State *L = cbd->L; top = lua_gettop(L); @@ -203,11 +203,11 @@ lua_udp_maybe_push_error(struct lua_udp_cbdata *cbd, const gchar *err) } static void -lua_udp_push_data(struct lua_udp_cbdata *cbd, const gchar *data, +lua_udp_push_data(struct lua_udp_cbdata *cbd, const char *data, gssize len) { if (cbd->cbref != -1) { - gint top; + int top; lua_State *L = cbd->L; top = lua_gettop(L); @@ -259,7 +259,7 @@ lua_udp_maybe_register_event(struct lua_udp_cbdata *cbd) } static void -lua_udp_io_handler(gint fd, short what, gpointer p) +lua_udp_io_handler(int fd, short what, gpointer p) { struct lua_udp_cbdata *cbd = (struct lua_udp_cbdata *) p; gssize r; @@ -311,7 +311,7 @@ lua_udp_io_handler(gint fd, short what, gpointer p) } } else if (what == EV_READ) { - guchar udpbuf[4096]; + unsigned char udpbuf[4096]; socklen_t slen; struct sockaddr *sa; @@ -343,19 +343,19 @@ lua_udp_io_handler(gint fd, short what, gpointer p) * - `callback`: optional callback if reply should be read * @return {boolean} true if request has been sent (additional string if it has not) */ -static gint +static int lua_udp_sendto(lua_State *L) { LUA_TRACE_POINT; - const gchar *host; - guint port; + const char *host; + unsigned int port; struct ev_loop *ev_base = NULL; struct lua_udp_cbdata *cbd; struct rspamd_async_session *session = NULL; struct rspamd_task *task = NULL; rspamd_inet_addr_t *addr; rspamd_mempool_t *pool = NULL; - gdouble timeout = default_udp_timeout; + double timeout = default_udp_timeout; if (lua_type(L, 1) == LUA_TTABLE) { lua_pushstring(L, "port"); @@ -579,7 +579,7 @@ lua_udp_sendto(lua_State *L) return 1; } -static gint +static int lua_load_udp(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c index 69d9f39c4..181ef9398 100644 --- a/src/lua/lua_upstream.c +++ b/src/lua/lua_upstream.c @@ -106,7 +106,7 @@ lua_check_upstream(lua_State *L, int pos) * Get ip of upstream * @return {ip} ip address object */ -static gint +static int lua_upstream_get_addr(lua_State *L) { LUA_TRACE_POINT; @@ -127,7 +127,7 @@ lua_upstream_get_addr(lua_State *L) * Get name of upstream * @return {string} name of the upstream */ -static gint +static int lua_upstream_get_name(lua_State *L) { LUA_TRACE_POINT; @@ -148,7 +148,7 @@ lua_upstream_get_name(lua_State *L) * Get port of upstream * @return {int} port of the upstream */ -static gint +static int lua_upstream_get_port(lua_State *L) { LUA_TRACE_POINT; @@ -168,13 +168,13 @@ lua_upstream_get_port(lua_State *L) * @method upstream:fail() * Indicate upstream failure. After certain amount of failures during specified time frame, an upstream is marked as down and does not participate in rotations. */ -static gint +static int lua_upstream_fail(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_upstream *up = lua_check_upstream(L, 1); gboolean fail_addr = FALSE; - const gchar *reason = "unknown"; + const char *reason = "unknown"; if (up) { @@ -199,7 +199,7 @@ lua_upstream_fail(lua_State *L) * @method upstream:ok() * Indicates upstream success. Resets errors count for an upstream. */ -static gint +static int lua_upstream_ok(lua_State *L) { LUA_TRACE_POINT; @@ -212,7 +212,7 @@ lua_upstream_ok(lua_State *L) return 0; } -static gint +static int lua_upstream_destroy(lua_State *L) { LUA_TRACE_POINT; @@ -239,7 +239,7 @@ lua_check_upstream_list(lua_State *L) } static struct rspamd_lua_upstream * -lua_push_upstream(lua_State *L, gint up_idx, struct upstream *up) +lua_push_upstream(lua_State *L, int up_idx, struct upstream *up) { struct rspamd_lua_upstream *lua_ups; @@ -265,15 +265,15 @@ lua_push_upstream(lua_State *L, gint up_idx, struct upstream *up) * @param {number} default_port default port for upstreams * @return {upstream_list} upstream list structure */ -static gint +static int lua_upstream_list_create(lua_State *L) { LUA_TRACE_POINT; struct upstream_list *new = NULL, **pnew; struct rspamd_config *cfg = NULL; - const gchar *def; - guint default_port = 0; - gint top; + const char *def; + unsigned int default_port = 0; + int top; if (lua_type(L, 1) == LUA_TUSERDATA) { @@ -333,7 +333,7 @@ lua_upstream_list_create(lua_State *L) * @param L * @return */ -static gint +static int lua_upstream_list_destroy(lua_State *L) { LUA_TRACE_POINT; @@ -350,13 +350,13 @@ lua_upstream_list_destroy(lua_State *L) * @param {string} key a string used as input for stable hash algorithm * @return {upstream} upstream from a list corresponding to the given key */ -static gint +static int lua_upstream_list_get_upstream_by_hash(lua_State *L) { LUA_TRACE_POINT; struct upstream_list *upl; struct upstream *selected; - const gchar *key; + const char *key; gsize keyl; upl = lua_check_upstream_list(L); @@ -364,7 +364,7 @@ lua_upstream_list_get_upstream_by_hash(lua_State *L) key = luaL_checklstring(L, 2, &keyl); if (key) { selected = rspamd_upstream_get(upl, RSPAMD_UPSTREAM_HASHED, key, - (guint) keyl); + (unsigned int) keyl); if (selected) { lua_push_upstream(L, 1, selected); @@ -389,7 +389,7 @@ lua_upstream_list_get_upstream_by_hash(lua_State *L) * Get upstream round robin (by current weight) * @return {upstream} upstream from a list in round-robin matter */ -static gint +static int lua_upstream_list_get_upstream_round_robin(lua_State *L) { LUA_TRACE_POINT; @@ -419,7 +419,7 @@ lua_upstream_list_get_upstream_round_robin(lua_State *L) * Get upstream master slave order (by static priority) * @return {upstream} upstream from a list in master-slave order */ -static gint +static int lua_upstream_list_get_upstream_master_slave(lua_State *L) { LUA_TRACE_POINT; @@ -448,10 +448,10 @@ lua_upstream_list_get_upstream_master_slave(lua_State *L) struct upstream_foreach_cbdata { lua_State *L; - gint ups_pos; + int ups_pos; }; -static void lua_upstream_inserter(struct upstream *up, guint idx, void *ud) +static void lua_upstream_inserter(struct upstream *up, unsigned int idx, void *ud) { struct upstream_foreach_cbdata *cbd = (struct upstream_foreach_cbdata *) ud; @@ -463,7 +463,7 @@ static void lua_upstream_inserter(struct upstream *up, guint idx, void *ud) * Returns all upstreams for this list * @return {table|upstream} all upstreams defined */ -static gint +static int lua_upstream_list_all_upstreams(lua_State *L) { LUA_TRACE_POINT; @@ -486,7 +486,7 @@ lua_upstream_list_all_upstreams(lua_State *L) } static inline enum rspamd_upstreams_watch_event -lua_str_to_upstream_flag(const gchar *str) +lua_str_to_upstream_flag(const char *str) { enum rspamd_upstreams_watch_event fl = 0; @@ -509,10 +509,10 @@ lua_str_to_upstream_flag(const gchar *str) return fl; } -static inline const gchar * +static inline const char * lua_upstream_flag_to_str(enum rspamd_upstreams_watch_event fl) { - const gchar *res = "unknown"; + const char *res = "unknown"; /* Works with single flags, not combinations */ if (fl & RSPAMD_UPSTREAM_WATCH_SUCCESS) { @@ -536,22 +536,22 @@ lua_upstream_flag_to_str(enum rspamd_upstreams_watch_event fl) struct rspamd_lua_upstream_watcher_cbdata { lua_State *L; - gint cbref; - gint parent_cbref; /* Reference to the upstream list */ + int cbref; + int parent_cbref; /* Reference to the upstream list */ struct upstream_list *upl; }; static void lua_upstream_watch_func(struct upstream *up, enum rspamd_upstreams_watch_event event, - guint cur_errors, + unsigned int cur_errors, void *ud) { struct rspamd_lua_upstream_watcher_cbdata *cdata = (struct rspamd_lua_upstream_watcher_cbdata *) ud; lua_State *L; - const gchar *what; - gint err_idx; + const char *what; + int err_idx; L = cdata->L; what = lua_upstream_flag_to_str(event); @@ -604,7 +604,7 @@ ups:add_watcher('success', function(what, up, cur_errors) ... end) ups:add_watcher({'online', 'offline'}, function(what, up, cur_errors) ... end) * @return nothing */ -static gint +static int lua_upstream_list_add_watcher(lua_State *L) { LUA_TRACE_POINT; @@ -652,7 +652,7 @@ lua_upstream_list_add_watcher(lua_State *L) return 0; } -static gint +static int lua_load_upstream_list(lua_State *L) { lua_newtable(L); diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index f84f64a2c..8e6680a91 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -117,7 +117,7 @@ static const struct luaL_reg urllib_f[] = { {NULL, NULL}}; struct rspamd_lua_url * -lua_check_url(lua_State *L, gint pos) +lua_check_url(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_url_classname); luaL_argcheck(L, ud != NULL, pos, "'url' expected"); @@ -143,7 +143,7 @@ lua_url_single_inserter(struct rspamd_url *url, gsize start_offset, * Get length of the url * @return {number} length of url in bytes */ -static gint +static int lua_url_get_length(lua_State *L) { LUA_TRACE_POINT; @@ -163,7 +163,7 @@ lua_url_get_length(lua_State *L) * Get domain part of the url * @return {string} domain part of URL */ -static gint +static int lua_url_get_host(lua_State *L) { LUA_TRACE_POINT; @@ -183,7 +183,7 @@ lua_url_get_host(lua_State *L) * Get port of the url * @return {number} url port */ -static gint +static int lua_url_get_port(lua_State *L) { LUA_TRACE_POINT; @@ -208,7 +208,7 @@ lua_url_get_port(lua_State *L) * Get user part of the url (e.g. username in email) * @return {string} user part of URL */ -static gint +static int lua_url_get_user(lua_State *L) { LUA_TRACE_POINT; @@ -229,7 +229,7 @@ lua_url_get_user(lua_State *L) * Get path of the url * @return {string} path part of URL */ -static gint +static int lua_url_get_path(lua_State *L) { LUA_TRACE_POINT; @@ -250,7 +250,7 @@ lua_url_get_path(lua_State *L) * Get query of the url * @return {string} query part of URL */ -static gint +static int lua_url_get_query(lua_State *L) { LUA_TRACE_POINT; @@ -271,7 +271,7 @@ lua_url_get_query(lua_State *L) * Get fragment of the url * @return {string} fragment part of URL */ -static gint +static int lua_url_get_fragment(lua_State *L) { LUA_TRACE_POINT; @@ -292,7 +292,7 @@ lua_url_get_fragment(lua_State *L) * Get full content of the url * @return {string} url string */ -static gint +static int lua_url_get_text(lua_State *L) { LUA_TRACE_POINT; @@ -313,7 +313,7 @@ lua_url_get_text(lua_State *L) * Get full content of the url or user@domain in case of email * @return {string} url as a string */ -static gint +static int lua_url_tostring(lua_State *L) { LUA_TRACE_POINT; @@ -321,8 +321,8 @@ lua_url_tostring(lua_State *L) if (url != NULL && url->url != NULL) { if (url->url->protocol == PROTOCOL_MAILTO) { - gchar *tmp = g_malloc(url->url->userlen + 1 + - url->url->hostlen); + char *tmp = g_malloc(url->url->userlen + 1 + + url->url->hostlen); if (url->url->userlen) { memcpy(tmp, url->url->string + url->url->usershift, url->url->userlen); } @@ -350,7 +350,7 @@ lua_url_tostring(lua_State *L) * Get URL suitable for HTTP request (e.g. by trimming fragment and user parts) * @return {string} url as a string */ -static gint +static int lua_url_to_http(lua_State *L) { LUA_TRACE_POINT; @@ -373,8 +373,8 @@ lua_url_to_http(lua_State *L) len--; } } - gchar *nstr = g_malloc(len); - gchar *d = nstr, *end = nstr + len; + char *nstr = g_malloc(len); + char *d = nstr, *end = nstr + len; memcpy(nstr, url->url->string, url->url->protocollen); d += url->url->protocollen; *d++ = ':'; @@ -433,7 +433,7 @@ lua_url_to_http(lua_State *L) * Get full content of the url as it was parsed (e.g. with urldecode) * @return {string} url string */ -static gint +static int lua_url_get_raw(lua_State *L) { LUA_TRACE_POINT; @@ -454,7 +454,7 @@ lua_url_get_raw(lua_State *L) * Check whether URL is treated as phished * @return {boolean} `true` if URL is phished */ -static gint +static int lua_url_is_phished(lua_State *L) { LUA_TRACE_POINT; @@ -475,7 +475,7 @@ lua_url_is_phished(lua_State *L) * Check whether URL was redirected * @return {boolean} `true` if URL is redirected */ -static gint +static int lua_url_is_redirected(lua_State *L) { LUA_TRACE_POINT; @@ -496,7 +496,7 @@ lua_url_is_redirected(lua_State *L) * Check whether URL is treated as obscured or obfuscated (e.g. numbers in IP address or other hacks) * @return {boolean} `true` if URL is obscured */ -static gint +static int lua_url_is_obscured(lua_State *L) { LUA_TRACE_POINT; @@ -518,7 +518,7 @@ lua_url_is_obscured(lua_State *L) * Check whether URL is just displayed in HTML (e.g. NOT a real href) * @return {boolean} `true` if URL is displayed only */ -static gint +static int lua_url_is_html_displayed(lua_State *L) { LUA_TRACE_POINT; @@ -539,7 +539,7 @@ lua_url_is_html_displayed(lua_State *L) * Check whether URL is found in subject * @return {boolean} `true` if URL is found in subject */ -static gint +static int lua_url_is_subject(lua_State *L) { LUA_TRACE_POINT; @@ -560,7 +560,7 @@ lua_url_is_subject(lua_State *L) * Get another URL that pretends to be this URL (e.g. used in phishing) * @return {url} phished URL */ -static gint +static int lua_url_get_phished(lua_State *L) { LUA_TRACE_POINT; @@ -591,7 +591,7 @@ lua_url_get_phished(lua_State *L) * @param {pool} pool memory pool to allocate memory if needed * @return {url} parsed redirected url (if needed) */ -static gint +static int lua_url_set_redirected(lua_State *L) { LUA_TRACE_POINT; @@ -615,7 +615,7 @@ lua_url_set_redirected(lua_State *L) } gsize len; - const gchar *urlstr = lua_tolstring(L, 2, &len); + const char *urlstr = lua_tolstring(L, 2, &len); rspamd_url_find_single(pool, urlstr, len, RSPAMD_URL_FIND_ALL, lua_url_single_inserter, L); @@ -666,7 +666,7 @@ lua_url_set_redirected(lua_State *L) * Get effective second level domain part (eSLD) of the url host * @return {string} effective second level domain part (eSLD) of the url host */ -static gint +static int lua_url_get_tld(lua_State *L) { LUA_TRACE_POINT; @@ -687,7 +687,7 @@ lua_url_get_tld(lua_State *L) * Get protocol name * @return {string} protocol as a string */ -static gint +static int lua_url_get_protocol(lua_State *L) { LUA_TRACE_POINT; @@ -708,7 +708,7 @@ lua_url_get_protocol(lua_State *L) * Return number of occurrences for this particular URL * @return {number} number of occurrences */ -static gint +static int lua_url_get_count(lua_State *L) { LUA_TRACE_POINT; @@ -729,7 +729,7 @@ lua_url_get_count(lua_State *L) * Get visible part of the url with html tags stripped * @return {string} url string */ -static gint +static int lua_url_get_visible(lua_State *L) { LUA_TRACE_POINT; @@ -757,7 +757,7 @@ lua_url_get_visible(lua_State *L) * - `protocol`: url protocol * @return {table} URL as a table */ -static gint +static int lua_url_to_table(lua_State *L) { LUA_TRACE_POINT; @@ -844,7 +844,7 @@ RSPAMD_DESTRUCTOR(rspamd_urls_static_pool_dtor) * @param {string} text that contains URL (can also contain other stuff) * @return {url} new url object that exists as long as the corresponding mempool exists */ -static gint +static int lua_url_create(lua_State *L) { LUA_TRACE_POINT; @@ -885,7 +885,7 @@ lua_url_create(lua_State *L) /* Add flags */ for (lua_pushnil(L); lua_next(L, 3); lua_pop(L, 1)) { int nmask = 0; - const gchar *fname = lua_tostring(L, -1); + const char *fname = lua_tostring(L, -1); if (rspamd_url_flag_from_string(fname, &nmask)) { u->url->flags |= nmask; @@ -906,10 +906,10 @@ lua_url_create(lua_State *L) * @param {string} tld_file path to effective_tld_names.dat file (public suffix list) * @return nothing */ -static gint +static int lua_url_init(lua_State *L) { - const gchar *tld_path; + const char *tld_path; tld_path = luaL_checkstring(L, 1); @@ -924,7 +924,7 @@ lua_url_table_inserter(struct rspamd_url *url, gsize start_offset, { lua_State *L = ud; struct rspamd_lua_url *lua_url; - gint n; + int n; n = rspamd_lua_table_size(L, -1); lua_url = lua_newuserdata(L, sizeof(struct rspamd_lua_url)); @@ -936,12 +936,12 @@ lua_url_table_inserter(struct rspamd_url *url, gsize start_offset, } -static gint +static int lua_url_all(lua_State *L) { LUA_TRACE_POINT; rspamd_mempool_t *pool = rspamd_lua_check_mempool(L, 1); - const gchar *text; + const char *text; size_t length; if (pool == NULL) { @@ -999,7 +999,7 @@ lua_url_all(lua_State *L) } \ } while (0) -static gint +static int lua_url_get_flags(lua_State *L) { LUA_TRACE_POINT; @@ -1011,7 +1011,7 @@ lua_url_get_flags(lua_State *L) lua_createtable(L, 0, 4); - for (gint i = 0; i < RSPAMD_URL_MAX_FLAG_SHIFT; i++) { + for (int i = 0; i < RSPAMD_URL_MAX_FLAG_SHIFT; i++) { PUSH_FLAG(1u << i); } } @@ -1024,7 +1024,7 @@ lua_url_get_flags(lua_State *L) #undef PUSH_FLAG -static gint +static int lua_url_get_flags_num(lua_State *L) { LUA_TRACE_POINT; @@ -1040,7 +1040,7 @@ lua_url_get_flags_num(lua_State *L) return 1; } -static gint +static int lua_url_get_order(lua_State *L) { LUA_TRACE_POINT; @@ -1061,7 +1061,7 @@ lua_url_get_order(lua_State *L) return 1; } -static gint +static int lua_url_get_part_order(lua_State *L) { LUA_TRACE_POINT; @@ -1113,7 +1113,7 @@ void lua_tree_url_callback(gpointer key, gpointer value, gpointer ud) } if (cb->skip_prob > 0) { - gdouble coin = rspamd_random_double_fast_seed(&cb->random_seed); + double coin = rspamd_random_double_fast_seed(&cb->random_seed); if (coin < cb->skip_prob) { return; @@ -1130,16 +1130,16 @@ void lua_tree_url_callback(gpointer key, gpointer value, gpointer ud) gboolean lua_url_cbdata_fill(lua_State *L, - gint pos, + int pos, struct lua_tree_cb_data *cbd, - guint default_protocols, - guint default_flags, + unsigned int default_protocols, + unsigned int default_flags, gsize max_urls) { - gint protocols_mask = 0; + int protocols_mask = 0; - gint pos_arg_type = lua_type(L, pos); - guint flags_mask = default_flags; + int pos_arg_type = lua_type(L, pos); + unsigned int flags_mask = default_flags; gboolean seen_flags = FALSE, seen_protocols = FALSE; memset(cbd, 0, sizeof(*cbd)); @@ -1157,11 +1157,11 @@ lua_url_cbdata_fill(lua_State *L, lua_getfield(L, pos, "flags"); if (lua_istable(L, -1)) { - gint top = lua_gettop(L); + int top = lua_gettop(L); lua_getfield(L, pos, "flags_mode"); if (lua_isstring(L, -1)) { - const gchar *mode_str = lua_tostring(L, -1); + const char *mode_str = lua_tostring(L, -1); if (strcmp(mode_str, "explicit") == 0) { cbd->flags_mode = url_flags_mode_include_explicit; @@ -1179,7 +1179,7 @@ lua_url_cbdata_fill(lua_State *L, if (lua_type(L, -1) == LUA_TSTRING) { - const gchar *fname = lua_tostring(L, -1); + const char *fname = lua_tostring(L, -1); if (rspamd_url_flag_from_string(fname, &nmask)) { @@ -1204,11 +1204,11 @@ lua_url_cbdata_fill(lua_State *L, lua_getfield(L, pos, "protocols"); if (lua_istable(L, -1)) { - gint top = lua_gettop(L); + int top = lua_gettop(L); for (lua_pushnil(L); lua_next(L, top); lua_pop(L, 1)) { int nmask; - const gchar *pname = lua_tostring(L, -1); + const char *pname = lua_tostring(L, -1); nmask = rspamd_url_protocol_from_string(pname); @@ -1285,7 +1285,7 @@ lua_url_cbdata_fill(lua_State *L, /* Plain table of the protocols */ for (lua_pushnil(L); lua_next(L, pos); lua_pop(L, 1)) { int nmask; - const gchar *pname = lua_tostring(L, -1); + const char *pname = lua_tostring(L, -1); nmask = rspamd_url_protocol_from_string(pname); @@ -1302,9 +1302,9 @@ lua_url_cbdata_fill(lua_State *L, lua_pop(L, 1); /* After rspamd_lua_geti */ } else if (pos_arg_type == LUA_TSTRING) { - const gchar *plist = lua_tostring(L, pos); - gchar **strvec; - gchar *const *cvec; + const char *plist = lua_tostring(L, pos); + char **strvec; + char *const *cvec; strvec = g_strsplit_set(plist, ",;", -1); cvec = strvec; @@ -1362,15 +1362,15 @@ lua_url_cbdata_fill(lua_State *L, gboolean lua_url_cbdata_fill_exclude_include(lua_State *L, - gint pos, + int pos, struct lua_tree_cb_data *cbd, - guint default_protocols, + unsigned int default_protocols, gsize max_urls) { - guint protocols_mask = default_protocols; - guint include_flags_mask, exclude_flags_mask; + unsigned int protocols_mask = default_protocols; + unsigned int include_flags_mask, exclude_flags_mask; - gint pos_arg_type = lua_type(L, pos); + int pos_arg_type = lua_type(L, pos); memset(cbd, 0, sizeof(*cbd)); cbd->flags_mode = url_flags_mode_exclude_include; @@ -1383,7 +1383,7 @@ lua_url_cbdata_fill_exclude_include(lua_State *L, int nmask = 0; if (lua_type(L, -1) == LUA_TSTRING) { - const gchar *fname = lua_tostring(L, -1); + const char *fname = lua_tostring(L, -1); if (rspamd_url_flag_from_string(fname, &nmask)) { include_flags_mask |= nmask; @@ -1416,7 +1416,7 @@ lua_url_cbdata_fill_exclude_include(lua_State *L, int nmask = 0; if (lua_type(L, -1) == LUA_TSTRING) { - const gchar *fname = lua_tostring(L, -1); + const char *fname = lua_tostring(L, -1); if (rspamd_url_flag_from_string(fname, &nmask)) { exclude_flags_mask |= nmask; @@ -1445,7 +1445,7 @@ lua_url_cbdata_fill_exclude_include(lua_State *L, for (lua_pushnil(L); lua_next(L, pos + 2); lua_pop(L, 1)) { int nmask; - const gchar *pname = lua_tostring(L, -1); + const char *pname = lua_tostring(L, -1); nmask = rspamd_url_protocol_from_string(pname); @@ -1486,12 +1486,12 @@ void lua_url_cbdata_dtor(struct lua_tree_cb_data *cbd) } gsize lua_url_adjust_skip_prob(float timestamp, - guchar digest[16], + unsigned char digest[16], struct lua_tree_cb_data *cb, gsize sz) { if (cb->max_urls > 0 && sz > cb->max_urls) { - cb->skip_prob = 1.0 - ((gdouble) cb->max_urls) / (gdouble) sz; + cb->skip_prob = 1.0 - ((double) cb->max_urls) / (double) sz; /* * Use task dependent probabilistic seed to ensure that * consequent task:get_urls return the same list of urls @@ -1506,7 +1506,7 @@ gsize lua_url_adjust_skip_prob(float timestamp, return sz; } -static gint +static int lua_url_eq(lua_State *L) { LUA_TRACE_POINT; @@ -1523,7 +1523,7 @@ lua_url_eq(lua_State *L) return 1; } -static gint +static int lua_url_lt(lua_State *L) { LUA_TRACE_POINT; @@ -1540,7 +1540,7 @@ lua_url_lt(lua_State *L) return 1; } -static gint +static int lua_load_url(lua_State *L) { lua_newtable(L); @@ -1549,7 +1549,7 @@ lua_load_url(lua_State *L) /* Push flags */ lua_createtable(L, 0, RSPAMD_URL_MAX_FLAG_SHIFT); for (int i = 0; i < RSPAMD_URL_MAX_FLAG_SHIFT; i++) { - guint flag = 1u << i; + unsigned int flag = 1u << i; lua_pushinteger(L, flag); lua_setfield(L, -2, rspamd_url_flag_to_string(flag)); diff --git a/src/lua/lua_url.h b/src/lua/lua_url.h index 930b4f553..3bb505994 100644 --- a/src/lua/lua_url.h +++ b/src/lua/lua_url.h @@ -26,9 +26,9 @@ struct lua_tree_cb_data { lua_State *L; int i; int metatable_pos; - guint flags_mask; - guint flags_exclude_mask; - guint protocols_mask; + unsigned int flags_mask; + unsigned int flags_exclude_mask; + unsigned int protocols_mask; enum { url_flags_mode_include_any, url_flags_mode_include_explicit, @@ -36,7 +36,7 @@ struct lua_tree_cb_data { } flags_mode; gboolean sort; gsize max_urls; - gdouble skip_prob; + double skip_prob; uint64_t random_seed; }; @@ -49,15 +49,15 @@ void lua_tree_url_callback(gpointer key, gpointer value, gpointer ud); * @param cbd * @return */ -gboolean lua_url_cbdata_fill(lua_State *L, gint pos, +gboolean lua_url_cbdata_fill(lua_State *L, int pos, struct lua_tree_cb_data *cbd, - guint default_protocols, - guint default_flags, + unsigned int default_protocols, + unsigned int default_flags, gsize max_urls); -gboolean lua_url_cbdata_fill_exclude_include(lua_State *L, gint pos, +gboolean lua_url_cbdata_fill_exclude_include(lua_State *L, int pos, struct lua_tree_cb_data *cbd, - guint default_protocols, + unsigned int default_protocols, gsize max_urls); /** @@ -76,7 +76,7 @@ void lua_url_cbdata_dtor(struct lua_tree_cb_data *cbd); * @return */ gsize lua_url_adjust_skip_prob(float timestamp, - guchar digest[16], + unsigned char digest[16], struct lua_tree_cb_data *cb, gsize sz); diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 11e45b723..3370a757d 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -761,7 +761,7 @@ static const struct luaL_reg ev_baselib_m[] = { {NULL, NULL}}; static int64_t -lua_check_int64(lua_State *L, gint pos) +lua_check_int64(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_int64_classname); luaL_argcheck(L, ud != NULL, pos, "'int64' expected"); @@ -769,7 +769,7 @@ lua_check_int64(lua_State *L, gint pos) } -static gint +static int lua_util_create_event_base(lua_State *L) { LUA_TRACE_POINT; @@ -782,12 +782,12 @@ lua_util_create_event_base(lua_State *L) return 1; } -static gint +static int lua_util_load_rspamd_config(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg, **pcfg; - const gchar *cfg_name; + const char *cfg_name; cfg_name = luaL_checkstring(L, 1); @@ -810,13 +810,13 @@ lua_util_load_rspamd_config(lua_State *L) return 1; } -static gint +static int parse_config_options(const char *str_options) { - gint ret = 0; - gchar **vec; - const gchar *str; - guint i, l; + int ret = 0; + char **vec; + const char *str; + unsigned int i, l; vec = g_strsplit_set(str_options, ",;", -1); if (vec) { @@ -853,7 +853,7 @@ parse_config_options(const char *str_options) return ret; } -static gint +static int lua_util_config_from_ucl(lua_State *L) { LUA_TRACE_POINT; @@ -862,7 +862,7 @@ lua_util_config_from_ucl(lua_State *L) GError *err = NULL; ucl_object_t *obj; const char *str_options = NULL; - gint int_options = 0; + int int_options = 0; obj = ucl_object_lua_import(L, 1); @@ -919,12 +919,12 @@ lua_util_task_fin(struct rspamd_task *task, void *ud) return TRUE; } -static gint +static int lua_util_process_message(lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config(L, 1); - const gchar *message; + const char *message; gsize mlen; struct rspamd_task *task; struct ev_loop *base; @@ -979,12 +979,12 @@ lua_util_process_message(lua_State *L) return 1; } -static gint +static int lua_util_encode_base64(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t; - gchar *out; + char *out; gsize outlen; long str_lim = 0; gboolean fold = FALSE; @@ -1008,7 +1008,7 @@ lua_util_encode_base64(lua_State *L) enum rspamd_newlines_type how = RSPAMD_TASK_NEWLINES_CRLF; if (lua_type(L, 3) == LUA_TSTRING) { - const gchar *how_str = lua_tostring(L, 3); + const char *how_str = lua_tostring(L, 3); if (g_ascii_strcasecmp(how_str, "cr") == 0) { how = RSPAMD_TASK_NEWLINES_CR; @@ -1035,15 +1035,15 @@ lua_util_encode_base64(lua_State *L) return 1; } -static gint +static int lua_util_encode_qp(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t; - const gchar *s = NULL; - gchar *out; + const char *s = NULL; + char *out; gsize inlen, outlen; - guint str_lim = 0; + unsigned int str_lim = 0; if (lua_type(L, 1) == LUA_TSTRING) { s = luaL_checklstring(L, 1, &inlen); @@ -1068,7 +1068,7 @@ lua_util_encode_qp(lua_State *L) enum rspamd_newlines_type how = RSPAMD_TASK_NEWLINES_CRLF; if (lua_type(L, 3) == LUA_TSTRING) { - const gchar *how_str = lua_tostring(L, 3); + const char *how_str = lua_tostring(L, 3); if (g_ascii_strcasecmp(how_str, "cr") == 0) { how = RSPAMD_TASK_NEWLINES_CR; @@ -1099,12 +1099,12 @@ lua_util_encode_qp(lua_State *L) return 1; } -static gint +static int lua_util_decode_qp(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t, *out; - const gchar *s = NULL; + const char *s = NULL; gsize inlen = 0; gssize outlen; @@ -1128,7 +1128,7 @@ lua_util_decode_qp(lua_State *L) rspamd_lua_setclass(L, rspamd_text_classname, -1); out->start = g_malloc(inlen + 1); out->flags = RSPAMD_TEXT_FLAG_OWN; - outlen = rspamd_decode_qp_buf(s, inlen, (gchar *) out->start, inlen + 1); + outlen = rspamd_decode_qp_buf(s, inlen, (char *) out->start, inlen + 1); if (outlen > 0) { out->len = outlen; @@ -1145,12 +1145,12 @@ lua_util_decode_qp(lua_State *L) return 1; } -static gint +static int lua_util_decode_base64(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t; - const gchar *s = NULL; + const char *s = NULL; gsize inlen = 0, outlen; if (lua_type(L, 1) == LUA_TSTRING) { @@ -1171,7 +1171,7 @@ lua_util_decode_base64(lua_State *L) t->len = (inlen / 4) * 3 + 3; t->start = g_malloc(t->len); - rspamd_cryptobox_base64_decode(s, inlen, (guchar *) t->start, + rspamd_cryptobox_base64_decode(s, inlen, (unsigned char *) t->start, &outlen); t->len = outlen; t->flags = RSPAMD_TEXT_FLAG_OWN; @@ -1183,13 +1183,13 @@ lua_util_decode_base64(lua_State *L) return 1; } -static gint +static int lua_util_encode_base32(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t; - const gchar *s = NULL; - gchar *out; + const char *s = NULL; + char *out; enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT; gsize inlen, outlen; @@ -1236,12 +1236,12 @@ lua_util_encode_base32(lua_State *L) return 1; } -static gint +static int lua_util_decode_base32(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t; - const gchar *s = NULL; + const char *s = NULL; gsize inlen, outlen; enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT; @@ -1266,14 +1266,14 @@ lua_util_decode_base32(lua_State *L) } if (s != NULL) { - guchar *decoded; + unsigned char *decoded; decoded = rspamd_decode_base32(s, inlen, &outlen, btype); if (decoded) { t = lua_newuserdata(L, sizeof(*t)); rspamd_lua_setclass(L, rspamd_text_classname, -1); - t->start = (const gchar *) decoded; + t->start = (const char *) decoded; t->len = outlen; t->flags = RSPAMD_TEXT_FLAG_OWN; } @@ -1288,7 +1288,7 @@ lua_util_decode_base32(lua_State *L) return 1; } -static gint +static int lua_util_decode_url(lua_State *L) { LUA_TRACE_POINT; @@ -1309,36 +1309,36 @@ lua_util_decode_url(lua_State *L) } -static gint +static int lua_util_tokenize_text(lua_State *L) { return lua_parsers_tokenize_text(L); } -static gint +static int lua_util_tanh(lua_State *L) { LUA_TRACE_POINT; - gdouble in = luaL_checknumber(L, 1); + double in = luaL_checknumber(L, 1); lua_pushnumber(L, tanh(in)); return 1; } -static gint +static int lua_util_parse_html(lua_State *L) { return lua_parsers_parse_html(L); } -static gint +static int lua_util_levenshtein_distance(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t1, *t2; - gint dist = 0; - guint replace_cost = 1; + int dist = 0; + unsigned int replace_cost = 1; t1 = lua_check_text_or_string(L, 1); t2 = lua_check_text_or_string(L, 2); @@ -1359,11 +1359,11 @@ lua_util_levenshtein_distance(lua_State *L) return 1; } -static gint +static int lua_util_fold_header(lua_State *L) { LUA_TRACE_POINT; - const gchar *how, *stop_chars = NULL; + const char *how, *stop_chars = NULL; struct rspamd_lua_text *name, *value; GString *folded; @@ -1415,13 +1415,13 @@ lua_util_fold_header(lua_State *L) return 1; } -static gint +static int lua_util_is_uppercase(lua_State *L) { LUA_TRACE_POINT; int32_t i = 0; UChar32 uc; - guint nlc = 0, nuc = 0; + unsigned int nlc = 0, nuc = 0; struct rspamd_lua_text *t = lua_check_text_or_string(L, 1); if (t) { @@ -1451,12 +1451,12 @@ lua_util_is_uppercase(lua_State *L) return 1; } -static gint +static int lua_util_humanize_number(lua_State *L) { LUA_TRACE_POINT; int64_t number = luaL_checkinteger(L, 1); - gchar numbuf[32]; + char numbuf[32]; rspamd_snprintf(numbuf, sizeof(numbuf), "%hL", number); @@ -1465,11 +1465,11 @@ lua_util_humanize_number(lua_State *L) return 1; } -static gint +static int lua_util_get_tld(lua_State *L) { LUA_TRACE_POINT; - const gchar *host; + const char *host; gsize hostlen; rspamd_ftok_t tld; @@ -1491,13 +1491,13 @@ lua_util_get_tld(lua_State *L) } -static gint +static int lua_util_glob(lua_State *L) { LUA_TRACE_POINT; - const gchar *pattern; + const char *pattern; glob_t gl; - gint top, i, flags = 0; + int top, i, flags = 0; top = lua_gettop(L); memset(&gl, 0, sizeof(gl)); @@ -1518,7 +1518,7 @@ lua_util_glob(lua_State *L) lua_createtable(L, gl.gl_pathc, 0); /* Push results */ - for (i = 0; i < (gint) gl.gl_pathc; i++) { + for (i = 0; i < (int) gl.gl_pathc; i++) { lua_pushstring(L, gl.gl_pathv[i]); lua_rawseti(L, -2, i + 1); } @@ -1528,13 +1528,13 @@ lua_util_glob(lua_State *L) return 1; } -static gint +static int lua_util_parse_mail_address(lua_State *L) { return lua_parsers_parse_mail_address(L); } -static gint +static int lua_util_strlen_utf8(lua_State *L) { LUA_TRACE_POINT; @@ -1547,7 +1547,7 @@ lua_util_strlen_utf8(lua_State *L) UChar32 uc; while (i < t->len) { - U8_NEXT((guint8 *) t->start, i, t->len, uc); + U8_NEXT((uint8_t *) t->start, i, t->len, uc); nchars++; } @@ -1560,13 +1560,13 @@ lua_util_strlen_utf8(lua_State *L) return 1; } -static gint +static int lua_util_lower_utf8(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t; - gchar *dst; + char *dst; UChar32 uc; UBool err = 0; int32_t i = 0, j = 0; @@ -1577,7 +1577,7 @@ lua_util_lower_utf8(lua_State *L) dst = g_malloc(t->len); while (i < t->len && err == 0) { - U8_NEXT((guint8 *) t->start, i, t->len, uc); + U8_NEXT((uint8_t *) t->start, i, t->len, uc); uc = u_tolower(uc); U8_APPEND(dst, j, t->len, uc, err); } @@ -1599,7 +1599,7 @@ lua_util_lower_utf8(lua_State *L) return 1; } -static gint +static int lua_util_normalize_utf8(lua_State *L) { LUA_TRACE_POINT; @@ -1632,7 +1632,7 @@ lua_util_normalize_utf8(lua_State *L) return 2; } -static gint +static int lua_util_transliterate(lua_State *L) { LUA_TRACE_POINT; @@ -1650,12 +1650,12 @@ lua_util_transliterate(lua_State *L) return 1; } -static gint +static int lua_util_strequal_caseless(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t1, *t2; - gint ret = -1; + int ret = -1; t1 = lua_check_text_or_string(L, 1); t2 = lua_check_text_or_string(L, 2); @@ -1677,12 +1677,12 @@ lua_util_strequal_caseless(lua_State *L) return 1; } -static gint +static int lua_util_strequal_caseless_utf8(lua_State *L) { LUA_TRACE_POINT; struct rspamd_lua_text *t1, *t2; - gint ret = -1; + int ret = -1; t1 = lua_check_text_or_string(L, 1); t2 = lua_check_text_or_string(L, 2); @@ -1699,11 +1699,11 @@ lua_util_strequal_caseless_utf8(lua_State *L) return 1; } -static gint +static int lua_util_get_ticks(lua_State *L) { LUA_TRACE_POINT; - gdouble ticks; + double ticks; gboolean rdtsc = FALSE; if (lua_isboolean(L, 1)) { @@ -1716,7 +1716,7 @@ lua_util_get_ticks(lua_State *L) return 1; } -static gint +static int lua_util_get_time(lua_State *L) { LUA_TRACE_POINT; @@ -1726,11 +1726,11 @@ lua_util_get_time(lua_State *L) return 1; } -static gint +static int lua_util_time_to_string(lua_State *L) { LUA_TRACE_POINT; - gdouble seconds; + double seconds; char timebuf[128]; if (lua_isnumber(L, 1)) { @@ -1746,11 +1746,11 @@ lua_util_time_to_string(lua_State *L) return 1; } -static gint +static int lua_util_stat(lua_State *L) { LUA_TRACE_POINT; - const gchar *fpath; + const char *fpath; struct stat st; fpath = luaL_checkstring(L, 1); @@ -1792,12 +1792,12 @@ lua_util_stat(lua_State *L) return 2; } -static gint +static int lua_util_unlink(lua_State *L) { LUA_TRACE_POINT; - const gchar *fpath; - gint ret; + const char *fpath; + int ret; fpath = luaL_checkstring(L, 1); @@ -1820,12 +1820,12 @@ lua_util_unlink(lua_State *L) return 1; } -static gint +static int lua_util_lock_file(lua_State *L) { LUA_TRACE_POINT; - const gchar *fpath; - gint fd = -1; + const char *fpath; + int fd = -1; gboolean own = FALSE; #if !HAVE_FLOCK @@ -1878,11 +1878,11 @@ lua_util_lock_file(lua_State *L) return 1; } -static gint +static int lua_util_unlock_file(lua_State *L) { LUA_TRACE_POINT; - gint fd = -1, ret, serrno; + int fd = -1, ret, serrno; gboolean do_close = TRUE; #if !HAVE_FLOCK @@ -1928,12 +1928,12 @@ lua_util_unlock_file(lua_State *L) return 1; } -static gint +static int lua_util_create_file(lua_State *L) { LUA_TRACE_POINT; - gint fd, mode = 00644; - const gchar *fpath; + int fd, mode = 00644; + const char *fpath; fpath = luaL_checkstring(L, 1); @@ -1960,11 +1960,11 @@ lua_util_create_file(lua_State *L) return 1; } -static gint +static int lua_util_close_file(lua_State *L) { LUA_TRACE_POINT; - gint fd = -1; + int fd = -1; if (lua_isnumber(L, 1)) { fd = lua_tointeger(L, 1); @@ -1985,12 +1985,12 @@ lua_util_close_file(lua_State *L) return 1; } -static gint +static int lua_util_random_hex(lua_State *L) { LUA_TRACE_POINT; - gchar *buf; - gint buflen; + char *buf; + int buflen; buflen = lua_tointeger(L, 1); @@ -2006,41 +2006,41 @@ lua_util_random_hex(lua_State *L) return 1; } -static gint +static int lua_util_zstd_compress(lua_State *L) { return lua_compress_zstd_compress(L); } -static gint +static int lua_util_zstd_decompress(lua_State *L) { return lua_compress_zstd_decompress(L); } -static gint +static int lua_util_gzip_compress(lua_State *L) { return lua_compress_zlib_compress(L); } -static gint +static int lua_util_gzip_decompress(lua_State *L) { return lua_compress_zlib_decompress(L, true); } -static gint +static int lua_util_inflate(lua_State *L) { return lua_compress_zlib_decompress(L, false); } -static gint +static int lua_util_normalize_prob(lua_State *L) { LUA_TRACE_POINT; - gdouble x, bias = 0.5; + double x, bias = 0.5; x = lua_tonumber(L, 1); @@ -2053,7 +2053,7 @@ lua_util_normalize_prob(lua_State *L) return 1; } -static gint +static int lua_util_caseless_hash(lua_State *L) { LUA_TRACE_POINT; @@ -2082,7 +2082,7 @@ lua_util_caseless_hash(lua_State *L) return 1; } -static gint +static int lua_util_caseless_hash_fast(lua_State *L) { LUA_TRACE_POINT; @@ -2118,14 +2118,14 @@ lua_util_caseless_hash_fast(lua_State *L) return 1; } -static gint +static int lua_util_is_utf_spoofed(lua_State *L) { LUA_TRACE_POINT; gsize l1, l2; - gint ret, nres = 2; - const gchar *s1 = lua_tolstring(L, 1, &l1), - *s2 = lua_tolstring(L, 2, &l2); + int ret, nres = 2; + const char *s1 = lua_tolstring(L, 1, &l1), + *s2 = lua_tolstring(L, 2, &l2); static USpoofChecker *spc, *spc_sgl; UErrorCode uc_err = U_ZERO_ERROR; @@ -2195,12 +2195,12 @@ lua_util_is_utf_spoofed(lua_State *L) return nres; } -static gint +static int lua_util_is_utf_mixed_script(lua_State *L) { LUA_TRACE_POINT; gsize len_of_string; - const guchar *string_to_check = lua_tolstring(L, 1, &len_of_string); + const unsigned char *string_to_check = lua_tolstring(L, 1, &len_of_string); UScriptCode last_script_code = USCRIPT_INVALID_CODE; UErrorCode uc_err = U_ZERO_ERROR; @@ -2250,17 +2250,17 @@ lua_util_is_utf_mixed_script(lua_State *L) return 1; } -static gint +static int lua_util_get_string_stats(lua_State *L) { LUA_TRACE_POINT; - gint num_of_digits = 0, num_of_letters = 0; + int num_of_digits = 0, num_of_letters = 0; struct rspamd_lua_text *t; t = lua_check_text_or_string(L, 1); if (t) { - const gchar *p = t->start, *end = t->start + t->len; + const char *p = t->start, *end = t->start + t->len; while (p < end) { if (g_ascii_isdigit(*p)) { num_of_digits++; @@ -2287,11 +2287,11 @@ lua_util_get_string_stats(lua_State *L) } -static gint +static int lua_util_is_utf_outside_range(lua_State *L) { LUA_TRACE_POINT; - gint ret; + int ret; struct rspamd_lua_text *t = lua_check_text_or_string(L, 1); uint32_t range_start = lua_tointeger(L, 2); uint32_t range_end = lua_tointeger(L, 3); @@ -2358,11 +2358,11 @@ lua_util_is_utf_outside_range(lua_State *L) } -static gint +static int lua_util_get_hostname(lua_State *L) { LUA_TRACE_POINT; - gchar *hostbuf; + char *hostbuf; gsize hostlen; hostlen = sysconf(_SC_HOST_NAME_MAX); @@ -2383,20 +2383,20 @@ lua_util_get_hostname(lua_State *L) return 1; } -static gint +static int lua_util_parse_content_type(lua_State *L) { return lua_parsers_parse_content_type(L); } -static gint +static int lua_util_mime_header_encode(lua_State *L) { LUA_TRACE_POINT; gsize len; - const gchar *hdr = luaL_checklstring(L, 1, &len); - gchar *encoded; + const char *hdr = luaL_checklstring(L, 1, &len); + char *encoded; if (!hdr) { return luaL_error(L, "invalid arguments"); @@ -2409,7 +2409,7 @@ lua_util_mime_header_encode(lua_State *L) return 1; } -static gint +static int lua_util_is_valid_utf8(lua_State *L) { LUA_TRACE_POINT; @@ -2435,7 +2435,7 @@ lua_util_is_valid_utf8(lua_State *L) return 1; } -static gint +static int lua_util_has_obscured_unicode(lua_State *L) { LUA_TRACE_POINT; @@ -2464,12 +2464,12 @@ lua_util_has_obscured_unicode(lua_State *L) return 1; } -static gint +static int lua_util_readline(lua_State *L) { LUA_TRACE_POINT; - const gchar *prompt = ""; - gchar *input = NULL; + const char *prompt = ""; + char *input = NULL; if (lua_type(L, 1) == LUA_TSTRING) { prompt = lua_tostring(L, 1); @@ -2483,7 +2483,7 @@ lua_util_readline(lua_State *L) replxx_history_add(rx_instance, ""); } - input = (gchar *) replxx_input(rx_instance, prompt); + input = (char *) replxx_input(rx_instance, prompt); if (input) { lua_pushstring(L, input); @@ -2515,11 +2515,11 @@ lua_util_readline(lua_State *L) return 1; } -static gint +static int lua_util_readpassphrase(lua_State *L) { LUA_TRACE_POINT; - gchar test_password[8192]; + char test_password[8192]; gsize r; r = rspamd_read_passphrase(test_password, sizeof(test_password), 0, NULL); @@ -2537,12 +2537,12 @@ lua_util_readpassphrase(lua_State *L) return 1; } -static gint +static int lua_util_file_exists(lua_State *L) { LUA_TRACE_POINT; - const gchar *fname = luaL_checkstring(L, 1); - gint serrno; + const char *fname = luaL_checkstring(L, 1); + int serrno; if (fname) { if (access(fname, R_OK) == -1) { @@ -2562,13 +2562,13 @@ lua_util_file_exists(lua_State *L) return 2; } -static gint +static int lua_util_mkdir(lua_State *L) { LUA_TRACE_POINT; - const gchar *dname = luaL_checkstring(L, 1); + const char *dname = luaL_checkstring(L, 1); gboolean recursive = FALSE; - gint r = -1; + int r = -1; if (dname) { if (lua_isboolean(L, 2)) { @@ -2626,14 +2626,14 @@ lua_util_mkdir(lua_State *L) } -static gint +static int lua_util_umask(lua_State *L) { LUA_TRACE_POINT; mode_t mask = 0, old; if (lua_type(L, 1) == LUA_TSTRING) { - const gchar *str = lua_tostring(L, 1); + const char *str = lua_tostring(L, 1); if (str[0] == '0') { /* e.g. '022' */ @@ -2658,7 +2658,7 @@ lua_util_umask(lua_State *L) return 1; } -static gint +static int lua_util_isatty(lua_State *L) { LUA_TRACE_POINT; @@ -3418,7 +3418,7 @@ lua_util_btc_polymod(lua_State *L) } for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) { - guint8 c0 = c >> 35; + uint8_t c0 = c >> 35; uint64_t d = lua_tointeger(L, -1); c = ((c & 0x07ffffffff) << 5) ^ d; @@ -3447,7 +3447,7 @@ lua_util_parse_smtp_date(lua_State *L) } -static gint +static int lua_load_util(lua_State *L) { lua_newtable(L); @@ -3456,7 +3456,7 @@ lua_load_util(lua_State *L) return 1; } -static gint +static int lua_load_int64(lua_State *L) { lua_newtable(L); @@ -3480,7 +3480,7 @@ static int lua_int64_tostring(lua_State *L) { int64_t n = lua_check_int64(L, 1); - gchar buf[32]; + char buf[32]; bool is_signed = false; if (lua_isboolean(L, 2)) { @@ -3547,7 +3547,7 @@ static int lua_int64_tonumber(lua_State *L) { int64_t n = lua_check_int64(L, 1); - gdouble d; + double d; d = n; lua_pushinteger(L, d); @@ -3559,7 +3559,7 @@ static int lua_int64_hex(lua_State *L) { int64_t n = lua_check_int64(L, 1); - gchar buf[32]; + char buf[32]; rspamd_snprintf(buf, sizeof(buf), "%XL", n); lua_pushstring(L, buf); diff --git a/src/lua/lua_worker.c b/src/lua/lua_worker.c index 2b9856b08..b18e9e515 100644 --- a/src/lua/lua_worker.c +++ b/src/lua/lua_worker.c @@ -61,14 +61,14 @@ const luaL_reg worker_reg[] = { {NULL, NULL}}; static struct rspamd_worker * -lua_check_worker(lua_State *L, gint pos) +lua_check_worker(lua_State *L, int pos) { void *ud = rspamd_lua_check_udata(L, pos, rspamd_worker_classname); luaL_argcheck(L, ud != NULL, pos, "'worker' expected"); return ud ? *((struct rspamd_worker **) ud) : NULL; } -static gint +static int lua_worker_get_stat(lua_State *L) { struct rspamd_worker *w = lua_check_worker(L, 1); @@ -77,7 +77,7 @@ lua_worker_get_stat(lua_State *L) rspamd_mempool_stat_t mem_st; struct rspamd_stat *stat, stat_copy; ucl_object_t *top, *sub; - gint i; + int i; uint64_t spam = 0, ham = 0; memset(&mem_st, 0, sizeof(mem_st)); @@ -150,7 +150,7 @@ lua_worker_get_stat(lua_State *L) return 1; } -static gint +static int lua_worker_get_name(lua_State *L) { struct rspamd_worker *w = lua_check_worker(L, 1); @@ -165,7 +165,7 @@ lua_worker_get_name(lua_State *L) return 1; } -static gint +static int lua_worker_get_index(lua_State *L) { struct rspamd_worker *w = lua_check_worker(L, 1); @@ -180,7 +180,7 @@ lua_worker_get_index(lua_State *L) return 1; } -static gint +static int lua_worker_get_count(lua_State *L) { struct rspamd_worker *w = lua_check_worker(L, 1); @@ -195,7 +195,7 @@ lua_worker_get_count(lua_State *L) return 1; } -static gint +static int lua_worker_get_pid(lua_State *L) { struct rspamd_worker *w = lua_check_worker(L, 1); @@ -211,7 +211,7 @@ lua_worker_get_pid(lua_State *L) } -static gint +static int lua_worker_is_scanner(lua_State *L) { struct rspamd_worker *w = lua_check_worker(L, 1); @@ -226,7 +226,7 @@ lua_worker_is_scanner(lua_State *L) return 1; } -static gint +static int lua_worker_is_primary_controller(lua_State *L) { struct rspamd_worker *w = lua_check_worker(L, 1); @@ -249,8 +249,8 @@ struct rspamd_control_cbdata { struct ev_loop *event_loop; struct rspamd_async_session *session; enum rspamd_control_type cmd; - gint cbref; - gint fd; + int cbref; + int fd; }; static gboolean @@ -284,8 +284,8 @@ lua_worker_control_session_dtor(void *ud) static gboolean lua_worker_control_handler(struct rspamd_main *rspamd_main, struct rspamd_worker *worker, - gint fd, - gint attached_fd, + int fd, + int attached_fd, struct rspamd_control_command *cmd, gpointer ud) { @@ -293,7 +293,7 @@ lua_worker_control_handler(struct rspamd_main *rspamd_main, struct rspamd_control_cbdata *cbd = (struct rspamd_control_cbdata *) ud; rspamd_mempool_t *pool; lua_State *L; - gint err_idx, status; + int err_idx, status; L = cbd->L; pool = cbd->pool; @@ -403,13 +403,13 @@ lua_worker_control_handler(struct rspamd_main *rspamd_main, return TRUE; } -static gint +static int lua_worker_add_control_handler(lua_State *L) { struct rspamd_worker *w = lua_check_worker(L, 1); struct rspamd_config *cfg = lua_check_config(L, 2); struct ev_loop *event_loop = lua_check_ev_base(L, 3); - const gchar *cmd_name = luaL_checkstring(L, 4); + const char *cmd_name = luaL_checkstring(L, 4); enum rspamd_control_type cmd; struct rspamd_control_cbdata *cbd; @@ -454,7 +454,7 @@ lua_worker_jemalloc_stats_cb(void *ud, const char *msg) } #endif -static gint +static int lua_worker_get_mem_stats(lua_State *L) { struct rspamd_worker *w = lua_check_worker(L, 1); @@ -474,9 +474,9 @@ lua_worker_get_mem_stats(lua_State *L) } struct rspamd_lua_process_cbdata { - gint sp[2]; - gint func_cbref; - gint cb_cbref; + int sp[2]; + int func_cbref; + int cb_cbref; gboolean replied; gboolean is_error; pid_t cpid; @@ -494,7 +494,7 @@ static void rspamd_lua_execute_lua_subprocess(lua_State *L, struct rspamd_lua_process_cbdata *cbdata) { - gint err_idx, r; + int err_idx, r; uint64_t wlen = 0; lua_pushcfunction(L, &rspamd_lua_traceback); @@ -503,7 +503,7 @@ rspamd_lua_execute_lua_subprocess(lua_State *L, lua_rawgeti(L, LUA_REGISTRYINDEX, cbdata->func_cbref); if (lua_pcall(L, 0, 1, err_idx) != 0) { - const gchar *s = lua_tostring(L, -1); + const char *s = lua_tostring(L, -1); gsize slen = strlen(s); msg_err("call to subprocess failed: %s", s); @@ -549,10 +549,10 @@ rspamd_lua_execute_lua_subprocess(lua_State *L, static void rspamd_lua_call_on_complete(lua_State *L, struct rspamd_lua_process_cbdata *cbdata, - const gchar *err_msg, - const gchar *data, gsize datalen) + const char *err_msg, + const char *data, gsize datalen) { - gint err_idx; + int err_idx; lua_pushcfunction(L, &rspamd_lua_traceback); err_idx = lua_gettop(L); @@ -588,7 +588,7 @@ rspamd_lua_cld_handler(struct rspamd_worker_signal_handler *sigh, void *ud) struct rspamd_srv_command srv_cmd; lua_State *L; pid_t died; - gint res = 0; + int res = 0; /* Are we called by a correct children ? */ died = waitpid(cbdata->cpid, &res, WNOHANG); @@ -673,7 +673,7 @@ rspamd_lua_subprocess_io(EV_P_ ev_io *w, int revents) cbdata->io_buf->len += r; if (cbdata->io_buf->len == sizeof(uint64_t)) { - memcpy((guchar *) &sz, cbdata->io_buf->str, sizeof(sz)); + memcpy((unsigned char *) &sz, cbdata->io_buf->str, sizeof(sz)); if (sz & (1ULL << 63)) { cbdata->is_error = TRUE; @@ -718,7 +718,7 @@ rspamd_lua_subprocess_io(EV_P_ ev_io *w, int revents) cbdata->io_buf->len += r; if (cbdata->io_buf->len == cbdata->sz) { - gchar rep[4]; + char rep[4]; ev_io_stop(cbdata->event_loop, &cbdata->ev); /* Finished reading data */ @@ -742,18 +742,18 @@ rspamd_lua_subprocess_io(EV_P_ ev_io *w, int revents) } } -static gint +static int lua_worker_spawn_process(lua_State *L) { struct rspamd_worker *w = lua_check_worker(L, 1); struct rspamd_lua_process_cbdata *cbdata; struct rspamd_abstract_worker_ctx *actx; struct rspamd_srv_command srv_cmd; - const gchar *cmdline = NULL, *input = NULL, *proctitle = NULL; + const char *cmdline = NULL, *input = NULL, *proctitle = NULL; gsize inputlen = 0; pid_t pid; GError *err = NULL; - gint func_cbref, cb_cbref; + int func_cbref, cb_cbref; if (!rspamd_lua_parse_table_arguments(L, 2, &err, RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, @@ -806,8 +806,8 @@ lua_worker_spawn_process(lua_State *L) } else if (pid == 0) { /* Child */ - gint rc; - gchar inbuf[4]; + int rc; + char inbuf[4]; rspamd_log_on_fork(w->cf->type, w->srv->cfg, w->srv->logger); rc = ottery_init(w->srv->cfg->libs_ctx->ottery_cfg); diff --git a/src/lua/lua_xmlrpc.c b/src/lua/lua_xmlrpc.c index efb2b22e6..67e8840d5 100644 --- a/src/lua/lua_xmlrpc.c +++ b/src/lua/lua_xmlrpc.c @@ -60,26 +60,26 @@ enum lua_xmlrpc_stack { struct lua_xmlrpc_ud { enum lua_xmlrpc_state parser_state; GQueue *st; - gint param_count; + int param_count; gboolean got_text; lua_State *L; }; static void xmlrpc_start_element(GMarkupParseContext *context, - const gchar *name, - const gchar **attribute_names, - const gchar **attribute_values, + const char *name, + const char **attribute_names, + const char **attribute_values, gpointer user_data, GError **error); static void xmlrpc_end_element(GMarkupParseContext *context, - const gchar *element_name, + const char *element_name, gpointer user_data, GError **error); static void xmlrpc_error(GMarkupParseContext *context, GError *error, gpointer user_data); static void xmlrpc_text(GMarkupParseContext *context, - const gchar *text, + const char *text, gsize text_len, gpointer user_data, GError **error); @@ -100,9 +100,9 @@ xmlrpc_error_quark(void) static void xmlrpc_start_element(GMarkupParseContext *context, - const gchar *name, - const gchar **attribute_names, - const gchar **attribute_values, + const char *name, + const char **attribute_names, + const char **attribute_values, gpointer user_data, GError **error) { @@ -328,7 +328,7 @@ xmlrpc_start_element(GMarkupParseContext *context, static void xmlrpc_end_element(GMarkupParseContext *context, - const gchar *name, + const char *name, gpointer user_data, GError **error) { @@ -521,7 +521,7 @@ xmlrpc_end_element(GMarkupParseContext *context, case read_array_element: /* Got tag value */ if (g_ascii_strcasecmp(name, "value") == 0) { - guint tbl_len = rspamd_lua_table_size(ud->L, -2); + unsigned int tbl_len = rspamd_lua_table_size(ud->L, -2); lua_rawseti(ud->L, -2, tbl_len + 1); msg_debug_xmlrpc("set array element idx: %d", tbl_len + 1); ud->parser_state = read_array_value; @@ -547,14 +547,14 @@ xmlrpc_end_element(GMarkupParseContext *context, static void xmlrpc_text(GMarkupParseContext *context, - const gchar *text, + const char *text, gsize text_len, gpointer user_data, GError **error) { struct lua_xmlrpc_ud *ud = user_data; gulong num; - gdouble dnum; + double dnum; /* Strip line */ while (text_len > 0 && g_ascii_isspace(*text)) { @@ -599,11 +599,11 @@ xmlrpc_error(GMarkupParseContext *context, GError *error, gpointer user_data) msg_err("xmlrpc parser error: %s", error->message); } -static gint +static int lua_xmlrpc_parse_reply(lua_State *L) { LUA_TRACE_POINT; - const gchar *data; + const char *data; GMarkupParseContext *ctx; GError *err = NULL; struct lua_xmlrpc_ud ud; @@ -635,14 +635,14 @@ lua_xmlrpc_parse_reply(lua_State *L) return 1; } -static gint +static int lua_xmlrpc_parse_table(lua_State *L, - gint pos, - gchar *databuf, - gint pr, + int pos, + char *databuf, + int pr, gsize size) { - gint r = pr, num; + int r = pr, num; double dnum; r += rspamd_snprintf(databuf + r, size - r, ""); @@ -705,13 +705,13 @@ lua_xmlrpc_parse_table(lua_State *L, * Internal limitation: xmlrpc request must NOT be more than * BUFSIZ * 2 (16384 bytes) */ -static gint +static int lua_xmlrpc_make_request(lua_State *L) { LUA_TRACE_POINT; - gchar databuf[BUFSIZ * 2]; - const gchar *func; - gint r, top, i, num; + char databuf[BUFSIZ * 2]; + const char *func; + int r, top, i, num; double dnum; func = luaL_checkstring(L, 1); @@ -781,7 +781,7 @@ lua_xmlrpc_make_request(lua_State *L) return 1; } -static gint +static int lua_load_xmlrpc(lua_State *L) { lua_newtable(L); diff --git a/src/plugins/chartable.cxx b/src/plugins/chartable.cxx index 172242ba3..a5c7cb899 100644 --- a/src/plugins/chartable.cxx +++ b/src/plugins/chartable.cxx @@ -45,11 +45,11 @@ INIT_LOG_MODULE(chartable) /* Initialization */ -gint chartable_module_init(struct rspamd_config *cfg, struct module_ctx **ctx); +int chartable_module_init(struct rspamd_config *cfg, struct module_ctx **ctx); -gint chartable_module_config(struct rspamd_config *cfg, bool validate); +int chartable_module_config(struct rspamd_config *cfg, bool validate); -gint chartable_module_reconfig(struct rspamd_config *cfg); +int chartable_module_reconfig(struct rspamd_config *cfg); module_t chartable_module = { "chartable", @@ -58,15 +58,15 @@ module_t chartable_module = { chartable_module_reconfig, nullptr, RSPAMD_MODULE_VER, - (guint) -1, + (unsigned int) -1, }; struct chartable_ctx { struct module_ctx ctx; - const gchar *symbol; - const gchar *url_symbol; + const char *symbol; + const char *url_symbol; double threshold; - guint max_word_len; + unsigned int max_word_len; }; static inline struct chartable_ctx * @@ -84,7 +84,7 @@ static void chartable_url_symbol_callback(struct rspamd_task *task, struct rspamd_symcache_dynamic_item *item, void *unused); -gint chartable_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) +int chartable_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) { struct chartable_ctx *chartable_module_ctx; @@ -98,10 +98,10 @@ gint chartable_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) } -gint chartable_module_config(struct rspamd_config *cfg, bool _) +int chartable_module_config(struct rspamd_config *cfg, bool _) { const ucl_object_t *value; - gint res = TRUE; + int res = TRUE; struct chartable_ctx *chartable_module_ctx = chartable_get_context(cfg); if (!rspamd_config_is_module_enabled(cfg, "chartable")) { @@ -160,7 +160,7 @@ gint chartable_module_config(struct rspamd_config *cfg, bool _) return res; } -gint chartable_module_reconfig(struct rspamd_config *cfg) +int chartable_module_reconfig(struct rspamd_config *cfg) { return chartable_module_config(cfg, false); } @@ -1689,26 +1689,26 @@ static const auto latin_confusable = ankerl::unordered_dense::set{ }; static gboolean -rspamd_can_alias_latin(gint ch) +rspamd_can_alias_latin(int ch) { return latin_confusable.contains(ch); } -static gdouble +static double rspamd_chartable_process_word_utf(struct rspamd_task *task, rspamd_stat_token_t *w, gboolean is_url, - guint *ncap, + unsigned int *ncap, struct chartable_ctx *chartable_module_ctx, gboolean ignore_diacritics) { const UChar32 *p, *end; - gdouble badness = 0.0; + double badness = 0.0; UChar32 uc; UBlockCode sc; - guint cat; - gint last_is_latin = -1; - guint same_script_count = 0, nsym = 0, nspecial = 0; + unsigned int cat; + int last_is_latin = -1; + unsigned int same_script_count = 0, nsym = 0, nspecial = 0; enum { start_process = 0, got_alpha, @@ -1773,7 +1773,7 @@ rspamd_chartable_process_word_utf(struct rspamd_task *task, if (sc != UBLOCK_BASIC_LATIN && last_is_latin) { if (rspamd_can_alias_latin(uc)) { - badness += 1.0 / (gdouble) same_script_count; + badness += 1.0 / (double) same_script_count; } last_is_latin = 0; @@ -1834,25 +1834,25 @@ rspamd_chartable_process_word_utf(struct rspamd_task *task, } msg_debug_chartable("word %*s, badness: %.2f", - (gint) w->normalized.len, w->normalized.begin, + (int) w->normalized.len, w->normalized.begin, badness); return badness; } -static gdouble +static double rspamd_chartable_process_word_ascii(struct rspamd_task *task, rspamd_stat_token_t *w, gboolean is_url, struct chartable_ctx *chartable_module_ctx) { - gdouble badness = 0.0; + double badness = 0.0; enum { ascii = 1, non_ascii } sc, last_sc; - gint same_script_count = 0, seen_alpha = FALSE; + int same_script_count = 0, seen_alpha = FALSE; enum { start_process = 0, got_alpha, @@ -1884,7 +1884,7 @@ rspamd_chartable_process_word_ascii(struct rspamd_task *task, if (same_script_count > 0) { if (sc != last_sc) { - badness += 1.0 / (gdouble) same_script_count; + badness += 1.0 / (double) same_script_count; last_sc = sc; same_script_count = 1; } @@ -1919,7 +1919,7 @@ rspamd_chartable_process_word_ascii(struct rspamd_task *task, } msg_debug_chartable("word %*s, badness: %.2f", - (gint) w->normalized.len, w->normalized.begin, + (int) w->normalized.len, w->normalized.begin, badness); return badness; @@ -1932,8 +1932,8 @@ rspamd_chartable_process_part(struct rspamd_task *task, gboolean ignore_diacritics) { rspamd_stat_token_t *w; - guint i, ncap = 0; - gdouble cur_score = 0.0; + unsigned int i, ncap = 0; + double cur_score = 0.0; if (part == nullptr || part->utf_words == nullptr || part->utf_words->len == 0 || part->nwords == 0) { @@ -1963,7 +1963,7 @@ rspamd_chartable_process_part(struct rspamd_task *task, */ part->capital_letters += ncap; - cur_score /= (gdouble) part->nwords; + cur_score /= (double) part->nwords; if (cur_score > 1.0) { cur_score = 1.0; @@ -1983,7 +1983,7 @@ chartable_symbol_callback(struct rspamd_task *task, struct rspamd_symcache_dynamic_item *item, void *_) { - guint i; + unsigned int i; struct rspamd_mime_text_part *part; struct chartable_ctx *chartable_module_ctx = chartable_get_context(task->cfg); gboolean ignore_diacritics = TRUE, seen_violated_part = FALSE; @@ -1993,7 +1993,7 @@ chartable_symbol_callback(struct rspamd_task *task, { if (part->languages && part->languages->len > 0) { auto *lang = (struct rspamd_lang_detector_res *) g_ptr_array_index(part->languages, 0); - gint flags; + int flags; flags = rspamd_language_detector_elt_flags(lang->elt); @@ -2017,7 +2017,7 @@ chartable_symbol_callback(struct rspamd_task *task, if (task->meta_words != nullptr && task->meta_words->len > 0) { rspamd_stat_token_t *w; - gdouble cur_score = 0; + double cur_score = 0; gsize arlen = task->meta_words->len; for (i = 0; i < arlen; i++) { @@ -2026,7 +2026,7 @@ chartable_symbol_callback(struct rspamd_task *task, nullptr, chartable_module_ctx, ignore_diacritics); } - cur_score /= (gdouble) (arlen + 1); + cur_score /= (double) (arlen + 1); if (cur_score > 1.0) { cur_score = 1.0; @@ -2059,7 +2059,7 @@ chartable_url_symbol_callback(struct rspamd_task *task, GHashTableIter it; gpointer k, v; rspamd_stat_token_t w; - gdouble cur_score = 0.0; + double cur_score = 0.0; struct chartable_ctx *chartable_module_ctx = chartable_get_context (task->cfg); g_hash_table_iter_init (&it, task->urls); diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index 1e1b13c73..b0340738e 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -51,39 +51,39 @@ #define DEFAULT_TIME_JITTER 60 #define DEFAULT_MAX_SIGS 5 -static const gchar *M = "rspamd dkim plugin"; - -static const gchar default_sign_headers[] = "" - "(o)from:(x)sender:(o)reply-to:(o)subject:(x)date:(x)message-id:" - "(o)to:(o)cc:(x)mime-version:(x)content-type:(x)content-transfer-encoding:" - "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:" - "(x)in-reply-to:(x)references:list-id:list-help:list-owner:list-unsubscribe:" - "list-unsubscribe-post:list-subscribe:list-post:(x)openpgp:(x)autocrypt"; -static const gchar default_arc_sign_headers[] = "" - "(o)from:(x)sender:(o)reply-to:(o)subject:(x)date:(x)message-id:" - "(o)to:(o)cc:(x)mime-version:(x)content-type:(x)content-transfer-encoding:" - "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:" - "(x)in-reply-to:(x)references:list-id:list-help:list-owner:list-unsubscribe:" - "list-unsubscribe-post:list-subscribe:list-post:dkim-signature:(x)openpgp:" - "(x)autocrypt"; +static const char *M = "rspamd dkim plugin"; + +static const char default_sign_headers[] = "" + "(o)from:(x)sender:(o)reply-to:(o)subject:(x)date:(x)message-id:" + "(o)to:(o)cc:(x)mime-version:(x)content-type:(x)content-transfer-encoding:" + "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:" + "(x)in-reply-to:(x)references:list-id:list-help:list-owner:list-unsubscribe:" + "list-unsubscribe-post:list-subscribe:list-post:(x)openpgp:(x)autocrypt"; +static const char default_arc_sign_headers[] = "" + "(o)from:(x)sender:(o)reply-to:(o)subject:(x)date:(x)message-id:" + "(o)to:(o)cc:(x)mime-version:(x)content-type:(x)content-transfer-encoding:" + "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:" + "(x)in-reply-to:(x)references:list-id:list-help:list-owner:list-unsubscribe:" + "list-unsubscribe-post:list-subscribe:list-post:dkim-signature:(x)openpgp:" + "(x)autocrypt"; struct dkim_ctx { struct module_ctx ctx; - const gchar *symbol_reject; - const gchar *symbol_tempfail; - const gchar *symbol_allow; - const gchar *symbol_na; - const gchar *symbol_permfail; + const char *symbol_reject; + const char *symbol_tempfail; + const char *symbol_allow; + const char *symbol_na; + const char *symbol_permfail; struct rspamd_radix_map_helper *whitelist_ip; struct rspamd_hash_map_helper *dkim_domains; - guint strict_multiplier; - guint time_jitter; + unsigned int strict_multiplier; + unsigned int time_jitter; rspamd_lru_hash_t *dkim_hash; rspamd_lru_hash_t *dkim_sign_hash; - const gchar *sign_headers; - const gchar *arc_sign_headers; - guint max_sigs; + const char *sign_headers; + const char *arc_sign_headers; + unsigned int max_sigs; gboolean trusted_only; gboolean check_local; gboolean check_authed; @@ -94,8 +94,8 @@ struct dkim_check_result { rspamd_dkim_key_t *key; struct rspamd_task *task; struct rspamd_dkim_check_result *res; - gdouble mult_allow; - gdouble mult_deny; + double mult_allow; + double mult_deny; struct rspamd_symcache_dynamic_item *item; struct dkim_check_result *next, *prev, *first; }; @@ -104,14 +104,14 @@ static void dkim_symbol_callback(struct rspamd_task *task, struct rspamd_symcache_dynamic_item *item, void *unused); -static gint lua_dkim_sign_handler(lua_State *L); -static gint lua_dkim_verify_handler(lua_State *L); -static gint lua_dkim_canonicalize_handler(lua_State *L); +static int lua_dkim_sign_handler(lua_State *L); +static int lua_dkim_verify_handler(lua_State *L); +static int lua_dkim_canonicalize_handler(lua_State *L); /* Initialization */ -gint dkim_module_init(struct rspamd_config *cfg, struct module_ctx **ctx); -gint dkim_module_config(struct rspamd_config *cfg, bool validate); -gint dkim_module_reconfig(struct rspamd_config *cfg); +int dkim_module_init(struct rspamd_config *cfg, struct module_ctx **ctx); +int dkim_module_config(struct rspamd_config *cfg, bool validate); +int dkim_module_reconfig(struct rspamd_config *cfg); module_t dkim_module = { "dkim", @@ -120,7 +120,7 @@ module_t dkim_module = { dkim_module_reconfig, NULL, RSPAMD_MODULE_VER, - (guint) -1, + (unsigned int) -1, }; static inline struct dkim_ctx * @@ -144,7 +144,7 @@ dkim_module_free_list(gpointer k) g_list_free_full((GList *) k, rspamd_gstring_free_hard); } -gint dkim_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) +int dkim_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) { struct dkim_ctx *dkim_module_ctx; @@ -304,11 +304,11 @@ gint dkim_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) return 0; } -gint dkim_module_config(struct rspamd_config *cfg, bool validate) +int dkim_module_config(struct rspamd_config *cfg, bool validate) { const ucl_object_t *value; - gint res = TRUE, cb_id = -1; - guint cache_size, sign_cache_size; + int res = TRUE, cb_id = -1; + unsigned int cache_size, sign_cache_size; gboolean got_trusted = FALSE; struct dkim_ctx *dkim_module_ctx = dkim_get_context(cfg); @@ -614,11 +614,11 @@ gint dkim_module_config(struct rspamd_config *cfg, bool validate) rspamd_dkim_sign_key_t * dkim_module_load_key_format(struct rspamd_task *task, struct dkim_ctx *dkim_module_ctx, - const gchar *key, gsize keylen, + const char *key, gsize keylen, enum rspamd_dkim_key_format key_format) { - guchar h[rspamd_cryptobox_HASHBYTES], + unsigned char h[rspamd_cryptobox_HASHBYTES], hex_hash[rspamd_cryptobox_HASHBYTES * 2 + 1]; rspamd_dkim_sign_key_t *ret = NULL; GError *err = NULL; @@ -691,7 +691,7 @@ dkim_module_load_key_format(struct rspamd_task *task, return ret; } -static gint +static int lua_dkim_sign_handler(lua_State *L) { struct rspamd_task *task = lua_check_task(L, 1); @@ -700,9 +700,9 @@ lua_dkim_sign_handler(lua_State *L) GError *err = NULL; GString *hdr; GList *sigs = NULL; - const gchar *selector = NULL, *domain = NULL, *key = NULL, *rawkey = NULL, - *headers = NULL, *sign_type_str = NULL, *arc_cv = NULL, - *pubkey = NULL; + const char *selector = NULL, *domain = NULL, *key = NULL, *rawkey = NULL, + *headers = NULL, *sign_type_str = NULL, *arc_cv = NULL, + *pubkey = NULL; rspamd_dkim_sign_context_t *ctx; rspamd_dkim_sign_key_t *dkim_key; gsize rawlen = 0, keylen = 0; @@ -895,7 +895,7 @@ lua_dkim_sign_handler(lua_State *L) return 2; } -gint dkim_module_reconfig(struct rspamd_config *cfg) +int dkim_module_reconfig(struct rspamd_config *cfg) { return dkim_module_config(cfg, false); } @@ -904,12 +904,12 @@ gint dkim_module_reconfig(struct rspamd_config *cfg) * Parse strict value for domain in format: 'reject_multiplier:deny_multiplier' */ static gboolean -dkim_module_parse_strict(const gchar *value, gdouble *allow, gdouble *deny) +dkim_module_parse_strict(const char *value, double *allow, double *deny) { - const gchar *colon; - gchar *err = NULL; - gdouble val; - gchar numbuf[64]; + const char *colon; + char *err = NULL; + double val; + char numbuf[64]; colon = strchr(value, ':'); if (colon) { @@ -937,7 +937,7 @@ static void dkim_module_check(struct dkim_check_result *res) { gboolean all_done = TRUE; - const gchar *strict_value; + const char *strict_value; struct dkim_check_result *first, *cur = NULL; struct dkim_ctx *dkim_module_ctx = dkim_get_context(res->task->cfg); struct rspamd_task *task = res->task; @@ -955,7 +955,7 @@ dkim_module_check(struct dkim_check_result *res) if (dkim_module_ctx->dkim_domains != NULL) { /* Perform strict check */ - const gchar *domain = rspamd_dkim_get_domain(cur->ctx); + const char *domain = rspamd_dkim_get_domain(cur->ctx); if ((strict_value = rspamd_match_hash_map(dkim_module_ctx->dkim_domains, @@ -985,7 +985,7 @@ dkim_module_check(struct dkim_check_result *res) if (all_done) { /* Create zero terminated array of results */ struct rspamd_dkim_check_result **pres; - guint nres = 0, i = 0; + unsigned int nres = 0, i = 0; DL_FOREACH(first, cur) { @@ -1001,8 +1001,8 @@ dkim_module_check(struct dkim_check_result *res) DL_FOREACH(first, cur) { - const gchar *symbol = NULL, *trace = NULL; - gdouble symbol_weight = 1.0; + const char *symbol = NULL, *trace = NULL; + double symbol_weight = 1.0; if (cur->ctx == NULL || cur->res == NULL) { continue; @@ -1030,10 +1030,10 @@ dkim_module_check(struct dkim_check_result *res) } if (symbol != NULL) { - const gchar *domain = rspamd_dkim_get_domain(cur->ctx); - const gchar *selector = rspamd_dkim_get_selector(cur->ctx); + const char *domain = rspamd_dkim_get_domain(cur->ctx); + const char *selector = rspamd_dkim_get_selector(cur->ctx); gsize tracelen; - gchar *tracebuf; + char *tracebuf; tracelen = strlen(domain) + strlen(selector) + 4; tracebuf = rspamd_mempool_alloc(task->task_pool, @@ -1131,8 +1131,8 @@ dkim_symbol_callback(struct rspamd_task *task, GError *err = NULL; struct rspamd_mime_header *rh, *rh_cur; struct dkim_check_result *res = NULL, *cur; - guint checked = 0; - gdouble *dmarc_checks; + unsigned int checked = 0; + double *dmarc_checks; struct dkim_ctx *dkim_module_ctx = dkim_get_context(task->cfg); /* Allow dmarc */ @@ -1223,7 +1223,7 @@ dkim_symbol_callback(struct rspamd_task *task, else { /* Get key */ cur->ctx = ctx; - const gchar *domain = rspamd_dkim_get_domain(cur->ctx); + const char *domain = rspamd_dkim_get_domain(cur->ctx); if (dkim_module_ctx->trusted_only && (dkim_module_ctx->dkim_domains == NULL || @@ -1290,7 +1290,7 @@ struct rspamd_dkim_lua_verify_cbdata { struct rspamd_task *task; lua_State *L; rspamd_dkim_key_t *key; - gint cbref; + int cbref; }; static void @@ -1298,7 +1298,7 @@ dkim_module_lua_push_verify_result(struct rspamd_dkim_lua_verify_cbdata *cbd, struct rspamd_dkim_check_result *res, GError *err) { struct rspamd_task **ptask, *task; - const gchar *error_str = "unknown error"; + const char *error_str = "unknown error"; gboolean success = FALSE; task = cbd->task; @@ -1474,17 +1474,17 @@ dkim_module_lua_on_key(rspamd_dkim_key_t *key, dkim_module_lua_push_verify_result(cbd, res, NULL); } -static gint +static int lua_dkim_verify_handler(lua_State *L) { struct rspamd_task *task = lua_check_task(L, 1); - const gchar *sig = luaL_checkstring(L, 2); + const char *sig = luaL_checkstring(L, 2); rspamd_dkim_context_t *ctx; struct rspamd_dkim_lua_verify_cbdata *cbd; rspamd_dkim_key_t *key; struct rspamd_dkim_check_result *ret; GError *err = NULL; - const gchar *type_str = NULL; + const char *type_str = NULL; enum rspamd_dkim_type type = RSPAMD_DKIM_NORMAL; struct dkim_ctx *dkim_module_ctx; @@ -1575,15 +1575,15 @@ lua_dkim_verify_handler(lua_State *L) return 2; } -static gint +static int lua_dkim_canonicalize_handler(lua_State *L) { gsize nlen, vlen; - const gchar *hname = luaL_checklstring(L, 1, &nlen), - *hvalue = luaL_checklstring(L, 2, &vlen); - static gchar st_buf[8192]; - gchar *buf; - guint inlen; + const char *hname = luaL_checklstring(L, 1, &nlen), + *hvalue = luaL_checklstring(L, 2, &vlen); + static char st_buf[8192]; + char *buf; + unsigned int inlen; gboolean allocated = FALSE; goffset r; diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 0bc7bd69d..75968ce84 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -58,28 +58,28 @@ #define RSPAMD_FUZZY_PLUGIN_VERSION RSPAMD_FUZZY_VERSION -static const gint rspamd_fuzzy_hash_len = 5; -static const gchar *M = "fuzzy check"; +static const int rspamd_fuzzy_hash_len = 5; +static const char *M = "fuzzy check"; struct fuzzy_ctx; struct fuzzy_mapping { uint64_t fuzzy_flag; - const gchar *symbol; + const char *symbol; double weight; }; struct fuzzy_rule { struct upstream_list *servers; - const gchar *symbol; - const gchar *algorithm_str; - const gchar *name; + const char *symbol; + const char *algorithm_str; + const char *name; const ucl_object_t *ucl_obj; enum rspamd_shingle_alg alg; GHashTable *mappings; GPtrArray *fuzzy_headers; GString *hash_key; GString *shingles_key; - gdouble io_timeout; + double io_timeout; struct rspamd_cryptobox_keypair *local_key; struct rspamd_cryptobox_pubkey *peer_key; double max_score; @@ -88,11 +88,11 @@ struct fuzzy_rule { gboolean skip_unknown; gboolean no_share; gboolean no_subject; - gint learn_condition_cb; + int learn_condition_cb; uint32_t retransmits; struct rspamd_hash_map_helper *skip_map; struct fuzzy_ctx *ctx; - gint lua_id; + int lua_id; }; struct fuzzy_ctx { @@ -100,15 +100,15 @@ struct fuzzy_ctx { rspamd_mempool_t *fuzzy_pool; GPtrArray *fuzzy_rules; struct rspamd_config *cfg; - const gchar *default_symbol; + const char *default_symbol; struct rspamd_radix_map_helper *whitelist; struct rspamd_keypair_cache *keypairs_cache; - guint max_errors; - gdouble revive_time; - gdouble io_timeout; - gint check_mime_part_ref; /* Lua callback */ - gint process_rule_ref; /* Lua callback */ - gint cleanup_rules_ref; + unsigned int max_errors; + double revive_time; + double io_timeout; + int check_mime_part_ref; /* Lua callback */ + int process_rule_ref; /* Lua callback */ + int cleanup_rules_ref; uint32_t retransmits; gboolean enabled; }; @@ -121,10 +121,10 @@ enum fuzzy_result_type { }; struct fuzzy_client_result { - const gchar *symbol; - gchar *option; - gdouble score; - gdouble prob; + const char *symbol; + char *option; + double score; + double prob; enum fuzzy_result_type type; }; @@ -137,17 +137,17 @@ struct fuzzy_client_session { struct fuzzy_rule *rule; struct ev_loop *event_loop; struct rspamd_io_ev ev; - gint state; - gint fd; - guint retransmits; + int state; + int fd; + unsigned int retransmits; }; struct fuzzy_learn_session { GPtrArray *commands; - gint *saved; + int *saved; struct { - const gchar *error_message; - gint error_code; + const char *error_message; + int error_code; } err; struct rspamd_http_connection_entry *http_entry; struct rspamd_async_session *session; @@ -156,8 +156,8 @@ struct fuzzy_learn_session { struct rspamd_task *task; struct ev_loop *event_loop; struct rspamd_io_ev ev; - gint fd; - guint retransmits; + int fd; + unsigned int retransmits; }; #define FUZZY_CMD_FLAG_REPLIED (1 << 0) @@ -185,18 +185,18 @@ static void fuzzy_symbol_callback(struct rspamd_task *task, void *unused); /* Initialization */ -gint fuzzy_check_module_init(struct rspamd_config *cfg, - struct module_ctx **ctx); -gint fuzzy_check_module_config(struct rspamd_config *cfg, bool valdate); -gint fuzzy_check_module_reconfig(struct rspamd_config *cfg); -static gint fuzzy_attach_controller(struct module_ctx *ctx, - GHashTable *commands); -static gint fuzzy_lua_learn_handler(lua_State *L); -static gint fuzzy_lua_unlearn_handler(lua_State *L); -static gint fuzzy_lua_gen_hashes_handler(lua_State *L); -static gint fuzzy_lua_hex_hashes_handler(lua_State *L); -static gint fuzzy_lua_list_storages(lua_State *L); -static gint fuzzy_lua_ping_storage(lua_State *L); +int fuzzy_check_module_init(struct rspamd_config *cfg, + struct module_ctx **ctx); +int fuzzy_check_module_config(struct rspamd_config *cfg, bool valdate); +int fuzzy_check_module_reconfig(struct rspamd_config *cfg); +static int fuzzy_attach_controller(struct module_ctx *ctx, + GHashTable *commands); +static int fuzzy_lua_learn_handler(lua_State *L); +static int fuzzy_lua_unlearn_handler(lua_State *L); +static int fuzzy_lua_gen_hashes_handler(lua_State *L); +static int fuzzy_lua_hex_hashes_handler(lua_State *L); +static int fuzzy_lua_list_storages(lua_State *L); +static int fuzzy_lua_ping_storage(lua_State *L); module_t fuzzy_check_module = { "fuzzy_check", @@ -205,7 +205,7 @@ module_t fuzzy_check_module = { fuzzy_check_module_reconfig, fuzzy_attach_controller, RSPAMD_MODULE_VER, - (guint) -1, + (unsigned int) -1, }; static inline struct fuzzy_ctx * @@ -219,11 +219,11 @@ static void parse_flags(struct fuzzy_rule *rule, struct rspamd_config *cfg, const ucl_object_t *val, - gint cb_id) + int cb_id) { const ucl_object_t *elt; struct fuzzy_mapping *map; - const gchar *sym = NULL; + const char *sym = NULL; if (val->type == UCL_STRING) { msg_err_config( @@ -275,10 +275,10 @@ parse_flags(struct fuzzy_rule *rule, } static GPtrArray * -parse_fuzzy_headers(struct rspamd_config *cfg, const gchar *str) +parse_fuzzy_headers(struct rspamd_config *cfg, const char *str) { - gchar **strvec; - gint num, i; + char **strvec; + int num, i; GPtrArray *res; strvec = g_strsplit_set(str, ",", 0); @@ -344,9 +344,9 @@ fuzzy_free_rule(gpointer r) } } -static gint +static int fuzzy_parse_rule(struct rspamd_config *cfg, const ucl_object_t *obj, - const gchar *name, gint cb_id) + const char *name, int cb_id) { const ucl_object_t *value, *cur; struct fuzzy_rule *rule; @@ -389,7 +389,7 @@ fuzzy_parse_rule(struct rspamd_config *cfg, const ucl_object_t *obj, it = NULL; while ((cur = ucl_object_iterate(value, &it, value->type == UCL_ARRAY)) != NULL) { GPtrArray *tmp; - guint i; + unsigned int i; gpointer ptr; tmp = parse_fuzzy_headers(cfg, ucl_obj_tostring(cur)); @@ -513,8 +513,8 @@ fuzzy_parse_rule(struct rspamd_config *cfg, const ucl_object_t *obj, * it allows to configure error_rate threshold and upstream dead timer */ rspamd_upstreams_set_limits(rule->servers, - (gdouble) fuzzy_module_ctx->revive_time, NAN, NAN, NAN, - (guint) fuzzy_module_ctx->max_errors, 0); + (double) fuzzy_module_ctx->revive_time, NAN, NAN, NAN, + (unsigned int) fuzzy_module_ctx->max_errors, 0); rspamd_mempool_add_destructor(cfg->cfg_pool, (rspamd_mempool_destruct_t) rspamd_upstreams_destroy, @@ -643,7 +643,7 @@ fuzzy_parse_rule(struct rspamd_config *cfg, const ucl_object_t *obj, /* * Process rule in Lua */ - gint err_idx, ret; + int err_idx, ret; lua_State *L = (lua_State *) cfg->lua_state; lua_pushcfunction(L, &rspamd_lua_traceback); @@ -670,7 +670,7 @@ fuzzy_parse_rule(struct rspamd_config *cfg, const ucl_object_t *obj, return 0; } -gint fuzzy_check_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) +int fuzzy_check_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) { struct fuzzy_ctx *fuzzy_module_ctx; @@ -995,11 +995,11 @@ gint fuzzy_check_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) return 0; } -gint fuzzy_check_module_config(struct rspamd_config *cfg, bool validate) +int fuzzy_check_module_config(struct rspamd_config *cfg, bool validate) { const ucl_object_t *value, *cur, *elt; ucl_object_iter_t it; - gint res = TRUE, cb_id, nrules = 0; + int res = TRUE, cb_id, nrules = 0; lua_State *L = cfg->lua_state; struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(cfg); @@ -1240,13 +1240,13 @@ gint fuzzy_check_module_config(struct rspamd_config *cfg, bool validate) return res; } -gint fuzzy_check_module_reconfig(struct rspamd_config *cfg) +int fuzzy_check_module_reconfig(struct rspamd_config *cfg) { struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(cfg); if (fuzzy_module_ctx->cleanup_rules_ref != -1) { /* Sync lua_fuzzy rules */ - gint err_idx, ret; + int err_idx, ret; lua_State *L = (lua_State *) cfg->lua_state; lua_pushcfunction(L, &rspamd_lua_traceback); @@ -1304,10 +1304,10 @@ fuzzy_preprocess_words(struct rspamd_mime_text_part *part, rspamd_mempool_t *poo static void fuzzy_encrypt_cmd(struct fuzzy_rule *rule, struct rspamd_fuzzy_encrypted_req_hdr *hdr, - guchar *data, gsize datalen) + unsigned char *data, gsize datalen) { - const guchar *pk; - guint pklen; + const unsigned char *pk; + unsigned int pklen; g_assert(hdr != NULL); g_assert(data != NULL); @@ -1334,7 +1334,7 @@ fuzzy_encrypt_cmd(struct fuzzy_rule *rule, static struct fuzzy_cmd_io * fuzzy_cmd_stat(struct fuzzy_rule *rule, int c, - gint flag, + int flag, uint32_t weight, rspamd_mempool_t *pool) { @@ -1361,7 +1361,7 @@ fuzzy_cmd_stat(struct fuzzy_rule *rule, memcpy(&io->cmd, cmd, sizeof(io->cmd)); if (rule->peer_key && enccmd) { - fuzzy_encrypt_cmd(rule, &enccmd->hdr, (guchar *) cmd, sizeof(*cmd)); + fuzzy_encrypt_cmd(rule, &enccmd->hdr, (unsigned char *) cmd, sizeof(*cmd)); io->io.iov_base = enccmd; io->io.iov_len = sizeof(*enccmd); } @@ -1414,7 +1414,7 @@ fuzzy_cmd_ping(struct fuzzy_rule *rule, memcpy(&io->cmd, cmd, sizeof(io->cmd)); if (rule->peer_key && enccmd) { - fuzzy_encrypt_cmd(rule, &enccmd->hdr, (guchar *) cmd, sizeof(*cmd)); + fuzzy_encrypt_cmd(rule, &enccmd->hdr, (unsigned char *) cmd, sizeof(*cmd)); io->io.iov_base = enccmd; io->io.iov_len = sizeof(*enccmd); } @@ -1430,7 +1430,7 @@ static struct fuzzy_cmd_io * fuzzy_cmd_hash(struct fuzzy_rule *rule, int c, const rspamd_ftok_t *hash, - gint flag, + int flag, uint32_t weight, rspamd_mempool_t *pool) { @@ -1471,7 +1471,7 @@ fuzzy_cmd_hash(struct fuzzy_rule *rule, memcpy(&io->cmd, cmd, sizeof(io->cmd)); if (rule->peer_key && enccmd) { - fuzzy_encrypt_cmd(rule, &enccmd->hdr, (guchar *) cmd, sizeof(*cmd)); + fuzzy_encrypt_cmd(rule, &enccmd->hdr, (unsigned char *) cmd, sizeof(*cmd)); io->io.iov_base = enccmd; io->io.iov_len = sizeof(*enccmd); } @@ -1485,9 +1485,9 @@ fuzzy_cmd_hash(struct fuzzy_rule *rule, struct rspamd_cached_shingles { struct rspamd_shingle *sh; - guchar digest[rspamd_cryptobox_HASHBYTES]; - guint additional_length; - guchar *additional_data; + unsigned char digest[rspamd_cryptobox_HASHBYTES]; + unsigned int additional_length; + unsigned char *additional_data; }; @@ -1496,8 +1496,8 @@ fuzzy_cmd_get_cached(struct fuzzy_rule *rule, struct rspamd_task *task, struct rspamd_mime_part *mp) { - gchar key[32]; - gint key_part; + char key[32]; + int key_part; struct rspamd_cached_shingles **cached; memcpy(&key_part, rule->shingles_key->str, sizeof(key_part)); @@ -1520,8 +1520,8 @@ fuzzy_cmd_set_cached(struct fuzzy_rule *rule, struct rspamd_mime_part *mp, struct rspamd_cached_shingles *data) { - gchar key[32]; - gint key_part; + char key[32]; + int key_part; struct rspamd_cached_shingles **cached; memcpy(&key_part, rule->shingles_key->str, sizeof(key_part)); @@ -1552,10 +1552,10 @@ fuzzy_rule_check_mimepart(struct rspamd_task *task, { lua_State *L = (lua_State *) task->cfg->lua_state; - gint old_top = lua_gettop(L); + int old_top = lua_gettop(L); if (rule->lua_id != -1 && rule->ctx->check_mime_part_ref != -1) { - gint err_idx, ret; + int err_idx, ret; struct rspamd_task **ptask; struct rspamd_mime_part **ppart; @@ -1597,11 +1597,11 @@ fuzzy_rule_check_mimepart(struct rspamd_task *task, #define MAX_FUZZY_DOMAIN 64 -static guint +static unsigned int fuzzy_cmd_extension_length(struct rspamd_task *task, struct fuzzy_rule *rule) { - guint total = 0; + unsigned int total = 0; if (rule->no_share) { return 0; @@ -1629,13 +1629,13 @@ fuzzy_cmd_extension_length(struct rspamd_task *task, return total; } -static guint +static unsigned int fuzzy_cmd_write_extensions(struct rspamd_task *task, struct fuzzy_rule *rule, - guchar *dest, + unsigned char *dest, gsize available) { - guint written = 0; + unsigned int written = 0; if (rule->no_share) { return 0; @@ -1645,7 +1645,7 @@ fuzzy_cmd_write_extensions(struct rspamd_task *task, struct rspamd_email_address *addr = g_ptr_array_index(MESSAGE_FIELD(task, from_mime), 0); - guint to_write = MIN(MAX_FUZZY_DOMAIN, addr->domain_len) + 2; + unsigned int to_write = MIN(MAX_FUZZY_DOMAIN, addr->domain_len) + 2; if (to_write > 0 && to_write <= available) { *dest++ = RSPAMD_FUZZY_EXT_SOURCE_DOMAIN; @@ -1670,8 +1670,8 @@ fuzzy_cmd_write_extensions(struct rspamd_task *task, if (task->from_addr && rspamd_inet_address_get_af(task->from_addr) == AF_INET) { if (available >= sizeof(struct in_addr) + 1) { - guint klen; - guchar *inet_data = rspamd_inet_address_get_hash_key(task->from_addr, &klen); + unsigned int klen; + unsigned char *inet_data = rspamd_inet_address_get_hash_key(task->from_addr, &klen); *dest++ = RSPAMD_FUZZY_EXT_SOURCE_IP4; @@ -1684,8 +1684,8 @@ fuzzy_cmd_write_extensions(struct rspamd_task *task, } else if (task->from_addr && rspamd_inet_address_get_af(task->from_addr) == AF_INET6) { if (available >= sizeof(struct in6_addr) + 1) { - guint klen; - guchar *inet_data = rspamd_inet_address_get_hash_key(task->from_addr, &klen); + unsigned int klen; + unsigned char *inet_data = rspamd_inet_address_get_hash_key(task->from_addr, &klen); *dest++ = RSPAMD_FUZZY_EXT_SOURCE_IP6; @@ -1707,7 +1707,7 @@ static struct fuzzy_cmd_io * fuzzy_cmd_from_text_part(struct rspamd_task *task, struct fuzzy_rule *rule, int c, - gint flag, + int flag, uint32_t weight, gboolean short_text, struct rspamd_mime_text_part *part, @@ -1719,13 +1719,13 @@ fuzzy_cmd_from_text_part(struct rspamd_task *task, struct rspamd_fuzzy_encrypted_cmd *enccmd = NULL; struct rspamd_cached_shingles *cached = NULL; struct rspamd_shingle *sh = NULL; - guint i; + unsigned int i; rspamd_cryptobox_hash_state_t st; rspamd_stat_token_t *word; GArray *words; struct fuzzy_cmd_io *io; - guint additional_length; - guchar *additional_data; + unsigned int additional_length; + unsigned char *additional_data; cached = fuzzy_cmd_get_cached(rule, task, mp); @@ -1763,7 +1763,7 @@ fuzzy_cmd_from_text_part(struct rspamd_task *task, memcpy(cmd->digest, cached->digest, sizeof(cached->digest)); cmd->shingles_count = 0; - memcpy(((guchar *) enccmd) + sizeof(*enccmd), additional_data, + memcpy(((unsigned char *) enccmd) + sizeof(*enccmd), additional_data, additional_length); } else if (cached->sh) { @@ -1773,7 +1773,7 @@ fuzzy_cmd_from_text_part(struct rspamd_task *task, memcpy(&shcmd->sgl, cached->sh, sizeof(struct rspamd_shingle)); memcpy(shcmd->basic.digest, cached->digest, sizeof(cached->digest)); - memcpy(((guchar *) encshcmd) + sizeof(*encshcmd), additional_data, + memcpy(((unsigned char *) encshcmd) + sizeof(*encshcmd), additional_data, additional_length); shcmd->basic.shingles_count = RSPAMD_SHINGLE_SIZE; } @@ -1790,7 +1790,7 @@ fuzzy_cmd_from_text_part(struct rspamd_task *task, * occasional encryption */ cached->additional_length = additional_length; - cached->additional_data = ((guchar *) cached) + sizeof(*cached); + cached->additional_data = ((unsigned char *) cached) + sizeof(*cached); if (additional_length > 0) { fuzzy_cmd_write_extensions(task, rule, cached->additional_data, @@ -1817,7 +1817,7 @@ fuzzy_cmd_from_text_part(struct rspamd_task *task, memcpy(cached->digest, cmd->digest, sizeof(cached->digest)); cached->sh = NULL; - additional_data = ((guchar *) enccmd) + sizeof(*enccmd); + additional_data = ((unsigned char *) enccmd) + sizeof(*enccmd); memcpy(additional_data, cached->additional_data, additional_length); } else { @@ -1860,7 +1860,7 @@ fuzzy_cmd_from_text_part(struct rspamd_task *task, cached->sh = sh; memcpy(cached->digest, shcmd->basic.digest, sizeof(cached->digest)); - additional_data = ((guchar *) encshcmd) + sizeof(*encshcmd); + additional_data = ((unsigned char *) encshcmd) + sizeof(*encshcmd); memcpy(additional_data, cached->additional_data, additional_length); } @@ -1908,13 +1908,13 @@ fuzzy_cmd_from_text_part(struct rspamd_task *task, if (rule->peer_key) { /* Encrypt data */ if (!short_text) { - fuzzy_encrypt_cmd(rule, &encshcmd->hdr, (guchar *) shcmd, + fuzzy_encrypt_cmd(rule, &encshcmd->hdr, (unsigned char *) shcmd, sizeof(*shcmd) + additional_length); io->io.iov_base = encshcmd; io->io.iov_len = sizeof(*encshcmd) + additional_length; } else { - fuzzy_encrypt_cmd(rule, &enccmd->hdr, (guchar *) cmd, + fuzzy_encrypt_cmd(rule, &enccmd->hdr, (unsigned char *) cmd, sizeof(*cmd) + additional_length); io->io.iov_base = enccmd; io->io.iov_len = sizeof(*enccmd) + additional_length; @@ -1939,7 +1939,7 @@ fuzzy_cmd_from_text_part(struct rspamd_task *task, static struct fuzzy_cmd_io * fuzzy_cmd_from_image_part (struct fuzzy_rule *rule, int c, - gint flag, + int flag, uint32_t weight, struct rspamd_task *task, struct rspamd_image *img, @@ -1984,7 +1984,7 @@ fuzzy_cmd_from_image_part (struct fuzzy_rule *rule, } rspamd_cryptobox_hash (shcmd->basic.digest, - (const guchar *)img->dct, RSPAMD_DCT_LEN / NBBY, + (const unsigned char *)img->dct, RSPAMD_DCT_LEN / NBBY, rule->hash_key->str, rule->hash_key->len); msg_debug_task ("loading shingles of type %s with key %*xs", @@ -2021,7 +2021,7 @@ fuzzy_cmd_from_image_part (struct fuzzy_rule *rule, if (rule->peer_key) { /* Encrypt data */ - fuzzy_encrypt_cmd (rule, &encshcmd->hdr, (guchar *) shcmd, sizeof (*shcmd)); + fuzzy_encrypt_cmd (rule, &encshcmd->hdr, (unsigned char *) shcmd, sizeof (*shcmd)); io->io.iov_base = encshcmd; io->io.iov_len = sizeof (*encshcmd); } @@ -2037,17 +2037,17 @@ fuzzy_cmd_from_image_part (struct fuzzy_rule *rule, static struct fuzzy_cmd_io * fuzzy_cmd_from_data_part(struct fuzzy_rule *rule, int c, - gint flag, + int flag, uint32_t weight, struct rspamd_task *task, - guchar digest[rspamd_cryptobox_HASHBYTES], + unsigned char digest[rspamd_cryptobox_HASHBYTES], struct rspamd_mime_part *mp) { struct rspamd_fuzzy_cmd *cmd; struct rspamd_fuzzy_encrypted_cmd *enccmd = NULL; struct fuzzy_cmd_io *io; - guint additional_length; - guchar *additional_data; + unsigned int additional_length; + unsigned char *additional_data; additional_length = fuzzy_cmd_extension_length(task, rule); @@ -2055,12 +2055,12 @@ fuzzy_cmd_from_data_part(struct fuzzy_rule *rule, enccmd = rspamd_mempool_alloc0(task->task_pool, sizeof(*enccmd) + additional_length); cmd = &enccmd->cmd; - additional_data = ((guchar *) enccmd) + sizeof(*enccmd); + additional_data = ((unsigned char *) enccmd) + sizeof(*enccmd); } else { cmd = rspamd_mempool_alloc0(task->task_pool, sizeof(*cmd) + additional_length); - additional_data = ((guchar *) cmd) + sizeof(*cmd); + additional_data = ((unsigned char *) cmd) + sizeof(*cmd); } cmd->cmd = c; @@ -2086,7 +2086,7 @@ fuzzy_cmd_from_data_part(struct fuzzy_rule *rule, if (rule->peer_key) { g_assert(enccmd != NULL); - fuzzy_encrypt_cmd(rule, &enccmd->hdr, (guchar *) cmd, + fuzzy_encrypt_cmd(rule, &enccmd->hdr, (unsigned char *) cmd, sizeof(*cmd) + additional_length); io->io.iov_base = enccmd; io->io.iov_len = sizeof(*enccmd) + additional_length; @@ -2100,7 +2100,7 @@ fuzzy_cmd_from_data_part(struct fuzzy_rule *rule, } static gboolean -fuzzy_cmd_to_wire(gint fd, struct iovec *io) +fuzzy_cmd_to_wire(int fd, struct iovec *io) { struct msghdr msg; @@ -2119,9 +2119,9 @@ fuzzy_cmd_to_wire(gint fd, struct iovec *io) } static gboolean -fuzzy_cmd_vector_to_wire(gint fd, GPtrArray *v) +fuzzy_cmd_vector_to_wire(int fd, GPtrArray *v) { - guint i; + unsigned int i; gboolean all_sent = TRUE, all_replied = TRUE; struct fuzzy_cmd_io *io; gboolean processed = FALSE; @@ -2166,13 +2166,13 @@ fuzzy_cmd_vector_to_wire(gint fd, GPtrArray *v) * Read replies one-by-one and remove them from req array */ static const struct rspamd_fuzzy_reply * -fuzzy_process_reply(guchar **pos, gint *r, GPtrArray *req, +fuzzy_process_reply(unsigned char **pos, int *r, GPtrArray *req, struct fuzzy_rule *rule, struct rspamd_fuzzy_cmd **pcmd, struct fuzzy_cmd_io **pio) { - guchar *p = *pos; - gint remain = *r; - guint i, required_size; + unsigned char *p = *pos; + int remain = *r; + unsigned int i, required_size; struct fuzzy_cmd_io *io; const struct rspamd_fuzzy_reply *rep; struct rspamd_fuzzy_encrypted_reply encrep; @@ -2185,7 +2185,7 @@ fuzzy_process_reply(guchar **pos, gint *r, GPtrArray *req, required_size = sizeof(*rep); } - if (remain <= 0 || (guint) remain < required_size) { + if (remain <= 0 || (unsigned int) remain < required_size) { return NULL; } @@ -2198,7 +2198,7 @@ fuzzy_process_reply(guchar **pos, gint *r, GPtrArray *req, rspamd_keypair_cache_process(rule->ctx->keypairs_cache, rule->local_key, rule->peer_key); - if (!rspamd_cryptobox_decrypt_nm_inplace((guchar *) &encrep.rep, + if (!rspamd_cryptobox_decrypt_nm_inplace((unsigned char *) &encrep.rep, sizeof(encrep.rep), encrep.hdr.nonce, rspamd_pubkey_get_nm(rule->peer_key, rule->local_key), @@ -2254,20 +2254,20 @@ fuzzy_insert_result(struct fuzzy_client_session *session, const struct rspamd_fuzzy_reply *rep, struct rspamd_fuzzy_cmd *cmd, struct fuzzy_cmd_io *io, - guint flag) + unsigned int flag) { - const gchar *symbol; + const char *symbol; struct fuzzy_mapping *map; struct rspamd_task *task = session->task; double weight; double nval; - guchar buf[2048]; - const gchar *type = "bin"; + unsigned char buf[2048]; + const char *type = "bin"; struct fuzzy_client_result *res; gboolean is_fuzzy = FALSE; - gchar hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; + char hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; /* Discriminate scores for small images */ - static const guint short_image_limit = 32 * 1024; + static const unsigned int short_image_limit = 32 * 1024; /* Get mapping by flag */ if ((map = @@ -2332,7 +2332,7 @@ fuzzy_insert_result(struct fuzzy_client_session *session, if (map != NULL || !session->rule->skip_unknown) { GList *fuzzy_var; rspamd_fstring_t *hex_result; - gchar timebuf[64]; + char timebuf[64]; struct tm tm_split; if (session->rule->skip_map) { @@ -2362,9 +2362,9 @@ fuzzy_insert_result(struct fuzzy_client_session *session, "%.2f, probability %.2f, in list: %s:%d%s; added on %s", type, hexbuf, - (gint) sizeof(cmd->digest), cmd->digest, + (int) sizeof(cmd->digest), cmd->digest, nval, - (gdouble) rep->v1.prob, + (double) rep->v1.prob, symbol, rep->v1.flag, map == NULL ? "(unknown)" : "", @@ -2377,7 +2377,7 @@ fuzzy_insert_result(struct fuzzy_client_session *session, type, hexbuf, nval, - (gdouble) rep->v1.prob, + (double) rep->v1.prob, symbol, rep->v1.flag, map == NULL ? "(unknown)" : "", @@ -2388,7 +2388,7 @@ fuzzy_insert_result(struct fuzzy_client_session *session, sizeof(buf), "%d:%*s:%.2f:%s", rep->v1.flag, - (gint) MIN(rspamd_fuzzy_hash_len * 2, sizeof(rep->digest) * 2), hexbuf, + (int) MIN(rspamd_fuzzy_hash_len * 2, sizeof(rep->digest) * 2), hexbuf, rep->v1.prob, type); res->option = rspamd_mempool_strdup(task->task_pool, buf); @@ -2416,15 +2416,15 @@ fuzzy_insert_result(struct fuzzy_client_session *session, } } -static gint +static int fuzzy_check_try_read(struct fuzzy_client_session *session) { struct rspamd_task *task; const struct rspamd_fuzzy_reply *rep; struct rspamd_fuzzy_cmd *cmd = NULL; struct fuzzy_cmd_io *io = NULL; - gint r, ret; - guchar buf[2048], *p; + int r, ret; + unsigned char buf[2048], *p; task = session->task; @@ -2510,12 +2510,12 @@ fuzzy_insert_metric_results(struct rspamd_task *task, struct fuzzy_rule *rule, GPtrArray *results) { struct fuzzy_client_result *res; - guint i; + unsigned int i; gboolean seen_text_hash = FALSE, seen_img_hash = FALSE, seen_text_part = FALSE, seen_long_text = FALSE; - gdouble prob_txt = 0.0, mult; + double prob_txt = 0.0, mult; struct rspamd_mime_text_part *tp; /* About 5 words */ @@ -2587,7 +2587,7 @@ fuzzy_insert_metric_results(struct rspamd_task *task, struct fuzzy_rule *rule, } } - gdouble weight = res->score * mult; + double weight = res->score * mult; if (!isnan(rule->weight_threshold)) { if (weight >= rule->weight_threshold) { @@ -2610,7 +2610,7 @@ static gboolean fuzzy_check_session_is_completed(struct fuzzy_client_session *session) { struct fuzzy_cmd_io *io; - guint nreplied = 0, i; + unsigned int nreplied = 0, i; rspamd_upstream_ok(session->server); @@ -2639,7 +2639,7 @@ fuzzy_check_session_is_completed(struct fuzzy_client_session *session) /* Fuzzy check timeout callback */ static void -fuzzy_check_timer_callback(gint fd, short what, void *arg) +fuzzy_check_timer_callback(int fd, short what, void *arg) { struct fuzzy_client_session *session = arg; struct rspamd_task *task; @@ -2677,11 +2677,11 @@ fuzzy_check_timer_callback(gint fd, short what, void *arg) /* Fuzzy check callback */ static void -fuzzy_check_io_callback(gint fd, short what, void *arg) +fuzzy_check_io_callback(int fd, short what, void *arg) { struct fuzzy_client_session *session = arg; struct rspamd_task *task; - gint r; + int r; enum { return_error = 0, @@ -2787,7 +2787,7 @@ fuzzy_controller_lua_fin(void *ud) /* Controller IO */ static void -fuzzy_controller_timer_callback(gint fd, short what, void *arg) +fuzzy_controller_timer_callback(int fd, short what, void *arg) { struct fuzzy_learn_session *session = arg; struct rspamd_task *task; @@ -2843,24 +2843,24 @@ fuzzy_controller_timer_callback(gint fd, short what, void *arg) } static void -fuzzy_controller_io_callback(gint fd, short what, void *arg) +fuzzy_controller_io_callback(int fd, short what, void *arg) { struct fuzzy_learn_session *session = arg; const struct rspamd_fuzzy_reply *rep; struct fuzzy_mapping *map; struct rspamd_task *task; - guchar buf[2048], *p; + unsigned char buf[2048], *p; struct fuzzy_cmd_io *io; struct rspamd_fuzzy_cmd *cmd = NULL; - const gchar *symbol, *ftype; - gint r; + const char *symbol, *ftype; + int r; enum { return_error = 0, return_want_more, return_finished } ret = return_want_more; - guint i, nreplied; - const gchar *op = "process"; + unsigned int i, nreplied; + const char *op = "process"; task = session->task; @@ -2922,7 +2922,7 @@ fuzzy_controller_io_callback(gint fd, short what, void *arg) "message <%s>", op, ftype, - (gint) sizeof(rep->digest), rep->digest, + (int) sizeof(rep->digest), rep->digest, symbol, rep->v1.flag, MESSAGE_FIELD_CHECK(session->task, message_id)); @@ -2936,7 +2936,7 @@ fuzzy_controller_io_callback(gint fd, short what, void *arg) ftype, op, MESSAGE_FIELD_CHECK(session->task, message_id), - (gint) sizeof(rep->digest), rep->digest, + (int) sizeof(rep->digest), rep->digest, symbol, rep->v1.flag); @@ -2951,7 +2951,7 @@ fuzzy_controller_io_callback(gint fd, short what, void *arg) ftype, op, MESSAGE_FIELD_CHECK(session->task, message_id), - (gint) sizeof(rep->digest), rep->digest, + (int) sizeof(rep->digest), rep->digest, symbol, rep->v1.flag, rep->v1.value); @@ -3056,7 +3056,7 @@ cleanup: if (session->http_entry) { ucl_object_t *reply, *hashes; - gchar hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; + char hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; reply = ucl_object_typed_new(UCL_OBJECT); @@ -3068,7 +3068,7 @@ cleanup: io = g_ptr_array_index(session->commands, i); rspamd_snprintf(hexbuf, sizeof(hexbuf), "%*xs", - (gint) sizeof(io->cmd.digest), io->cmd.digest); + (int) sizeof(io->cmd.digest), io->cmd.digest); ucl_array_append(hashes, ucl_object_fromstring(hexbuf)); } @@ -3089,13 +3089,13 @@ cleanup: static GPtrArray * fuzzy_generate_commands(struct rspamd_task *task, struct fuzzy_rule *rule, - gint c, gint flag, uint32_t value, guint flags) + int c, int flag, uint32_t value, unsigned int flags) { struct rspamd_mime_text_part *part; struct rspamd_mime_part *mime_part; struct rspamd_image *image; struct fuzzy_cmd_io *io, *cur; - guint i, j; + unsigned int i, j; GPtrArray *res = NULL; gboolean check_part, fuzzy_check; @@ -3165,7 +3165,7 @@ fuzzy_generate_commands(struct rspamd_task *task, struct fuzzy_rule *rule, if (lua_spec->type == RSPAMD_LUA_PART_TABLE) { lua_State *L = (lua_State *) task->cfg->lua_state; - gint old_top; + int old_top; old_top = lua_gettop(L); /* Push table */ @@ -3174,11 +3174,11 @@ fuzzy_generate_commands(struct rspamd_task *task, struct fuzzy_rule *rule, lua_gettable(L, -2); if (lua_type(L, -1) == LUA_TTABLE) { - gint tbl_pos = lua_gettop(L); + int tbl_pos = lua_gettop(L); for (lua_pushnil(L); lua_next(L, tbl_pos); lua_pop(L, 1)) { - const gchar *h = NULL; + const char *h = NULL; gsize hlen = 0; if (lua_isstring(L, -1)) { @@ -3199,7 +3199,7 @@ fuzzy_generate_commands(struct rspamd_task *task, struct fuzzy_rule *rule, io = fuzzy_cmd_from_data_part(rule, c, flag, value, task, - (guchar *) h, + (unsigned char *) h, mime_part); if (io) { @@ -3267,7 +3267,7 @@ register_fuzzy_client_call(struct rspamd_task *task, struct fuzzy_client_session *session; struct upstream *selected; rspamd_inet_addr_t *addr; - gint sock; + int sock; if (!rspamd_session_blocked(task->s)) { /* Get upstream */ @@ -3324,7 +3324,7 @@ fuzzy_symbol_callback(struct rspamd_task *task, void *unused) { struct fuzzy_rule *rule; - guint i; + unsigned int i; GPtrArray *commands; struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg); @@ -3364,7 +3364,7 @@ fuzzy_symbol_callback(struct rspamd_task *task, void fuzzy_stat_command(struct rspamd_task *task) { struct fuzzy_rule *rule; - guint i; + unsigned int i; GPtrArray *commands; struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg); @@ -3381,19 +3381,19 @@ void fuzzy_stat_command(struct rspamd_task *task) } } -static inline gint +static inline int register_fuzzy_controller_call(struct rspamd_http_connection_entry *entry, struct fuzzy_rule *rule, struct rspamd_task *task, GPtrArray *commands, - gint *saved) + int *saved) { struct fuzzy_learn_session *s; struct upstream *selected; rspamd_inet_addr_t *addr; struct rspamd_controller_session *session = entry->ud; - gint sock; - gint ret = -1; + int sock; + int ret = -1; /* Get upstream */ @@ -3443,25 +3443,25 @@ register_fuzzy_controller_call(struct rspamd_http_connection_entry *entry, static void fuzzy_process_handler(struct rspamd_http_connection_entry *conn_ent, - struct rspamd_http_message *msg, gint cmd, gint value, gint flag, - struct fuzzy_ctx *ctx, gboolean is_hash, guint flags) + struct rspamd_http_message *msg, int cmd, int value, int flag, + struct fuzzy_ctx *ctx, gboolean is_hash, unsigned int flags) { struct fuzzy_rule *rule; struct rspamd_controller_session *session = conn_ent->ud; struct rspamd_task *task, **ptask; gboolean processed = FALSE, skip = FALSE; - gint res = 0; - guint i; + int res = 0; + unsigned int i; GPtrArray *commands; lua_State *L; - gint r, *saved, rules = 0, err_idx; + int r, *saved, rules = 0, err_idx; struct fuzzy_ctx *fuzzy_module_ctx; /* Prepare task */ task = rspamd_task_new(session->wrk, session->cfg, NULL, session->lang_det, conn_ent->rt->event_loop, FALSE); task->cfg = ctx->cfg; - saved = rspamd_mempool_alloc0(session->pool, sizeof(gint)); + saved = rspamd_mempool_alloc0(session->pool, sizeof(int)); fuzzy_module_ctx = fuzzy_get_context(ctx->cfg); if (!is_hash) { @@ -3530,7 +3530,7 @@ fuzzy_process_handler(struct rspamd_http_connection_entry *conn_ent, msg_info_task("learn condition changed flag from %d to " "%d", flag, - (gint) lua_tonumber(L, err_idx + 2)); + (int) lua_tonumber(L, err_idx + 2)); flag = lua_tonumber(L, err_idx + 2); } } @@ -3565,7 +3565,7 @@ fuzzy_process_handler(struct rspamd_http_connection_entry *conn_ent, if (is_hash) { GPtrArray *args; const rspamd_ftok_t *arg; - guint j; + unsigned int j; args = rspamd_http_message_find_header_multiple(msg, "Hash"); @@ -3655,7 +3655,7 @@ fuzzy_process_handler(struct rspamd_http_connection_entry *conn_ent, static int fuzzy_controller_handler(struct rspamd_http_connection_entry *conn_ent, - struct rspamd_http_message *msg, struct module_ctx *ctx, gint cmd, + struct rspamd_http_message *msg, struct module_ctx *ctx, int cmd, gboolean is_hash) { const rspamd_ftok_t *arg; @@ -3700,7 +3700,7 @@ fuzzy_controller_handler(struct rspamd_http_connection_entry *conn_ent, /* Search flag by symbol */ if (arg) { struct fuzzy_rule *rule; - guint i; + unsigned int i; GHashTableIter it; gpointer k, v; struct fuzzy_mapping *map; @@ -3753,17 +3753,17 @@ fuzzy_controller_handler(struct rspamd_http_connection_entry *conn_ent, return 0; } -static inline gint +static inline int fuzzy_check_send_lua_learn(struct fuzzy_rule *rule, struct rspamd_task *task, GPtrArray *commands, - gint *saved) + int *saved) { struct fuzzy_learn_session *s; struct upstream *selected; rspamd_inet_addr_t *addr; - gint sock; - gint ret = -1; + int sock; + int ret = -1; /* Get upstream */ if (!rspamd_session_blocked(task->s)) { @@ -3814,16 +3814,16 @@ fuzzy_check_send_lua_learn(struct fuzzy_rule *rule, static gboolean fuzzy_check_lua_process_learn(struct rspamd_task *task, - gint cmd, gint value, gint flag, guint send_flags) + int cmd, int value, int flag, unsigned int send_flags) { struct fuzzy_rule *rule; gboolean processed = FALSE, res = TRUE; - guint i; + unsigned int i; GPtrArray *commands; - gint *saved, rules = 0; + int *saved, rules = 0; struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg); - saved = rspamd_mempool_alloc0(task->task_pool, sizeof(gint)); + saved = rspamd_mempool_alloc0(task->task_pool, sizeof(int)); PTR_ARRAY_FOREACH(fuzzy_module_ctx->fuzzy_rules, i, rule) { @@ -3880,7 +3880,7 @@ fuzzy_check_lua_process_learn(struct rspamd_task *task, return TRUE; } -static gint +static int fuzzy_lua_learn_handler(lua_State *L) { struct rspamd_task *task = lua_check_task(L, 1); @@ -3889,8 +3889,8 @@ fuzzy_lua_learn_handler(lua_State *L) return luaL_error(L, "invalid arguments"); } - guint flag = 0, weight = 1, send_flags = 0; - const gchar *symbol; + unsigned int flag = 0, weight = 1, send_flags = 0; + const char *symbol; struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg); if (lua_type(L, 2) == LUA_TNUMBER) { @@ -3898,7 +3898,7 @@ fuzzy_lua_learn_handler(lua_State *L) } else if (lua_type(L, 2) == LUA_TSTRING) { struct fuzzy_rule *rule; - guint i; + unsigned int i; GHashTableIter it; gpointer k, v; struct fuzzy_mapping *map; @@ -3933,7 +3933,7 @@ fuzzy_lua_learn_handler(lua_State *L) } if (lua_type(L, 4) == LUA_TTABLE) { - const gchar *sf; + const char *sf; for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { sf = lua_tostring(L, -1); @@ -3958,7 +3958,7 @@ fuzzy_lua_learn_handler(lua_State *L) return 1; } -static gint +static int fuzzy_lua_unlearn_handler(lua_State *L) { struct rspamd_task *task = lua_check_task(L, 1); @@ -3966,8 +3966,8 @@ fuzzy_lua_unlearn_handler(lua_State *L) return luaL_error(L, "invalid arguments"); } - guint flag = 0, weight = 1.0, send_flags = 0; - const gchar *symbol; + unsigned int flag = 0, weight = 1.0, send_flags = 0; + const char *symbol; struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg); if (lua_type(L, 2) == LUA_TNUMBER) { @@ -3975,7 +3975,7 @@ fuzzy_lua_unlearn_handler(lua_State *L) } else if (lua_type(L, 2) == LUA_TSTRING) { struct fuzzy_rule *rule; - guint i; + unsigned int i; GHashTableIter it; gpointer k, v; struct fuzzy_mapping *map; @@ -4011,7 +4011,7 @@ fuzzy_lua_unlearn_handler(lua_State *L) } if (lua_type(L, 4) == LUA_TTABLE) { - const gchar *sf; + const char *sf; for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { sf = lua_tostring(L, -1); @@ -4037,7 +4037,7 @@ fuzzy_lua_unlearn_handler(lua_State *L) return 1; } -static gint +static int fuzzy_lua_gen_hashes_handler(lua_State *L) { struct rspamd_task *task = lua_check_task(L, 1); @@ -4046,13 +4046,13 @@ fuzzy_lua_gen_hashes_handler(lua_State *L) return luaL_error(L, "invalid arguments"); } - guint flag = 0, weight = 1, send_flags = 0; - const gchar *symbol; + unsigned int flag = 0, weight = 1, send_flags = 0; + const char *symbol; struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg); struct fuzzy_rule *rule; GPtrArray *commands; - gint cmd = FUZZY_WRITE; - gint i; + int cmd = FUZZY_WRITE; + int i; if (lua_type(L, 2) == LUA_TNUMBER) { flag = lua_tonumber(L, 2); @@ -4094,7 +4094,7 @@ fuzzy_lua_gen_hashes_handler(lua_State *L) /* Flags */ if (lua_type(L, 4) == LUA_TTABLE) { - const gchar *sf; + const char *sf; for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { sf = lua_tostring(L, -1); @@ -4115,7 +4115,7 @@ fuzzy_lua_gen_hashes_handler(lua_State *L) /* Type */ if (lua_type(L, 5) == LUA_TSTRING) { - const gchar *cmd_name = lua_tostring(L, 5); + const char *cmd_name = lua_tostring(L, 5); if (strcmp(cmd_name, "add") == 0 || strcmp(cmd_name, "write") == 0) { cmd = FUZZY_WRITE; @@ -4150,7 +4150,7 @@ fuzzy_lua_gen_hashes_handler(lua_State *L) if (commands != NULL) { struct fuzzy_cmd_io *io; - gint j; + int j; lua_pushstring(L, rule->name); lua_createtable(L, commands->len, 0); @@ -4171,7 +4171,7 @@ fuzzy_lua_gen_hashes_handler(lua_State *L) return 1; } -static gint +static int fuzzy_lua_hex_hashes_handler(lua_State *L) { struct rspamd_task *task = lua_check_task(L, 1); @@ -4180,12 +4180,12 @@ fuzzy_lua_hex_hashes_handler(lua_State *L) return luaL_error(L, "invalid arguments"); } - guint flag = 0, weight = 1, send_flags = 0; - const gchar *symbol; + unsigned int flag = 0, weight = 1, send_flags = 0; + const char *symbol; struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg); struct fuzzy_rule *rule; GPtrArray *commands; - gint i; + int i; if (lua_type(L, 2) == LUA_TNUMBER) { flag = lua_tonumber(L, 2); @@ -4246,7 +4246,7 @@ fuzzy_lua_hex_hashes_handler(lua_State *L) * get hex hashes */ struct rspamd_mime_part *mp; - gint j, part_idx = 1; + int j, part_idx = 1; PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), j, mp) { @@ -4255,9 +4255,9 @@ fuzzy_lua_hex_hashes_handler(lua_State *L) cached = fuzzy_cmd_get_cached(rule, task, mp); if (cached) { - gchar hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; - gint r = rspamd_encode_hex_buf(cached->digest, sizeof(cached->digest), hexbuf, - sizeof(hexbuf)); + char hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; + int r = rspamd_encode_hex_buf(cached->digest, sizeof(cached->digest), hexbuf, + sizeof(hexbuf)); lua_pushlstring(L, hexbuf, r); lua_rawseti(L, -2, part_idx++); } @@ -4334,7 +4334,7 @@ fuzzy_attach_controller(struct module_ctx *ctx, GHashTable *commands) /* TODO: move to a separate unit, as this file is now a bit too hard to read */ static void -lua_upstream_str_inserter(struct upstream *up, guint idx, void *ud) +lua_upstream_str_inserter(struct upstream *up, unsigned int idx, void *ud) { lua_State *L = (lua_State *) ud; @@ -4342,7 +4342,7 @@ lua_upstream_str_inserter(struct upstream *up, guint idx, void *ud) lua_rawseti(L, -2, idx + 1); } -static gint +static int fuzzy_lua_list_storages(lua_State *L) { struct rspamd_config *cfg = lua_check_config(L, 1); @@ -4353,7 +4353,7 @@ fuzzy_lua_list_storages(lua_State *L) struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(cfg); struct fuzzy_rule *rule; - guint i; + unsigned int i; lua_createtable(L, 0, fuzzy_module_ctx->fuzzy_rules->len); PTR_ARRAY_FOREACH(fuzzy_module_ctx->fuzzy_rules, i, rule) @@ -4398,8 +4398,8 @@ struct fuzzy_lua_session { GPtrArray *commands; struct fuzzy_rule *rule; struct rspamd_io_ev ev; - gint cbref; - gint fd; + int cbref; + int fd; }; static void @@ -4419,7 +4419,7 @@ static gboolean fuzzy_lua_session_is_completed(struct fuzzy_lua_session *session) { struct fuzzy_cmd_io *io; - guint nreplied = 0, i; + unsigned int nreplied = 0, i; for (i = 0; i < session->commands->len; i++) { @@ -4441,7 +4441,7 @@ fuzzy_lua_session_is_completed(struct fuzzy_lua_session *session) } static void -fuzzy_lua_push_result(struct fuzzy_lua_session *session, gdouble latency) +fuzzy_lua_push_result(struct fuzzy_lua_session *session, double latency) { lua_rawgeti(session->L, LUA_REGISTRYINDEX, session->cbref); lua_pushboolean(session->L, TRUE); @@ -4454,11 +4454,11 @@ fuzzy_lua_push_result(struct fuzzy_lua_session *session, gdouble latency) #ifdef __GNUC__ static void -fuzzy_lua_push_error(struct fuzzy_lua_session *session, const gchar *err_fmt, ...) __attribute__((format(printf, 2, 3))); +fuzzy_lua_push_error(struct fuzzy_lua_session *session, const char *err_fmt, ...) __attribute__((format(printf, 2, 3))); #endif static void -fuzzy_lua_push_error(struct fuzzy_lua_session *session, const gchar *err_fmt, ...) +fuzzy_lua_push_error(struct fuzzy_lua_session *session, const char *err_fmt, ...) { va_list v; @@ -4473,14 +4473,14 @@ fuzzy_lua_push_error(struct fuzzy_lua_session *session, const gchar *err_fmt, .. lua_pcall(session->L, 3, 0, 0); } -static gint +static int fuzzy_lua_try_read(struct fuzzy_lua_session *session) { const struct rspamd_fuzzy_reply *rep; struct rspamd_fuzzy_cmd *cmd = NULL; struct fuzzy_cmd_io *io = NULL; - gint r, ret; - guchar buf[2048], *p; + int r, ret; + unsigned char buf[2048], *p; if ((r = read(session->fd, buf, sizeof(buf) - 1)) == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { @@ -4520,10 +4520,10 @@ fuzzy_lua_try_read(struct fuzzy_lua_session *session) /* Fuzzy check callback */ static void -fuzzy_lua_io_callback(gint fd, short what, void *arg) +fuzzy_lua_io_callback(int fd, short what, void *arg) { struct fuzzy_lua_session *session = arg; - gint r; + int r; enum { return_error = 0, @@ -4598,7 +4598,7 @@ fuzzy_lua_io_callback(gint fd, short what, void *arg) * @function fuzzy_check.ping_storage(task, callback, rule, timeout[, server_override]) * @return */ -static gint +static int fuzzy_lua_ping_storage(lua_State *L) { struct rspamd_task *task = lua_check_task(L, 1); @@ -4632,7 +4632,7 @@ fuzzy_lua_ping_storage(lua_State *L) rspamd_inet_addr_t *addr = NULL; if (lua_type(L, 5) == LUA_TSTRING) { - const gchar *server_name = lua_tostring(L, 5); + const char *server_name = lua_tostring(L, 5); enum rspamd_parse_host_port_result res; GPtrArray *addrs = g_ptr_array_new(); diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 510e1f70b..414e1b3a6 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -30,7 +30,7 @@ static const uint64_t rspamd_regexp_cb_magic = 0xca9d9649fc3e2659ULL; struct regexp_module_item { uint64_t magic; struct rspamd_expression *expr; - const gchar *symbol; + const char *symbol; struct ucl_lua_funcdata *lua_function; }; @@ -45,9 +45,9 @@ static void process_regexp_item(struct rspamd_task *task, /* Initialization */ -gint regexp_module_init(struct rspamd_config *cfg, struct module_ctx **ctx); -gint regexp_module_config(struct rspamd_config *cfg, bool validate); -gint regexp_module_reconfig(struct rspamd_config *cfg); +int regexp_module_init(struct rspamd_config *cfg, struct module_ctx **ctx); +int regexp_module_config(struct rspamd_config *cfg, bool validate); +int regexp_module_reconfig(struct rspamd_config *cfg); module_t regexp_module = { "regexp", @@ -56,7 +56,7 @@ module_t regexp_module = { regexp_module_reconfig, NULL, RSPAMD_MODULE_VER, - (guint) -1, + (unsigned int) -1, }; @@ -71,8 +71,8 @@ regexp_get_context(struct rspamd_config *cfg) static gboolean read_regexp_expression(rspamd_mempool_t *pool, struct regexp_module_item *chain, - const gchar *symbol, - const gchar *line, + const char *symbol, + const char *line, struct rspamd_mime_expr_ud *ud) { struct rspamd_expression *e = NULL; @@ -96,7 +96,7 @@ read_regexp_expression(rspamd_mempool_t *pool, /* Init function */ -gint regexp_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) +int regexp_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) { struct regexp_ctx *regexp_module_ctx; @@ -128,13 +128,13 @@ gint regexp_module_init(struct rspamd_config *cfg, struct module_ctx **ctx) return 0; } -gint regexp_module_config(struct rspamd_config *cfg, bool validate) +int regexp_module_config(struct rspamd_config *cfg, bool validate) { struct regexp_ctx *regexp_module_ctx = regexp_get_context(cfg); struct regexp_module_item *cur_item = NULL; const ucl_object_t *sec, *value, *elt; ucl_object_iter_t it = NULL; - gint res = TRUE, nre = 0, nlua = 0, nshots = cfg->default_max_shots; + int res = TRUE, nre = 0, nlua = 0, nshots = cfg->default_max_shots; if (!rspamd_config_is_module_enabled(cfg, "regexp")) { return TRUE; @@ -203,9 +203,9 @@ gint regexp_module_config(struct rspamd_config *cfg, bool validate) nlua++; } else if (value->type == UCL_OBJECT) { - const gchar *description = NULL, *group = NULL; - gdouble score = 0.0; - guint flags = 0, priority = 0; + const char *description = NULL, *group = NULL; + double score = 0.0; + unsigned int flags = 0, priority = 0; gboolean is_lua = FALSE, valid_expression = TRUE; struct rspamd_mime_expr_ud ud; @@ -456,7 +456,7 @@ gint regexp_module_config(struct rspamd_config *cfg, bool validate) return res; } -gint regexp_module_reconfig(struct rspamd_config *cfg) +int regexp_module_reconfig(struct rspamd_config *cfg) { return regexp_module_config(cfg, false); } @@ -464,13 +464,13 @@ gint regexp_module_reconfig(struct rspamd_config *cfg) static gboolean rspamd_lua_call_expression_func(struct ucl_lua_funcdata *lua_data, struct rspamd_task *task, - GArray *args, gdouble *res, - const gchar *symbol) + GArray *args, double *res, + const char *symbol) { lua_State *L = lua_data->L; struct rspamd_task **ptask; struct expression_argument *arg; - gint pop = 0, i, nargs = 0; + int pop = 0, i, nargs = 0; lua_rawgeti(L, LUA_REGISTRYINDEX, lua_data->idx); /* Now we got function in top of stack */ @@ -480,12 +480,12 @@ rspamd_lua_call_expression_func(struct ucl_lua_funcdata *lua_data, /* Now push all arguments */ if (args) { - for (i = 0; i < (gint) args->len; i++) { + for (i = 0; i < (int) args->len; i++) { arg = &g_array_index(args, struct expression_argument, i); if (arg) { switch (arg->type) { case EXPRESSION_ARGUMENT_NORMAL: - lua_pushstring(L, (const gchar *) arg->data); + lua_pushstring(L, (const char *) arg->data); break; case EXPRESSION_ARGUMENT_BOOL: lua_pushboolean(L, (gboolean) GPOINTER_TO_SIZE(arg->data)); @@ -533,7 +533,7 @@ process_regexp_item(struct rspamd_task *task, void *user_data) { struct regexp_module_item *item = user_data; - gdouble res = FALSE; + double res = FALSE; /* Non-threaded version */ if (item->lua_function) { diff --git a/src/ragel/rfc2047_parser.rl b/src/ragel/rfc2047_parser.rl index 88e107be1..09ba879f4 100644 --- a/src/ragel/rfc2047_parser.rl +++ b/src/ragel/rfc2047_parser.rl @@ -58,15 +58,15 @@ %% write data; gboolean -rspamd_rfc2047_parser (const gchar *in, gsize len, gint *pencoding, - const gchar **charset, gsize *charset_len, - const gchar **encoded, gsize *encoded_len) +rspamd_rfc2047_parser (const char *in, gsize len, int *pencoding, + const char **charset, gsize *charset_len, + const char **encoded, gsize *encoded_len) { const char *p = in, *pe = in + len, *encoded_start = NULL, *encoded_end = NULL, *charset_start = NULL, *charset_end = NULL, *eof = in + len; - gint encoding = RSPAMD_RFC2047_QP, cs = 0; + int encoding = RSPAMD_RFC2047_QP, cs = 0; %% write init; %% write exec; diff --git a/src/ragel/smtp_date_parser.rl b/src/ragel/smtp_date_parser.rl index 1521ed317..97969a786 100644 --- a/src/ragel/smtp_date_parser.rl +++ b/src/ragel/smtp_date_parser.rl @@ -19,7 +19,7 @@ rspamd_parse_smtp_date (const unsigned char *data, size_t len, GError **err) const unsigned char *p = data, *pe = data + len, *eof = data + len, *tmp = data; struct tm tm; glong tz = 0; - gint cs = 0, *stack = NULL;; + int cs = 0, *stack = NULL;; gsize top = 0; memset (&tm, 0, sizeof (tm)); diff --git a/src/ragel/smtp_ip_parser.rl b/src/ragel/smtp_ip_parser.rl index 617f731f2..8506328b7 100644 --- a/src/ragel/smtp_ip_parser.rl +++ b/src/ragel/smtp_ip_parser.rl @@ -42,7 +42,7 @@ rspamd_parse_smtp_ip (const char *data, size_t len, rspamd_mempool_t *pool) const char *p = data, *pe = data + len, *eof = data + len; const char *ip_start = NULL, *ip_end = NULL; gboolean in_v6 = FALSE; - gint cs = 0; + int cs = 0; %% write init; %% write exec; diff --git a/src/rspamadm/commands.c b/src/rspamadm/commands.c index d64b172a7..1eff95a86 100644 --- a/src/rspamadm/commands.c +++ b/src/rspamadm/commands.c @@ -44,11 +44,11 @@ const struct rspamadm_command *commands[] = { const struct rspamadm_command * -rspamadm_search_command(const gchar *name, GPtrArray *all_commands) +rspamadm_search_command(const char *name, GPtrArray *all_commands) { const struct rspamadm_command *ret = NULL, *cmd; - const gchar *alias; - guint i, j; + const char *alias; + unsigned int i, j; if (name == NULL) { name = "help"; @@ -75,7 +75,7 @@ rspamadm_search_command(const gchar *name, GPtrArray *all_commands) void rspamadm_fill_internal_commands(GPtrArray *dest) { - guint i; + unsigned int i; for (i = 0; i < G_N_ELEMENTS(commands); i++) { if (commands[i]) { @@ -92,15 +92,15 @@ lua_thread_str_error_cb(struct thread_entry *thread, int ret, const char *msg) } static void -rspamadm_lua_command_run(gint argc, gchar **argv, +rspamadm_lua_command_run(int argc, char **argv, const struct rspamadm_command *cmd) { struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg); lua_State *L = thread->lua_state; - gint table_idx = GPOINTER_TO_INT(cmd->command_data); - gint i; + int table_idx = GPOINTER_TO_INT(cmd->command_data); + int i; /* Function */ lua_rawgeti(L, LUA_REGISTRYINDEX, table_idx); @@ -122,11 +122,11 @@ rspamadm_lua_command_run(gint argc, gchar **argv, lua_settop(L, 0); } -static const gchar * +static const char * rspamadm_lua_command_help(gboolean full_help, const struct rspamadm_command *cmd) { - gint table_idx = GPOINTER_TO_INT(cmd->command_data); + int table_idx = GPOINTER_TO_INT(cmd->command_data); if (full_help) { struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg); @@ -172,13 +172,13 @@ rspamadm_lua_command_help(gboolean full_help, void rspamadm_fill_lua_commands(lua_State *L, GPtrArray *dest) { - gint i; + int i; GPtrArray *lua_paths; GError *err = NULL; - const gchar *lualibdir = RSPAMD_LUALIBDIR, *path; + const char *lualibdir = RSPAMD_LUALIBDIR, *path; struct rspamadm_command *lua_cmd; - gchar search_dir[PATH_MAX]; + char search_dir[PATH_MAX]; if (g_hash_table_lookup(ucl_vars, "LUALIBDIR")) { lualibdir = g_hash_table_lookup(ucl_vars, "LUALIBDIR"); @@ -230,7 +230,7 @@ void rspamadm_fill_lua_commands(lua_State *L, GPtrArray *dest) } else { goffset ext_pos; - gchar *name; + char *name; name = g_path_get_basename(path); /* Remove .lua */ diff --git a/src/rspamadm/configdump.c b/src/rspamadm/configdump.c index dc8b82218..167b4c891 100644 --- a/src/rspamadm/configdump.c +++ b/src/rspamadm/configdump.c @@ -30,13 +30,13 @@ static gboolean modules_state = FALSE; static gboolean symbol_groups_only = FALSE; static gboolean symbol_full_details = FALSE; static gboolean skip_template = FALSE; -static gchar *config = NULL; +static char *config = NULL; extern struct rspamd_main *rspamd_main; /* Defined in modules.c */ extern module_t *modules[]; extern worker_t *workers[]; -static void rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *); +static void rspamadm_configdump(int argc, char **argv, const struct rspamadm_command *); static const char *rspamadm_configdump_help(gboolean full_help, const struct rspamadm_command *); struct rspamadm_command configdump_command = { @@ -234,16 +234,16 @@ rspamadm_dump_section_obj(struct rspamd_config *cfg, } __attribute__((noreturn)) static void -rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *cmd) +rspamadm_configdump(int argc, char **argv, const struct rspamadm_command *cmd) { GOptionContext *context; GError *error = NULL; - const gchar *confdir; + const char *confdir; const ucl_object_t *obj = NULL, *cur, *doc_obj; struct rspamd_config *cfg = rspamd_main->cfg; gboolean ret = TRUE; worker_t **pworker; - gint i; + int i; context = g_option_context_new( "configdump - dumps Rspamd configuration"); @@ -319,7 +319,7 @@ rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *cmd) const ucl_object_t *all_symbols_ucl = ucl_object_lookup(cfg->cfg_ucl_obj, "symbols"); while (g_hash_table_iter_next(&it, &sk, &sv)) { - const gchar *sym_name = (const gchar *) sk; + const char *sym_name = (const char *) sk; struct rspamd_symbol *s = (struct rspamd_symbol *) sv; ucl_object_t *this_sym_ucl = ucl_object_typed_new(UCL_OBJECT); @@ -364,7 +364,7 @@ rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *cmd) if (s->groups) { ucl_object_t *add_groups = ucl_object_typed_new(UCL_ARRAY); - guint j; + unsigned int j; struct rspamd_symbols_group *add_gr; bool has_extra_groups = false; @@ -428,7 +428,7 @@ rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *cmd) g_hash_table_iter_init(&it, cfg->groups); while (g_hash_table_iter_next(&it, &k, &v)) { - const gchar *gr_name = (const gchar *) k; + const char *gr_name = (const char *) k; struct rspamd_symbols_group *gr = (struct rspamd_symbols_group *) v; ucl_object_t *gr_ucl = ucl_object_typed_new(UCL_OBJECT); @@ -456,7 +456,7 @@ rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *cmd) ucl_object_t *sym_ucl = ucl_object_typed_new(UCL_OBJECT); while (g_hash_table_iter_next(&sit, &sk, &sv)) { - const gchar *sym_name = (const gchar *) sk; + const char *sym_name = (const char *) sk; struct rspamd_symbol *s = (struct rspamd_symbol *) sv; ucl_object_t *spec_sym = ucl_object_typed_new(UCL_OBJECT); @@ -486,7 +486,7 @@ rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *cmd) } ucl_object_t *add_groups = ucl_object_typed_new(UCL_ARRAY); - guint j; + unsigned int j; struct rspamd_symbols_group *add_gr; PTR_ARRAY_FOREACH(s->groups, j, add_gr) diff --git a/src/rspamadm/confighelp.c b/src/rspamadm/confighelp.c index 2ad07c0a6..196324d13 100644 --- a/src/rspamadm/confighelp.c +++ b/src/rspamadm/confighelp.c @@ -24,13 +24,13 @@ static gboolean json = FALSE; static gboolean compact = FALSE; static gboolean keyword = FALSE; -static const gchar *plugins_path = RSPAMD_PLUGINSDIR; +static const char *plugins_path = RSPAMD_PLUGINSDIR; extern struct rspamd_main *rspamd_main; /* Defined in modules.c */ extern module_t *modules[]; extern worker_t *workers[]; -static void rspamadm_confighelp(gint argc, gchar **argv, +static void rspamadm_confighelp(int argc, char **argv, const struct rspamadm_command *cmd); static const char *rspamadm_confighelp_help(gboolean full_help, @@ -81,7 +81,7 @@ rspamadm_confighelp_help(gboolean full_help, const struct rspamadm_command *cmd) } static void -rspamadm_confighelp_show(struct rspamd_config *cfg, gint argc, gchar **argv, +rspamadm_confighelp_show(struct rspamd_config *cfg, int argc, char **argv, const char *key, const ucl_object_t *obj) { rspamd_fstring_t *out; @@ -124,13 +124,13 @@ rspamadm_confighelp_show(struct rspamd_config *cfg, gint argc, gchar **argv, static void rspamadm_confighelp_search_word_step(const ucl_object_t *obj, ucl_object_t *res, - const gchar *str, + const char *str, gsize len, GString *path) { ucl_object_iter_t it = NULL; const ucl_object_t *cur, *elt; - const gchar *dot_pos; + const char *dot_pos; while ((cur = ucl_object_iterate(obj, &it, true)) != NULL) { if (cur->keylen > 0) { @@ -175,7 +175,7 @@ rspamadm_confighelp_search_word_step(const ucl_object_t *obj, } static ucl_object_t * -rspamadm_confighelp_search_word(const ucl_object_t *obj, const gchar *str) +rspamadm_confighelp_search_word(const ucl_object_t *obj, const char *str) { gsize len = strlen(str); GString *path = g_string_new(""); @@ -190,7 +190,7 @@ rspamadm_confighelp_search_word(const ucl_object_t *obj, const gchar *str) } __attribute__((noreturn)) static void -rspamadm_confighelp(gint argc, gchar **argv, const struct rspamadm_command *cmd) +rspamadm_confighelp(int argc, char **argv, const struct rspamadm_command *cmd) { struct rspamd_config *cfg; ucl_object_t *doc_obj; @@ -200,7 +200,7 @@ rspamadm_confighelp(gint argc, gchar **argv, const struct rspamadm_command *cmd) module_t *mod, **pmod; worker_t **pworker; struct module_ctx *mod_ctx; - gint i, ret = 0, processed_args = 0; + int i, ret = 0, processed_args = 0; context = g_option_context_new( "confighelp - displays help for the configuration options"); diff --git a/src/rspamadm/configtest.c b/src/rspamadm/configtest.c index f513f00f9..67f2e0bb5 100644 --- a/src/rspamadm/configtest.c +++ b/src/rspamadm/configtest.c @@ -21,7 +21,7 @@ #include "lua/lua_common.h" static gboolean quiet = FALSE; -static gchar *config = NULL; +static char *config = NULL; static gboolean strict = FALSE; static gboolean skip_template = FALSE; extern struct rspamd_main *rspamd_main; @@ -29,7 +29,7 @@ extern struct rspamd_main *rspamd_main; extern module_t *modules[]; extern worker_t *workers[]; -static void rspamadm_configtest(gint argc, gchar **argv, +static void rspamadm_configtest(int argc, char **argv, const struct rspamadm_command *cmd); static const char *rspamadm_configtest_help(gboolean full_help, const struct rspamadm_command *cmd); @@ -79,11 +79,11 @@ config_logger(rspamd_mempool_t *pool, gpointer ud) } static void -rspamadm_configtest(gint argc, gchar **argv, const struct rspamadm_command *cmd) +rspamadm_configtest(int argc, char **argv, const struct rspamadm_command *cmd) { GOptionContext *context; GError *error = NULL; - const gchar *confdir; + const char *confdir; struct rspamd_config *cfg = rspamd_main->cfg; gboolean ret = TRUE; worker_t **pworker; @@ -106,7 +106,7 @@ rspamadm_configtest(gint argc, gchar **argv, const struct rspamadm_command *cmd) g_option_context_free(context); if (config == NULL) { - static gchar fbuf[PATH_MAX]; + static char fbuf[PATH_MAX]; if ((confdir = g_hash_table_lookup(ucl_vars, "CONFDIR")) == NULL) { confdir = RSPAMD_CONFDIR; diff --git a/src/rspamadm/control.c b/src/rspamadm/control.c index c82d4ac0c..381bdaa7a 100644 --- a/src/rspamadm/control.c +++ b/src/rspamadm/control.c @@ -25,13 +25,13 @@ #include "libutil/util.h" #include "lua/lua_common.h" -static gchar *control_path = RSPAMD_DBDIR "/rspamd.sock"; +static char *control_path = RSPAMD_DBDIR "/rspamd.sock"; static gboolean json = FALSE; static gboolean ucl = TRUE; static gboolean compact = FALSE; -static gdouble timeout = 1.0; +static double timeout = 1.0; -static void rspamadm_control(gint argc, gchar **argv, +static void rspamadm_control(int argc, char **argv, const struct rspamadm_command *cmd); static const char *rspamadm_control_help(gboolean full_help, const struct rspamadm_command *cmd); @@ -45,9 +45,9 @@ struct rspamadm_command control_command = { }; struct rspamadm_control_cbdata { - const gchar *path; - gint argc; - gchar **argv; + const char *path; + int argc; + char **argv; }; static GOptionEntry entries[] = { @@ -100,14 +100,14 @@ rspamd_control_error_handler(struct rspamd_http_connection *conn, GError *err) ev_break(rspamd_main->event_loop, EVBREAK_ALL); } -static gint +static int rspamd_control_finish_handler(struct rspamd_http_connection *conn, struct rspamd_http_message *msg) { struct ucl_parser *parser; ucl_object_t *obj; rspamd_fstring_t *out; - const gchar *body; + const char *body; gsize body_len; struct rspamadm_control_cbdata *cbdata = conn->ud; @@ -161,11 +161,11 @@ end: } static void -rspamadm_control(gint argc, gchar **argv, const struct rspamadm_command *_cmd) +rspamadm_control(int argc, char **argv, const struct rspamadm_command *_cmd) { GOptionContext *context; GError *error = NULL; - const gchar *cmd, *path = NULL; + const char *cmd, *path = NULL; struct rspamd_http_connection *conn; struct rspamd_http_message *msg; rspamd_inet_addr_t *addr; diff --git a/src/rspamadm/fuzzy_convert.c b/src/rspamadm/fuzzy_convert.c index a4da8bdbc..5f6c298b2 100644 --- a/src/rspamadm/fuzzy_convert.c +++ b/src/rspamadm/fuzzy_convert.c @@ -34,14 +34,14 @@ #include "rspamadm.h" #include "lua/lua_common.h" -static gchar *source_db = NULL; -static gchar *redis_host = NULL; -static gchar *redis_db = NULL; -static gchar *redis_username = NULL; -static gchar *redis_password = NULL; +static char *source_db = NULL; +static char *redis_host = NULL; +static char *redis_db = NULL; +static char *redis_username = NULL; +static char *redis_password = NULL; static int64_t fuzzy_expiry = 0; -static void rspamadm_fuzzyconvert(gint argc, gchar **argv, +static void rspamadm_fuzzyconvert(int argc, char **argv, const struct rspamadm_command *cmd); static const char *rspamadm_fuzzyconvert_help(gboolean full_help, const struct rspamadm_command *cmd); @@ -93,7 +93,7 @@ rspamadm_fuzzyconvert_help(gboolean full_help, const struct rspamadm_command *cm } static void -rspamadm_fuzzyconvert(gint argc, gchar **argv, const struct rspamadm_command *cmd) +rspamadm_fuzzyconvert(int argc, char **argv, const struct rspamadm_command *cmd) { GOptionContext *context; GError *error = NULL; diff --git a/src/rspamadm/lua_repl.c b/src/rspamadm/lua_repl.c index a3d5541fd..1d6da5aa9 100644 --- a/src/rspamadm/lua_repl.c +++ b/src/rspamadm/lua_repl.c @@ -32,14 +32,14 @@ #include #endif -static gchar **paths = NULL; -static gchar **scripts = NULL; -static gchar **lua_args = NULL; -static gchar *histfile = NULL; -static guint max_history = 2000; -static gchar *serve = NULL; -static gchar *exec_line = NULL; -static gint batch = -1; +static char **paths = NULL; +static char **scripts = NULL; +static char **lua_args = NULL; +static char *histfile = NULL; +static unsigned int max_history = 2000; +static char *serve = NULL; +static char *exec_line = NULL; +static int batch = -1; extern struct rspamd_async_session *rspamadm_session; static const char *default_history_file = ".rspamd_repl.hist"; @@ -55,7 +55,7 @@ static Replxx *rx_instance = NULL; #endif #define MULTILINE_PROMPT "... " -static void rspamadm_lua(gint argc, gchar **argv, +static void rspamadm_lua(int argc, char **argv, const struct rspamadm_command *cmd); static const char *rspamadm_lua_help(gboolean full_help, const struct rspamadm_command *cmd); @@ -71,17 +71,17 @@ struct rspamadm_command lua_command = { /* * Dot commands */ -typedef void (*rspamadm_lua_dot_handler)(lua_State *L, gint argc, gchar **argv); +typedef void (*rspamadm_lua_dot_handler)(lua_State *L, int argc, char **argv); struct rspamadm_lua_dot_command { - const gchar *name; - const gchar *description; + const char *name; + const char *description; rspamadm_lua_dot_handler handler; }; -static void rspamadm_lua_help_handler(lua_State *L, gint argc, gchar **argv); -static void rspamadm_lua_load_handler(lua_State *L, gint argc, gchar **argv); -static void rspamadm_lua_exec_handler(lua_State *L, gint argc, gchar **argv); -static void rspamadm_lua_message_handler(lua_State *L, gint argc, gchar **argv); +static void rspamadm_lua_help_handler(lua_State *L, int argc, char **argv); +static void rspamadm_lua_load_handler(lua_State *L, int argc, char **argv); +static void rspamadm_lua_exec_handler(lua_State *L, int argc, char **argv); +static void rspamadm_lua_message_handler(lua_State *L, int argc, char **argv); static void lua_thread_error_cb(struct thread_entry *thread, int ret, const char *msg); static void lua_thread_finish_cb(struct thread_entry *thread, int ret); @@ -147,9 +147,9 @@ rspamadm_lua_help(gboolean full_help, const struct rspamadm_command *cmd) } static void -rspamadm_lua_add_path(lua_State *L, const gchar *path) +rspamadm_lua_add_path(lua_State *L, const char *path) { - const gchar *old_path; + const char *old_path; gsize len; GString *new_path; @@ -203,7 +203,7 @@ lua_thread_str_error_cb(struct thread_entry *thread, int ret, const char *msg) } static gboolean -rspamadm_lua_load_script(lua_State *L, const gchar *path) +rspamadm_lua_load_script(lua_State *L, const char *path) { struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg); L = thread->lua_state; @@ -226,12 +226,12 @@ rspamadm_lua_load_script(lua_State *L, const gchar *path) } static void -rspamadm_exec_input(lua_State *L, const gchar *input) +rspamadm_exec_input(lua_State *L, const char *input) { GString *tb; - gint i, cbref; + int i, cbref; int top = 0; - gchar outbuf[8192]; + char outbuf[8192]; struct lua_logger_trace tr; struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg); @@ -292,7 +292,7 @@ wait_session_events(void) msg_debug("finished events waiting, terminating session"); } -gint lua_repl_thread_call(struct thread_entry *thread, gint narg, gpointer ud, lua_thread_error_t error_func) +int lua_repl_thread_call(struct thread_entry *thread, int narg, gpointer ud, lua_thread_error_t error_func) { int ret; struct lua_call_data *cd = g_new0(struct lua_call_data, 1); @@ -320,9 +320,9 @@ gint lua_repl_thread_call(struct thread_entry *thread, gint narg, gpointer ud, l } static void -rspamadm_lua_help_handler(lua_State *L, gint argc, gchar **argv) +rspamadm_lua_help_handler(lua_State *L, int argc, char **argv) { - guint i; + unsigned int i; struct rspamadm_lua_dot_command *cmd; if (argv[1] == NULL) { @@ -349,9 +349,9 @@ rspamadm_lua_help_handler(lua_State *L, gint argc, gchar **argv) } static void -rspamadm_lua_load_handler(lua_State *L, gint argc, gchar **argv) +rspamadm_lua_load_handler(lua_State *L, int argc, char **argv) { - guint i; + unsigned int i; gboolean ret; for (i = 1; argv[i] != NULL; i++) { @@ -361,9 +361,9 @@ rspamadm_lua_load_handler(lua_State *L, gint argc, gchar **argv) } static void -rspamadm_lua_exec_handler(lua_State *L, gint argc, gchar **argv) +rspamadm_lua_exec_handler(lua_State *L, int argc, char **argv) { - gint i; + int i; struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg); L = thread->lua_state; @@ -385,14 +385,14 @@ rspamadm_lua_exec_handler(lua_State *L, gint argc, gchar **argv) } static void -rspamadm_lua_message_handler(lua_State *L, gint argc, gchar **argv) +rspamadm_lua_message_handler(lua_State *L, int argc, char **argv) { gulong cbref; - gint old_top, func_idx, i, j; + int old_top, func_idx, i, j; struct rspamd_task *task, **ptask; gpointer map; gsize len; - gchar outbuf[8192]; + char outbuf[8192]; struct lua_logger_trace tr; if (argv[1] == NULL) { @@ -474,10 +474,10 @@ rspamadm_lua_message_handler(lua_State *L, gint argc, gchar **argv) static gboolean -rspamadm_lua_try_dot_command(lua_State *L, const gchar *input) +rspamadm_lua_try_dot_command(lua_State *L, const char *input) { struct rspamadm_lua_dot_command *cmd; - gchar **argv; + char **argv; argv = g_strsplit_set(input + 1, " ", -1); @@ -504,7 +504,7 @@ rspamadm_lua_try_dot_command(lua_State *L, const gchar *input) } #ifdef WITH_LUA_REPL -static gint lex_ref_idx = -1; +static int lex_ref_idx = -1; static void lua_syntax_highlighter(const char *str, ReplxxColor *colours, int size, void *ud) @@ -539,7 +539,7 @@ lua_syntax_highlighter(const char *str, ReplxxColor *colours, int size, void *ud * 3 - line num (int), always 1... * 4 - column num (must be less than size) */ - const gchar *what; + const char *what; gsize column, tlen, cur_top, elt_pos; ReplxxColor elt_color = REPLXX_COLOR_DEFAULT; @@ -604,7 +604,7 @@ lua_syntax_highlighter(const char *str, ReplxxColor *colours, int size, void *ud static void rspamadm_lua_run_repl(lua_State *L, bool is_batch) { - gchar *input = NULL; + char *input = NULL; #ifdef WITH_LUA_REPL gboolean is_multiline = FALSE; GString *tb = NULL; @@ -649,7 +649,7 @@ rspamadm_lua_run_repl(lua_State *L, bool is_batch) L); if (!is_multiline) { - input = (gchar *) replxx_input(rx_instance, MAIN_PROMPT); + input = (char *) replxx_input(rx_instance, MAIN_PROMPT); if (input == NULL) { return; @@ -677,7 +677,7 @@ rspamadm_lua_run_repl(lua_State *L, bool is_batch) lua_settop(L, 0); } else { - input = (gchar *) replxx_input(rx_instance, MULTILINE_PROMPT); + input = (char *) replxx_input(rx_instance, MULTILINE_PROMPT); if (input == NULL) { g_string_free(tb, TRUE); @@ -719,7 +719,7 @@ struct rspamadm_lua_repl_session { struct rspamd_http_connection_router *rt; rspamd_inet_addr_t *addr; struct rspamadm_lua_repl_context *ctx; - gint sock; + int sock; }; static void @@ -729,7 +729,7 @@ rspamadm_lua_accept_cb(EV_P_ ev_io *w, int revents) (struct rspamadm_lua_repl_context *) w->data; rspamd_inet_addr_t *addr = NULL; struct rspamadm_lua_repl_session *session; - gint nfd; + int nfd; if ((nfd = rspamd_accept_from_socket(w->fd, &addr, NULL, NULL)) == -1) { @@ -789,10 +789,10 @@ rspamadm_lua_handle_exec(struct rspamd_http_connection_entry *conn_ent, struct rspamd_http_message *msg) { GString *tb; - gint err_idx, i; + int err_idx, i; lua_State *L; ucl_object_t *obj, *elt; - const gchar *body; + const char *body; gsize body_len; struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg); @@ -811,7 +811,7 @@ rspamadm_lua_handle_exec(struct rspamd_http_connection_entry *conn_ent, /* First try return + input */ tb = g_string_sized_new(body_len + sizeof("return ")); - rspamd_printf_gstring(tb, "return %*s", (gint) body_len, body); + rspamd_printf_gstring(tb, "return %*s", (int) body_len, body); if (luaL_loadstring(L, tb->str) != 0) { /* Reset stack */ @@ -855,12 +855,12 @@ rspamadm_lua_handle_exec(struct rspamd_http_connection_entry *conn_ent, } static void -rspamadm_lua(gint argc, gchar **argv, const struct rspamadm_command *cmd) +rspamadm_lua(int argc, char **argv, const struct rspamadm_command *cmd) { GOptionContext *context; GError *error = NULL; - gchar **elt; - guint i; + char **elt; + unsigned int i; lua_State *L = rspamd_main->cfg->lua_state; context = g_option_context_new("lua - run lua interpreter"); @@ -923,10 +923,10 @@ rspamadm_lua(gint argc, gchar **argv, const struct rspamadm_command *cmd) if (serve) { /* HTTP Server mode */ GPtrArray *addrs = NULL; - gchar *name = NULL; + char *name = NULL; struct ev_loop *ev_base; struct rspamd_http_connection_router *http; - gint fd; + int fd; struct rspamadm_lua_repl_context *ctx; if (rspamd_parse_host_port_priority(serve, &addrs, NULL, &name, @@ -971,7 +971,7 @@ rspamadm_lua(gint argc, gchar **argv, const struct rspamadm_command *cmd) } if (histfile == NULL) { - const gchar *homedir; + const char *homedir; GString *hist_path; homedir = getenv("HOME"); diff --git a/src/rspamadm/pw.c b/src/rspamadm/pw.c index 9fe9cd754..717b1b430 100644 --- a/src/rspamadm/pw.c +++ b/src/rspamadm/pw.c @@ -21,7 +21,7 @@ #include "rspamadm.h" #include "unix-std.h" -static void rspamadm_pw(gint argc, gchar **argv, +static void rspamadm_pw(int argc, char **argv, const struct rspamadm_command *cmd); static const char *rspamadm_pw_help(gboolean full_help, const struct rspamadm_command *cmd); @@ -31,8 +31,8 @@ static gboolean do_encrypt = FALSE; static gboolean do_check = FALSE; static gboolean quiet = FALSE; static gboolean list = FALSE; -static gchar *type = "catena"; -static gchar *password = NULL; +static char *type = "catena"; +static char *password = NULL; struct rspamadm_command pw_command = { .name = "pw", @@ -84,7 +84,7 @@ static const struct rspamd_controller_pbkdf * rspamadm_get_pbkdf(void) { const struct rspamd_controller_pbkdf *pbkdf; - guint i; + unsigned int i; for (i = 0; i < RSPAMD_PBKDF_ID_MAX - 1; i++) { pbkdf = &pbkdf_list[i]; @@ -104,8 +104,8 @@ static char * rspamadm_pw_encrypt(char *password) { const struct rspamd_controller_pbkdf *pbkdf; - guchar *salt, *key; - gchar *encoded_salt, *encoded_key; + unsigned char *salt, *key; + char *encoded_salt, *encoded_key; GString *result; gsize plen; @@ -151,11 +151,11 @@ rspamadm_pw_encrypt(char *password) return password; } -static const gchar * -rspamd_encrypted_password_get_str(const gchar *password, gsize skip, +static const char * +rspamd_encrypted_password_get_str(const char *password, gsize skip, gsize *length) { - const gchar *str, *start, *end; + const char *str, *start, *end; gsize size; start = password + skip; @@ -182,13 +182,13 @@ static void rspamadm_pw_check(void) { const struct rspamd_controller_pbkdf *pbkdf = NULL; - const gchar *salt, *hash; - const gchar *start, *end; - guchar *salt_decoded, *key_decoded, *local_key; + const char *salt, *hash; + const char *start, *end; + unsigned char *salt_decoded, *key_decoded, *local_key; gsize salt_len, key_len, size; - gchar test_password[8192], encrypted_password[8192]; + char test_password[8192], encrypted_password[8192]; gsize plen, i; - gint id; + int id; gboolean ret = FALSE; if (password == NULL) { @@ -211,7 +211,7 @@ rspamadm_pw_check(void) } if (size > 0) { - gchar *endptr; + char *endptr; id = strtoul(start, &endptr, 10); if ((endptr == NULL || *endptr == *end)) { @@ -307,11 +307,11 @@ rspamadm_pw_check(void) } } -static gint +static int rspamadm_pw_lua_encrypt(lua_State *L) { - const gchar *pw_in = NULL; - gchar *ret, *tmp = NULL; + const char *pw_in = NULL; + char *ret, *tmp = NULL; if (lua_type(L, 1) == LUA_TSTRING) { pw_in = lua_tostring(L, 1); @@ -341,7 +341,7 @@ static void rspamadm_alg_list(void) { const struct rspamd_controller_pbkdf *pbkdf; - guint i; + unsigned int i; for (i = 0; i < RSPAMD_PBKDF_ID_MAX - 1; i++) { pbkdf = &pbkdf_list[i]; @@ -352,7 +352,7 @@ rspamadm_alg_list(void) } static void -rspamadm_pw(gint argc, gchar **argv, const struct rspamadm_command *cmd) +rspamadm_pw(int argc, char **argv, const struct rspamadm_command *cmd) { GOptionContext *context; GError *error = NULL; @@ -382,7 +382,7 @@ rspamadm_pw(gint argc, gchar **argv, const struct rspamadm_command *cmd) } if (do_encrypt) { - gchar *encr = rspamadm_pw_encrypt(password); + char *encr = rspamadm_pw_encrypt(password); rspamd_printf("%s\n", encr); g_free(encr); } diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index 0b7a65006..e323880f3 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -32,7 +32,7 @@ static gboolean list_commands = FALSE; static gboolean show_help = FALSE; static gboolean show_version = FALSE; GHashTable *ucl_vars = NULL; -gchar **lua_env = NULL; +char **lua_env = NULL; struct rspamd_main *rspamd_main = NULL; struct rspamd_async_session *rspamadm_session = NULL; lua_State *L = NULL; @@ -41,7 +41,7 @@ lua_State *L = NULL; extern module_t *modules[]; extern worker_t *workers[]; -static void rspamadm_help(gint argc, gchar **argv, const struct rspamadm_command *); +static void rspamadm_help(int argc, char **argv, const struct rspamadm_command *); static const char *rspamadm_help_help(gboolean full_help, const struct rspamadm_command *); struct rspamadm_command help_command = { @@ -50,8 +50,8 @@ struct rspamadm_command help_command = { .help = rspamadm_help_help, .run = rspamadm_help}; -static gboolean rspamadm_parse_ucl_var(const gchar *option_name, - const gchar *value, gpointer data, +static gboolean rspamadm_parse_ucl_var(const char *option_name, + const char *value, gpointer data, GError **error); @@ -85,7 +85,7 @@ rspamadm_version(void) static void rspamadm_usage(GOptionContext *context) { - gchar *help_str; + char *help_str; help_str = g_option_context_get_help(context, TRUE, NULL); rspamd_printf("%s", help_str); @@ -95,7 +95,7 @@ static void rspamadm_commands(GPtrArray *all_commands) { const struct rspamadm_command *cmd; - guint i; + unsigned int i; rspamd_printf("Rspamadm %s\n", RVERSION); rspamd_printf("Usage: rspamadm [global_options] command [command_options]\n"); @@ -131,9 +131,9 @@ rspamadm_help_help(gboolean full_help, const struct rspamadm_command *cmd) } static void -rspamadm_help(gint argc, gchar **argv, const struct rspamadm_command *command) +rspamadm_help(int argc, char **argv, const struct rspamadm_command *command) { - const gchar *cmd_name; + const char *cmd_name; const struct rspamadm_command *cmd; GPtrArray *all_commands = (GPtrArray *) command->command_data; @@ -156,7 +156,7 @@ rspamadm_help(gint argc, gchar **argv, const struct rspamadm_command *command) } if (strcmp(cmd_name, "help") == 0) { - guint i; + unsigned int i; rspamd_printf("Available commands:\n"); PTR_ARRAY_FOREACH(all_commands, i, cmd) @@ -185,11 +185,11 @@ rspamadm_help(gint argc, gchar **argv, const struct rspamadm_command *command) } static gboolean -rspamadm_parse_ucl_var(const gchar *option_name, - const gchar *value, gpointer data, +rspamadm_parse_ucl_var(const char *option_name, + const char *value, gpointer data, GError **error) { - gchar *k, *v, *t; + char *k, *v, *t; t = strchr(value, '='); @@ -221,17 +221,17 @@ lua_thread_str_error_cb(struct thread_entry *thread, int ret, const char *msg) } gboolean -rspamadm_execute_lua_ucl_subr(gint argc, gchar **argv, +rspamadm_execute_lua_ucl_subr(int argc, char **argv, const ucl_object_t *res, - const gchar *script_name, + const char *script_name, gboolean rspamadm_subcommand) { struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg); lua_State *L = thread->lua_state; - gint i; - gchar str[PATH_MAX]; + int i; + char str[PATH_MAX]; g_assert(script_name != NULL); g_assert(res != NULL); @@ -293,7 +293,7 @@ rspamadm_execute_lua_ucl_subr(gint argc, gchar **argv, return TRUE; } -static gint +static int rspamdadm_commands_sort_func(gconstpointer a, gconstpointer b) { const struct rspamadm_command *cmda = *((struct rspamadm_command const **) a), @@ -303,7 +303,7 @@ rspamdadm_commands_sort_func(gconstpointer a, gconstpointer b) } static gboolean -rspamadm_command_maybe_match_name(const gchar *cmd, const gchar *input) +rspamadm_command_maybe_match_name(const char *cmd, const char *input) { gsize clen, inplen; @@ -366,23 +366,23 @@ rspamadm_cmd_dtor(gpointer p) } } -gint main(gint argc, gchar **argv, gchar **env) +int main(int argc, char **argv, char **env) { GError *error = NULL; GOptionContext *context; GOptionGroup *og; struct rspamd_config *cfg; GQuark process_quark; - gchar **nargv, **targv; - const gchar *cmd_name; + char **nargv, **targv; + const char *cmd_name; const struct rspamadm_command *cmd; struct rspamd_dns_resolver *resolver; GPtrArray *all_commands = g_ptr_array_new_full(32, rspamadm_cmd_dtor); /* Discovered during check */ - gint i, nargc, targc; + int i, nargc, targc; worker_t **pworker; gboolean lua_file = FALSE; - gint retcode = 0; + int retcode = 0; ucl_vars = g_hash_table_new_full(rspamd_strcase_hash, rspamd_strcase_equal, g_free, g_free); @@ -400,7 +400,7 @@ gint main(gint argc, gchar **argv, gchar **env) help_command.command_data = all_commands; /* Now read options and store everything till the first non-dash argument */ - nargv = g_malloc0(sizeof(gchar *) * (argc + 1)); + nargv = g_malloc0(sizeof(char *) * (argc + 1)); nargv[0] = g_strdup(argv[0]); for (i = 1, nargc = 1; i < argc; i++) { @@ -541,8 +541,8 @@ gint main(gint argc, gchar **argv, gchar **env) rspamd_fprintf(stderr, "Suggested commands:\n"); PTR_ARRAY_FOREACH(all_commands, i, cmd) { - guint j; - const gchar *alias; + unsigned int j; + const char *alias; if (rspamadm_command_maybe_match_name(cmd->name, cmd_name)) { rspamd_fprintf(stderr, "%s\n", cmd->name); @@ -564,13 +564,13 @@ gint main(gint argc, gchar **argv, gchar **env) if (nargc < argc) { if (lua_file) { - nargv = g_malloc0(sizeof(gchar *) * (argc - nargc + 2)); + nargv = g_malloc0(sizeof(char *) * (argc - nargc + 2)); nargv[1] = g_strdup(argv[nargc]); i = 2; argc++; } else { - nargv = g_malloc0(sizeof(gchar *) * (argc - nargc + 1)); + nargv = g_malloc0(sizeof(char *) * (argc - nargc + 1)); i = 1; } diff --git a/src/rspamadm/rspamadm.h b/src/rspamadm/rspamadm.h index 5fe51c319..e9063bb40 100644 --- a/src/rspamadm/rspamadm.h +++ b/src/rspamadm/rspamadm.h @@ -27,17 +27,17 @@ extern "C" { #endif extern GHashTable *ucl_vars; -extern gchar **lua_env; +extern char **lua_env; extern struct rspamd_main *rspamd_main; GQuark rspamadm_error(void); struct rspamadm_command; -typedef const gchar *(*rspamadm_help_func)(gboolean full_help, - const struct rspamadm_command *cmd); +typedef const char *(*rspamadm_help_func)(gboolean full_help, + const struct rspamadm_command *cmd); -typedef void (*rspamadm_run_func)(gint argc, gchar **argv, +typedef void (*rspamadm_run_func)(int argc, char **argv, const struct rspamadm_command *cmd); typedef void (*rspamadm_lua_exports_func)(gpointer lua_state); @@ -47,8 +47,8 @@ typedef void (*rspamadm_lua_exports_func)(gpointer lua_state); #define RSPAMADM_FLAG_DYNAMIC (1u << 2u) struct rspamadm_command { - const gchar *name; - guint flags; + const char *name; + unsigned int flags; rspamadm_help_func help; rspamadm_run_func run; rspamadm_lua_exports_func lua_subrs; @@ -59,16 +59,16 @@ struct rspamadm_command { extern const struct rspamadm_command *commands[]; extern struct rspamadm_command help_command; -const struct rspamadm_command *rspamadm_search_command(const gchar *name, +const struct rspamadm_command *rspamadm_search_command(const char *name, GPtrArray *all_commands); void rspamadm_fill_internal_commands(GPtrArray *dest); void rspamadm_fill_lua_commands(lua_State *L, GPtrArray *dest); -gboolean rspamadm_execute_lua_ucl_subr(gint argc, gchar **argv, +gboolean rspamadm_execute_lua_ucl_subr(int argc, char **argv, const ucl_object_t *res, - const gchar *script_name, + const char *script_name, gboolean rspamadm_subcommand); struct thread_entry; @@ -77,13 +77,13 @@ typedef void (*lua_thread_error_t)(struct thread_entry *thread, int ret, const c struct lua_call_data { - gint top; - gint ret; + int top; + int ret; gpointer ud; }; -gint lua_repl_thread_call(struct thread_entry *thread, gint narg, - gpointer ud, lua_thread_error_t error_func); +int lua_repl_thread_call(struct thread_entry *thread, int narg, + gpointer ud, lua_thread_error_t error_func); #ifdef __cplusplus } diff --git a/src/rspamadm/signtool.c b/src/rspamadm/signtool.c index b39b87058..612a67c83 100644 --- a/src/rspamadm/signtool.c +++ b/src/rspamadm/signtool.c @@ -30,16 +30,16 @@ static gboolean openssl = FALSE; static gboolean verify = FALSE; static gboolean quiet = FALSE; -static gchar *suffix = NULL; -static gchar *pubkey_file = NULL; -static gchar *pubkey = NULL; -static gchar *pubout = NULL; -static gchar *keypair_file = NULL; -static gchar *editor = NULL; +static char *suffix = NULL; +static char *pubkey_file = NULL; +static char *pubkey = NULL; +static char *pubout = NULL; +static char *keypair_file = NULL; +static char *editor = NULL; static gboolean edit = FALSE; enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519; -static void rspamadm_signtool(gint argc, gchar **argv, +static void rspamadm_signtool(int argc, char **argv, const struct rspamadm_command *cmd); static const char *rspamadm_signtool_help(gboolean full_help, const struct rspamadm_command *cmd); @@ -103,15 +103,15 @@ rspamadm_signtool_help(gboolean full_help, return help_str; } -static gint -rspamadm_edit_file(const gchar *fname) +static int +rspamadm_edit_file(const char *fname) { - gchar tmppath[PATH_MAX], run_cmdline[PATH_MAX]; - guchar *map; + char tmppath[PATH_MAX], run_cmdline[PATH_MAX]; + unsigned char *map; gsize len = 0; - gint fd_out, retcode, child_argc; + int fd_out, retcode, child_argc; GPid child_pid; - gchar *tmpdir, **child_argv = NULL; + char *tmpdir, **child_argv = NULL; struct stat st; GError *err = NULL; @@ -278,14 +278,14 @@ rspamadm_edit_file(const gchar *fname) } static bool -rspamadm_sign_file(const gchar *fname, struct rspamd_cryptobox_keypair *kp) +rspamadm_sign_file(const char *fname, struct rspamd_cryptobox_keypair *kp) { - gint fd_sig, fd_input; - guchar sig[rspamd_cryptobox_MAX_SIGBYTES], *map; - gchar sigpath[PATH_MAX]; + int fd_sig, fd_input; + unsigned char sig[rspamd_cryptobox_MAX_SIGBYTES], *map; + char sigpath[PATH_MAX]; FILE *pub_fp; struct stat st; - const guchar *sk; + const unsigned char *sk; if (suffix == NULL) { suffix = ".sig"; @@ -392,11 +392,11 @@ rspamadm_sign_file(const gchar *fname, struct rspamd_cryptobox_keypair *kp) } static bool -rspamadm_verify_file(const gchar *fname, const guchar *pk) +rspamadm_verify_file(const char *fname, const unsigned char *pk) { - gint fd_sig, fd_input; - guchar *map, *map_sig; - gchar sigpath[PATH_MAX]; + int fd_sig, fd_input; + unsigned char *map, *map_sig; + char sigpath[PATH_MAX]; struct stat st, st_sig; bool ret; @@ -442,7 +442,7 @@ rspamadm_verify_file(const gchar *fname, const guchar *pk) if (st_sig.st_size != rspamd_cryptobox_signature_bytes(mode)) { close(fd_sig); rspamd_fprintf(stderr, "invalid signature size %s: %ud\n", fname, - (guint) st_sig.st_size); + (unsigned int) st_sig.st_size); munmap(map, st.st_size); exit(EXIT_FAILURE); } @@ -476,7 +476,7 @@ rspamadm_verify_file(const gchar *fname, const guchar *pk) static void -rspamadm_signtool(gint argc, gchar **argv, const struct rspamadm_command *cmd) +rspamadm_signtool(int argc, char **argv, const struct rspamadm_command *cmd) { GOptionContext *context; GError *error = NULL; @@ -485,7 +485,7 @@ rspamadm_signtool(gint argc, gchar **argv, const struct rspamadm_command *cmd) struct rspamd_cryptobox_pubkey *pk; struct rspamd_cryptobox_keypair *kp; gsize fsize, flen; - gint i; + int i; context = g_option_context_new( "keypair - create encryption keys"); @@ -520,8 +520,8 @@ rspamadm_signtool(gint argc, gchar **argv, const struct rspamadm_command *cmd) g_assert(pubkey || pubkey_file); if (pubkey_file) { - gint fd; - gchar *map; + int fd; + char *map; struct stat st; fd = open(pubkey_file, O_RDONLY); @@ -555,7 +555,7 @@ rspamadm_signtool(gint argc, gchar **argv, const struct rspamadm_command *cmd) if (pk == NULL) { rspamd_fprintf(stderr, "bad size %s: %ud, %ud expected\n", pubkey_file, - (guint) flen, + (unsigned int) flen, rspamd_cryptobox_pk_sig_bytes(mode)); exit(EXIT_FAILURE); } @@ -569,7 +569,7 @@ rspamadm_signtool(gint argc, gchar **argv, const struct rspamadm_command *cmd) if (pk == NULL) { rspamd_fprintf(stderr, "bad size %s: %ud, %ud expected\n", pubkey_file, - (guint) strlen(pubkey), + (unsigned int) strlen(pubkey), rspamd_cryptobox_pk_sig_bytes(mode)); exit(EXIT_FAILURE); } diff --git a/src/rspamadm/stat_convert.c b/src/rspamadm/stat_convert.c index 0741279aa..bde15c037 100644 --- a/src/rspamadm/stat_convert.c +++ b/src/rspamadm/stat_convert.c @@ -20,25 +20,25 @@ #include "contrib/uthash/utlist.h" /* Common */ -static gchar *config_file = NULL; -static gchar *symbol_ham = NULL; -static gchar *symbol_spam = NULL; +static char *config_file = NULL; +static char *symbol_ham = NULL; +static char *symbol_spam = NULL; -static gdouble expire = 0.0; +static double expire = 0.0; /* Inputs */ -static gchar *spam_db = NULL; -static gchar *ham_db = NULL; -static gchar *cache_db = NULL; +static char *spam_db = NULL; +static char *ham_db = NULL; +static char *cache_db = NULL; /* Outputs */ -static gchar *redis_host = NULL; -static gchar *redis_db = NULL; -static gchar *redis_username = NULL; -static gchar *redis_password = NULL; +static char *redis_host = NULL; +static char *redis_db = NULL; +static char *redis_username = NULL; +static char *redis_password = NULL; static gboolean reset_previous = FALSE; -static void rspamadm_statconvert(gint argc, gchar **argv, +static void rspamadm_statconvert(int argc, char **argv, const struct rspamadm_command *cmd); static const char *rspamadm_statconvert_help(gboolean full_help, const struct rspamadm_command *cmd); @@ -111,7 +111,7 @@ rspamadm_statconvert_help(gboolean full_help, const struct rspamadm_command *cmd } static void -rspamadm_statconvert(gint argc, gchar **argv, const struct rspamadm_command *cmd) +rspamadm_statconvert(int argc, char **argv, const struct rspamadm_command *cmd) { GOptionContext *context; GError *error = NULL; diff --git a/src/rspamd.c b/src/rspamd.c index b8523b44b..8d4c83a28 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -1,5 +1,5 @@ /* - * Copyright 2023 Vsevolod Stakhov + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,7 +74,7 @@ static void rspamd_cld_handler(EV_P_ ev_child *w, struct rspamd_worker *wrk); /* Control socket */ -static gint control_fd; +static int control_fd; static ev_io control_ev; static struct rspamd_stat old_stat; static ev_timer stat_ev; @@ -84,17 +84,17 @@ static gboolean valgrind_mode = FALSE; /* Cmdline options */ static gboolean no_fork = FALSE; static gboolean show_version = FALSE; -static gchar **cfg_names = NULL; -static gchar *rspamd_user = NULL; -static gchar *rspamd_group = NULL; -static gchar *rspamd_pidfile = NULL; +static char **cfg_names = NULL; +static char *rspamd_user = NULL; +static char *rspamd_group = NULL; +static char *rspamd_pidfile = NULL; static gboolean is_debug = FALSE; static gboolean is_insecure = FALSE; static GHashTable *ucl_vars = NULL; -static gchar **lua_env = NULL; +static char **lua_env = NULL; static gboolean skip_template = FALSE; -static gint term_attempts = 0; +static int term_attempts = 0; /* List of active listen sockets indexed by worker type */ static GHashTable *listen_sockets = NULL; @@ -104,8 +104,8 @@ extern module_t *modules[]; extern worker_t *workers[]; /* Command line options */ -static gboolean rspamd_parse_var(const gchar *option_name, - const gchar *value, gpointer data, +static gboolean rspamd_parse_var(const char *option_name, + const char *value, gpointer data, GError **error); static GOptionEntry entries[] = { @@ -134,11 +134,11 @@ static GOptionEntry entries[] = {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}}; static gboolean -rspamd_parse_var(const gchar *option_name, - const gchar *value, gpointer data, +rspamd_parse_var(const char *option_name, + const char *value, gpointer data, GError **error) { - gchar *k, *v, *t; + char *k, *v, *t; t = strchr(value, '='); @@ -165,11 +165,11 @@ rspamd_parse_var(const gchar *option_name, } static void -read_cmd_line(gint *argc, gchar ***argv, struct rspamd_config *cfg) +read_cmd_line(int *argc, char ***argv, struct rspamd_config *cfg) { GError *error = NULL; GOptionContext *context; - guint cfg_num; + unsigned int cfg_num; context = g_option_context_new("- run rspamd daemon"); #if defined(GIT_VERSION) && GIT_VERSION == 1 @@ -311,7 +311,7 @@ static gboolean reread_config(struct rspamd_main *rspamd_main) { struct rspamd_config *tmp_cfg, *old_cfg; - gchar *cfg_file; + char *cfg_file; int load_opts = RSPAMD_CONFIG_INIT_VALIDATE | RSPAMD_CONFIG_INIT_SYMCACHE | RSPAMD_CONFIG_INIT_LIBS | RSPAMD_CONFIG_INIT_URL; @@ -362,7 +362,7 @@ struct waiting_worker { struct rspamd_main *rspamd_main; struct ev_timer wait_ev; struct rspamd_worker_conf *cf; - guint oldindex; + unsigned int oldindex; }; static void @@ -381,7 +381,7 @@ rspamd_fork_delayed_cb(EV_P_ ev_timer *w, int revents) static void rspamd_fork_delayed(struct rspamd_worker_conf *cf, - guint index, + unsigned int index, struct rspamd_main *rspamd_main) { struct waiting_worker *nw; @@ -397,12 +397,12 @@ rspamd_fork_delayed(struct rspamd_worker_conf *cf, } static GList * -create_listen_socket(GPtrArray *addrs, guint cnt, +create_listen_socket(GPtrArray *addrs, unsigned int cnt, enum rspamd_worker_socket_type listen_type) { GList *result = NULL; - gint fd; - guint i; + int fd; + unsigned int i; static const int listen_opts = RSPAMD_INET_ADDRESS_LISTEN_ASYNC; struct rspamd_worker_listen_socket *ls; @@ -442,13 +442,13 @@ create_listen_socket(GPtrArray *addrs, guint cnt, } static GList * -systemd_get_socket(struct rspamd_main *rspamd_main, const gchar *fdname) +systemd_get_socket(struct rspamd_main *rspamd_main, const char *fdname) { int number, sock, num_passed, flags; GList *result = NULL; - const gchar *e; - gchar **fdnames; - gchar *end; + const char *e; + char **fdnames; + char *end; struct stat st; static const int sd_listen_fds_start = 3; /* SD_LISTEN_FDS_START */ struct rspamd_worker_listen_socket *ls; @@ -460,7 +460,7 @@ systemd_get_socket(struct rspamd_main *rspamd_main, const gchar *fdname) struct sockaddr_in6 s6; } addr_storage; socklen_t slen = sizeof(addr_storage); - gint stype; + int stype; number = strtoul(fdname, &end, 10); if (end != NULL && *end != '\0') { @@ -561,13 +561,13 @@ static void pass_signal_cb(gpointer key, gpointer value, gpointer ud) { struct rspamd_worker *cur = value; - gint signo = GPOINTER_TO_INT(ud); + int signo = GPOINTER_TO_INT(ud); kill(cur->pid, signo); } static void -rspamd_pass_signal(GHashTable *workers, gint signo) +rspamd_pass_signal(GHashTable *workers, int signo) { g_hash_table_foreach(workers, pass_signal_cb, GINT_TO_POINTER(signo)); } @@ -576,10 +576,10 @@ static inline uintptr_t make_listen_key(struct rspamd_worker_bind_conf *cf) { rspamd_cryptobox_fast_hash_state_t st; - guint i, keylen = 0; - guint8 *key; + unsigned int i, keylen = 0; + uint8_t *key; rspamd_inet_addr_t *addr; - guint16 port; + uint16_t port; rspamd_cryptobox_fast_hash_init(&st, rspamd_hash_seed()); if (cf->is_systemd) { @@ -605,7 +605,7 @@ static void spawn_worker_type(struct rspamd_main *rspamd_main, struct ev_loop *event_loop, struct rspamd_worker_conf *cf) { - gint i; + int i; if (cf->count < 0) { msg_info_main("skip spawning of worker %s: disabled in configuration", @@ -645,7 +645,7 @@ spawn_workers(struct rspamd_main *rspamd_main, struct ev_loop *ev_base) gboolean listen_ok = FALSE; GPtrArray *seen_mandatory_workers; worker_t **cw, *wrk; - guint i; + unsigned int i; /* Special hack for hs_helper if it's not defined in a config */ seen_mandatory_workers = g_ptr_array_new(); @@ -851,9 +851,9 @@ struct core_check_cbdata { static struct core_check_cbdata cores_cbdata; -static gint -rspamd_check_core_cb(const gchar *path, const struct stat *st, - gint flag, struct FTW *ft) +static int +rspamd_check_core_cb(const char *path, const struct stat *st, + int flag, struct FTW *ft) { if (S_ISREG(st->st_mode)) { cores_cbdata.total_count++; @@ -1052,7 +1052,7 @@ rspamd_term_handler(struct ev_loop *loop, ev_signal *w, int revents) shutdown_ts = MAX(SOFT_SHUTDOWN_TIME, rspamd_main->cfg->task_timeout * 2.0); msg_info_main("catch termination signal, waiting for %d children for %.2f seconds", - (gint) g_hash_table_size(rspamd_main->workers), + (int) g_hash_table_size(rspamd_main->workers), valgrind_mode ? shutdown_ts * 10 : shutdown_ts); /* Stop srv events to avoid false notifications */ g_hash_table_foreach(rspamd_main->workers, stop_srv_ev, rspamd_main); @@ -1099,22 +1099,22 @@ rspamd_stat_update_handler(struct ev_loop *loop, ev_timer *w, int revents) { struct rspamd_main *rspamd_main = (struct rspamd_main *) w->data; struct rspamd_stat cur_stat; - gchar proctitle[128]; + char proctitle[128]; memcpy(&cur_stat, rspamd_main->stat, sizeof(cur_stat)); if (old_stat.messages_scanned > 0 && cur_stat.messages_scanned > old_stat.messages_scanned) { - gdouble rate = (double) (cur_stat.messages_scanned - old_stat.messages_scanned) / - w->repeat; - gdouble old_spam = old_stat.actions_stat[METRIC_ACTION_REJECT] + - old_stat.actions_stat[METRIC_ACTION_ADD_HEADER] + - old_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT]; - gdouble old_ham = old_stat.actions_stat[METRIC_ACTION_NOACTION]; - gdouble new_spam = cur_stat.actions_stat[METRIC_ACTION_REJECT] + - cur_stat.actions_stat[METRIC_ACTION_ADD_HEADER] + - cur_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT]; - gdouble new_ham = cur_stat.actions_stat[METRIC_ACTION_NOACTION]; + double rate = (double) (cur_stat.messages_scanned - old_stat.messages_scanned) / + w->repeat; + double old_spam = old_stat.actions_stat[METRIC_ACTION_REJECT] + + old_stat.actions_stat[METRIC_ACTION_ADD_HEADER] + + old_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT]; + double old_ham = old_stat.actions_stat[METRIC_ACTION_NOACTION]; + double new_spam = cur_stat.actions_stat[METRIC_ACTION_REJECT] + + cur_stat.actions_stat[METRIC_ACTION_ADD_HEADER] + + cur_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT]; + double new_ham = cur_stat.actions_stat[METRIC_ACTION_NOACTION]; gsize cnt = MAX_AVG_TIME_SLOTS; float sum = rspamd_sum_floats(cur_stat.avg_time.avg_time, &cnt); @@ -1227,7 +1227,7 @@ rspamd_control_handler(EV_P_ ev_io *w, int revents) { struct rspamd_main *rspamd_main = (struct rspamd_main *) w->data; rspamd_inet_addr_t *addr = NULL; - gint nfd; + int nfd; if ((nfd = rspamd_accept_from_socket(w->fd, &addr, NULL, NULL)) == -1) { @@ -1246,7 +1246,7 @@ rspamd_control_handler(EV_P_ ev_io *w, int revents) rspamd_control_process_client_socket(rspamd_main, nfd, addr); } -static guint +static unsigned int rspamd_spair_hash(gconstpointer p) { return rspamd_cryptobox_fast_hash(p, PAIR_ID_LEN, rspamd_hash_seed()); @@ -1261,7 +1261,7 @@ rspamd_spair_equal(gconstpointer a, gconstpointer b) static void rspamd_spair_close(gpointer p) { - gint *fds = p; + int *fds = p; close(fds[0]); close(fds[1]); @@ -1399,9 +1399,9 @@ rspamd_main_daemon(struct rspamd_main *rspamd_main) return TRUE; } -gint main(gint argc, gchar **argv, gchar **env) +int main(int argc, char **argv, char **env) { - gint i, res = 0; + int i, res = 0; struct sigaction signals, sigpipe_act; worker_t **pworker; GQuark type; @@ -1458,7 +1458,7 @@ gint main(gint argc, gchar **argv, gchar **env) /* Parse variables */ for (i = 0; i < argc; i++) { if (strchr(argv[i], '=') != NULL) { - gchar *k, *v, *t; + char *k, *v, *t; k = g_strdup(argv[i]); t = strchr(k, '='); @@ -1626,7 +1626,7 @@ gint main(gint argc, gchar **argv, gchar **env) if (event_loop) { int loop_type = ev_backend(event_loop); gboolean effective_backend; - const gchar *loop_str; + const char *loop_str; loop_str = rspamd_config_ev_backend_to_string(loop_type, &effective_backend); diff --git a/src/rspamd.h b/src/rspamd.h index f9a2d3c0b..60613ce0a 100644 --- a/src/rspamd.h +++ b/src/rspamd.h @@ -102,21 +102,21 @@ enum rspamd_worker_state { struct rspamd_worker { pid_t pid; /**< pid of worker */ pid_t ppid; /**< pid of parent */ - guint index; /**< index number */ - guint nconns; /**< current connections count */ + unsigned int index; /**< index number */ + unsigned int nconns; /**< current connections count */ enum rspamd_worker_state state; /**< current worker state */ gboolean cores_throttled; /**< set to true if cores throttling took place */ - gdouble start_time; /**< start time */ + double start_time; /**< start time */ struct rspamd_main *srv; /**< pointer to server structure */ GQuark type; /**< process type */ GHashTable *signal_events; /**< signal events */ struct rspamd_worker_accept_event *accept_events; /**< socket events */ struct rspamd_worker_conf *cf; /**< worker config data */ gpointer ctx; /**< worker's specific data */ - gint flags; /**< worker's flags (enum rspamd_worker_flags) */ - gint control_pipe[2]; /**< control pipe. [0] is used by main process, + int flags; /**< worker's flags (enum rspamd_worker_flags) */ + int control_pipe[2]; /**< control pipe. [0] is used by main process, [1] is used by a worker */ - gint srv_pipe[2]; /**< used by workers to request something from the + int srv_pipe[2]; /**< used by workers to request something from the main process. [0] - main, [1] - worker */ ev_io srv_ev; /**< used by main for read workers' requests */ struct rspamd_worker_heartbeat hb; /**< heartbeat data */ @@ -150,7 +150,7 @@ struct rspamd_worker_signal_handler_elt { }; struct rspamd_worker_signal_handler { - gint signo; + int signo; gboolean enabled; ev_signal ev_sig; struct ev_loop *event_loop; @@ -164,9 +164,9 @@ struct rspamd_worker_signal_handler { struct module_s; struct module_ctx { - gint (*filter)(struct rspamd_task *task); /**< pointer to headers process function */ - struct module_s *mod; /**< module pointer */ - gboolean enabled; /**< true if module is enabled in configuration */ + int (*filter)(struct rspamd_task *task); /**< pointer to headers process function */ + struct module_s *mod; /**< module pointer */ + gboolean enabled; /**< true if module is enabled in configuration */ }; #ifndef WITH_HYPERSCAN @@ -209,7 +209,7 @@ struct module_ctx { * Module */ typedef struct module_s { - const gchar *name; + const char *name; int (*module_init_func)(struct rspamd_config *cfg, struct module_ctx **ctx); @@ -220,10 +220,10 @@ typedef struct module_s { int (*module_attach_controller_func)(struct module_ctx *ctx, GHashTable *custom_commands); - guint module_version; + unsigned int module_version; uint64_t rspamd_version; - const gchar *rspamd_features; - guint ctx_offset; + const char *rspamd_features; + unsigned int ctx_offset; } module_t; enum rspamd_worker_socket_type { @@ -234,13 +234,13 @@ enum rspamd_worker_socket_type { struct rspamd_worker_listen_socket { const rspamd_inet_addr_t *addr; - gint fd; + int fd; enum rspamd_worker_socket_type type; bool is_systemd; }; typedef struct worker_s { - const gchar *name; + const char *name; gpointer (*worker_init_func)(struct rspamd_config *cfg); @@ -248,9 +248,9 @@ typedef struct worker_s { int flags; int listen_type; - guint worker_version; + unsigned int worker_version; uint64_t rspamd_version; - const gchar *rspamd_features; + const char *rspamd_features; } worker_t; /** @@ -288,12 +288,12 @@ struct RSPAMD_ALIGNED(64) rspamd_avg_time { * Server statistics */ struct RSPAMD_ALIGNED(64) rspamd_stat { - guint messages_scanned; /**< total number of messages scanned */ - guint actions_stat[METRIC_ACTION_MAX]; /**< statistic for each action */ - guint connections_count; /**< total connections count */ - guint control_connections_count; /**< connections count to control interface */ - guint messages_learned; /**< messages learned */ - struct rspamd_avg_time avg_time; /**< average time stats */ + unsigned int messages_scanned; /**< total number of messages scanned */ + unsigned int actions_stat[METRIC_ACTION_MAX]; /**< statistic for each action */ + unsigned int connections_count; /**< total connections count */ + unsigned int control_connections_count; /**< connections count to control interface */ + unsigned int messages_learned; /**< messages learned */ + struct rspamd_avg_time avg_time; /**< average time stats */ }; /** @@ -329,12 +329,12 @@ struct rspamd_main { struct controller_command; struct controller_session; -typedef gboolean (*controller_func_t)(gchar **args, +typedef gboolean (*controller_func_t)(char **args, struct controller_session *session); struct controller_session { struct rspamd_worker *worker; /**< pointer to worker structure (controller in fact) */ - gint sock; /**< socket descriptor */ + int sock; /**< socket descriptor */ struct controller_command *cmd; /**< real command */ struct rspamd_config *cfg; /**< pointer to config file */ GList *parts; /**< extracted mime parts */ @@ -346,7 +346,7 @@ struct controller_session { struct zstd_dictionary { void *dict; gsize size; - guint id; + unsigned int id; }; struct rspamd_external_libs_ctx { @@ -366,7 +366,7 @@ struct rspamd_external_libs_ctx { /** * Register custom controller function */ -void register_custom_controller_command(const gchar *name, +void register_custom_controller_command(const char *name, controller_func_t handler, gboolean privileged, gboolean require_message); diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index 0d8b6f60a..39df7c98d 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -85,27 +85,27 @@ worker_t rspamd_proxy_worker = { RSPAMD_WORKER_VER}; struct rspamd_http_upstream { - gchar *name; - gchar *settings_id; + char *name; + char *settings_id; struct upstream_list *u; struct rspamd_cryptobox_pubkey *key; - gdouble timeout; - gint parser_from_ref; - gint parser_to_ref; + double timeout; + int parser_from_ref; + int parser_to_ref; gboolean local; gboolean self_scan; gboolean compress; }; struct rspamd_http_mirror { - gchar *name; - gchar *settings_id; + char *name; + char *settings_id; struct upstream_list *u; struct rspamd_cryptobox_pubkey *key; - gdouble prob; - gdouble timeout; - gint parser_from_ref; - gint parser_to_ref; + double prob; + double timeout; + int parser_from_ref; + int parser_to_ref; gboolean local; gboolean compress; }; @@ -121,7 +121,7 @@ struct rspamd_proxy_ctx { /* Config */ struct rspamd_config *cfg; /* END OF COMMON PART */ - gdouble timeout; + double timeout; /* Encryption key for clients */ struct rspamd_cryptobox_keypair *key; /* HTTP context */ @@ -136,7 +136,7 @@ struct rspamd_proxy_ctx { /* Array of callback functions called on end of scan to compare results */ GArray *cmp_refs; /* Maximum count for retries */ - guint max_retries; + unsigned int max_retries; gboolean encrypted_only; /* If we have self_scanning backends, we need to work as a normal worker */ gboolean has_self_scan; @@ -147,17 +147,17 @@ struct rspamd_proxy_ctx { /* Quarantine messages instead of rejecting them */ gboolean quarantine_on_reject; /* Milter spam header */ - gchar *spam_header; + char *spam_header; /* CA name that can be used for client certificates */ - gchar *client_ca_name; + char *client_ca_name; /* Milter rejection message */ - gchar *reject_message; + char *reject_message; /* Sessions cache */ void *sessions_cache; struct rspamd_milter_context milter_ctx; /* Language detector */ struct rspamd_lang_detector *lang_det; - gdouble task_timeout; + double task_timeout; }; enum rspamd_backend_flags { @@ -169,19 +169,19 @@ enum rspamd_backend_flags { struct rspamd_proxy_session; struct rspamd_proxy_backend_connection { - const gchar *name; + const char *name; struct rspamd_cryptobox_keypair *local_key; struct rspamd_cryptobox_pubkey *remote_key; struct upstream *up; struct rspamd_http_connection *backend_conn; ucl_object_t *results; - const gchar *err; + const char *err; struct rspamd_proxy_session *s; - gint backend_sock; + int backend_sock; ev_tstamp timeout; enum rspamd_backend_flags flags; - gint parser_from_ref; - gint parser_to_ref; + int parser_from_ref; + int parser_to_ref; struct rspamd_task *task; }; @@ -200,15 +200,15 @@ struct rspamd_proxy_session { struct rspamd_milter_session *client_milter_conn; struct rspamd_http_upstream *backend; gpointer map; - gchar *fname; + char *fname; gpointer shmem_ref; struct rspamd_proxy_backend_connection *master_conn; struct rspamd_http_message *client_message; GPtrArray *mirror_conns; gsize map_len; - gint client_sock; + int client_sock; enum rspamd_proxy_legacy_support legacy_support; - gint retries; + int retries; ref_entry_t ref; }; @@ -222,11 +222,11 @@ rspamd_proxy_quark(void) static gboolean rspamd_proxy_parse_lua_parser(lua_State *L, const ucl_object_t *obj, - gint *ref_from, gint *ref_to, GError **err) + int *ref_from, int *ref_to, GError **err) { - const gchar *lua_script; + const char *lua_script; gsize slen; - gint err_idx, ref_idx; + int err_idx, ref_idx; gboolean has_ref = FALSE; g_assert(obj != NULL); @@ -663,9 +663,9 @@ rspamd_proxy_parse_script(rspamd_mempool_t *pool, struct rspamd_proxy_ctx *ctx; struct rspamd_rcl_struct_parser *pd = ud; lua_State *L; - const gchar *lua_script; + const char *lua_script; gsize slen; - gint err_idx, ref_idx; + int err_idx, ref_idx; struct stat st; ctx = pd->user_struct; @@ -763,7 +763,7 @@ init_rspamd_proxy(struct rspamd_config *cfg) (rspamd_mempool_destruct_t) rspamd_ptr_array_free_hard, ctx->mirrors); ctx->cfg = cfg; ctx->lua_state = cfg->lua_state; - ctx->cmp_refs = g_array_new(FALSE, FALSE, sizeof(gint)); + ctx->cmp_refs = g_array_new(FALSE, FALSE, sizeof(int)); rspamd_mempool_add_destructor(cfg->cfg_pool, (rspamd_mempool_destruct_t) rspamd_array_free_hard, ctx->cmp_refs); ctx->max_retries = DEFAULT_RETRIES; @@ -895,14 +895,14 @@ proxy_backend_close_connection(struct rspamd_proxy_backend_connection *conn) static gboolean proxy_backend_parse_results(struct rspamd_proxy_session *session, struct rspamd_proxy_backend_connection *conn, - lua_State *L, gint parser_ref, + lua_State *L, int parser_ref, struct rspamd_http_message *msg, goffset *body_offset, const rspamd_ftok_t *ct) { struct ucl_parser *parser; - gint err_idx; - const gchar *in = msg->body_buf.begin; + int err_idx; + const char *in = msg->body_buf.begin; gsize inlen = msg->body_buf.len; const rspamd_ftok_t *offset_hdr; @@ -953,7 +953,7 @@ proxy_backend_parse_results(struct rspamd_proxy_session *session, parser = ucl_parser_new(0); if (!ucl_parser_add_chunk(parser, in, inlen)) { - gchar *encoded; + char *encoded; encoded = rspamd_encode_base64(in, inlen, 0, NULL); msg_err_session("cannot parse input: %s", ucl_parser_get_error( @@ -974,10 +974,10 @@ proxy_backend_parse_results(struct rspamd_proxy_session *session, } static void -proxy_call_cmp_script(struct rspamd_proxy_session *session, gint cbref) +proxy_call_cmp_script(struct rspamd_proxy_session *session, int cbref) { - gint err_idx; - guint i; + int err_idx; + unsigned int i; struct rspamd_proxy_backend_connection *conn; lua_State *L; @@ -1015,7 +1015,7 @@ proxy_call_cmp_script(struct rspamd_proxy_session *session, gint cbref) } } - gchar log_tag[RSPAMD_LOG_ID_LEN + 1]; + char log_tag[RSPAMD_LOG_ID_LEN + 1]; rspamd_strlcpy(log_tag, session->pool->tag.uid, sizeof(log_tag)); lua_pushstring(L, log_tag); @@ -1031,13 +1031,13 @@ proxy_call_cmp_script(struct rspamd_proxy_session *session, gint cbref) static void proxy_session_dtor(struct rspamd_proxy_session *session) { - guint i; - gint cbref; + unsigned int i; + int cbref; struct rspamd_proxy_backend_connection *conn; if (session->master_conn && session->master_conn->results) { for (i = 0; i < session->ctx->cmp_refs->len; i++) { - cbref = g_array_index(session->ctx->cmp_refs, gint, i); + cbref = g_array_index(session->ctx->cmp_refs, int, i); proxy_call_cmp_script(session, cbref); } } @@ -1109,10 +1109,10 @@ proxy_session_dtor(struct rspamd_proxy_session *session) static void proxy_request_compress(struct rspamd_http_message *msg) { - guint flags; + unsigned int flags; ZSTD_CCtx *zctx; rspamd_fstring_t *body; - const gchar *in; + const char *in; gsize inlen; flags = rspamd_http_message_get_flags(msg); @@ -1153,7 +1153,7 @@ static void proxy_request_decompress(struct rspamd_http_message *msg) { rspamd_fstring_t *body; - const gchar *in; + const char *in; gsize inlen, outlen, r; ZSTD_DStream *zstream; ZSTD_inBuffer zin; @@ -1244,7 +1244,7 @@ proxy_check_file(struct rspamd_http_message *msg, { const rspamd_ftok_t *tok, *key_tok; rspamd_ftok_t srch; - gchar *file_str; + char *file_str; GHashTable *query_args; GHashTableIter it; gpointer k, v; @@ -1357,7 +1357,7 @@ proxy_backend_mirror_error_handler(struct rspamd_http_connection *conn, GError * REF_RELEASE(bk_conn->s); } -static gint +static int proxy_backend_mirror_finish_handler(struct rspamd_http_connection *conn, struct rspamd_http_message *msg) { @@ -1391,9 +1391,9 @@ proxy_backend_mirror_finish_handler(struct rspamd_http_connection *conn, static void proxy_open_mirror_connections(struct rspamd_proxy_session *session) { - gdouble coin; + double coin; struct rspamd_http_mirror *m; - guint i; + unsigned int i; struct rspamd_proxy_backend_connection *bk_conn; struct rspamd_http_message *msg; GError *err = NULL; @@ -1521,8 +1521,8 @@ proxy_open_mirror_connections(struct rspamd_proxy_session *session) } static void -proxy_client_write_error(struct rspamd_proxy_session *session, gint code, - const gchar *status) +proxy_client_write_error(struct rspamd_proxy_session *session, int code, + const char *status) { struct rspamd_http_message *reply; @@ -1618,7 +1618,7 @@ proxy_backend_master_error_handler(struct rspamd_http_connection *conn, GError * } } -static gint +static int proxy_backend_master_finish_handler(struct rspamd_http_connection *conn, struct rspamd_http_message *msg) { @@ -1691,7 +1691,7 @@ proxy_backend_master_finish_handler(struct rspamd_http_connection *conn, rspamd_http_message_free(msg); } else { - const gchar *passed_ct = NULL; + const char *passed_ct = NULL; if (orig_ct) { passed_ct = rspamd_mempool_ftokdup(session->pool, orig_ct); @@ -1756,7 +1756,7 @@ rspamd_proxy_scan_self_reply(struct rspamd_task *task) nsession = proxy_session_refresh(session); if (task->flags & RSPAMD_TASK_FLAG_MESSAGE_REWRITE) { - const gchar *start; + const char *start; goffset len, hdr_off; start = task->msg.begin; @@ -1843,7 +1843,7 @@ rspamd_proxy_self_scan(struct rspamd_proxy_session *session) { struct rspamd_task *task; struct rspamd_http_message *msg; - const gchar *data; + const char *data; gsize len; msg = session->client_message; @@ -1931,7 +1931,7 @@ proxy_send_master_message(struct rspamd_proxy_session *session) struct rspamd_http_upstream *backend = NULL; const rspamd_ftok_t *host; GError *err = NULL; - gchar hostbuf[512]; + char hostbuf[512]; host = rspamd_http_message_find_header(session->client_message, "Host"); @@ -1974,7 +1974,7 @@ proxy_send_master_message(struct rspamd_proxy_session *session) } /* Provide hash key if hashing based on source address is desired */ - guint hash_len; + unsigned int hash_len; gpointer hash_key = rspamd_inet_address_get_hash_key(session->client_addr, &hash_len); @@ -2134,7 +2134,7 @@ proxy_client_error_handler(struct rspamd_http_connection *conn, GError *err) REF_RELEASE(session); } -static gint +static int proxy_client_finish_handler(struct rspamd_http_connection *conn, struct rspamd_http_message *msg) { @@ -2205,7 +2205,7 @@ err: } static void -proxy_milter_finish_handler(gint fd, +proxy_milter_finish_handler(int fd, struct rspamd_milter_session *rms, void *ud) { @@ -2236,7 +2236,7 @@ proxy_milter_finish_handler(gint fd, } static void -proxy_milter_error_handler(gint fd, +proxy_milter_error_handler(int fd, struct rspamd_milter_session *rms, /* unused */ void *ud, GError *err) { @@ -2269,7 +2269,7 @@ proxy_accept_socket(EV_P_ ev_io *w, int revents) struct rspamd_proxy_ctx *ctx; rspamd_inet_addr_t *addr = NULL; struct rspamd_proxy_session *session; - gint nfd; + int nfd; ctx = worker->ctx; @@ -2341,7 +2341,7 @@ proxy_accept_socket(EV_P_ ev_io *w, int revents) #endif if (rspamd_inet_address_get_af(addr) != AF_UNIX) { - gint sopt = 1; + int sopt = 1; if (setsockopt(nfd, SOL_TCP, TCP_NODELAY, &sopt, sizeof(sopt)) == -1) { diff --git a/src/worker.c b/src/worker.c index f734fe41c..9bf27b260 100644 --- a/src/worker.c +++ b/src/worker.c @@ -69,7 +69,7 @@ worker_t normal_worker = { struct rspamd_worker_session { int64_t magic; struct rspamd_task *task; - gint fd; + int fd; rspamd_inet_addr_t *addr; struct rspamd_worker_ctx *ctx; struct rspamd_http_connection *http_conn; @@ -102,10 +102,10 @@ reduce_tasks_count(gpointer arg) } } -static gint +static int rspamd_worker_body_handler(struct rspamd_http_connection *conn, struct rspamd_http_message *msg, - const gchar *chunk, gsize len) + const char *chunk, gsize len) { struct rspamd_worker_session *session = (struct rspamd_worker_session *) conn->ud; struct rspamd_task *task; @@ -292,7 +292,7 @@ rspamd_worker_error_handler(struct rspamd_http_connection *conn, GError *err) } } -static gint +static int rspamd_worker_finish_handler(struct rspamd_http_connection *conn, struct rspamd_http_message *msg) { @@ -343,7 +343,7 @@ accept_socket(EV_P_ ev_io *w, int revents) struct rspamd_worker_ctx *ctx; struct rspamd_worker_session *session; rspamd_inet_addr_t *addr = NULL; - gint nfd, http_opts = 0; + int nfd, http_opts = 0; ctx = worker->ctx; diff --git a/test/rspamd_cryptobox_test.c b/test/rspamd_cryptobox_test.c index e6c68fb6a..b32b2822b 100644 --- a/test/rspamd_cryptobox_test.c +++ b/test/rspamd_cryptobox_test.c @@ -27,7 +27,7 @@ static const int random_fuzz_cnt = 10000; enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519; static void * -create_mapping(int mapping_len, guchar **beg, guchar **end) +create_mapping(int mapping_len, unsigned char **beg, unsigned char **end) { void *map; int psize = getpagesize(); @@ -38,7 +38,7 @@ create_mapping(int mapping_len, guchar **beg, guchar **end) memset(map, 0, mapping_len + psize * 3); mprotect(map, psize, PROT_NONE); /* Misalign pointer */ - *beg = ((guchar *) map) + psize + 1; + *beg = ((unsigned char *) map) + psize + 1; *end = *beg + mapping_len; mprotect(*beg + mapping_len - 1 + psize, psize, PROT_NONE); @@ -47,7 +47,7 @@ create_mapping(int mapping_len, guchar **beg, guchar **end) static void check_result(const rspamd_nm_t key, const rspamd_nonce_t nonce, - const rspamd_mac_t mac, guchar *begin, guchar *end) + const rspamd_mac_t mac, unsigned char *begin, unsigned char *end) { uint64_t *t = (uint64_t *) begin; @@ -62,10 +62,10 @@ check_result(const rspamd_nm_t key, const rspamd_nonce_t nonce, static int create_random_split(struct rspamd_cryptobox_segment *seg, int mseg, - guchar *begin, guchar *end) + unsigned char *begin, unsigned char *end) { gsize remain = end - begin; - gint used = 0; + int used = 0; while (remain > 0 && used < mseg - 1) { seg->data = begin; @@ -88,10 +88,10 @@ create_random_split(struct rspamd_cryptobox_segment *seg, int mseg, static int create_realistic_split(struct rspamd_cryptobox_segment *seg, int mseg, - guchar *begin, guchar *end) + unsigned char *begin, unsigned char *end) { gsize remain = end - begin; - gint used = 0; + int used = 0; static const int small_seg = 512, medium_seg = 2048; while (remain > 0 && used < mseg - 1) { @@ -126,10 +126,10 @@ create_realistic_split(struct rspamd_cryptobox_segment *seg, int mseg, static int create_constrained_split(struct rspamd_cryptobox_segment *seg, int mseg, int constraint, - guchar *begin, guchar *end) + unsigned char *begin, unsigned char *end) { gsize remain = end - begin; - gint used = 0; + int used = 0; while (remain > 0 && used < mseg - 1) { seg->data = begin; @@ -155,13 +155,13 @@ create_constrained_split(struct rspamd_cryptobox_segment *seg, int mseg, void rspamd_cryptobox_test_func(void) { void *map; - guchar *begin, *end; + unsigned char *begin, *end; rspamd_nm_t key; rspamd_nonce_t nonce; rspamd_mac_t mac; struct rspamd_cryptobox_segment *seg; double t1, t2; - gint i, cnt, ms; + int i, cnt, ms; gboolean checked_openssl = FALSE; map = create_mapping(mapping_size, &begin, &end); diff --git a/test/rspamd_dkim_test.c b/test/rspamd_dkim_test.c index 57e4d5a2f..0797f15dd 100644 --- a/test/rspamd_dkim_test.c +++ b/test/rspamd_dkim_test.c @@ -18,13 +18,13 @@ #include "rspamd.h" #include "dkim.h" -static const gchar test_dkim_sig[] = "v=1; a=rsa-sha256; c=relaxed/relaxed; " - "d=highsecure.ru; s=dkim; t=1410516996; " - "bh=guFoWYHWVzFRqVyAQebnvPcdm7bUQo7pRHt/uIHD7gs=; " - "h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding; " - "b=PCiECkOaPFb99DW+gApgfmdlTUo6XN6YXjnj52Cxoz2FoA857B0ZHFgeQe4JAKHuhW" - "oq3BLHap0GcMTTpSOgfQOKa8Df35Ns11JoOFjdBQ8GpM99kOrJP+vZcT8b7AMfthYm0Kwy" - "D9TjlkpScuoY5LjsWVnijh9dSNVLFqLatzg=;"; +static const char test_dkim_sig[] = "v=1; a=rsa-sha256; c=relaxed/relaxed; " + "d=highsecure.ru; s=dkim; t=1410516996; " + "bh=guFoWYHWVzFRqVyAQebnvPcdm7bUQo7pRHt/uIHD7gs=; " + "h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding; " + "b=PCiECkOaPFb99DW+gApgfmdlTUo6XN6YXjnj52Cxoz2FoA857B0ZHFgeQe4JAKHuhW" + "oq3BLHap0GcMTTpSOgfQOKa8Df35Ns11JoOFjdBQ8GpM99kOrJP+vZcT8b7AMfthYm0Kwy" + "D9TjlkpScuoY5LjsWVnijh9dSNVLFqLatzg=;"; extern struct ev_loop *event_loop; #if 0 diff --git a/test/rspamd_dns_test.c b/test/rspamd_dns_test.c index d77919342..d041351df 100644 --- a/test/rspamd_dns_test.c +++ b/test/rspamd_dns_test.c @@ -7,7 +7,7 @@ #include "async_session.h" #include "cfg_file.h" -static guint requests = 0; +static unsigned int requests = 0; extern struct ev_loop *event_loop; struct rspamd_dns_resolver *resolver; diff --git a/test/rspamd_heap_test.c b/test/rspamd_heap_test.c index dcc7bbc4d..711ad6aca 100644 --- a/test/rspamd_heap_test.c +++ b/test/rspamd_heap_test.c @@ -19,11 +19,11 @@ #include "heap.h" #include "ottery.h" -static const guint niter = 100500; -static const guint nrem = 100; +static const unsigned int niter = 100500; +static const unsigned int nrem = 100; static inline struct rspamd_min_heap_elt * -new_elt(guint pri) +new_elt(unsigned int pri) { struct rspamd_min_heap_elt *elt; @@ -33,13 +33,13 @@ new_elt(guint pri) return elt; } -static gdouble -heap_nelts_test(guint nelts) +static double +heap_nelts_test(unsigned int nelts) { struct rspamd_min_heap *heap; struct rspamd_min_heap_elt *elts; - gdouble t1, t2; - guint i; + double t1, t2; + unsigned int i; heap = rspamd_min_heap_create(nelts); /* Preallocate all elts */ @@ -70,9 +70,9 @@ void rspamd_heap_test_func(void) { struct rspamd_min_heap *heap; struct rspamd_min_heap_elt *elt, *telt; - guint i; - guint prev; - gdouble t[16]; + unsigned int i; + unsigned int prev; + double t[16]; /* Push + update */ heap = rspamd_min_heap_create(32); diff --git a/test/rspamd_lua_pcall_vs_resume_test.c b/test/rspamd_lua_pcall_vs_resume_test.c index 0502378c9..82de9bb8b 100644 --- a/test/rspamd_lua_pcall_vs_resume_test.c +++ b/test/rspamd_lua_pcall_vs_resume_test.c @@ -20,18 +20,18 @@ #include "unix-std.h" static const char *lua_src_name = "lua/pcall_test.lua"; -extern gchar *argv0_dirname; +extern char *argv0_dirname; extern struct rspamd_main *rspamd_main; const int N = 20000; -static gdouble -test_pcall(lua_State *L, gint function_call) +static double +test_pcall(lua_State *L, int function_call) { - gdouble t1, t2; - gint i; + double t1, t2; + int i; t1 = rspamd_get_virtual_ticks(); for (i = 0; i < N; i++) { @@ -45,11 +45,11 @@ test_pcall(lua_State *L, gint function_call) return t2 - t1; } -static gdouble -test_resume(lua_State *L, gint function_call) +static double +test_resume(lua_State *L, int function_call) { - gdouble t1, t2; - gint i; + double t1, t2; + int i; t1 = rspamd_get_virtual_ticks(); for (i = 0; i < N; i++) { @@ -69,11 +69,11 @@ test_resume(lua_State *L, gint function_call) return t2 - t1; } -static gdouble -test_resume_get_thread(gint function_call) +static double +test_resume_get_thread(int function_call) { - gdouble t1, t2; - gint i; + double t1, t2; + int i; struct thread_entry *ent; t1 = rspamd_get_virtual_ticks(); @@ -99,11 +99,11 @@ test_resume_get_thread(gint function_call) return t2 - t1; } -static gdouble -test_resume_get_new_thread(gint function_call) +static double +test_resume_get_new_thread(int function_call) { - gdouble t1, t2; - gint i; + double t1, t2; + int i; struct thread_entry *ent; t1 = rspamd_get_virtual_ticks(); @@ -132,8 +132,8 @@ test_resume_get_new_thread(gint function_call) void rspamd_lua_lua_pcall_vs_resume_test_func(void) { lua_State *L = rspamd_main->cfg->lua_state; - gchar *lua_src; - gdouble t1, reference; + char *lua_src; + double t1, reference; lua_src = g_build_filename(argv0_dirname, lua_src_name, NULL); if (luaL_dofile(L, lua_src) != 0) { @@ -142,19 +142,19 @@ void rspamd_lua_lua_pcall_vs_resume_test_func(void) } g_free(lua_src); - gint function_call = luaL_ref(L, LUA_REGISTRYINDEX); + int function_call = luaL_ref(L, LUA_REGISTRYINDEX); msg_info("calling"); reference = t1 = test_pcall(L, function_call); - msg_notice("pcall stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (gdouble) N, t1 / reference); + msg_notice("pcall stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (double) N, t1 / reference); t1 = test_resume(L, function_call); - msg_notice("resume stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (gdouble) N, t1 / reference); + msg_notice("resume stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (double) N, t1 / reference); t1 = test_resume_get_thread(function_call); - msg_notice("resume+get thread stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (gdouble) N, t1 / reference); + msg_notice("resume+get thread stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (double) N, t1 / reference); t1 = test_resume_get_new_thread(function_call); - msg_notice("resume+get [new] thread stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (gdouble) N, t1 / reference); + msg_notice("resume+get [new] thread stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (double) N, t1 / reference); } diff --git a/test/rspamd_lua_test.c b/test/rspamd_lua_test.c index 87cc9b7cf..2e5abe37c 100644 --- a/test/rspamd_lua_test.c +++ b/test/rspamd_lua_test.c @@ -24,9 +24,9 @@ #endif static const char *lua_src_name = "lua/tests.lua"; -extern gchar *lua_test; -extern gchar *lua_test_case; -extern gchar *argv0_dirname; +extern char *lua_test; +extern char *lua_test_case; +extern char *argv0_dirname; extern struct rspamd_main *rspamd_main; static int @@ -60,10 +60,10 @@ _Noreturn void rspamd_lua_test_func(void) { lua_State *L = (lua_State *) rspamd_main->cfg->lua_state; - gchar *lua_src, *rp, rp_buf[PATH_MAX], path_buf[PATH_MAX], *tmp, *dir, *pattern; - const gchar *old_path; + char *lua_src, *rp, rp_buf[PATH_MAX], path_buf[PATH_MAX], *tmp, *dir, *pattern; + const char *old_path; glob_t globbuf; - gint i, len; + int i, len; rspamd_lua_set_env(L, NULL, NULL, NULL); rspamd_lua_set_globals(rspamd_main->cfg, L); @@ -105,14 +105,14 @@ rspamd_lua_test_func(void) pattern = g_malloc(len); rspamd_snprintf(pattern, len, "%s/unit/%s", dir, "*.lua"); - gint lua_test_len = 0; - gint inserted_file = 1; - gint path_start; + int lua_test_len = 0; + int inserted_file = 1; + int path_start; if (lua_test) { lua_test_len = strlen(lua_test); } if (glob(pattern, GLOB_DOOFFS, NULL, &globbuf) == 0) { - for (i = 0; i < (gint) globbuf.gl_pathc; i++) { + for (i = 0; i < (int) globbuf.gl_pathc; i++) { if (lua_test) { path_start = strlen(globbuf.gl_pathv[i]) - lua_test_len; if (path_start < 0 || diff --git a/test/rspamd_radix_test.c b/test/rspamd_radix_test.c index 466f355cf..3d6aca3e7 100644 --- a/test/rspamd_radix_test.c +++ b/test/rspamd_radix_test.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,8 +20,8 @@ #include "btrie.h" const gsize max_elts = 500 * 1024; -const gint lookup_cycles = 1 * 1024; -const gint lookup_divisor = 10; +const int lookup_cycles = 1 * 1024; +const int lookup_divisor = 10; const uint masks[] = { 8, @@ -39,8 +39,8 @@ struct _tv { const char *nip; const char *m; uint32_t mask; - guint8 *addr; - guint8 *naddr; + uint8_t *addr; + uint8_t *naddr; gsize len; } test_vec[] = { {"192.168.1.1", "192.168.1.2", "32", 0, 0, 0, 0}, @@ -209,14 +209,14 @@ void rspamd_radix_test_func(void) struct { uint32_t addr; uint32_t mask; - guint8 addr6[16]; + uint8_t addr6[16]; uint32_t mask6; - guint8 addr64[16]; + uint8_t addr64[16]; } *addrs; gsize nelts, i, check; - gint lc; + int lc; gboolean all_good = TRUE; - gdouble ts1, ts2; + double ts1, ts2; double diff; /* Test suite for the compressed trie */ @@ -277,7 +277,7 @@ void rspamd_radix_test_func(void) msg_notice("Checked %hz elements in %.0f ticks (%.2f ticks per lookup)", nelts * lookup_cycles / lookup_divisor, diff, - diff / ((gdouble) nelts * lookup_cycles / lookup_divisor)); + diff / ((double) nelts * lookup_cycles / lookup_divisor)); rspamd_mempool_delete(pool); /* @@ -289,7 +289,7 @@ void rspamd_radix_test_func(void) ts1 = rspamd_get_ticks(TRUE); for (i = 0; i < nelts; i++) { - btrie_add_prefix(btrie, (guchar *) &addrs[i].addr, + btrie_add_prefix(btrie, (unsigned char *) &addrs[i].addr, addrs[i].mask, GSIZE_TO_POINTER(i + 1)); } ts2 = rspamd_get_ticks(TRUE); @@ -303,12 +303,12 @@ void rspamd_radix_test_func(void) for (i = 0; i < nelts / lookup_divisor; i++) { check = rspamd_random_uint64_fast() % nelts; - if (btrie_lookup(btrie, (guchar *) &addrs[check].addr, sizeof(addrs[check].addr) * 8) == NULL) { + if (btrie_lookup(btrie, (unsigned char *) &addrs[check].addr, sizeof(addrs[check].addr) * 8) == NULL) { char ipbuf[INET6_ADDRSTRLEN + 1]; all_good = FALSE; - inet_ntop(AF_INET, (guchar *) &addrs[check].addr, ipbuf, sizeof(ipbuf)); + inet_ntop(AF_INET, (unsigned char *) &addrs[check].addr, ipbuf, sizeof(ipbuf)); msg_notice("BAD btrie: {\"%s\", NULL, \"%ud\", 0, 0, 0, 0},", ipbuf, addrs[check].mask); @@ -322,7 +322,7 @@ void rspamd_radix_test_func(void) msg_notice("Checked %hz elements in %.0f ticks (%.2f ticks per lookup)", nelts * lookup_cycles / lookup_divisor, diff, - diff / ((gdouble) nelts * lookup_cycles / lookup_divisor)); + diff / ((double) nelts * lookup_cycles / lookup_divisor)); rspamd_mempool_delete(pool); /* @@ -355,7 +355,7 @@ void rspamd_radix_test_func(void) all_good = FALSE; - inet_ntop(AF_INET, (guchar *) &addrs[check].addr, ipbuf, sizeof(ipbuf)); + inet_ntop(AF_INET, (unsigned char *) &addrs[check].addr, ipbuf, sizeof(ipbuf)); msg_notice("BAD btrie: {\"%s\", NULL, \"%ud\", 0, 0, 0, 0},", ipbuf, addrs[check].mask); @@ -369,7 +369,7 @@ void rspamd_radix_test_func(void) msg_notice("Checked %hz elements in %.0f ticks (%.2f ticks per lookup)", nelts * lookup_cycles / lookup_divisor, diff, - diff / ((gdouble) nelts * lookup_cycles / lookup_divisor)); + diff / ((double) nelts * lookup_cycles / lookup_divisor)); rspamd_mempool_delete(pool); g_free(addrs); diff --git a/test/rspamd_rrd_test.c b/test/rspamd_rrd_test.c index 2860cd8f6..60cc72097 100644 --- a/test/rspamd_rrd_test.c +++ b/test/rspamd_rrd_test.c @@ -25,15 +25,15 @@ const int pdp_per_cdp = 60; void rspamd_rrd_test_func(void) { - gchar tmpfile[PATH_MAX]; + char tmpfile[PATH_MAX]; struct rrd_rra_def rra[4]; struct rrd_ds_def ds[2]; GArray ar; GError *err = NULL; struct rspamd_rrd_file *rrd; - gdouble ticks; - gint i; - gdouble t[2], cnt = 0.0; + double ticks; + int i; + double t[2], cnt = 0.0; rspamd_snprintf(tmpfile, sizeof(tmpfile), "/tmp/rspamd_rrd.rrd"); unlink(tmpfile); diff --git a/test/rspamd_shingles_test.c b/test/rspamd_shingles_test.c index 4c1c6472f..d1a10de84 100644 --- a/test/rspamd_shingles_test.c +++ b/test/rspamd_shingles_test.c @@ -19,10 +19,10 @@ #include "ottery.h" #include -static const gchar * +static const char * algorithm_to_string(enum rspamd_shingle_alg alg) { - const gchar *ret = "unknown"; + const char *ret = "unknown"; switch (alg) { case RSPAMD_SHINGLES_OLD: @@ -77,7 +77,7 @@ generate_fuzzy_words(gsize cnt, gsize max_len) } static void -permute_vector(GArray *in, gdouble prob) +permute_vector(GArray *in, double prob) { gsize i, total = 0; rspamd_ftok_t *w; @@ -85,7 +85,7 @@ permute_vector(GArray *in, gdouble prob) for (i = 0; i < in->len; i++) { if (ottery_rand_unsigned() <= G_MAXUINT * prob) { w = &g_array_index(in, rspamd_ftok_t, i); - generate_random_string((gchar *) w->begin, w->len); + generate_random_string((char *) w->begin, w->len); total++; } } @@ -105,14 +105,14 @@ free_fuzzy_words(GArray *ar) } static void -test_case(gsize cnt, gsize max_len, gdouble perm_factor, +test_case(gsize cnt, gsize max_len, double perm_factor, enum rspamd_shingle_alg alg) { GArray *input; struct rspamd_shingle *sgl, *sgl_permuted; - gdouble res; - guchar key[16]; - gdouble ts1, ts2; + double res; + unsigned char key[16]; + double ts1, ts2; ottery_rand_bytes(key, sizeof(key)); input = generate_fuzzy_words(cnt, max_len); @@ -280,7 +280,7 @@ void rspamd_shingles_test_func(void) { enum rspamd_shingle_alg alg = RSPAMD_SHINGLES_OLD; struct rspamd_shingle *sgl; - guchar key[16]; + unsigned char key[16]; GArray *input; rspamd_ftok_t tok; int i; @@ -289,7 +289,7 @@ void rspamd_shingles_test_func(void) input = g_array_sized_new(FALSE, FALSE, sizeof(rspamd_ftok_t), 5); for (i = 0; i < 5; i++) { - gchar *b = g_alloca(8); + char *b = g_alloca(8); memset(b, 0, 8); memcpy(b + 1, "test", 4); b[0] = 'a' + i; diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c index b3d03915f..7648cddd4 100644 --- a/test/rspamd_test_suite.c +++ b/test/rspamd_test_suite.c @@ -9,10 +9,10 @@ struct rspamd_main *rspamd_main = NULL; struct ev_loop *event_loop = NULL; worker_t *workers[] = {NULL}; -gchar *lua_test = NULL; -gchar *lua_test_case = NULL; +char *lua_test = NULL; +char *lua_test_case = NULL; gboolean verbose = FALSE; -gchar *argv0_dirname = NULL; +char *argv0_dirname = NULL; static GOptionEntry entries[] = { diff --git a/test/rspamd_upstream_test.c b/test/rspamd_upstream_test.c index 1f4e27daa..998a51f26 100644 --- a/test/rspamd_upstream_test.c +++ b/test/rspamd_upstream_test.c @@ -27,7 +27,7 @@ extern struct ev_loop *event_loop; static void rspamd_upstream_test_method(struct upstream_list *ls, - enum rspamd_upstream_rotation rot, const gchar *expected) + enum rspamd_upstream_rotation rot, const char *expected) { struct upstream *up; @@ -58,9 +58,9 @@ void rspamd_upstream_test_func(void) struct upstream *up, *upn; struct rspamd_dns_resolver *resolver; struct rspamd_config *cfg; - gint i, success = 0; - const gint assumptions = 100500; - gdouble p; + int i, success = 0; + const int assumptions = 100500; + double p; static ev_timer ev; rspamd_inet_addr_t *addr, *next_addr, *paddr; @@ -149,7 +149,7 @@ void rspamd_upstream_test_func(void) } } - p = 1.0 - fabs(3.0 / 4.0 - (gdouble) success / (gdouble) assumptions); + p = 1.0 - fabs(3.0 / 4.0 - (double) success / (double) assumptions); /* * P value is calculated as following: * when we add/remove M upstreams from the list, the probability of hash diff --git a/utils/base64.c b/utils/base64.c index d1202db53..f6ec71125 100644 --- a/utils/base64.c +++ b/utils/base64.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,16 +20,16 @@ #include "cryptobox.h" #include "unix-std.h" -static gdouble total_time = 0; +static double total_time = 0; static void -rspamd_process_file(const gchar *fname, gint decode) +rspamd_process_file(const char *fname, int decode) { - gint fd; + int fd; gpointer map; struct stat st; - guint8 *dest; + uint8_t *dest; gsize destlen; fd = open(fname, O_RDONLY); @@ -61,7 +61,7 @@ rspamd_process_file(const gchar *fname, gint decode) dest = rspamd_encode_base64(map, st.st_size, 80, &destlen); } - rspamd_printf("%*s", (gint) destlen, dest); + rspamd_printf("%*s", (int) destlen, dest); g_free(dest); munmap(map, st.st_size); @@ -69,7 +69,7 @@ rspamd_process_file(const gchar *fname, gint decode) int main(int argc, char **argv) { - gint i, start = 1, decode = 0; + int i, start = 1, decode = 0; if (argc > 2 && *argv[1] == '-') { start = 2; diff --git a/utils/rspamd_http_bench.c b/utils/rspamd_http_bench.c index 4cb153102..84f94a5ae 100644 --- a/utils/rspamd_http_bench.c +++ b/utils/rspamd_http_bench.c @@ -28,23 +28,23 @@ #include #endif -static guint port = 43000; -static gchar *host = "127.0.0.1"; -static gchar *server_key = NULL; -static guint cache_size = 10; -static guint nworkers = 1; +static unsigned int port = 43000; +static char *host = "127.0.0.1"; +static char *server_key = NULL; +static unsigned int cache_size = 10; +static unsigned int nworkers = 1; static gboolean openssl_mode = FALSE; -static guint file_size = 500; -static guint pconns = 100; -static gdouble test_time = 10.0; -static gchar *latencies_file = NULL; +static unsigned int file_size = 500; +static unsigned int pconns = 100; +static double test_time = 10.0; +static char *latencies_file = NULL; static gboolean csv_output = FALSE; /* Dynamic vars */ static rspamd_inet_addr_t *addr; static uint32_t workers_left = 0; static uint32_t *conns_done = NULL; -static const guint store_latencies = 1000; +static const unsigned int store_latencies = 1000; static uint32_t conns_pending = 0; static GOptionEntry entries[] = { @@ -73,16 +73,16 @@ static GOptionEntry entries[] = { {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}}; struct lat_elt { - gdouble lat; - guchar checked; + double lat; + unsigned char checked; }; static struct lat_elt *latencies; -static gint +static int rspamd_client_body(struct rspamd_http_connection *conn, struct rspamd_http_message *msg, - const gchar *chunk, gsize len) + const char *chunk, gsize len) { g_assert(chunk[0] == '\0'); @@ -92,7 +92,7 @@ rspamd_client_body(struct rspamd_http_connection *conn, struct client_cbdata { struct lat_elt *lat; uint32_t *wconns; - gdouble ts; + double ts; struct ev_loop *ev_base; }; @@ -107,7 +107,7 @@ rspamd_client_err(struct rspamd_http_connection *conn, GError *err) rspamd_http_connection_unref(conn); } -static gint +static int rspamd_client_finish(struct rspamd_http_connection *conn, struct rspamd_http_message *msg) { @@ -137,9 +137,9 @@ rspamd_http_client_func(struct ev_loop *ev_base, struct lat_elt *latency, { struct rspamd_http_message *msg; struct rspamd_http_connection *conn; - gchar urlbuf[PATH_MAX]; + char urlbuf[PATH_MAX]; struct client_cbdata *cb; - gint fd, flags; + int fd, flags; fd = rspamd_inet_address_connect(addr, SOCK_STREAM, TRUE); g_assert(fd != -1); @@ -176,7 +176,7 @@ rspamd_http_client_func(struct ev_loop *ev_base, struct lat_elt *latency, static void rspamd_worker_func(struct lat_elt *plat, uint32_t *wconns) { - guint i, j; + unsigned int i, j; struct ev_loop *ev_base; struct itimerval itv; struct rspamd_keypair_cache *c = NULL; @@ -224,8 +224,8 @@ cmpd(const void *p1, const void *p2) double rspamd_http_calculate_mean(struct lat_elt *lats, double *std) { - guint i, cnt, checked = 0; - gdouble mean = 0., dev = 0.; + unsigned int i, cnt, checked = 0; + double mean = 0., dev = 0.; cnt = store_latencies * pconns; qsort(lats, cnt, sizeof(*lats), cmpd); @@ -255,7 +255,7 @@ rspamd_http_calculate_mean(struct lat_elt *lats, double *std) static void rspamd_http_start_workers(pid_t *sfd) { - guint i; + unsigned int i; for (i = 0; i < nworkers; i++) { sfd[i] = fork(); g_assert(sfd[i] != -1); @@ -275,8 +275,8 @@ rspamd_http_start_workers(pid_t *sfd) static void rspamd_http_stop_workers(pid_t *sfd) { - guint i; - gint res; + unsigned int i; + int res; for (i = 0; i < nworkers; i++) { kill(sfd[i], SIGTERM); @@ -296,7 +296,7 @@ rspamd_http_bench_term(int fd, short what, void *arg) static void rspamd_http_bench_cld(int fd, short what, void *arg) { - gint res; + int res; while (waitpid(-1, &res, WNOHANG) > 0) { if (--workers_left == 0) { @@ -316,8 +316,8 @@ int main(int argc, char **argv) struct event term_ev, int_ev, cld_ev; uint64_t total_done; FILE *lat_file; - gdouble mean, std; - guint i; + double mean, std; + unsigned int i; rspamd_init_libs(); diff --git a/utils/rspamd_http_server.c b/utils/rspamd_http_server.c index ecd1d38c7..76e64e466 100644 --- a/utils/rspamd_http_server.c +++ b/utils/rspamd_http_server.c @@ -29,12 +29,12 @@ #include #endif -static guint port = 43000; -static guint cache_size = 10; -static guint nworkers = 1; +static unsigned int port = 43000; +static unsigned int cache_size = 10; +static unsigned int nworkers = 1; static gboolean openssl_mode = FALSE; static GHashTable *maps = NULL; -static gchar *key = NULL; +static char *key = NULL; static struct rspamd_keypair_cache *c; static struct rspamd_cryptobox_keypair *server_key; static struct timeval io_tv = { @@ -57,9 +57,9 @@ static GOptionEntry entries[] = { struct rspamd_http_server_session { struct rspamd_http_connection *conn; struct ev_loop *ev_base; - guint req_size; + unsigned int req_size; gboolean reply; - gint fd; + int fd; }; static void @@ -81,8 +81,8 @@ rspamd_server_finish(struct rspamd_http_connection *conn, struct rspamd_http_server_session *session = conn->ud; struct rspamd_http_message *reply; gulong size; - const gchar *url_str; - guint url_len; + const char *url_str; + unsigned int url_len; rspamd_fstring_t *body; if (!session->reply) { @@ -127,12 +127,12 @@ rspamd_server_finish(struct rspamd_http_connection *conn, } static void -rspamd_server_accept(gint fd, short what, void *arg) +rspamd_server_accept(int fd, short what, void *arg) { struct ev_loop *ev_base = arg; struct rspamd_http_server_session *session; rspamd_inet_addr_t *addr; - gint nfd; + int nfd; do { if ((nfd = @@ -168,7 +168,7 @@ rspamd_server_accept(gint fd, short what, void *arg) } static void -rspamd_http_term_handler(gint fd, short what, void *arg) +rspamd_http_term_handler(int fd, short what, void *arg) { struct ev_loop *ev_base = arg; struct timeval tv = {0, 0}; @@ -177,7 +177,7 @@ rspamd_http_term_handler(gint fd, short what, void *arg) } static void -rspamd_http_server_func(gint fd, rspamd_inet_addr_t *addr) +rspamd_http_server_func(int fd, rspamd_inet_addr_t *addr) { struct ev_loop *ev_base = event_init(); struct event accept_ev, term_ev; @@ -196,8 +196,8 @@ rspamd_http_server_func(gint fd, rspamd_inet_addr_t *addr) static void rspamd_http_start_servers(pid_t *sfd, rspamd_inet_addr_t *addr) { - guint i; - gint fd; + unsigned int i; + int fd; fd = rspamd_inet_address_listen(addr, SOCK_STREAM, TRUE); g_assert(fd != -1); @@ -218,8 +218,8 @@ rspamd_http_start_servers(pid_t *sfd, rspamd_inet_addr_t *addr) static void rspamd_http_stop_servers(pid_t *sfd) { - guint i; - gint res; + unsigned int i; + int res; for (i = 0; i < nworkers; i++) { kill(sfd[i], SIGTERM); @@ -236,7 +236,7 @@ rspamd_http_server_term(int fd, short what, void *arg) event_loopexit(NULL); } -int main(int argc, gchar **argv) +int main(int argc, char **argv) { GOptionContext *context; GError *error = NULL; -- 2.39.5