diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-18 18:56:33 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-18 18:56:33 +0000 |
commit | 14c13854d3cae9d93c3d148be30fb72f1eaffe55 (patch) | |
tree | 7b1a3e41b75490fac4d45722c90a1847543c6796 /src/libserver | |
parent | 6b2b4167187fee09365271cca182866ecb029af3 (diff) | |
download | rspamd-14c13854d3cae9d93c3d148be30fb72f1eaffe55.tar.gz rspamd-14c13854d3cae9d93c3d148be30fb72f1eaffe55.zip |
[Rework] Further types conversion (no functional changes)
Diffstat (limited to 'src/libserver')
81 files changed, 2606 insertions, 2574 deletions
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<std::pair<std::string, gpointer>, 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<rspamd_config *>(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<rspamd_rcl_symbol_data *>(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<rspamd_config *>(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<frozen }); static gboolean rspamd_rcl_worker_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<rspamd_config *>(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<rspamd_config *>(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<rspamd_config *>(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<rspamd_config *>(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>(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_map<frozen::string, e }); gboolean -rspamd_action_from_str(const gchar *data, enum rspamd_action_type *result) +rspamd_action_from_str(const char *data, enum rspamd_action_type *result) { auto maybe_action = rspamd::find_map(action_types, std::string_view{data}); @@ -2330,7 +2330,7 @@ rspamd_action_from_str(const gchar *data, enum rspamd_action_type *result) } } -const gchar * +const char * rspamd_action_to_str(enum rspamd_action_type action) { switch (action) { @@ -2359,7 +2359,7 @@ rspamd_action_to_str(enum rspamd_action_type action) return "unknown action"; } -const gchar * +const char * rspamd_action_to_str_alt(enum rspamd_action_type action) { switch (action) { @@ -2400,7 +2400,7 @@ rspamd_config_settings_elt_dtor(struct rspamd_config_settings_elt *e) } uint32_t -rspamd_config_name_to_id(const gchar *name, gsize namelen) +rspamd_config_name_to_id(const char *name, gsize namelen) { uint64_t h; @@ -2429,7 +2429,7 @@ rspamd_config_find_settings_id_ref(struct rspamd_config *cfg, 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) { uint32_t id; @@ -2439,7 +2439,7 @@ struct rspamd_config_settings_elt *rspamd_config_find_settings_name_ref( } 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) @@ -2561,7 +2561,7 @@ int rspamd_config_ev_backend_get(struct rspamd_config *cfg) return AUTO_BACKEND; } -const gchar * +const char * rspamd_config_ev_backend_to_string(int ev_backend, gboolean *effective) { #define SET_EFFECTIVE(b) \ @@ -2638,7 +2638,7 @@ rspamd_init_libs(void) #endif /* Configure utf8 library */ - guint utf8_flags = 0; + unsigned int utf8_flags = 0; if ((ctx->crypto_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<symbol_remove_data> 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=<number> 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 <unicode/uidna.h> -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 <prefix>_<number>_<value> <expire> <digest> @@ -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<guchar *>(decoded), &decoded_len); + reinterpret_cast<unsigned char *>(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<rspamd::html::html_tag *>(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<bool> tags_seen; std::vector<html_image *> images; std::vector<std::unique_ptr<struct html_tag>> 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 *> { 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, * <hyperscan blob> */ - 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<class rspamd::redis_pool *>(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 <unicode/ucnv.h> 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); |