summaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/addr.c160
-rw-r--r--src/libutil/addr.h48
-rw-r--r--src/libutil/cxx/utf8_util.cxx6
-rw-r--r--src/libutil/cxx/utf8_util.h4
-rw-r--r--src/libutil/expression.c118
-rw-r--r--src/libutil/expression.h42
-rw-r--r--src/libutil/fstring.c36
-rw-r--r--src/libutil/fstring.h30
-rw-r--r--src/libutil/hash.c64
-rw-r--r--src/libutil/hash.h10
-rw-r--r--src/libutil/heap.c6
-rw-r--r--src/libutil/heap.h8
-rw-r--r--src/libutil/mem_pool.c144
-rw-r--r--src/libutil/mem_pool.h62
-rw-r--r--src/libutil/mem_pool_internal.h22
-rw-r--r--src/libutil/multipattern.c132
-rw-r--r--src/libutil/multipattern.h38
-rw-r--r--src/libutil/printf.c114
-rw-r--r--src/libutil/printf.h28
-rw-r--r--src/libutil/radix.c56
-rw-r--r--src/libutil/radix.h26
-rw-r--r--src/libutil/regexp.c116
-rw-r--r--src/libutil/regexp.h32
-rw-r--r--src/libutil/rrd.c144
-rw-r--r--src/libutil/rrd.h66
-rw-r--r--src/libutil/shingles.c58
-rw-r--r--src/libutil/shingles.h14
-rw-r--r--src/libutil/sqlite_utils.c32
-rw-r--r--src/libutil/sqlite_utils.h22
-rw-r--r--src/libutil/str_util.c510
-rw-r--r--src/libutil/str_util.h144
-rw-r--r--src/libutil/upstream.c182
-rw-r--r--src/libutil/upstream.h44
-rw-r--r--src/libutil/util.c304
-rw-r--r--src/libutil/util.h122
35 files changed, 1472 insertions, 1472 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index a7dafe43b..3cac4de87 100644
--- a/src/libutil/addr.c
+++ b/src/libutil/addr.c
@@ -55,7 +55,7 @@ union sa_inet {
struct rspamd_addr_unix {
struct sockaddr_un addr;
- gint mode;
+ int mode;
uid_t owner;
gid_t group;
};
@@ -69,7 +69,7 @@ struct rspamd_inet_addr_s {
struct rspamd_addr_inet in;
struct rspamd_addr_unix *un;
} u;
- gint af;
+ int af;
socklen_t slen;
};
@@ -109,7 +109,7 @@ rspamd_ip_validate_af(rspamd_inet_addr_t *addr)
(pool != NULL) ? rspamd_mempool_alloc0((pool), (sz)) : g_malloc0(sz)
static rspamd_inet_addr_t *
-rspamd_inet_addr_create(gint af, rspamd_mempool_t *pool)
+rspamd_inet_addr_create(int af, rspamd_mempool_t *pool)
{
rspamd_inet_addr_t *addr;
@@ -144,7 +144,7 @@ static void
rspamd_ip_check_ipv6(void)
{
if (ipv6_status == RSPAMD_IPV6_UNDEFINED) {
- gint s;
+ int s;
s = socket(AF_INET6, SOCK_STREAM, 0);
@@ -200,11 +200,11 @@ rspamd_ip_is_valid(const rspamd_inet_addr_t *addr)
return ret;
}
-gint rspamd_accept_from_socket(gint sock, rspamd_inet_addr_t **target,
- rspamd_accept_throttling_handler hdl,
- void *hdl_data)
+int rspamd_accept_from_socket(int sock, rspamd_inet_addr_t **target,
+ rspamd_accept_throttling_handler hdl,
+ void *hdl_data)
{
- gint nfd, serrno;
+ int nfd, serrno;
union sa_union su;
socklen_t len = sizeof(su);
rspamd_inet_addr_t *addr = NULL;
@@ -232,12 +232,12 @@ gint rspamd_accept_from_socket(gint sock, rspamd_inet_addr_t **target,
if (su.sa.sa_family == AF_INET6) {
/* Deal with bloody v4 mapped to v6 addresses */
- static const guint8 mask[] = {
+ static const uint8_t mask[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- const guint8 *p;
+ const uint8_t *p;
- if (memcmp((const guint8 *) &su.s6.sin6_addr, mask, sizeof(mask)) == 0) {
- p = (const guint8 *) &su.s6.sin6_addr;
+ if (memcmp((const uint8_t *) &su.s6.sin6_addr, mask, sizeof(mask)) == 0) {
+ p = (const uint8_t *) &su.s6.sin6_addr;
if ((p[10] == 0xff && p[11] == 0xff)) {
addr = rspamd_inet_addr_create(AF_INET, NULL);
@@ -313,7 +313,7 @@ rspamd_parse_unix_path(rspamd_inet_addr_t **target,
rspamd_mempool_t *pool,
enum rspamd_inet_address_parse_flags how)
{
- gchar **tokens, **cur_tok, *p, *pwbuf;
+ char **tokens, **cur_tok, *p, *pwbuf;
glong pwlen;
struct passwd pw, *ppw;
struct group gr, *pgr;
@@ -456,12 +456,12 @@ err:
}
gboolean
-rspamd_parse_inet_address_ip4(const guchar *text, gsize len, gpointer target)
+rspamd_parse_inet_address_ip4(const unsigned char *text, gsize len, gpointer target)
{
- const guchar *p;
- guchar c;
+ const unsigned char *p;
+ unsigned char c;
uint32_t addr = 0, *addrptr = target;
- guint octet = 0, n = 0;
+ unsigned int octet = 0, n = 0;
g_assert(text != NULL);
g_assert(target != NULL);
@@ -504,12 +504,12 @@ rspamd_parse_inet_address_ip4(const guchar *text, gsize len, gpointer target)
}
gboolean
-rspamd_parse_inet_address_ip6(const guchar *text, gsize len, gpointer target)
+rspamd_parse_inet_address_ip6(const unsigned char *text, gsize len, gpointer target)
{
- guchar t, *zero = NULL, *s, *d, *addr = target;
- const guchar *p, *digit = NULL, *percent;
+ unsigned char t, *zero = NULL, *s, *d, *addr = target;
+ const unsigned char *p, *digit = NULL, *percent;
gsize len4 = 0;
- guint n = 8, nibbles = 0, word = 0;
+ unsigned int n = 8, nibbles = 0, word = 0;
g_assert(text != NULL);
g_assert(target != NULL);
@@ -582,8 +582,8 @@ rspamd_parse_inet_address_ip6(const guchar *text, gsize len, gpointer target)
}
word = ntohl(word);
- *addr++ = (guchar) ((word >> 24) & 0xff);
- *addr++ = (guchar) ((word >> 16) & 0xff);
+ *addr++ = (unsigned char) ((word >> 24) & 0xff);
+ *addr++ = (unsigned char) ((word >> 16) & 0xff);
n--;
break;
}
@@ -613,8 +613,8 @@ rspamd_parse_inet_address_ip6(const guchar *text, gsize len, gpointer target)
return FALSE;
}
- *addr++ = (guchar) (word >> 8);
- *addr++ = (guchar) (word & 0xff);
+ *addr++ = (unsigned char) (word >> 8);
+ *addr++ = (unsigned char) (word & 0xff);
if (--n) {
if (zero) {
@@ -645,12 +645,12 @@ rspamd_inet_address_v6_maybe_map(const struct sockaddr_in6 *sin6,
{
rspamd_inet_addr_t *addr = NULL;
/* 10 zero bytes or 80 bits */
- static const guint8 mask[] = {
+ static const uint8_t mask[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- const guint8 *p;
+ const uint8_t *p;
- if (memcmp((const guint8 *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) {
- p = (const guint8 *) &sin6->sin6_addr;
+ if (memcmp((const uint8_t *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) {
+ p = (const uint8_t *) &sin6->sin6_addr;
if ((p[10] == 0xff && p[11] == 0xff)) {
addr = rspamd_inet_addr_create(AF_INET, pool);
@@ -678,12 +678,12 @@ rspamd_inet_address_v6_maybe_map_static(const struct sockaddr_in6 *sin6,
rspamd_inet_addr_t *addr)
{
/* 10 zero bytes or 80 bits */
- static const guint8 mask[] = {
+ static const uint8_t mask[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- const guint8 *p;
+ const uint8_t *p;
- if (memcmp((const guint8 *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) {
- p = (const guint8 *) &sin6->sin6_addr;
+ if (memcmp((const uint8_t *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) {
+ p = (const uint8_t *) &sin6->sin6_addr;
if ((p[10] == 0xff && p[11] == 0xff)) {
memcpy(&addr->u.in.addr.s4.sin_addr, &p[12],
@@ -719,7 +719,7 @@ rspamd_parse_inet_address_common(rspamd_inet_addr_t **target,
union sa_inet su;
const char *end = NULL;
char ipbuf[INET6_ADDRSTRLEN + 1];
- guint iplen;
+ unsigned int iplen;
gulong portnum;
if (srclen == 0) {
@@ -737,7 +737,7 @@ rspamd_parse_inet_address_common(rspamd_inet_addr_t **target,
}
if (src[0] == '[') {
- const gchar *ip_start;
+ const char *ip_start;
/* Ipv6 address in format [::1]:port or just [::1] */
end = memchr(src + 1, ']', srclen - 1);
@@ -851,7 +851,7 @@ rspamd_parse_inet_address_ip(const char *src, gsize srclen,
{
const char *end;
char ipbuf[INET6_ADDRSTRLEN + 1];
- guint iplen;
+ unsigned int iplen;
gulong portnum;
gboolean ret = FALSE;
union sa_inet su;
@@ -951,7 +951,7 @@ const char *
rspamd_inet_address_to_string(const rspamd_inet_addr_t *addr)
{
static char addr_str[NADDR_BUFS][INET6_ADDRSTRLEN + 1];
- static guint cur_addr = 0;
+ static unsigned int cur_addr = 0;
char *addr_buf;
if (addr == NULL) {
@@ -980,7 +980,7 @@ const char *
rspamd_inet_address_to_string_pretty(const rspamd_inet_addr_t *addr)
{
static char addr_str[NADDR_BUFS][PRETTY_IP_BUFSIZE];
- static guint cur_addr = 0;
+ static unsigned int cur_addr = 0;
char *addr_buf;
if (addr == NULL) {
@@ -1034,7 +1034,7 @@ void rspamd_inet_address_set_port(rspamd_inet_addr_t *addr, uint16_t port)
}
}
-int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, gint type,
+int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, int type,
gboolean async)
{
int fd, r;
@@ -1084,12 +1084,12 @@ int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, gint type,
return fd;
}
-int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type,
+int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, int type,
enum rspamd_inet_address_listen_opts opts,
- gint listen_queue)
+ int listen_queue)
{
- gint fd, r;
- gint on = 1, serrno;
+ int fd, r;
+ int on = 1, serrno;
const struct sockaddr *sa;
const char *path;
@@ -1116,7 +1116,7 @@ int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type,
}
#if defined(SO_REUSEADDR)
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(gint)) == -1) {
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(int)) == -1) {
msg_err("cannot set SO_REUSEADDR on %s (fd=%d): %s",
rspamd_inet_address_to_string_pretty(addr),
fd, strerror(errno));
@@ -1128,7 +1128,7 @@ int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type,
if (opts & RSPAMD_INET_ADDRESS_LISTEN_REUSEPORT) {
on = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (const void *) &on, sizeof(gint)) == -1) {
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (const void *) &on, sizeof(int)) == -1) {
msg_err("cannot set SO_REUSEPORT on %s (fd=%d): %s",
rspamd_inet_address_to_string_pretty(addr),
fd, strerror(errno));
@@ -1142,9 +1142,9 @@ int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type,
/* We need to set this flag to avoid errors */
on = 1;
#ifdef SOL_IPV6
- (void) setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(gint));
+ (void) setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(int));
#elif defined(IPPROTO_IPV6)
- (void) setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(gint));
+ (void) setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(int));
#endif
}
#endif
@@ -1210,7 +1210,7 @@ err:
}
gssize
-rspamd_inet_address_recvfrom(gint fd, void *buf, gsize len, gint fl,
+rspamd_inet_address_recvfrom(int fd, void *buf, gsize len, int fl,
rspamd_inet_addr_t **target)
{
gssize ret;
@@ -1245,7 +1245,7 @@ rspamd_inet_address_recvfrom(gint fd, void *buf, gsize len, gint fl,
}
gssize
-rspamd_inet_address_sendto(gint fd, const void *buf, gsize len, gint fl,
+rspamd_inet_address_sendto(int fd, const void *buf, gsize len, int fl,
const rspamd_inet_addr_t *addr)
{
gssize r;
@@ -1271,12 +1271,12 @@ rspamd_inet_address_sendto(gint fd, const void *buf, gsize len, gint fl,
}
static gboolean
-rspamd_check_port_priority(const char *line, guint default_port,
- guint *priority, gchar *out,
+rspamd_check_port_priority(const char *line, unsigned int default_port,
+ unsigned int *priority, char *out,
gsize outlen, rspamd_mempool_t *pool)
{
- guint real_port = default_port, real_priority = 0;
- gchar *err_str, *err_str_prio;
+ unsigned int real_port = default_port, real_priority = 0;
+ char *err_str, *err_str_prio;
if (line && line[0] == ':') {
errno = 0;
@@ -1318,13 +1318,13 @@ rspamd_check_port_priority(const char *line, guint default_port,
static enum rspamd_parse_host_port_result
rspamd_resolve_addrs(const char *begin, size_t len, GPtrArray **addrs,
- const gchar *portbuf, gint flags,
+ const char *portbuf, int flags,
rspamd_mempool_t *pool)
{
struct addrinfo hints, *res, *cur;
rspamd_inet_addr_t *cur_addr = NULL;
- gint r, addr_cnt;
- gchar *addr_cpy = NULL;
+ int r, addr_cnt;
+ char *addr_cpy = NULL;
enum rspamd_parse_host_port_result ret = RSPAMD_PARSE_ADDR_FAIL;
rspamd_ip_check_ipv6();
@@ -1428,16 +1428,16 @@ rspamd_resolve_addrs(const char *begin, size_t len, GPtrArray **addrs,
}
enum rspamd_parse_host_port_result
-rspamd_parse_host_port_priority(const gchar *str,
+rspamd_parse_host_port_priority(const char *str,
GPtrArray **addrs,
- guint *priority,
- gchar **name_ptr,
- guint default_port,
+ unsigned int *priority,
+ char **name_ptr,
+ unsigned int default_port,
gboolean allow_listen,
rspamd_mempool_t *pool)
{
- gchar portbuf[8];
- const gchar *p, *name = NULL;
+ char portbuf[8];
+ const char *p, *name = NULL;
gsize namelen;
rspamd_inet_addr_t *cur_addr = NULL;
enum rspamd_parse_host_port_result ret = RSPAMD_PARSE_ADDR_FAIL;
@@ -1571,7 +1571,7 @@ rspamd_parse_host_port_priority(const gchar *str,
portbuf, 0, pool);
}
else {
- const gchar *second_semicolon = strchr(p + 1, ':');
+ const char *second_semicolon = strchr(p + 1, ':');
name = str;
@@ -1608,10 +1608,10 @@ rspamd_parse_host_port_priority(const gchar *str,
return ret;
}
-guchar *
-rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, guint *klen)
+unsigned char *
+rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, unsigned int *klen)
{
- guchar *res = NULL;
+ unsigned char *res = NULL;
static struct in_addr local = {INADDR_LOOPBACK};
g_assert(addr != NULL);
@@ -1619,15 +1619,15 @@ rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, guint *klen)
if (addr->af == AF_INET) {
*klen = sizeof(struct in_addr);
- res = (guchar *) &addr->u.in.addr.s4.sin_addr;
+ res = (unsigned char *) &addr->u.in.addr.s4.sin_addr;
}
else if (addr->af == AF_INET6) {
*klen = sizeof(struct in6_addr);
- res = (guchar *) &addr->u.in.addr.s6.sin6_addr;
+ res = (unsigned char *) &addr->u.in.addr.s6.sin6_addr;
}
else if (addr->af == AF_UNIX) {
*klen = sizeof(struct in_addr);
- res = (guchar *) &local;
+ res = (unsigned char *) &local;
}
else {
*klen = 0;
@@ -1726,7 +1726,7 @@ rspamd_inet_address_from_rnds(const struct rdns_reply_entry *rep)
return addr;
}
-void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask)
+void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, unsigned int mask)
{
uint32_t umsk, *p;
@@ -1757,7 +1757,7 @@ void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask)
}
}
-static gint
+static int
rspamd_inet_address_af_order(const rspamd_inet_addr_t *addr)
{
int ret;
@@ -1777,8 +1777,8 @@ rspamd_inet_address_af_order(const rspamd_inet_addr_t *addr)
return ret;
}
-gint rspamd_inet_address_compare(const rspamd_inet_addr_t *a1,
- const rspamd_inet_addr_t *a2, gboolean compare_ports)
+int rspamd_inet_address_compare(const rspamd_inet_addr_t *a1,
+ const rspamd_inet_addr_t *a2, gboolean compare_ports)
{
g_assert(a1 != NULL);
g_assert(a2 != NULL);
@@ -1828,8 +1828,8 @@ gint rspamd_inet_address_compare(const rspamd_inet_addr_t *a1,
return 0;
}
-gint rspamd_inet_address_compare_ptr(gconstpointer a1,
- gconstpointer a2)
+int rspamd_inet_address_compare_ptr(gconstpointer a1,
+ gconstpointer a2)
{
const rspamd_inet_addr_t **i1 = (const rspamd_inet_addr_t **) a1,
**i2 = (const rspamd_inet_addr_t **) a2;
@@ -1858,7 +1858,7 @@ rspamd_inet_address_copy(const rspamd_inet_addr_t *addr, rspamd_mempool_t *pool)
return n;
}
-gint rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr)
+int rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr)
{
g_assert(addr != NULL);
@@ -1882,11 +1882,11 @@ rspamd_inet_address_get_sa(const rspamd_inet_addr_t *addr,
}
-guint rspamd_inet_address_hash(gconstpointer a)
+unsigned int rspamd_inet_address_hash(gconstpointer a)
{
const rspamd_inet_addr_t *addr = a;
struct {
- gchar buf[sizeof(struct in6_addr)]; /* 16 bytes */
+ char buf[sizeof(struct in6_addr)]; /* 16 bytes */
int af;
} layout;
@@ -1922,11 +1922,11 @@ guint rspamd_inet_address_hash(gconstpointer a)
return k;
}
-guint rspamd_inet_address_port_hash(gconstpointer a)
+unsigned int rspamd_inet_address_port_hash(gconstpointer a)
{
const rspamd_inet_addr_t *addr = a;
struct {
- gchar buf[sizeof(struct in6_addr)]; /* 16 bytes */
+ char buf[sizeof(struct in6_addr)]; /* 16 bytes */
int port;
int af;
} layout;
diff --git a/src/libutil/addr.h b/src/libutil/addr.h
index 25a364125..9feb7f05f 100644
--- a/src/libutil/addr.h
+++ b/src/libutil/addr.h
@@ -92,7 +92,7 @@ rspamd_inet_addr_t *rspamd_inet_address_from_rnds(
* @param target target structure
* @return TRUE if the address has been parsed, otherwise `target` content is undefined
*/
-gboolean rspamd_parse_inet_address_ip6(const guchar *text, gsize len,
+gboolean rspamd_parse_inet_address_ip6(const unsigned char *text, gsize len,
gpointer target);
enum rspamd_inet_address_parse_flags {
@@ -110,7 +110,7 @@ enum rspamd_inet_address_parse_flags {
* @param target target structure
* @return TRUE if the address has been parsed, otherwise `target` content is undefined
*/
-gboolean rspamd_parse_inet_address_ip4(const guchar *text, gsize len,
+gboolean rspamd_parse_inet_address_ip4(const unsigned char *text, gsize len,
gpointer target);
/**
@@ -173,7 +173,7 @@ uint16_t rspamd_inet_address_get_port(const rspamd_inet_addr_t *addr);
* @param addr
* @return
*/
-gint rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr);
+int rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr);
/**
* Returns sockaddr and size for this address
@@ -190,7 +190,7 @@ struct sockaddr *rspamd_inet_address_get_sa(const rspamd_inet_addr_t *addr,
* @param klen
* @return
*/
-guchar *rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, guint *klen);
+unsigned char *rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, unsigned int *klen);
/**
* Receive data from an unconnected socket and fill the inet_addr structure if needed
@@ -200,7 +200,7 @@ guchar *rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, guint *
* @param target
* @return same as recvfrom(2)
*/
-gssize rspamd_inet_address_recvfrom(gint fd, void *buf, gsize len, gint fl,
+gssize rspamd_inet_address_recvfrom(int fd, void *buf, gsize len, int fl,
rspamd_inet_addr_t **target);
/**
@@ -211,7 +211,7 @@ gssize rspamd_inet_address_recvfrom(gint fd, void *buf, gsize len, gint fl,
* @param target
* @return
*/
-gssize rspamd_inet_address_sendto(gint fd, const void *buf, gsize len, gint fl,
+gssize rspamd_inet_address_sendto(int fd, const void *buf, gsize len, int fl,
const rspamd_inet_addr_t *addr);
/**
@@ -225,7 +225,7 @@ void rspamd_inet_address_set_port(rspamd_inet_addr_t *addr, uint16_t port);
* @param async perform operations asynchronously
* @return newly created and connected socket
*/
-int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, gint type,
+int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, int type,
gboolean async);
enum rspamd_inet_address_listen_opts {
@@ -241,9 +241,9 @@ enum rspamd_inet_address_listen_opts {
* @param opts
* @return
*/
-int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type,
+int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, int type,
enum rspamd_inet_address_listen_opts opts,
- gint listen_queue);
+ int listen_queue);
/**
* Check whether specified ip is valid (not INADDR_ANY or INADDR_NONE) for ipv4 or ipv6
@@ -253,7 +253,7 @@ int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type,
*/
gboolean rspamd_ip_is_valid(const rspamd_inet_addr_t *addr);
-typedef void (*rspamd_accept_throttling_handler)(gint, void *);
+typedef void (*rspamd_accept_throttling_handler)(int, void *);
/**
* Accept from listening socket filling addr structure
@@ -261,10 +261,10 @@ typedef void (*rspamd_accept_throttling_handler)(gint, void *);
* @param target allocated inet addr structure
* @return
*/
-gint rspamd_accept_from_socket(gint sock,
- rspamd_inet_addr_t **target,
- rspamd_accept_throttling_handler hdl,
- void *hdl_data);
+int rspamd_accept_from_socket(int sock,
+ rspamd_inet_addr_t **target,
+ rspamd_accept_throttling_handler hdl,
+ void *hdl_data);
enum rspamd_parse_host_port_result {
RSPAMD_PARSE_ADDR_FAIL = 0,
@@ -279,10 +279,10 @@ enum rspamd_parse_host_port_result {
* @return RSPAMD_PARSE_ADDR_FAIL in case of error, RSPAMD_PARSE_ADDR_NUMERIC in case of pure ip/unix socket
*/
enum rspamd_parse_host_port_result
-rspamd_parse_host_port_priority(const gchar *str,
+rspamd_parse_host_port_priority(const char *str,
GPtrArray **addrs,
- guint *priority, gchar **name,
- guint default_port,
+ unsigned int *priority, char **name,
+ unsigned int default_port,
gboolean allow_listen,
rspamd_mempool_t *pool);
@@ -297,7 +297,7 @@ void rspamd_inet_address_free(rspamd_inet_addr_t *addr);
* @param addr
* @param mask
*/
-void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask);
+void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, unsigned int mask);
/**
* Compare a1 and a2 and return value >0, ==0 and <0 if a1 is more, equal or less than a2 correspondingly
@@ -305,8 +305,8 @@ void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask);
* @param a2
* @return
*/
-gint rspamd_inet_address_compare(const rspamd_inet_addr_t *a1,
- const rspamd_inet_addr_t *a2, gboolean compare_ports);
+int rspamd_inet_address_compare(const rspamd_inet_addr_t *a1,
+ const rspamd_inet_addr_t *a2, gboolean compare_ports);
/**
* Utility function to compare addresses by in g_ptr_array
@@ -314,8 +314,8 @@ gint rspamd_inet_address_compare(const rspamd_inet_addr_t *a1,
* @param a2
* @return
*/
-gint rspamd_inet_address_compare_ptr(gconstpointer a1,
- gconstpointer a2);
+int rspamd_inet_address_compare_ptr(gconstpointer a1,
+ gconstpointer a2);
/**
* Performs deep copy of rspamd inet addr
@@ -327,9 +327,9 @@ rspamd_inet_addr_t *rspamd_inet_address_copy(const rspamd_inet_addr_t *addr, rsp
/**
* Returns hash for inet address (ignoring port)
*/
-guint rspamd_inet_address_hash(gconstpointer a);
+unsigned int rspamd_inet_address_hash(gconstpointer a);
-guint rspamd_inet_address_port_hash(gconstpointer a);
+unsigned int rspamd_inet_address_port_hash(gconstpointer a);
/**
* Returns true if two address are equal
diff --git a/src/libutil/cxx/utf8_util.cxx b/src/libutil/cxx/utf8_util.cxx
index 5fc83ca85..05a7f9d7b 100644
--- a/src/libutil/cxx/utf8_util.cxx
+++ b/src/libutil/cxx/utf8_util.cxx
@@ -161,8 +161,8 @@ rspamd_normalise_unicode_inplace(char *start, size_t *len)
return static_cast<enum rspamd_utf8_normalise_result>(ret);
}
-gchar *
-rspamd_utf8_transliterate(const gchar *start, gsize len, gsize *target_len)
+char *
+rspamd_utf8_transliterate(const char *start, gsize len, gsize *target_len)
{
UErrorCode uc_err = U_ZERO_ERROR;
@@ -195,7 +195,7 @@ rspamd_utf8_transliterate(const gchar *start, gsize len, gsize *target_len)
// We assume that all characters are now ascii
auto dest_len = uc_string.length();
- gchar *dest = (gchar *) g_malloc(dest_len + 1);
+ char *dest = (char *) g_malloc(dest_len + 1);
auto sink = icu::CheckedArrayByteSink(dest, dest_len);
uc_string.toUTF8(sink);
diff --git a/src/libutil/cxx/utf8_util.h b/src/libutil/cxx/utf8_util.h
index 044beae36..fcb0d2f70 100644
--- a/src/libutil/cxx/utf8_util.h
+++ b/src/libutil/cxx/utf8_util.h
@@ -49,7 +49,7 @@ enum rspamd_utf8_normalise_result {
* @param len
* @return TRUE if a string has been normalised
*/
-enum rspamd_utf8_normalise_result rspamd_normalise_unicode_inplace(gchar *start, gsize *len);
+enum rspamd_utf8_normalise_result rspamd_normalise_unicode_inplace(char *start, gsize *len);
/**
* Transliterate a string to ASCII
@@ -58,7 +58,7 @@ enum rspamd_utf8_normalise_result rspamd_normalise_unicode_inplace(gchar *start,
* @param target_len
* @return a new string that should be freed with g_free
*/
-gchar *rspamd_utf8_transliterate(const gchar *start, gsize len, gsize *target_len);
+char *rspamd_utf8_transliterate(const char *start, gsize len, gsize *target_len);
/**
* Compare two strings using libicu collator
diff --git a/src/libutil/expression.c b/src/libutil/expression.c
index 51eac6885..e36964e72 100644
--- a/src/libutil/expression.c
+++ b/src/libutil/expression.c
@@ -47,8 +47,8 @@ enum rspamd_expression_op_flag {
struct rspamd_expression_operation {
enum rspamd_expression_op op;
- guint logical_priority;
- guint op_flags;
+ unsigned int logical_priority;
+ unsigned int op_flags;
};
struct rspamd_expression_elt {
@@ -56,12 +56,12 @@ struct rspamd_expression_elt {
union {
rspamd_expression_atom_t *atom;
struct rspamd_expression_operation op;
- gdouble lim;
+ double lim;
} p;
- gint flags;
- gint priority;
- gdouble value;
+ int flags;
+ int priority;
+ double value;
};
struct rspamd_expression {
@@ -69,14 +69,14 @@ struct rspamd_expression {
GArray *expressions;
GPtrArray *expression_stack;
GNode *ast;
- gchar *log_id;
- guint next_resort;
- guint evals;
+ char *log_id;
+ unsigned int next_resort;
+ unsigned int evals;
};
struct rspamd_expr_process_data {
gpointer *ud;
- gint flags;
+ int flags;
/* != NULL if trace is collected */
GPtrArray *trace;
rspamd_expression_process_cb process_closure;
@@ -106,12 +106,12 @@ rspamd_expr_quark(void)
return g_quark_from_static_string("rspamd-expression");
}
-static const gchar *RSPAMD_CONST_FUNCTION
+static const char *RSPAMD_CONST_FUNCTION
rspamd_expr_op_to_str(enum rspamd_expression_op op);
-static const gchar *
+static const char *
rspamd_expr_op_to_str(enum rspamd_expression_op op)
{
- const gchar *op_str = NULL;
+ const char *op_str = NULL;
switch (op) {
case OP_AND:
@@ -181,7 +181,7 @@ static gpointer
rspamd_expr_stack_elt_pop(GPtrArray *stack)
{
gpointer e;
- gint idx;
+ int idx;
if (stack->len == 0) {
return NULL;
@@ -212,7 +212,7 @@ static gpointer
rspamd_expr_stack_peek(struct rspamd_expression *expr)
{
gpointer e;
- gint idx;
+ int idx;
GPtrArray *stack = expr->expression_stack;
if (stack->len == 0) {
@@ -228,12 +228,12 @@ rspamd_expr_stack_peek(struct rspamd_expression *expr)
/*
* Return operation priority
*/
-static gint RSPAMD_CONST_FUNCTION
+static int RSPAMD_CONST_FUNCTION
rspamd_expr_logic_priority(enum rspamd_expression_op op);
-static gint
+static int
rspamd_expr_logic_priority(enum rspamd_expression_op op)
{
- gint ret = 0;
+ int ret = 0;
switch (op) {
case OP_NOT:
@@ -273,13 +273,13 @@ rspamd_expr_logic_priority(enum rspamd_expression_op op)
return ret;
}
-static guint RSPAMD_CONST_FUNCTION
+static unsigned int RSPAMD_CONST_FUNCTION
rspamd_expr_op_flags(enum rspamd_expression_op op);
-static guint
+static unsigned int
rspamd_expr_op_flags(enum rspamd_expression_op op)
{
- guint ret = 0;
+ unsigned int ret = 0;
switch (op) {
case OP_NOT:
@@ -323,9 +323,9 @@ rspamd_expr_op_flags(enum rspamd_expression_op op)
* Return TRUE if symbol is operation symbol
*/
static gboolean RSPAMD_CONST_FUNCTION
-rspamd_expr_is_operation_symbol(gchar a);
+rspamd_expr_is_operation_symbol(char a);
static gboolean
-rspamd_expr_is_operation_symbol(gchar a)
+rspamd_expr_is_operation_symbol(char a)
{
switch (a) {
case '!':
@@ -348,18 +348,18 @@ rspamd_expr_is_operation_symbol(gchar a)
static gboolean
rspamd_expr_is_operation(struct rspamd_expression *e,
- const gchar *p, const gchar *end, rspamd_regexp_t *num_re)
+ const char *p, const char *end, rspamd_regexp_t *num_re)
{
if (rspamd_expr_is_operation_symbol(*p)) {
if (p + 1 < end) {
- gchar t = *(p + 1);
+ char t = *(p + 1);
if (t == ':') {
/* Special case, treat it as an atom */
}
else if (*p == '/') {
/* Lookahead for division operation to distinguish from regexp */
- const gchar *track = p + 1;
+ const char *track = p + 1;
/* Skip spaces */
while (track < end && g_ascii_isspace(*track)) {
@@ -409,7 +409,7 @@ rspamd_expr_is_operation(struct rspamd_expression *e,
/* Return character representation of operation */
static enum rspamd_expression_op
-rspamd_expr_str_to_op(const gchar *a, const gchar *end, const gchar **next)
+rspamd_expr_str_to_op(const char *a, const char *end, const char **next)
{
enum rspamd_expression_op op = OP_INVALID;
@@ -538,7 +538,7 @@ rspamd_expr_str_to_op(const gchar *a, const gchar *end, const gchar **next)
static void
rspamd_expression_destroy(struct rspamd_expression *expr)
{
- guint i;
+ unsigned int i;
struct rspamd_expression_elt *elt;
if (expr != NULL) {
@@ -714,7 +714,7 @@ rspamd_ast_priority_traverse(GNode *node, gpointer d)
{
struct rspamd_expression_elt *elt = node->data, *cur_elt;
struct rspamd_expression *expr = d;
- gint cnt = 0;
+ int cnt = 0;
GNode *cur;
if (node->children) {
@@ -750,11 +750,11 @@ rspamd_ast_priority_traverse(GNode *node, gpointer d)
#define ATOM_PRIORITY(a) ((a)->p.atom->hits / ((a)->p.atom->exec_time.mean > 0 ? (a)->p.atom->exec_time.mean * 10000000 : 1.0))
-static gint
+static int
rspamd_ast_priority_cmp(GNode *a, GNode *b)
{
struct rspamd_expression_elt *ea = a->data, *eb = b->data;
- gdouble w1, w2;
+ double w1, w2;
if (ea->type == ELT_LIMIT) {
return 1;
@@ -819,7 +819,7 @@ rspamd_expr_dup_elt(rspamd_mempool_t *pool, struct rspamd_expression_elt *elt)
}
gboolean
-rspamd_parse_expression(const gchar *line, gsize len,
+rspamd_parse_expression(const char *line, gsize len,
const struct rspamd_atom_subr *subr, gpointer subr_data,
rspamd_mempool_t *pool, GError **err,
struct rspamd_expression **target)
@@ -829,7 +829,7 @@ rspamd_parse_expression(const gchar *line, gsize len,
rspamd_expression_atom_t *atom;
rspamd_regexp_t *num_re;
enum rspamd_expression_op op, op_stack;
- const gchar *p, *c, *end;
+ const char *p, *c, *end;
GPtrArray *operand_stack;
GNode *tmp;
@@ -1020,7 +1020,7 @@ rspamd_parse_expression(const gchar *line, gsize len,
goto error_label;
}
- guint op_priority = rspamd_expr_logic_priority(op);
+ unsigned int op_priority = rspamd_expr_logic_priority(op);
msg_debug_expression("found op: %s; priority = %d",
rspamd_expr_op_to_str(op), op_priority);
@@ -1064,8 +1064,8 @@ rspamd_parse_expression(const gchar *line, gsize len,
}
/* We ignore associativity for now */
- guint op_priority = rspamd_expr_logic_priority(op),
- stack_op_priority = rspamd_expr_logic_priority(op_stack);
+ unsigned int op_priority = rspamd_expr_logic_priority(op),
+ stack_op_priority = rspamd_expr_logic_priority(op_stack);
msg_debug_expression("operators stack %d; operands stack: %d; "
"process operation '%s'(%d); pop operation '%s'(%d)",
@@ -1201,7 +1201,7 @@ error_label:
* Node optimizer function: skip nodes that are not relevant
*/
static gboolean
-rspamd_ast_node_done(struct rspamd_expression_elt *elt, gdouble acc)
+rspamd_ast_node_done(struct rspamd_expression_elt *elt, double acc)
{
gboolean ret = FALSE;
@@ -1225,10 +1225,10 @@ rspamd_ast_node_done(struct rspamd_expression_elt *elt, gdouble acc)
}
-static gdouble
-rspamd_ast_do_unary_op(struct rspamd_expression_elt *elt, gdouble operand)
+static double
+rspamd_ast_do_unary_op(struct rspamd_expression_elt *elt, double operand)
{
- gdouble ret;
+ double ret;
g_assert(elt->type == ELT_OP);
switch (elt->p.op.op) {
@@ -1242,10 +1242,10 @@ rspamd_ast_do_unary_op(struct rspamd_expression_elt *elt, gdouble operand)
return ret;
}
-static gdouble
-rspamd_ast_do_binary_op(struct rspamd_expression_elt *elt, gdouble op1, gdouble op2)
+static double
+rspamd_ast_do_binary_op(struct rspamd_expression_elt *elt, double op1, double op2)
{
- gdouble ret;
+ double ret;
g_assert(elt->type == ELT_OP);
@@ -1288,10 +1288,10 @@ rspamd_ast_do_binary_op(struct rspamd_expression_elt *elt, gdouble op1, gdouble
return ret;
}
-static gdouble
-rspamd_ast_do_nary_op(struct rspamd_expression_elt *elt, gdouble val, gdouble acc)
+static double
+rspamd_ast_do_nary_op(struct rspamd_expression_elt *elt, double val, double acc)
{
- gdouble ret;
+ double ret;
g_assert(elt->type == ELT_OP);
@@ -1329,17 +1329,17 @@ rspamd_ast_do_nary_op(struct rspamd_expression_elt *elt, gdouble val, gdouble ac
return ret;
}
-static gdouble
+static double
rspamd_ast_process_node(struct rspamd_expression *e, GNode *node,
struct rspamd_expr_process_data *process_data)
{
struct rspamd_expression_elt *elt;
GNode *cld;
- gdouble acc = NAN;
+ double acc = NAN;
float t1, t2;
- gdouble val;
+ double val;
gboolean calc_ticks = FALSE;
- __attribute__((unused)) const gchar *op_name = NULL;
+ __attribute__((unused)) const char *op_name = NULL;
elt = node->data;
@@ -1412,7 +1412,7 @@ rspamd_ast_process_node(struct rspamd_expression *e, GNode *node,
c2 = c1->next;
g_assert(c2->next == NULL);
- gdouble val1, val2;
+ double val1, val2;
msg_debug_expression_verbose("proceed binary operation %s",
op_name);
@@ -1457,15 +1457,15 @@ rspamd_ast_cleanup_traverse(GNode *n, gpointer d)
return FALSE;
}
-gdouble
+double
rspamd_process_expression_closure(struct rspamd_expression *expr,
rspamd_expression_process_cb cb,
- gint flags,
+ int flags,
gpointer runtime_ud,
GPtrArray **track)
{
struct rspamd_expr_process_data pd;
- gdouble ret = 0;
+ double ret = 0;
g_assert(expr != NULL);
/* Ensure that stack is empty at this point */
@@ -1505,9 +1505,9 @@ rspamd_process_expression_closure(struct rspamd_expression *expr,
return ret;
}
-gdouble
+double
rspamd_process_expression_track(struct rspamd_expression *expr,
- gint flags,
+ int flags,
gpointer runtime_ud,
GPtrArray **track)
{
@@ -1515,9 +1515,9 @@ rspamd_process_expression_track(struct rspamd_expression *expr,
expr->subr->process, flags, runtime_ud, track);
}
-gdouble
+double
rspamd_process_expression(struct rspamd_expression *expr,
- gint flags,
+ int flags,
gpointer runtime_ud)
{
return rspamd_process_expression_closure(expr,
@@ -1528,7 +1528,7 @@ static gboolean
rspamd_ast_string_traverse(GNode *n, gpointer d)
{
GString *res = d;
- gint cnt;
+ int cnt;
GNode *cur;
struct rspamd_expression_elt *elt = n->data;
const char *op_str = NULL;
diff --git a/src/libutil/expression.h b/src/libutil/expression.h
index ea4e102bb..44a793e46 100644
--- a/src/libutil/expression.h
+++ b/src/libutil/expression.h
@@ -54,28 +54,28 @@ typedef struct rspamd_expression_atom_s {
/* Opaque userdata */
gpointer data;
/* String representation of atom */
- const gchar *str;
+ const char *str;
/* Length of the string representation of atom */
- guint len;
+ unsigned int len;
/* Relative priority */
- gint priority;
- guint hits;
+ int priority;
+ unsigned int hits;
struct rspamd_counter_data exec_time;
} rspamd_expression_atom_t;
-typedef gdouble (*rspamd_expression_process_cb)(gpointer runtime_data,
- rspamd_expression_atom_t *atom);
+typedef double (*rspamd_expression_process_cb)(gpointer runtime_data,
+ rspamd_expression_atom_t *atom);
struct rspamd_atom_subr {
/* Parses atom from string and returns atom structure */
- rspamd_expression_atom_t *(*parse)(const gchar *line, gsize len,
+ rspamd_expression_atom_t *(*parse)(const char *line, gsize len,
rspamd_mempool_t *pool, gpointer ud, GError **err);
/* Process atom via the opaque pointer (e.g. struct rspamd_task *) */
rspamd_expression_process_cb process;
/* Calculates the relative priority of the expression */
- gint (*priority)(rspamd_expression_atom_t *atom);
+ int (*priority)(rspamd_expression_atom_t *atom);
void (*destroy)(rspamd_expression_atom_t *atom);
};
@@ -94,7 +94,7 @@ struct rspamd_expression;
* @param target the target expression
* @return TRUE if an expression have been parsed
*/
-gboolean rspamd_parse_expression(const gchar *line, gsize len,
+gboolean rspamd_parse_expression(const char *line, gsize len,
const struct rspamd_atom_subr *subr, gpointer subr_data,
rspamd_mempool_t *pool, GError **err,
struct rspamd_expression **target);
@@ -105,9 +105,9 @@ gboolean rspamd_parse_expression(const gchar *line, gsize len,
* @param data opaque data pointer for all the atoms
* @return the value of expression
*/
-gdouble rspamd_process_expression(struct rspamd_expression *expr,
- gint flags,
- gpointer runtime_ud);
+double rspamd_process_expression(struct rspamd_expression *expr,
+ int flags,
+ gpointer runtime_ud);
/**
* Process the expression and return its value using atom 'process' functions with the specified data pointer.
@@ -117,10 +117,10 @@ gdouble rspamd_process_expression(struct rspamd_expression *expr,
* @param track pointer array to atoms tracking
* @return the value of expression
*/
-gdouble rspamd_process_expression_track(struct rspamd_expression *expr,
- gint flags,
- gpointer runtime_ud,
- GPtrArray **track);
+double rspamd_process_expression_track(struct rspamd_expression *expr,
+ int flags,
+ gpointer runtime_ud,
+ GPtrArray **track);
/**
* Process the expression with the custom processor
@@ -129,11 +129,11 @@ gdouble rspamd_process_expression_track(struct rspamd_expression *expr,
* @param process_data
* @return
*/
-gdouble rspamd_process_expression_closure(struct rspamd_expression *expr,
- rspamd_expression_process_cb cb,
- gint flags,
- gpointer runtime_ud,
- GPtrArray **track);
+double rspamd_process_expression_closure(struct rspamd_expression *expr,
+ rspamd_expression_process_cb cb,
+ int flags,
+ gpointer runtime_ud,
+ GPtrArray **track);
/**
* Shows string representation of an expression
diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c
index f092b307f..ffe130477 100644
--- a/src/libutil/fstring.c
+++ b/src/libutil/fstring.c
@@ -72,7 +72,7 @@ rspamd_fstring_sized_new(gsize initial_size)
}
rspamd_fstring_t *
-rspamd_fstring_new_init(const gchar *init, gsize len)
+rspamd_fstring_new_init(const char *init, gsize len)
{
rspamd_fstring_t *s;
gsize real_size = MAX(default_initial_size, len);
@@ -92,7 +92,7 @@ rspamd_fstring_new_init(const gchar *init, gsize len)
}
rspamd_fstring_t *
-rspamd_fstring_assign(rspamd_fstring_t *str, const gchar *init, gsize len)
+rspamd_fstring_assign(rspamd_fstring_t *str, const char *init, gsize len)
{
gsize avail;
@@ -244,7 +244,7 @@ rspamd_fstrhash_lc(const rspamd_ftok_t *str, gboolean is_utf)
{
gsize i;
uint64_t hval;
- const gchar *p, *end = NULL;
+ const char *p, *end = NULL;
gunichar uc;
if (str == NULL) {
@@ -301,10 +301,10 @@ rspamd_fstring_equal(const rspamd_fstring_t *s1,
return FALSE;
}
-gint rspamd_fstring_casecmp(const rspamd_fstring_t *s1,
- const rspamd_fstring_t *s2)
+int rspamd_fstring_casecmp(const rspamd_fstring_t *s1,
+ const rspamd_fstring_t *s2)
{
- gint ret = 0;
+ int ret = 0;
g_assert(s1 != NULL && s2 != NULL);
@@ -318,8 +318,8 @@ gint rspamd_fstring_casecmp(const rspamd_fstring_t *s1,
return ret;
}
-gint rspamd_fstring_cmp(const rspamd_fstring_t *s1,
- const rspamd_fstring_t *s2)
+int rspamd_fstring_cmp(const rspamd_fstring_t *s1,
+ const rspamd_fstring_t *s2)
{
g_assert(s1 != NULL && s2 != NULL);
@@ -330,10 +330,10 @@ gint rspamd_fstring_cmp(const rspamd_fstring_t *s1,
return s1->len - s2->len;
}
-gint rspamd_ftok_casecmp(const rspamd_ftok_t *s1,
- const rspamd_ftok_t *s2)
+int rspamd_ftok_casecmp(const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2)
{
- gint ret = 0;
+ int ret = 0;
g_assert(s1 != NULL && s2 != NULL);
@@ -347,8 +347,8 @@ gint rspamd_ftok_casecmp(const rspamd_ftok_t *s1,
return ret;
}
-gint rspamd_ftok_cmp(const rspamd_ftok_t *s1,
- const rspamd_ftok_t *s2)
+int rspamd_ftok_cmp(const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2)
{
g_assert(s1 != NULL && s2 != NULL);
@@ -429,7 +429,7 @@ rspamd_ftok_cstr(const rspamd_ftok_t *s)
}
gboolean
-rspamd_ftok_cstr_equal(const rspamd_ftok_t *s, const gchar *pat,
+rspamd_ftok_cstr_equal(const rspamd_ftok_t *s, const char *pat,
gboolean icase)
{
gsize slen;
@@ -449,10 +449,10 @@ rspamd_ftok_cstr_equal(const rspamd_ftok_t *s, const gchar *pat,
return (rspamd_ftok_cmp(s, &srch) == 0);
}
-gchar *
+char *
rspamd_ftokdup(const rspamd_ftok_t *src)
{
- gchar *newstr;
+ char *newstr;
if (src == NULL) {
return NULL;
@@ -465,10 +465,10 @@ rspamd_ftokdup(const rspamd_ftok_t *src)
return newstr;
}
-gchar *
+char *
rspamd_fstringdup(const rspamd_fstring_t *src)
{
- gchar *newstr;
+ char *newstr;
if (src == NULL) {
return NULL;
diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h
index 30a32a389..0792ab9fa 100644
--- a/src/libutil/fstring.h
+++ b/src/libutil/fstring.h
@@ -32,7 +32,7 @@ extern "C" {
typedef struct f_str_s {
gsize len;
gsize allocated;
- gchar str[];
+ char str[];
} rspamd_fstring_t;
#define RSPAMD_FSTRING_DATA(s) ((s)->str)
@@ -41,7 +41,7 @@ typedef struct f_str_s {
typedef struct f_str_tok {
gsize len;
- const gchar *begin;
+ const char *begin;
} rspamd_ftok_t;
typedef struct f_str_unicode_tok {
@@ -64,14 +64,14 @@ rspamd_fstring_t *rspamd_fstring_sized_new(gsize initial_size)
/**
* Create new fixed length string and initialize it with the initial data
*/
-rspamd_fstring_t *rspamd_fstring_new_init(const gchar *init, gsize len)
+rspamd_fstring_t *rspamd_fstring_new_init(const char *init, gsize len)
G_GNUC_WARN_UNUSED_RESULT;
/**
* Assign new value to fixed string
*/
rspamd_fstring_t *rspamd_fstring_assign(rspamd_fstring_t *str,
- const gchar *init, gsize len) G_GNUC_WARN_UNUSED_RESULT;
+ const char *init, gsize len) G_GNUC_WARN_UNUSED_RESULT;
/**
* Free fixed length string
@@ -125,26 +125,26 @@ gboolean rspamd_fstring_equal(const rspamd_fstring_t *s1,
/**
* Compare two fixed strings ignoring case
*/
-gint rspamd_fstring_casecmp(const rspamd_fstring_t *s1,
- const rspamd_fstring_t *s2);
+int rspamd_fstring_casecmp(const rspamd_fstring_t *s1,
+ const rspamd_fstring_t *s2);
/**
* Compare two fixed strings
*/
-gint rspamd_fstring_cmp(const rspamd_fstring_t *s1,
- const rspamd_fstring_t *s2);
+int rspamd_fstring_cmp(const rspamd_fstring_t *s1,
+ const rspamd_fstring_t *s2);
/**
* Compare two fixed tokens ignoring case
*/
-gint rspamd_ftok_casecmp(const rspamd_ftok_t *s1,
- const rspamd_ftok_t *s2);
+int rspamd_ftok_casecmp(const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2);
/**
* Compare two fixed tokens
*/
-gint rspamd_ftok_cmp(const rspamd_ftok_t *s1,
- const rspamd_ftok_t *s2);
+int rspamd_ftok_cmp(const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2);
/**
* Returns true if `s1` starts with `s2`
@@ -159,7 +159,7 @@ gboolean rspamd_ftok_starts_with(const rspamd_ftok_t *s1,
* Return TRUE if ftok is equal to specified C string
*/
gboolean rspamd_ftok_cstr_equal(const rspamd_ftok_t *s,
- const gchar *pat, gboolean icase);
+ const char *pat, gboolean icase);
/**
* Free fstring_t that is mapped to ftok_t
@@ -199,14 +199,14 @@ rspamd_fstring_t *rspamd_fstring_grow(rspamd_fstring_t *str,
* @param src
* @return
*/
-gchar *rspamd_ftokdup(const rspamd_ftok_t *src) G_GNUC_WARN_UNUSED_RESULT;
+char *rspamd_ftokdup(const rspamd_ftok_t *src) G_GNUC_WARN_UNUSED_RESULT;
/**
* Copies fstring to zero terminated string (must be freed using g_free)
* @param src
* @return
*/
-gchar *rspamd_fstringdup(const rspamd_fstring_t *src) G_GNUC_WARN_UNUSED_RESULT;
+char *rspamd_fstringdup(const rspamd_fstring_t *src) G_GNUC_WARN_UNUSED_RESULT;
#define RSPAMD_FTOK_ASSIGN(t, lit) \
do { \
diff --git a/src/libutil/hash.c b/src/libutil/hash.c
index d2af88c16..1f2f76c7a 100644
--- a/src/libutil/hash.c
+++ b/src/libutil/hash.c
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,16 +22,16 @@
* LRU hashing
*/
-static const guint log_base = 10;
-static const guint eviction_candidates = 16;
-static const gdouble lfu_base_value = 5.0;
+static const unsigned int log_base = 10;
+static const unsigned int eviction_candidates = 16;
+static const double lfu_base_value = 5.0;
struct rspamd_lru_volatile_element_s;
struct rspamd_lru_hash_s {
- guint maxsize;
- guint eviction_min_prio;
- guint eviction_used;
+ unsigned int maxsize;
+ unsigned int eviction_min_prio;
+ unsigned int eviction_used;
struct rspamd_lru_element_s **eviction_pool;
GDestroyNotify value_destroy;
@@ -52,10 +52,10 @@ enum rspamd_lru_element_flags {
};
struct rspamd_lru_element_s {
- guint16 last;
- guint8 lg_usages;
- guint8 eviction_pos;
- guint8 flags;
+ uint16_t last;
+ uint8_t lg_usages;
+ uint8_t eviction_pos;
+ uint8_t flags;
gpointer data;
};
@@ -66,7 +66,7 @@ struct rspamd_lru_volatile_element_s {
};
typedef struct rspamd_lru_volatile_element_s rspamd_lru_vol_element_t;
-#define TIME_TO_TS(t) ((guint16) (((t) / 60) & 0xFFFFU))
+#define TIME_TO_TS(t) ((uint16_t) (((t) / 60) & 0xFFFFU))
static rspamd_lru_vol_element_t *
rspamd_lru_hash_get(const rspamd_lru_hash_t *h, gconstpointer key)
@@ -153,7 +153,7 @@ rspamd_lru_hash_resize(rspamd_lru_hash_t *h,
khint_t new_mask;
new_mask = new_n_buckets - 1;
val = h->vals[j];
- val.e.eviction_pos = (guint8) -1;
+ val.e.eviction_pos = (uint8_t) -1;
__ac_set_isdel_true(h->flags, j);
while (1) { /* kick-out process; sort of like in Cuckoo hashing */
@@ -178,7 +178,7 @@ rspamd_lru_hash_resize(rspamd_lru_hash_t *h,
rspamd_lru_vol_element_t tmp = h->vals[i];
h->vals[i] = val;
val = tmp;
- val.e.eviction_pos = (guint8) -1;
+ val.e.eviction_pos = (uint8_t) -1;
}
__ac_set_isdel_true(h->flags, i);
/* mark it as deleted in the old hash table */
@@ -310,7 +310,7 @@ static void
rspamd_lru_hash_remove_evicted(rspamd_lru_hash_t *hash,
rspamd_lru_element_t *elt)
{
- guint i;
+ unsigned int i;
rspamd_lru_element_t *cur;
g_assert(hash->eviction_used > 0);
@@ -345,7 +345,7 @@ rspamd_lru_hash_remove_evicted(rspamd_lru_hash_t *hash,
static void
rspamd_lru_hash_update_counter(rspamd_lru_element_t *elt)
{
- guint8 counter = elt->lg_usages;
+ uint8_t counter = elt->lg_usages;
if (counter != 255) {
double r, baseval, p;
@@ -378,10 +378,10 @@ static gboolean
rspamd_lru_hash_maybe_evict(rspamd_lru_hash_t *hash,
rspamd_lru_element_t *elt)
{
- guint i;
+ unsigned int i;
rspamd_lru_element_t *cur;
- if (elt->eviction_pos == (guint8) -1) {
+ if (elt->eviction_pos == (uint8_t) -1) {
if (hash->eviction_used < eviction_candidates) {
/* There are free places in eviction pool */
hash->eviction_pool[hash->eviction_used] = elt;
@@ -424,7 +424,7 @@ rspamd_lru_hash_maybe_evict(rspamd_lru_hash_t *hash,
static void
rspamd_lru_hash_remove_node(rspamd_lru_hash_t *hash, rspamd_lru_element_t *elt)
{
- if (elt->eviction_pos != (guint8) -1) {
+ if (elt->eviction_pos != (uint8_t) -1) {
rspamd_lru_hash_remove_evicted(hash, elt);
}
@@ -435,9 +435,9 @@ static void
rspamd_lru_hash_evict(rspamd_lru_hash_t *hash, time_t now)
{
double r;
- guint i;
+ unsigned int i;
rspamd_lru_element_t *elt = NULL;
- guint nexpired = 0;
+ unsigned int nexpired = 0;
/*
* We either evict one node from the eviction list
@@ -503,7 +503,7 @@ rspamd_lru_hash_evict(rspamd_lru_hash_t *hash, time_t now)
}
rspamd_lru_hash_t *
-rspamd_lru_hash_new_full(gint maxsize,
+rspamd_lru_hash_new_full(int maxsize,
GDestroyNotify key_destroy,
GDestroyNotify value_destroy,
GHashFunc hf,
@@ -532,7 +532,7 @@ rspamd_lru_hash_new_full(gint maxsize,
}
rspamd_lru_hash_t *
-rspamd_lru_hash_new(gint maxsize,
+rspamd_lru_hash_new(int maxsize,
GDestroyNotify key_destroy,
GDestroyNotify value_destroy)
{
@@ -593,11 +593,11 @@ void rspamd_lru_hash_insert(rspamd_lru_hash_t *hash,
gpointer key,
gpointer value,
time_t now,
- guint ttl)
+ unsigned int ttl)
{
rspamd_lru_element_t *node;
rspamd_lru_vol_element_t *vnode;
- gint ret;
+ int ret;
vnode = rspamd_lru_hash_put(hash, key, &ret);
node = &vnode->e;
@@ -629,9 +629,9 @@ void rspamd_lru_hash_insert(rspamd_lru_hash_t *hash,
}
node->data = value;
- node->lg_usages = (guint8) lfu_base_value;
+ node->lg_usages = (uint8_t) lfu_base_value;
node->last = TIME_TO_TS(now);
- node->eviction_pos = (guint8) -1;
+ node->eviction_pos = (uint8_t) -1;
if (ret != 0) {
/* Also need to check maxsize */
@@ -679,7 +679,7 @@ rspamd_lru_hash_element_data(rspamd_lru_element_t *elt)
int rspamd_lru_hash_foreach(rspamd_lru_hash_t *h, int it, gpointer *k,
gpointer *v)
{
- gint i;
+ int i;
g_assert(it >= 0);
for (i = it; i != kh_end(h); ++i) {
@@ -701,7 +701,7 @@ int rspamd_lru_hash_foreach(rspamd_lru_hash_t *h, int it, gpointer *k,
}
-guint rspamd_lru_hash_size(rspamd_lru_hash_t *hash)
+unsigned int rspamd_lru_hash_size(rspamd_lru_hash_t *hash)
{
return kh_size(hash);
}
@@ -710,7 +710,7 @@ guint rspamd_lru_hash_size(rspamd_lru_hash_t *hash)
* Returns hash capacity
* @param hash hash object
*/
-guint rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash)
+unsigned int rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash)
{
return hash->maxsize;
} \ No newline at end of file
diff --git a/src/libutil/hash.h b/src/libutil/hash.h
index 3882ce5c7..1feeacf5f 100644
--- a/src/libutil/hash.h
+++ b/src/libutil/hash.h
@@ -27,7 +27,7 @@ typedef struct rspamd_lru_element_s rspamd_lru_element_t;
* @param key_equal_func pointer to function for comparing keys
* @return new rspamd_hash object
*/
-rspamd_lru_hash_t *rspamd_lru_hash_new(gint maxsize,
+rspamd_lru_hash_t *rspamd_lru_hash_new(int maxsize,
GDestroyNotify key_destroy,
GDestroyNotify value_destroy);
@@ -40,7 +40,7 @@ rspamd_lru_hash_t *rspamd_lru_hash_new(gint maxsize,
* @param key_equal_func pointer to function for comparing keys
* @return new rspamd_hash object
*/
-rspamd_lru_hash_t *rspamd_lru_hash_new_full(gint maxsize,
+rspamd_lru_hash_t *rspamd_lru_hash_new_full(int maxsize,
GDestroyNotify key_destroy,
GDestroyNotify value_destroy,
GHashFunc hfunc,
@@ -75,7 +75,7 @@ void rspamd_lru_hash_insert(rspamd_lru_hash_t *hash,
gpointer key,
gpointer value,
time_t now,
- guint ttl);
+ unsigned int ttl);
/**
* Remove lru hash
@@ -99,13 +99,13 @@ int rspamd_lru_hash_foreach(rspamd_lru_hash_t *hash, int it, gpointer *k,
* Returns number of elements in a hash
* @param hash hash object
*/
-guint rspamd_lru_hash_size(rspamd_lru_hash_t *hash);
+unsigned int rspamd_lru_hash_size(rspamd_lru_hash_t *hash);
/**
* Returns hash capacity
* @param hash hash object
*/
-guint rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash);
+unsigned int rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash);
#ifdef __cplusplus
}
diff --git a/src/libutil/heap.c b/src/libutil/heap.c
index 8ce70cf71..dcff58b40 100644
--- a/src/libutil/heap.c
+++ b/src/libutil/heap.c
@@ -140,9 +140,9 @@ rspamd_min_heap_pop(struct rspamd_min_heap *heap)
}
void rspamd_min_heap_update_elt(struct rspamd_min_heap *heap,
- struct rspamd_min_heap_elt *elt, guint npri)
+ struct rspamd_min_heap_elt *elt, unsigned int npri)
{
- guint oldpri;
+ unsigned int oldpri;
g_assert(heap != NULL);
g_assert(elt->idx > 0 && elt->idx <= heap->ar->len);
@@ -188,7 +188,7 @@ void rspamd_min_heap_destroy(struct rspamd_min_heap *heap)
}
struct rspamd_min_heap_elt *
-rspamd_min_heap_index(struct rspamd_min_heap *heap, guint idx)
+rspamd_min_heap_index(struct rspamd_min_heap *heap, unsigned int idx)
{
g_assert(heap != NULL);
g_assert(idx < heap->ar->len);
diff --git a/src/libutil/heap.h b/src/libutil/heap.h
index 805f817c9..d56ee02b2 100644
--- a/src/libutil/heap.h
+++ b/src/libutil/heap.h
@@ -28,8 +28,8 @@ extern "C" {
struct rspamd_min_heap_elt {
gpointer data;
- guint pri;
- guint idx;
+ unsigned int pri;
+ unsigned int idx;
};
struct rspamd_min_heap;
@@ -64,7 +64,7 @@ struct rspamd_min_heap_elt *rspamd_min_heap_pop(struct rspamd_min_heap *heap);
* @param npri new priority
*/
void rspamd_min_heap_update_elt(struct rspamd_min_heap *heap,
- struct rspamd_min_heap_elt *elt, guint npri);
+ struct rspamd_min_heap_elt *elt, unsigned int npri);
/**
@@ -88,7 +88,7 @@ void rspamd_min_heap_destroy(struct rspamd_min_heap *heap);
* @return
*/
struct rspamd_min_heap_elt *rspamd_min_heap_index(struct rspamd_min_heap *heap,
- guint idx);
+ unsigned int idx);
#ifdef __cplusplus
}
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c
index 9d7c4a99a..2912d423c 100644
--- a/src/libutil/mem_pool.c
+++ b/src/libutil/mem_pool.c
@@ -65,7 +65,7 @@
static inline uint32_t
rspamd_entry_hash(const char *str)
{
- return (guint) rspamd_cryptobox_fast_hash(str, strlen(str), rspamd_hash_seed());
+ return (unsigned int) rspamd_cryptobox_fast_hash(str, strlen(str), rspamd_hash_seed());
}
static inline int
@@ -75,7 +75,7 @@ rspamd_entry_equal(const char *k1, const char *k2)
}
-KHASH_INIT(mempool_entry, const gchar *, struct rspamd_mempool_entry_point *,
+KHASH_INIT(mempool_entry, const char *, struct rspamd_mempool_entry_point *,
1, rspamd_entry_hash, rspamd_entry_equal)
static khash_t(mempool_entry) *mempool_entries = NULL;
@@ -103,10 +103,10 @@ pool_chain_free(struct _pool_chain *chain)
#define FIXED_POOL_SIZE 4096
static inline struct rspamd_mempool_entry_point *
-rspamd_mempool_entry_new(const gchar *loc)
+rspamd_mempool_entry_new(const char *loc)
{
struct rspamd_mempool_entry_point **pentry, *entry;
- gint r;
+ int r;
khiter_t k;
k = kh_put(mempool_entry, mempool_entries, loc, &r);
@@ -150,7 +150,7 @@ RSPAMD_DESTRUCTOR(rspamd_mempool_entries_dtor)
}
static inline struct rspamd_mempool_entry_point *
-rspamd_mempool_get_entry(const gchar *loc)
+rspamd_mempool_get_entry(const char *loc)
{
khiter_t k;
struct rspamd_mempool_entry_point *elt;
@@ -194,9 +194,9 @@ rspamd_mempool_chain_new(gsize size, gsize alignment, enum rspamd_mempool_chain_
abort();
}
chain = map;
- chain->begin = ((guint8 *) chain) + sizeof(struct _pool_chain);
+ chain->begin = ((uint8_t *) chain) + sizeof(struct _pool_chain);
#elif defined(HAVE_MMAP_ZERO)
- gint fd;
+ int fd;
fd = open("/dev/zero", O_RDWR);
if (fd == -1) {
@@ -214,7 +214,7 @@ rspamd_mempool_chain_new(gsize size, gsize alignment, enum rspamd_mempool_chain_
abort();
}
chain = map;
- chain->begin = ((guint8 *) chain) + sizeof(struct _pool_chain);
+ chain->begin = ((uint8_t *) chain) + sizeof(struct _pool_chain);
#else
#error No mmap methods are defined
#endif
@@ -226,7 +226,7 @@ rspamd_mempool_chain_new(gsize size, gsize alignment, enum rspamd_mempool_chain_
optimal_size = sys_alloc_size(total_size);
#endif
total_size = MAX(total_size, optimal_size);
- gint ret = posix_memalign(&map, alignment, total_size);
+ int ret = posix_memalign(&map, alignment, total_size);
if (ret != 0 || map == NULL) {
g_error("%s: failed to allocate %" G_GSIZE_FORMAT " bytes: %d - %s",
@@ -235,7 +235,7 @@ rspamd_mempool_chain_new(gsize size, gsize alignment, enum rspamd_mempool_chain_
}
chain = map;
- chain->begin = ((guint8 *) chain) + sizeof(struct _pool_chain);
+ chain->begin = ((uint8_t *) chain) + sizeof(struct _pool_chain);
g_atomic_int_add(&mem_pool_stat->bytes_allocated, total_size);
g_atomic_int_inc(&mem_pool_stat->chunks_allocated);
}
@@ -280,7 +280,7 @@ rspamd_mempool_append_chain(rspamd_mempool_t *pool,
* @return new memory pool object
*/
rspamd_mempool_t *
-rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc)
+rspamd_mempool_new_(gsize size, const char *tag, int flags, const char *loc)
{
rspamd_mempool_t *new_pool;
gpointer map;
@@ -301,7 +301,7 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc)
}
mem_pool_stat = (rspamd_mempool_stat_t *) map;
#elif defined(HAVE_MMAP_ZERO)
- gint fd;
+ int fd;
fd = open("/dev/zero", O_RDWR);
g_assert(fd != -1);
@@ -359,9 +359,9 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc)
* alignment (if needed)
* memory chunk
*/
- guchar *mem_chunk;
- gint ret = posix_memalign((void **) &mem_chunk, MIN_MEM_ALIGNMENT,
- total_size);
+ unsigned char *mem_chunk;
+ int ret = posix_memalign((void **) &mem_chunk, MIN_MEM_ALIGNMENT,
+ total_size);
gsize priv_offset;
if (ret != 0 || mem_chunk == NULL) {
@@ -416,10 +416,10 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc)
priv_offset +
sizeof(struct rspamd_mempool_specific));
- guchar *unaligned = mem_chunk +
- priv_offset +
- sizeof(struct rspamd_mempool_specific) +
- sizeof(struct _pool_chain);
+ unsigned char *unaligned = mem_chunk +
+ priv_offset +
+ sizeof(struct rspamd_mempool_specific) +
+ sizeof(struct _pool_chain);
nchain->slice_size = size;
nchain->begin = unaligned;
@@ -430,7 +430,7 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc)
/* Adjust stats */
g_atomic_int_add(&mem_pool_stat->bytes_allocated,
- (gint) size);
+ (int) size);
g_atomic_int_add(&mem_pool_stat->chunks_allocated, 1);
return new_pool;
@@ -439,14 +439,14 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc)
static void *
memory_pool_alloc_common(rspamd_mempool_t *pool, gsize size, gsize alignment,
enum rspamd_mempool_chain_type pool_type,
- const gchar *loc)
+ const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
-void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const gchar *loc)
+void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const char *loc)
{
if (pool && G_UNLIKELY(pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) {
- GHashTable *debug_tbl = *(GHashTable **) (((guchar *) pool + sizeof(*pool)));
+ GHashTable *debug_tbl = *(GHashTable **) (((unsigned char *) pool + sizeof(*pool)));
gpointer ptr;
ptr = g_hash_table_lookup(debug_tbl, loc);
@@ -464,9 +464,9 @@ void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const gcha
static void *
memory_pool_alloc_common(rspamd_mempool_t *pool, gsize size, gsize alignment,
- enum rspamd_mempool_chain_type pool_type, const gchar *loc)
+ enum rspamd_mempool_chain_type pool_type, const char *loc)
{
- guint8 *tmp;
+ uint8_t *tmp;
struct _pool_chain *new, *cur;
gsize free = 0;
@@ -549,7 +549,7 @@ memory_pool_alloc_common(rspamd_mempool_t *pool, gsize size, gsize alignment,
void *
-rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
{
return memory_pool_alloc_common(pool, size, alignment, RSPAMD_MEMPOOL_NORMAL, loc);
}
@@ -561,7 +561,7 @@ rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const
#define MUL_NO_OVERFLOW (1UL << (sizeof(gsize) * 4))
void *
-rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const gchar *loc)
+rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const char *loc)
{
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
nmemb > 0 && G_MAXSIZE / nmemb < size) {
@@ -574,7 +574,7 @@ rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsi
}
void *
-rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
{
void *pointer = rspamd_mempool_alloc_(pool, size, alignment, loc);
memset(pointer, 0, size);
@@ -582,7 +582,7 @@ rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, cons
return pointer;
}
void *
-rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
{
void *pointer = rspamd_mempool_alloc_shared_(pool, size, alignment, loc);
@@ -591,14 +591,14 @@ rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignmen
}
void *
-rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
{
return memory_pool_alloc_common(pool, size, alignment, RSPAMD_MEMPOOL_SHARED, loc);
}
-gchar *
-rspamd_mempool_strdup_(rspamd_mempool_t *pool, const gchar *src, const gchar *loc)
+char *
+rspamd_mempool_strdup_(rspamd_mempool_t *pool, const char *src, const char *loc)
{
if (src == NULL) {
return NULL;
@@ -606,10 +606,10 @@ rspamd_mempool_strdup_(rspamd_mempool_t *pool, const gchar *src, const gchar *lo
return rspamd_mempool_strdup_len_(pool, src, strlen(src), loc);
}
-gchar *
-rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const gchar *src, gsize len, const gchar *loc)
+char *
+rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const char *src, gsize len, const char *loc)
{
- gchar *newstr;
+ char *newstr;
if (src == NULL) {
return NULL;
@@ -622,11 +622,11 @@ rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const gchar *src, gsize len,
return newstr;
}
-gchar *
+char *
rspamd_mempool_ftokdup_(rspamd_mempool_t *pool, const rspamd_ftok_t *src,
- const gchar *loc)
+ const char *loc)
{
- gchar *newstr;
+ char *newstr;
if (src == NULL) {
return NULL;
@@ -642,8 +642,8 @@ rspamd_mempool_ftokdup_(rspamd_mempool_t *pool, const rspamd_ftok_t *src,
void rspamd_mempool_add_destructor_full(rspamd_mempool_t *pool,
rspamd_mempool_destruct_t func,
void *data,
- const gchar *function,
- const gchar *line)
+ const char *function,
+ const char *line)
{
struct _pool_destructors *cur;
@@ -685,10 +685,10 @@ void rspamd_mempool_replace_destructor(rspamd_mempool_t *pool,
}
}
-static gint
+static int
cmp_int(gconstpointer a, gconstpointer b)
{
- gint i1 = *(const gint *) a, i2 = *(const gint *) b;
+ int i1 = *(const int *) a, i2 = *(const int *) b;
return i1 - i2;
}
@@ -696,14 +696,14 @@ cmp_int(gconstpointer a, gconstpointer b)
static void
rspamd_mempool_adjust_entry(struct rspamd_mempool_entry_point *e)
{
- gint sz[G_N_ELEMENTS(e->elts)], sel_pos, sel_neg;
- guint i, jitter;
+ int sz[G_N_ELEMENTS(e->elts)], sel_pos, sel_neg;
+ unsigned int i, jitter;
for (i = 0; i < G_N_ELEMENTS(sz); i++) {
- sz[i] = e->elts[i].fragmentation - (gint) e->elts[i].leftover;
+ sz[i] = e->elts[i].fragmentation - (int) e->elts[i].leftover;
}
- qsort(sz, G_N_ELEMENTS(sz), sizeof(gint), cmp_int);
+ qsort(sz, G_N_ELEMENTS(sz), sizeof(int), cmp_int);
jitter = rspamd_random_uint64_fast() % 10;
/*
* Take stochastic quantiles
@@ -751,11 +751,11 @@ rspamd_mempool_variables_cleanup(rspamd_mempool_t *pool)
* previous count
* 3) Our variables count is less than some hard limit
*/
- static const guint max_preallocated_vars = 512;
+ static const unsigned int max_preallocated_vars = 512;
- guint cur_size = kh_size(pool->priv->variables);
- guint old_guess = pool->priv->entry->cur_vars;
- guint new_guess;
+ unsigned int cur_size = kh_size(pool->priv->variables);
+ unsigned int old_guess = pool->priv->entry->cur_vars;
+ unsigned int new_guess;
if (old_guess == 0) {
new_guess = MIN(cur_size, max_preallocated_vars);
@@ -801,16 +801,16 @@ void rspamd_mempool_destructors_enforce(rspamd_mempool_t *pool)
struct mempool_debug_elt {
gsize sz;
- const gchar *loc;
+ const char *loc;
};
-static gint
+static int
rspamd_mempool_debug_elt_cmp(const void *a, const void *b)
{
const struct mempool_debug_elt *e1 = a, *e2 = b;
/* Inverse order */
- return (gint) ((gssize) e2->sz) - ((gssize) e1->sz);
+ return (int) ((gssize) e2->sz) - ((gssize) e1->sz);
}
void rspamd_mempool_delete(rspamd_mempool_t *pool)
@@ -818,7 +818,7 @@ void rspamd_mempool_delete(rspamd_mempool_t *pool)
struct _pool_chain *cur, *tmp;
struct _pool_destructors *destructor;
gpointer ptr;
- guint i;
+ unsigned int i;
gsize len;
POOL_MTX_LOCK();
@@ -826,7 +826,7 @@ void rspamd_mempool_delete(rspamd_mempool_t *pool)
cur = pool->priv->pools[RSPAMD_MEMPOOL_NORMAL];
if (G_UNLIKELY(pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) {
- GHashTable *debug_tbl = *(GHashTable **) (((guchar *) pool) + sizeof(*pool));
+ GHashTable *debug_tbl = *(GHashTable **) (((unsigned char *) pool) + sizeof(*pool));
/* Show debug info */
gsize ndtor = 0;
LL_COUNT(pool->priv->dtors_head, destructor, ndtor);
@@ -850,14 +850,14 @@ void rspamd_mempool_delete(rspamd_mempool_t *pool)
while (g_hash_table_iter_next(&it, &k, &v)) {
struct mempool_debug_elt e;
- e.loc = (const gchar *) k;
+ e.loc = (const char *) k;
e.sz = GPOINTER_TO_SIZE(v);
g_array_append_val(sorted_debug_size, e);
}
g_array_sort(sorted_debug_size, rspamd_mempool_debug_elt_cmp);
- for (guint _i = 0; _i < sorted_debug_size->len; _i++) {
+ for (unsigned int _i = 0; _i < sorted_debug_size->len; _i++) {
struct mempool_debug_elt *e;
e = &g_array_index(sorted_debug_size, struct mempool_debug_elt, _i);
@@ -905,7 +905,7 @@ void rspamd_mempool_delete(rspamd_mempool_t *pool)
LL_FOREACH_SAFE(pool->priv->pools[i], cur, tmp)
{
g_atomic_int_add(&mem_pool_stat->bytes_allocated,
- -((gint) cur->slice_size));
+ -((int) cur->slice_size));
g_atomic_int_add(&mem_pool_stat->chunks_allocated, -1);
len = cur->slice_size + sizeof(struct _pool_chain);
@@ -957,7 +957,7 @@ gsize rspamd_mempool_suggest_size_(const char *loc)
/*
* Own emulation
*/
-static inline gint
+static inline int
__mutex_spin(rspamd_mempool_mutex_t *mutex)
{
/* check spin count */
@@ -1159,7 +1159,7 @@ void rspamd_mempool_wunlock_rwlock(rspamd_mempool_rwlock_t *lock)
#define RSPAMD_MEMPOOL_VARS_HASH_SEED 0xb32ad7c55eb2e647ULL
void rspamd_mempool_set_variable(rspamd_mempool_t *pool,
- const gchar *name,
+ const char *name,
gpointer value,
rspamd_mempool_destruct_t destructor)
{
@@ -1175,10 +1175,10 @@ void rspamd_mempool_set_variable(rspamd_mempool_t *pool,
}
}
- gint hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
+ int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
+ RSPAMD_MEMPOOL_VARS_HASH_SEED);
khiter_t it;
- gint r;
+ int r;
it = kh_put(rspamd_mempool_vars_hash, pool->priv->variables, hv, &r);
@@ -1204,15 +1204,15 @@ void rspamd_mempool_set_variable(rspamd_mempool_t *pool,
}
gpointer
-rspamd_mempool_get_variable(rspamd_mempool_t *pool, const gchar *name)
+rspamd_mempool_get_variable(rspamd_mempool_t *pool, const char *name)
{
if (pool->priv->variables == NULL) {
return NULL;
}
khiter_t it;
- gint hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
+ int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
+ RSPAMD_MEMPOOL_VARS_HASH_SEED);
it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv);
@@ -1227,15 +1227,15 @@ rspamd_mempool_get_variable(rspamd_mempool_t *pool, const gchar *name)
}
gpointer
-rspamd_mempool_steal_variable(rspamd_mempool_t *pool, const gchar *name)
+rspamd_mempool_steal_variable(rspamd_mempool_t *pool, const char *name)
{
if (pool->priv->variables == NULL) {
return NULL;
}
khiter_t it;
- gint hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
+ int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
+ RSPAMD_MEMPOOL_VARS_HASH_SEED);
it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv);
@@ -1251,12 +1251,12 @@ rspamd_mempool_steal_variable(rspamd_mempool_t *pool, const gchar *name)
return NULL;
}
-void rspamd_mempool_remove_variable(rspamd_mempool_t *pool, const gchar *name)
+void rspamd_mempool_remove_variable(rspamd_mempool_t *pool, const char *name)
{
if (pool->priv->variables != NULL) {
khiter_t it;
- gint hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
+ int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
+ RSPAMD_MEMPOOL_VARS_HASH_SEED);
it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv);
diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h
index de0fea14b..651b44661 100644
--- a/src/libutil/mem_pool.h
+++ b/src/libutil/mem_pool.h
@@ -85,9 +85,9 @@ typedef void (*rspamd_mempool_destruct_t)(void *ptr);
*/
#if !defined(HAVE_PTHREAD_PROCESS_SHARED) || defined(DISABLE_PTHREAD_MUTEX)
typedef struct memory_pool_mutex_s {
- gint lock;
+ int lock;
pid_t owner;
- guint spin;
+ unsigned int spin;
} rspamd_mempool_mutex_t;
/**
* Rwlock for locking shared memory regions
@@ -105,8 +105,8 @@ typedef pthread_rwlock_t rspamd_mempool_rwlock_t;
* Tag to use for logging purposes
*/
struct rspamd_mempool_tag {
- gchar tagname[MEMPOOL_TAG_LEN]; /**< readable name */
- gchar uid[MEMPOOL_UID_LEN]; /**< unique id */
+ char tagname[MEMPOOL_TAG_LEN]; /**< readable name */
+ char uid[MEMPOOL_UID_LEN]; /**< unique id */
};
enum rspamd_mempool_flags {
@@ -128,14 +128,14 @@ typedef struct memory_pool_s {
* Statistics structure
*/
typedef struct memory_pool_stat_s {
- guint pools_allocated; /**< total number of allocated pools */
- guint pools_freed; /**< number of freed pools */
- guint bytes_allocated; /**< bytes that are allocated with pool allocator */
- guint chunks_allocated; /**< number of chunks that are allocated */
- guint shared_chunks_allocated; /**< shared chunks allocated */
- guint chunks_freed; /**< chunks freed */
- guint oversized_chunks; /**< oversized chunks */
- guint fragmented_size; /**< fragmentation size */
+ unsigned int pools_allocated; /**< total number of allocated pools */
+ unsigned int pools_freed; /**< number of freed pools */
+ unsigned int bytes_allocated; /**< bytes that are allocated with pool allocator */
+ unsigned int chunks_allocated; /**< number of chunks that are allocated */
+ unsigned int shared_chunks_allocated; /**< shared chunks allocated */
+ unsigned int chunks_freed; /**< chunks freed */
+ unsigned int oversized_chunks; /**< oversized chunks */
+ unsigned int fragmented_size; /**< fragmentation size */
} rspamd_mempool_stat_t;
@@ -144,8 +144,8 @@ typedef struct memory_pool_stat_s {
* @param size size of pool's page
* @return new memory pool object
*/
-rspamd_mempool_t *rspamd_mempool_new_(gsize size, const gchar *tag, gint flags,
- const gchar *loc);
+rspamd_mempool_t *rspamd_mempool_new_(gsize size, const char *tag, int flags,
+ const char *loc);
#define rspamd_mempool_new(size, tag, flags) \
rspamd_mempool_new_((size), (tag), (flags), G_STRLOC)
@@ -158,7 +158,7 @@ rspamd_mempool_t *rspamd_mempool_new_(gsize size, const gchar *tag, gint flags,
* @param size bytes to allocate
* @return pointer to allocated object
*/
-void *rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+void *rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
/**
* Allocates array handling potential integer overflow
@@ -169,7 +169,7 @@ void *rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment,
* @param loc
* @return
*/
-void *rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const gchar *loc)
+void *rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
#define rspamd_mempool_alloc(pool, size) \
rspamd_mempool_alloc_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC))
@@ -188,7 +188,7 @@ void *rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize siz
* @param size
* @param loc
*/
-void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const gchar *loc);
+void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const char *loc);
#define rspamd_mempool_notify_alloc(pool, size) \
rspamd_mempool_notify_alloc_((pool), (size), (G_STRLOC))
@@ -198,7 +198,7 @@ void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const gcha
* @param size bytes to allocate
* @return pointer to allocated object
*/
-void *rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+void *rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
#define rspamd_mempool_alloc0(pool, size) \
rspamd_mempool_alloc0_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC))
@@ -212,11 +212,11 @@ void *rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment
* @param src source string
* @return pointer to newly created string that is copy of src
*/
-gchar *rspamd_mempool_strdup_(rspamd_mempool_t *pool, const gchar *src, const gchar *loc)
+char *rspamd_mempool_strdup_(rspamd_mempool_t *pool, const char *src, const char *loc)
RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
#define rspamd_mempool_strdup(pool, src) \
rspamd_mempool_strdup_((pool), (src), (G_STRLOC))
-gchar *rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const gchar *src, gsize len, const gchar *loc)
+char *rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const char *src, gsize len, const char *loc)
RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
#define rspamd_mempool_strdup_len(pool, src, len) \
rspamd_mempool_strdup_len_((pool), (src), (len), (G_STRLOC))
@@ -229,9 +229,9 @@ struct f_str_tok;
* @param src source string
* @return pointer to newly created string that is copy of src
*/
-gchar *rspamd_mempool_ftokdup_(rspamd_mempool_t *pool,
- const struct f_str_tok *src,
- const gchar *loc)
+char *rspamd_mempool_ftokdup_(rspamd_mempool_t *pool,
+ const struct f_str_tok *src,
+ const char *loc)
RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
#define rspamd_mempool_ftokdup(pool, src) \
rspamd_mempool_ftokdup_((pool), (src), (G_STRLOC))
@@ -241,7 +241,7 @@ gchar *rspamd_mempool_ftokdup_(rspamd_mempool_t *pool,
* @param pool memory pool object
* @param size bytes to allocate
*/
-void *rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+void *rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
#define rspamd_mempool_alloc_shared(pool, size) \
rspamd_mempool_alloc_shared_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC))
@@ -249,7 +249,7 @@ void *rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize ali
(type *) (rspamd_mempool_alloc_shared_((pool), sizeof(type), \
MAX(MIN_MEM_ALIGNMENT, RSPAMD_ALIGNOF(type)), (G_STRLOC)))
-void *rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+void *rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
#define rspamd_mempool_alloc0_shared(pool, size) \
rspamd_mempool_alloc0_shared_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC))
@@ -266,8 +266,8 @@ void *rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize al
void rspamd_mempool_add_destructor_full(rspamd_mempool_t *pool,
rspamd_mempool_destruct_t func,
void *data,
- const gchar *function,
- const gchar *line);
+ const char *function,
+ const char *line);
/* Macros for common usage */
#define rspamd_mempool_add_destructor(pool, func, data) \
@@ -377,7 +377,7 @@ gsize rspamd_mempool_get_wasted_size(rspamd_mempool_t *pool);
* @param destructor pointer to function-destructor
*/
void rspamd_mempool_set_variable(rspamd_mempool_t *pool,
- const gchar *name,
+ const char *name,
gpointer value,
rspamd_mempool_destruct_t destructor);
@@ -388,7 +388,7 @@ void rspamd_mempool_set_variable(rspamd_mempool_t *pool,
* @return NULL or pointer to variable data
*/
gpointer rspamd_mempool_get_variable(rspamd_mempool_t *pool,
- const gchar *name);
+ const char *name);
/**
* Steal memory pool variable
* @param pool
@@ -396,7 +396,7 @@ gpointer rspamd_mempool_get_variable(rspamd_mempool_t *pool,
* @return
*/
gpointer rspamd_mempool_steal_variable(rspamd_mempool_t *pool,
- const gchar *name);
+ const char *name);
/**
* Removes variable from memory pool
@@ -404,7 +404,7 @@ gpointer rspamd_mempool_steal_variable(rspamd_mempool_t *pool,
* @param name name of variable
*/
void rspamd_mempool_remove_variable(rspamd_mempool_t *pool,
- const gchar *name);
+ const char *name);
/**
* Prepend element to a list creating it in the memory pool
diff --git a/src/libutil/mem_pool_internal.h b/src/libutil/mem_pool_internal.h
index 9fff5c7de..26a687b6c 100644
--- a/src/libutil/mem_pool_internal.h
+++ b/src/libutil/mem_pool_internal.h
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2019 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,7 +22,7 @@
*/
#define align_ptr(p, a) \
- ((guint8 *) ((uintptr_t) (p) + ((-(intptr_t) (p)) & ((a) -1))))
+ ((uint8_t *) ((uintptr_t) (p) + ((-(intptr_t) (p)) & ((a) -1))))
enum rspamd_mempool_chain_type {
RSPAMD_MEMPOOL_NORMAL = 0,
@@ -38,7 +38,7 @@ struct entry_elt {
};
struct rspamd_mempool_entry_point {
- gchar src[ENTRY_LEN];
+ char src[ENTRY_LEN];
uint32_t cur_suggestion;
uint32_t cur_elts;
uint32_t cur_vars;
@@ -51,8 +51,8 @@ struct rspamd_mempool_entry_point {
struct _pool_destructors {
rspamd_mempool_destruct_t func; /**< pointer to destructor */
void *data; /**< data to free */
- const gchar *function; /**< function from which this destructor was added */
- const gchar *loc; /**< line number */
+ const char *function; /**< function from which this destructor was added */
+ const char *loc; /**< line number */
struct _pool_destructors *next;
};
@@ -74,16 +74,16 @@ struct rspamd_mempool_specific {
struct rspamd_mempool_entry_point *entry;
gsize elt_len; /**< size of an element */
gsize used_memory;
- guint wasted_memory;
- gint flags;
+ unsigned int wasted_memory;
+ int flags;
};
/**
* Pool page structure
*/
struct _pool_chain {
- guint8 *begin; /**< begin of pool chain block */
- guint8 *pos; /**< current start of free space in block */
+ uint8_t *begin; /**< begin of pool chain block */
+ uint8_t *pos; /**< current start of free space in block */
gsize slice_size; /**< length of block */
struct _pool_chain *next;
};
diff --git a/src/libutil/multipattern.c b/src/libutil/multipattern.c
index bf3c7ad9a..3c9be0df3 100644
--- a/src/libutil/multipattern.c
+++ b/src/libutil/multipattern.c
@@ -49,14 +49,14 @@ struct RSPAMD_ALIGNED(64) rspamd_multipattern {
GArray *hs_pats;
GArray *hs_ids;
GArray *hs_flags;
- guint scratch_used;
+ unsigned int scratch_used;
#endif
ac_trie_t *t;
GArray *pats;
GArray *res;
gboolean compiled;
- guint cnt;
+ unsigned int cnt;
enum rspamd_multipattern_flags flags;
};
@@ -83,7 +83,7 @@ rspamd_hs_check(void)
return hs_suitable_cpu == RSPAMD_HS_SUPPORTED;
}
-void rspamd_multipattern_library_init(const gchar *cache_dir)
+void rspamd_multipattern_library_init(const char *cache_dir)
{
hs_cache_dir = cache_dir;
#ifdef WITH_HYPERSCAN
@@ -92,13 +92,13 @@ void rspamd_multipattern_library_init(const gchar *cache_dir)
}
#ifdef WITH_HYPERSCAN
-static gchar *
-rspamd_multipattern_escape_tld_hyperscan(const gchar *pattern, gsize slen,
+static char *
+rspamd_multipattern_escape_tld_hyperscan(const char *pattern, gsize slen,
gsize *dst_len)
{
gsize len;
- const gchar *p, *prefix, *suffix;
- gchar *res;
+ const char *p, *prefix, *suffix;
+ char *res;
/*
* We understand the following cases
@@ -141,13 +141,13 @@ rspamd_multipattern_escape_tld_hyperscan(const gchar *pattern, gsize slen,
}
#endif
-static gchar *
-rspamd_multipattern_escape_tld_acism(const gchar *pattern, gsize len,
+static char *
+rspamd_multipattern_escape_tld_acism(const char *pattern, gsize len,
gsize *dst_len)
{
gsize dlen, slen;
- const gchar *p, *prefix;
- gchar *res;
+ const char *p, *prefix;
+ char *res;
/*
* We understand the following cases
@@ -192,13 +192,13 @@ rspamd_multipattern_escape_tld_acism(const gchar *pattern, gsize len,
/*
* Escapes special characters from specific pattern
*/
-static gchar *
-rspamd_multipattern_pattern_filter(const gchar *pattern, gsize len,
+static char *
+rspamd_multipattern_pattern_filter(const char *pattern, gsize len,
enum rspamd_multipattern_flags flags,
gsize *dst_len)
{
- gchar *ret = NULL;
- gint gl_flags = RSPAMD_REGEXP_ESCAPE_ASCII;
+ char *ret = NULL;
+ int gl_flags = RSPAMD_REGEXP_ESCAPE_ASCII;
if (flags & RSPAMD_MULTIPATTERN_UTF8) {
gl_flags |= RSPAMD_REGEXP_ESCAPE_UTF;
@@ -207,7 +207,7 @@ rspamd_multipattern_pattern_filter(const gchar *pattern, gsize len,
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
if (flags & RSPAMD_MULTIPATTERN_TLD) {
- gchar *tmp;
+ char *tmp;
gsize tlen;
tmp = rspamd_multipattern_escape_tld_hyperscan(pattern, len, &tlen);
@@ -262,9 +262,9 @@ rspamd_multipattern_create(enum rspamd_multipattern_flags flags)
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- mp->hs_pats = g_array_new(FALSE, TRUE, sizeof(gchar *));
- mp->hs_flags = g_array_new(FALSE, TRUE, sizeof(gint));
- mp->hs_ids = g_array_new(FALSE, TRUE, sizeof(gint));
+ mp->hs_pats = g_array_new(FALSE, TRUE, sizeof(char *));
+ mp->hs_flags = g_array_new(FALSE, TRUE, sizeof(int));
+ mp->hs_ids = g_array_new(FALSE, TRUE, sizeof(int));
rspamd_cryptobox_hash_init(&mp->hash_state, NULL, 0);
return mp;
@@ -277,7 +277,7 @@ rspamd_multipattern_create(enum rspamd_multipattern_flags flags)
}
struct rspamd_multipattern *
-rspamd_multipattern_create_sized(guint npatterns,
+rspamd_multipattern_create_sized(unsigned int npatterns,
enum rspamd_multipattern_flags flags)
{
struct rspamd_multipattern *mp;
@@ -290,9 +290,9 @@ rspamd_multipattern_create_sized(guint npatterns,
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- mp->hs_pats = g_array_sized_new(FALSE, TRUE, sizeof(gchar *), npatterns);
- mp->hs_flags = g_array_sized_new(FALSE, TRUE, sizeof(gint), npatterns);
- mp->hs_ids = g_array_sized_new(FALSE, TRUE, sizeof(gint), npatterns);
+ mp->hs_pats = g_array_sized_new(FALSE, TRUE, sizeof(char *), npatterns);
+ mp->hs_flags = g_array_sized_new(FALSE, TRUE, sizeof(int), npatterns);
+ mp->hs_ids = g_array_sized_new(FALSE, TRUE, sizeof(int), npatterns);
rspamd_cryptobox_hash_init(&mp->hash_state, NULL, 0);
return mp;
@@ -305,7 +305,7 @@ rspamd_multipattern_create_sized(guint npatterns,
}
void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp,
- const gchar *pattern, gint flags)
+ const char *pattern, int flags)
{
g_assert(pattern != NULL);
@@ -313,7 +313,7 @@ void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp,
}
void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp,
- const gchar *pattern, gsize patlen, gint flags)
+ const char *pattern, gsize patlen, int flags)
{
gsize dlen;
@@ -323,9 +323,9 @@ void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp,
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- gchar *np;
- gint fl = HS_FLAG_SOM_LEFTMOST;
- gint adjusted_flags = mp->flags | flags;
+ char *np;
+ int fl = HS_FLAG_SOM_LEFTMOST;
+ int adjusted_flags = mp->flags | flags;
if (adjusted_flags & RSPAMD_MULTIPATTERN_ICASE) {
fl |= HS_FLAG_CASELESS;
@@ -372,11 +372,11 @@ void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp,
}
struct rspamd_multipattern *
-rspamd_multipattern_create_full(const gchar **patterns,
- guint npatterns, enum rspamd_multipattern_flags flags)
+rspamd_multipattern_create_full(const char **patterns,
+ unsigned int npatterns, enum rspamd_multipattern_flags flags)
{
struct rspamd_multipattern *mp;
- guint i;
+ unsigned int i;
g_assert(npatterns > 0);
g_assert(patterns != NULL);
@@ -393,16 +393,16 @@ rspamd_multipattern_create_full(const gchar **patterns,
#ifdef WITH_HYPERSCAN
static gboolean
rspamd_multipattern_try_load_hs(struct rspamd_multipattern *mp,
- const guchar *hash)
+ const unsigned char *hash)
{
- gchar fp[PATH_MAX];
+ char fp[PATH_MAX];
if (hs_cache_dir == NULL) {
return FALSE;
}
rspamd_snprintf(fp, sizeof(fp), "%s/%*xs.hsmp", hs_cache_dir,
- (gint) rspamd_cryptobox_HASHBYTES / 2, hash);
+ (int) rspamd_cryptobox_HASHBYTES / 2, hash);
mp->hs_db = rspamd_hyperscan_maybe_load(fp, 0);
return mp->hs_db != NULL;
@@ -410,12 +410,12 @@ rspamd_multipattern_try_load_hs(struct rspamd_multipattern *mp,
static void
rspamd_multipattern_try_save_hs(struct rspamd_multipattern *mp,
- const guchar *hash)
+ const unsigned char *hash)
{
- gchar fp[PATH_MAX], np[PATH_MAX];
+ char fp[PATH_MAX], np[PATH_MAX];
char *bytes = NULL;
gsize len;
- gint fd;
+ int fd;
if (hs_cache_dir == NULL) {
return;
@@ -438,7 +438,7 @@ rspamd_multipattern_try_save_hs(struct rspamd_multipattern *mp,
fsync(fd);
rspamd_snprintf(np, sizeof(np), "%s/%*xs.hsmp", hs_cache_dir,
- (gint) rspamd_cryptobox_HASHBYTES / 2, hash);
+ (int) rspamd_cryptobox_HASHBYTES / 2, hash);
if (rename(fp, np) == -1) {
msg_warn("cannot rename hyperscan cache from %s to %s: %s",
@@ -473,10 +473,10 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError **
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- guint i;
+ unsigned int i;
hs_platform_info_t plt;
hs_compile_error_t *hs_errors;
- guchar hash[rspamd_cryptobox_HASHBYTES];
+ unsigned char hash[rspamd_cryptobox_HASHBYTES];
if (mp->cnt > 0) {
g_assert(hs_populate_platform(&plt) == HS_SUCCESS);
@@ -508,7 +508,7 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError **
if (hs_cache_dir != NULL) {
char fpath[PATH_MAX];
rspamd_snprintf(fpath, sizeof(fpath), "%s/%*xs.hsmp", hs_cache_dir,
- (gint) rspamd_cryptobox_HASHBYTES / 2, hash);
+ (int) rspamd_cryptobox_HASHBYTES / 2, hash);
mp->hs_db = rspamd_hyperscan_from_raw_db(db, fpath);
}
else {
@@ -564,9 +564,9 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError **
mp->res = g_array_sized_new(FALSE, TRUE,
sizeof(rspamd_regexp_t *), mp->cnt);
- for (guint i = 0; i < mp->cnt; i++) {
+ for (unsigned int i = 0; i < mp->cnt; i++) {
const ac_trie_pat_t *pat;
- const gchar *pat_flags = NULL;
+ const char *pat_flags = NULL;
if (mp->flags & RSPAMD_MULTIPATTERN_UTF8) {
pat_flags = "u";
@@ -594,16 +594,16 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError **
struct rspamd_multipattern_cbdata {
struct rspamd_multipattern *mp;
- const gchar *in;
+ const char *in;
gsize len;
rspamd_multipattern_cb_t cb;
gpointer ud;
- guint nfound;
- gint ret;
+ unsigned int nfound;
+ int ret;
};
#ifdef WITH_HYPERSCAN
-static gint
+static int
rspamd_multipattern_hs_cb(unsigned int id,
unsigned long long from,
unsigned long long to,
@@ -611,7 +611,7 @@ rspamd_multipattern_hs_cb(unsigned int id,
void *ud)
{
struct rspamd_multipattern_cbdata *cbd = ud;
- gint ret = 0;
+ int ret = 0;
if (to > 0) {
@@ -629,11 +629,11 @@ rspamd_multipattern_hs_cb(unsigned int id,
}
#endif
-static gint
+static int
rspamd_multipattern_acism_cb(int strnum, int textpos, void *context)
{
struct rspamd_multipattern_cbdata *cbd = context;
- gint ret;
+ int ret;
ac_trie_pat_t pat;
pat = g_array_index(cbd->mp->pats, ac_trie_pat_t, strnum);
@@ -646,12 +646,12 @@ rspamd_multipattern_acism_cb(int strnum, int textpos, void *context)
return ret;
}
-gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
- const gchar *in, gsize len, rspamd_multipattern_cb_t cb,
- gpointer ud, guint *pnfound)
+int rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
+ const char *in, gsize len, rspamd_multipattern_cb_t cb,
+ gpointer ud, unsigned int *pnfound)
{
struct rspamd_multipattern_cbdata cbd;
- gint ret = 0;
+ int ret = 0;
g_assert(mp != NULL);
@@ -670,7 +670,7 @@ gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
hs_scratch_t *scr = NULL;
- guint i;
+ unsigned int i;
for (i = 0; i < MAX_SCRATCH; i++) {
if (!(mp->scratch_used & (1 << i))) {
@@ -702,13 +702,13 @@ gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
}
#endif
- gint state = 0;
+ int state = 0;
if (mp->flags & (RSPAMD_MULTIPATTERN_GLOB | RSPAMD_MULTIPATTERN_RE)) {
/* Terribly inefficient, but who cares - just use hyperscan */
- for (guint i = 0; i < mp->cnt; i++) {
+ for (unsigned int i = 0; i < mp->cnt; i++) {
rspamd_regexp_t *re = g_array_index(mp->res, rspamd_regexp_t *, i);
- const gchar *start = NULL, *end = NULL;
+ const char *start = NULL, *end = NULL;
while (rspamd_regexp_search(re,
in,
@@ -745,12 +745,12 @@ gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
void rspamd_multipattern_destroy(struct rspamd_multipattern *mp)
{
- guint i;
+ unsigned int i;
if (mp) {
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- gchar *p;
+ char *p;
if (mp->compiled && mp->cnt > 0) {
for (i = 0; i < MAX_SCRATCH; i++) {
@@ -763,7 +763,7 @@ void rspamd_multipattern_destroy(struct rspamd_multipattern *mp)
}
for (i = 0; i < mp->cnt; i++) {
- p = g_array_index(mp->hs_pats, gchar *, i);
+ p = g_array_index(mp->hs_pats, char *, i);
g_free(p);
}
@@ -783,7 +783,7 @@ void rspamd_multipattern_destroy(struct rspamd_multipattern *mp)
for (i = 0; i < mp->cnt; i++) {
pat = g_array_index(mp->pats, ac_trie_pat_t, i);
- g_free((gchar *) pat.ptr);
+ g_free((char *) pat.ptr);
}
g_array_free(mp->pats, TRUE);
@@ -792,16 +792,16 @@ void rspamd_multipattern_destroy(struct rspamd_multipattern *mp)
}
}
-const gchar *
+const char *
rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp,
- guint index)
+ unsigned int index)
{
g_assert(mp != NULL);
g_assert(index < mp->cnt);
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- return g_array_index(mp->hs_pats, gchar *, index);
+ return g_array_index(mp->hs_pats, char *, index);
}
#endif
@@ -812,7 +812,7 @@ rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp,
return pat.ptr;
}
-guint rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp)
+unsigned int rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp)
{
g_assert(mp != NULL);
diff --git a/src/libutil/multipattern.h b/src/libutil/multipattern.h
index 15099aaca..771dcd94a 100644
--- a/src/libutil/multipattern.h
+++ b/src/libutil/multipattern.h
@@ -56,19 +56,19 @@ struct rspamd_cryptobox_library_ctx;
* @param context userdata
* @return if 0 then search for another pattern, otherwise return this value to caller
*/
-typedef gint (*rspamd_multipattern_cb_t)(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
- gsize len,
- void *context);
+typedef int (*rspamd_multipattern_cb_t)(struct rspamd_multipattern *mp,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
+ gsize len,
+ void *context);
/**
* Init multipart library and set the appropriate cache dir
* @param cache_dir
*/
-void rspamd_multipattern_library_init(const gchar *cache_dir);
+void rspamd_multipattern_library_init(const char *cache_dir);
/**
* Creates empty multipattern structure
@@ -84,7 +84,7 @@ struct rspamd_multipattern *rspamd_multipattern_create(
* @param reserved
* @return
*/
-struct rspamd_multipattern *rspamd_multipattern_create_sized(guint reserved,
+struct rspamd_multipattern *rspamd_multipattern_create_sized(unsigned int reserved,
enum rspamd_multipattern_flags flags);
/**
@@ -95,8 +95,8 @@ struct rspamd_multipattern *rspamd_multipattern_create_sized(guint reserved,
* @return new multipattern structure
*/
struct rspamd_multipattern *rspamd_multipattern_create_full(
- const gchar **patterns,
- guint npatterns,
+ const char **patterns,
+ unsigned int npatterns,
enum rspamd_multipattern_flags flags);
/**
@@ -105,7 +105,7 @@ struct rspamd_multipattern *rspamd_multipattern_create_full(
* @param pattern
*/
void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp,
- const gchar *pattern, gint flags);
+ const char *pattern, int flags);
/**
* Adds new pattern from arbitrary string
@@ -115,7 +115,7 @@ void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp,
* @param flags
*/
void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp,
- const gchar *pattern, gsize patlen, gint flags);
+ const char *pattern, gsize patlen, int flags);
#define RSPAMD_MULTIPATTERN_COMPILE_NO_FS (0x1u << 0u)
@@ -137,9 +137,9 @@ gboolean rspamd_multipattern_compile(struct rspamd_multipattern *mp,
* @param ud callback data
* @return
*/
-gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
- const gchar *in, gsize len, rspamd_multipattern_cb_t cb,
- gpointer ud, guint *pnfound);
+int rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
+ const char *in, gsize len, rspamd_multipattern_cb_t cb,
+ gpointer ud, unsigned int *pnfound);
/**
* Get pattern string from multipattern identified by index
@@ -147,15 +147,15 @@ gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
* @param index
* @return
*/
-const gchar *rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp,
- guint index);
+const char *rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp,
+ unsigned int index);
/**
* Returns number of patterns in a multipattern matcher
* @param mp
* @return
*/
-guint rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp);
+unsigned int rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp);
/**
* Destroys multipattern structure
diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index b8322fc6b..82eab0ab8 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -46,13 +46,13 @@
* From FreeBSD libutil code
*/
static const int maxscale = 6;
-static const gchar _hex[] = "0123456789abcdef";
-static const gchar _HEX[] = "0123456789ABCDEF";
+static const char _hex[] = "0123456789abcdef";
+static const char _HEX[] = "0123456789ABCDEF";
-static gchar *
-rspamd_humanize_number(gchar *buf, gchar *last, int64_t num, gboolean bytes)
+static char *
+rspamd_humanize_number(char *buf, char *last, int64_t num, gboolean bytes)
{
- const gchar *prefixes;
+ const char *prefixes;
int i, r, remainder, sign;
int64_t divisor;
gsize len = last - buf;
@@ -96,7 +96,7 @@ rspamd_humanize_number(gchar *buf, gchar *last, int64_t num, gboolean bytes)
else {
/* Floating point version */
r = rspamd_snprintf(buf, len, "%.2f%s",
- sign * (num + remainder / (gdouble) divisor),
+ sign * (num + remainder / (double) divisor),
SCALE2PREFIX(i));
}
@@ -255,11 +255,11 @@ static const char int_lookup_table[200] = {
'9', '0', '9', '1', '9', '2', '9', '3', '9', '4',
'9', '5', '9', '6', '9', '7', '9', '8', '9', '9'};
-static inline guint
-rspamd_uint32_print(uint32_t in, gchar *out)
+static inline unsigned int
+rspamd_uint32_print(uint32_t in, char *out)
{
- guint ndigits = rspamd_decimal_digits32(in);
- gchar *p;
+ unsigned int ndigits = rspamd_decimal_digits32(in);
+ char *p;
p = out + ndigits - 1;
@@ -286,12 +286,12 @@ rspamd_uint32_print(uint32_t in, gchar *out)
return ndigits;
}
-static inline guint
-rspamd_uint64_print(uint64_t in, gchar *out)
+static inline unsigned int
+rspamd_uint64_print(uint64_t in, char *out)
{
- guint ndigits = rspamd_decimal_digits64(in);
+ unsigned int ndigits = rspamd_decimal_digits64(in);
uint32_t v32;
- gchar *p;
+ char *p;
p = out + ndigits - 1;
@@ -376,11 +376,11 @@ rspamd_ffsll(long long n)
#endif
}
-static gchar *
-rspamd_sprintf_num(gchar *buf, gchar *last, uint64_t ui64, gchar zero,
- guint hexadecimal, guint binary, guint width)
+static char *
+rspamd_sprintf_num(char *buf, char *last, uint64_t ui64, char zero,
+ unsigned int hexadecimal, unsigned int binary, unsigned int width)
{
- gchar *p, temp[64];
+ char *p, temp[64];
size_t len = 0;
if (G_LIKELY(hexadecimal == 0 && binary == 0)) {
@@ -436,7 +436,7 @@ rspamd_sprintf_num(gchar *buf, gchar *last, uint64_t ui64, gchar zero,
len = last - buf;
}
- return ((gchar *) memcpy(buf, p, len)) + len;
+ return ((char *) memcpy(buf, p, len)) + len;
}
struct rspamd_printf_char_buf {
@@ -446,7 +446,7 @@ struct rspamd_printf_char_buf {
};
static glong
-rspamd_printf_append_char(const gchar *buf, glong buflen, gpointer ud)
+rspamd_printf_append_char(const char *buf, glong buflen, gpointer ud)
{
struct rspamd_printf_char_buf *dst = (struct rspamd_printf_char_buf *) ud;
glong wr;
@@ -464,7 +464,7 @@ rspamd_printf_append_char(const gchar *buf, glong buflen, gpointer ud)
}
static glong
-rspamd_printf_append_file(const gchar *buf, glong buflen, gpointer ud)
+rspamd_printf_append_file(const char *buf, glong buflen, gpointer ud)
{
FILE *dst = (FILE *) ud;
if (buflen > 0) {
@@ -476,7 +476,7 @@ rspamd_printf_append_file(const gchar *buf, glong buflen, gpointer ud)
}
static glong
-rspamd_printf_append_gstring(const gchar *buf, glong buflen, gpointer ud)
+rspamd_printf_append_gstring(const char *buf, glong buflen, gpointer ud)
{
GString *dst = (GString *) ud;
@@ -488,7 +488,7 @@ rspamd_printf_append_gstring(const gchar *buf, glong buflen, gpointer ud)
}
static glong
-rspamd_printf_append_fstring(const gchar *buf, glong buflen, gpointer ud)
+rspamd_printf_append_fstring(const char *buf, glong buflen, gpointer ud)
{
rspamd_fstring_t **dst = ud;
@@ -499,7 +499,7 @@ rspamd_printf_append_fstring(const gchar *buf, glong buflen, gpointer ud)
return buflen;
}
-glong rspamd_fprintf(FILE *f, const gchar *fmt, ...)
+glong rspamd_fprintf(FILE *f, const char *fmt, ...)
{
va_list args;
glong r;
@@ -511,7 +511,7 @@ glong rspamd_fprintf(FILE *f, const gchar *fmt, ...)
return r;
}
-glong rspamd_printf(const gchar *fmt, ...)
+glong rspamd_printf(const char *fmt, ...)
{
va_list args;
glong r;
@@ -523,7 +523,7 @@ glong rspamd_printf(const gchar *fmt, ...)
return r;
}
-glong rspamd_log_fprintf(FILE *f, const gchar *fmt, ...)
+glong rspamd_log_fprintf(FILE *f, const char *fmt, ...)
{
va_list args;
glong r;
@@ -538,9 +538,9 @@ glong rspamd_log_fprintf(FILE *f, const gchar *fmt, ...)
}
-glong rspamd_snprintf(gchar *buf, glong max, const gchar *fmt, ...)
+glong rspamd_snprintf(char *buf, glong max, const char *fmt, ...)
{
- gchar *r;
+ char *r;
va_list args;
va_start(args, fmt);
@@ -550,8 +550,8 @@ glong rspamd_snprintf(gchar *buf, glong max, const gchar *fmt, ...)
return (r - buf);
}
-gchar *
-rspamd_vsnprintf(gchar *buf, glong max, const gchar *fmt, va_list args)
+char *
+rspamd_vsnprintf(char *buf, glong max, const char *fmt, va_list args)
{
struct rspamd_printf_char_buf dst;
@@ -564,7 +564,7 @@ rspamd_vsnprintf(gchar *buf, glong max, const gchar *fmt, va_list args)
return dst.pos;
}
-glong rspamd_printf_gstring(GString *s, const gchar *fmt, ...)
+glong rspamd_printf_gstring(GString *s, const char *fmt, ...)
{
va_list args;
glong r;
@@ -576,12 +576,12 @@ glong rspamd_printf_gstring(GString *s, const gchar *fmt, ...)
return r;
}
-glong rspamd_vprintf_gstring(GString *s, const gchar *fmt, va_list args)
+glong rspamd_vprintf_gstring(GString *s, const char *fmt, va_list args)
{
return rspamd_vprintf_common(rspamd_printf_append_gstring, s, fmt, args);
}
-glong rspamd_printf_fstring(rspamd_fstring_t **s, const gchar *fmt, ...)
+glong rspamd_printf_fstring(rspamd_fstring_t **s, const char *fmt, ...)
{
va_list args;
glong r;
@@ -593,7 +593,7 @@ glong rspamd_printf_fstring(rspamd_fstring_t **s, const gchar *fmt, ...)
return r;
}
-glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const gchar *fmt, va_list args)
+glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const char *fmt, va_list args)
{
return rspamd_vprintf_common(rspamd_printf_append_fstring, s, fmt, args);
}
@@ -616,18 +616,18 @@ glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const gchar *fmt, va_list arg
glong rspamd_vprintf_common(rspamd_printf_append_func func,
gpointer apd,
- const gchar *fmt,
+ const char *fmt,
va_list args)
{
- gchar zero, numbuf[G_ASCII_DTOSTR_BUF_SIZE], dtoabuf[32], *p, *last;
- guchar c;
- const gchar *buf_start = fmt;
- gint d;
- gdouble f;
+ char zero, numbuf[G_ASCII_DTOSTR_BUF_SIZE], dtoabuf[32], *p, *last;
+ unsigned char c;
+ const char *buf_start = fmt;
+ int d;
+ double f;
glong written = 0, wr, slen;
int64_t i64;
uint64_t ui64;
- guint width, sign, hex, humanize, bytes, frac_width, b32, b64;
+ unsigned int width, sign, hex, humanize, bytes, frac_width, b32, b64;
rspamd_fstring_t *v;
rspamd_ftok_t *tok;
GString *gs;
@@ -654,7 +654,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
i64 = 0;
ui64 = 0;
- zero = (gchar) ((*++fmt == '0') ? '0' : ' ');
+ zero = (char) ((*++fmt == '0') ? '0' : ' ');
width = 0;
sign = 1;
hex = 0;
@@ -718,11 +718,11 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
fmt++;
if (*fmt == '*') {
- d = (gint) va_arg(args, gint);
+ d = (int) va_arg(args, int);
if (G_UNLIKELY(d < 0)) {
return 0;
}
- frac_width = (guint) d;
+ frac_width = (unsigned int) d;
fmt++;
}
else {
@@ -734,7 +734,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
break;
case '*':
- d = (gint) va_arg(args, gint);
+ d = (int) va_arg(args, int);
if (G_UNLIKELY(d < 0)) {
return 0;
}
@@ -824,14 +824,14 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
continue;
case 's':
- p = va_arg(args, gchar *);
+ p = va_arg(args, char *);
if (p == NULL) {
p = "(NULL)";
slen = sizeof("(NULL)") - 1;
}
if (G_UNLIKELY(b32)) {
- gchar *b32buf;
+ char *b32buf;
if (G_UNLIKELY(slen == -1)) {
if (G_LIKELY(width != 0)) {
@@ -854,7 +854,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
}
}
else if (G_UNLIKELY(hex)) {
- gchar hexbuf[2];
+ char hexbuf[2];
if (G_UNLIKELY(slen == -1)) {
if (G_LIKELY(width != 0)) {
@@ -878,7 +878,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
buf_start = fmt;
}
else if (G_UNLIKELY(b64)) {
- gchar *b64buf;
+ char *b64buf;
gsize olen = 0;
if (G_UNLIKELY(slen == -1)) {
@@ -942,10 +942,10 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
case 'd':
if (sign) {
- i64 = (int64_t) va_arg(args, gint);
+ i64 = (int64_t) va_arg(args, int);
}
else {
- ui64 = (uint64_t) va_arg(args, guint);
+ ui64 = (uint64_t) va_arg(args, unsigned int);
}
break;
@@ -978,7 +978,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
case 'f':
- f = (gdouble) va_arg(args, double);
+ f = (double) va_arg(args, double);
slen = fpconv_dtoa(f, dtoabuf, frac_width, false);
RSPAMD_PRINTF_APPEND(dtoabuf, slen);
@@ -986,14 +986,14 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
continue;
case 'g':
- f = (gdouble) va_arg(args, double);
+ f = (double) va_arg(args, double);
slen = fpconv_dtoa(f, dtoabuf, 0, true);
RSPAMD_PRINTF_APPEND(dtoabuf, slen);
continue;
case 'F':
- f = (gdouble) va_arg(args, long double);
+ f = (double) va_arg(args, long double);
slen = fpconv_dtoa(f, dtoabuf, frac_width, false);
RSPAMD_PRINTF_APPEND(dtoabuf, slen);
@@ -1001,7 +1001,7 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
continue;
case 'G':
- f = (gdouble) va_arg(args, long double);
+ f = (double) va_arg(args, long double);
slen = fpconv_dtoa(f, dtoabuf, 0, true);
RSPAMD_PRINTF_APPEND(dtoabuf, slen);
@@ -1016,10 +1016,10 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
break;
case 'c':
- c = va_arg(args, gint);
+ c = va_arg(args, int);
c &= 0xffu;
if (G_UNLIKELY(hex)) {
- gchar hexbuf[2];
+ char hexbuf[2];
hexbuf[0] = hex == 2 ? _HEX[(c >> 4u) & 0xfu] : _hex[(c >> 4u) & 0xfu];
hexbuf[1] = hex == 2 ? _HEX[c & 0xfu] : _hex[c & 0xfu];
diff --git a/src/libutil/printf.h b/src/libutil/printf.h
index b4db34b8e..363f47bd9 100644
--- a/src/libutil/printf.h
+++ b/src/libutil/printf.h
@@ -27,7 +27,7 @@ extern "C" {
* %[0][width][x][X]O off_t
* %[0][width]T time_t
* %[0][width][u][x|X|h|H|b|B]z ssize_t/size_t
- * %[0][width][u][x|X|h|H|b|B]d gint/guint
+ * %[0][width][u][x|X|h|H|b|B]d int/unsigned int
* %[0][width][u][x|X|h|H|b|B]l long
* %[0][width][u][x|X|h|H|b|B]D int32_t/uint32_t
* %[0][width][u][x|X|h|H|b|B]L int64_t/uint64_t
@@ -48,7 +48,7 @@ extern "C" {
* %*s length and string
* %Z '\0'
* %N '\n'
- * %c gchar
+ * %c char
* %t time_t
* %e GError *
* %% %
@@ -62,31 +62,31 @@ extern "C" {
* @param ud opaque pointer
* @return number of characters written
*/
-typedef glong (*rspamd_printf_append_func)(const gchar *buf, glong buflen,
+typedef glong (*rspamd_printf_append_func)(const char *buf, glong buflen,
gpointer ud);
-glong rspamd_fprintf(FILE *f, const gchar *fmt, ...);
+glong rspamd_fprintf(FILE *f, const char *fmt, ...);
-glong rspamd_printf(const gchar *fmt, ...);
+glong rspamd_printf(const char *fmt, ...);
-glong rspamd_log_fprintf(FILE *f, const gchar *fmt, ...);
+glong rspamd_log_fprintf(FILE *f, const char *fmt, ...);
-glong rspamd_snprintf(gchar *buf, glong max, const gchar *fmt, ...);
+glong rspamd_snprintf(char *buf, glong max, const char *fmt, ...);
-gchar *rspamd_vsnprintf(gchar *buf, glong max, const gchar *fmt,
- va_list args);
+char *rspamd_vsnprintf(char *buf, glong max, const char *fmt,
+ va_list args);
-glong rspamd_printf_gstring(GString *s, const gchar *fmt, ...);
+glong rspamd_printf_gstring(GString *s, const char *fmt, ...);
-glong rspamd_vprintf_gstring(GString *s, const gchar *fmt, va_list args);
+glong rspamd_vprintf_gstring(GString *s, const char *fmt, va_list args);
-glong rspamd_printf_fstring(rspamd_fstring_t **s, const gchar *fmt, ...);
+glong rspamd_printf_fstring(rspamd_fstring_t **s, const char *fmt, ...);
-glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const gchar *fmt, va_list args);
+glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const char *fmt, va_list args);
glong rspamd_vprintf_common(rspamd_printf_append_func func,
gpointer apd,
- const gchar *fmt,
+ const char *fmt,
va_list args);
#ifdef __cplusplus
diff --git a/src/libutil/radix.c b/src/libutil/radix.c
index 93c728c8f..2cae8e34a 100644
--- a/src/libutil/radix.c
+++ b/src/libutil/radix.c
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -41,14 +41,14 @@ INIT_LOG_MODULE(radix)
struct radix_tree_compressed {
rspamd_mempool_t *pool;
struct btrie *tree;
- const gchar *name;
+ const char *name;
size_t size;
- guint duplicates;
+ unsigned int duplicates;
gboolean own_pool;
};
uintptr_t
-radix_find_compressed(radix_compressed_t *tree, const guint8 *key, gsize keylen)
+radix_find_compressed(radix_compressed_t *tree, const uint8_t *key, gsize keylen)
{
gconstpointer ret;
@@ -66,14 +66,14 @@ radix_find_compressed(radix_compressed_t *tree, const guint8 *key, gsize keylen)
uintptr_t
radix_insert_compressed(radix_compressed_t *tree,
- guint8 *key, gsize keylen,
+ uint8_t *key, gsize keylen,
gsize masklen,
uintptr_t value)
{
- static const guint max_duplicates = 32;
- guint keybits = keylen * NBBY;
+ static const unsigned int max_duplicates = 32;
+ unsigned int keybits = keylen * NBBY;
uintptr_t old;
- gchar ip_str[INET6_ADDRSTRLEN + 1];
+ char ip_str[INET6_ADDRSTRLEN + 1];
int ret;
g_assert(tree != NULL);
@@ -103,14 +103,14 @@ radix_insert_compressed(radix_compressed_t *tree,
tree->name,
(gpointer) value,
inet_ntop(AF_INET, key, ip_str, sizeof(ip_str) - 1),
- (gint) (keybits - masklen));
+ (int) (keybits - masklen));
}
else if (keybits == 128) {
msg_err_radix("%s: cannot insert %p, key: [%s]/%d, duplicate value",
tree->name,
(gpointer) value,
inet_ntop(AF_INET6, key, ip_str, sizeof(ip_str) - 1),
- (gint) (keybits - masklen));
+ (int) (keybits - masklen));
}
else {
msg_err_radix("%s: cannot insert %p with mask %z, key: %*xs, duplicate value",
@@ -130,7 +130,7 @@ radix_insert_compressed(radix_compressed_t *tree,
radix_compressed_t *
-radix_create_compressed(const gchar *tree_name)
+radix_create_compressed(const char *tree_name)
{
radix_compressed_t *tree;
@@ -150,7 +150,7 @@ radix_create_compressed(const gchar *tree_name)
}
radix_compressed_t *
-radix_create_compressed_with_pool(rspamd_mempool_t *pool, const gchar *tree_name)
+radix_create_compressed_with_pool(rspamd_mempool_t *pool, const char *tree_name)
{
radix_compressed_t *tree;
@@ -179,9 +179,9 @@ uintptr_t
radix_find_compressed_addr(radix_compressed_t *tree,
const rspamd_inet_addr_t *addr)
{
- const guchar *key;
- guint klen = 0;
- guchar buf[16];
+ const unsigned char *key;
+ unsigned int klen = 0;
+ unsigned char buf[16];
if (addr == NULL) {
return RADIX_NO_VALUE;
@@ -207,19 +207,19 @@ radix_find_compressed_addr(radix_compressed_t *tree,
return RADIX_NO_VALUE;
}
-gint rspamd_radix_add_iplist(const gchar *list, const gchar *separators,
- radix_compressed_t *tree, gconstpointer value,
- gboolean resolve, const gchar *tree_name)
+int rspamd_radix_add_iplist(const char *list, const char *separators,
+ radix_compressed_t *tree, gconstpointer value,
+ gboolean resolve, const char *tree_name)
{
- gchar *token, *ipnet, *err_str, **strv, **cur, *brace;
+ char *token, *ipnet, *err_str, **strv, **cur, *brace;
union {
struct in_addr ina;
struct in6_addr ina6;
- guchar buf[16];
+ unsigned char buf[16];
} addr_buf;
- guint k = G_MAXINT;
- gint af;
- gint res = 0, r;
+ unsigned int k = G_MAXINT;
+ int af;
+ int res = 0, r;
struct addrinfo hints, *ai_res, *cur_ai;
/* Split string if there are multiple items inside a single string */
@@ -388,8 +388,8 @@ gint rspamd_radix_add_iplist(const gchar *list, const gchar *separators,
}
gboolean
-radix_add_generic_iplist(const gchar *ip_list, radix_compressed_t **tree,
- gboolean resolve, const gchar *tree_name)
+radix_add_generic_iplist(const char *ip_list, radix_compressed_t **tree,
+ gboolean resolve, const char *tree_name)
{
static const char fill_ptr[] = "1";
@@ -423,7 +423,7 @@ radix_get_pool(radix_compressed_t *tree)
return NULL;
}
-const gchar *
+const char *
radix_get_info(radix_compressed_t *tree)
{
if (tree == NULL) {
diff --git a/src/libutil/radix.h b/src/libutil/radix.h
index a85da5b5f..c4fe96441 100644
--- a/src/libutil/radix.h
+++ b/src/libutil/radix.h
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -39,7 +39,7 @@ typedef struct radix_tree_compressed radix_compressed_t;
*/
uintptr_t
radix_insert_compressed(radix_compressed_t *tree,
- guint8 *key, gsize keylen,
+ uint8_t *key, gsize keylen,
gsize masklen,
uintptr_t value);
@@ -50,7 +50,7 @@ radix_insert_compressed(radix_compressed_t *tree,
* @param keylen length of a key
* @return opaque pointer or `RADIX_NO_VALUE` if no value has been found
*/
-uintptr_t radix_find_compressed(radix_compressed_t *tree, const guint8 *key,
+uintptr_t radix_find_compressed(radix_compressed_t *tree, const uint8_t *key,
gsize keylen);
/**
@@ -72,9 +72,9 @@ void radix_destroy_compressed(radix_compressed_t *tree);
* Create new radix trie
* @return
*/
-radix_compressed_t *radix_create_compressed(const gchar *tree_name);
+radix_compressed_t *radix_create_compressed(const char *tree_name);
-radix_compressed_t *radix_create_compressed_with_pool(rspamd_mempool_t *pool, const gchar *tree_name);
+radix_compressed_t *radix_create_compressed_with_pool(rspamd_mempool_t *pool, const char *tree_name);
/**
* Insert list of ip addresses and masks to the radix tree
@@ -83,19 +83,19 @@ radix_compressed_t *radix_create_compressed_with_pool(rspamd_mempool_t *pool, co
* @param tree target tree
* @return number of elements inserted
*/
-gint rspamd_radix_add_iplist(const gchar *list, const gchar *separators,
- radix_compressed_t *tree, gconstpointer value,
- gboolean resolve, const gchar *tree_name);
+int rspamd_radix_add_iplist(const char *list, const char *separators,
+ radix_compressed_t *tree, gconstpointer value,
+ gboolean resolve, const char *tree_name);
/**
* Generic version of @see rspamd_radix_add_iplist. This function creates tree
* if `tree` is NULL.
*/
gboolean
-radix_add_generic_iplist(const gchar *ip_list,
+radix_add_generic_iplist(const char *ip_list,
radix_compressed_t **tree,
gboolean resolve,
- const gchar *tree_name);
+ const char *tree_name);
/**
* Returns number of elements in the tree
@@ -109,7 +109,7 @@ gsize radix_get_size(radix_compressed_t *tree);
* @param tree
* @return constant string
*/
-const gchar *radix_get_info(radix_compressed_t *tree);
+const char *radix_get_info(radix_compressed_t *tree);
/**
* Returns memory pool associated with the radix tree
diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c
index 63ce73f5f..b97e66a03 100644
--- a/src/libutil/regexp.c
+++ b/src/libutil/regexp.c
@@ -45,13 +45,13 @@
#define PCRE_FLAG(x) G_PASTE(PCRE2_, x)
#endif
-typedef guchar regexp_id_t[rspamd_cryptobox_HASHBYTES];
+typedef unsigned char regexp_id_t[rspamd_cryptobox_HASHBYTES];
#undef DISABLE_JIT_FAST
struct rspamd_regexp_s {
- gdouble exec_time;
- gchar *pattern;
+ double exec_time;
+ char *pattern;
PCRE_T *re;
PCRE_T *raw_re;
#ifndef WITH_PCRE2
@@ -67,10 +67,10 @@ struct rspamd_regexp_s {
gpointer re_class;
uint64_t cache_id;
gsize match_limit;
- guint max_hits;
- gint flags;
- gint pcre_flags;
- gint ncaptures;
+ unsigned int max_hits;
+ int flags;
+ int pcre_flags;
+ int ncaptures;
};
struct rspamd_regexp_cache {
@@ -96,7 +96,7 @@ rspamd_regexp_quark(void)
}
static void
-rspamd_regexp_generate_id(const gchar *pattern, const gchar *flags,
+rspamd_regexp_generate_id(const char *pattern, const char *flags,
regexp_id_t out)
{
rspamd_cryptobox_hash_state_t st;
@@ -164,7 +164,7 @@ rspamd_regexp_post_process(rspamd_regexp_t *r)
rspamd_regexp_library_init(NULL);
}
#if defined(WITH_PCRE2)
- static const guint max_recursion_depth = 100000, max_backtrack = 1000000;
+ static const unsigned int max_recursion_depth = 100000, max_backtrack = 1000000;
/* Create match context */
r->mcontext = pcre2_match_context_create(NULL);
@@ -186,7 +186,7 @@ rspamd_regexp_post_process(rspamd_regexp_t *r)
}
#ifdef HAVE_PCRE_JIT
- guint jit_flags = can_jit ? PCRE2_JIT_COMPLETE : 0;
+ unsigned int jit_flags = can_jit ? PCRE2_JIT_COMPLETE : 0;
gsize jsz;
PCRE2_UCHAR errstr[128];
int errcode;
@@ -231,9 +231,9 @@ rspamd_regexp_post_process(rspamd_regexp_t *r)
#endif
#else
- const gchar *err_str = "unknown";
+ const char *err_str = "unknown";
gboolean try_jit = TRUE, try_raw_jit = TRUE;
- gint study_flags = 0;
+ int study_flags = 0;
#if defined(HAVE_PCRE_JIT)
study_flags |= PCRE_STUDY_JIT_COMPILE;
@@ -270,7 +270,7 @@ rspamd_regexp_post_process(rspamd_regexp_t *r)
/* JIT path */
if (try_jit) {
#ifdef HAVE_PCRE_JIT
- gint jit, n;
+ int jit, n;
if (can_jit) {
jit = 0;
@@ -295,7 +295,7 @@ rspamd_regexp_post_process(rspamd_regexp_t *r)
if (try_raw_jit) {
#ifdef HAVE_PCRE_JIT
- gint jit, n;
+ int jit, n;
if (can_jit) {
@@ -320,21 +320,21 @@ rspamd_regexp_post_process(rspamd_regexp_t *r)
}
rspamd_regexp_t *
-rspamd_regexp_new_len(const gchar *pattern, gsize len, const gchar *flags,
+rspamd_regexp_new_len(const char *pattern, gsize len, const char *flags,
GError **err)
{
- const gchar *start = pattern, *end = start + len, *flags_str = NULL, *flags_end = NULL;
- gchar *err_str;
+ const char *start = pattern, *end = start + len, *flags_str = NULL, *flags_end = NULL;
+ char *err_str;
rspamd_regexp_t *res;
gboolean explicit_utf = FALSE;
PCRE_T *r;
- gchar sep = 0, *real_pattern;
+ char sep = 0, *real_pattern;
#ifndef WITH_PCRE2
- gint err_off;
+ int err_off;
#else
gsize err_off;
#endif
- gint regexp_flags = 0, rspamd_flags = 0, err_code, ncaptures;
+ int regexp_flags = 0, rspamd_flags = 0, err_code, ncaptures;
gboolean strict_flags = FALSE;
rspamd_regexp_library_init(NULL);
@@ -367,7 +367,7 @@ rspamd_regexp_new_len(const gchar *pattern, gsize len, const gchar *flags,
rspamd_flags &= ~RSPAMD_REGEXP_FLAG_FULL_MATCH;
}
else {
- gchar *last_sep = rspamd_memrchr(pattern, sep, len);
+ char *last_sep = rspamd_memrchr(pattern, sep, len);
if (last_sep == NULL || last_sep <= start) {
g_set_error(err, rspamd_regexp_quark(), EINVAL,
@@ -480,7 +480,7 @@ fin:
if (r == NULL) {
g_set_error(err, rspamd_regexp_quark(), EINVAL,
"regexp parsing error: '%s' at position %d; pattern: %s",
- err_str, (gint) err_off, real_pattern);
+ err_str, (int) err_off, real_pattern);
g_free(real_pattern);
return NULL;
@@ -516,7 +516,7 @@ fin:
#endif
if (res->raw_re == NULL) {
msg_warn("raw regexp parsing error: '%s': '%s' at position %d",
- err_str, real_pattern, (gint) err_off);
+ err_str, real_pattern, (int) err_off);
}
}
@@ -541,7 +541,7 @@ fin:
}
rspamd_regexp_t *
-rspamd_regexp_new(const gchar *pattern, const gchar *flags,
+rspamd_regexp_new(const char *pattern, const char *flags,
GError **err)
{
return rspamd_regexp_new_len(pattern, strlen(pattern), flags, err);
@@ -549,8 +549,8 @@ rspamd_regexp_new(const gchar *pattern, const gchar *flags,
#ifndef WITH_PCRE2
gboolean
-rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
- const gchar **start, const gchar **end, gboolean raw,
+rspamd_regexp_search(const rspamd_regexp_t *re, const char *text, gsize len,
+ const char **start, const char **end, gboolean raw,
GArray *captures)
{
pcre *r;
@@ -558,9 +558,9 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
#if defined(HAVE_PCRE_JIT) && defined(HAVE_PCRE_JIT_FAST) && !defined(DISABLE_JIT_FAST)
pcre_jit_stack *st = NULL;
#endif
- const gchar *mt;
+ const char *mt;
gsize remain = 0;
- gint rc, match_flags = 0, *ovec, ncaptures, i;
+ int rc, match_flags = 0, *ovec, ncaptures, i;
const int junk = 0xdeadbabe;
g_assert(re != NULL);
@@ -578,7 +578,7 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
/* Incremental search */
mt = (*end);
- if ((gint) len > (mt - text)) {
+ if ((int) len > (mt - text)) {
remain = len - (mt - text);
}
}
@@ -620,7 +620,7 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
}
ncaptures = (re->ncaptures + 1) * 3;
- ovec = g_alloca(sizeof(gint) * ncaptures);
+ ovec = g_alloca(sizeof(int) * ncaptures);
for (i = 0; i < ncaptures; i++) {
@@ -697,7 +697,7 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
if (re->flags & RSPAMD_REGEXP_FLAG_FULL_MATCH) {
/* We also ensure that the match is full */
- if (ovec[0] != 0 || (guint) ovec[1] < len) {
+ if (ovec[0] != 0 || (unsigned int) ovec[1] < len) {
return FALSE;
}
}
@@ -710,17 +710,17 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
#else
/* PCRE 2 version */
gboolean
-rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
- const gchar **start, const gchar **end, gboolean raw,
+rspamd_regexp_search(const rspamd_regexp_t *re, const char *text, gsize len,
+ const char **start, const char **end, gboolean raw,
GArray *captures)
{
pcre2_match_data *match_data;
pcre2_match_context *mcontext;
PCRE_T *r;
- const gchar *mt;
+ const char *mt;
PCRE2_SIZE remain = 0, *ovec;
const PCRE2_SIZE junk = 0xdeadbabeeeeeeeeULL;
- gint rc, match_flags, novec, i;
+ int rc, match_flags, novec, i;
gboolean ret = FALSE;
g_assert(re != NULL);
@@ -738,7 +738,7 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
/* Incremental search */
mt = (*end);
- if ((gint) len > (mt - text)) {
+ if ((int) len > (mt - text)) {
remain = len - (mt - text);
}
}
@@ -838,7 +838,7 @@ rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
if (re->flags & RSPAMD_REGEXP_FLAG_FULL_MATCH) {
/* We also ensure that the match is full */
- if (ovec[0] != 0 || (guint) ovec[1] < len) {
+ if (ovec[0] != 0 || (unsigned int) ovec[1] < len) {
ret = FALSE;
}
}
@@ -858,9 +858,9 @@ rspamd_regexp_get_pattern(const rspamd_regexp_t *re)
return re->pattern;
}
-guint rspamd_regexp_set_flags(rspamd_regexp_t *re, guint new_flags)
+unsigned int rspamd_regexp_set_flags(rspamd_regexp_t *re, unsigned int new_flags)
{
- guint old_flags;
+ unsigned int old_flags;
g_assert(re != NULL);
old_flags = re->flags;
@@ -869,30 +869,30 @@ guint rspamd_regexp_set_flags(rspamd_regexp_t *re, guint new_flags)
return old_flags;
}
-guint rspamd_regexp_get_flags(const rspamd_regexp_t *re)
+unsigned int rspamd_regexp_get_flags(const rspamd_regexp_t *re)
{
g_assert(re != NULL);
return re->flags;
}
-guint rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re)
+unsigned int rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re)
{
g_assert(re != NULL);
return re->pcre_flags;
}
-guint rspamd_regexp_get_maxhits(const rspamd_regexp_t *re)
+unsigned int rspamd_regexp_get_maxhits(const rspamd_regexp_t *re)
{
g_assert(re != NULL);
return re->max_hits;
}
-guint rspamd_regexp_set_maxhits(rspamd_regexp_t *re, guint new_maxhits)
+unsigned int rspamd_regexp_set_maxhits(rspamd_regexp_t *re, unsigned int new_maxhits)
{
- guint old_hits;
+ unsigned int old_hits;
g_assert(re != NULL);
old_hits = re->max_hits;
@@ -940,10 +940,10 @@ gsize rspamd_regexp_set_match_limit(rspamd_regexp_t *re, gsize lim)
}
gboolean
-rspamd_regexp_match(const rspamd_regexp_t *re, const gchar *text, gsize len,
+rspamd_regexp_match(const rspamd_regexp_t *re, const char *text, gsize len,
gboolean raw)
{
- const gchar *start = NULL, *end = NULL;
+ const char *start = NULL, *end = NULL;
g_assert(re != NULL);
g_assert(text != NULL);
@@ -994,7 +994,7 @@ rspamd_regexp_get_ud(const rspamd_regexp_t *re)
gboolean
rspamd_regexp_equal(gconstpointer a, gconstpointer b)
{
- const guchar *ia = a, *ib = b;
+ const unsigned char *ia = a, *ib = b;
return (memcmp(ia, ib, sizeof(regexp_id_t)) == 0);
}
@@ -1002,7 +1002,7 @@ rspamd_regexp_equal(gconstpointer a, gconstpointer b)
uint32_t
rspamd_regexp_hash(gconstpointer a)
{
- const guchar *ia = a;
+ const unsigned char *ia = a;
uint32_t res;
memcpy(&res, ia, sizeof(res));
@@ -1013,7 +1013,7 @@ rspamd_regexp_hash(gconstpointer a)
gboolean
rspamd_regexp_cmp(gconstpointer a, gconstpointer b)
{
- const guchar *ia = a, *ib = b;
+ const unsigned char *ia = a, *ib = b;
return memcmp(ia, ib, sizeof(regexp_id_t));
}
@@ -1039,8 +1039,8 @@ rspamd_regexp_cache_new(void)
rspamd_regexp_t *
rspamd_regexp_cache_query(struct rspamd_regexp_cache *cache,
- const gchar *pattern,
- const gchar *flags)
+ const char *pattern,
+ const char *flags)
{
rspamd_regexp_t *res = NULL;
regexp_id_t id;
@@ -1061,8 +1061,8 @@ rspamd_regexp_cache_query(struct rspamd_regexp_cache *cache,
rspamd_regexp_t *
rspamd_regexp_cache_create(struct rspamd_regexp_cache *cache,
- const gchar *pattern,
- const gchar *flags, GError **err)
+ const char *pattern,
+ const char *flags, GError **err)
{
rspamd_regexp_t *res;
@@ -1160,8 +1160,8 @@ void rspamd_regexp_library_init(struct rspamd_config *cfg)
if (check_jit) {
#ifdef HAVE_PCRE_JIT
- gint jit, rc;
- gchar *str;
+ int jit, rc;
+ char *str;
#ifndef WITH_PCRE2
rc = pcre_config(PCRE_CONFIG_JIT, &jit);
@@ -1243,13 +1243,13 @@ rspamd_regexp_set_class(rspamd_regexp_t *re, gpointer re_class)
}
rspamd_regexp_t *
-rspamd_regexp_from_glob(const gchar *gl, gsize sz, GError **err)
+rspamd_regexp_from_glob(const char *gl, gsize sz, GError **err)
{
GString *out;
rspamd_regexp_t *re;
- const gchar *end;
+ const char *end;
gboolean escaping = FALSE;
- gint nbraces = 0;
+ int nbraces = 0;
g_assert(gl != NULL);
diff --git a/src/libutil/regexp.h b/src/libutil/regexp.h
index 5be9046be..44881512b 100644
--- a/src/libutil/regexp.h
+++ b/src/libutil/regexp.h
@@ -57,7 +57,7 @@ struct rspamd_re_capture {
* @param err error pointer set if compilation failed
* @return new regexp object
*/
-rspamd_regexp_t *rspamd_regexp_new(const gchar *pattern, const gchar *flags,
+rspamd_regexp_t *rspamd_regexp_new(const char *pattern, const char *flags,
GError **err);
/**
@@ -67,7 +67,7 @@ rspamd_regexp_t *rspamd_regexp_new(const gchar *pattern, const gchar *flags,
* @param err error pointer set if compilation failed
* @return new regexp object
*/
-rspamd_regexp_t *rspamd_regexp_new_len(const gchar *pattern, gsize len, const gchar *flags,
+rspamd_regexp_t *rspamd_regexp_new_len(const char *pattern, gsize len, const char *flags,
GError **err);
/**
@@ -82,8 +82,8 @@ rspamd_regexp_t *rspamd_regexp_new_len(const gchar *pattern, gsize len, const gc
* @return
*/
gboolean rspamd_regexp_search(const rspamd_regexp_t *re,
- const gchar *text, gsize len,
- const gchar **start, const gchar **end, gboolean raw,
+ const char *text, gsize len,
+ const char **start, const char **end, gboolean raw,
GArray *captures);
@@ -95,7 +95,7 @@ gboolean rspamd_regexp_search(const rspamd_regexp_t *re,
* @return
*/
gboolean rspamd_regexp_match(const rspamd_regexp_t *re,
- const gchar *text, gsize len, gboolean raw);
+ const char *text, gsize len, gboolean raw);
/**
* Increase refcount for a regexp object
@@ -139,27 +139,27 @@ const char *rspamd_regexp_get_pattern(const rspamd_regexp_t *re);
/**
* Get PCRE flags for the regexp
*/
-guint rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re);
+unsigned int rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re);
/**
* Get rspamd flags for the regexp
*/
-guint rspamd_regexp_get_flags(const rspamd_regexp_t *re);
+unsigned int rspamd_regexp_get_flags(const rspamd_regexp_t *re);
/**
* Set rspamd flags for the regexp
*/
-guint rspamd_regexp_set_flags(rspamd_regexp_t *re, guint new_flags);
+unsigned int rspamd_regexp_set_flags(rspamd_regexp_t *re, unsigned int new_flags);
/**
* Set regexp maximum hits
*/
-guint rspamd_regexp_get_maxhits(const rspamd_regexp_t *re);
+unsigned int rspamd_regexp_get_maxhits(const rspamd_regexp_t *re);
/**
* Get regexp maximum hits
*/
-guint rspamd_regexp_set_maxhits(rspamd_regexp_t *re, guint new_maxhits);
+unsigned int rspamd_regexp_set_maxhits(rspamd_regexp_t *re, unsigned int new_maxhits);
/**
* Returns cache id for a regexp
@@ -206,8 +206,8 @@ struct rspamd_regexp_cache *rspamd_regexp_cache_new(void);
* @return
*/
rspamd_regexp_t *rspamd_regexp_cache_query(struct rspamd_regexp_cache *cache,
- const gchar *pattern,
- const gchar *flags);
+ const char *pattern,
+ const char *flags);
/**
* Create or get cached regexp from the specified cache
@@ -218,8 +218,8 @@ rspamd_regexp_t *rspamd_regexp_cache_query(struct rspamd_regexp_cache *cache,
* @return new regexp object
*/
rspamd_regexp_t *rspamd_regexp_cache_create(struct rspamd_regexp_cache *cache,
- const gchar *pattern,
- const gchar *flags, GError **err);
+ const char *pattern,
+ const char *flags, GError **err);
/**
* Remove regexp from the cache
@@ -254,7 +254,7 @@ gboolean rspamd_regexp_equal(gconstpointer a, gconstpointer b);
/**
* Acts like memcmp but for regexp
*/
-gint rspamd_regexp_cmp(gconstpointer a, gconstpointer b);
+int rspamd_regexp_cmp(gconstpointer a, gconstpointer b);
/**
* Initialize superglobal regexp cache and library
@@ -267,7 +267,7 @@ void rspamd_regexp_library_init(struct rspamd_config *cfg);
* @param err
* @return
*/
-rspamd_regexp_t *rspamd_regexp_from_glob(const gchar *gl, gsize sz, GError **err);
+rspamd_regexp_t *rspamd_regexp_from_glob(const char *gl, gsize sz, GError **err);
#ifdef __cplusplus
}
diff --git a/src/libutil/rrd.c b/src/libutil/rrd.c
index 451e22202..9f128ff95 100644
--- a/src/libutil/rrd.c
+++ b/src/libutil/rrd.c
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -55,7 +55,7 @@ rrd_error_quark(void)
* Convert rrd dst type from string to numeric value
*/
enum rrd_dst_type
-rrd_dst_from_string(const gchar *str)
+rrd_dst_from_string(const char *str)
{
if (g_ascii_strcasecmp(str, "counter") == 0) {
return RRD_DST_COUNTER;
@@ -79,7 +79,7 @@ rrd_dst_from_string(const gchar *str)
/**
* Convert numeric presentation of dst to string
*/
-const gchar *
+const char *
rrd_dst_to_string(enum rrd_dst_type type)
{
switch (type) {
@@ -104,7 +104,7 @@ rrd_dst_to_string(enum rrd_dst_type type)
* Convert rrd consolidation function type from string to numeric value
*/
enum rrd_cf_type
-rrd_cf_from_string(const gchar *str)
+rrd_cf_from_string(const char *str)
{
if (g_ascii_strcasecmp(str, "average") == 0) {
return RRD_CF_AVERAGE;
@@ -126,7 +126,7 @@ rrd_cf_from_string(const gchar *str)
/**
* Convert numeric presentation of cf to string
*/
-const gchar *
+const char *
rrd_cf_to_string(enum rrd_cf_type type)
{
switch (type) {
@@ -147,7 +147,7 @@ rrd_cf_to_string(enum rrd_cf_type type)
return "U";
}
-void rrd_make_default_rra(const gchar *cf_name,
+void rrd_make_default_rra(const char *cf_name,
gulong pdp_cnt,
gulong rows,
struct rrd_rra_def *rra)
@@ -162,8 +162,8 @@ void rrd_make_default_rra(const gchar *cf_name,
rra->par[RRA_cdp_xff_val].dv = 0.5;
}
-void rrd_make_default_ds(const gchar *name,
- const gchar *type,
+void rrd_make_default_ds(const char *name,
+ const char *type,
gulong pdp_step,
struct rrd_ds_def *ds)
{
@@ -183,13 +183,13 @@ void rrd_make_default_ds(const gchar *name,
* Check rrd file for correctness (size, cookies, etc)
*/
static gboolean
-rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err)
+rspamd_rrd_check_file(const char *filename, gboolean need_data, GError **err)
{
- gint fd, i;
+ int fd, i;
struct stat st;
struct rrd_file_head head;
struct rrd_rra_def rra;
- gint head_size;
+ int head_size;
fd = open(filename, O_RDWR);
if (fd == -1) {
@@ -207,7 +207,7 @@ rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err)
if (st.st_size < (goffset) sizeof(struct rrd_file_head)) {
/* We have trimmed file */
g_set_error(err, rrd_error_quark(), EINVAL, "rrd size is bad: %ud",
- (guint) st.st_size);
+ (unsigned int) st.st_size);
close(fd);
return FALSE;
}
@@ -268,7 +268,7 @@ rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err)
close(fd);
return FALSE;
}
- for (i = 0; i < (gint) head.rra_cnt; i++) {
+ for (i = 0; i < (int) head.rra_cnt; i++) {
if (read(fd, &rra, sizeof(rra)) != sizeof(rra)) {
g_set_error(err,
rrd_error_quark(), errno, "rrd read rra error: %s",
@@ -276,13 +276,13 @@ rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err)
close(fd);
return FALSE;
}
- head_size += rra.row_cnt * head.ds_cnt * sizeof(gdouble);
+ head_size += rra.row_cnt * head.ds_cnt * sizeof(double);
}
if (st.st_size != head_size) {
g_set_error(err,
rrd_error_quark(), EINVAL, "rrd file seems to have incorrect size: %d, must be %d",
- (gint) st.st_size, head_size);
+ (int) st.st_size, head_size);
close(fd);
return FALSE;
}
@@ -299,7 +299,7 @@ rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err)
static void
rspamd_rrd_adjust_pointers(struct rspamd_rrd_file *file, gboolean completed)
{
- guint8 *ptr;
+ uint8_t *ptr;
ptr = file->map;
file->stat_head = (struct rrd_file_head *) ptr;
@@ -318,7 +318,7 @@ rspamd_rrd_adjust_pointers(struct rspamd_rrd_file *file, gboolean completed)
file->rra_ptr = (struct rrd_rra_ptr *) ptr;
if (completed) {
ptr += sizeof(struct rrd_rra_ptr) * file->stat_head->rra_cnt;
- file->rrd_value = (gdouble *) ptr;
+ file->rrd_value = (double *) ptr;
}
else {
file->rrd_value = NULL;
@@ -328,9 +328,9 @@ rspamd_rrd_adjust_pointers(struct rspamd_rrd_file *file, gboolean completed)
static void
rspamd_rrd_calculate_checksum(struct rspamd_rrd_file *file)
{
- guchar sigbuf[rspamd_cryptobox_HASHBYTES];
+ unsigned char sigbuf[rspamd_cryptobox_HASHBYTES];
struct rrd_ds_def *ds;
- guint i;
+ unsigned int i;
rspamd_cryptobox_hash_state_t st;
if (file->finalized) {
@@ -349,12 +349,12 @@ rspamd_rrd_calculate_checksum(struct rspamd_rrd_file *file)
}
static int
-rspamd_rrd_open_exclusive(const gchar *filename)
+rspamd_rrd_open_exclusive(const char *filename)
{
struct timespec sleep_ts = {
.tv_sec = 0,
.tv_nsec = 1000000};
- gint fd;
+ int fd;
fd = open(filename, O_RDWR);
@@ -389,10 +389,10 @@ rspamd_rrd_open_exclusive(const gchar *filename)
* @return
*/
static struct rspamd_rrd_file *
-rspamd_rrd_open_common(const gchar *filename, gboolean completed, GError **err)
+rspamd_rrd_open_common(const char *filename, gboolean completed, GError **err)
{
struct rspamd_rrd_file *file;
- gint fd;
+ int fd;
struct stat st;
if (!rspamd_rrd_check_file(filename, completed, err)) {
@@ -453,7 +453,7 @@ rspamd_rrd_open_common(const gchar *filename, gboolean completed, GError **err)
* @return rrd file structure
*/
struct rspamd_rrd_file *
-rspamd_rrd_open(const gchar *filename, GError **err)
+rspamd_rrd_open(const char *filename, GError **err)
{
struct rspamd_rrd_file *file;
@@ -474,11 +474,11 @@ rspamd_rrd_open(const gchar *filename, GError **err)
* @return TRUE if file has been created
*/
struct rspamd_rrd_file *
-rspamd_rrd_create(const gchar *filename,
+rspamd_rrd_create(const char *filename,
gulong ds_count,
gulong rra_count,
gulong pdp_step,
- gdouble initial_ticks,
+ double initial_ticks,
GError **err)
{
struct rspamd_rrd_file *new;
@@ -489,8 +489,8 @@ rspamd_rrd_create(const gchar *filename,
struct rrd_pdp_prep pdp;
struct rrd_cdp_prep cdp;
struct rrd_rra_ptr rra_ptr;
- gint fd;
- guint i, j;
+ int fd;
+ unsigned int i, j;
/* Open file */
fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0644);
@@ -680,10 +680,10 @@ rspamd_rrd_add_rra(struct rspamd_rrd_file *file, GArray *rra, GError **err)
gboolean
rspamd_rrd_finalize(struct rspamd_rrd_file *file, GError **err)
{
- gint fd;
- guint i;
- gint count = 0;
- gdouble vbuf[1024];
+ int fd;
+ unsigned int i;
+ int count = 0;
+ double vbuf[1024];
struct stat st;
if (file == NULL || file->filename == NULL || file->fd == -1) {
@@ -720,7 +720,7 @@ rspamd_rrd_finalize(struct rspamd_rrd_file *file, GError **err)
while (count > 0) {
/* Write values in buffered matter */
if (write(fd, vbuf,
- MIN((gint) G_N_ELEMENTS(vbuf), count) * sizeof(gdouble)) == -1) {
+ MIN((int) G_N_ELEMENTS(vbuf), count) * sizeof(double)) == -1) {
g_set_error(err,
rrd_error_quark(), errno, "rrd write error: %s",
strerror(errno));
@@ -769,11 +769,11 @@ rspamd_rrd_finalize(struct rspamd_rrd_file *file, GError **err)
*/
static gboolean
rspamd_rrd_update_pdp_prep(struct rspamd_rrd_file *file,
- gdouble *vals,
- gdouble *pdp_new,
- gdouble interval)
+ double *vals,
+ double *pdp_new,
+ double interval)
{
- guint i;
+ unsigned int i;
enum rrd_dst_type type;
for (i = 0; i < file->stat_head->ds_cnt; i++) {
@@ -840,12 +840,12 @@ rspamd_rrd_update_pdp_prep(struct rspamd_rrd_file *file,
*/
static void
rspamd_rrd_update_pdp_step(struct rspamd_rrd_file *file,
- gdouble *pdp_new,
- gdouble *pdp_temp,
- gdouble interval,
+ double *pdp_new,
+ double *pdp_temp,
+ double interval,
gulong pdp_diff)
{
- guint i;
+ unsigned int i;
rrd_value_t *scratch;
gulong heartbeat;
@@ -896,17 +896,17 @@ rspamd_rrd_update_pdp_step(struct rspamd_rrd_file *file,
*/
static void
rspamd_rrd_update_cdp(struct rspamd_rrd_file *file,
- gdouble pdp_steps,
- gdouble pdp_offset,
+ double pdp_steps,
+ double pdp_offset,
gulong *rra_steps,
gulong rra_index,
- gdouble *pdp_temp)
+ double *pdp_temp)
{
- guint i;
+ unsigned int i;
struct rrd_rra_def *rra;
rrd_value_t *scratch;
enum rrd_cf_type cf;
- gdouble last_cdp = INFINITY, cur_cdp = INFINITY;
+ double last_cdp = INFINITY, cur_cdp = INFINITY;
gulong pdp_in_cdp;
rra = &file->rra_def[rra_index];
@@ -1064,10 +1064,10 @@ rspamd_rrd_update_cdp(struct rspamd_rrd_file *file,
*/
void rspamd_rrd_write_rra(struct rspamd_rrd_file *file, gulong *rra_steps)
{
- guint i, j, ds_cnt;
+ unsigned int i, j, ds_cnt;
struct rrd_rra_def *rra;
struct rrd_cdp_prep *cdp;
- gdouble *rra_row = file->rrd_value, *cur_row;
+ double *rra_row = file->rrd_value, *cur_row;
ds_cnt = file->stat_head->ds_cnt;
@@ -1105,16 +1105,16 @@ void rspamd_rrd_write_rra(struct rspamd_rrd_file *file, gulong *rra_steps)
gboolean
rspamd_rrd_add_record(struct rspamd_rrd_file *file,
GArray *points,
- gdouble ticks,
+ double ticks,
GError **err)
{
- gdouble interval, *pdp_new, *pdp_temp;
- guint i;
+ double interval, *pdp_new, *pdp_temp;
+ unsigned int i;
glong seconds, microseconds;
gulong pdp_steps, cur_pdp_count, prev_pdp_step, cur_pdp_step,
prev_pdp_age, cur_pdp_age, *rra_steps, pdp_offset;
- if (file == NULL || file->stat_head->ds_cnt * sizeof(gdouble) !=
+ if (file == NULL || file->stat_head->ds_cnt * sizeof(double) !=
points->len) {
g_set_error(err,
rrd_error_quark(), EINVAL,
@@ -1125,18 +1125,18 @@ rspamd_rrd_add_record(struct rspamd_rrd_file *file,
/* Get interval */
seconds = (glong) ticks;
microseconds = (glong) ((ticks - seconds) * 1000000.);
- interval = ticks - ((gdouble) file->live_head->last_up +
+ interval = ticks - ((double) file->live_head->last_up +
file->live_head->last_up_usec / 1000000.);
msg_debug_rrd("update rrd record after %.3f seconds", interval);
/* Update PDP preparation values */
- pdp_new = g_malloc0(sizeof(gdouble) * file->stat_head->ds_cnt);
- pdp_temp = g_malloc0(sizeof(gdouble) * file->stat_head->ds_cnt);
+ pdp_new = g_malloc0(sizeof(double) * file->stat_head->ds_cnt);
+ pdp_temp = g_malloc0(sizeof(double) * file->stat_head->ds_cnt);
/* How much steps need to be updated in each RRA */
rra_steps = g_malloc0(sizeof(gulong) * file->stat_head->rra_cnt);
- if (!rspamd_rrd_update_pdp_prep(file, (gdouble *) points->data, pdp_new,
+ if (!rspamd_rrd_update_pdp_prep(file, (double *) points->data, pdp_new,
interval)) {
g_set_error(err,
rrd_error_quark(), EINVAL,
@@ -1239,7 +1239,7 @@ rspamd_rrd_add_record(struct rspamd_rrd_file *file,
* @param file
* @return
*/
-gint rspamd_rrd_close(struct rspamd_rrd_file *file)
+int rspamd_rrd_close(struct rspamd_rrd_file *file)
{
if (file == NULL) {
errno = EINVAL;
@@ -1257,12 +1257,12 @@ gint rspamd_rrd_close(struct rspamd_rrd_file *file)
}
static struct rspamd_rrd_file *
-rspamd_rrd_create_file(const gchar *path, gboolean finalize, GError **err)
+rspamd_rrd_create_file(const char *path, gboolean finalize, GError **err)
{
struct rspamd_rrd_file *file;
struct rrd_ds_def ds[RSPAMD_RRD_DS_COUNT];
struct rrd_rra_def rra[RSPAMD_RRD_RRA_COUNT];
- gint i;
+ int i;
GArray ar;
/* Try to create new rrd file */
@@ -1281,7 +1281,7 @@ rspamd_rrd_create_file(const gchar *path, gboolean finalize, GError **err)
rrd_dst_to_string(RRD_DST_COUNTER), 1, &ds[i]);
}
- ar.data = (gchar *) ds;
+ ar.data = (char *) ds;
ar.len = sizeof(ds);
if (!rspamd_rrd_add_ds(file, &ar, err)) {
@@ -1301,7 +1301,7 @@ rspamd_rrd_create_file(const gchar *path, gboolean finalize, GError **err)
/* Once per hour for 1 year */
rrd_make_default_rra(rrd_cf_to_string(RRD_CF_AVERAGE),
60 * 60, 365 * 24, &rra[3]);
- ar.data = (gchar *) rra;
+ ar.data = (char *) rra;
ar.len = sizeof(rra);
if (!rspamd_rrd_add_rra(file, &ar, err)) {
@@ -1319,11 +1319,11 @@ rspamd_rrd_create_file(const gchar *path, gboolean finalize, GError **err)
static void
rspamd_rrd_convert_ds(struct rspamd_rrd_file *old,
- struct rspamd_rrd_file *cur, gint idx_old, gint idx_new)
+ struct rspamd_rrd_file *cur, int idx_old, int idx_new)
{
struct rrd_pdp_prep *pdp_prep_old, *pdp_prep_new;
struct rrd_cdp_prep *cdp_prep_old, *cdp_prep_new;
- gdouble *val_old, *val_new;
+ double *val_old, *val_new;
gulong rra_cnt, i, j, points_cnt, old_ds, new_ds;
rra_cnt = old->stat_head->rra_cnt;
@@ -1351,11 +1351,11 @@ rspamd_rrd_convert_ds(struct rspamd_rrd_file *old,
}
static struct rspamd_rrd_file *
-rspamd_rrd_convert(const gchar *path, struct rspamd_rrd_file *old,
+rspamd_rrd_convert(const char *path, struct rspamd_rrd_file *old,
GError **err)
{
struct rspamd_rrd_file *rrd;
- gchar tpath[PATH_MAX];
+ char tpath[PATH_MAX];
g_assert(old != NULL);
@@ -1403,7 +1403,7 @@ rspamd_rrd_convert(const gchar *path, struct rspamd_rrd_file *old,
}
struct rspamd_rrd_file *
-rspamd_rrd_file_default(const gchar *path,
+rspamd_rrd_file_default(const char *path,
GError **err)
{
struct rspamd_rrd_file *file, *nf;
@@ -1465,8 +1465,8 @@ rspamd_rrd_query(struct rspamd_rrd_file *file,
{
struct rspamd_rrd_query_result *res;
struct rrd_rra_def *rra;
- const gdouble *rra_offset = NULL;
- guint i;
+ const double *rra_offset = NULL;
+ unsigned int i;
g_assert(file != NULL);
@@ -1479,8 +1479,8 @@ rspamd_rrd_query(struct rspamd_rrd_file *file,
res = g_malloc0(sizeof(*res));
res->ds_count = file->stat_head->ds_cnt;
- res->last_update = (gdouble) file->live_head->last_up +
- ((gdouble) file->live_head->last_up_usec / 1e6f);
+ res->last_update = (double) file->live_head->last_up +
+ ((double) file->live_head->last_up_usec / 1e6f);
res->pdp_per_cdp = file->rra_def[rra_num].pdp_cnt;
res->rra_rows = file->rra_def[rra_num].row_cnt;
rra_offset = file->rrd_value;
diff --git a/src/libutil/rrd.h b/src/libutil/rrd.h
index 3d814771a..2379b7e09 100644
--- a/src/libutil/rrd.h
+++ b/src/libutil/rrd.h
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -37,9 +37,9 @@ typedef union {
struct rrd_file_head {
/* Data Base Identification Section ** */
- gchar cookie[4]; /* RRD */
- gchar version[5]; /* version of the format */
- gdouble float_cookie; /* is it the correct double representation ? */
+ char cookie[4]; /* RRD */
+ char version[5]; /* version of the format */
+ double float_cookie; /* is it the correct double representation ? */
/* Data Base Structure Definition **** */
gulong ds_cnt; /* how many different ds provide input to the rrd */
@@ -75,9 +75,9 @@ enum rrd_ds_param {
#define RRD_DST_SIZE 20
struct rrd_ds_def {
- gchar ds_nam[RRD_DS_NAM_SIZE]; /* Name of the data source (null terminated) */
- gchar dst[RRD_DST_SIZE]; /* Type of data source (null terminated) */
- rrd_value_t par[10]; /* index of this array see ds_param_en */
+ char ds_nam[RRD_DS_NAM_SIZE]; /* Name of the data source (null terminated) */
+ char dst[RRD_DST_SIZE]; /* Type of data source (null terminated) */
+ rrd_value_t par[10]; /* index of this array see ds_param_en */
};
/* RRA definition */
@@ -103,7 +103,7 @@ enum rrd_rra_param {
#define RRD_CF_NAM_SIZE 20
struct rrd_rra_def {
- gchar cf_nam[RRD_CF_NAM_SIZE]; /* consolidation function (null term) */
+ char cf_nam[RRD_CF_NAM_SIZE]; /* consolidation function (null term) */
gulong row_cnt; /* number of entries in the store */
gulong pdp_cnt; /* how many primary data points are
* required for a consolidated data point?*/
@@ -125,12 +125,12 @@ enum rrd_pdp_param {
this depends on dst */
struct rrd_pdp_prep {
- gchar last_ds[RRD_LAST_DS_LEN]; /* the last reading from the data
+ char last_ds[RRD_LAST_DS_LEN]; /* the last reading from the data
* source. this is stored in ASCII
* to cater for very large counters
* we might encounter in connection
* with SNMP. */
- rrd_value_t scratch[10]; /* contents according to pdp_par_en */
+ rrd_value_t scratch[10]; /* contents according to pdp_par_en */
};
#define RRD_MAX_CDP_PAR_EN 10
@@ -200,14 +200,14 @@ struct rspamd_rrd_file {
struct rrd_pdp_prep *pdp_prep; /* pdp data prep area */
struct rrd_cdp_prep *cdp_prep; /* cdp prep area */
struct rrd_rra_ptr *rra_ptr; /* list of rra pointers */
- gdouble *rrd_value; /* list of rrd values */
+ double *rrd_value; /* list of rrd values */
- gchar *filename;
- guint8 *map; /* mmapped area */
- gsize size; /* its size */
+ char *filename;
+ uint8_t *map; /* mmapped area */
+ gsize size; /* its size */
gboolean finalized;
- gchar *id;
- gint fd;
+ char *id;
+ int fd;
};
@@ -219,7 +219,7 @@ struct rspamd_rrd_file {
* @param err error pointer
* @return rrd file structure
*/
-struct rspamd_rrd_file *rspamd_rrd_open(const gchar *filename, GError **err);
+struct rspamd_rrd_file *rspamd_rrd_open(const char *filename, GError **err);
/**
* Create basic header for rrd file
@@ -230,11 +230,11 @@ struct rspamd_rrd_file *rspamd_rrd_open(const gchar *filename, GError **err);
* @param err error pointer
* @return TRUE if file has been created
*/
-struct rspamd_rrd_file *rspamd_rrd_create(const gchar *filename,
+struct rspamd_rrd_file *rspamd_rrd_create(const char *filename,
gulong ds_count,
gulong rra_count,
gulong pdp_step,
- gdouble initial_ticks,
+ double initial_ticks,
GError **err);
/**
@@ -276,7 +276,7 @@ gboolean rspamd_rrd_finalize(struct rspamd_rrd_file *file, GError **err);
*/
gboolean rspamd_rrd_add_record(struct rspamd_rrd_file *file,
GArray *points,
- gdouble ticks,
+ double ticks,
GError **err);
/**
@@ -284,7 +284,7 @@ gboolean rspamd_rrd_add_record(struct rspamd_rrd_file *file,
* @param file
* @return
*/
-gint rspamd_rrd_close(struct rspamd_rrd_file *file);
+int rspamd_rrd_close(struct rspamd_rrd_file *file);
/*
* Conversion functions
@@ -293,29 +293,29 @@ gint rspamd_rrd_close(struct rspamd_rrd_file *file);
/**
* Convert rrd dst type from string to numeric value
*/
-enum rrd_dst_type rrd_dst_from_string(const gchar *str);
+enum rrd_dst_type rrd_dst_from_string(const char *str);
/**
* Convert numeric presentation of dst to string
*/
-const gchar *rrd_dst_to_string(enum rrd_dst_type type);
+const char *rrd_dst_to_string(enum rrd_dst_type type);
/**
* Convert rrd consolidation function type from string to numeric value
*/
-enum rrd_cf_type rrd_cf_from_string(const gchar *str);
+enum rrd_cf_type rrd_cf_from_string(const char *str);
/**
* Convert numeric presentation of cf to string
*/
-const gchar *rrd_cf_to_string(enum rrd_cf_type type);
+const char *rrd_cf_to_string(enum rrd_cf_type type);
/* Default RRA and DS */
/**
* Create default RRA
*/
-void rrd_make_default_rra(const gchar *cf_name,
+void rrd_make_default_rra(const char *cf_name,
gulong pdp_cnt,
gulong rows,
struct rrd_rra_def *rra);
@@ -323,15 +323,15 @@ void rrd_make_default_rra(const gchar *cf_name,
/**
* Create default DS
*/
-void rrd_make_default_ds(const gchar *name,
- const gchar *type,
+void rrd_make_default_ds(const char *name,
+ const char *type,
gulong pdp_step,
struct rrd_ds_def *ds);
/**
* Open or create the default rspamd rrd file
*/
-struct rspamd_rrd_file *rspamd_rrd_file_default(const gchar *path,
+struct rspamd_rrd_file *rspamd_rrd_file_default(const char *path,
GError **err);
/**
@@ -341,9 +341,9 @@ struct rspamd_rrd_query_result {
gulong rra_rows;
gulong pdp_per_cdp;
gulong ds_count;
- gdouble last_update;
+ double last_update;
gulong cur_row;
- const gdouble *data;
+ const double *data;
};
/**
diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c
index f074c76ff..5fe110eb8 100644
--- a/src/libutil/shingles.c
+++ b/src/libutil/shingles.c
@@ -22,7 +22,7 @@
#define SHINGLES_WINDOW 3
#define SHINGLES_KEY_SIZE rspamd_cryptobox_SIPKEYBYTES
-static guint
+static unsigned int
rspamd_shingles_keys_hash(gconstpointer k)
{
return rspamd_cryptobox_fast_hash(k, SHINGLES_KEY_SIZE,
@@ -38,8 +38,8 @@ rspamd_shingles_keys_equal(gconstpointer k1, gconstpointer k2)
static void
rspamd_shingles_keys_free(gpointer p)
{
- guchar **k = p;
- guint i;
+ unsigned char **k = p;
+ unsigned int i;
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) {
g_free(k[i]);
@@ -48,30 +48,30 @@ rspamd_shingles_keys_free(gpointer p)
g_free(k);
}
-static guchar **
+static unsigned char **
rspamd_shingles_keys_new(void)
{
- guchar **k;
- guint i;
+ unsigned char **k;
+ unsigned int i;
- k = g_malloc0(sizeof(guchar *) * RSPAMD_SHINGLE_SIZE);
+ k = g_malloc0(sizeof(unsigned char *) * RSPAMD_SHINGLE_SIZE);
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) {
- k[i] = g_malloc0(sizeof(guchar) * SHINGLES_KEY_SIZE);
+ k[i] = g_malloc0(sizeof(unsigned char) * SHINGLES_KEY_SIZE);
}
return k;
}
-static guchar **
-rspamd_shingles_get_keys_cached(const guchar key[SHINGLES_KEY_SIZE])
+static unsigned char **
+rspamd_shingles_get_keys_cached(const unsigned char key[SHINGLES_KEY_SIZE])
{
static GHashTable *ht = NULL;
- guchar **keys = NULL, *key_cpy;
+ unsigned char **keys = NULL, *key_cpy;
rspamd_cryptobox_hash_state_t bs;
- const guchar *cur_key;
- guchar shabuf[rspamd_cryptobox_HASHBYTES], *out_key;
- guint i;
+ const unsigned char *cur_key;
+ unsigned char shabuf[rspamd_cryptobox_HASHBYTES], *out_key;
+ unsigned int i;
if (ht == NULL) {
ht = g_hash_table_new_full(rspamd_shingles_keys_hash,
@@ -113,7 +113,7 @@ rspamd_shingles_get_keys_cached(const guchar key[SHINGLES_KEY_SIZE])
struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
rspamd_shingles_from_text(GArray *input,
- const guchar key[16],
+ const unsigned char key[16],
rspamd_mempool_t *pool,
rspamd_shingles_filter filter,
gpointer filterd,
@@ -121,11 +121,11 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
{
struct rspamd_shingle *res;
uint64_t **hashes;
- guchar **keys;
+ unsigned char **keys;
rspamd_fstring_t *row;
rspamd_stat_token_t *word;
uint64_t val;
- gint i, j, k;
+ int i, j, k;
gsize hlen, ilen = 0, beg = 0, widx = 0;
enum rspamd_cryptobox_fast_hash_type ht;
@@ -157,8 +157,8 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
/* Now parse input words into a vector of hashes using rolling window */
if (alg == RSPAMD_SHINGLES_OLD) {
- for (i = 0; i <= (gint) ilen; i++) {
- if (i - beg >= SHINGLES_WINDOW || i == (gint) ilen) {
+ for (i = 0; i <= (int) ilen; i++) {
+ if (i - beg >= SHINGLES_WINDOW || i == (int) ilen) {
for (j = beg; j < i; j++) {
word = NULL;
@@ -196,7 +196,7 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
/* Now we need to create a new row here */
for (j = 0; j < RSPAMD_SHINGLE_SIZE; j++) {
- rspamd_cryptobox_siphash((guchar *) &val, row->str, row->len,
+ rspamd_cryptobox_siphash((unsigned char *) &val, row->str, row->len,
keys[j]);
g_assert(hlen > beg);
hashes[j][beg] = val;
@@ -301,8 +301,8 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
}
struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
- rspamd_shingles_from_image(guchar *dct,
- const guchar key[16],
+ rspamd_shingles_from_image(unsigned char *dct,
+ const unsigned char key[16],
rspamd_mempool_t *pool,
rspamd_shingles_filter filter,
gpointer filterd,
@@ -310,10 +310,10 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
{
struct rspamd_shingle *shingle;
uint64_t **hashes;
- guchar **keys;
+ unsigned char **keys;
uint64_t d;
uint64_t val;
- gint i, j;
+ int i, j;
gsize hlen, beg = 0;
enum rspamd_cryptobox_fast_hash_type ht;
uint64_t res[SHINGLES_WINDOW * RSPAMD_SHINGLE_SIZE], seed;
@@ -382,7 +382,7 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
uint64_t
rspamd_shingles_default_filter(uint64_t *input, gsize count,
- gint shno, const guchar *key, gpointer ud)
+ int shno, const unsigned char *key, gpointer ud)
{
uint64_t minimal = G_MAXUINT64;
gsize i;
@@ -397,10 +397,10 @@ rspamd_shingles_default_filter(uint64_t *input, gsize count,
}
-gdouble rspamd_shingles_compare(const struct rspamd_shingle *a,
- const struct rspamd_shingle *b)
+double rspamd_shingles_compare(const struct rspamd_shingle *a,
+ const struct rspamd_shingle *b)
{
- gint i, common = 0;
+ int i, common = 0;
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) {
if (a->hashes[i] == b->hashes[i]) {
@@ -408,5 +408,5 @@ gdouble rspamd_shingles_compare(const struct rspamd_shingle *a,
}
}
- return (gdouble) common / (gdouble) RSPAMD_SHINGLE_SIZE;
+ return (double) common / (double) RSPAMD_SHINGLE_SIZE;
}
diff --git a/src/libutil/shingles.h b/src/libutil/shingles.h
index d0da3fc04..fe6f16cf8 100644
--- a/src/libutil/shingles.h
+++ b/src/libutil/shingles.h
@@ -43,7 +43,7 @@ enum rspamd_shingle_alg {
* @return shingle value
*/
typedef uint64_t (*rspamd_shingles_filter)(uint64_t *input, gsize count,
- gint shno, const guchar *key, gpointer ud);
+ int shno, const unsigned char *key, gpointer ud);
/**
* Generate shingles from the input of fixed size strings using lemmatizer
@@ -56,7 +56,7 @@ typedef uint64_t (*rspamd_shingles_filter)(uint64_t *input, gsize count,
* @return shingles array
*/
struct rspamd_shingle *rspamd_shingles_from_text(GArray *input,
- const guchar key[16],
+ const unsigned char key[16],
rspamd_mempool_t *pool,
rspamd_shingles_filter filter,
gpointer filterd,
@@ -71,8 +71,8 @@ struct rspamd_shingle *rspamd_shingles_from_text(GArray *input,
* @param filterd opaque data for filtering function
* @return shingles array
*/
-struct rspamd_shingle *rspamd_shingles_from_image(guchar *dct,
- const guchar key[16],
+struct rspamd_shingle *rspamd_shingles_from_image(unsigned char *dct,
+ const unsigned char key[16],
rspamd_mempool_t *pool,
rspamd_shingles_filter filter,
gpointer filterd,
@@ -85,14 +85,14 @@ struct rspamd_shingle *rspamd_shingles_from_image(guchar *dct,
* @param b
* @return
*/
-gdouble rspamd_shingles_compare(const struct rspamd_shingle *a,
- const struct rspamd_shingle *b);
+double rspamd_shingles_compare(const struct rspamd_shingle *a,
+ const struct rspamd_shingle *b);
/**
* Default filtering function
*/
uint64_t rspamd_shingles_default_filter(uint64_t *input, gsize count,
- gint shno, const guchar *key, gpointer ud);
+ int shno, const unsigned char *key, gpointer ud);
#ifdef __cplusplus
}
diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c
index 0c9b4463f..88d420425 100644
--- a/src/libutil/sqlite_utils.c
+++ b/src/libutil/sqlite_utils.c
@@ -28,10 +28,10 @@ rspamd_sqlite3_quark(void)
GArray *
rspamd_sqlite3_init_prstmt(sqlite3 *db,
struct rspamd_sqlite3_prstmt *init_stmt,
- gint max_idx,
+ int max_idx,
GError **err)
{
- gint i;
+ int i;
GArray *res;
struct rspamd_sqlite3_prstmt *nst;
@@ -58,18 +58,18 @@ rspamd_sqlite3_init_prstmt(sqlite3 *db,
}
int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts,
- gint idx, ...)
+ int idx, ...)
{
- gint retcode;
+ int retcode;
va_list ap;
sqlite3_stmt *stmt;
- gint i, rowid, nargs, j;
+ int i, rowid, nargs, j;
int64_t len;
gpointer p;
struct rspamd_sqlite3_prstmt *nst;
const char *argtypes;
- if (idx < 0 || idx >= (gint) stmts->len) {
+ if (idx < 0 || idx >= (int) stmts->len) {
return -1;
}
@@ -119,13 +119,13 @@ int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts
case 'S':
for (j = 0; j < nargs; j++, rowid++) {
- sqlite3_bind_int(stmt, rowid, va_arg(ap, gint));
+ sqlite3_bind_int(stmt, rowid, va_arg(ap, int));
}
nargs = 1;
break;
case '*':
- nargs = va_arg(ap, gint);
+ nargs = va_arg(ap, int);
break;
}
}
@@ -186,7 +186,7 @@ int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts
void rspamd_sqlite3_close_prstmt(sqlite3 *db, GArray *stmts)
{
- guint i;
+ unsigned int i;
struct rspamd_sqlite3_prstmt *nst;
for (i = 0; i < stmts->len; i++) {
@@ -202,9 +202,9 @@ void rspamd_sqlite3_close_prstmt(sqlite3 *db, GArray *stmts)
}
static gboolean
-rspamd_sqlite3_wait(rspamd_mempool_t *pool, const gchar *lock)
+rspamd_sqlite3_wait(rspamd_mempool_t *pool, const char *lock)
{
- gint fd;
+ int fd;
pid_t pid;
gssize r;
struct timespec sleep_ts = {
@@ -278,11 +278,11 @@ rspamd_sqlite3_wait(rspamd_mempool_t *pool, const gchar *lock)
#define RSPAMD_SQLITE_CACHE_SIZE 262144
sqlite3 *
-rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, const gchar *path, const gchar *create_sql, guint version, GError **err)
+rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, const char *path, const char *create_sql, unsigned int version, GError **err)
{
sqlite3 *sqlite;
- gint rc, flags, lock_fd;
- gchar lock_path[PATH_MAX], dbdir[PATH_MAX], *pdir;
+ int rc, flags, lock_fd;
+ char lock_path[PATH_MAX], dbdir[PATH_MAX], *pdir;
static const char sqlite_wal[] =
"PRAGMA journal_mode=\"wal\";"
"PRAGMA wal_autocheckpoint = 16;"
@@ -587,9 +587,9 @@ rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, const gchar *path, const g
}
gboolean
-rspamd_sqlite3_sync(sqlite3 *db, gint *wal_frames, gint *wal_checkpoints)
+rspamd_sqlite3_sync(sqlite3 *db, int *wal_frames, int *wal_checkpoints)
{
- gint wf = 0, wc = 0, mode;
+ int wf = 0, wc = 0, mode;
#ifdef SQLITE_OPEN_WAL
#ifdef SQLITE_CHECKPOINT_TRUNCATE
diff --git a/src/libutil/sqlite_utils.h b/src/libutil/sqlite_utils.h
index 4bb8dea17..c17bf36f8 100644
--- a/src/libutil/sqlite_utils.h
+++ b/src/libutil/sqlite_utils.h
@@ -27,13 +27,13 @@ extern "C" {
#endif
struct rspamd_sqlite3_prstmt {
- gint idx;
- const gchar *sql;
- const gchar *args;
+ int idx;
+ const char *sql;
+ const char *args;
sqlite3_stmt *stmt;
- gint result;
- const gchar *ret;
- gint flags;
+ int result;
+ const char *ret;
+ int flags;
};
/**
@@ -45,7 +45,7 @@ struct rspamd_sqlite3_prstmt {
*/
GArray *rspamd_sqlite3_init_prstmt(sqlite3 *db,
struct rspamd_sqlite3_prstmt *init_stmt,
- gint max_idx,
+ int max_idx,
GError **err);
/**
@@ -56,8 +56,8 @@ GArray *rspamd_sqlite3_init_prstmt(sqlite3 *db,
* @param idx
* @return
*/
-gint rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts,
- gint idx, ...);
+int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts,
+ int idx, ...);
/**
* Close and free prepared statements
@@ -73,7 +73,7 @@ void rspamd_sqlite3_close_prstmt(sqlite3 *db, GArray *stmts);
* @return
*/
sqlite3 *rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool,
- const gchar *path, const gchar *create_sql,
+ const char *path, const char *create_sql,
uint32_t version, GError **err);
@@ -81,7 +81,7 @@ sqlite3 *rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool,
* Sync sqlite3 db ensuring that all wal things are done
* @param db
*/
-gboolean rspamd_sqlite3_sync(sqlite3 *db, gint *wal_frames, gint *wal_checkpoints);
+gboolean rspamd_sqlite3_sync(sqlite3 *db, int *wal_frames, int *wal_checkpoints);
#ifdef __cplusplus
}
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index 77fa20f54..eda3331fa 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -33,7 +33,7 @@
#include "contrib/fastutf8/fastutf8.h"
-const guchar lc_map[256] = {
+const unsigned char lc_map[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -67,13 +67,13 @@ const guchar lc_map[256] = {
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff};
-guint rspamd_str_lc(gchar *str, guint size)
+unsigned int rspamd_str_lc(char *str, unsigned int size)
{
- guint leftover = size % 4;
- guint fp, i;
+ unsigned int leftover = size % 4;
+ unsigned int fp, i;
const uint8_t *s = (const uint8_t *) str;
- gchar *dest = str;
- guchar c1, c2, c3, c4;
+ char *dest = str;
+ unsigned char c1, c2, c3, c4;
fp = size - leftover;
@@ -88,25 +88,25 @@ guint rspamd_str_lc(gchar *str, guint size)
switch (leftover) {
case 3:
- *dest++ = lc_map[(guchar) str[i++]];
+ *dest++ = lc_map[(unsigned char) str[i++]];
/* FALLTHRU */
case 2:
- *dest++ = lc_map[(guchar) str[i++]];
+ *dest++ = lc_map[(unsigned char) str[i++]];
/* FALLTHRU */
case 1:
- *dest = lc_map[(guchar) str[i]];
+ *dest = lc_map[(unsigned char) str[i]];
}
return size;
}
-gsize rspamd_str_copy_lc(const gchar *src, gchar *dst, gsize size)
+gsize rspamd_str_copy_lc(const char *src, char *dst, gsize size)
{
- gchar *d = dst;
+ char *d = dst;
/* Find aligned start */
while ((0xf & (uintptr_t) src) && size > 0) {
- *d++ = lc_map[(guchar) *src++];
+ *d++ = lc_map[(unsigned char) *src++];
size--;
}
@@ -130,23 +130,23 @@ gsize rspamd_str_copy_lc(const gchar *src, gchar *dst, gsize size)
/* Leftover */
while (size > 0) {
- *d++ = lc_map[(guchar) *src++];
+ *d++ = lc_map[(unsigned char) *src++];
size--;
}
return (d - dst);
}
-gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l)
+int rspamd_lc_cmp(const char *s, const char *d, gsize l)
{
gsize fp, i;
- guchar c1, c2, c3, c4;
+ unsigned char c1, c2, c3, c4;
union {
- guchar c[4];
+ unsigned char c[4];
uint32_t n;
} cmp1, cmp2;
gsize leftover = l % 4;
- gint ret = 0;
+ int ret = 0;
fp = l - leftover;
@@ -185,16 +185,16 @@ gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l)
* string to lower case, so some locale peculiarities are simply ignored
* If the target string is longer than initial one, then we just trim it
*/
-guint rspamd_str_lc_utf8(gchar *str, guint size)
+unsigned int rspamd_str_lc_utf8(char *str, unsigned int size)
{
- guchar *d = (guchar *) str, tst[6];
+ unsigned char *d = (unsigned char *) str, tst[6];
int32_t i = 0, prev = 0;
UChar32 uc;
while (i < size) {
prev = i;
- U8_NEXT((guint8 *) str, i, size, uc);
+ U8_NEXT((uint8_t *) str, i, size, uc);
uc = u_tolower(uc);
int32_t olen = 0;
@@ -210,13 +210,13 @@ guint rspamd_str_lc_utf8(gchar *str, guint size)
}
}
- return d - (guchar *) str;
+ return d - (unsigned char *) str;
}
gboolean
rspamd_strcase_equal(gconstpointer v, gconstpointer v2)
{
- if (g_ascii_strcasecmp((const gchar *) v, (const gchar *) v2) == 0) {
+ if (g_ascii_strcasecmp((const char *) v, (const char *) v2) == 0) {
return TRUE;
}
@@ -224,14 +224,14 @@ rspamd_strcase_equal(gconstpointer v, gconstpointer v2)
}
uint64_t
-rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed)
+rspamd_icase_hash(const char *in, gsize len, uint64_t seed)
{
- guint leftover = len % sizeof(uint64_t);
- guint fp, i;
+ unsigned int leftover = len % sizeof(uint64_t);
+ unsigned int fp, i;
const uint8_t *s = (const uint8_t *) in;
union {
struct {
- guchar c1, c2, c3, c4, c5, c6, c7, c8;
+ unsigned char c1, c2, c3, c4, c5, c6, c7, c8;
} c;
uint64_t pp;
} u;
@@ -257,19 +257,19 @@ rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed)
switch (leftover) {
case 7:
- u.c.c7 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c7 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 6:
- u.c.c6 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c6 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 5:
- u.c.c5 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c5 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 4:
- u.c.c4 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c4 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 3:
- u.c.c3 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c3 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 2:
- u.c.c2 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c2 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 1:
- u.c.c1 = lc_map[(guchar) s[i]];
+ u.c.c1 = lc_map[(unsigned char) s[i]];
break;
}
@@ -278,29 +278,29 @@ rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed)
return h;
}
-guint rspamd_strcase_hash(gconstpointer key)
+unsigned int rspamd_strcase_hash(gconstpointer key)
{
- const gchar *p = key;
+ const char *p = key;
gsize len;
len = strlen(p);
- return (guint) rspamd_icase_hash(p, len, rspamd_hash_seed());
+ return (unsigned int) rspamd_icase_hash(p, len, rspamd_hash_seed());
}
-guint rspamd_str_hash(gconstpointer key)
+unsigned int rspamd_str_hash(gconstpointer key)
{
gsize len;
- len = strlen((const gchar *) key);
+ len = strlen((const char *) key);
- return (guint) rspamd_cryptobox_fast_hash(key, len, rspamd_hash_seed());
+ return (unsigned int) rspamd_cryptobox_fast_hash(key, len, rspamd_hash_seed());
}
gboolean
rspamd_str_equal(gconstpointer v, gconstpointer v2)
{
- return strcmp((const gchar *) v, (const gchar *) v2) == 0;
+ return strcmp((const char *) v, (const char *) v2) == 0;
}
gboolean
@@ -317,11 +317,11 @@ rspamd_ftok_icase_equal(gconstpointer v, gconstpointer v2)
}
-guint rspamd_ftok_icase_hash(gconstpointer key)
+unsigned int rspamd_ftok_icase_hash(gconstpointer key)
{
const rspamd_ftok_t *f = key;
- return (guint) rspamd_icase_hash(f->begin, f->len, rspamd_hash_seed());
+ return (unsigned int) rspamd_icase_hash(f->begin, f->len, rspamd_hash_seed());
}
gboolean
@@ -336,11 +336,11 @@ rspamd_gstring_icase_equal(gconstpointer v, gconstpointer v2)
return FALSE;
}
-guint rspamd_gstring_icase_hash(gconstpointer key)
+unsigned int rspamd_gstring_icase_hash(gconstpointer key)
{
const GString *f = key;
- return (guint) rspamd_icase_hash(f->str, f->len, rspamd_hash_seed());
+ return (unsigned int) rspamd_icase_hash(f->str, f->len, rspamd_hash_seed());
}
/* https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord */
@@ -355,10 +355,10 @@ guint rspamd_gstring_icase_hash(gconstpointer key)
#define HASZERO(x) ~(((((x) &ZEROMASK) + ZEROMASK) | (x)) | ZEROMASK)
-gsize rspamd_strlcpy_fast(gchar *dst, const gchar *src, gsize siz)
+gsize rspamd_strlcpy_fast(char *dst, const char *src, gsize siz)
{
- gchar *d = dst;
- const gchar *s = src;
+ char *d = dst;
+ const char *s = src;
gsize n = siz;
WORD_TYPE *wd;
const WORD_TYPE *ws;
@@ -398,8 +398,8 @@ gsize rspamd_strlcpy_fast(gchar *dst, const gchar *src, gsize siz)
return (d - dst);
}
-gsize rspamd_null_safe_copy(const gchar *src, gsize srclen,
- gchar *dest, gsize destlen)
+gsize rspamd_null_safe_copy(const char *src, gsize srclen,
+ char *dest, gsize destlen)
{
gsize copied = 0, si = 0, di = 0;
@@ -424,9 +424,9 @@ gsize rspamd_null_safe_copy(const gchar *src, gsize srclen,
size_t
-rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz)
+rspamd_strlcpy_safe(char *dst, const char *src, gsize siz)
{
- gchar *d = dst;
+ char *d = dst;
gsize nleft = siz;
if (nleft != 0) {
@@ -451,10 +451,10 @@ rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz)
* Try to convert string of length to long
*/
gboolean
-rspamd_strtol(const gchar *s, gsize len, glong *value)
+rspamd_strtol(const char *s, gsize len, glong *value)
{
- const gchar *p = s, *end = s + len;
- gchar c;
+ const char *p = s, *end = s + len;
+ char c;
glong v = 0;
const glong cutoff = G_MAXLONG / 10, cutlim = G_MAXLONG % 10;
gboolean neg;
@@ -496,34 +496,34 @@ rspamd_strtol(const gchar *s, gsize len, glong *value)
/*
* Try to convert string of length to long
*/
-#define CONV_STR_LIM_DECIMAL(max_num) \
- do { \
- while (p < end) { \
- c = *p; \
- if (c >= '0' && c <= '9') { \
- c -= '0'; \
- if (v > cutoff || (v == cutoff && (guint8) c > cutlim)) { \
- *value = (max_num); \
- return FALSE; \
- } \
- else { \
- v *= 10; \
- v += c; \
- } \
- } \
- else { \
- *value = v; \
- return FALSE; \
- } \
- p++; \
- } \
+#define CONV_STR_LIM_DECIMAL(max_num) \
+ do { \
+ while (p < end) { \
+ c = *p; \
+ if (c >= '0' && c <= '9') { \
+ c -= '0'; \
+ if (v > cutoff || (v == cutoff && (uint8_t) c > cutlim)) { \
+ *value = (max_num); \
+ return FALSE; \
+ } \
+ else { \
+ v *= 10; \
+ v += c; \
+ } \
+ } \
+ else { \
+ *value = v; \
+ return FALSE; \
+ } \
+ p++; \
+ } \
} while (0)
gboolean
-rspamd_strtoul(const gchar *s, gsize len, gulong *value)
+rspamd_strtoul(const char *s, gsize len, gulong *value)
{
- const gchar *p = s, *end = s + len;
- gchar c;
+ const char *p = s, *end = s + len;
+ char c;
gulong v = 0;
const gulong cutoff = G_MAXULONG / 10, cutlim = G_MAXULONG % 10;
@@ -535,10 +535,10 @@ rspamd_strtoul(const gchar *s, gsize len, gulong *value)
}
gboolean
-rspamd_strtou64(const gchar *s, gsize len, uint64_t *value)
+rspamd_strtou64(const char *s, gsize len, uint64_t *value)
{
- const gchar *p = s, *end = s + len;
- gchar c;
+ const char *p = s, *end = s + len;
+ char c;
uint64_t v = 0;
const uint64_t cutoff = G_MAXUINT64 / 10, cutlim = G_MAXUINT64 % 10;
@@ -550,10 +550,10 @@ rspamd_strtou64(const gchar *s, gsize len, uint64_t *value)
}
gboolean
-rspamd_xstrtoul(const gchar *s, gsize len, gulong *value)
+rspamd_xstrtoul(const char *s, gsize len, gulong *value)
{
- const gchar *p = s, *end = s + len;
- gchar c;
+ const char *p = s, *end = s + len;
+ char c;
gulong v = 0;
const gulong cutoff = G_MAXULONG / 10, cutlim = G_MAXULONG % 10;
@@ -562,7 +562,7 @@ rspamd_xstrtoul(const gchar *s, gsize len, gulong *value)
c = g_ascii_tolower(*p);
if (c >= '0' && c <= '9') {
c -= '0';
- if (v > cutoff || (v == cutoff && (guint8) c > cutlim)) {
+ if (v > cutoff || (v == cutoff && (uint8_t) c > cutlim)) {
/* Range error */
*value = G_MAXULONG;
return FALSE;
@@ -574,7 +574,7 @@ rspamd_xstrtoul(const gchar *s, gsize len, gulong *value)
}
else if (c >= 'a' || c <= 'f') {
c = c - 'a' + 10;
- if (v > cutoff || (v == cutoff && (guint8) c > cutlim)) {
+ if (v > cutoff || (v == cutoff && (uint8_t) c > cutlim)) {
/* Range error */
*value = G_MAXULONG;
return FALSE;
@@ -615,16 +615,16 @@ rspamd_str_pool_copy(gconstpointer data, gpointer ud)
* http://philzimmermann.com/docs/human-oriented-base-32-encoding.txt
*/
-gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out, gsize outlen,
- enum rspamd_base32_type type)
+int rspamd_encode_base32_buf(const unsigned char *in, gsize inlen, char *out, gsize outlen,
+ enum rspamd_base32_type type)
{
static const char b32_default[] = "ybndrfg8ejkmcpqxot1uwisza345h769",
b32_bleach[] = "qpzry9x8gf2tvdw0s3jn54khce6mua7l",
b32_rfc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
*b32;
- gchar *o, *end;
+ char *o, *end;
gsize i;
- gint remain = -1, x;
+ int remain = -1, x;
bool inverse_order = true;
end = out + outlen;
@@ -744,12 +744,12 @@ gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out, gsize o
return -1;
}
-gchar *
-rspamd_encode_base32(const guchar *in, gsize inlen, enum rspamd_base32_type type)
+char *
+rspamd_encode_base32(const unsigned char *in, gsize inlen, enum rspamd_base32_type type)
{
gsize allocated_len = inlen * 8 / 5 + 2;
- gchar *out;
- gint outlen;
+ char *out;
+ int outlen;
out = g_malloc(allocated_len);
outlen = rspamd_encode_base32_buf(in, inlen, out,
@@ -767,7 +767,7 @@ rspamd_encode_base32(const guchar *in, gsize inlen, enum rspamd_base32_type type
}
enum rspamd_base32_type
-rspamd_base32_decode_type_from_str(const gchar *str)
+rspamd_base32_decode_type_from_str(const char *str)
{
enum rspamd_base32_type ret = RSPAMD_BASE32_INVALID;
@@ -788,7 +788,7 @@ rspamd_base32_decode_type_from_str(const gchar *str)
return ret;
}
-static const guchar b32_dec_zbase[] = {
+static const unsigned char b32_dec_zbase[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -821,7 +821,7 @@ static const guchar b32_dec_zbase[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-static const guchar b32_dec_bleach[] = {
+static const unsigned char b32_dec_bleach[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -854,7 +854,7 @@ static const guchar b32_dec_bleach[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-static const guchar b32_dec_rfc[] = {
+static const unsigned char b32_dec_rfc[] = {
0xff,
0xff,
0xff,
@@ -1114,15 +1114,15 @@ static const guchar b32_dec_rfc[] = {
};
-gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, gsize outlen,
- enum rspamd_base32_type type)
+int rspamd_decode_base32_buf(const char *in, gsize inlen, unsigned char *out, gsize outlen,
+ enum rspamd_base32_type type)
{
- guchar *o, *end, decoded;
- guchar c;
- guint acc = 0U;
- guint processed_bits = 0;
+ unsigned char *o, *end, decoded;
+ unsigned char c;
+ unsigned int acc = 0U;
+ unsigned int processed_bits = 0;
gsize i;
- const guchar *b32_dec;
+ const unsigned char *b32_dec;
bool inverse_bits = true;
end = out + outlen;
@@ -1147,7 +1147,7 @@ gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, gsize o
if (inverse_bits) {
for (i = 0; i < inlen; i++) {
- c = (guchar) in[i];
+ c = (unsigned char) in[i];
if (processed_bits >= 8) {
/* Emit from left to right */
@@ -1174,7 +1174,7 @@ gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, gsize o
}
else {
for (i = 0; i < inlen; i++) {
- c = (guchar) in[i];
+ c = (unsigned char) in[i];
decoded = b32_dec[c];
if (decoded == 0xff) {
@@ -1210,11 +1210,11 @@ gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, gsize o
return (o - out);
}
-guchar *
-rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen,
+unsigned char *
+rspamd_decode_base32(const char *in, gsize inlen, gsize *outlen,
enum rspamd_base32_type type)
{
- guchar *res;
+ unsigned char *res;
gsize allocated_len = inlen * 5 / 8 + 2;
gssize olen;
@@ -1245,8 +1245,8 @@ rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen,
}
-gchar *
-rspamd_encode_base64_common(const guchar *in, gsize inlen, gint str_len,
+char *
+rspamd_encode_base64_common(const unsigned char *in, gsize inlen, int str_len,
gsize *outlen, gboolean fold, enum rspamd_newlines_type how)
{
#define ADD_SPLIT \
@@ -1264,10 +1264,10 @@ rspamd_encode_base64_common(const guchar *in, gsize inlen, gint str_len,
} while (0)
gsize allocated_len = (inlen / 3) * 4 + 5;
- gchar *out, *o;
+ char *out, *o;
uint64_t n;
uint32_t rem, t, carry;
- gint cols, shift;
+ int cols, shift;
static const char b64_enc[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
@@ -1415,16 +1415,16 @@ end:
return out;
}
-gchar *
-rspamd_encode_base64(const guchar *in, gsize inlen, gint str_len,
+char *
+rspamd_encode_base64(const unsigned char *in, gsize inlen, int str_len,
gsize *outlen)
{
return rspamd_encode_base64_common(in, inlen, str_len, outlen, FALSE,
RSPAMD_TASK_NEWLINES_CRLF);
}
-gchar *
-rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len,
+char *
+rspamd_encode_base64_fold(const unsigned char *in, gsize inlen, int str_len,
gsize *outlen, enum rspamd_newlines_type how)
{
return rspamd_encode_base64_common(in, inlen, str_len, outlen, TRUE, how);
@@ -1436,15 +1436,15 @@ rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len,
#define QP_SPAN_SPECIAL(span, str_len) ((str_len) > 0 && \
((span) + 4) >= (str_len))
-gchar *
-rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len,
+char *
+rspamd_encode_qp_fold(const unsigned char *in, gsize inlen, int str_len,
gsize *outlen, enum rspamd_newlines_type how)
{
gsize olen = 0, span = 0, i = 0, seen_spaces = 0;
- gchar *out;
- gint ch, last_sp;
- const guchar *end = in + inlen, *p = in;
- static const gchar hexdigests[16] = "0123456789ABCDEF";
+ char *out;
+ int ch, last_sp;
+ const unsigned char *end = in + inlen, *p = in;
+ static const char hexdigests[16] = "0123456789ABCDEF";
while (p < end) {
ch = *p;
@@ -1662,15 +1662,15 @@ rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len,
#define MIN3(a, b, c) ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))
-gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len,
- const gchar *s2, gsize s2len,
- guint replace_cost)
+int rspamd_strings_levenshtein_distance(const char *s1, gsize s1len,
+ const char *s2, gsize s2len,
+ unsigned int replace_cost)
{
- gchar c1, c2, last_c2, last_c1;
+ char c1, c2, last_c2, last_c1;
static GArray *current_row = NULL, *prev_row = NULL, *transp_row = NULL;
- gint eq;
- static const guint max_cmp = 8192;
- gint ret;
+ int eq;
+ static const unsigned int max_cmp = 8192;
+ int ret;
g_assert(s1 != NULL);
g_assert(s2 != NULL);
@@ -1689,7 +1689,7 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len,
if (s1len > s2len) {
/* Exchange s1 and s2 */
- const gchar *tmp;
+ const char *tmp;
gsize tmplen;
tmp = s2;
@@ -1703,9 +1703,9 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len,
/* Adjust static space */
if (current_row == NULL) {
- current_row = g_array_sized_new(FALSE, FALSE, sizeof(gint), s1len + 1);
- prev_row = g_array_sized_new(FALSE, FALSE, sizeof(gint), s1len + 1);
- transp_row = g_array_sized_new(FALSE, FALSE, sizeof(gint), s1len + 1);
+ current_row = g_array_sized_new(FALSE, FALSE, sizeof(int), s1len + 1);
+ prev_row = g_array_sized_new(FALSE, FALSE, sizeof(int), s1len + 1);
+ transp_row = g_array_sized_new(FALSE, FALSE, sizeof(int), s1len + 1);
g_array_set_size(current_row, s1len + 1);
g_array_set_size(prev_row, s1len + 1);
g_array_set_size(transp_row, s1len + 1);
@@ -1716,33 +1716,33 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len,
g_array_set_size(transp_row, s1len + 1);
}
- memset(current_row->data, 0, (s1len + 1) * sizeof(gint));
- memset(transp_row->data, 0, (s1len + 1) * sizeof(gint));
+ memset(current_row->data, 0, (s1len + 1) * sizeof(int));
+ memset(transp_row->data, 0, (s1len + 1) * sizeof(int));
- for (gint i = 0; i <= s1len; i++) {
- g_array_index(prev_row, gint, i) = i;
+ for (int i = 0; i <= s1len; i++) {
+ g_array_index(prev_row, int, i) = i;
}
last_c2 = '\0';
- for (gint i = 1; i <= s2len; i++) {
+ for (int i = 1; i <= s2len; i++) {
c2 = s2[i - 1];
- g_array_index(current_row, gint, 0) = i;
+ g_array_index(current_row, int, 0) = i;
last_c1 = '\0';
- for (gint j = 1; j <= s1len; j++) {
+ for (int j = 1; j <= s1len; j++) {
c1 = s1[j - 1];
eq = c1 == c2 ? 0 : replace_cost;
- ret = MIN3(g_array_index(current_row, gint, j - 1) + 1, /* Insert */
- g_array_index(prev_row, gint, j) + 1, /* Remove */
- g_array_index(prev_row, gint, j - 1) + eq /* Replace */);
+ ret = MIN3(g_array_index(current_row, int, j - 1) + 1, /* Insert */
+ g_array_index(prev_row, int, j) + 1, /* Remove */
+ g_array_index(prev_row, int, j - 1) + eq /* Replace */);
/* Take reordering into account */
if (c1 == last_c2 && c2 == last_c1 && j >= 2) {
- ret = MIN(ret, g_array_index(transp_row, gint, j - 2) + eq);
+ ret = MIN(ret, g_array_index(transp_row, int, j - 2) + eq);
}
- g_array_index(current_row, gint, j) = ret;
+ g_array_index(current_row, int, j) = ret;
last_c1 = c1;
}
@@ -1756,24 +1756,24 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len,
current_row = tmp;
}
- ret = g_array_index(prev_row, gint, s1len);
+ ret = g_array_index(prev_row, int, s1len);
return ret;
}
GString *
-rspamd_header_value_fold(const gchar *name, gsize name_len,
- const gchar *value,
+rspamd_header_value_fold(const char *name, gsize name_len,
+ const char *value,
gsize value_len,
- guint fold_max,
+ unsigned int fold_max,
enum rspamd_newlines_type how,
- const gchar *fold_on_chars)
+ const char *fold_on_chars)
{
GString *res;
- const guint default_fold_max = 76;
- guint cur_len;
- const gchar *p, *c, *end, *fold_sequence;
- guint nspaces = 0;
+ const unsigned int default_fold_max = 76;
+ unsigned int cur_len;
+ const char *p, *c, *end, *fold_sequence;
+ unsigned int nspaces = 0;
gboolean first_token = TRUE;
enum {
fold_before = 0,
@@ -1940,7 +1940,7 @@ rspamd_header_value_fold(const gchar *name, gsize name_len,
* Check any spaces that are appended to the result
* before folding
*/
- const gchar *last = &res->str[res->len - 1];
+ const char *last = &res->str[res->len - 1];
while (g_ascii_isspace(*last)) {
last--;
@@ -1965,7 +1965,7 @@ rspamd_header_value_fold(const gchar *name, gsize name_len,
cur_len = 0;
}
else {
- const gchar *last;
+ const char *last;
/* Skip space if needed */
if (g_ascii_isspace(*c) && p > c) {
@@ -2071,20 +2071,20 @@ rspamd_header_value_fold(const gchar *name, gsize name_len,
return res;
}
-static inline bool rspamd_substring_cmp_func(guchar a, guchar b)
+static inline bool rspamd_substring_cmp_func(unsigned char a, unsigned char b)
{
return a == b;
}
-static inline bool rspamd_substring_casecmp_func(guchar a, guchar b)
+static inline bool rspamd_substring_casecmp_func(unsigned char a, unsigned char b)
{
return lc_map[a] == lc_map[b];
}
-typedef bool (*rspamd_cmpchar_func_t)(guchar a, guchar b);
+typedef bool (*rspamd_cmpchar_func_t)(unsigned char a, unsigned char b);
static inline void
-rspamd_substring_preprocess_kmp(const gchar *pat, gsize len, goffset *fsm,
+rspamd_substring_preprocess_kmp(const char *pat, gsize len, goffset *fsm,
rspamd_cmpchar_func_t f)
{
goffset i, j;
@@ -2111,8 +2111,8 @@ rspamd_substring_preprocess_kmp(const gchar *pat, gsize len, goffset *fsm,
}
static inline goffset
-rspamd_substring_search_preprocessed(const gchar *in, gsize inlen,
- const gchar *srch,
+rspamd_substring_search_preprocessed(const char *in, gsize inlen,
+ const char *srch,
gsize srchlen,
const goffset *fsm,
rspamd_cmpchar_func_t f)
@@ -2164,8 +2164,8 @@ rspamd_substring_search_preprocessed(const gchar *in, gsize inlen,
}
static inline goffset
-rspamd_substring_search_common(const gchar *in, gsize inlen,
- const gchar *srch, gsize srchlen, rspamd_cmpchar_func_t f)
+rspamd_substring_search_common(const char *in, gsize inlen,
+ const char *srch, gsize srchlen, rspamd_cmpchar_func_t f)
{
static goffset st_fsm[128];
goffset *fsm, ret;
@@ -2188,12 +2188,12 @@ rspamd_substring_search_common(const gchar *in, gsize inlen,
}
goffset
-rspamd_substring_search(const gchar *in, gsize inlen,
- const gchar *srch, gsize srchlen)
+rspamd_substring_search(const char *in, gsize inlen,
+ const char *srch, gsize srchlen)
{
if (inlen > srchlen) {
if (G_UNLIKELY(srchlen == 1)) {
- const gchar *p;
+ const char *p;
p = memchr(in, srch[0], inlen);
@@ -2221,16 +2221,16 @@ rspamd_substring_search(const gchar *in, gsize inlen,
}
goffset
-rspamd_substring_search_caseless(const gchar *in, gsize inlen,
- const gchar *srch, gsize srchlen)
+rspamd_substring_search_caseless(const char *in, gsize inlen,
+ const char *srch, gsize srchlen)
{
if (inlen > srchlen) {
if (G_UNLIKELY(srchlen == 1)) {
goffset i;
- gchar s = lc_map[(guchar) srch[0]];
+ char s = lc_map[(unsigned char) srch[0]];
for (i = 0; i < inlen; i++) {
- if (lc_map[(guchar) in[i]] == s) {
+ if (lc_map[(unsigned char) in[i]] == s) {
return i;
}
}
@@ -2251,7 +2251,7 @@ rspamd_substring_search_caseless(const gchar *in, gsize inlen,
goffset
rspamd_string_find_eoh(GString *input, goffset *body_start)
{
- const gchar *p, *c = NULL, *end;
+ const char *p, *c = NULL, *end;
enum {
skip_char = 0,
got_cr,
@@ -2492,12 +2492,12 @@ rspamd_string_find_eoh(GString *input, goffset *body_start)
return -1;
}
-gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out,
- gsize outlen)
+int rspamd_encode_hex_buf(const unsigned char *in, gsize inlen, char *out,
+ gsize outlen)
{
- gchar *o, *end;
- const guchar *p;
- static const gchar hexdigests[16] = "0123456789abcdef";
+ char *o, *end;
+ const unsigned char *p;
+ static const char hexdigests[16] = "0123456789abcdef";
end = out + outlen;
o = out;
@@ -2516,12 +2516,12 @@ gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out,
return -1;
}
-gchar *
-rspamd_encode_hex(const guchar *in, gsize inlen)
+char *
+rspamd_encode_hex(const unsigned char *in, gsize inlen)
{
- gchar *out;
+ char *out;
gsize outlen = inlen * 2 + 1;
- gint olen;
+ int olen;
if (in == NULL) {
return NULL;
@@ -2543,12 +2543,12 @@ rspamd_encode_hex(const guchar *in, gsize inlen)
}
gssize
-rspamd_decode_hex_buf(const gchar *in, gsize inlen,
- guchar *out, gsize outlen)
+rspamd_decode_hex_buf(const char *in, gsize inlen,
+ unsigned char *out, gsize outlen)
{
- guchar *o, *end, ret = 0;
- const gchar *p;
- gchar c;
+ unsigned char *o, *end, ret = 0;
+ const char *p;
+ char c;
end = out + outlen;
o = out;
@@ -2587,12 +2587,12 @@ rspamd_decode_hex_buf(const gchar *in, gsize inlen,
return -1;
}
-guchar *
-rspamd_decode_hex(const gchar *in, gsize inlen)
+unsigned char *
+rspamd_decode_hex(const char *in, gsize inlen)
{
- guchar *out;
+ unsigned char *out;
gsize outlen = (inlen / 2 + inlen % 2) + 1;
- gint olen;
+ int olen;
if (in == NULL) {
return NULL;
@@ -2614,12 +2614,12 @@ rspamd_decode_hex(const gchar *in, gsize inlen)
}
gssize
-rspamd_decode_qp_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen)
+rspamd_decode_qp_buf(const char *in, gsize inlen,
+ char *out, gsize outlen)
{
- gchar *o, *end, *pos, c;
- const gchar *p;
- guchar ret;
+ char *o, *end, *pos, c;
+ const char *p;
+ unsigned char ret;
gssize remain, processed;
p = in;
@@ -2715,7 +2715,7 @@ rspamd_decode_qp_buf(const gchar *in, gsize inlen,
}
if (end - o > 0) {
- *o++ = (gchar) ret;
+ *o++ = (char) ret;
}
else {
return (-1);
@@ -2769,15 +2769,15 @@ rspamd_decode_qp_buf(const gchar *in, gsize inlen,
}
gssize
-rspamd_decode_uue_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen)
+rspamd_decode_uue_buf(const char *in, gsize inlen,
+ char *out, gsize outlen)
{
- gchar *o, *out_end;
- const gchar *p;
+ char *o, *out_end;
+ const char *p;
gssize remain;
gboolean base64 = FALSE;
goffset pos;
- const gchar *nline = "\r\n";
+ const char *nline = "\r\n";
p = in;
o = out;
@@ -2848,8 +2848,8 @@ rspamd_decode_uue_buf(const gchar *in, gsize inlen,
while (remain > 0 && o < out_end) {
/* Main cycle */
- const gchar *eol;
- gint i, ch;
+ const char *eol;
+ int i, ch;
pos = rspamd_memcspn(p, nline, remain);
@@ -2930,10 +2930,10 @@ rspamd_decode_uue_buf(const gchar *in, gsize inlen,
((a)[(gsize) (b) / (8 * sizeof *(a))] op(gsize) 1 << ((gsize) (b) % (8 * sizeof *(a))))
-gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len)
+gsize rspamd_memcspn(const char *s, const char *e, gsize len)
{
gsize byteset[32 / sizeof(gsize)];
- const gchar *p = s, *end = s + len;
+ const char *p = s, *end = s + len;
if (!e[1]) {
for (; p < end && *p != *e; p++)
@@ -2943,18 +2943,18 @@ gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len)
memset(byteset, 0, sizeof byteset);
- for (; *e && BITOP(byteset, *(guchar *) e, |=); e++)
+ for (; *e && BITOP(byteset, *(unsigned char *) e, |=); e++)
;
- for (; p < end && !BITOP(byteset, *(guchar *) p, &); p++)
+ for (; p < end && !BITOP(byteset, *(unsigned char *) p, &); p++)
;
return p - s;
}
-gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len)
+gsize rspamd_memspn(const char *s, const char *e, gsize len)
{
gsize byteset[32 / sizeof(gsize)];
- const gchar *p = s, *end = s + len;
+ const char *p = s, *end = s + len;
if (!e[1]) {
for (; p < end && *p == *e; p++)
@@ -2964,21 +2964,21 @@ gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len)
memset(byteset, 0, sizeof byteset);
- for (; *e && BITOP(byteset, *(guchar *) e, |=); e++)
+ for (; *e && BITOP(byteset, *(unsigned char *) e, |=); e++)
;
- for (; p < end && BITOP(byteset, *(guchar *) p, &); p++)
+ for (; p < end && BITOP(byteset, *(unsigned char *) p, &); p++)
;
return p - s;
}
gssize
-rspamd_decode_qp2047_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen)
+rspamd_decode_qp2047_buf(const char *in, gsize inlen,
+ char *out, gsize outlen)
{
- gchar *o, *end, c;
- const gchar *p;
- guchar ret;
+ char *o, *end, c;
+ const char *p;
+ unsigned char ret;
gsize remain, processed;
p = in;
@@ -3033,7 +3033,7 @@ rspamd_decode_qp2047_buf(const gchar *in, gsize inlen,
}
if (end - o > 0) {
- *o++ = (gchar) ret;
+ *o++ = (char) ret;
}
else {
return (-1);
@@ -3080,11 +3080,11 @@ rspamd_decode_qp2047_buf(const gchar *in, gsize inlen,
}
gssize
-rspamd_encode_qp2047_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen)
+rspamd_encode_qp2047_buf(const char *in, gsize inlen,
+ char *out, gsize outlen)
{
- gchar *o = out, *end = out + outlen, c;
- static const gchar hexdigests[16] = "0123456789ABCDEF";
+ char *o = out, *end = out + outlen, c;
+ static const char hexdigests[16] = "0123456789ABCDEF";
while (inlen > 0 && o < end) {
c = *in;
@@ -3239,7 +3239,7 @@ rspamd_fstring_emit_append_double(double val, void *ud)
#define MAX_PRECISION 6
if (isfinite(val)) {
- if (val == (double) ((gint) val)) {
+ if (val == (double) ((int) val)) {
rspamd_printf_fstring(buf, "%.1f", val);
}
else {
@@ -3271,9 +3271,9 @@ void rspamd_ucl_emit_fstring_comments(const ucl_object_t *obj,
#ifndef HAVE_MEMRCHR
void *
-rspamd_memrchr(const void *m, gint c, gsize len)
+rspamd_memrchr(const void *m, int c, gsize len)
{
- const guint8 *p = m;
+ const uint8_t *p = m;
for (gsize i = len; i > 0; i--) {
if (p[i - 1] == c) {
@@ -3337,14 +3337,14 @@ rspamd_get_unicode_normalizer(void)
#endif
}
-gchar *
-rspamd_str_regexp_escape(const gchar *pattern, gsize slen,
+char *
+rspamd_str_regexp_escape(const char *pattern, gsize slen,
gsize *dst_len, enum rspamd_regexp_escape_flags flags)
{
- const gchar *p, *end = pattern + slen;
- gchar *res, *d, t, *tmp_utf = NULL, *dend;
+ const char *p, *end = pattern + slen;
+ char *res, *d, t, *tmp_utf = NULL, *dend;
gsize len;
- static const gchar hexdigests[16] = "0123456789abcdef";
+ static const char hexdigests[16] = "0123456789abcdef";
len = 0;
p = pattern;
@@ -3541,15 +3541,15 @@ rspamd_str_regexp_escape(const gchar *pattern, gsize slen,
}
-gchar *
-rspamd_str_make_utf_valid(const guchar *src, gsize slen,
+char *
+rspamd_str_make_utf_valid(const unsigned char *src, gsize slen,
gsize *dstlen,
rspamd_mempool_t *pool)
{
UChar32 uc;
goffset err_offset;
- const guchar *p;
- gchar *dst, *d;
+ const unsigned char *p;
+ char *dst, *d;
gsize remain = slen, dlen = 0;
if (src == NULL) {
@@ -3569,7 +3569,7 @@ rspamd_str_make_utf_valid(const guchar *src, gsize slen,
/* Check space required */
while (remain > 0 && (err_offset = rspamd_fast_utf8_validate(p, remain)) > 0) {
- gint i = 0;
+ int i = 0;
err_offset--; /* As it returns it 1 indexed */
p += err_offset;
@@ -3610,13 +3610,13 @@ rspamd_str_make_utf_valid(const guchar *src, gsize slen,
d += err_offset;
/* Append 0xFFFD for each bad character */
- gint i = 0;
+ int i = 0;
p += err_offset;
remain -= err_offset;
while (i < remain) {
- gint old_i = i;
+ int old_i = i;
U8_NEXT(p, i, remain, uc);
if (uc < 0) {
@@ -3655,9 +3655,9 @@ rspamd_str_make_utf_valid(const guchar *src, gsize slen,
return dst;
}
-gsize rspamd_gstring_strip(GString *s, const gchar *strip_chars)
+gsize rspamd_gstring_strip(GString *s, const char *strip_chars)
{
- const gchar *p, *sc;
+ const char *p, *sc;
gsize strip_len = 0, total = 0;
p = s->str + s->len - 1;
@@ -3703,11 +3703,11 @@ gsize rspamd_gstring_strip(GString *s, const gchar *strip_chars)
return total;
}
-const gchar *rspamd_string_len_strip(const gchar *in,
- gsize *len,
- const gchar *strip_chars)
+const char *rspamd_string_len_strip(const char *in,
+ gsize *len,
+ const char *strip_chars)
{
- const gchar *p, *sc;
+ const char *p, *sc;
gsize strip_len = 0, old_len = *len;
p = in + old_len - 1;
@@ -3755,13 +3755,13 @@ const gchar *rspamd_string_len_strip(const gchar *in,
return in;
}
-gchar **
-rspamd_string_len_split(const gchar *in, gsize len, const gchar *spill,
- gint max_elts, rspamd_mempool_t *pool)
+char **
+rspamd_string_len_split(const char *in, gsize len, const char *spill,
+ int max_elts, rspamd_mempool_t *pool)
{
- const gchar *p = in, *end = in + len;
+ const char *p = in, *end = in + len;
gsize detected_elts = 0;
- gchar **res;
+ char **res;
/* Detect number of elements */
while (p < end) {
@@ -3780,7 +3780,7 @@ rspamd_string_len_split(const gchar *in, gsize len, const gchar *spill,
p += rspamd_memspn(p, spill, end - p);
}
- res = pool ? rspamd_mempool_alloc(pool, sizeof(gchar *) * (detected_elts + 1)) : g_malloc(sizeof(gchar *) * (detected_elts + 1));
+ res = pool ? rspamd_mempool_alloc(pool, sizeof(char *) * (detected_elts + 1)) : g_malloc(sizeof(char *) * (detected_elts + 1));
/* Last one */
res[detected_elts] = NULL;
detected_elts = 0;
@@ -3790,7 +3790,7 @@ rspamd_string_len_split(const gchar *in, gsize len, const gchar *spill,
gsize cur_fragment = rspamd_memcspn(p, spill, end - p);
if (cur_fragment > 0) {
- gchar *elt;
+ char *elt;
elt = pool ? rspamd_mempool_alloc(pool, cur_fragment + 1) : g_malloc(cur_fragment + 1);
@@ -3816,12 +3816,12 @@ rspamd_string_len_split(const gchar *in, gsize len, const gchar *spill,
#endif
static inline gboolean
-rspamd_str_has_8bit_u64(const guchar *beg, gsize len)
+rspamd_str_has_8bit_u64(const unsigned char *beg, gsize len)
{
- guint8 orb = 0;
+ uint8_t orb = 0;
if (len >= 16) {
- const guchar *nextd = beg + sizeof(uint64_t);
+ const unsigned char *nextd = beg + sizeof(uint64_t);
uint64_t n1 = 0, n2 = 0;
do {
@@ -3851,7 +3851,7 @@ rspamd_str_has_8bit_u64(const guchar *beg, gsize len)
}
gboolean
-rspamd_str_has_8bit(const guchar *beg, gsize len)
+rspamd_str_has_8bit(const unsigned char *beg, gsize len)
{
#if defined(__x86_64__)
if (len >= 32) {
diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h
index ff5827a0b..a7252f3bf 100644
--- a/src/libutil/str_util.h
+++ b/src/libutil/str_util.h
@@ -36,12 +36,12 @@ enum rspamd_newlines_type {
/**
* Compare two memory regions of size `l` using case insensitive matching
*/
-gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l);
+int rspamd_lc_cmp(const char *s, const char *d, gsize l);
/**
* Convert string to lowercase in-place using ASCII conversion
*/
-guint rspamd_str_lc(gchar *str, guint size);
+unsigned int rspamd_str_lc(char *str, unsigned int size);
/**
* Performs ascii copy & lowercase
@@ -49,26 +49,26 @@ guint rspamd_str_lc(gchar *str, guint size);
* @param size
* @return
*/
-gsize rspamd_str_copy_lc(const gchar *src, gchar *dst, gsize size);
+gsize rspamd_str_copy_lc(const char *src, char *dst, gsize size);
/**
* Convert string to lowercase in-place using utf (limited) conversion
*/
-guint rspamd_str_lc_utf8(gchar *str, guint size);
+unsigned int rspamd_str_lc_utf8(char *str, unsigned int size);
/*
* Hash table utility functions for case insensitive hashing
*/
-uint64_t rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed);
+uint64_t rspamd_icase_hash(const char *in, gsize len, uint64_t seed);
-guint rspamd_strcase_hash(gconstpointer key);
+unsigned int rspamd_strcase_hash(gconstpointer key);
gboolean rspamd_strcase_equal(gconstpointer v, gconstpointer v2);
/*
* Hash table utility functions for case sensitive hashing
*/
-guint rspamd_str_hash(gconstpointer key);
+unsigned int rspamd_str_hash(gconstpointer key);
gboolean rspamd_str_equal(gconstpointer v, gconstpointer v2);
@@ -76,7 +76,7 @@ gboolean rspamd_str_equal(gconstpointer v, gconstpointer v2);
/*
* Hash table utility functions for hashing fixed strings
*/
-guint rspamd_ftok_icase_hash(gconstpointer key);
+unsigned int rspamd_ftok_icase_hash(gconstpointer key);
gboolean rspamd_ftok_icase_equal(gconstpointer v, gconstpointer v2);
@@ -84,7 +84,7 @@ gboolean rspamd_ftok_icase_equal(gconstpointer v, gconstpointer v2);
#define rspamd_ftok_hash(key) _wyhash32((key)->begin, (key)->len, 0)
#define rspamd_ftok_equal(v1, v2) ((v1)->len == (v2)->len && memcmp((v1)->begin, (v2)->begin, (v1)->len) == 0)
-guint rspamd_gstring_icase_hash(gconstpointer key);
+unsigned int rspamd_gstring_icase_hash(gconstpointer key);
gboolean rspamd_gstring_icase_equal(gconstpointer v, gconstpointer v2);
@@ -98,9 +98,9 @@ gboolean rspamd_gstring_icase_equal(gconstpointer v, gconstpointer v2);
* @param siz length of destination buffer
* @return bytes copied
*/
-gsize rspamd_strlcpy_fast(gchar *dst, const gchar *src, gsize siz);
+gsize rspamd_strlcpy_fast(char *dst, const char *src, gsize siz);
-gsize rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz);
+gsize rspamd_strlcpy_safe(char *dst, const char *src, gsize siz);
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
@@ -128,24 +128,24 @@ gsize rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz);
* @param destlen
* @return number of bytes copied
*/
-gsize rspamd_null_safe_copy(const gchar *src, gsize srclen,
- gchar *dest, gsize destlen);
+gsize rspamd_null_safe_copy(const char *src, gsize srclen,
+ char *dest, gsize destlen);
/*
* Try to convert string of length to long
*/
-gboolean rspamd_strtol(const gchar *s, gsize len, glong *value);
+gboolean rspamd_strtol(const char *s, gsize len, glong *value);
/*
* Try to convert a string of length to unsigned long
*/
-gboolean rspamd_strtoul(const gchar *s, gsize len, gulong *value);
-gboolean rspamd_strtou64(const gchar *s, gsize len, uint64_t *value);
+gboolean rspamd_strtoul(const char *s, gsize len, gulong *value);
+gboolean rspamd_strtou64(const char *s, gsize len, uint64_t *value);
/*
* Try to convert a hex string of length to unsigned long
*/
-gboolean rspamd_xstrtoul(const gchar *s, gsize len, gulong *value);
+gboolean rspamd_xstrtoul(const char *s, gsize len, gulong *value);
/**
* Utility function to provide mem_pool copy for rspamd_hash_table_copy function
@@ -161,7 +161,7 @@ gpointer rspamd_str_pool_copy(gconstpointer data, gpointer ud);
* @param inlen input length
* @return freshly allocated base32 encoding of a specified string
*/
-gchar *rspamd_encode_hex(const guchar *in, gsize inlen);
+char *rspamd_encode_hex(const unsigned char *in, gsize inlen);
/**
* Decode string using hex encoding
@@ -169,7 +169,7 @@ gchar *rspamd_encode_hex(const guchar *in, gsize inlen);
* @param inlen input length
* @return freshly allocated base32 decoded value or NULL if input is invalid
*/
-guchar *rspamd_decode_hex(const gchar *in, gsize inlen);
+unsigned char *rspamd_decode_hex(const char *in, gsize inlen);
enum rspamd_base32_type {
RSPAMD_BASE32_DEFAULT = 0,
@@ -184,7 +184,7 @@ enum rspamd_base32_type {
* @param str
* @return
*/
-enum rspamd_base32_type rspamd_base32_decode_type_from_str(const gchar *str);
+enum rspamd_base32_type rspamd_base32_decode_type_from_str(const char *str);
/**
* Encode string using base32 encoding
@@ -192,8 +192,8 @@ enum rspamd_base32_type rspamd_base32_decode_type_from_str(const gchar *str);
* @param inlen input length
* @return freshly allocated base32 encoding of a specified string
*/
-gchar *rspamd_encode_base32(const guchar *in, gsize inlen,
- enum rspamd_base32_type type);
+char *rspamd_encode_base32(const unsigned char *in, gsize inlen,
+ enum rspamd_base32_type type);
/**
* Decode string using base32 encoding
@@ -201,7 +201,7 @@ gchar *rspamd_encode_base32(const guchar *in, gsize inlen,
* @param inlen input length
* @return freshly allocated base32 decoded value or NULL if input is invalid
*/
-guchar *rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen, enum rspamd_base32_type type);
+unsigned char *rspamd_decode_base32(const char *in, gsize inlen, gsize *outlen, enum rspamd_base32_type type);
/**
* Encode string using base32 encoding
@@ -211,8 +211,8 @@ guchar *rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen, enum r
* @param outlen output buf len
* @return encoded len if `outlen` is enough to encode `inlen`
*/
-gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out,
- gsize outlen, enum rspamd_base32_type type);
+int rspamd_encode_base32_buf(const unsigned char *in, gsize inlen, char *out,
+ gsize outlen, enum rspamd_base32_type type);
/**
* Decode string using base32 encoding
@@ -222,8 +222,8 @@ gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out,
* @param outlen output buf len
* @return decoded len if in is valid base32 and `outlen` is enough to encode `inlen`
*/
-gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out,
- gsize outlen, enum rspamd_base32_type type);
+int rspamd_decode_base32_buf(const char *in, gsize inlen, unsigned char *out,
+ gsize outlen, enum rspamd_base32_type type);
/**
* Encode string using hex encoding
@@ -233,8 +233,8 @@ gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out,
* @param outlen output buf len
* @return encoded len if `outlen` is enough to encode `inlen`
*/
-gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out,
- gsize outlen);
+int rspamd_encode_hex_buf(const unsigned char *in, gsize inlen, char *out,
+ gsize outlen);
/**
@@ -245,8 +245,8 @@ gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out,
* @param outlen output buf len
* @return decoded len if in is valid hex and `outlen` is enough to encode `inlen`
*/
-gssize rspamd_decode_hex_buf(const gchar *in, gsize inlen,
- guchar *out, gsize outlen);
+gssize rspamd_decode_hex_buf(const char *in, gsize inlen,
+ unsigned char *out, gsize outlen);
/**
* Common version of base64 encoder
@@ -258,10 +258,10 @@ gssize rspamd_decode_hex_buf(const gchar *in, gsize inlen,
* @param how
* @return
*/
-gchar *
-rspamd_encode_base64_common(const guchar *in,
+char *
+rspamd_encode_base64_common(const unsigned char *in,
gsize inlen,
- gint str_len,
+ int str_len,
gsize *outlen,
gboolean fold,
enum rspamd_newlines_type how);
@@ -273,8 +273,8 @@ rspamd_encode_base64_common(const guchar *in,
* @param str_len maximum string length (if <= 0 then no lines are split)
* @return freshly allocated base64 encoded value or NULL if input is invalid
*/
-gchar *rspamd_encode_base64(const guchar *in, gsize inlen, gint str_len,
- gsize *outlen);
+char *rspamd_encode_base64(const unsigned char *in, gsize inlen, int str_len,
+ gsize *outlen);
/**
* Encode and fold string using base64 encoding
@@ -283,8 +283,8 @@ gchar *rspamd_encode_base64(const guchar *in, gsize inlen, gint str_len,
* @param str_len maximum string length (if <= 0 then no lines are split)
* @return freshly allocated base64 encoded value or NULL if input is invalid
*/
-gchar *rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len,
- gsize *outlen, enum rspamd_newlines_type how);
+char *rspamd_encode_base64_fold(const unsigned char *in, gsize inlen, int str_len,
+ gsize *outlen, enum rspamd_newlines_type how);
/**
* Encode and fold string using quoted printable encoding
@@ -293,8 +293,8 @@ gchar *rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len,
* @param str_len maximum string length (if <= 0 then no lines are split)
* @return freshly allocated base64 encoded value or NULL if input is invalid
*/
-gchar *rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len,
- gsize *outlen, enum rspamd_newlines_type how);
+char *rspamd_encode_qp_fold(const unsigned char *in, gsize inlen, int str_len,
+ gsize *outlen, enum rspamd_newlines_type how);
/**
* Decode quoted-printable encoded buffer, input and output must not overlap
@@ -304,8 +304,8 @@ gchar *rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len,
* @param outlen length of output
* @return real size of decoded output or (-1) if outlen is not enough
*/
-gssize rspamd_decode_qp_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen);
+gssize rspamd_decode_qp_buf(const char *in, gsize inlen,
+ char *out, gsize outlen);
/**
* Decode uuencode encoded buffer, input and output must not overlap
@@ -315,8 +315,8 @@ gssize rspamd_decode_qp_buf(const gchar *in, gsize inlen,
* @param outlen length of output
* @return real size of decoded output or (-1) if outlen is not enough
*/
-gssize rspamd_decode_uue_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen);
+gssize rspamd_decode_uue_buf(const char *in, gsize inlen,
+ char *out, gsize outlen);
/**
* Decode quoted-printable encoded buffer using rfc2047 format, input and output must not overlap
@@ -326,8 +326,8 @@ gssize rspamd_decode_uue_buf(const gchar *in, gsize inlen,
* @param outlen length of output
* @return real size of decoded output or (-1) if outlen is not enough
*/
-gssize rspamd_decode_qp2047_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen);
+gssize rspamd_decode_qp2047_buf(const char *in, gsize inlen,
+ char *out, gsize outlen);
/**
* Encode quoted-printable buffer using rfc2047 format, input and output must not overlap
@@ -337,8 +337,8 @@ gssize rspamd_decode_qp2047_buf(const gchar *in, gsize inlen,
* @param outlen
* @return
*/
-gssize rspamd_encode_qp2047_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen);
+gssize rspamd_encode_qp2047_buf(const char *in, gsize inlen,
+ char *out, gsize outlen);
#ifndef g_tolower
#define g_tolower(x) (((x) >= 'A' && (x) <= 'Z') ? (x) - 'A' + 'a' : (x))
@@ -352,8 +352,8 @@ gssize rspamd_encode_qp2047_buf(const gchar *in, gsize inlen,
* @param s2len
* @return
*/
-gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len,
- const gchar *s2, gsize s2len, guint replace_cost);
+int rspamd_strings_levenshtein_distance(const char *s1, gsize s1len,
+ const char *s2, gsize s2len, unsigned int replace_cost);
/**
* Fold header using rfc822 rules, return new GString from the previous one
@@ -364,13 +364,13 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len,
* @param fold_on_chars
* @return new GString with the folded value
*/
-GString *rspamd_header_value_fold(const gchar *name,
+GString *rspamd_header_value_fold(const char *name,
gsize name_len,
- const gchar *value,
+ const char *value,
gsize value_len,
- guint fold_max,
+ unsigned int fold_max,
enum rspamd_newlines_type how,
- const gchar *fold_on_chars);
+ const char *fold_on_chars);
/**
* Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm
@@ -381,8 +381,8 @@ GString *rspamd_header_value_fold(const gchar *name,
* @param srchlen length of the search string
* @return position of the first substring match or (-1) if not found
*/
-goffset rspamd_substring_search(const gchar *in, gsize inlen,
- const gchar *srch, gsize srchlen);
+goffset rspamd_substring_search(const char *in, gsize inlen,
+ const char *srch, gsize srchlen);
/**
* Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm in caseless matter (ASCII only)
@@ -393,8 +393,8 @@ goffset rspamd_substring_search(const gchar *in, gsize inlen,
* @param srchlen length of the search string
* @return position of the first substring match or (-1) if not found
*/
-goffset rspamd_substring_search_caseless(const gchar *in, gsize inlen,
- const gchar *srch, gsize srchlen);
+goffset rspamd_substring_search_caseless(const char *in, gsize inlen,
+ const char *srch, gsize srchlen);
/**
* Search for end-of-headers mark in the input string. Returns position just after
@@ -435,7 +435,7 @@ void rspamd_ucl_emit_fstring_comments(const ucl_object_t *obj,
rspamd_fstring_t **target,
const ucl_object_t *comments);
-extern const guchar lc_map[256];
+extern const unsigned char lc_map[256];
/**
* Search for the last occurrence of character `c` in memory block of size `len`
@@ -447,7 +447,7 @@ extern const guchar lc_map[256];
#ifdef HAVE_MEMRCHR
#define rspamd_memrchr memrchr
#else
-void *rspamd_memrchr(const void *m, gint c, gsize len);
+void *rspamd_memrchr(const void *m, int c, gsize len);
#endif
/**
@@ -457,7 +457,7 @@ void *rspamd_memrchr(const void *m, gint c, gsize len);
* @param len length of `s`
* @return segment size
*/
-gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len);
+gsize rspamd_memcspn(const char *s, const char *e, gsize len);
/**
* Return length of memory segment starting in `s` that contains only chars from `e`
@@ -466,7 +466,7 @@ gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len);
* @param len length of `s`
* @return segment size
*/
-gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len);
+gsize rspamd_memspn(const char *s, const char *e, gsize len);
/* https://graphics.stanford.edu/~seander/bithacks.html#HasMoreInWord */
#define rspamd_str_hasmore(x, n) ((((x) + ~0UL / 255 * (127 - (n))) | (x)) & ~0UL / 255 * 128)
@@ -475,7 +475,7 @@ gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len);
*/
#define rspamd_is_aligned(p, n) (((uintptr_t) (p) & ((uintptr_t) (n) -1)) == 0)
#define rspamd_is_aligned_as(p, v) rspamd_is_aligned(p, RSPAMD_ALIGNOF(__typeof((v))))
-gboolean rspamd_str_has_8bit(const guchar *beg, gsize len);
+gboolean rspamd_str_has_8bit(const unsigned char *beg, gsize len);
struct UConverter;
@@ -501,8 +501,8 @@ enum rspamd_regexp_escape_flags {
* @param allow_glob allow glob expressions to be translated into pcre
* @return newly allocated zero terminated escaped pattern
*/
-gchar *
-rspamd_str_regexp_escape(const gchar *pattern, gsize slen,
+char *
+rspamd_str_regexp_escape(const char *pattern, gsize slen,
gsize *dst_len, enum rspamd_regexp_escape_flags flags) G_GNUC_WARN_UNUSED_RESULT;
/**
@@ -513,23 +513,23 @@ rspamd_str_regexp_escape(const gchar *pattern, gsize slen,
* @param dstelen
* @return
*/
-gchar *rspamd_str_make_utf_valid(const guchar *src, gsize slen, gsize *dstlen,
- rspamd_mempool_t *pool) G_GNUC_WARN_UNUSED_RESULT;
+char *rspamd_str_make_utf_valid(const unsigned char *src, gsize slen, gsize *dstlen,
+ rspamd_mempool_t *pool) G_GNUC_WARN_UNUSED_RESULT;
/**
* Strips characters in `strip_chars` from start and end of the GString
* @param s
* @param strip_chars
*/
-gsize rspamd_gstring_strip(GString *s, const gchar *strip_chars);
+gsize rspamd_gstring_strip(GString *s, const char *strip_chars);
/**
* Strips characters in `strip_chars` from start and end of the sized string
* @param s
* @param strip_chars
*/
-const gchar *rspamd_string_len_strip(const gchar *in,
- gsize *len, const gchar *strip_chars) G_GNUC_WARN_UNUSED_RESULT;
+const char *rspamd_string_len_strip(const char *in,
+ gsize *len, const char *strip_chars) G_GNUC_WARN_UNUSED_RESULT;
/**
* Returns a NULL terminated list of zero terminated strings based on splitting of
@@ -542,8 +542,8 @@ const gchar *rspamd_string_len_strip(const gchar *in,
* @param max_elts
* @return
*/
-gchar **rspamd_string_len_split(const gchar *in, gsize len,
- const gchar *spill, gint max_elts, rspamd_mempool_t *pool);
+char **rspamd_string_len_split(const char *in, gsize len,
+ const char *spill, int max_elts, rspamd_mempool_t *pool);
#define IS_ZERO_WIDTH_SPACE(uc) ((uc) == 0x200B || \
(uc) == 0x200C || \
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index a004a298b..300f907a7 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -31,14 +31,14 @@
struct upstream_inet_addr_entry {
rspamd_inet_addr_t *addr;
- guint priority;
+ unsigned int priority;
struct upstream_inet_addr_entry *next;
};
struct upstream_addr_elt {
rspamd_inet_addr_t *addr;
- guint priority;
- guint errors;
+ unsigned int priority;
+ unsigned int errors;
};
struct upstream_list_watcher {
@@ -50,17 +50,17 @@ struct upstream_list_watcher {
};
struct upstream {
- guint weight;
- guint cur_weight;
- guint errors;
- guint checked;
- guint dns_requests;
- gint active_idx;
- guint ttl;
- gchar *name;
+ unsigned int weight;
+ unsigned int cur_weight;
+ unsigned int errors;
+ unsigned int checked;
+ unsigned int dns_requests;
+ int active_idx;
+ unsigned int ttl;
+ char *name;
ev_timer ev;
- gdouble last_fail;
- gdouble last_resolve;
+ double last_fail;
+ double last_resolve;
gpointer ud;
enum rspamd_upstream_flag flags;
struct upstream_list *ls;
@@ -69,12 +69,12 @@ struct upstream {
struct {
GPtrArray *addr; /* struct upstream_addr_elt */
- guint cur;
+ unsigned int cur;
} addrs;
struct upstream_inet_addr_entry *new_addrs;
gpointer data;
- gchar uid[8];
+ char uid[8];
ref_entry_t ref;
#ifdef UPSTREAMS_THREAD_SAFE
rspamd_mutex_t *lock;
@@ -82,17 +82,17 @@ struct upstream {
};
struct upstream_limits {
- gdouble revive_time;
- gdouble revive_jitter;
- gdouble error_time;
- gdouble dns_timeout;
- gdouble lazy_resolve_time;
- guint max_errors;
- guint dns_retransmits;
+ double revive_time;
+ double revive_jitter;
+ double error_time;
+ double dns_timeout;
+ double lazy_resolve_time;
+ unsigned int max_errors;
+ unsigned int dns_retransmits;
};
struct upstream_list {
- gchar *ups_line;
+ char *ups_line;
struct upstream_ctx *ctx;
GPtrArray *ups;
GPtrArray *alive;
@@ -100,7 +100,7 @@ struct upstream_list {
uint64_t hash_seed;
const struct upstream_limits *limits;
enum rspamd_upstream_flag flags;
- guint cur_elt;
+ unsigned int cur_elt;
enum rspamd_upstream_rotation rot_alg;
#ifdef UPSTREAMS_THREAD_SAFE
rspamd_mutex_t *lock;
@@ -146,20 +146,20 @@ INIT_LOG_MODULE(upstream)
/* 4 errors in 10 seconds */
#define DEFAULT_MAX_ERRORS 4
-static const guint default_max_errors = DEFAULT_MAX_ERRORS;
+static const unsigned int default_max_errors = DEFAULT_MAX_ERRORS;
#define DEFAULT_REVIVE_TIME 60
-static const gdouble default_revive_time = DEFAULT_REVIVE_TIME;
+static const double default_revive_time = DEFAULT_REVIVE_TIME;
#define DEFAULT_REVIVE_JITTER 0.4
-static const gdouble default_revive_jitter = DEFAULT_REVIVE_JITTER;
+static const double default_revive_jitter = DEFAULT_REVIVE_JITTER;
#define DEFAULT_ERROR_TIME 10
-static const gdouble default_error_time = DEFAULT_ERROR_TIME;
+static const double default_error_time = DEFAULT_ERROR_TIME;
#define DEFAULT_DNS_TIMEOUT 1.0
-static const gdouble default_dns_timeout = DEFAULT_DNS_TIMEOUT;
+static const double default_dns_timeout = DEFAULT_DNS_TIMEOUT;
#define DEFAULT_DNS_RETRANSMITS 2
-static const guint default_dns_retransmits = DEFAULT_DNS_RETRANSMITS;
+static const unsigned int default_dns_retransmits = DEFAULT_DNS_RETRANSMITS;
/* TODO: make it configurable */
#define DEFAULT_LAZY_RESOLVE_TIME 3600.0
-static const gdouble default_lazy_resolve_time = DEFAULT_LAZY_RESOLVE_TIME;
+static const double default_lazy_resolve_time = DEFAULT_LAZY_RESOLVE_TIME;
static const struct upstream_limits default_limits = {
.revive_time = DEFAULT_REVIVE_TIME,
@@ -215,7 +215,7 @@ void rspamd_upstreams_library_config(struct rspamd_config *cfg,
upstream = cur->data;
if (!ev_can_stop(&upstream->ev) && upstream->ls &&
!(upstream->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) {
- gdouble when;
+ double when;
if (upstream->flags & RSPAMD_UPSTREAM_FLAG_SRV_RESOLVE) {
/* Resolve them immediately ! */
@@ -278,7 +278,7 @@ rspamd_upstreams_library_init(void)
return ctx;
}
-static gint
+static int
rspamd_upstream_af_to_weight(const rspamd_inet_addr_t *addr)
{
int ret;
@@ -301,12 +301,12 @@ rspamd_upstream_af_to_weight(const rspamd_inet_addr_t *addr)
/*
* Select IPv4 addresses before IPv6
*/
-static gint
+static int
rspamd_upstream_addr_sort_func(gconstpointer a, gconstpointer b)
{
const struct upstream_addr_elt *ip1 = *(const struct upstream_addr_elt **) a,
*ip2 = *(const struct upstream_addr_elt **) b;
- gint w1, w2;
+ int w1, w2;
if (ip1->priority == 0 && ip2->priority == 0) {
w1 = rspamd_upstream_af_to_weight(ip1->addr);
@@ -336,7 +336,7 @@ rspamd_upstream_set_active(struct upstream_list *ls, struct upstream *upstream)
}
/* Start lazy (or not so lazy) names resolution */
- gdouble when;
+ double when;
if (upstream->flags & RSPAMD_UPSTREAM_FLAG_SRV_RESOLVE) {
/* Resolve them immediately ! */
@@ -371,7 +371,7 @@ rspamd_upstream_addr_elt_dtor(gpointer a)
static void
rspamd_upstream_update_addrs(struct upstream *upstream)
{
- guint addr_cnt, i, port;
+ unsigned int addr_cnt, i, port;
gboolean seen_addr, reset_errors = FALSE;
struct upstream_inet_addr_entry *cur, *tmp;
GPtrArray *new_addrs;
@@ -500,9 +500,9 @@ rspamd_upstream_dns_cb(struct rdns_reply *reply, void *arg)
struct rspamd_upstream_srv_dns_cb {
struct upstream *up;
- guint priority;
- guint port;
- guint requests_inflight;
+ unsigned int priority;
+ unsigned int port;
+ unsigned int requests_inflight;
};
/* Used when we have resolved SRV record and resolved addrs */
@@ -642,14 +642,14 @@ rspamd_upstream_resolve_addrs(const struct upstream_list *ls,
struct upstream *upstream)
{
/* XXX: maybe make it configurable */
- static const gdouble min_resolve_interval = 60.0;
+ static const double min_resolve_interval = 60.0;
if (upstream->ctx->res != NULL &&
upstream->ctx->configured &&
upstream->dns_requests == 0 &&
!(upstream->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) {
- gdouble now = ev_now(upstream->ctx->event_loop);
+ double now = ev_now(upstream->ctx->event_loop);
if (now - upstream->last_resolve < min_resolve_interval) {
msg_info_upstream("do not resolve upstream %s as it was checked %.0f "
@@ -751,8 +751,8 @@ rspamd_upstream_lazy_resolve_cb(struct ev_loop *loop, ev_timer *w, int revents)
static void
rspamd_upstream_set_inactive(struct upstream_list *ls, struct upstream *upstream)
{
- gdouble ntim;
- guint i;
+ double ntim;
+ unsigned int i;
struct upstream *cur;
struct upstream_list_watcher *w;
@@ -799,10 +799,10 @@ rspamd_upstream_set_inactive(struct upstream_list *ls, struct upstream *upstream
void rspamd_upstream_fail(struct upstream *upstream,
gboolean addr_failure,
- const gchar *reason)
+ const char *reason)
{
- gdouble error_rate = 0, max_error_rate = 0;
- gdouble sec_last, sec_cur;
+ double error_rate = 0, max_error_rate = 0;
+ double sec_last, sec_cur;
struct upstream_addr_elt *addr_elt;
struct upstream_list_watcher *w;
@@ -847,8 +847,8 @@ void rspamd_upstream_fail(struct upstream *upstream,
}
if (sec_cur - sec_last >= upstream->ls->limits->error_time) {
- error_rate = ((gdouble) upstream->errors) / (sec_cur - sec_last);
- max_error_rate = ((gdouble) upstream->ls->limits->max_errors) /
+ error_rate = ((double) upstream->errors) / (sec_cur - sec_last);
+ max_error_rate = ((double) upstream->ls->limits->max_errors) /
upstream->ls->limits->error_time;
}
@@ -942,7 +942,7 @@ void rspamd_upstream_ok(struct upstream *upstream)
RSPAMD_UPSTREAM_UNLOCK(upstream);
}
-void rspamd_upstream_set_weight(struct upstream *up, guint weight)
+void rspamd_upstream_set_weight(struct upstream *up, unsigned int weight)
{
RSPAMD_UPSTREAM_LOCK(up);
up->weight = weight;
@@ -1026,7 +1026,7 @@ rspamd_upstream_dtor(struct upstream *up)
rspamd_inet_addr_t *
rspamd_upstream_addr_next(struct upstream *up)
{
- guint idx, next_idx;
+ unsigned int idx, next_idx;
struct upstream_addr_elt *e1, *e2;
do {
@@ -1050,13 +1050,13 @@ rspamd_upstream_addr_cur(const struct upstream *up)
return elt->addr;
}
-const gchar *
+const char *
rspamd_upstream_name(struct upstream *up)
{
return up->name;
}
-gint rspamd_upstream_port(struct upstream *up)
+int rspamd_upstream_port(struct upstream *up)
{
struct upstream_addr_elt *elt;
@@ -1065,13 +1065,13 @@ gint rspamd_upstream_port(struct upstream *up)
}
gboolean
-rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str,
- guint16 def_port, enum rspamd_upstream_parse_type parse_type,
+rspamd_upstreams_add_upstream(struct upstream_list *ups, const char *str,
+ uint16_t def_port, enum rspamd_upstream_parse_type parse_type,
void *data)
{
struct upstream *upstream;
GPtrArray *addrs = NULL;
- guint i, slen;
+ unsigned int i, slen;
rspamd_inet_addr_t *addr;
enum rspamd_parse_host_port_result ret = RSPAMD_PARSE_ADDR_FAIL;
@@ -1082,7 +1082,7 @@ rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str,
case RSPAMD_UPSTREAM_PARSE_DEFAULT:
if (slen > sizeof("service=") &&
RSPAMD_LEN_CHECK_STARTS_WITH(str, slen, "service=")) {
- const gchar *plus_pos, *service_pos, *semicolon_pos;
+ const char *plus_pos, *service_pos, *semicolon_pos;
/* Accept service=srv_name+hostname[:priority] */
service_pos = str + sizeof("service=") - 1;
@@ -1103,17 +1103,17 @@ rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str,
* where <domain> is string between semicolon_pos and plus_pos +1
* while service is a string between service_pos and plus_pos
*/
- guint namelen = (semicolon_pos - (plus_pos + 1)) +
- (plus_pos - service_pos) +
- (sizeof("tcp") - 1) +
- 4;
+ unsigned int namelen = (semicolon_pos - (plus_pos + 1)) +
+ (plus_pos - service_pos) +
+ (sizeof("tcp") - 1) +
+ 4;
addrs = g_ptr_array_sized_new(1);
upstream->name = ups->ctx ? rspamd_mempool_alloc(ups->ctx->pool, namelen + 1) : g_malloc(namelen + 1);
rspamd_snprintf(upstream->name, namelen + 1,
"_%*s._tcp.%*s",
- (gint) (plus_pos - service_pos), service_pos,
- (gint) (semicolon_pos - (plus_pos + 1)), plus_pos + 1);
+ (int) (plus_pos - service_pos), service_pos,
+ (int) (semicolon_pos - (plus_pos + 1)), plus_pos + 1);
upstream->flags |= RSPAMD_UPSTREAM_FLAG_SRV_RESOLVE;
ret = RSPAMD_PARSE_ADDR_RESOLVED;
}
@@ -1200,10 +1200,10 @@ rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str,
upstream->ctx_pos = g_queue_peek_tail_link(ups->ctx->upstreams);
}
- guint h = rspamd_cryptobox_fast_hash(upstream->name,
- strlen(upstream->name), 0);
+ unsigned int h = rspamd_cryptobox_fast_hash(upstream->name,
+ strlen(upstream->name), 0);
memset(upstream->uid, 0, sizeof(upstream->uid));
- rspamd_encode_base32_buf((const guchar *) &h, sizeof(h),
+ rspamd_encode_base32_buf((const unsigned char *) &h, sizeof(h),
upstream->uid, sizeof(upstream->uid) - 1, RSPAMD_BASE32_DEFAULT);
msg_debug_upstream("added upstream %s (%s)", upstream->name,
@@ -1247,12 +1247,12 @@ rspamd_upstream_add_addr(struct upstream *up, rspamd_inet_addr_t *addr)
gboolean
rspamd_upstreams_parse_line_len(struct upstream_list *ups,
- const gchar *str, gsize len, guint16 def_port, void *data)
+ const char *str, gsize len, uint16_t def_port, void *data)
{
- const gchar *end = str + len, *p = str;
- const gchar *separators = ";, \n\r\t";
- gchar *tmp;
- guint span_len;
+ const char *end = str + len, *p = str;
+ const char *separators = ";, \n\r\t";
+ char *tmp;
+ unsigned int span_len;
gboolean ret = FALSE;
if (RSPAMD_LEN_CHECK_STARTS_WITH(p, len, "random:")) {
@@ -1306,7 +1306,7 @@ rspamd_upstreams_parse_line_len(struct upstream_list *ups,
gboolean
rspamd_upstreams_parse_line(struct upstream_list *ups,
- const gchar *str, guint16 def_port, void *data)
+ const char *str, uint16_t def_port, void *data)
{
return rspamd_upstreams_parse_line_len(ups, str, strlen(str),
def_port, data);
@@ -1314,7 +1314,7 @@ rspamd_upstreams_parse_line(struct upstream_list *ups,
gboolean
rspamd_upstreams_from_ucl(struct upstream_list *ups,
- const ucl_object_t *in, guint16 def_port, void *data)
+ const ucl_object_t *in, uint16_t def_port, void *data)
{
gboolean ret = FALSE;
const ucl_object_t *cur;
@@ -1336,7 +1336,7 @@ rspamd_upstreams_from_ucl(struct upstream_list *ups,
void rspamd_upstreams_destroy(struct upstream_list *ups)
{
- guint i;
+ unsigned int i;
struct upstream *up;
struct upstream_list_watcher *w, *tmp;
@@ -1401,7 +1401,7 @@ rspamd_upstream_get_random(struct upstream_list *ups,
struct upstream *except)
{
for (;;) {
- guint idx = ottery_rand_range(ups->alive->len - 1);
+ unsigned int idx = ottery_rand_range(ups->alive->len - 1);
struct upstream *up;
up = g_ptr_array_index(ups->alive, idx);
@@ -1419,9 +1419,9 @@ rspamd_upstream_get_round_robin(struct upstream_list *ups,
struct upstream *except,
gboolean use_cur)
{
- guint max_weight = 0, min_checked = G_MAXUINT;
+ unsigned int max_weight = 0, min_checked = G_MAXUINT;
struct upstream *up = NULL, *selected = NULL, *min_checked_sel = NULL;
- guint i;
+ unsigned int i;
/* Select upstream with the maximum cur_weight */
RSPAMD_UPSTREAM_LOCK(ups);
@@ -1509,11 +1509,11 @@ rspamd_consistent_hash(uint64_t key, uint32_t nbuckets)
static struct upstream *
rspamd_upstream_get_hashed(struct upstream_list *ups,
struct upstream *except,
- const guint8 *key, guint keylen)
+ const uint8_t *key, unsigned int keylen)
{
uint64_t k;
uint32_t idx;
- static const guint max_tries = 20;
+ static const unsigned int max_tries = 20;
struct upstream *up = NULL;
/* Generate 64 bits input key */
@@ -1524,7 +1524,7 @@ rspamd_upstream_get_hashed(struct upstream_list *ups,
/*
* Select new upstream from all upstreams
*/
- for (guint i = 0; i < max_tries; i++) {
+ for (unsigned int i = 0; i < max_tries; i++) {
idx = rspamd_consistent_hash(k, ups->ups->len);
up = g_ptr_array_index(ups->ups, idx);
@@ -1554,7 +1554,7 @@ static struct upstream *
rspamd_upstream_get_common(struct upstream_list *ups,
struct upstream *except,
enum rspamd_upstream_rotation default_type,
- const guchar *key, gsize keylen,
+ const unsigned char *key, gsize keylen,
gboolean forced)
{
enum rspamd_upstream_rotation type;
@@ -1622,7 +1622,7 @@ end:
struct upstream *
rspamd_upstream_get(struct upstream_list *ups,
enum rspamd_upstream_rotation default_type,
- const guchar *key, gsize keylen)
+ const unsigned char *key, gsize keylen)
{
return rspamd_upstream_get_common(ups, NULL, default_type, key, keylen, FALSE);
}
@@ -1630,7 +1630,7 @@ rspamd_upstream_get(struct upstream_list *ups,
struct upstream *
rspamd_upstream_get_forced(struct upstream_list *ups,
enum rspamd_upstream_rotation forced_type,
- const guchar *key, gsize keylen)
+ const unsigned char *key, gsize keylen)
{
return rspamd_upstream_get_common(ups, NULL, forced_type, key, keylen, TRUE);
}
@@ -1638,7 +1638,7 @@ rspamd_upstream_get_forced(struct upstream_list *ups,
struct upstream *rspamd_upstream_get_except(struct upstream_list *ups,
struct upstream *except,
enum rspamd_upstream_rotation default_type,
- const guchar *key, gsize keylen)
+ const unsigned char *key, gsize keylen)
{
return rspamd_upstream_get_common(ups, except, default_type, key, keylen, FALSE);
}
@@ -1679,7 +1679,7 @@ void rspamd_upstreams_foreach(struct upstream_list *ups,
rspamd_upstream_traverse_func cb, void *ud)
{
struct upstream *up;
- guint i;
+ unsigned int i;
for (i = 0; i < ups->ups->len; i++) {
up = g_ptr_array_index(ups->ups, i);
@@ -1689,12 +1689,12 @@ void rspamd_upstreams_foreach(struct upstream_list *ups,
}
void rspamd_upstreams_set_limits(struct upstream_list *ups,
- gdouble revive_time,
- gdouble revive_jitter,
- gdouble error_time,
- gdouble dns_timeout,
- guint max_errors,
- guint dns_retransmits)
+ double revive_time,
+ double revive_jitter,
+ double error_time,
+ double dns_timeout,
+ unsigned int max_errors,
+ unsigned int dns_retransmits)
{
struct upstream_limits *nlimits;
g_assert(ups != NULL);
diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h
index 22a020c9c..60c658a6f 100644
--- a/src/libutil/upstream.h
+++ b/src/libutil/upstream.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@ void rspamd_upstreams_library_config(struct rspamd_config *cfg,
/**
* Add an error to an upstream
*/
-void rspamd_upstream_fail(struct upstream *upstream, gboolean addr_failure, const gchar *reason);
+void rspamd_upstream_fail(struct upstream *upstream, gboolean addr_failure, const char *reason);
/**
* Increase upstream successes count
@@ -90,7 +90,7 @@ void rspamd_upstream_ok(struct upstream *up);
* Set weight for an upstream
* @param up
*/
-void rspamd_upstream_set_weight(struct upstream *up, guint weight);
+void rspamd_upstream_set_weight(struct upstream *up, unsigned int weight);
/**
* Create new list of upstreams
@@ -119,12 +119,12 @@ void rspamd_upstreams_set_flags(struct upstream_list *ups,
* @param dns_retransmits
*/
void rspamd_upstreams_set_limits(struct upstream_list *ups,
- gdouble revive_time,
- gdouble revive_jitter,
- gdouble error_time,
- gdouble dns_timeout,
- guint max_errors,
- guint dns_retransmits);
+ double revive_time,
+ double revive_jitter,
+ double error_time,
+ double dns_timeout,
+ unsigned int max_errors,
+ unsigned int dns_retransmits);
/**
* Sets rotation policy for upstreams list
@@ -167,8 +167,8 @@ enum rspamd_upstream_parse_type {
* @param data optional userdata
* @return TRUE if upstream has been added
*/
-gboolean rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str,
- guint16 def_port, enum rspamd_upstream_parse_type parse_type,
+gboolean rspamd_upstreams_add_upstream(struct upstream_list *ups, const char *str,
+ uint16_t def_port, enum rspamd_upstream_parse_type parse_type,
void *data);
/**
@@ -180,12 +180,12 @@ gboolean rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *s
* @return TRUE if **any** of upstreams has been added
*/
gboolean rspamd_upstreams_parse_line(struct upstream_list *ups,
- const gchar *str, guint16 def_port, void *data);
+ const char *str, uint16_t def_port, void *data);
gboolean rspamd_upstreams_parse_line_len(struct upstream_list *ups,
- const gchar *str, gsize len,
- guint16 def_port,
+ const char *str, gsize len,
+ uint16_t def_port,
void *data);
/**
@@ -197,10 +197,10 @@ gboolean rspamd_upstreams_parse_line_len(struct upstream_list *ups,
* @return
*/
gboolean rspamd_upstreams_from_ucl(struct upstream_list *ups,
- const ucl_object_t *in, guint16 def_port, void *data);
+ const ucl_object_t *in, uint16_t def_port, void *data);
-typedef void (*rspamd_upstream_traverse_func)(struct upstream *up, guint idx,
+typedef void (*rspamd_upstream_traverse_func)(struct upstream *up, unsigned int idx,
void *ud);
/**
@@ -222,7 +222,7 @@ enum rspamd_upstreams_watch_event {
typedef void (*rspamd_upstream_watch_func)(struct upstream *up,
enum rspamd_upstreams_watch_event event,
- guint cur_errors,
+ unsigned int cur_errors,
void *ud);
/**
@@ -265,14 +265,14 @@ gboolean rspamd_upstream_add_addr(struct upstream *up,
* @param up
* @return
*/
-const gchar *rspamd_upstream_name(struct upstream *up);
+const char *rspamd_upstream_name(struct upstream *up);
/**
* Returns the port of the current address for the upstream
* @param up
* @return
*/
-gint rspamd_upstream_port(struct upstream *up);
+int rspamd_upstream_port(struct upstream *up);
/**
* Sets opaque user data associated with this upstream
@@ -297,7 +297,7 @@ gpointer rspamd_upstream_get_data(struct upstream *up);
*/
struct upstream *rspamd_upstream_get(struct upstream_list *ups,
enum rspamd_upstream_rotation default_type,
- const guchar *key, gsize keylen);
+ const unsigned char *key, gsize keylen);
/**
* Get new upstream from the list
@@ -307,7 +307,7 @@ struct upstream *rspamd_upstream_get(struct upstream_list *ups,
*/
struct upstream *rspamd_upstream_get_forced(struct upstream_list *ups,
enum rspamd_upstream_rotation forced_type,
- const guchar *key, gsize keylen);
+ const unsigned char *key, gsize keylen);
/**
* Get new upstream from the list excepting the upstream specified
@@ -318,7 +318,7 @@ struct upstream *rspamd_upstream_get_forced(struct upstream_list *ups,
struct upstream *rspamd_upstream_get_except(struct upstream_list *ups,
struct upstream *except,
enum rspamd_upstream_rotation default_type,
- const guchar *key, gsize keylen);
+ const unsigned char *key, gsize keylen);
/**
* Re-resolve addresses for all upstreams registered
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 10aeebf45..b585a2690 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -94,9 +94,9 @@ const struct rspamd_controller_pbkdf pbkdf_list[] = {
.salt_len = 20,
.key_len = rspamd_cryptobox_HASHBYTES / 2}};
-gint rspamd_socket_nonblocking(gint fd)
+int rspamd_socket_nonblocking(int fd)
{
- gint ofl;
+ int ofl;
ofl = fcntl(fd, F_GETFL, 0);
@@ -106,9 +106,9 @@ gint rspamd_socket_nonblocking(gint fd)
return 0;
}
-gint rspamd_socket_blocking(gint fd)
+int rspamd_socket_blocking(int fd)
{
- gint ofl;
+ int ofl;
ofl = fcntl(fd, F_GETFL, 0);
@@ -118,9 +118,9 @@ gint rspamd_socket_blocking(gint fd)
return 0;
}
-gint rspamd_socket_poll(gint fd, gint timeout, short events)
+int rspamd_socket_poll(int fd, int timeout, short events)
{
- gint r;
+ int r;
struct pollfd fds[1];
fds->fd = fd;
@@ -135,9 +135,9 @@ gint rspamd_socket_poll(gint fd, gint timeout, short events)
return r;
}
-gint rspamd_socket_create(gint af, gint type, gint protocol, gboolean async)
+int rspamd_socket_create(int af, int type, int protocol, gboolean async)
{
- gint fd;
+ int fd;
fd = socket(af, type, protocol);
if (fd == -1) {
@@ -159,11 +159,11 @@ gint rspamd_socket_create(gint af, gint type, gint protocol, gboolean async)
return fd;
}
-static gint
-rspamd_inet_socket_create(gint type, struct addrinfo *addr, gboolean is_server,
+static int
+rspamd_inet_socket_create(int type, struct addrinfo *addr, gboolean is_server,
gboolean async, GList **list)
{
- gint fd = -1, r, on = 1, s_error;
+ int fd = -1, r, on = 1, s_error;
struct addrinfo *cur;
gpointer ptr;
socklen_t optlen;
@@ -178,11 +178,11 @@ rspamd_inet_socket_create(gint type, struct addrinfo *addr, gboolean is_server,
if (is_server) {
(void) setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on,
- sizeof(gint));
+ sizeof(int));
#ifdef HAVE_IPV6_V6ONLY
if (cur->ai_family == AF_INET6) {
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *) &on,
- sizeof(gint));
+ sizeof(int));
}
#endif
r = bind(fd, cur->ai_addr, cur->ai_addrlen);
@@ -242,25 +242,25 @@ rspamd_inet_socket_create(gint type, struct addrinfo *addr, gboolean is_server,
return (fd);
}
-gint rspamd_socket_tcp(struct addrinfo *addr, gboolean is_server, gboolean async)
+int rspamd_socket_tcp(struct addrinfo *addr, gboolean is_server, gboolean async)
{
return rspamd_inet_socket_create(SOCK_STREAM, addr, is_server, async, NULL);
}
-gint rspamd_socket_udp(struct addrinfo *addr, gboolean is_server, gboolean async)
+int rspamd_socket_udp(struct addrinfo *addr, gboolean is_server, gboolean async)
{
return rspamd_inet_socket_create(SOCK_DGRAM, addr, is_server, async, NULL);
}
-gint rspamd_socket_unix(const gchar *path,
- struct sockaddr_un *addr,
- gint type,
- gboolean is_server,
- gboolean async)
+int rspamd_socket_unix(const char *path,
+ struct sockaddr_un *addr,
+ int type,
+ gboolean is_server,
+ gboolean async)
{
socklen_t optlen;
- gint fd = -1, s_error, r, serrno, on = 1;
+ int fd = -1, s_error, r, serrno, on = 1;
struct stat st;
if (path == NULL)
@@ -302,7 +302,7 @@ gint rspamd_socket_unix(const gchar *path,
}
if (is_server) {
(void) setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on,
- sizeof(gint));
+ sizeof(int));
r = bind(fd, (struct sockaddr *) addr, SUN_LEN(addr));
}
else {
@@ -365,14 +365,14 @@ rspamd_prefer_v4_hack(const struct addrinfo *a1, const struct addrinfo *a2)
* @param is_server make this socket as server socket
* @param try_resolve try name resolution for a socket (BLOCKING)
*/
-gint rspamd_socket(const gchar *credits, guint16 port,
- gint type, gboolean async, gboolean is_server, gboolean try_resolve)
+int rspamd_socket(const char *credits, uint16_t port,
+ int type, gboolean async, gboolean is_server, gboolean try_resolve)
{
struct sockaddr_un un;
struct stat st;
struct addrinfo hints, *res;
- gint r;
- gchar portbuf[8];
+ int r;
+ char portbuf[8];
if (*credits == '/') {
if (is_server) {
@@ -430,9 +430,9 @@ gint rspamd_socket(const gchar *credits, guint16 port,
}
gboolean
-rspamd_socketpair(gint pair[2], gint af)
+rspamd_socketpair(int pair[2], int af)
{
- gint r = -1, serrno;
+ int r = -1, serrno;
#ifdef HAVE_SOCK_SEQPACKET
if (af == SOCK_SEQPACKET) {
@@ -471,11 +471,11 @@ out:
}
#ifdef HAVE_SA_SIGINFO
-void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(gint,
+void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(int,
siginfo_t *,
void *))
#else
-void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(gint))
+void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(int))
#endif
{
struct sigaction sigpipe_act;
@@ -530,10 +530,10 @@ void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(gint))
#ifndef HAVE_SETPROCTITLE
#ifdef LINUX
-static gchar *title_buffer = NULL;
+static char *title_buffer = NULL;
static size_t title_buffer_size = 0;
-static gchar *title_progname, *title_progname_full;
-gchar **old_environ = NULL;
+static char *title_progname, *title_progname_full;
+char **old_environ = NULL;
static void
rspamd_title_dtor(gpointer d)
@@ -543,8 +543,8 @@ rspamd_title_dtor(gpointer d)
environ = old_environ;
}
- gchar **env = (gchar **) d;
- guint i;
+ char **env = (char **) d;
+ unsigned int i;
for (i = 0; env[i] != NULL; i++) {
g_free(env[i]);
@@ -556,12 +556,12 @@ rspamd_title_dtor(gpointer d)
#endif /* ifndef HAVE_SETPROCTITLE */
-gint rspamd_init_title(rspamd_mempool_t *pool,
- gint argc, gchar *argv[], gchar *envp[])
+int rspamd_init_title(rspamd_mempool_t *pool,
+ int argc, char *argv[], char *envp[])
{
#if defined(LINUX) && !defined(HAVE_SETPROCTITLE)
- gchar *begin_of_buffer = 0, *end_of_buffer = 0;
- gint i;
+ char *begin_of_buffer = 0, *end_of_buffer = 0;
+ int i;
for (i = 0; i < argc; ++i) {
if (!begin_of_buffer) {
@@ -585,7 +585,7 @@ gint rspamd_init_title(rspamd_mempool_t *pool,
return 0;
}
- gchar **new_environ = g_malloc((i + 1) * sizeof(envp[0]));
+ char **new_environ = g_malloc((i + 1) * sizeof(envp[0]));
for (i = 0; envp[i]; ++i) {
new_environ[i] = g_strdup(envp[i]);
@@ -596,7 +596,7 @@ gint rspamd_init_title(rspamd_mempool_t *pool,
if (program_invocation_name) {
title_progname_full = g_strdup(program_invocation_name);
- gchar *p = strrchr(title_progname_full, '/');
+ char *p = strrchr(title_progname_full, '/');
if (p) {
title_progname = p + 1;
@@ -622,7 +622,7 @@ gint rspamd_init_title(rspamd_mempool_t *pool,
return 0;
}
-gint rspamd_setproctitle(const gchar *fmt, ...)
+int rspamd_setproctitle(const char *fmt, ...)
{
#ifdef HAVE_SETPROCTITLE
if (fmt) {
@@ -697,9 +697,9 @@ gint rspamd_setproctitle(const gchar *fmt, ...)
#ifndef HAVE_PIDFILE
-static gint _rspamd_pidfile_remove(rspamd_pidfh_t *pfh, gint freeit);
+static int _rspamd_pidfile_remove(rspamd_pidfh_t *pfh, int freeit);
-static gint
+static int
rspamd_pidfile_verify(rspamd_pidfh_t *pfh)
{
struct stat sb;
@@ -716,11 +716,11 @@ rspamd_pidfile_verify(rspamd_pidfh_t *pfh)
return 0;
}
-static gint
-rspamd_pidfile_read(const gchar *path, pid_t *pidptr)
+static int
+rspamd_pidfile_read(const char *path, pid_t *pidptr)
{
- gchar buf[16], *endptr;
- gint error, fd, i;
+ char buf[16], *endptr;
+ int error, fd, i;
fd = open(path, O_RDONLY);
if (fd == -1)
@@ -743,11 +743,11 @@ rspamd_pidfile_read(const gchar *path, pid_t *pidptr)
}
rspamd_pidfh_t *
-rspamd_pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr)
+rspamd_pidfile_open(const char *path, mode_t mode, pid_t *pidptr)
{
rspamd_pidfh_t *pfh;
struct stat sb;
- gint error, fd, len, count;
+ int error, fd, len, count;
struct timespec rqtp;
pfh = g_malloc(sizeof(*pfh));
@@ -761,7 +761,7 @@ rspamd_pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr)
g_get_prgname());
else
len = snprintf(pfh->pf_path, sizeof(pfh->pf_path), "%s", path);
- if (len >= (gint) sizeof(pfh->pf_path)) {
+ if (len >= (int) sizeof(pfh->pf_path)) {
g_free(pfh);
errno = ENAMETOOLONG;
return NULL;
@@ -814,10 +814,10 @@ rspamd_pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr)
return pfh;
}
-gint rspamd_pidfile_write(rspamd_pidfh_t *pfh)
+int rspamd_pidfile_write(rspamd_pidfh_t *pfh)
{
- gchar pidstr[16];
- gint error, fd;
+ char pidstr[16];
+ int error, fd;
/*
* Check remembered descriptor, so we don't overwrite some other
@@ -853,9 +853,9 @@ gint rspamd_pidfile_write(rspamd_pidfh_t *pfh)
return 0;
}
-gint rspamd_pidfile_close(rspamd_pidfh_t *pfh)
+int rspamd_pidfile_close(rspamd_pidfh_t *pfh)
{
- gint error;
+ int error;
error = rspamd_pidfile_verify(pfh);
if (error != 0) {
@@ -873,10 +873,10 @@ gint rspamd_pidfile_close(rspamd_pidfh_t *pfh)
return 0;
}
-static gint
-_rspamd_pidfile_remove(rspamd_pidfh_t *pfh, gint freeit)
+static int
+_rspamd_pidfile_remove(rspamd_pidfh_t *pfh, int freeit)
{
- gint error;
+ int error;
error = rspamd_pidfile_verify(pfh);
if (error != 0) {
@@ -905,7 +905,7 @@ _rspamd_pidfile_remove(rspamd_pidfh_t *pfh, gint freeit)
return 0;
}
-gint rspamd_pidfile_remove(rspamd_pidfh_t *pfh)
+int rspamd_pidfile_remove(rspamd_pidfh_t *pfh)
{
return (_rspamd_pidfile_remove(pfh, 1));
@@ -913,15 +913,15 @@ gint rspamd_pidfile_remove(rspamd_pidfh_t *pfh)
#endif
/* Replace %r with rcpt value and %f with from value, new string is allocated in pool */
-gchar *
+char *
resolve_stat_filename(rspamd_mempool_t *pool,
- gchar *pattern,
- gchar *rcpt,
- gchar *from)
+ char *pattern,
+ char *rcpt,
+ char *from)
{
- gint need_to_format = 0, len = 0;
- gint rcptlen, fromlen;
- gchar *c = pattern, *new, *s;
+ int need_to_format = 0, len = 0;
+ int rcptlen, fromlen;
+ char *c = pattern, *new, *s;
if (rcpt) {
rcptlen = strlen(rcpt);
@@ -980,28 +980,28 @@ resolve_stat_filename(rspamd_mempool_t *pool,
return new;
}
-const gchar *
-rspamd_log_check_time(gdouble start, gdouble end, gint resolution)
+const char *
+rspamd_log_check_time(double start, double end, int resolution)
{
- gdouble diff;
- static gchar res[64];
- gchar fmt[32];
+ double diff;
+ static char res[64];
+ char fmt[32];
diff = (end - start) * 1000.0;
rspamd_snprintf(fmt, sizeof(fmt), "%%.%dfms", resolution);
rspamd_snprintf(res, sizeof(res), fmt, diff);
- return (const gchar *) res;
+ return (const char *) res;
}
#ifdef HAVE_FLOCK
/* Flock version */
gboolean
-rspamd_file_lock(gint fd, gboolean async)
+rspamd_file_lock(int fd, gboolean async)
{
- gint flags;
+ int flags;
if (async) {
flags = LOCK_EX | LOCK_NB;
@@ -1018,9 +1018,9 @@ rspamd_file_lock(gint fd, gboolean async)
}
gboolean
-rspamd_file_unlock(gint fd, gboolean async)
+rspamd_file_unlock(int fd, gboolean async)
{
- gint flags;
+ int flags;
if (async) {
flags = LOCK_UN | LOCK_NB;
@@ -1042,7 +1042,7 @@ rspamd_file_unlock(gint fd, gboolean async)
#else /* HAVE_FLOCK */
/* Fctnl version */
gboolean
-rspamd_file_lock(gint fd, gboolean async)
+rspamd_file_lock(int fd, gboolean async)
{
struct flock fl = {
.l_type = F_WRLCK,
@@ -1062,7 +1062,7 @@ rspamd_file_lock(gint fd, gboolean async)
}
gboolean
-rspamd_file_unlock(gint fd, gboolean async)
+rspamd_file_unlock(int fd, gboolean async)
{
struct flock fl = {
.l_type = F_UNLCK,
@@ -1093,11 +1093,11 @@ g_int64_equal(gconstpointer v1, gconstpointer v2)
{
return *((const int64_t *) v1) == *((const int64_t *) v2);
}
-guint g_int64_hash(gconstpointer v)
+unsigned int g_int64_hash(gconstpointer v)
{
uint64_t v64 = *(uint64_t *) v;
- return (guint) (v ^ (v >> 32));
+ return (unsigned int) (v ^ (v >> 32));
}
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 14))
@@ -1112,7 +1112,7 @@ void g_queue_clear(GQueue *queue)
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 30))
GPtrArray *
-g_ptr_array_new_full(guint reserved_size,
+g_ptr_array_new_full(unsigned int reserved_size,
GDestroyNotify element_free_func)
{
GPtrArray *array;
@@ -1140,11 +1140,11 @@ void g_queue_free_full(GQueue *queue, GDestroyNotify free_func)
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 40))
-void g_ptr_array_insert(GPtrArray *array, gint index_, gpointer data)
+void g_ptr_array_insert(GPtrArray *array, int index_, gpointer data)
{
g_return_if_fail(array);
g_return_if_fail(index_ >= -1);
- g_return_if_fail(index_ <= (gint) array->len);
+ g_return_if_fail(index_ <= (int) array->len);
g_ptr_array_set_size(array, array->len + 1);
@@ -1162,11 +1162,11 @@ void g_ptr_array_insert(GPtrArray *array, gint index_, gpointer data)
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 32))
-const gchar *
-g_environ_getenv(gchar **envp, const gchar *variable)
+const char *
+g_environ_getenv(char **envp, const char *variable)
{
gsize len;
- gint i;
+ int i;
if (envp == NULL) {
return NULL;
@@ -1184,7 +1184,7 @@ g_environ_getenv(gchar **envp, const gchar *variable)
}
#endif
-gint rspamd_fallocate(gint fd, off_t offset, off_t len)
+int rspamd_fallocate(int fd, off_t offset, off_t len)
{
#if defined(HAVE_FALLOCATE)
return fallocate(fd, 0, offset, len);
@@ -1253,8 +1253,8 @@ void rspamd_mutex_free(rspamd_mutex_t *mtx)
}
struct rspamd_thread_data {
- gchar *name;
- gint id;
+ char *name;
+ int id;
GThreadFunc func;
gpointer data;
};
@@ -1340,7 +1340,7 @@ read_pass_tmp_sig_handler(int s)
#define _PATH_TTY "/dev/tty"
#endif
-gint rspamd_read_passphrase_with_prompt(const gchar *prompt, gchar *buf, gint size, bool echo, gpointer key)
+int rspamd_read_passphrase_with_prompt(const char *prompt, char *buf, int size, bool echo, gpointer key)
{
#ifdef HAVE_READPASSPHRASE_H
int flags = echo ? RPP_ECHO_ON : RPP_ECHO_OFF;
@@ -1353,8 +1353,8 @@ gint rspamd_read_passphrase_with_prompt(const gchar *prompt, gchar *buf, gint si
struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
struct sigaction savetstp, savettin, savettou, savepipe;
struct termios term, oterm;
- gint input, output, i;
- gchar *end, *p, ch;
+ int input, output, i;
+ char *end, *p, ch;
restart:
if ((input = output = open(_PATH_TTY, O_RDWR)) == -1) {
@@ -1460,10 +1460,10 @@ restart:
#endif
#endif
-gdouble
+double
rspamd_get_ticks(gboolean rdtsc_ok)
{
- gdouble res;
+ double res;
#ifdef HAVE_RDTSC
#ifdef __x86_64__
@@ -1480,7 +1480,7 @@ rspamd_get_ticks(gboolean rdtsc_ok)
#endif
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
- gint clk_id = RSPAMD_FAST_MONOTONIC_CLOCK;
+ int clk_id = RSPAMD_FAST_MONOTONIC_CLOCK;
clock_gettime(clk_id, &ts);
@@ -1512,10 +1512,10 @@ rspamd_get_ticks(gboolean rdtsc_ok)
return res;
}
-gdouble
+double
rspamd_get_virtual_ticks(void)
{
- gdouble res;
+ double res;
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
@@ -1548,7 +1548,7 @@ rspamd_get_virtual_ticks(void)
}
res = info.user_time.seconds + info.system_time.seconds;
- res += ((gdouble) (info.user_time.microseconds + info.system_time.microseconds)) / 1e6;
+ res += ((double) (info.user_time.microseconds + info.system_time.microseconds)) / 1e6;
mach_port_deallocate(mach_task_self(), thread);
#elif defined(HAVE_RUSAGE_SELF)
struct rusage rusage;
@@ -1563,10 +1563,10 @@ rspamd_get_virtual_ticks(void)
return res;
}
-gdouble
+double
rspamd_get_calendar_ticks(void)
{
- gdouble res;
+ double res;
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
@@ -1586,9 +1586,9 @@ rspamd_get_calendar_ticks(void)
return res;
}
-void rspamd_random_hex(gchar *buf, uint64_t len)
+void rspamd_random_hex(char *buf, uint64_t len)
{
- static const gchar hexdigests[16] = "0123456789abcdef";
+ static const char hexdigests[16] = "0123456789abcdef";
int64_t i;
g_assert(len > 0);
@@ -1604,10 +1604,10 @@ void rspamd_random_hex(gchar *buf, uint64_t len)
}
}
-gint rspamd_shmem_mkstemp(gchar *pattern)
+int rspamd_shmem_mkstemp(char *pattern)
{
- gint fd = -1;
- gchar *nbuf, *xpos;
+ int fd = -1;
+ char *nbuf, *xpos;
gsize blen;
xpos = strchr(pattern, 'X');
@@ -1718,7 +1718,7 @@ rspamd_hash_seed(void)
return 0xabf9727ba290690bULL;
}
-static inline gdouble
+static inline double
rspamd_double_from_int64(uint64_t x)
{
const union {
@@ -1730,7 +1730,7 @@ rspamd_double_from_int64(uint64_t x)
return u.d - 1.0;
}
-gdouble
+double
rspamd_random_double(void)
{
uint64_t rnd_int;
@@ -1791,14 +1791,14 @@ rspamd_random_uint64_fast_seed(uint64_t *seed)
#endif
}
-gdouble
+double
rspamd_random_double_fast(void)
{
return rspamd_random_double_fast_seed(rspamd_fast_random_seed());
}
/* xoshiro256+ */
-inline gdouble
+inline double
rspamd_random_double_fast_seed(uint64_t *seed)
{
return rspamd_double_from_int64(rspamd_random_uint64_fast_seed(seed));
@@ -1815,8 +1815,8 @@ void rspamd_random_seed_fast(void)
(void) rspamd_fast_random_seed();
}
-gdouble
-rspamd_time_jitter(gdouble in, gdouble jitter)
+double
+rspamd_time_jitter(double in, double jitter)
{
if (jitter == 0) {
jitter = in;
@@ -1829,10 +1829,10 @@ gboolean
rspamd_constant_memcmp(const void *a, const void *b, gsize len)
{
gsize lena, lenb, i;
- guint16 d, r = 0, m;
- guint16 v;
- const guint8 *aa = (const guint8 *) a,
- *bb = (const guint8 *) b;
+ uint16_t d, r = 0, m;
+ uint16_t v;
+ const uint8_t *aa = (const uint8_t *) a,
+ *bb = (const uint8_t *) b;
if (len == 0) {
lena = strlen((const char *) a);
@@ -1846,16 +1846,16 @@ rspamd_constant_memcmp(const void *a, const void *b, gsize len)
}
for (i = 0; i < len; i++) {
- v = ((guint16) (guint8) r) + 255;
+ v = ((uint16_t) (uint8_t) r) + 255;
m = v / 256 - 1;
- d = (guint16) ((int) aa[i] - (int) bb[i]);
+ d = (uint16_t) ((int) aa[i] - (int) bb[i]);
r |= (d & m);
}
- return (((int32_t) (guint16) ((uint32_t) r + 0x8000) - 0x8000) == 0);
+ return (((int32_t) (uint16_t) ((uint32_t) r + 0x8000) - 0x8000) == 0);
}
-int rspamd_file_xopen(const char *fname, int oflags, guint mode,
+int rspamd_file_xopen(const char *fname, int oflags, unsigned int mode,
gboolean allow_symlink)
{
struct stat sb;
@@ -1911,10 +1911,10 @@ int rspamd_file_xopen(const char *fname, int oflags, guint mode,
}
gpointer
-rspamd_file_xmap(const char *fname, guint mode, gsize *size,
+rspamd_file_xmap(const char *fname, unsigned int mode, gsize *size,
gboolean allow_symlink)
{
- gint fd;
+ int fd;
struct stat sb;
gpointer map;
@@ -1960,10 +1960,10 @@ rspamd_file_xmap(const char *fname, guint mode, gsize *size,
gpointer
-rspamd_shmem_xmap(const char *fname, guint mode,
+rspamd_shmem_xmap(const char *fname, unsigned int mode,
gsize *size)
{
- gint fd;
+ int fd;
struct stat sb;
gpointer map;
@@ -2019,10 +2019,10 @@ rspamd_shmem_xmap(const char *fname, guint mode,
* New approach:
* y = ((x - bias)*2)^8
*/
-gdouble
-rspamd_normalize_probability(gdouble x, gdouble bias)
+double
+rspamd_normalize_probability(double x, double bias)
{
- gdouble xx;
+ double xx;
xx = (x - bias) * 2.0;
@@ -2037,11 +2037,11 @@ rspamd_tm_to_time(const struct tm *tm, glong tz)
{
uint64_t result;
gboolean is_leap = FALSE;
- gint leaps, y = tm->tm_year, cycles, rem, centuries;
+ int leaps, y = tm->tm_year, cycles, rem, centuries;
glong offset = (tz / 100) * 3600 + (tz % 100) * 60;
/* How many seconds in each month from the beginning of the year */
- static const gint secs_through_month[] = {
+ static const int secs_through_month[] = {
0, 31 * 86400, 59 * 86400, 90 * 86400,
120 * 86400, 151 * 86400, 181 * 86400, 212 * 86400,
243 * 86400, 273 * 86400, 304 * 86400, 334 * 86400};
@@ -2102,7 +2102,7 @@ rspamd_tm_to_time(const struct tm *tm, glong tz)
}
}
- leaps += 97 * cycles + 24 * centuries - (gint) is_leap;
+ leaps += 97 * cycles + 24 * centuries - (int) is_leap;
result = (y - 100) * 31536000LL + leaps * 86400LL + 946684800 + 86400;
}
@@ -2350,16 +2350,16 @@ rspamd_fstring_gunzip(rspamd_fstring_t **in)
}
static gboolean
-rspamd_glob_dir(const gchar *full_path, const gchar *pattern,
- gboolean recursive, guint rec_len,
+rspamd_glob_dir(const char *full_path, const char *pattern,
+ gboolean recursive, unsigned int rec_len,
GPtrArray *res, GError **err)
{
glob_t globbuf;
- const gchar *path;
- static gchar pathbuf[PATH_MAX]; /* Static to help recursion */
- guint i;
- gint rc;
- static const guint rec_lim = 16;
+ const char *path;
+ static char pathbuf[PATH_MAX]; /* Static to help recursion */
+ unsigned int i;
+ int rc;
+ static const unsigned int rec_lim = 16;
struct stat st;
if (rec_len > rec_lim) {
@@ -2425,12 +2425,12 @@ rspamd_glob_dir(const gchar *full_path, const gchar *pattern,
}
GPtrArray *
-rspamd_glob_path(const gchar *dir,
- const gchar *pattern,
+rspamd_glob_path(const char *dir,
+ const char *pattern,
gboolean recursive,
GError **err)
{
- gchar path[PATH_MAX];
+ char path[PATH_MAX];
GPtrArray *res;
res = g_ptr_array_new_full(32, (GDestroyNotify) g_free);
@@ -2446,9 +2446,9 @@ rspamd_glob_path(const gchar *dir,
}
double
-rspamd_set_counter(struct rspamd_counter_data *cd, gdouble value)
+rspamd_set_counter(struct rspamd_counter_data *cd, double value)
{
- gdouble cerr;
+ double cerr;
/* Cumulative moving average using per-process counter data */
if (cd->number == 0) {
@@ -2456,9 +2456,9 @@ rspamd_set_counter(struct rspamd_counter_data *cd, gdouble value)
cd->stddev = 0;
}
- cd->mean += (value - cd->mean) / (gdouble) (++cd->number);
+ cd->mean += (value - cd->mean) / (double) (++cd->number);
cerr = (value - cd->mean) * (value - cd->mean);
- cd->stddev += (cerr - cd->stddev) / (gdouble) (cd->number);
+ cd->stddev += (cerr - cd->stddev) / (double) (cd->number);
return cd->mean;
}
@@ -2490,10 +2490,10 @@ void rspamd_ptr_array_shuffle(GPtrArray *ar)
return;
}
- guint n = ar->len;
+ unsigned int n = ar->len;
- for (guint i = 0; i < n - 1; i++) {
- guint j = i + rspamd_random_uint64_fast() % (n - i);
+ for (unsigned int i = 0; i < n - 1; i++) {
+ unsigned int j = i + rspamd_random_uint64_fast() % (n - i);
gpointer t = g_ptr_array_index(ar, j);
g_ptr_array_index(ar, j) = g_ptr_array_index(ar, i);
g_ptr_array_index(ar, i) = t;
@@ -2522,10 +2522,10 @@ float rspamd_sum_floats(float *ar, gsize *nelts)
return sum;
}
-void rspamd_normalize_path_inplace(gchar *path, guint len, gsize *nlen)
+void rspamd_normalize_path_inplace(char *path, unsigned int len, gsize *nlen)
{
- const gchar *p, *end, *slash = NULL, *dot = NULL;
- gchar *o;
+ const char *p, *end, *slash = NULL, *dot = NULL;
+ char *o;
enum {
st_normal = 0,
st_got_dot,
@@ -2637,7 +2637,7 @@ void rspamd_normalize_path_inplace(gchar *path, guint len, gsize *nlen)
}
if (slash) {
- o = (gchar *) slash;
+ o = (char *) slash;
}
/* Otherwise we keep these dots */
slash = p;
@@ -2701,7 +2701,7 @@ void rspamd_normalize_path_inplace(gchar *path, guint len, gsize *nlen)
if (slash) {
/* Remove last / */
- o = (gchar *) slash;
+ o = (char *) slash;
}
}
else {
diff --git a/src/libutil/util.h b/src/libutil/util.h
index 54e86d3bb..8531ce450 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -46,7 +46,7 @@ enum rspamd_exception_type {
*/
struct rspamd_process_exception {
goffset pos;
- guint len;
+ unsigned int len;
gpointer ptr;
enum rspamd_exception_type type;
};
@@ -59,26 +59,26 @@ struct rspamd_process_exception {
* @param async set non-blocking on a socket
* @return socket FD or -1 in case of error
*/
-gint rspamd_socket_create(gint af, gint type, gint protocol, gboolean async);
+int rspamd_socket_create(int af, int type, int protocol, gboolean async);
/*
* Create socket and bind or connect it to specified address and port
*/
-gint rspamd_socket_tcp(struct addrinfo *, gboolean is_server, gboolean async);
+int rspamd_socket_tcp(struct addrinfo *, gboolean is_server, gboolean async);
/*
* Create socket and bind or connect it to specified address and port
*/
-gint rspamd_socket_udp(struct addrinfo *, gboolean is_server, gboolean async);
+int rspamd_socket_udp(struct addrinfo *, gboolean is_server, gboolean async);
/*
* Create and bind or connect unix socket
*/
-gint rspamd_socket_unix(const gchar *,
- struct sockaddr_un *,
- gint type,
- gboolean is_server,
- gboolean async);
+int rspamd_socket_unix(const char *,
+ struct sockaddr_un *,
+ int type,
+ gboolean is_server,
+ gboolean async);
/**
* Make a universal socket
@@ -89,75 +89,75 @@ gint rspamd_socket_unix(const gchar *,
* @param is_server make this socket as server socket
* @param try_resolve try name resolution for a socket (BLOCKING)
*/
-gint rspamd_socket(const gchar *credits, guint16 port, gint type,
- gboolean async, gboolean is_server, gboolean try_resolve);
+int rspamd_socket(const char *credits, uint16_t port, int type,
+ gboolean async, gboolean is_server, gboolean try_resolve);
/*
* Create socketpair
*/
-gboolean rspamd_socketpair(gint pair[2], gint af);
+gboolean rspamd_socketpair(int pair[2], int af);
/*
* Make specified socket non-blocking
*/
-gint rspamd_socket_nonblocking(gint);
+int rspamd_socket_nonblocking(int);
/*
* Make specified socket blocking
*/
-gint rspamd_socket_blocking(gint);
+int rspamd_socket_blocking(int);
/*
* Poll a sync socket for specified events
*/
-gint rspamd_socket_poll(gint fd, gint timeout, short events);
+int rspamd_socket_poll(int fd, int timeout, short events);
/*
* Init signals
*/
#ifdef HAVE_SA_SIGINFO
-void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(gint,
+void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(int,
siginfo_t *,
void *));
#else
-void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(gint));
+void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(int));
#endif
/*
* Process title utility functions
*/
-gint rspamd_init_title(rspamd_mempool_t *pool, gint argc, gchar *argv[], gchar *envp[]);
-gint rspamd_setproctitle(const gchar *fmt, ...);
+int rspamd_init_title(rspamd_mempool_t *pool, int argc, char *argv[], char *envp[]);
+int rspamd_setproctitle(const char *fmt, ...);
#ifndef HAVE_PIDFILE
/*
* Pidfile functions from FreeBSD libutil code
*/
typedef struct rspamd_pidfh_s {
- gint pf_fd;
+ int pf_fd;
#ifdef HAVE_PATH_MAX
- gchar pf_path[PATH_MAX + 1];
+ char pf_path[PATH_MAX + 1];
#elif defined(HAVE_MAXPATHLEN)
- gchar pf_path[MAXPATHLEN + 1];
+ char pf_path[MAXPATHLEN + 1];
#else
- gchar pf_path[1024 + 1];
+ char pf_path[1024 + 1];
#endif
dev_t pf_dev;
ino_t pf_ino;
} rspamd_pidfh_t;
-rspamd_pidfh_t *rspamd_pidfile_open(const gchar *path,
+rspamd_pidfh_t *rspamd_pidfile_open(const char *path,
mode_t mode,
pid_t *pidptr);
-gint rspamd_pidfile_write(rspamd_pidfh_t *pfh);
+int rspamd_pidfile_write(rspamd_pidfh_t *pfh);
-gint rspamd_pidfile_close(rspamd_pidfh_t *pfh);
+int rspamd_pidfile_close(rspamd_pidfh_t *pfh);
-gint rspamd_pidfile_remove(rspamd_pidfh_t *pfh);
+int rspamd_pidfile_remove(rspamd_pidfh_t *pfh);
#else
typedef struct pidfh rspamd_pidfh_t;
@@ -170,20 +170,20 @@ typedef struct pidfh rspamd_pidfh_t;
/*
* Replace %r with rcpt value and %f with from value, new string is allocated in pool
*/
-gchar *resolve_stat_filename(rspamd_mempool_t *pool,
- gchar *pattern,
- gchar *rcpt,
- gchar *from);
+char *resolve_stat_filename(rspamd_mempool_t *pool,
+ char *pattern,
+ char *rcpt,
+ char *from);
-const gchar *
-rspamd_log_check_time(gdouble start, gdouble end, gint resolution);
+const char *
+rspamd_log_check_time(double start, double end, int resolution);
/*
* File locking functions
*/
-gboolean rspamd_file_lock(gint fd, gboolean async);
+gboolean rspamd_file_lock(int fd, gboolean async);
-gboolean rspamd_file_unlock(gint fd, gboolean async);
+gboolean rspamd_file_unlock(int fd, gboolean async);
/*
* Workarounds for older versions of glib
@@ -191,7 +191,7 @@ gboolean rspamd_file_unlock(gint fd, gboolean async);
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 22))
void g_ptr_array_unref(GPtrArray *array);
gboolean g_int64_equal(gconstpointer v1, gconstpointer v2);
-guint g_int64_hash(gconstpointer v);
+unsigned int g_int64_hash(gconstpointer v);
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 14))
void g_queue_clear(GQueue *queue);
@@ -200,14 +200,14 @@ void g_queue_clear(GQueue *queue);
void g_queue_free_full(GQueue *queue, GDestroyNotify free_func);
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 40))
-void g_ptr_array_insert(GPtrArray *array, gint index_, gpointer data);
+void g_ptr_array_insert(GPtrArray *array, int index_, gpointer data);
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 30))
-GPtrArray *g_ptr_array_new_full(guint reserved_size,
+GPtrArray *g_ptr_array_new_full(unsigned int reserved_size,
GDestroyNotify element_free_func);
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 32))
-const gchar *g_environ_getenv(gchar **envp, const gchar *variable);
+const char *g_environ_getenv(char **envp, const char *variable);
#endif
/*
@@ -244,7 +244,7 @@ const gchar *g_environ_getenv(gchar **envp, const gchar *variable);
* @param len length to allocate
* @return -1 in case of failure
*/
-gint rspamd_fallocate(gint fd, off_t offset, off_t len);
+int rspamd_fallocate(int fd, off_t offset, off_t len);
/**
* Utils for working with threads to be compatible with all glib versions
@@ -315,25 +315,25 @@ void rspamd_hash_table_copy(GHashTable *src, GHashTable *dst,
* @param key unused key
* @return
*/
-gint rspamd_read_passphrase_with_prompt(const gchar *prompt, gchar *buf, gint size, bool echo, gpointer key);
+int rspamd_read_passphrase_with_prompt(const char *prompt, char *buf, int size, bool echo, gpointer key);
/**
* Portably return the current clock ticks as seconds
* @return
*/
-gdouble rspamd_get_ticks(gboolean rdtsc_ok);
+double rspamd_get_ticks(gboolean rdtsc_ok);
/**
* Portably return the current virtual clock ticks as seconds
* @return
*/
-gdouble rspamd_get_virtual_ticks(void);
+double rspamd_get_virtual_ticks(void);
/**
* Return the real timestamp as unixtime
*/
-gdouble rspamd_get_calendar_ticks(void);
+double rspamd_get_calendar_ticks(void);
/**
* Special utility to help array freeing in rspamd_mempool
@@ -377,32 +377,32 @@ uint64_t rspamd_hash_seed(void);
* @param buf
* @param len
*/
-void rspamd_random_hex(gchar *buf, uint64_t len);
+void rspamd_random_hex(char *buf, uint64_t len);
/**
* Returns
* @param pattern pattern to create (should end with some number of X symbols), modified by this function
* @return
*/
-gint rspamd_shmem_mkstemp(gchar *pattern);
+int rspamd_shmem_mkstemp(char *pattern);
/**
* Return jittered time value
*/
-gdouble rspamd_time_jitter(gdouble in, gdouble jitter);
+double rspamd_time_jitter(double in, double jitter);
/**
* Return random double in range [0..1)
* @return
*/
-gdouble rspamd_random_double(void);
+double rspamd_random_double(void);
/**
* Return random double in range [0..1) using xoroshiro128+ algorithm (not crypto secure)
* @return
*/
-gdouble rspamd_random_double_fast(void);
-gdouble rspamd_random_double_fast_seed(uint64_t *seed);
+double rspamd_random_double_fast(void);
+double rspamd_random_double_fast_seed(uint64_t *seed);
uint64_t rspamd_random_uint64_fast_seed(uint64_t *seed);
uint64_t rspamd_random_uint64_fast(void);
@@ -423,7 +423,7 @@ gboolean rspamd_constant_memcmp(const void *a, const void *b, gsize len);
* @param mode mode to open
* @return fd or -1 in case of error
*/
-int rspamd_file_xopen(const char *fname, int oflags, guint mode,
+int rspamd_file_xopen(const char *fname, int oflags, unsigned int mode,
gboolean allow_symlink);
/**
@@ -433,7 +433,7 @@ int rspamd_file_xopen(const char *fname, int oflags, guint mode,
* @param size target size (must NOT be NULL)
* @return pointer to memory (should be freed using munmap) or NULL in case of error
*/
-gpointer rspamd_file_xmap(const char *fname, guint mode, gsize *size,
+gpointer rspamd_file_xmap(const char *fname, unsigned int mode, gsize *size,
gboolean allow_symlink);
/**
@@ -443,7 +443,7 @@ gpointer rspamd_file_xmap(const char *fname, guint mode, gsize *size,
* @param size target size (must NOT be NULL)
* @return pointer to memory (should be freed using munmap) or NULL in case of error
*/
-gpointer rspamd_shmem_xmap(const char *fname, guint mode,
+gpointer rspamd_shmem_xmap(const char *fname, unsigned int mode,
gsize *size);
/**
@@ -451,7 +451,7 @@ gpointer rspamd_shmem_xmap(const char *fname, guint mode,
* @param x probability (bias .. 1)
* @return
*/
-gdouble rspamd_normalize_probability(gdouble x, gdouble bias);
+double rspamd_normalize_probability(double x, double bias);
/**
* Converts struct tm to time_t
@@ -499,10 +499,10 @@ gboolean rspamd_fstring_gunzip(rspamd_fstring_t **in);
* @param pattern
* @param recursive
* @param err
- * @return GPtrArray of gchar *, elements are freed when array is freed
+ * @return GPtrArray of char *, elements are freed when array is freed
*/
-GPtrArray *rspamd_glob_path(const gchar *dir,
- const gchar *pattern,
+GPtrArray *rspamd_glob_path(const char *dir,
+ const char *pattern,
gboolean recursive,
GError **err);
@@ -530,7 +530,7 @@ float rspamd_set_counter_ema(struct rspamd_counter_data *cd,
* @return new counter value
*/
double rspamd_set_counter(struct rspamd_counter_data *cd,
- gdouble value);
+ double value);
/**
* Shuffle elements in an array inplace
@@ -549,8 +549,8 @@ struct rspamd_controller_pbkdf {
const char *alias;
const char *description;
int type; /* enum rspamd_cryptobox_pbkdf_type */
- gint id;
- guint complexity;
+ int id;
+ unsigned int complexity;
gsize salt_len;
gsize key_len;
};
@@ -572,7 +572,7 @@ float rspamd_sum_floats(float *ar, gsize *nelts);
* @param len
* @param nlen
*/
-void rspamd_normalize_path_inplace(gchar *path, guint len, gsize *nlen);
+void rspamd_normalize_path_inplace(char *path, unsigned int len, gsize *nlen);
#ifdef __cplusplus
}