diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-08 15:22:05 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-08 15:22:05 +0100 |
commit | c271eb36656a4ff88a9c8c1d59934949260275a3 (patch) | |
tree | 3dd586e38b5b37cfebc7c12b6ff6f434904167c7 /src/libutil | |
parent | b266445f47dec06392a7e058f499325fa3c052b9 (diff) | |
download | rspamd-c271eb36656a4ff88a9c8c1d59934949260275a3.tar.gz rspamd-c271eb36656a4ff88a9c8c1d59934949260275a3.zip |
[Rework] Add C++ guards to all headers
Diffstat (limited to 'src/libutil')
30 files changed, 785 insertions, 456 deletions
diff --git a/src/libutil/addr.h b/src/libutil/addr.h index 7efa5e318..fe00ccc86 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -35,6 +35,10 @@ #include "mem_pool.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * Opaque structure */ @@ -43,6 +47,7 @@ typedef struct rspamd_inet_addr_s rspamd_inet_addr_t; struct rspamd_radix_map_helper; struct rspamd_radix_map_helper **rspamd_inet_library_init (void); + void rspamd_inet_library_destroy (void); /** @@ -51,7 +56,7 @@ void rspamd_inet_library_destroy (void); * @param init * @return new inet addr */ -rspamd_inet_addr_t * rspamd_inet_address_new (int af, const void *init); +rspamd_inet_addr_t *rspamd_inet_address_new (int af, const void *init); /** * Create new inet address structure from struct sockaddr @@ -59,15 +64,15 @@ rspamd_inet_addr_t * rspamd_inet_address_new (int af, const void *init); * @param slen * @return */ -rspamd_inet_addr_t * rspamd_inet_address_from_sa (const struct sockaddr *sa, - socklen_t slen); +rspamd_inet_addr_t *rspamd_inet_address_from_sa (const struct sockaddr *sa, + socklen_t slen); /** * Create new inet address from rdns reply * @param rep reply element * @return new ipv4 or ipv6 addr (port is NOT set) */ -rspamd_inet_addr_t * rspamd_inet_address_from_rnds ( +rspamd_inet_addr_t *rspamd_inet_address_from_rnds ( const struct rdns_reply_entry *rep); /** @@ -79,7 +84,7 @@ rspamd_inet_addr_t * rspamd_inet_address_from_rnds ( * @return TRUE if the address has been parsed, otherwise `target` content is undefined */ gboolean rspamd_parse_inet_address_ip6 (const guchar *text, gsize len, - gpointer target); + gpointer target); /** * Parse string with ipv4 address of length `len` to `target` which should be @@ -90,7 +95,7 @@ gboolean rspamd_parse_inet_address_ip6 (const guchar *text, gsize len, * @return TRUE if the address has been parsed, otherwise `target` content is undefined */ gboolean rspamd_parse_inet_address_ip4 (const guchar *text, gsize len, - gpointer target); + gpointer target); /** * Parse ipv4 or ipv6 address to a static buffer `target`. Does not support Unix sockets @@ -100,7 +105,7 @@ gboolean rspamd_parse_inet_address_ip4 (const guchar *text, gsize len, * @return */ gboolean rspamd_parse_inet_address_ip (const char *src, - gsize srclen, rspamd_inet_addr_t *target); + gsize srclen, rspamd_inet_addr_t *target); /** * Try to parse address from string @@ -109,8 +114,8 @@ gboolean rspamd_parse_inet_address_ip (const char *src, * @return TRUE if addr has been parsed */ gboolean rspamd_parse_inet_address (rspamd_inet_addr_t **target, - const char *src, - gsize srclen); + const char *src, + gsize srclen); /** * Use memory pool allocated inet address @@ -119,23 +124,23 @@ gboolean rspamd_parse_inet_address (rspamd_inet_addr_t **target, * @param pool * @return */ -rspamd_inet_addr_t* rspamd_parse_inet_address_pool (const char *src, - gsize srclen, - rspamd_mempool_t *pool); +rspamd_inet_addr_t *rspamd_parse_inet_address_pool (const char *src, + gsize srclen, + rspamd_mempool_t *pool); /** * Returns string representation of inet address * @param addr * @return statically allocated string pointer (not thread safe) */ -const char * rspamd_inet_address_to_string (const rspamd_inet_addr_t *addr); +const char *rspamd_inet_address_to_string (const rspamd_inet_addr_t *addr); /** * Returns pretty string representation of inet address * @param addr * @return statically allocated string pointer (not thread safe) */ -const char * rspamd_inet_address_to_string_pretty (const rspamd_inet_addr_t *addr); +const char *rspamd_inet_address_to_string_pretty (const rspamd_inet_addr_t *addr); /** * Returns port number for the specified inet address in host byte order @@ -157,8 +162,8 @@ gint rspamd_inet_address_get_af (const rspamd_inet_addr_t *addr); * @param sz * @return */ -struct sockaddr* rspamd_inet_address_get_sa (const rspamd_inet_addr_t *addr, - socklen_t *sz); +struct sockaddr *rspamd_inet_address_get_sa (const rspamd_inet_addr_t *addr, + socklen_t *sz); /** * Makes a radix key from inet address @@ -166,7 +171,7 @@ struct sockaddr* rspamd_inet_address_get_sa (const rspamd_inet_addr_t *addr, * @param klen * @return */ -guchar * rspamd_inet_address_get_hash_key (const rspamd_inet_addr_t *addr, guint *klen); +guchar *rspamd_inet_address_get_hash_key (const rspamd_inet_addr_t *addr, guint *klen); /** * Receive data from an unconnected socket and fill the inet_addr structure if needed @@ -177,7 +182,7 @@ guchar * rspamd_inet_address_get_hash_key (const rspamd_inet_addr_t *addr, guint * @return same as recvfrom(2) */ gssize rspamd_inet_address_recvfrom (gint fd, void *buf, gsize len, gint fl, - rspamd_inet_addr_t **target); + rspamd_inet_addr_t **target); /** * Send data via unconnected socket using the specified inet_addr structure @@ -188,7 +193,7 @@ gssize rspamd_inet_address_recvfrom (gint fd, void *buf, gsize len, gint fl, * @return */ gssize rspamd_inet_address_sendto (gint fd, const void *buf, gsize len, gint fl, - const rspamd_inet_addr_t *addr); + const rspamd_inet_addr_t *addr); /** * Set port for inet address @@ -202,7 +207,7 @@ void rspamd_inet_address_set_port (rspamd_inet_addr_t *addr, uint16_t port); * @return newly created and connected socket */ int rspamd_inet_address_connect (const rspamd_inet_addr_t *addr, gint type, - gboolean async); + gboolean async); /** * Listen on a specified inet address @@ -212,7 +217,8 @@ int rspamd_inet_address_connect (const rspamd_inet_addr_t *addr, gint type, * @return */ int rspamd_inet_address_listen (const rspamd_inet_addr_t *addr, gint type, - gboolean async); + gboolean async); + /** * Check whether specified ip is valid (not INADDR_ANY or INADDR_NONE) for ipv4 or ipv6 * @param ptr pointer to struct in_addr or struct in6_addr @@ -221,7 +227,8 @@ int rspamd_inet_address_listen (const rspamd_inet_addr_t *addr, gint type, */ gboolean rspamd_ip_is_valid (const rspamd_inet_addr_t *addr); -typedef void (*rspamd_accept_throttling_handler)(gint, void *); +typedef void (*rspamd_accept_throttling_handler) (gint, void *); + /** * Accept from listening socket filling addr structure * @param sock listening socket @@ -241,9 +248,9 @@ gint rspamd_accept_from_socket (gint sock, * @return TRUE if string was parsed */ gboolean rspamd_parse_host_port_priority (const gchar *str, - GPtrArray **addrs, - guint *priority, gchar **name, guint default_port, - rspamd_mempool_t *pool); + GPtrArray **addrs, + guint *priority, gchar **name, guint default_port, + rspamd_mempool_t *pool); /** * Destroy the specified IP address @@ -265,7 +272,7 @@ void rspamd_inet_address_apply_mask (rspamd_inet_addr_t *addr, guint mask); * @return */ gint rspamd_inet_address_compare (const rspamd_inet_addr_t *a1, - const rspamd_inet_addr_t *a2, gboolean compare_ports); + const rspamd_inet_addr_t *a2, gboolean compare_ports); /** * Utility function to compare addresses by in g_ptr_array @@ -274,7 +281,8 @@ gint rspamd_inet_address_compare (const rspamd_inet_addr_t *a1, * @return */ gint rspamd_inet_address_compare_ptr (gconstpointer a1, - gconstpointer a2); + gconstpointer a2); + /** * Performs deep copy of rspamd inet addr * @param addr @@ -286,19 +294,21 @@ rspamd_inet_addr_t *rspamd_inet_address_copy (const rspamd_inet_addr_t *addr); * Returns hash for inet address (ignoring port) */ guint rspamd_inet_address_hash (gconstpointer a); + guint rspamd_inet_address_port_hash (gconstpointer a); /** * Returns true if two address are equal */ gboolean rspamd_inet_address_equal (gconstpointer a, gconstpointer b); + gboolean rspamd_inet_address_port_equal (gconstpointer a, gconstpointer b); /** * Returns TRUE if an address belongs to some local address */ gboolean rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr, - gboolean check_laddrs); + gboolean check_laddrs); /** * Returns size of storage required to store a complete IP address @@ -306,4 +316,8 @@ gboolean rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr, */ gsize rspamd_inet_address_storage_size (void); +#ifdef __cplusplus +} +#endif + #endif /* ADDR_H_ */ diff --git a/src/libutil/expression.h b/src/libutil/expression.h index bd336b87b..bd18fa75f 100644 --- a/src/libutil/expression.h +++ b/src/libutil/expression.h @@ -20,6 +20,10 @@ #include "mem_pool.h" #include "fstring.h" +#ifdef __cplusplus +extern "C" { +#endif + #define RSPAMD_EXPRESSION_MAX_PRIORITY 1024 #define RSPAMD_EXPRESSION_FLAG_NOOPT (1 << 0) @@ -56,17 +60,20 @@ typedef struct rspamd_expression_atom_s { gint priority; } rspamd_expression_atom_t; -typedef gdouble (*rspamd_expression_process_cb)(gpointer runtime_data, - rspamd_expression_atom_t *atom); +typedef gdouble (*rspamd_expression_process_cb) (gpointer runtime_data, + rspamd_expression_atom_t *atom); struct rspamd_atom_subr { /* Parses atom from string and returns atom structure */ - rspamd_expression_atom_t * (*parse)(const gchar *line, gsize len, - rspamd_mempool_t *pool, gpointer ud, GError **err); + rspamd_expression_atom_t *(*parse) (const gchar *line, gsize len, + rspamd_mempool_t *pool, gpointer ud, GError **err); + /* Process atom via the opaque pointer (e.g. struct rspamd_task *) */ rspamd_expression_process_cb process; + /* Calculates the relative priority of the expression */ gint (*priority) (rspamd_expression_atom_t *atom); + void (*destroy) (rspamd_expression_atom_t *atom); }; @@ -85,9 +92,9 @@ struct rspamd_expression; * @return TRUE if an expression have been parsed */ gboolean rspamd_parse_expression (const gchar *line, gsize len, - const struct rspamd_atom_subr *subr, gpointer subr_data, - rspamd_mempool_t *pool, GError **err, - struct rspamd_expression **target); + const struct rspamd_atom_subr *subr, gpointer subr_data, + rspamd_mempool_t *pool, GError **err, + struct rspamd_expression **target); /** * Process the expression and return its value using atom 'process' functions with the specified data pointer @@ -124,6 +131,7 @@ gdouble rspamd_process_expression_closure (struct rspamd_expression *expr, gint flags, gpointer runtime_ud, GPtrArray **track); + /** * Shows string representation of an expression * @param expr expression to show @@ -136,7 +144,7 @@ GString *rspamd_expression_tostring (struct rspamd_expression *expr); * and should not be modified within callback */ typedef void (*rspamd_expression_atom_foreach_cb) (const rspamd_ftok_t *atom, - gpointer ud); + gpointer ud); /** * Traverse over all atoms in the expression @@ -145,7 +153,7 @@ typedef void (*rspamd_expression_atom_foreach_cb) (const rspamd_ftok_t *atom, * @param ud opaque data passed to `cb` */ void rspamd_expression_atom_foreach (struct rspamd_expression *expr, - rspamd_expression_atom_foreach_cb cb, gpointer cbdata); + rspamd_expression_atom_foreach_cb cb, gpointer cbdata); /** * Checks if a specified node in AST is the specified operation @@ -155,4 +163,8 @@ void rspamd_expression_atom_foreach (struct rspamd_expression *expr, */ gboolean rspamd_expression_node_is_op (GNode *node, enum rspamd_expression_op op); +#ifdef __cplusplus +} +#endif + #endif /* SRC_LIBUTIL_EXPRESSION_H_ */ diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h index 1a4d25eb9..6102215d4 100644 --- a/src/libutil/fstring.h +++ b/src/libutil/fstring.h @@ -20,6 +20,10 @@ #include "mem_pool.h" #include <unicode/uchar.h> +#ifdef __cplusplus +extern "C" { +#endif + /** * Fixed strings library * These strings are NOT null-terminated for speed @@ -47,26 +51,26 @@ typedef struct f_str_unicode_tok { /** * Create new fixed length string */ -rspamd_fstring_t* rspamd_fstring_new (void) - G_GNUC_WARN_UNUSED_RESULT; +rspamd_fstring_t *rspamd_fstring_new (void) +G_GNUC_WARN_UNUSED_RESULT; /** * Create new fixed length string with preallocated size */ rspamd_fstring_t *rspamd_fstring_sized_new (gsize initial_size) - G_GNUC_WARN_UNUSED_RESULT; +G_GNUC_WARN_UNUSED_RESULT; /** * Create new fixed length string and initialize it with the initial data */ rspamd_fstring_t *rspamd_fstring_new_init (const gchar *init, gsize len) - G_GNUC_WARN_UNUSED_RESULT; +G_GNUC_WARN_UNUSED_RESULT; /** * Assign new value to fixed string */ rspamd_fstring_t *rspamd_fstring_assign (rspamd_fstring_t *str, - const gchar *init, gsize len) G_GNUC_WARN_UNUSED_RESULT; + const gchar *init, gsize len) G_GNUC_WARN_UNUSED_RESULT; /** * Free fixed length string @@ -76,14 +80,14 @@ void rspamd_fstring_free (rspamd_fstring_t *str); /** * Append data to a fixed length string */ -rspamd_fstring_t* rspamd_fstring_append (rspamd_fstring_t *str, - const char *in, gsize len) G_GNUC_WARN_UNUSED_RESULT; +rspamd_fstring_t *rspamd_fstring_append (rspamd_fstring_t *str, + const char *in, gsize len) G_GNUC_WARN_UNUSED_RESULT; /** * Append `len` repeated chars `c` to string `str` */ rspamd_fstring_t *rspamd_fstring_append_chars (rspamd_fstring_t *str, - char c, gsize len) G_GNUC_WARN_UNUSED_RESULT; + char c, gsize len) G_GNUC_WARN_UNUSED_RESULT; /** * Erase `len` characters at position `pos` @@ -96,14 +100,16 @@ void rspamd_fstring_erase (rspamd_fstring_t *str, gsize pos, gsize len); * Convert fixed string to a zero terminated string. This string must be * freed by a caller */ -char * rspamd_fstring_cstr (const rspamd_fstring_t *str) - G_GNUC_WARN_UNUSED_RESULT; +char *rspamd_fstring_cstr (const rspamd_fstring_t *str) +G_GNUC_WARN_UNUSED_RESULT; + /** * Convert fixed string usign ftok_t to a zero terminated string. This string must be * freed by a caller */ -char * rspamd_ftok_cstr (const rspamd_ftok_t *str) - G_GNUC_WARN_UNUSED_RESULT; +char *rspamd_ftok_cstr (const rspamd_ftok_t *str) +G_GNUC_WARN_UNUSED_RESULT; + /* * Return fast hash value for fixed string converted to lowercase */ @@ -113,31 +119,31 @@ guint32 rspamd_fstrhash_lc (const rspamd_ftok_t *str, gboolean is_utf); * Return true if two strings are equal */ gboolean rspamd_fstring_equal (const rspamd_fstring_t *s1, - const rspamd_fstring_t *s2); + const rspamd_fstring_t *s2); /** * Compare two fixed strings ignoring case */ gint rspamd_fstring_casecmp (const rspamd_fstring_t *s1, - const rspamd_fstring_t *s2); + const rspamd_fstring_t *s2); /** * Compare two fixed strings */ gint rspamd_fstring_cmp (const rspamd_fstring_t *s1, - const rspamd_fstring_t *s2); + const rspamd_fstring_t *s2); /** * Compare two fixed tokens ignoring case */ gint rspamd_ftok_casecmp (const rspamd_ftok_t *s1, - const rspamd_ftok_t *s2); + const rspamd_ftok_t *s2); /** * Compare two fixed tokens */ gint rspamd_ftok_cmp (const rspamd_ftok_t *s1, - const rspamd_ftok_t *s2); + const rspamd_ftok_t *s2); /** * Returns true if `s1` starts with `s2` @@ -152,7 +158,7 @@ gboolean rspamd_ftok_starts_with (const rspamd_ftok_t *s1, * Return TRUE if ftok is equal to specified C string */ gboolean rspamd_ftok_cstr_equal (const rspamd_ftok_t *s, - const gchar *pat, gboolean icase); + const gchar *pat, gboolean icase); /** * Free fstring_t that is mapped to ftok_t @@ -184,8 +190,8 @@ gsize rspamd_fstring_suggest_size (gsize len, gsize allocated, gsize needed_len) * @param needed_len * @return */ -rspamd_fstring_t * rspamd_fstring_grow (rspamd_fstring_t *str, - gsize needed_len) G_GNUC_WARN_UNUSED_RESULT; +rspamd_fstring_t *rspamd_fstring_grow (rspamd_fstring_t *str, + gsize needed_len) G_GNUC_WARN_UNUSED_RESULT; /** * Copies ftok to zero terminated string (must be freed using g_free) @@ -203,14 +209,17 @@ gchar *rspamd_fstringdup (const rspamd_fstring_t *src) G_GNUC_WARN_UNUSED_RESULT #define RSPAMD_FTOK_ASSIGN(t, lit) do { (t)->begin = (lit); (t)->len = sizeof(lit) - 1; } while (0) #define RSPAMD_FTOK_FROM_STR(t, str) do { \ - if (G_LIKELY(str)) { \ - (t)->begin = (const char*)(str); \ - (t)->len = strlen (str); \ - } \ - else { \ - (t)->begin = NULL; \ - (t)->len = 0; \ - } \ + if (G_LIKELY(str)) { \ + (t)->begin = (const char*)(str); \ + (t)->len = strlen (str); \ + } \ + else { \ + (t)->begin = NULL; \ + (t)->len = 0; \ + } \ } while (0) +#ifdef __cplusplus +} +#endif #endif diff --git a/src/libutil/hash.h b/src/libutil/hash.h index bae3cacfa..e1284a885 100644 --- a/src/libutil/hash.h +++ b/src/libutil/hash.h @@ -9,6 +9,10 @@ #include "config.h" +#ifdef __cplusplus +extern "C" { +#endif + struct rspamd_lru_hash_s; typedef struct rspamd_lru_hash_s rspamd_lru_hash_t; struct rspamd_lru_element_s; @@ -23,9 +27,9 @@ typedef struct rspamd_lru_element_s rspamd_lru_element_t; * @param key_equal_func pointer to function for comparing keys * @return new rspamd_hash object */ -rspamd_lru_hash_t * rspamd_lru_hash_new (gint maxsize, - GDestroyNotify key_destroy, - GDestroyNotify value_destroy); +rspamd_lru_hash_t *rspamd_lru_hash_new (gint maxsize, + GDestroyNotify key_destroy, + GDestroyNotify value_destroy); /** @@ -36,11 +40,11 @@ rspamd_lru_hash_t * rspamd_lru_hash_new (gint maxsize, * @param key_equal_func pointer to function for comparing keys * @return new rspamd_hash object */ -rspamd_lru_hash_t * rspamd_lru_hash_new_full (gint maxsize, - GDestroyNotify key_destroy, - GDestroyNotify value_destroy, - GHashFunc hfunc, - GEqualFunc eqfunc); +rspamd_lru_hash_t *rspamd_lru_hash_new_full (gint maxsize, + GDestroyNotify key_destroy, + GDestroyNotify value_destroy, + GHashFunc hfunc, + GEqualFunc eqfunc); /** * Lookup item from hash @@ -60,6 +64,7 @@ gpointer rspamd_lru_hash_lookup (rspamd_lru_hash_t *hash, */ gboolean rspamd_lru_hash_remove (rspamd_lru_hash_t *hash, gconstpointer key); + /** * Insert item in hash * @param hash hash object @@ -88,7 +93,7 @@ void rspamd_lru_hash_destroy (rspamd_lru_hash_t *hash); * @return new it or -1 if iteration has been reached over */ int rspamd_lru_hash_foreach (rspamd_lru_hash_t *hash, int it, gpointer *k, - gpointer *v); + gpointer *v); /** * Returns number of elements in a hash @@ -101,4 +106,9 @@ guint rspamd_lru_hash_size (rspamd_lru_hash_t *hash); * @param hash hash object */ guint rspamd_lru_hash_capacity (rspamd_lru_hash_t *hash); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libutil/heap.h b/src/libutil/heap.h index 7d6ef4fff..94501a740 100644 --- a/src/libutil/heap.h +++ b/src/libutil/heap.h @@ -18,6 +18,10 @@ #include "config.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * Binary minimal heap interface based on glib */ @@ -44,14 +48,14 @@ struct rspamd_min_heap *rspamd_min_heap_create (gsize reserved_size); * @param elt element to push */ void rspamd_min_heap_push (struct rspamd_min_heap *heap, - struct rspamd_min_heap_elt *elt); + struct rspamd_min_heap_elt *elt); /** * Pops the minimum element from the heap and reorder the queue * @param heap heap structure * @return minimum element */ -struct rspamd_min_heap_elt* rspamd_min_heap_pop (struct rspamd_min_heap *heap); +struct rspamd_min_heap_elt *rspamd_min_heap_pop (struct rspamd_min_heap *heap); /** * Updates priority for the element. It must be in queue (so `idx` should be sane) @@ -60,7 +64,7 @@ struct rspamd_min_heap_elt* rspamd_min_heap_pop (struct rspamd_min_heap *heap); * @param npri new priority */ void rspamd_min_heap_update_elt (struct rspamd_min_heap *heap, - struct rspamd_min_heap_elt *elt, guint npri); + struct rspamd_min_heap_elt *elt, guint npri); /** @@ -69,7 +73,7 @@ void rspamd_min_heap_update_elt (struct rspamd_min_heap *heap, * @param elt */ void rspamd_min_heap_remove_elt (struct rspamd_min_heap *heap, - struct rspamd_min_heap_elt *elt); + struct rspamd_min_heap_elt *elt); /** * Destroys heap (elements are not destroyed themselves) @@ -83,7 +87,11 @@ void rspamd_min_heap_destroy (struct rspamd_min_heap *heap); * @param idx * @return */ -struct rspamd_min_heap_elt* rspamd_min_heap_index (struct rspamd_min_heap *heap, - guint idx); +struct rspamd_min_heap_elt *rspamd_min_heap_index (struct rspamd_min_heap *heap, + guint idx); + +#ifdef __cplusplus +} +#endif #endif /* SRC_LIBUTIL_HEAP_H_ */ diff --git a/src/libutil/http_connection.h b/src/libutil/http_connection.h index fc1303446..1923e5953 100644 --- a/src/libutil/http_connection.h +++ b/src/libutil/http_connection.h @@ -33,6 +33,10 @@ #include "contrib/libev/ev.h" +#ifdef __cplusplus +extern "C" { +#endif + enum rspamd_http_connection_type { RSPAMD_HTTP_SERVER, RSPAMD_HTTP_CLIENT @@ -88,15 +92,15 @@ enum rspamd_http_options { }; typedef int (*rspamd_http_body_handler_t) (struct rspamd_http_connection *conn, - struct rspamd_http_message *msg, - const gchar *chunk, - gsize len); + struct rspamd_http_message *msg, + const gchar *chunk, + gsize len); typedef void (*rspamd_http_error_handler_t) (struct rspamd_http_connection *conn, - GError *err); + GError *err); typedef int (*rspamd_http_finish_handler_t) (struct rspamd_http_connection *conn, - struct rspamd_http_message *msg); + struct rspamd_http_message *msg); /** * HTTP connection structure @@ -195,14 +199,14 @@ struct rspamd_http_connection *rspamd_http_connection_new_client_socket ( * @param key opaque key structure */ void rspamd_http_connection_set_key (struct rspamd_http_connection *conn, - struct rspamd_cryptobox_keypair *key); + struct rspamd_cryptobox_keypair *key); /** * Get peer's public key * @param conn connection structure * @return pubkey structure or NULL */ -const struct rspamd_cryptobox_pubkey* rspamd_http_connection_get_peer_key ( +const struct rspamd_cryptobox_pubkey *rspamd_http_connection_get_peer_key ( struct rspamd_http_connection *conn); /** @@ -263,8 +267,7 @@ void rspamd_http_connection_free (struct rspamd_http_connection *conn); * @return */ static inline struct rspamd_http_connection * -rspamd_http_connection_ref (struct rspamd_http_connection *conn) -{ +rspamd_http_connection_ref (struct rspamd_http_connection *conn) { conn->ref++; return conn; } @@ -274,8 +277,7 @@ rspamd_http_connection_ref (struct rspamd_http_connection *conn) * @param conn */ static void -rspamd_http_connection_unref (struct rspamd_http_connection *conn) -{ +rspamd_http_connection_unref (struct rspamd_http_connection *conn) { if (--conn->ref <= 0) { rspamd_http_connection_free (conn); } @@ -292,8 +294,12 @@ void rspamd_http_connection_reset (struct rspamd_http_connection *conn); * @param sz */ void rspamd_http_connection_set_max_size (struct rspamd_http_connection *conn, - gsize sz); + gsize sz); void rspamd_http_connection_disable_encryption (struct rspamd_http_connection *conn); +#ifdef __cplusplus +} +#endif + #endif /* HTTP_H_ */ diff --git a/src/libutil/http_context.h b/src/libutil/http_context.h index c610ffbbd..f7697c406 100644 --- a/src/libutil/http_context.h +++ b/src/libutil/http_context.h @@ -23,6 +23,10 @@ #include "contrib/libev/ev.h" +#ifdef __cplusplus +extern "C" { +#endif + struct rspamd_http_context; struct rspamd_config; struct rspamd_http_message; @@ -44,20 +48,21 @@ struct rspamd_http_context_cfg { * @param ev_base event base * @return new context used for both client and server HTTP connections */ -struct rspamd_http_context* rspamd_http_context_create (struct rspamd_config *cfg, - struct ev_loop *ev_base, struct upstream_ctx *ctx); +struct rspamd_http_context *rspamd_http_context_create (struct rspamd_config *cfg, + struct ev_loop *ev_base, struct upstream_ctx *ctx); -struct rspamd_http_context* rspamd_http_context_create_config ( +struct rspamd_http_context *rspamd_http_context_create_config ( struct rspamd_http_context_cfg *cfg, struct ev_loop *ev_base, struct upstream_ctx *ctx); + /** * Destroys context * @param ctx */ void rspamd_http_context_free (struct rspamd_http_context *ctx); -struct rspamd_http_context* rspamd_http_context_default (void); +struct rspamd_http_context *rspamd_http_context_default (void); /** * Returns preserved keepalive connection if it's available. @@ -67,7 +72,7 @@ struct rspamd_http_context* rspamd_http_context_default (void); * @param host * @return */ -struct rspamd_http_connection* rspamd_http_context_check_keepalive ( +struct rspamd_http_connection *rspamd_http_context_check_keepalive ( struct rspamd_http_context *ctx, const rspamd_inet_addr_t *addr, const gchar *host); @@ -83,6 +88,7 @@ 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); + /** * Pushes a connection to keepalive pool after client request is finished, * keepalive key *must* be prepared before using of this function @@ -95,4 +101,8 @@ void rspamd_http_context_push_keepalive (struct rspamd_http_context *ctx, struct rspamd_http_message *msg, struct ev_loop *ev_base); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libutil/http_message.h b/src/libutil/http_message.h index c9e6abfce..e13c7427c 100644 --- a/src/libutil/http_message.h +++ b/src/libutil/http_message.h @@ -22,16 +22,23 @@ #include "fstring.h" #include "ref.h" + +#ifdef __cplusplus +extern "C" { +#endif + struct rspamd_http_connection; -enum rspamd_http_message_type { HTTP_REQUEST = 0, HTTP_RESPONSE }; +enum rspamd_http_message_type { + HTTP_REQUEST = 0, HTTP_RESPONSE +}; /** * Extract the current message from a connection to deal with separately * @param conn * @return */ -struct rspamd_http_message * rspamd_http_connection_steal_msg ( +struct rspamd_http_message *rspamd_http_connection_steal_msg ( struct rspamd_http_connection *conn); /** @@ -39,7 +46,7 @@ struct rspamd_http_message * rspamd_http_connection_steal_msg ( * @param conn * @return */ -struct rspamd_http_message * rspamd_http_connection_copy_msg ( +struct rspamd_http_message *rspamd_http_connection_copy_msg ( struct rspamd_http_message *msg, GError **err); /** @@ -47,14 +54,15 @@ struct rspamd_http_message * rspamd_http_connection_copy_msg ( * @param type request or response * @return new http message */ -struct rspamd_http_message * rspamd_http_new_message (enum rspamd_http_message_type type); +struct rspamd_http_message *rspamd_http_new_message (enum rspamd_http_message_type type); /** * Increase refcount number for an HTTP message * @param msg message to use * @return */ -struct rspamd_http_message * rspamd_http_message_ref (struct rspamd_http_message *msg); +struct rspamd_http_message *rspamd_http_message_ref (struct rspamd_http_message *msg); + /** * Decrease number of refcounts for http message * @param msg @@ -68,12 +76,13 @@ void rspamd_http_message_unref (struct rspamd_http_message *msg); */ void rspamd_http_message_set_peer_key (struct rspamd_http_message *msg, struct rspamd_cryptobox_pubkey *pk); + /** * Create HTTP message from URL * @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 gchar *url); /** * Returns body for a message @@ -101,6 +110,7 @@ gboolean rspamd_http_message_set_body (struct rspamd_http_message *msg, */ void rspamd_http_message_set_method (struct rspamd_http_message *msg, const gchar *method); + /** * Maps fd as message's body * @param msg @@ -162,7 +172,7 @@ void rspamd_http_message_add_header_fstr (struct rspamd_http_message *msg, * @param msg message * @param name name of header */ -const rspamd_ftok_t * rspamd_http_message_find_header ( +const rspamd_ftok_t *rspamd_http_message_find_header ( struct rspamd_http_message *msg, const gchar *name); @@ -172,7 +182,7 @@ const rspamd_ftok_t * rspamd_http_message_find_header ( * @param name * @return list of rspamd_ftok_t * with values */ -GPtrArray* rspamd_http_message_find_header_multiple ( +GPtrArray *rspamd_http_message_find_header_multiple ( struct rspamd_http_message *msg, const gchar *name); @@ -198,13 +208,14 @@ void rspamd_http_message_free (struct rspamd_http_message *msg); * @return new GHashTable which maps rspamd_ftok_t* to rspamd_ftok_t* * (table must be freed by a caller) */ -GHashTable* rspamd_http_message_parse_query (struct rspamd_http_message *msg); +GHashTable *rspamd_http_message_parse_query (struct rspamd_http_message *msg); /** * Increase refcount for shared file (if any) to prevent early memory unlinking * @param msg */ -struct rspamd_storage_shmem* rspamd_http_message_shmem_ref (struct rspamd_http_message *msg); +struct rspamd_storage_shmem *rspamd_http_message_shmem_ref (struct rspamd_http_message *msg); + /** * Decrease external ref for shmem segment associated with a message * @param msg @@ -218,4 +229,8 @@ void rspamd_http_message_shmem_unref (struct rspamd_storage_shmem *p); */ guint rspamd_http_message_get_flags (struct rspamd_http_message *msg); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libutil/http_private.h b/src/libutil/http_private.h index f5a7dd9cc..53c9a81f2 100644 --- a/src/libutil/http_private.h +++ b/src/libutil/http_private.h @@ -27,6 +27,10 @@ #define HASH_CASELESS #include "uthash_strcase.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * HTTP header structure */ @@ -84,9 +88,10 @@ struct rspamd_keepalive_hash_key { GQueue conns; }; -gint32 rspamd_keep_alive_key_hash (struct rspamd_keepalive_hash_key* k); -bool rspamd_keep_alive_key_equal (struct rspamd_keepalive_hash_key* k1, - struct rspamd_keepalive_hash_key* k2); +gint32 rspamd_keep_alive_key_hash (struct rspamd_keepalive_hash_key *k); + +bool rspamd_keep_alive_key_equal (struct rspamd_keepalive_hash_key *k1, + struct rspamd_keepalive_hash_key *k2); KHASH_INIT (rspamd_keep_alive_hash, struct rspamd_keepalive_hash_key *, char, 0, rspamd_keep_alive_key_hash, rspamd_keep_alive_key_equal); @@ -106,10 +111,16 @@ struct rspamd_http_context { }; #define HTTP_ERROR http_error_quark () + GQuark http_error_quark (void); void rspamd_http_message_storage_cleanup (struct rspamd_http_message *msg); + gboolean rspamd_http_message_grow_body (struct rspamd_http_message *msg, gsize len); +#ifdef __cplusplus +} +#endif + #endif /* SRC_LIBUTIL_HTTP_PRIVATE_H_ */ diff --git a/src/libutil/http_router.h b/src/libutil/http_router.h index b946067b7..115ee9b8a 100644 --- a/src/libutil/http_router.h +++ b/src/libutil/http_router.h @@ -19,14 +19,20 @@ #include "config.h" #include "http_connection.h" +#ifdef __cplusplus +extern "C" { +#endif + struct rspamd_http_connection_router; struct rspamd_http_connection_entry; typedef int (*rspamd_http_router_handler_t) (struct rspamd_http_connection_entry *conn_ent, struct rspamd_http_message *msg); + typedef void (*rspamd_http_router_error_handler_t) (struct rspamd_http_connection_entry *conn_ent, GError *err); + typedef void (*rspamd_http_router_finish_handler_t) (struct rspamd_http_connection_entry *conn_ent); @@ -62,7 +68,7 @@ struct rspamd_http_connection_router { * the specified directory * @return */ -struct rspamd_http_connection_router * rspamd_http_router_new ( +struct rspamd_http_connection_router *rspamd_http_router_new ( rspamd_http_router_error_handler_t eh, rspamd_http_router_finish_handler_t fh, ev_tstamp timeout, @@ -109,6 +115,7 @@ void rspamd_http_router_insert_headers (struct rspamd_http_connection_router *ro struct rspamd_http_message *msg); struct rspamd_regexp_s; + /** * Adds new pattern to router, regexp object is refcounted by this function * @param router @@ -117,6 +124,7 @@ struct rspamd_regexp_s; */ void rspamd_http_router_add_regexp (struct rspamd_http_connection_router *router, struct rspamd_regexp_s *re, rspamd_http_router_handler_t handler); + /** * Handle new accepted socket * @param router router object @@ -134,4 +142,8 @@ void rspamd_http_router_handle_socket ( */ void rspamd_http_router_free (struct rspamd_http_connection_router *router); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libutil/http_util.h b/src/libutil/http_util.h index 30d806ae0..7a22ffb16 100644 --- a/src/libutil/http_util.h +++ b/src/libutil/http_util.h @@ -19,6 +19,10 @@ #include "config.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * Parse HTTP date header and return it as time_t * @param header HTTP date header @@ -45,4 +49,8 @@ glong rspamd_http_date_format (gchar *buf, gsize len, time_t time); */ void rspamd_http_normalize_path_inplace (gchar *path, guint len, guint *nlen); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libutil/libev_helper.h b/src/libutil/libev_helper.h index cf52db557..8502043e6 100644 --- a/src/libutil/libev_helper.h +++ b/src/libutil/libev_helper.h @@ -20,12 +20,17 @@ #include "config.h" #include "contrib/libev/ev.h" + +#ifdef __cplusplus +extern "C" { +#endif + /* * This module is a little helper to simplify libevent->libev transition * It allows to create timed IO watchers utilising both */ -typedef void (*rspamd_ev_cb)(int fd, short what, void *ud); +typedef void (*rspamd_ev_cb) (int fd, short what, void *ud); struct rspamd_io_ev { ev_io io; @@ -45,7 +50,7 @@ struct rspamd_io_ev { * @param ud */ void rspamd_ev_watcher_init (struct rspamd_io_ev *ev, - int fd, short what, rspamd_ev_cb cb, void *ud); + int fd, short what, rspamd_ev_cb cb, void *ud); /** * Start watcher with the specific timeout @@ -75,4 +80,8 @@ void rspamd_ev_watcher_reschedule (struct ev_loop *loop, struct rspamd_io_ev *ev, short what); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libutil/logger.h b/src/libutil/logger.h index 7347e67b1..e56c37aad 100644 --- a/src/libutil/logger.h +++ b/src/libutil/logger.h @@ -2,23 +2,28 @@ #define RSPAMD_LOGGER_H #include "config.h" -#include "cfg_file.h" #include "radix.h" #include "util.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifndef G_LOG_LEVEL_USER_SHIFT #define G_LOG_LEVEL_USER_SHIFT 8 #endif +struct rspamd_config; + enum rspamd_log_flags { RSPAMD_LOG_FORCED = (1 << G_LOG_LEVEL_USER_SHIFT), RSPAMD_LOG_ENCRYPTED = (1 << (G_LOG_LEVEL_USER_SHIFT + 1)), - RSPAMD_LOG_LEVEL_MASK = ~(RSPAMD_LOG_FORCED|RSPAMD_LOG_ENCRYPTED) + RSPAMD_LOG_LEVEL_MASK = ~(RSPAMD_LOG_FORCED | RSPAMD_LOG_ENCRYPTED) }; typedef void (*rspamd_log_func_t) (const gchar *module, const gchar *id, - const gchar *function, - gint level_flags, const gchar *message, gpointer arg); + const gchar *function, + gint level_flags, const gchar *message, gpointer arg); typedef struct rspamd_logger_s rspamd_logger_t; @@ -28,9 +33,9 @@ typedef struct rspamd_logger_s rspamd_logger_t; * Init logger */ void rspamd_set_logger (struct rspamd_config *cfg, - GQuark ptype, - rspamd_logger_t **plogger, - rspamd_mempool_t *pool); + GQuark ptype, + rspamd_logger_t **plogger, + rspamd_mempool_t *pool); /** * Open log file or initialize other structures @@ -76,7 +81,7 @@ void rspamd_log_flush (rspamd_logger_t *logger); * Log function that is compatible for glib messages */ void rspamd_glib_log_function (const gchar *log_domain, - GLogLevelFlags log_level, const gchar *message, gpointer arg); + GLogLevelFlags log_level, const gchar *message, gpointer arg); /** * Log function for printing glib assertions @@ -87,13 +92,13 @@ void rspamd_glib_printerr_function (const gchar *message); * Function with variable number of arguments support */ void rspamd_common_log_function (rspamd_logger_t *logger, - gint level_flags, - const gchar *module, const gchar *id, - const gchar *function, const gchar *fmt, ...); + gint level_flags, + const gchar *module, const gchar *id, + const gchar *function, const gchar *fmt, ...); void 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); + const gchar *module, const gchar *id, const gchar *function, + const gchar *fmt, va_list args); /** * Add new logging module, returns module ID @@ -106,15 +111,15 @@ guint rspamd_logger_add_debug_module (const gchar *mod); * Macro to use for faster debug modules */ #define INIT_LOG_MODULE(mname) \ - static guint rspamd_##mname##_log_id = (guint)-1; \ - RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) { \ - rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \ + static guint rspamd_##mname##_log_id = (guint)-1; \ + RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) { \ + rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \ } #define INIT_LOG_MODULE_PUBLIC(mname) \ - guint rspamd_##mname##_log_id = (guint)-1; \ - RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) { \ - rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \ + guint rspamd_##mname##_log_id = (guint)-1; \ + RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) { \ + rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \ } void rspamd_logger_configure_modules (GHashTable *mods_enabled); @@ -123,22 +128,22 @@ void rspamd_logger_configure_modules (GHashTable *mods_enabled); * Conditional debug function */ void 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 gchar *module, const gchar *id, + const gchar *function, const gchar *fmt, ...); void rspamd_conditional_debug_fast (rspamd_logger_t *logger, - rspamd_inet_addr_t *addr, - guint mod_id, const gchar *module, const gchar *id, - const gchar *function, const gchar *fmt, ...); + rspamd_inet_addr_t *addr, + guint mod_id, const gchar *module, const gchar *id, + const gchar *function, const gchar *fmt, ...); /** * Function with variable number of arguments support that uses static default logger */ void rspamd_default_log_function (gint level_flags, - const gchar *module, const gchar *id, - const gchar *function, - const gchar *fmt, - ...); + const gchar *module, const gchar *id, + const gchar *function, + const gchar *fmt, + ...); /** * Varargs version of default log function @@ -148,10 +153,10 @@ void rspamd_default_log_function (gint level_flags, * @param args */ void rspamd_default_logv (gint level_flags, - const gchar *module, const gchar *id, - const gchar *function, - const gchar *fmt, - va_list args); + const gchar *module, const gchar *id, + const gchar *function, + const gchar *fmt, + va_list args); /** * Temporary turn on debug @@ -180,20 +185,20 @@ void rspamd_log_lock (rspamd_logger_t *logger); * 2 - info messages * 3 - debug messages */ -const guint64* rspamd_log_counters (rspamd_logger_t *logger); +const guint64 *rspamd_log_counters (rspamd_logger_t *logger); /** * Returns errors ring buffer as ucl array * @param logger * @return */ -ucl_object_t * rspamd_log_errorbuf_export (const rspamd_logger_t *logger); +ucl_object_t *rspamd_log_errorbuf_export (const rspamd_logger_t *logger); /** * Returns the current logger object * @return */ -rspamd_logger_t* rspamd_logger_get_singleton (void); +rspamd_logger_t *rspamd_logger_get_singleton (void); /* Typical functions */ @@ -282,7 +287,7 @@ extern guint rspamd_task_log_id; G_STRFUNC, \ __VA_ARGS__) #define msg_debug_task_check(...) rspamd_conditional_debug_fast (NULL, \ - task ? task->from_addr : NULL, \ + task ? task->from_addr : NULL, \ rspamd_task_log_id, "task", task ? task->task_pool->tag.uid : NULL, \ G_STRFUNC, \ __VA_ARGS__) @@ -310,7 +315,7 @@ extern guint rspamd_task_log_id; G_STRFUNC, \ __VA_ARGS__) #define msg_warn_pool_check(...) rspamd_default_log_function (G_LOG_LEVEL_WARNING, \ - pool ? pool->tag.tagname : NULL, pool ? pool->tag.uid : NULL, \ + pool ? pool->tag.tagname : NULL, pool ? pool->tag.uid : NULL, \ G_STRFUNC, \ __VA_ARGS__) #define msg_info_pool_check(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \ @@ -318,7 +323,12 @@ extern guint rspamd_task_log_id; G_STRFUNC, \ __VA_ARGS__) #define msg_debug_pool_check(...) rspamd_conditional_debug (NULL, NULL, \ - pool ? pool->tag.tagname : NULL, pool ? pool->tag.uid : NULL, \ - G_STRFUNC, \ - __VA_ARGS__) + pool ? pool->tag.tagname : NULL, pool ? pool->tag.uid : NULL, \ + G_STRFUNC, \ + __VA_ARGS__) + +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libutil/map.h b/src/libutil/map.h index 9f04d4c6c..9e09ab8fe 100644 --- a/src/libutil/map.h +++ b/src/libutil/map.h @@ -9,26 +9,34 @@ #include "radix.h" #include "dns.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * Maps API is designed to load lists data from different dynamic sources. * It monitor files and HTTP locations for modifications and reload them if they are * modified. */ struct map_cb_data; +struct rspamd_worker; /** * Callback types */ -typedef gchar * (*map_cb_t)(gchar *chunk, gint len, - struct map_cb_data *data, gboolean final); -typedef void (*map_fin_cb_t)(struct map_cb_data *data, void **target); -typedef void (*map_dtor_t)(struct map_cb_data *data); +typedef gchar *(*map_cb_t) (gchar *chunk, gint len, + struct map_cb_data *data, gboolean final); + +typedef void (*map_fin_cb_t) (struct map_cb_data *data, void **target); + +typedef void (*map_dtor_t) (struct map_cb_data *data); -typedef gboolean (*rspamd_map_traverse_cb)(gconstpointer key, - gconstpointer value, gsize hits, gpointer ud); -typedef void (*rspamd_map_traverse_function)(void *data, - rspamd_map_traverse_cb cb, - gpointer cbdata, gboolean reset_hits); +typedef gboolean (*rspamd_map_traverse_cb) (gconstpointer key, + gconstpointer value, gsize hits, gpointer ud); + +typedef void (*rspamd_map_traverse_function) (void *data, + rspamd_map_traverse_cb cb, + gpointer cbdata, gboolean reset_hits); /** * Common map object @@ -56,7 +64,7 @@ gboolean rspamd_map_is_map (const gchar *map_line); /** * Add map from line */ -struct rspamd_map* rspamd_map_add (struct rspamd_config *cfg, +struct rspamd_map *rspamd_map_add (struct rspamd_config *cfg, const gchar *map_line, const gchar *description, map_cb_t read_callback, @@ -67,7 +75,7 @@ struct rspamd_map* rspamd_map_add (struct rspamd_config *cfg, /** * Add map from ucl */ -struct rspamd_map* rspamd_map_add_from_ucl (struct rspamd_config *cfg, +struct rspamd_map *rspamd_map_add_from_ucl (struct rspamd_config *cfg, const ucl_object_t *obj, const gchar *description, map_cb_t read_callback, @@ -111,6 +119,10 @@ rspamd_map_traverse_function rspamd_map_get_traverse_function (struct rspamd_map * @return */ void rspamd_map_traverse (struct rspamd_map *map, rspamd_map_traverse_cb cb, - gpointer cbdata, gboolean reset_hits); + gpointer cbdata, gboolean reset_hits); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/libutil/map_helpers.h b/src/libutil/map_helpers.h index 4645024e3..4f7b5b804 100644 --- a/src/libutil/map_helpers.h +++ b/src/libutil/map_helpers.h @@ -27,6 +27,11 @@ * Defines helper structures to deal with different map types */ + +#ifdef __cplusplus +extern "C" { +#endif + /** * Common structures, abstract for simplicity */ @@ -42,56 +47,64 @@ enum rspamd_regexp_map_flags { }; typedef void (*insert_func) (gpointer st, gconstpointer key, - gconstpointer value); + gconstpointer value); /** * Radix list is a list like ip/mask */ -gchar * rspamd_radix_read ( +gchar *rspamd_radix_read ( gchar *chunk, gint len, struct map_cb_data *data, gboolean final); + void rspamd_radix_fin (struct map_cb_data *data, void **target); + 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 *rspamd_kv_list_read ( gchar *chunk, gint len, struct map_cb_data *data, gboolean final); + void rspamd_kv_list_fin (struct map_cb_data *data, void **target); + void rspamd_kv_list_dtor (struct map_cb_data *data); /** * Regexp list is a list of regular expressions */ -gchar * rspamd_regexp_list_read_single ( +gchar *rspamd_regexp_list_read_single ( gchar *chunk, gint len, struct map_cb_data *data, gboolean final); -gchar * rspamd_regexp_list_read_multiple ( + +gchar *rspamd_regexp_list_read_multiple ( gchar *chunk, gint len, struct map_cb_data *data, gboolean final); -gchar * rspamd_glob_list_read_single ( +gchar *rspamd_glob_list_read_single ( gchar *chunk, gint len, struct map_cb_data *data, gboolean final); -gchar * rspamd_glob_list_read_multiple ( + +gchar *rspamd_glob_list_read_multiple ( gchar *chunk, gint len, struct map_cb_data *data, gboolean final); + void rspamd_regexp_list_fin (struct map_cb_data *data, void **target); + void rspamd_regexp_list_dtor (struct map_cb_data *data); /** @@ -99,7 +112,7 @@ void rspamd_regexp_list_dtor (struct map_cb_data *data); */ gchar * rspamd_parse_kv_list ( - gchar * chunk, + gchar *chunk, gint len, struct map_cb_data *data, insert_func func, @@ -115,7 +128,7 @@ rspamd_parse_kv_list ( * @return */ gconstpointer rspamd_match_regexp_map_single (struct rspamd_regexp_map_helper *map, - const gchar *in, gsize len); + const gchar *in, gsize len); /** * Find a multiple (all) matching regexp for the specified text or NULL if @@ -125,8 +138,8 @@ gconstpointer rspamd_match_regexp_map_single (struct rspamd_regexp_map_helper *m * @param len * @return */ -GPtrArray* rspamd_match_regexp_map_all (struct rspamd_regexp_map_helper *map, - const gchar *in, gsize len); +GPtrArray *rspamd_match_regexp_map_all (struct rspamd_regexp_map_helper *map, + const gchar *in, gsize len); /** * Find value matching specific key in a hash map @@ -136,7 +149,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); + const gchar *in); /** * Find value matching specific key in a hash map @@ -146,10 +159,10 @@ gconstpointer rspamd_match_hash_map (struct rspamd_hash_map_helper *map, * @return */ gconstpointer rspamd_match_radix_map (struct rspamd_radix_map_helper *map, - const guchar *in, gsize inlen); + const guchar *in, gsize inlen); gconstpointer rspamd_match_radix_map_addr (struct rspamd_radix_map_helper *map, - const rspamd_inet_addr_t *addr); + const rspamd_inet_addr_t *addr); /** * Creates radix map helper @@ -157,6 +170,7 @@ gconstpointer rspamd_match_radix_map_addr (struct rspamd_radix_map_helper *map, * @return */ struct rspamd_radix_map_helper *rspamd_map_helper_new_radix (struct rspamd_map *map); + /** * Inserts new value into radix map * @param st @@ -164,6 +178,7 @@ struct rspamd_radix_map_helper *rspamd_map_helper_new_radix (struct rspamd_map * * @param value */ void rspamd_map_helper_insert_radix (gpointer st, gconstpointer key, gconstpointer value); + /** * Inserts new value into radix map performing synchronous resolving * @param st @@ -171,7 +186,8 @@ void rspamd_map_helper_insert_radix (gpointer st, gconstpointer key, gconstpoint * @param value */ void rspamd_map_helper_insert_radix_resolve (gpointer st, gconstpointer key, - gconstpointer value); + gconstpointer value); + /** * Destroys radix map helper * @param r @@ -185,6 +201,7 @@ void rspamd_map_helper_destroy_radix (struct rspamd_radix_map_helper *r); * @return */ struct rspamd_hash_map_helper *rspamd_map_helper_new_hash (struct rspamd_map *map); + /** * Inserts a new value into a hash map * @param st @@ -192,6 +209,7 @@ struct rspamd_hash_map_helper *rspamd_map_helper_new_hash (struct rspamd_map *ma * @param value */ void rspamd_map_helper_insert_hash (gpointer st, gconstpointer key, gconstpointer value); + /** * Destroys hash map helper * @param r @@ -204,8 +222,9 @@ void rspamd_map_helper_destroy_hash (struct rspamd_hash_map_helper *r); * @param flags * @return */ -struct rspamd_regexp_map_helper * rspamd_map_helper_new_regexp (struct rspamd_map *map, - enum rspamd_regexp_map_flags flags); +struct rspamd_regexp_map_helper *rspamd_map_helper_new_regexp (struct rspamd_map *map, + enum rspamd_regexp_map_flags flags); + /** * Inserts a new regexp into regexp map * @param st @@ -213,10 +232,15 @@ struct rspamd_regexp_map_helper * rspamd_map_helper_new_regexp (struct rspamd_ma * @param value */ void rspamd_map_helper_insert_re (gpointer st, gconstpointer key, gconstpointer value); + /** * Destroy regexp map * @param re_map */ void rspamd_map_helper_destroy_regexp (struct rspamd_regexp_map_helper *re_map); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h index e08c2dce3..de84322ec 100644 --- a/src/libutil/map_private.h +++ b/src/libutil/map_private.h @@ -23,18 +23,23 @@ #include "map.h" #include "ref.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef void (*rspamd_map_tmp_dtor) (gpointer p); + extern guint rspamd_map_log_id; #define msg_err_map(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \ - "map", map->tag, \ + "map", map->tag, \ G_STRFUNC, \ __VA_ARGS__) #define msg_warn_map(...) rspamd_default_log_function (G_LOG_LEVEL_WARNING, \ - "map", map->tag, \ + "map", map->tag, \ G_STRFUNC, \ __VA_ARGS__) #define msg_info_map(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \ - "map", map->tag, \ + "map", map->tag, \ G_STRFUNC, \ __VA_ARGS__) #define msg_debug_map(...) rspamd_conditional_debug_fast (NULL, NULL, \ @@ -209,4 +214,8 @@ struct http_callback_data { ref_entry_t ref; }; +#ifdef __cplusplus +} +#endif + #endif /* SRC_LIBUTIL_MAP_PRIVATE_H_ */ diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h index 0a2e86b6d..5a663e35f 100644 --- a/src/libutil/mem_pool.h +++ b/src/libutil/mem_pool.h @@ -13,13 +13,17 @@ #define RSPAMD_MEM_POOL_H #include "config.h" + + #if defined(HAVE_PTHREAD_PROCESS_SHARED) && !defined(DISABLE_PTHREAD_MUTEX) #include <pthread.h> #endif -struct f_str_s; - +#ifdef __cplusplus +extern "C" { +#endif +struct f_str_s; #ifdef __has_attribute # if __has_attribute(alloc_size) @@ -60,7 +64,7 @@ enum rspamd_mempool_chain_type { /** * Destructor type definition */ -typedef void (*rspamd_mempool_destruct_t)(void *ptr); +typedef void (*rspamd_mempool_destruct_t) (void *ptr); /** * Pool mutex structure @@ -122,7 +126,7 @@ typedef struct memory_pool_s { GArray *destructors; GPtrArray *trash_stack; GHashTable *variables; /**< private memory pool variables */ - gsize elt_len; /**< size of an element */ + gsize elt_len; /**< size of an element */ struct rspamd_mempool_entry_point *entry; struct rspamd_mempool_tag tag; /**< memory pool tag */ } rspamd_mempool_t; @@ -142,13 +146,13 @@ typedef struct memory_pool_stat_s { } rspamd_mempool_stat_t; - /** * Allocate new memory poll * @param size size of pool's page * @return new memory pool object */ -rspamd_mempool_t * rspamd_mempool_new_ (gsize size, const gchar *tag, const gchar *loc); +rspamd_mempool_t *rspamd_mempool_new_ (gsize size, const gchar *tag, const gchar *loc); + #define rspamd_mempool_new(size, tag) rspamd_mempool_new_((size), (tag), G_STRLOC) /** @@ -157,8 +161,8 @@ rspamd_mempool_t * rspamd_mempool_new_ (gsize size, const gchar *tag, const gcha * @param size bytes to allocate * @return pointer to allocated object */ -void * rspamd_mempool_alloc (rspamd_mempool_t * pool, gsize size) - RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; +void *rspamd_mempool_alloc (rspamd_mempool_t *pool, gsize size) +RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; /** * Get memory from temporary pool @@ -166,7 +170,7 @@ void * rspamd_mempool_alloc (rspamd_mempool_t * pool, gsize size) * @param size bytes to allocate * @return pointer to allocated object */ -void * rspamd_mempool_alloc_tmp (rspamd_mempool_t * pool, gsize size) RSPAMD_ATTR_RETURNS_NONNUL; +void *rspamd_mempool_alloc_tmp (rspamd_mempool_t *pool, gsize size) RSPAMD_ATTR_RETURNS_NONNUL; /** * Get memory and set it to zero @@ -174,8 +178,8 @@ void * rspamd_mempool_alloc_tmp (rspamd_mempool_t * pool, gsize size) RSPAMD_ATT * @param size bytes to allocate * @return pointer to allocated object */ -void * rspamd_mempool_alloc0 (rspamd_mempool_t * pool, gsize size) - RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; +void *rspamd_mempool_alloc0 (rspamd_mempool_t *pool, gsize size) +RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; /** * Get memory and set it to zero @@ -183,12 +187,12 @@ void * rspamd_mempool_alloc0 (rspamd_mempool_t * pool, gsize size) * @param size bytes to allocate * @return pointer to allocated object */ -void * rspamd_mempool_alloc0_tmp (rspamd_mempool_t * pool, gsize size) RSPAMD_ATTR_RETURNS_NONNUL; +void *rspamd_mempool_alloc0_tmp (rspamd_mempool_t *pool, gsize size) RSPAMD_ATTR_RETURNS_NONNUL; /** * Cleanup temporary data in pool */ -void rspamd_mempool_cleanup_tmp (rspamd_mempool_t * pool); +void rspamd_mempool_cleanup_tmp (rspamd_mempool_t *pool); /** * Make a copy of string in pool @@ -196,8 +200,8 @@ void rspamd_mempool_cleanup_tmp (rspamd_mempool_t * pool); * @param src source string * @return pointer to newly created string that is copy of src */ -gchar * rspamd_mempool_strdup (rspamd_mempool_t * pool, const gchar *src) - RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT); +gchar *rspamd_mempool_strdup (rspamd_mempool_t *pool, const gchar *src) +RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT); /** * Make a copy of fixed string in pool as null terminated string @@ -205,8 +209,8 @@ gchar * rspamd_mempool_strdup (rspamd_mempool_t * pool, const gchar *src) * @param src source string * @return pointer to newly created string that is copy of src */ -gchar * rspamd_mempool_fstrdup (rspamd_mempool_t * pool, - const struct f_str_s *src) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT); +gchar *rspamd_mempool_fstrdup (rspamd_mempool_t *pool, + const struct f_str_s *src) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT); struct f_str_tok; @@ -216,18 +220,20 @@ struct f_str_tok; * @param src source string * @return pointer to newly created string that is copy of src */ -gchar * rspamd_mempool_ftokdup (rspamd_mempool_t *pool, - const struct f_str_tok *src) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT); +gchar *rspamd_mempool_ftokdup (rspamd_mempool_t *pool, + const struct f_str_tok *src) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT); /** * Allocate piece of shared memory * @param pool memory pool object * @param size bytes to allocate */ -void * rspamd_mempool_alloc_shared (rspamd_mempool_t * pool, gsize size) - RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; -void * rspamd_mempool_alloc0_shared (rspamd_mempool_t *pool, gsize size) - RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; +void *rspamd_mempool_alloc_shared (rspamd_mempool_t *pool, gsize size) +RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; + +void *rspamd_mempool_alloc0_shared (rspamd_mempool_t *pool, gsize size) +RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; + /** * Add destructor callback to pool * @param pool memory pool object @@ -235,14 +241,14 @@ void * rspamd_mempool_alloc0_shared (rspamd_mempool_t *pool, gsize size) * @param data pointer to data that would be passed to destructor */ void rspamd_mempool_add_destructor_full (rspamd_mempool_t *pool, - rspamd_mempool_destruct_t func, - void *data, - const gchar *function, - const gchar *line); + rspamd_mempool_destruct_t func, + void *data, + const gchar *function, + const gchar *line); /* Macros for common usage */ #define rspamd_mempool_add_destructor(pool, func, data) \ - rspamd_mempool_add_destructor_full (pool, func, data, G_STRFUNC, G_STRLOC) + rspamd_mempool_add_destructor_full (pool, func, data, G_STRFUNC, G_STRLOC) /** * Replace destructor callback to pool for specified pointer @@ -252,7 +258,7 @@ void rspamd_mempool_add_destructor_full (rspamd_mempool_t *pool, * @param new_data pointer to data that would be passed to destructor */ void rspamd_mempool_replace_destructor (rspamd_mempool_t *pool, - rspamd_mempool_destruct_t func, void *old_data, void *new_data); + rspamd_mempool_destruct_t func, void *old_data, void *new_data); /** * Calls all destructors associated with the specific memory pool without removing @@ -272,7 +278,7 @@ void rspamd_mempool_delete (rspamd_mempool_t *pool); * @param pool memory pool object * @return mutex object */ -rspamd_mempool_mutex_t * rspamd_mempool_get_mutex (rspamd_mempool_t *pool); +rspamd_mempool_mutex_t *rspamd_mempool_get_mutex (rspamd_mempool_t *pool); /** * Lock mutex @@ -291,7 +297,7 @@ void rspamd_mempool_unlock_mutex (rspamd_mempool_mutex_t *mutex); * @param pool memory pool object * @return rwlock object */ -rspamd_mempool_rwlock_t * rspamd_mempool_get_rwlock (rspamd_mempool_t *pool); +rspamd_mempool_rwlock_t *rspamd_mempool_get_rwlock (rspamd_mempool_t *pool); /** * Acquire read lock @@ -333,6 +339,7 @@ void rspamd_mempool_stat_reset (void); * @return size of memory page in system */ #define rspamd_mempool_suggest_size() rspamd_mempool_suggest_size_(G_STRLOC) + gsize rspamd_mempool_suggest_size_ (const char *loc); /** @@ -343,7 +350,7 @@ gsize rspamd_mempool_suggest_size_ (const char *loc); * @param destructor pointer to function-destructor */ void rspamd_mempool_set_variable (rspamd_mempool_t *pool, const gchar *name, - gpointer value, rspamd_mempool_destruct_t destructor); + gpointer value, rspamd_mempool_destruct_t destructor); /** * Get memory pool variable @@ -352,7 +359,7 @@ void rspamd_mempool_set_variable (rspamd_mempool_t *pool, const gchar *name, * @return NULL or pointer to variable data */ gpointer rspamd_mempool_get_variable (rspamd_mempool_t *pool, - const gchar *name); + const gchar *name); /** * Removes variable from memory pool @@ -360,7 +367,8 @@ gpointer rspamd_mempool_get_variable (rspamd_mempool_t *pool, * @param name name of variable */ void rspamd_mempool_remove_variable (rspamd_mempool_t *pool, - const gchar *name); + const gchar *name); + /** * Prepend element to a list creating it in the memory pool * @param l @@ -368,7 +376,8 @@ void rspamd_mempool_remove_variable (rspamd_mempool_t *pool, * @return */ GList *rspamd_mempool_glist_prepend (rspamd_mempool_t *pool, - GList *l, gpointer p) G_GNUC_WARN_UNUSED_RESULT; + GList *l, gpointer p) G_GNUC_WARN_UNUSED_RESULT; + /** * Append element to a list creating it in the memory pool * @param l @@ -376,6 +385,10 @@ GList *rspamd_mempool_glist_prepend (rspamd_mempool_t *pool, * @return */ GList *rspamd_mempool_glist_append (rspamd_mempool_t *pool, - GList *l, gpointer p) G_GNUC_WARN_UNUSED_RESULT; + GList *l, gpointer p) G_GNUC_WARN_UNUSED_RESULT; + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/libutil/multipattern.h b/src/libutil/multipattern.h index 785c09e3d..959b13455 100644 --- a/src/libutil/multipattern.h +++ b/src/libutil/multipattern.h @@ -26,13 +26,17 @@ * hyperscan and ac-trie */ +#ifdef __cplusplus +extern "C" { +#endif + enum rspamd_multipattern_flags { RSPAMD_MULTIPATTERN_DEFAULT = 0, RSPAMD_MULTIPATTERN_ICASE = (1 << 0), RSPAMD_MULTIPATTERN_UTF8 = (1 << 1), RSPAMD_MULTIPATTERN_TLD = (1 << 2), /* Not supported by acism */ - RSPAMD_MULTIPATTERN_GLOB = (1 << 3), + RSPAMD_MULTIPATTERN_GLOB = (1 << 3), RSPAMD_MULTIPATTERN_RE = (1 << 4), }; @@ -50,12 +54,12 @@ struct rspamd_cryptobox_library_ctx; * @return if 0 then search for another pattern, otherwise return this value to caller */ typedef gint (*rspamd_multipattern_cb_t) (struct rspamd_multipattern *mp, - guint strnum, - gint match_start, - gint match_pos, - const gchar *text, - gsize len, - void *context); + guint strnum, + gint match_start, + gint match_pos, + const gchar *text, + gsize len, + void *context); /** * Init multipart library and set the appropriate cache dir @@ -78,7 +82,7 @@ struct rspamd_multipattern *rspamd_multipattern_create ( * @return */ struct rspamd_multipattern *rspamd_multipattern_create_sized (guint reserved, - enum rspamd_multipattern_flags flags); + enum rspamd_multipattern_flags flags); /** * Creates new multipattern structure @@ -98,7 +102,7 @@ struct rspamd_multipattern *rspamd_multipattern_create_full ( * @param pattern */ void rspamd_multipattern_add_pattern (struct rspamd_multipattern *mp, - const gchar *pattern, gint flags); + const gchar *pattern, gint flags); /** * Adds new pattern from arbitrary string @@ -108,7 +112,7 @@ void rspamd_multipattern_add_pattern (struct rspamd_multipattern *mp, * @param flags */ void rspamd_multipattern_add_pattern_len (struct rspamd_multipattern *mp, - const gchar *pattern, gsize patlen, gint flags); + const gchar *pattern, gsize patlen, gint flags); /** * Compiles multipattern structure @@ -116,7 +120,7 @@ void rspamd_multipattern_add_pattern_len (struct rspamd_multipattern *mp, * @return */ gboolean rspamd_multipattern_compile (struct rspamd_multipattern *mp, - GError **err); + GError **err); /** * Lookups for patterns in a text using the specified callback function @@ -128,16 +132,17 @@ gboolean rspamd_multipattern_compile (struct rspamd_multipattern *mp, * @return */ gint rspamd_multipattern_lookup (struct rspamd_multipattern *mp, - const gchar *in, gsize len, rspamd_multipattern_cb_t cb, - gpointer ud, guint *pnfound); + const gchar *in, gsize len, rspamd_multipattern_cb_t cb, + gpointer ud, guint *pnfound); + /** * Get pattern string from multipattern identified by index * @param mp * @param index * @return */ -const gchar* rspamd_multipattern_get_pattern (struct rspamd_multipattern *mp, - guint index); +const gchar *rspamd_multipattern_get_pattern (struct rspamd_multipattern *mp, + guint index); /** * Returns number of patterns in a multipattern matcher @@ -158,4 +163,8 @@ void rspamd_multipattern_destroy (struct rspamd_multipattern *mp); */ gboolean rspamd_multipattern_has_hyperscan (void); +#ifdef __cplusplus +} +#endif + #endif /* SRC_LIBUTIL_MULTIPATTERN_H_ */ diff --git a/src/libutil/printf.h b/src/libutil/printf.h index 86947f67c..008e08245 100644 --- a/src/libutil/printf.h +++ b/src/libutil/printf.h @@ -19,6 +19,9 @@ #include "config.h" #include "fstring.h" +#ifdef __cplusplus +extern "C" { +#endif /* * supported formats: * %[0][width][x][X]O off_t @@ -59,24 +62,35 @@ * @param ud opaque pointer * @return number of characters written */ -typedef glong (*rspamd_printf_append_func)(const gchar *buf, glong buflen, - gpointer ud); +typedef glong (*rspamd_printf_append_func) (const gchar *buf, glong buflen, + gpointer ud); glong rspamd_fprintf (FILE *f, const gchar *fmt, ...); + glong rspamd_printf (const gchar *fmt, ...); + glong rspamd_log_fprintf (FILE *f, const gchar *fmt, ...); + glong rspamd_snprintf (gchar *buf, glong max, const gchar *fmt, ...); -gchar * rspamd_vsnprintf (gchar *buf, glong max, const gchar *fmt, - va_list args); + +gchar *rspamd_vsnprintf (gchar *buf, glong max, const gchar *fmt, + va_list args); + glong rspamd_printf_gstring (GString *s, const gchar *fmt, ...); + glong rspamd_vprintf_gstring (GString *s, const gchar *fmt, va_list args); glong rspamd_printf_fstring (rspamd_fstring_t **s, const gchar *fmt, ...); + glong rspamd_vprintf_fstring (rspamd_fstring_t **s, const gchar *fmt, va_list args); glong rspamd_vprintf_common (rspamd_printf_append_func func, - gpointer apd, - const gchar *fmt, - va_list args); + gpointer apd, + const gchar *fmt, + va_list args); + +#ifdef __cplusplus +} +#endif #endif /* PRINTF_H_ */ diff --git a/src/libutil/radix.h b/src/libutil/radix.h index be75b1b7f..f08b6cc1b 100644 --- a/src/libutil/radix.h +++ b/src/libutil/radix.h @@ -22,6 +22,9 @@ #define RADIX_NO_VALUE (uintptr_t)-1 +#ifdef __cplusplus +extern "C" { +#endif typedef struct radix_tree_compressed radix_compressed_t; @@ -35,10 +38,10 @@ typedef struct radix_tree_compressed radix_compressed_t; * @return previous value of the key or `RADIX_NO_VALUE` */ uintptr_t -radix_insert_compressed (radix_compressed_t * tree, - guint8 *key, gsize keylen, - gsize masklen, - uintptr_t value); +radix_insert_compressed (radix_compressed_t *tree, + guint8 *key, gsize keylen, + gsize masklen, + uintptr_t value); /** * Find a key in a radix trie @@ -47,8 +50,8 @@ radix_insert_compressed (radix_compressed_t * tree, * @param keylen length of a key * @return opaque pointer or `RADIX_NO_VALUE` if no value has been found */ -uintptr_t radix_find_compressed (radix_compressed_t * tree, const guint8 *key, - gsize keylen); +uintptr_t radix_find_compressed (radix_compressed_t *tree, const guint8 *key, + gsize keylen); /** * Find specified address in tree (works for IPv4 or IPv6 addresses) @@ -57,7 +60,7 @@ uintptr_t radix_find_compressed (radix_compressed_t * tree, const guint8 *key, * @return */ uintptr_t radix_find_compressed_addr (radix_compressed_t *tree, - const rspamd_inet_addr_t *addr); + const rspamd_inet_addr_t *addr); /** * Destroy the complete radix trie @@ -81,14 +84,14 @@ radix_compressed_t *radix_create_compressed_with_pool (rspamd_mempool_t *pool); * @return number of elements inserted */ gint rspamd_radix_add_iplist (const gchar *list, const gchar *separators, - radix_compressed_t *tree, gconstpointer value, gboolean resolve); + radix_compressed_t *tree, gconstpointer value, gboolean resolve); /** * Generic version of @see rspamd_radix_add_iplist. This function creates tree * if `tree` is NULL. */ gboolean radix_add_generic_iplist (const gchar *ip_list, - radix_compressed_t **tree, gboolean resolve); + radix_compressed_t **tree, gboolean resolve); /** * Returns number of elements in the tree @@ -102,11 +105,15 @@ gsize radix_get_size (radix_compressed_t *tree); * @param tree * @return constant string */ -const gchar * radix_get_info (radix_compressed_t *tree); +const gchar *radix_get_info (radix_compressed_t *tree); /** * Returns memory pool associated with the radix tree */ -rspamd_mempool_t* radix_get_pool (radix_compressed_t *tree); +rspamd_mempool_t *radix_get_pool (radix_compressed_t *tree); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/libutil/ref.h b/src/libutil/ref.h index 1e2fc30b5..99498ac31 100644 --- a/src/libutil/ref.h +++ b/src/libutil/ref.h @@ -19,6 +19,8 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif + + /** * @file ref.h * A set of macros to handle refcounts diff --git a/src/libutil/regexp.h b/src/libutil/regexp.h index b982c08f6..f7ed05dad 100644 --- a/src/libutil/regexp.h +++ b/src/libutil/regexp.h @@ -35,6 +35,11 @@ #define RSPAMD_REGEXP_FLAG_DISABLE_JIT (1 << 5) #define RSPAMD_REGEXP_FLAG_UTF (1 << 6) + +#ifdef __cplusplus +extern "C" { +#endif + struct rspamd_config; typedef struct rspamd_regexp_s rspamd_regexp_t; @@ -51,8 +56,8 @@ struct rspamd_re_capture { * @param err error pointer set if compilation failed * @return new regexp object */ -rspamd_regexp_t* rspamd_regexp_new (const gchar *pattern, const gchar *flags, - GError **err); +rspamd_regexp_t *rspamd_regexp_new (const gchar *pattern, const gchar *flags, + GError **err); /** * Search the specified regexp in the text @@ -66,9 +71,9 @@ rspamd_regexp_t* rspamd_regexp_new (const gchar *pattern, const gchar *flags, * @return */ gboolean rspamd_regexp_search (rspamd_regexp_t *re, - const gchar *text, gsize len, - const gchar **start, const gchar **end, gboolean raw, - GArray *captures); + const gchar *text, gsize len, + const gchar **start, const gchar **end, gboolean raw, + GArray *captures); /** @@ -79,12 +84,12 @@ gboolean rspamd_regexp_search (rspamd_regexp_t *re, * @return */ gboolean rspamd_regexp_match (rspamd_regexp_t *re, - const gchar *text, gsize len, gboolean raw); + const gchar *text, gsize len, gboolean raw); /** * Increase refcount for a regexp object */ -rspamd_regexp_t* rspamd_regexp_ref (rspamd_regexp_t *re); +rspamd_regexp_t *rspamd_regexp_ref (rspamd_regexp_t *re); /** * Unref regexp object @@ -118,12 +123,13 @@ gpointer rspamd_regexp_get_id (rspamd_regexp_t *re); * @param re * @return */ -const char* rspamd_regexp_get_pattern (rspamd_regexp_t *re); +const char *rspamd_regexp_get_pattern (rspamd_regexp_t *re); /** * Get PCRE flags for the regexp */ guint rspamd_regexp_get_pcre_flags (rspamd_regexp_t *re); + /** * Get rspamd flags for the regexp */ @@ -179,7 +185,7 @@ gpointer rspamd_regexp_set_class (rspamd_regexp_t *re, gpointer re_class); * Create new regexp cache * @return */ -struct rspamd_regexp_cache* rspamd_regexp_cache_new (void); +struct rspamd_regexp_cache *rspamd_regexp_cache_new (void); /** * Query rspamd cache for a specified regexp @@ -188,9 +194,9 @@ struct rspamd_regexp_cache* rspamd_regexp_cache_new (void); * @param flags * @return */ -rspamd_regexp_t* rspamd_regexp_cache_query (struct rspamd_regexp_cache* cache, - const gchar *pattern, - const gchar *flags); +rspamd_regexp_t *rspamd_regexp_cache_query (struct rspamd_regexp_cache *cache, + const gchar *pattern, + const gchar *flags); /** * Insert item to the cache using custom pattern and flags @@ -199,9 +205,9 @@ rspamd_regexp_t* rspamd_regexp_cache_query (struct rspamd_regexp_cache* cache, * @param flags * @param re */ -void rspamd_regexp_cache_insert (struct rspamd_regexp_cache* cache, - const gchar *pattern, - const gchar *flags, rspamd_regexp_t *re); +void rspamd_regexp_cache_insert (struct rspamd_regexp_cache *cache, + const gchar *pattern, + const gchar *flags, rspamd_regexp_t *re); /** * Create or get cached regexp from the specified cache @@ -211,9 +217,9 @@ void rspamd_regexp_cache_insert (struct rspamd_regexp_cache* cache, * @param err error pointer set if compilation failed * @return new regexp object */ -rspamd_regexp_t* rspamd_regexp_cache_create (struct rspamd_regexp_cache *cache, - const gchar *pattern, - const gchar *flags, GError **err); +rspamd_regexp_t *rspamd_regexp_cache_create (struct rspamd_regexp_cache *cache, + const gchar *pattern, + const gchar *flags, GError **err); /** * Remove regexp from the cache @@ -222,7 +228,7 @@ rspamd_regexp_t* rspamd_regexp_cache_create (struct rspamd_regexp_cache *cache, * @return TRUE if a regexp has been removed */ gboolean rspamd_regexp_cache_remove (struct rspamd_regexp_cache *cache, - rspamd_regexp_t *re); + rspamd_regexp_t *re); /** * Destroy regexp cache and unref all elements inside it @@ -268,4 +274,8 @@ void rspamd_regexp_library_finalize (void); */ rspamd_regexp_t *rspamd_regexp_from_glob (const gchar *gl, gsize sz, GError **err); +#ifdef __cplusplus +} +#endif + #endif /* REGEXP_H_ */ diff --git a/src/libutil/rrd.c b/src/libutil/rrd.c index d17e823e6..9208c71da 100644 --- a/src/libutil/rrd.c +++ b/src/libutil/rrd.c @@ -16,6 +16,7 @@ #include "config.h" #include "rrd.h" #include "util.h" +#include "cfg_file.h" #include "logger.h" #include "unix-std.h" #include "cryptobox.h" diff --git a/src/libutil/rrd.h b/src/libutil/rrd.h index d24249965..ffffa921d 100644 --- a/src/libutil/rrd.h +++ b/src/libutil/rrd.h @@ -26,6 +26,10 @@ #define RRD_VERSION "0003" #define RRD_FLOAT_COOKIE ((double)8.642135E130) +#ifdef __cplusplus +extern "C" { +#endif + typedef union { unsigned long lv; double dv; @@ -139,41 +143,41 @@ enum rrd_cdp_param { CDP_val = 0, /* the base_interval is always an * average */ - CDP_unkn_pdp_cnt, + CDP_unkn_pdp_cnt, /* how many unknown pdp were * integrated. This and the cdp_xff * will decide if this is going to * be a UNKNOWN or a valid value */ - CDP_hw_intercept, + CDP_hw_intercept, /* Current intercept coefficient for the Holt-Winters * prediction algorithm. */ - CDP_hw_last_intercept, + CDP_hw_last_intercept, /* Last iteration intercept coefficient for the Holt-Winters * prediction algorihtm. */ - CDP_hw_slope, + CDP_hw_slope, /* Current slope coefficient for the Holt-Winters * prediction algorithm. */ - CDP_hw_last_slope, + CDP_hw_last_slope, /* Last iteration slope coeffient. */ - CDP_null_count, + CDP_null_count, /* Number of sequential Unknown (DNAN) values + 1 preceding * the current prediction. * */ - CDP_last_null_count, + CDP_last_null_count, /* Last iteration count of Unknown (DNAN) values. */ - CDP_primary_val = 8, + CDP_primary_val = 8, /* optimization for bulk updates: the value of the first CDP * value to be written in the bulk update. */ - CDP_secondary_val = 9, + CDP_secondary_val = 9, /* optimization for bulk updates: the value of subsequent * CDP values to be written in the bulk update. */ - CDP_hw_seasonal = CDP_hw_intercept, + CDP_hw_seasonal = CDP_hw_intercept, /* Current seasonal coefficient for the Holt-Winters * prediction algorithm. This is stored in CDP prep to avoid * redundant seek operations. */ - CDP_hw_last_seasonal = CDP_hw_last_intercept, + CDP_hw_last_seasonal = CDP_hw_last_intercept, /* Last iteration seasonal coefficient. */ - CDP_seasonal_deviation = CDP_hw_intercept, + CDP_seasonal_deviation = CDP_hw_intercept, CDP_last_seasonal_deviation = CDP_hw_last_intercept, CDP_init_seasonal = CDP_null_count }; @@ -200,7 +204,7 @@ struct rspamd_rrd_file { gdouble *rrd_value; /* list of rrd values */ gchar *filename; - guint8 * map; /* mmapped area */ + guint8 *map; /* mmapped area */ gsize size; /* its size */ gboolean finalized; gchar *id; @@ -216,7 +220,7 @@ struct rspamd_rrd_file { * @param err error pointer * @return rrd file structure */ -struct rspamd_rrd_file * rspamd_rrd_open (const gchar *filename, GError **err); +struct rspamd_rrd_file *rspamd_rrd_open (const gchar *filename, GError **err); /** * Create basic header for rrd file @@ -228,11 +232,11 @@ struct rspamd_rrd_file * rspamd_rrd_open (const gchar *filename, GError **err); * @return TRUE if file has been created */ struct rspamd_rrd_file *rspamd_rrd_create (const gchar *filename, - gulong ds_count, - gulong rra_count, - gulong pdp_step, - gdouble initial_ticks, - GError **err); + gulong ds_count, + gulong rra_count, + gulong pdp_step, + gdouble initial_ticks, + GError **err); /** * Add data sources to rrd file @@ -241,9 +245,9 @@ struct rspamd_rrd_file *rspamd_rrd_create (const gchar *filename, * @param err error pointer * @return TRUE if data sources were added */ -gboolean rspamd_rrd_add_ds (struct rspamd_rrd_file * file, - GArray *ds, - GError **err); +gboolean rspamd_rrd_add_ds (struct rspamd_rrd_file *file, + GArray *ds, + GError **err); /** * Add round robin archives to rrd file @@ -253,8 +257,8 @@ gboolean rspamd_rrd_add_ds (struct rspamd_rrd_file * file, * @return TRUE if archives were added */ gboolean rspamd_rrd_add_rra (struct rspamd_rrd_file *file, - GArray *rra, - GError **err); + GArray *rra, + GError **err); /** * Finalize rrd file header and initialize all RRA in the file @@ -272,16 +276,16 @@ gboolean rspamd_rrd_finalize (struct rspamd_rrd_file *file, GError **err); * @return TRUE if a row has been added */ gboolean rspamd_rrd_add_record (struct rspamd_rrd_file *file, - GArray *points, - gdouble ticks, - GError **err); + GArray *points, + gdouble ticks, + GError **err); /** * Close rrd file * @param file * @return */ -gint rspamd_rrd_close (struct rspamd_rrd_file * file); +gint rspamd_rrd_close (struct rspamd_rrd_file *file); /* * Conversion functions @@ -291,18 +295,21 @@ gint rspamd_rrd_close (struct rspamd_rrd_file * file); * Convert rrd dst type from string to numeric value */ enum rrd_dst_type rrd_dst_from_string (const gchar *str); + /** * Convert numeric presentation of dst to string */ -const gchar * rrd_dst_to_string (enum rrd_dst_type type); +const gchar *rrd_dst_to_string (enum rrd_dst_type type); + /** * Convert rrd consolidation function type from string to numeric value */ enum rrd_cf_type rrd_cf_from_string (const gchar *str); + /** * Convert numeric presentation of cf to string */ -const gchar * rrd_cf_to_string (enum rrd_cf_type type); +const gchar *rrd_cf_to_string (enum rrd_cf_type type); /* Default RRA and DS */ @@ -310,23 +317,23 @@ const gchar * rrd_cf_to_string (enum rrd_cf_type type); * Create default RRA */ void rrd_make_default_rra (const gchar *cf_name, - gulong pdp_cnt, - gulong rows, - struct rrd_rra_def *rra); + gulong pdp_cnt, + gulong rows, + struct rrd_rra_def *rra); /** * Create default DS */ void rrd_make_default_ds (const gchar *name, - const gchar *type, - gulong pdp_step, - struct rrd_ds_def *ds); + const gchar *type, + gulong pdp_step, + struct rrd_ds_def *ds); /** * Open or create the default rspamd rrd file */ struct rspamd_rrd_file *rspamd_rrd_file_default (const gchar *path, - GError **err); + GError **err); /** * Returned by querying rrd database @@ -346,6 +353,11 @@ struct rspamd_rrd_query_result { * @param rra_num number of rra to return data for * @return query result structure, that should be freed (using g_slice_free1) after usage */ -struct rspamd_rrd_query_result * rspamd_rrd_query (struct rspamd_rrd_file *file, - gulong rra_num); +struct rspamd_rrd_query_result *rspamd_rrd_query (struct rspamd_rrd_file *file, + gulong rra_num); + +#ifdef __cplusplus +} +#endif + #endif /* RRD_H_ */ diff --git a/src/libutil/shingles.h b/src/libutil/shingles.h index 5a107bdc4..2b2af9737 100644 --- a/src/libutil/shingles.h +++ b/src/libutil/shingles.h @@ -21,6 +21,10 @@ #define RSPAMD_SHINGLE_SIZE 32 +#ifdef __cplusplus +extern "C" { +#endif + struct rspamd_shingle { guint64 hashes[RSPAMD_SHINGLE_SIZE]; }; @@ -39,7 +43,7 @@ enum rspamd_shingle_alg { * @return shingle value */ typedef guint64 (*rspamd_shingles_filter) (guint64 *input, gsize count, - gint shno, const guchar *key, gpointer ud); + gint shno, const guchar *key, gpointer ud); /** * Generate shingles from the input of fixed size strings using lemmatizer @@ -51,12 +55,12 @@ typedef guint64 (*rspamd_shingles_filter) (guint64 *input, gsize count, * @param filterd opaque data for filtering function * @return shingles array */ -struct rspamd_shingle* rspamd_shingles_from_text (GArray *input, - const guchar key[16], - rspamd_mempool_t *pool, - rspamd_shingles_filter filter, - gpointer filterd, - enum rspamd_shingle_alg alg); +struct rspamd_shingle *rspamd_shingles_from_text (GArray *input, + const guchar key[16], + rspamd_mempool_t *pool, + rspamd_shingles_filter filter, + gpointer filterd, + enum rspamd_shingle_alg alg); /** * Generate shingles from the DCT matrix of an image @@ -67,12 +71,12 @@ struct rspamd_shingle* rspamd_shingles_from_text (GArray *input, * @param filterd opaque data for filtering function * @return shingles array */ -struct rspamd_shingle* rspamd_shingles_from_image (guchar *dct, - const guchar key[16], - rspamd_mempool_t *pool, - rspamd_shingles_filter filter, - gpointer filterd, - enum rspamd_shingle_alg alg); +struct rspamd_shingle *rspamd_shingles_from_image (guchar *dct, + const guchar key[16], + rspamd_mempool_t *pool, + rspamd_shingles_filter filter, + gpointer filterd, + enum rspamd_shingle_alg alg); /** * Compares two shingles and return result as a floating point value - 1.0 @@ -82,12 +86,16 @@ struct rspamd_shingle* rspamd_shingles_from_image (guchar *dct, * @return */ gdouble rspamd_shingles_compare (const struct rspamd_shingle *a, - const struct rspamd_shingle *b); + const struct rspamd_shingle *b); /** * Default filtering function */ guint64 rspamd_shingles_default_filter (guint64 *input, gsize count, - gint shno, const guchar *key, gpointer ud); + gint shno, const guchar *key, gpointer ud); + +#ifdef __cplusplus +} +#endif #endif /* SHINGLES_H_ */ diff --git a/src/libutil/sqlite_utils.h b/src/libutil/sqlite_utils.h index 78ee26fc6..53f13747c 100644 --- a/src/libutil/sqlite_utils.h +++ b/src/libutil/sqlite_utils.h @@ -22,6 +22,10 @@ #define RSPAMD_SQLITE3_STMT_MULTIPLE (1 << 0) +#ifdef __cplusplus +extern "C" { +#endif + struct rspamd_sqlite3_prstmt { gint idx; const gchar *sql; @@ -39,10 +43,10 @@ struct rspamd_sqlite3_prstmt { * @param err * @return new prepared statements array or NULL */ -GArray* rspamd_sqlite3_init_prstmt (sqlite3 *db, - struct rspamd_sqlite3_prstmt *init_stmt, - gint max_idx, - GError **err); +GArray *rspamd_sqlite3_init_prstmt (sqlite3 *db, + struct rspamd_sqlite3_prstmt *init_stmt, + gint max_idx, + GError **err); /** * Run prepared statements by its index getting parameters and setting results from @@ -53,7 +57,7 @@ GArray* rspamd_sqlite3_init_prstmt (sqlite3 *db, * @return */ gint rspamd_sqlite3_run_prstmt (rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts, - gint idx, ...); + gint idx, ...); /** * Close and free prepared statements @@ -68,8 +72,9 @@ void rspamd_sqlite3_close_prstmt (sqlite3 *db, GArray *stmts); * @param create_sql * @return */ -sqlite3 * rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const - gchar *create_sql, guint32 version, GError **err); +sqlite3 *rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, + const gchar *path, const gchar *create_sql, + guint32 version, GError **err); /** @@ -78,4 +83,8 @@ sqlite3 * rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *pa */ gboolean rspamd_sqlite3_sync (sqlite3 *db, gint *wal_frames, gint *wal_checkpoints); +#ifdef __cplusplus +} +#endif + #endif /* SRC_LIBUTIL_SQLITE_UTILS_H_ */ diff --git a/src/libutil/ssl_util.h b/src/libutil/ssl_util.h index f7f1652de..75436f2cc 100644 --- a/src/libutil/ssl_util.h +++ b/src/libutil/ssl_util.h @@ -20,18 +20,23 @@ #include "libutil/addr.h" #include "libutil/libev_helper.h" +#ifdef __cplusplus +extern "C" { +#endif + struct rspamd_ssl_connection; -typedef void (*rspamd_ssl_handler_t)(gint fd, short what, gpointer d); -typedef void (*rspamd_ssl_error_handler_t)(gpointer d, GError *err); +typedef void (*rspamd_ssl_handler_t) (gint fd, short what, gpointer d); + +typedef void (*rspamd_ssl_error_handler_t) (gpointer d, GError *err); /** * Creates a new ssl connection data structure * @param ssl_ctx initialized SSL_CTX structure * @return opaque connection data */ -struct rspamd_ssl_connection * rspamd_ssl_connection_new (gpointer ssl_ctx, - struct ev_loop *ev_base, gboolean verify_peer); +struct rspamd_ssl_connection *rspamd_ssl_connection_new (gpointer ssl_ctx, + struct ev_loop *ev_base, gboolean verify_peer); /** * Connects SSL session using the specified (connected) FD @@ -45,9 +50,9 @@ struct rspamd_ssl_connection * rspamd_ssl_connection_new (gpointer ssl_ctx, * @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, - rspamd_ssl_handler_t handler, rspamd_ssl_error_handler_t err_handler, - gpointer handler_data); + const gchar *hostname, struct rspamd_io_ev *ev, ev_tstamp timeout, + rspamd_ssl_handler_t handler, rspamd_ssl_error_handler_t err_handler, + gpointer handler_data); /** * Perform async read from SSL socket @@ -57,7 +62,7 @@ gboolean rspamd_ssl_connect_fd (struct rspamd_ssl_connection *conn, gint fd, * @return */ gssize rspamd_ssl_read (struct rspamd_ssl_connection *conn, gpointer buf, - gsize buflen); + gsize buflen); /** * Perform async write to ssl buffer @@ -69,7 +74,7 @@ gssize rspamd_ssl_read (struct rspamd_ssl_connection *conn, gpointer buf, * @return */ gssize rspamd_ssl_write (struct rspamd_ssl_connection *conn, gconstpointer buf, - gsize buflen); + gsize buflen); /** * Emulate writev by copying iovec to a temporary buffer @@ -79,7 +84,7 @@ gssize rspamd_ssl_write (struct rspamd_ssl_connection *conn, gconstpointer buf, * @return */ gssize rspamd_ssl_writev (struct rspamd_ssl_connection *conn, struct iovec *iov, - gsize iovlen); + gsize iovlen); /** * Removes connection data @@ -87,4 +92,8 @@ gssize rspamd_ssl_writev (struct rspamd_ssl_connection *conn, struct iovec *iov, */ void rspamd_ssl_connection_free (struct rspamd_ssl_connection *conn); +#ifdef __cplusplus +} +#endif + #endif /* SRC_LIBUTIL_SSL_UTIL_H_ */ diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h index 6fbb11ccf..c820bd10c 100644 --- a/src/libutil/str_util.h +++ b/src/libutil/str_util.h @@ -20,6 +20,9 @@ #include "ucl.h" #include "fstring.h" +#ifdef __cplusplus +extern "C" { +#endif enum rspamd_newlines_type { RSPAMD_TASK_NEWLINES_CR, @@ -37,6 +40,7 @@ gint rspamd_lc_cmp (const gchar *s, const gchar *d, gsize l); * Convert string to lowercase in-place using ASCII conversion */ void rspamd_str_lc (gchar *str, guint size); + /** * Convert string to lowercase in-place using utf (limited) conversion */ @@ -46,13 +50,16 @@ void rspamd_str_lc_utf8 (gchar *str, guint size); * Hash table utility functions for case insensitive hashing */ guint64 rspamd_icase_hash (const gchar *in, gsize len, guint64 seed); + guint rspamd_strcase_hash (gconstpointer key); + gboolean rspamd_strcase_equal (gconstpointer v, gconstpointer v2); /* * Hash table utility functions for case sensitive hashing */ guint rspamd_str_hash (gconstpointer key); + gboolean rspamd_str_equal (gconstpointer v, gconstpointer v2); @@ -60,10 +67,15 @@ gboolean rspamd_str_equal (gconstpointer v, gconstpointer v2); * Hash table utility functions for hashing fixed strings */ guint rspamd_ftok_icase_hash (gconstpointer key); + gboolean rspamd_ftok_icase_equal (gconstpointer v, gconstpointer v2); + guint rspamd_ftok_hash (gconstpointer key); + gboolean rspamd_ftok_equal (gconstpointer v, gconstpointer v2); + guint rspamd_gstring_icase_hash (gconstpointer key); + gboolean rspamd_gstring_icase_equal (gconstpointer v, gconstpointer v2); /** @@ -77,6 +89,7 @@ gboolean rspamd_gstring_icase_equal (gconstpointer v, gconstpointer v2); * @return bytes copied */ gsize rspamd_strlcpy_fast (gchar *dst, const gchar *src, gsize siz); + gsize rspamd_strlcpy_safe (gchar *dst, const gchar *src, gsize siz); #if defined(__has_feature) @@ -133,7 +146,7 @@ gpointer rspamd_str_pool_copy (gconstpointer data, gpointer ud); * @param inlen input length * @return freshly allocated base32 encoding of a specified string */ -gchar * rspamd_encode_base32 (const guchar *in, gsize inlen); +gchar *rspamd_encode_base32 (const guchar *in, gsize inlen); /** * Decode string using base32 encoding @@ -141,7 +154,7 @@ gchar * rspamd_encode_base32 (const guchar *in, gsize inlen); * @param inlen input length * @return freshly allocated base32 decoded value or NULL if input is invalid */ -guchar* rspamd_decode_base32 (const gchar *in, gsize inlen, gsize *outlen); +guchar *rspamd_decode_base32 (const gchar *in, gsize inlen, gsize *outlen); /** * Encode string using hex encoding @@ -149,7 +162,7 @@ guchar* rspamd_decode_base32 (const gchar *in, gsize inlen, gsize *outlen); * @param inlen input length * @return freshly allocated base32 encoding of a specified string */ -gchar * rspamd_encode_hex (const guchar *in, gsize inlen); +gchar *rspamd_encode_hex (const guchar *in, gsize inlen); /** * Decode string using hex encoding @@ -157,7 +170,7 @@ gchar * rspamd_encode_hex (const guchar *in, gsize inlen); * @param inlen input length * @return freshly allocated base32 decoded value or NULL if input is invalid */ -guchar* rspamd_decode_hex (const gchar *in, gsize inlen); +guchar *rspamd_decode_hex (const gchar *in, gsize inlen); /** * Encode string using base32 encoding @@ -168,7 +181,7 @@ guchar* rspamd_decode_hex (const gchar *in, gsize inlen); * @return encoded len if `outlen` is enough to encode `inlen` */ gint rspamd_encode_base32_buf (const guchar *in, gsize inlen, gchar *out, - gsize outlen); + gsize outlen); /** * Decode string using base32 encoding @@ -179,7 +192,7 @@ gint rspamd_encode_base32_buf (const guchar *in, gsize inlen, gchar *out, * @return decoded len if in is valid base32 and `outlen` is enough to encode `inlen` */ gint rspamd_decode_base32_buf (const gchar *in, gsize inlen, - guchar *out, gsize outlen); + guchar *out, gsize outlen); /** * Encode string using hex encoding @@ -190,7 +203,7 @@ gint rspamd_decode_base32_buf (const gchar *in, gsize inlen, * @return encoded len if `outlen` is enough to encode `inlen` */ gint rspamd_encode_hex_buf (const guchar *in, gsize inlen, gchar *out, - gsize outlen); + gsize outlen); /** @@ -202,7 +215,7 @@ gint rspamd_encode_hex_buf (const guchar *in, gsize inlen, gchar *out, * @return decoded len if in is valid hex and `outlen` is enough to encode `inlen` */ gssize rspamd_decode_hex_buf (const gchar *in, gsize inlen, - guchar *out, gsize outlen); + guchar *out, gsize outlen); /** * Common version of base64 encoder @@ -221,6 +234,7 @@ rspamd_encode_base64_common (const guchar *in, gsize *outlen, gboolean fold, enum rspamd_newlines_type how); + /** * Encode string using base64 encoding * @param in input @@ -228,8 +242,8 @@ rspamd_encode_base64_common (const guchar *in, * @param str_len maximum string length (if <= 0 then no lines are split) * @return freshly allocated base64 encoded value or NULL if input is invalid */ -gchar * rspamd_encode_base64 (const guchar *in, gsize inlen, gint str_len, - gsize *outlen); +gchar *rspamd_encode_base64 (const guchar *in, gsize inlen, gint str_len, + gsize *outlen); /** * Encode and fold string using base64 encoding @@ -238,8 +252,8 @@ gchar * rspamd_encode_base64 (const guchar *in, gsize inlen, gint str_len, * @param str_len maximum string length (if <= 0 then no lines are split) * @return freshly allocated base64 encoded value or NULL if input is invalid */ -gchar * rspamd_encode_base64_fold (const guchar *in, gsize inlen, gint str_len, - gsize *outlen, enum rspamd_newlines_type how); +gchar *rspamd_encode_base64_fold (const guchar *in, gsize inlen, gint str_len, + gsize *outlen, enum rspamd_newlines_type how); /** * Encode and fold string using quoted printable encoding @@ -248,8 +262,8 @@ gchar * rspamd_encode_base64_fold (const guchar *in, gsize inlen, gint str_len, * @param str_len maximum string length (if <= 0 then no lines are split) * @return freshly allocated base64 encoded value or NULL if input is invalid */ -gchar * rspamd_encode_qp_fold (const guchar *in, gsize inlen, gint str_len, - gsize *outlen, enum rspamd_newlines_type how); +gchar *rspamd_encode_qp_fold (const guchar *in, gsize inlen, gint str_len, + gsize *outlen, enum rspamd_newlines_type how); /** * Decode quoted-printable encoded buffer, input and output must not overlap @@ -260,7 +274,7 @@ gchar * rspamd_encode_qp_fold (const guchar *in, gsize inlen, gint str_len, * @return real size of decoded output or (-1) if outlen is not enough */ gssize rspamd_decode_qp_buf (const gchar *in, gsize inlen, - gchar *out, gsize outlen); + gchar *out, gsize outlen); /** * Decode quoted-printable encoded buffer using rfc2047 format, input and output must not overlap @@ -271,7 +285,7 @@ gssize rspamd_decode_qp_buf (const gchar *in, gsize inlen, * @return real size of decoded output or (-1) if outlen is not enough */ gssize rspamd_decode_qp2047_buf (const gchar *in, gsize inlen, - gchar *out, gsize outlen); + gchar *out, gsize outlen); /** * Encode quoted-printable buffer using rfc2047 format, input and output must not overlap @@ -282,7 +296,7 @@ gssize rspamd_decode_qp2047_buf (const gchar *in, gsize inlen, * @return */ gssize rspamd_encode_qp2047_buf (const gchar *in, gsize inlen, - gchar *out, gsize outlen); + gchar *out, gsize outlen); #ifndef g_tolower # define g_tolower(x) (((x) >= 'A' && (x) <= 'Z') ? (x) - 'A' + 'a' : (x)) @@ -297,7 +311,7 @@ gssize rspamd_encode_qp2047_buf (const gchar *in, gsize inlen, * @return */ gint rspamd_strings_levenshtein_distance (const gchar *s1, gsize s1len, - const gchar *s2, gsize s2len, guint replace_cost); + const gchar *s2, gsize s2len, guint replace_cost); /** * Fold header using rfc822 rules, return new GString from the previous one @@ -309,10 +323,10 @@ gint rspamd_strings_levenshtein_distance (const gchar *s1, gsize s1len, * @return new GString with the folded value */ GString *rspamd_header_value_fold (const gchar *name, - const gchar *value, - guint fold_max, - enum rspamd_newlines_type how, - const gchar *fold_on_chars); + const gchar *value, + guint fold_max, + enum rspamd_newlines_type how, + const gchar *fold_on_chars); /** * Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm @@ -324,7 +338,7 @@ GString *rspamd_header_value_fold (const gchar *name, * @return position of the first substring match or (-1) if not found */ goffset rspamd_substring_search (const gchar *in, gsize inlen, - const gchar *srch, gsize srchlen); + const gchar *srch, gsize srchlen); /** * Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm in caseless matter (ASCII only) @@ -336,7 +350,7 @@ goffset rspamd_substring_search (const gchar *in, gsize inlen, * @return position of the first substring match or (-1) if not found */ goffset rspamd_substring_search_caseless (const gchar *in, gsize inlen, - const gchar *srch, gsize srchlen); + const gchar *srch, gsize srchlen); /** * Search for end-of-headers mark in the input string. Returns position just after @@ -348,7 +362,8 @@ goffset rspamd_string_find_eoh (GString *input, goffset *body_start); #define rspamd_ucl_emit_gstring(o, t, target) \ - rspamd_ucl_emit_gstring_comments((o), (t), (target), NULL) + rspamd_ucl_emit_gstring_comments((o), (t), (target), NULL) + /** * Emit UCL object to gstring * @param obj object to emit @@ -357,12 +372,13 @@ goffset rspamd_string_find_eoh (GString *input, goffset *body_start); * @param target target string */ void rspamd_ucl_emit_gstring_comments (const ucl_object_t *obj, - enum ucl_emitter emit_type, - GString *target, - const ucl_object_t *comments); + enum ucl_emitter emit_type, + GString *target, + const ucl_object_t *comments); #define rspamd_ucl_emit_fstring(o, t, target) \ - rspamd_ucl_emit_fstring_comments((o), (t), (target), NULL) + rspamd_ucl_emit_fstring_comments((o), (t), (target), NULL) + /** * Emit UCL object to fstring * @param obj object to emit @@ -371,9 +387,9 @@ void rspamd_ucl_emit_gstring_comments (const ucl_object_t *obj, * @param target target string */ void rspamd_ucl_emit_fstring_comments (const ucl_object_t *obj, - enum ucl_emitter emit_type, - rspamd_fstring_t **target, - const ucl_object_t *comments); + enum ucl_emitter emit_type, + rspamd_fstring_t **target, + const ucl_object_t *comments); extern const guchar lc_map[256]; @@ -405,27 +421,26 @@ gsize rspamd_memcspn (const gchar *s, const gchar *e, gsize len); gsize rspamd_memspn (const gchar *s, const gchar *e, gsize len); /* https://graphics.stanford.edu/~seander/bithacks.html#HasMoreInWord */ -#define rspamd_str_hasmore(x,n) ((((x)+~0UL/255*(127-(n)))|(x))&~0UL/255*128) +#define rspamd_str_hasmore(x, n) ((((x)+~0UL/255*(127-(n)))|(x))&~0UL/255*128) static inline gboolean -rspamd_str_has_8bit (const guchar *beg, gsize len) -{ +rspamd_str_has_8bit (const guchar *beg, gsize len) { unsigned long *w; gsize i, leftover = len % sizeof (*w); - w = (unsigned long *)beg; + w = (unsigned long *) beg; - for (i = 0; i < len / sizeof (*w); i ++) { + for (i = 0; i < len / sizeof (*w); i++) { if (rspamd_str_hasmore (*w, 127)) { return TRUE; } - w ++; + w++; } - beg = (const guchar *)w; + beg = (const guchar *) w; - for (i = 0; i < leftover; i ++) { + for (i = 0; i < leftover; i++) { if (beg[i] > 127) { return TRUE; } @@ -435,9 +450,11 @@ rspamd_str_has_8bit (const guchar *beg, gsize len) } struct UConverter; + struct UConverter *rspamd_get_utf8_converter (void); struct UNormalizer2; + const struct UNormalizer2 *rspamd_get_unicode_normalizer (void); enum rspamd_normalise_result { @@ -456,7 +473,7 @@ enum rspamd_normalise_result { * @return TRUE if a string has been normalised */ enum rspamd_normalise_result rspamd_normalise_unicode_inplace (rspamd_mempool_t *pool, - gchar *start, guint *len); + gchar *start, guint *len); enum rspamd_regexp_escape_flags { RSPAMD_REGEXP_ESCAPE_ASCII = 0, @@ -464,6 +481,7 @@ enum rspamd_regexp_escape_flags { RSPAMD_REGEXP_ESCAPE_GLOB = 1u << 1, RSPAMD_REGEXP_ESCAPE_RE = 1u << 2, }; + /** * Escapes special characters when reading plain data to be processed in pcre * @param pattern pattern to process @@ -474,7 +492,7 @@ enum rspamd_regexp_escape_flags { */ gchar * rspamd_str_regexp_escape (const gchar *pattern, gsize slen, - gsize *dst_len, enum rspamd_regexp_escape_flags flags); + gsize *dst_len, enum rspamd_regexp_escape_flags flags); /** * Returns copy of src (zero terminated) where all unicode is made valid or replaced @@ -484,7 +502,7 @@ rspamd_str_regexp_escape (const gchar *pattern, gsize slen, * @param dstelen * @return */ -gchar * rspamd_str_make_utf_valid (const guchar *src, gsize slen, gsize *dstlen); +gchar *rspamd_str_make_utf_valid (const guchar *src, gsize slen, gsize *dstlen); /** * Strips characters in `strip_chars` from start and end of the GString @@ -498,19 +516,23 @@ gsize rspamd_gstring_strip (GString *s, const gchar *strip_chars); * @param s * @param strip_chars */ -const gchar* rspamd_string_len_strip (const gchar *in, - gsize *len, const gchar *strip_chars); +const gchar *rspamd_string_len_strip (const gchar *in, + gsize *len, const gchar *strip_chars); #define IS_ZERO_WIDTH_SPACE(uc) ((uc) == 0x200B || \ - (uc) == 0x200C || \ - (uc) == 0x200D || \ - (uc) == 0xFEFF) + (uc) == 0x200C || \ + (uc) == 0x200D || \ + (uc) == 0xFEFF) #define IS_OBSCURED_CHAR(uc) (((uc) >= 0x200B && (uc) <= 0x200F) || \ - ((uc) >= 0x2028 && (uc) <= 0x202F) || \ - ((uc) >= 0x205F && (uc) <= 0x206F) || \ - (uc) == 0xFEFF) + ((uc) >= 0x2028 && (uc) <= 0x202F) || \ + ((uc) >= 0x205F && (uc) <= 0x206F) || \ + (uc) == 0xFEFF) #define RSPAMD_LEN_CHECK_STARTS_WITH(s, len, lit) \ - ((len) >= sizeof(lit) - 1 && g_ascii_strncasecmp ((s), (lit), sizeof(lit) - 1) == 0) + ((len) >= sizeof(lit) - 1 && g_ascii_strncasecmp ((s), (lit), sizeof(lit) - 1) == 0) + +#ifdef __cplusplus +} +#endif #endif /* SRC_LIBUTIL_STR_UTIL_H_ */ diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h index 89ac0ee9e..04ec6d984 100644 --- a/src/libutil/upstream.h +++ b/src/libutil/upstream.h @@ -6,6 +6,10 @@ #include "rdns.h" #include "ucl.h" +#ifdef __cplusplus +extern "C" { +#endif + enum rspamd_upstream_rotation { RSPAMD_UPSTREAM_RANDOM = 0, RSPAMD_UPSTREAM_HASHED, @@ -29,7 +33,7 @@ struct upstream_ctx; * Init upstreams library * @param resolver */ -struct upstream_ctx* rspamd_upstreams_library_init (void); +struct upstream_ctx *rspamd_upstreams_library_init (void); /** * Remove reference from upstreams library @@ -41,8 +45,8 @@ void rspamd_upstreams_library_unref (struct upstream_ctx *ctx); * @param cfg */ void rspamd_upstreams_library_config (struct rspamd_config *cfg, - struct upstream_ctx *ctx, struct ev_loop *event_loop, - struct rdns_resolver *resolver); + struct upstream_ctx *ctx, struct ev_loop *event_loop, + struct rdns_resolver *resolver); /** * Upstream error logic @@ -72,7 +76,7 @@ void rspamd_upstream_set_weight (struct upstream *up, guint weight); * Create new list of upstreams * @return */ -struct upstream_list* rspamd_upstreams_create (struct upstream_ctx *ctx); +struct upstream_list *rspamd_upstreams_create (struct upstream_ctx *ctx); /** * Sets specific flag to the upstream list @@ -80,7 +84,7 @@ struct upstream_list* rspamd_upstreams_create (struct upstream_ctx *ctx); * @param flags */ void rspamd_upstreams_set_flags (struct upstream_list *ups, - enum rspamd_upstream_flag flags); + enum rspamd_upstream_flag flags); /** * Sets custom limits for upstreams @@ -106,7 +110,7 @@ void rspamd_upstreams_set_limits (struct upstream_list *ups, * @param rot */ void rspamd_upstreams_set_rotation (struct upstream_list *ups, - enum rspamd_upstream_rotation rot); + enum rspamd_upstream_rotation rot); /** * Destroy list of upstreams @@ -142,8 +146,8 @@ enum rspamd_upstream_parse_type { * @return TRUE if upstream has been added */ gboolean rspamd_upstreams_add_upstream (struct upstream_list *ups, const gchar *str, - guint16 def_port, enum rspamd_upstream_parse_type parse_type, - void *data); + guint16 def_port, enum rspamd_upstream_parse_type parse_type, + void *data); /** * Add multiple upstreams from comma, semicolon or space separated line @@ -154,13 +158,14 @@ gboolean rspamd_upstreams_add_upstream (struct upstream_list *ups, const gchar * * @return TRUE if **any** of upstreams has been added */ gboolean rspamd_upstreams_parse_line (struct upstream_list *ups, - const gchar *str, guint16 def_port, void *data); + const gchar *str, guint16 def_port, void *data); gboolean rspamd_upstreams_parse_line_len (struct upstream_list *ups, const gchar *str, gsize len, guint16 def_port, void *data); + /** * Parse upstreams list from the UCL object * @param ups @@ -170,11 +175,11 @@ gboolean rspamd_upstreams_parse_line_len (struct upstream_list *ups, * @return */ gboolean rspamd_upstreams_from_ucl (struct upstream_list *ups, - const ucl_object_t *in, guint16 def_port, void *data); + const ucl_object_t *in, guint16 def_port, void *data); typedef void (*rspamd_upstream_traverse_func) (struct upstream *up, guint idx, - void *ud); + void *ud); /** * Traverse upstreams list calling the function specified @@ -183,7 +188,7 @@ typedef void (*rspamd_upstream_traverse_func) (struct upstream *up, guint idx, * @param ud */ void rspamd_upstreams_foreach (struct upstream_list *ups, - rspamd_upstream_traverse_func cb, void *ud); + rspamd_upstream_traverse_func cb, void *ud); enum rspamd_upstreams_watch_event { RSPAMD_UPSTREAM_WATCH_SUCCESS = 1u << 0, @@ -216,14 +221,14 @@ void rspamd_upstreams_add_watch_callback (struct upstream_list *ups, * @param up * @return */ -rspamd_inet_addr_t* rspamd_upstream_addr_next (struct upstream *up); +rspamd_inet_addr_t *rspamd_upstream_addr_next (struct upstream *up); /** * Returns the current IP address of the upstream * @param up * @return */ -rspamd_inet_addr_t* rspamd_upstream_addr_cur (const struct upstream *up); +rspamd_inet_addr_t *rspamd_upstream_addr_cur (const struct upstream *up); /** * Add custom address for an upstream (ownership of addr is transferred to upstream) @@ -231,14 +236,14 @@ rspamd_inet_addr_t* rspamd_upstream_addr_cur (const struct upstream *up); * @return */ gboolean rspamd_upstream_add_addr (struct upstream *up, - rspamd_inet_addr_t *addr); + rspamd_inet_addr_t *addr); /** * Returns the symbolic name of the upstream * @param up * @return */ -const gchar* rspamd_upstream_name (struct upstream *up); +const gchar *rspamd_upstream_name (struct upstream *up); /** * Sets opaque user data associated with this upstream @@ -261,9 +266,9 @@ gpointer rspamd_upstream_get_data (struct upstream *up); * @param type type of rotation algorithm, for `RSPAMD_UPSTREAM_HASHED` it is required to specify `key` and `keylen` as arguments * @return */ -struct upstream* rspamd_upstream_get (struct upstream_list *ups, - enum rspamd_upstream_rotation default_type, - const guchar *key, gsize keylen); +struct upstream *rspamd_upstream_get (struct upstream_list *ups, + enum rspamd_upstream_rotation default_type, + const guchar *key, gsize keylen); /** * Get new upstream from the list @@ -271,16 +276,17 @@ struct upstream* rspamd_upstream_get (struct upstream_list *ups, * @param type type of rotation algorithm, for `RSPAMD_UPSTREAM_HASHED` it is required to specify `key` and `keylen` as arguments * @return */ -struct upstream* rspamd_upstream_get_forced (struct upstream_list *ups, - enum rspamd_upstream_rotation forced_type, - const guchar *key, gsize keylen); +struct upstream *rspamd_upstream_get_forced (struct upstream_list *ups, + enum rspamd_upstream_rotation forced_type, + const guchar *key, gsize keylen); /** * Re-resolve addresses for all upstreams registered */ void rspamd_upstream_reresolve (struct upstream_ctx *ctx); +#ifdef __cplusplus +} +#endif + #endif /* UPSTREAM_H */ -/* - * vi:ts=4 - */ diff --git a/src/libutil/util.h b/src/libutil/util.h index 7f13ded06..7c9eb5f91 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -15,6 +15,10 @@ #include "contrib/libev/ev.h" #include <time.h> +#ifdef __cplusplus +extern "C" { +#endif + struct rspamd_config; struct rspamd_main; struct workq; @@ -28,10 +32,12 @@ struct workq; * @return socket FD or -1 in case of error */ gint rspamd_socket_create (gint af, gint type, gint protocol, gboolean async); + /* * Create socket and bind or connect it to specified address and port */ gint rspamd_socket_tcp (struct addrinfo *, gboolean is_server, gboolean async); + /* * Create socket and bind or connect it to specified address and port */ @@ -41,10 +47,10 @@ gint rspamd_socket_udp (struct addrinfo *, gboolean is_server, gboolean async); * Create and bind or connect unix socket */ gint rspamd_socket_unix (const gchar *, - struct sockaddr_un *, - gint type, - gboolean is_server, - gboolean async); + struct sockaddr_un *, + gint type, + gboolean is_server, + gboolean async); /** * Make a universal socket @@ -56,7 +62,7 @@ gint rspamd_socket_unix (const gchar *, * @param try_resolve try name resolution for a socket (BLOCKING) */ gint rspamd_socket (const gchar *credits, guint16 port, gint type, - gboolean async, gboolean is_server, gboolean try_resolve); + gboolean async, gboolean is_server, gboolean try_resolve); /** * Make a universal sockets @@ -67,12 +73,13 @@ gint rspamd_socket (const gchar *credits, guint16 port, gint type, * @param is_server make this socket as server socket * @param try_resolve try name resolution for a socket (BLOCKING) */ -GList * rspamd_sockets_list (const gchar *credits, - guint16 port, - gint type, - gboolean async, - gboolean is_server, - gboolean try_resolve); +GList *rspamd_sockets_list (const gchar *credits, + guint16 port, + gint type, + gboolean async, + gboolean is_server, + gboolean try_resolve); + /* * Create socketpair */ @@ -87,6 +94,7 @@ gint rspamd_write_pid (struct rspamd_main *); * Make specified socket non-blocking */ gint rspamd_socket_nonblocking (gint); + /* * Make specified socket blocking */ @@ -101,9 +109,11 @@ gint rspamd_socket_poll (gint fd, gint timeout, short events); * Init signals */ #ifdef HAVE_SA_SIGINFO -void rspamd_signals_init (struct sigaction *sa, void (*sig_handler)(gint, - siginfo_t *, - void *)); + +void rspamd_signals_init (struct sigaction *sa, void (*sig_handler) (gint, + siginfo_t *, + void *)); + #else void rspamd_signals_init (struct sigaction *sa, void (*sig_handler)(gint)); #endif @@ -111,14 +121,17 @@ void rspamd_signals_init (struct sigaction *sa, void (*sig_handler)(gint)); /* * Send specified signal to each worker */ -void rspamd_pass_signal (GHashTable *, gint ); +void rspamd_pass_signal (GHashTable *, gint); #ifndef HAVE_SETPROCTITLE + /* * Process title utility functions */ gint init_title (struct rspamd_main *, gint argc, gchar *argv[], gchar *envp[]); + gint setproctitle (const gchar *fmt, ...); + #endif #ifndef HAVE_PIDFILE @@ -137,12 +150,17 @@ typedef struct rspamd_pidfh_s { dev_t pf_dev; ino_t pf_ino; } rspamd_pidfh_t; -rspamd_pidfh_t * rspamd_pidfile_open (const gchar *path, - mode_t mode, - pid_t *pidptr); + +rspamd_pidfh_t *rspamd_pidfile_open (const gchar *path, + mode_t mode, + pid_t *pidptr); + gint rspamd_pidfile_write (rspamd_pidfh_t *pfh); + gint rspamd_pidfile_close (rspamd_pidfh_t *pfh); + gint rspamd_pidfile_remove (rspamd_pidfh_t *pfh); + #else typedef struct pidfh rspamd_pidfh_t; #define rspamd_pidfile_open pidfile_open @@ -154,10 +172,10 @@ typedef struct pidfh rspamd_pidfh_t; /* * Replace %r with rcpt value and %f with from value, new string is allocated in pool */ -gchar * resolve_stat_filename (rspamd_mempool_t *pool, - gchar *pattern, - gchar *rcpt, - gchar *from); +gchar *resolve_stat_filename (rspamd_mempool_t *pool, + gchar *pattern, + gchar *rcpt, + gchar *from); const gchar * rspamd_log_check_time (gdouble start, gdouble end, gint resolution); @@ -166,12 +184,14 @@ rspamd_log_check_time (gdouble start, gdouble end, gint resolution); * File locking functions */ gboolean rspamd_file_lock (gint fd, gboolean async); + gboolean rspamd_file_unlock (gint fd, gboolean async); /* * Google perf-tools initialization function */ void gperf_profiler_init (struct rspamd_config *cfg, const gchar *descr); + void gperf_profiler_stop (void); /* @@ -203,18 +223,18 @@ const gchar *g_environ_getenv (gchar **envp, const gchar *variable); * Convert milliseconds to timeval fields */ #define msec_to_tv(msec, tv) do { (tv)->tv_sec = (msec) / 1000; (tv)->tv_usec = \ - ((msec) - (tv)->tv_sec * 1000) * 1000; \ + ((msec) - (tv)->tv_sec * 1000) * 1000; \ } while (0) #define double_to_tv(dbl, tv) do { (tv)->tv_sec = (int)(dbl); (tv)->tv_usec = \ - ((dbl) - (int)(dbl)) * 1000 * 1000; \ + ((dbl) - (int)(dbl)) * 1000 * 1000; \ } while (0) #define double_to_ts(dbl, ts) do { (ts)->tv_sec = (int)(dbl); (ts)->tv_nsec = \ ((dbl) - (int)(dbl)) * 1e9; \ } while (0) #define tv_to_msec(tv) ((tv)->tv_sec * 1000LLU + (tv)->tv_usec / 1000LLU) #define tv_to_double(tv) ((double)(tv)->tv_sec + (tv)->tv_usec / 1.0e6) -#define ts_to_usec(ts) ((ts)->tv_sec * 1000000LLU + \ - (ts)->tv_nsec / 1000LLU) +#define ts_to_usec(ts) ((ts)->tv_sec * 1000000LLU + \ + (ts)->tv_nsec / 1000LLU) #define ts_to_double(tv) ((double)(tv)->tv_sec + (tv)->tv_nsec / 1.0e9) /** @@ -242,7 +262,7 @@ typedef struct rspamd_mutex_s { * Create new mutex * @return mutex or NULL */ -rspamd_mutex_t * rspamd_mutex_new (void); +rspamd_mutex_t *rspamd_mutex_new (void); /** * Lock mutex @@ -271,9 +291,9 @@ void rspamd_mutex_free (rspamd_mutex_t *mtx); * @param ud user data for copy functions */ void rspamd_hash_table_copy (GHashTable *src, GHashTable *dst, - gpointer (*key_copy_func)(gconstpointer data, gpointer ud), - gpointer (*value_copy_func)(gconstpointer data, gpointer ud), - gpointer ud); + gpointer (*key_copy_func) (gconstpointer data, gpointer ud), + gpointer (*value_copy_func) (gconstpointer data, gpointer ud), + gpointer ud); /** @@ -315,6 +335,7 @@ void rspamd_ptr_array_free_hard (gpointer p); * @param p */ void rspamd_array_free_hard (gpointer p); + /** * Special utility to help GString freeing in rspamd_mempool * @param p @@ -334,25 +355,28 @@ void rspamd_gerror_free_maybe (gpointer p); void rspamd_gstring_free_soft (gpointer p); struct rspamd_external_libs_ctx; + /** * Initialize rspamd libraries */ -struct rspamd_external_libs_ctx* rspamd_init_libs (void); +struct rspamd_external_libs_ctx *rspamd_init_libs (void); gpointer rspamd_init_ssl_ctx (void); + gpointer rspamd_init_ssl_ctx_noverify (void); /** * Configure libraries */ void rspamd_config_libs (struct rspamd_external_libs_ctx *ctx, - struct rspamd_config *cfg); + struct rspamd_config *cfg); /** * Reset and initialize decompressor * @param ctx */ gboolean rspamd_libs_reset_decompression (struct rspamd_external_libs_ctx *ctx); + /** * Reset and initialize compressor * @param ctx @@ -421,7 +445,7 @@ gboolean rspamd_constant_memcmp (const void *a, const void *b, gsize len); * @return fd or -1 in case of error */ int rspamd_file_xopen (const char *fname, int oflags, guint mode, - gboolean allow_symlink); + gboolean allow_symlink); /** * Map file without following symlinks or special stuff @@ -431,7 +455,7 @@ int rspamd_file_xopen (const char *fname, int oflags, guint mode, * @return pointer to memory (should be freed using munmap) or NULL in case of error */ gpointer rspamd_file_xmap (const char *fname, guint mode, gsize *size, - gboolean allow_symlink); + gboolean allow_symlink); /** * Map named shared memory segment @@ -441,7 +465,7 @@ gpointer rspamd_file_xmap (const char *fname, guint mode, gsize *size, * @return pointer to memory (should be freed using munmap) or NULL in case of error */ gpointer rspamd_shmem_xmap (const char *fname, guint mode, - gsize *size); + gsize *size); /** * Normalize probabilities using polynomial function @@ -521,4 +545,8 @@ double rspamd_set_counter_ema (struct rspamd_counter_data *cd, double rspamd_set_counter (struct rspamd_counter_data *cd, gdouble value); +#ifdef __cplusplus +} +#endif + #endif |