aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-03-18 14:56:16 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-03-18 14:56:16 +0000
commit6b2b4167187fee09365271cca182866ecb029af3 (patch)
treea085717bc896b25ff4280eb86abecca0d5c36767 /src/libutil
parent47bcfc8360dfa1754474580e779314b8d6a78da6 (diff)
downloadrspamd-6b2b4167187fee09365271cca182866ecb029af3.tar.gz
rspamd-6b2b4167187fee09365271cca182866ecb029af3.zip
[Rework] Remove some of the GLib types in lieu of standard ones
This types have constant conflicts with the system ones especially on OSX.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/addr.c10
-rw-r--r--src/libutil/expression.c12
-rw-r--r--src/libutil/fstring.c20
-rw-r--r--src/libutil/fstring.h2
-rw-r--r--src/libutil/mem_pool.c6
-rw-r--r--src/libutil/mem_pool_internal.h12
-rw-r--r--src/libutil/printf.c78
-rw-r--r--src/libutil/printf.h10
-rw-r--r--src/libutil/regexp.c14
-rw-r--r--src/libutil/regexp.h8
-rw-r--r--src/libutil/shingles.c24
-rw-r--r--src/libutil/shingles.h10
-rw-r--r--src/libutil/sqlite_utils.c20
-rw-r--r--src/libutil/sqlite_utils.h2
-rw-r--r--src/libutil/str_util.c44
-rw-r--r--src/libutil/str_util.h4
-rw-r--r--src/libutil/upstream.c14
-rw-r--r--src/libutil/util.c50
-rw-r--r--src/libutil/util.h16
19 files changed, 178 insertions, 178 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index e011c991a..a7dafe43b 100644
--- a/src/libutil/addr.c
+++ b/src/libutil/addr.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -460,7 +460,7 @@ rspamd_parse_inet_address_ip4(const guchar *text, gsize len, gpointer target)
{
const guchar *p;
guchar c;
- guint32 addr = 0, *addrptr = target;
+ uint32_t addr = 0, *addrptr = target;
guint octet = 0, n = 0;
g_assert(text != NULL);
@@ -1728,7 +1728,7 @@ rspamd_inet_address_from_rnds(const struct rdns_reply_entry *rep)
void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask)
{
- guint32 umsk, *p;
+ uint32_t umsk, *p;
if (mask > 0 && addr != NULL) {
if (addr->af == AF_INET && mask <= 32) {
@@ -1890,7 +1890,7 @@ guint rspamd_inet_address_hash(gconstpointer a)
int af;
} layout;
- gint32 k;
+ int32_t k;
if (addr->af == AF_UNIX && addr->u.un) {
rspamd_cryptobox_fast_hash_state_t st;
@@ -1931,7 +1931,7 @@ guint rspamd_inet_address_port_hash(gconstpointer a)
int af;
} layout;
- gint32 k;
+ int32_t k;
if (addr->af == AF_UNIX && addr->u.un) {
rspamd_cryptobox_fast_hash_state_t st;
diff --git a/src/libutil/expression.c b/src/libutil/expression.c
index 957c47fab..51eac6885 100644
--- a/src/libutil/expression.c
+++ b/src/libutil/expression.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,
@@ -864,7 +864,7 @@ rspamd_parse_expression(const gchar *line, gsize len,
e->evals = 0;
e->next_resort = ottery_rand_range(MAX_RESORT_EVALS) + MIN_RESORT_EVALS;
e->log_id = g_malloc0(RSPAMD_LOG_ID_LEN + 1);
- guint64 h = rspamd_cryptobox_fast_hash(line, len, 0xdeadbabe);
+ uint64_t h = rspamd_cryptobox_fast_hash(line, len, 0xdeadbabe);
rspamd_snprintf(e->log_id, RSPAMD_LOG_ID_LEN + 1, "%xL", h);
msg_debug_expression("start to parse expression '%*s'", (int) len, line);
@@ -1538,8 +1538,8 @@ rspamd_ast_string_traverse(GNode *n, gpointer d)
(int) elt->p.atom->len, elt->p.atom->str);
}
else if (elt->type == ELT_LIMIT) {
- if (elt->p.lim == (double) (gint64) elt->p.lim) {
- rspamd_printf_gstring(res, "%L", (gint64) elt->p.lim);
+ if (elt->p.lim == (double) (int64_t) elt->p.lim) {
+ rspamd_printf_gstring(res, "%L", (int64_t) elt->p.lim);
}
else {
rspamd_printf_gstring(res, "%f", elt->p.lim);
diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c
index a921f3297..f092b307f 100644
--- a/src/libutil/fstring.c
+++ b/src/libutil/fstring.c
@@ -229,8 +229,8 @@ void rspamd_fstring_erase(rspamd_fstring_t *str, gsize pos, gsize len)
}
/* Compat code */
-static guint64
-fstrhash_c(guint64 c, guint64 hval)
+static uint64_t
+fstrhash_c(uint64_t c, uint64_t hval)
{
return mum_hash_step(hval, c);
}
@@ -239,11 +239,11 @@ fstrhash_c(guint64 c, guint64 hval)
/*
* Return hash value for a string
*/
-guint32
+uint32_t
rspamd_fstrhash_lc(const rspamd_ftok_t *str, gboolean is_utf)
{
gsize i;
- guint64 hval;
+ uint64_t hval;
const gchar *p, *end = NULL;
gunichar uc;
@@ -266,20 +266,20 @@ rspamd_fstrhash_lc(const rspamd_ftok_t *str, gboolean is_utf)
}
}
else {
- gsize large_steps = str->len / sizeof(guint64);
- for (i = 0; i < large_steps; i++, p += sizeof(guint64)) {
+ gsize large_steps = str->len / sizeof(uint64_t);
+ for (i = 0; i < large_steps; i++, p += sizeof(uint64_t)) {
/* Copy to the uint64 lowercasing each byte */
union {
- char c[sizeof(guint64)];
- guint64 iu64;
+ char c[sizeof(uint64_t)];
+ uint64_t iu64;
} t;
- for (int j = 0; j < sizeof(guint64); j++) {
+ for (int j = 0; j < sizeof(uint64_t); j++) {
t.c[j] = g_ascii_tolower(p[j]);
}
hval = fstrhash_c(t.iu64, hval);
}
- gsize remain = str->len % sizeof(guint64);
+ gsize remain = str->len % sizeof(uint64_t);
for (i = 0; i < remain; i++, p++) {
hval = fstrhash_c(g_ascii_tolower(*p), hval);
}
diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h
index 9eacf21d0..30a32a389 100644
--- a/src/libutil/fstring.h
+++ b/src/libutil/fstring.h
@@ -114,7 +114,7 @@ char *rspamd_ftok_cstr(const rspamd_ftok_t *str)
/*
* Return fast hash value for fixed string converted to lowercase
*/
-guint32 rspamd_fstrhash_lc(const rspamd_ftok_t *str, gboolean is_utf);
+uint32_t rspamd_fstrhash_lc(const rspamd_ftok_t *str, gboolean is_utf);
/**
* Return true if two strings are equal
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c
index 119ade33d..9d7c4a99a 100644
--- a/src/libutil/mem_pool.c
+++ b/src/libutil/mem_pool.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -94,9 +94,9 @@ static gboolean always_malloc = FALSE;
static gsize
pool_chain_free(struct _pool_chain *chain)
{
- gint64 occupied = chain->pos - chain->begin + MIN_MEM_ALIGNMENT;
+ int64_t occupied = chain->pos - chain->begin + MIN_MEM_ALIGNMENT;
- return (occupied < (gint64) chain->slice_size ? chain->slice_size - occupied : 0);
+ return (occupied < (int64_t) chain->slice_size ? chain->slice_size - occupied : 0);
}
/* By default allocate 4Kb chunks of memory */
diff --git a/src/libutil/mem_pool_internal.h b/src/libutil/mem_pool_internal.h
index 4fea83994..9fff5c7de 100644
--- a/src/libutil/mem_pool_internal.h
+++ b/src/libutil/mem_pool_internal.h
@@ -33,15 +33,15 @@ enum rspamd_mempool_chain_type {
#define ENTRY_NELTS 64
struct entry_elt {
- guint32 fragmentation;
- guint32 leftover;
+ uint32_t fragmentation;
+ uint32_t leftover;
};
struct rspamd_mempool_entry_point {
gchar src[ENTRY_LEN];
- guint32 cur_suggestion;
- guint32 cur_elts;
- guint32 cur_vars;
+ uint32_t cur_suggestion;
+ uint32_t cur_elts;
+ uint32_t cur_vars;
struct entry_elt elts[ENTRY_NELTS];
};
@@ -63,7 +63,7 @@ struct rspamd_mempool_variable {
};
KHASH_INIT(rspamd_mempool_vars_hash,
- guint32, struct rspamd_mempool_variable, 1,
+ uint32_t, struct rspamd_mempool_variable, 1,
kh_int_hash_func, kh_int_hash_equal);
struct rspamd_mempool_specific {
diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index ba53b56b8..b8322fc6b 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.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,
@@ -50,11 +50,11 @@ static const gchar _hex[] = "0123456789abcdef";
static const gchar _HEX[] = "0123456789ABCDEF";
static gchar *
-rspamd_humanize_number(gchar *buf, gchar *last, gint64 num, gboolean bytes)
+rspamd_humanize_number(gchar *buf, gchar *last, int64_t num, gboolean bytes)
{
const gchar *prefixes;
int i, r, remainder, sign;
- gint64 divisor;
+ int64_t divisor;
gsize len = last - buf;
remainder = 0;
@@ -107,9 +107,9 @@ rspamd_humanize_number(gchar *buf, gchar *last, gint64 num, gboolean bytes)
static inline unsigned
-rspamd_decimal_digits32(guint32 val)
+rspamd_decimal_digits32(uint32_t val)
{
- static const guint32 powers_of_10[] = {
+ static const uint32_t powers_of_10[] = {
0,
10,
100,
@@ -134,7 +134,7 @@ rspamd_decimal_digits32(guint32 val)
11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7,
19, 27, 23, 6, 26, 5, 4, 31};
- guint32 v = val | 1;
+ uint32_t v = val | 1;
v |= v >> 1;
v |= v >> 2;
@@ -147,9 +147,9 @@ rspamd_decimal_digits32(guint32 val)
}
static inline unsigned
-rspamd_decimal_digits64(guint64 val)
+rspamd_decimal_digits64(uint64_t val)
{
- static const guint64 powers_of_10[] = {
+ static const uint64_t powers_of_10[] = {
0,
10ULL,
100ULL,
@@ -175,7 +175,7 @@ rspamd_decimal_digits64(guint64 val)
#if defined(_MSC_VER)
#if _M_IX86
unsigned long r = 0;
- guint64 m = val | 1;
+ uint64_t m = val | 1;
if (_BitScanReverse(&r, m >> 32)) {
r += 32;
}
@@ -195,7 +195,7 @@ rspamd_decimal_digits64(guint64 val)
11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7,
19, 27, 23, 6, 26, 5, 4, 31};
- guint32 v = val >> 32;
+ uint32_t v = val >> 32;
if (v) {
v |= 1;
@@ -256,7 +256,7 @@ static const char int_lookup_table[200] = {
'9', '5', '9', '6', '9', '7', '9', '8', '9', '9'};
static inline guint
-rspamd_uint32_print(guint32 in, gchar *out)
+rspamd_uint32_print(uint32_t in, gchar *out)
{
guint ndigits = rspamd_decimal_digits32(in);
gchar *p;
@@ -287,17 +287,17 @@ rspamd_uint32_print(guint32 in, gchar *out)
}
static inline guint
-rspamd_uint64_print(guint64 in, gchar *out)
+rspamd_uint64_print(uint64_t in, gchar *out)
{
guint ndigits = rspamd_decimal_digits64(in);
- guint32 v32;
+ uint32_t v32;
gchar *p;
p = out + ndigits - 1;
while (in >= 100000000) {
- v32 = (guint32) (in % 100000000);
- guint32 a, b, a1, a2, b1, b2;
+ v32 = (uint32_t) (in % 100000000);
+ uint32_t a, b, a1, a2, b1, b2;
/* Initial spill */
a = v32 / 10000;
@@ -321,7 +321,7 @@ rspamd_uint64_print(guint64 in, gchar *out)
}
/* Remaining 32 bit */
- v32 = (guint32) in;
+ v32 = (uint32_t) in;
while (v32 >= 100) {
unsigned idx = (v32 % 100) << 1;
@@ -377,7 +377,7 @@ rspamd_ffsll(long long n)
}
static gchar *
-rspamd_sprintf_num(gchar *buf, gchar *last, guint64 ui64, gchar zero,
+rspamd_sprintf_num(gchar *buf, gchar *last, uint64_t ui64, gchar zero,
guint hexadecimal, guint binary, guint width)
{
gchar *p, temp[64];
@@ -387,7 +387,7 @@ rspamd_sprintf_num(gchar *buf, gchar *last, guint64 ui64, gchar zero,
p = temp;
if (ui64 < G_MAXUINT32) {
- len = rspamd_uint32_print((guint32) ui64, temp);
+ len = rspamd_uint32_print((uint32_t) ui64, temp);
}
else {
len = rspamd_uint64_print(ui64, temp);
@@ -396,7 +396,7 @@ rspamd_sprintf_num(gchar *buf, gchar *last, guint64 ui64, gchar zero,
else if (hexadecimal == 1) {
p = temp + sizeof(temp);
do {
- *--p = _hex[(guint32) (ui64 & 0xf)];
+ *--p = _hex[(uint32_t) (ui64 & 0xf)];
} while (ui64 >>= 4);
len = (temp + sizeof(temp)) - p;
@@ -404,7 +404,7 @@ rspamd_sprintf_num(gchar *buf, gchar *last, guint64 ui64, gchar zero,
else if (hexadecimal == 2) { /* hexadecimal == 2 */
p = temp + sizeof(temp);
do {
- *--p = _HEX[(guint32) (ui64 & 0xf)];
+ *--p = _HEX[(uint32_t) (ui64 & 0xf)];
} while (ui64 >>= 4);
len = (temp + sizeof(temp)) - p;
@@ -625,8 +625,8 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
gint d;
gdouble f;
glong written = 0, wr, slen;
- gint64 i64;
- guint64 ui64;
+ int64_t i64;
+ uint64_t ui64;
guint width, sign, hex, humanize, bytes, frac_width, b32, b64;
rspamd_fstring_t *v;
rspamd_ftok_t *tok;
@@ -917,62 +917,62 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
continue;
case 'O':
- i64 = (gint64) va_arg(args, off_t);
+ i64 = (int64_t) va_arg(args, off_t);
sign = 1;
break;
case 'P':
- i64 = (gint64) va_arg(args, pid_t);
+ i64 = (int64_t) va_arg(args, pid_t);
sign = 1;
break;
case 't':
- i64 = (gint64) va_arg(args, time_t);
+ i64 = (int64_t) va_arg(args, time_t);
sign = 1;
break;
case 'z':
if (sign) {
- i64 = (gint64) va_arg(args, ssize_t);
+ i64 = (int64_t) va_arg(args, ssize_t);
}
else {
- ui64 = (guint64) va_arg(args, size_t);
+ ui64 = (uint64_t) va_arg(args, size_t);
}
break;
case 'd':
if (sign) {
- i64 = (gint64) va_arg(args, gint);
+ i64 = (int64_t) va_arg(args, gint);
}
else {
- ui64 = (guint64) va_arg(args, guint);
+ ui64 = (uint64_t) va_arg(args, guint);
}
break;
case 'l':
if (sign) {
- i64 = (gint64) va_arg(args, glong);
+ i64 = (int64_t) va_arg(args, glong);
}
else {
- ui64 = (guint64) va_arg(args, gulong);
+ ui64 = (uint64_t) va_arg(args, gulong);
}
break;
case 'D':
if (sign) {
- i64 = (gint64) va_arg(args, gint32);
+ i64 = (int64_t) va_arg(args, int32_t);
}
else {
- ui64 = (guint64) va_arg(args, guint32);
+ ui64 = (uint64_t) va_arg(args, uint32_t);
}
break;
case 'L':
if (sign) {
- i64 = va_arg(args, gint64);
+ i64 = va_arg(args, int64_t);
}
else {
- ui64 = va_arg(args, guint64);
+ ui64 = va_arg(args, uint64_t);
}
break;
@@ -1062,10 +1062,10 @@ glong rspamd_vprintf_common(rspamd_printf_append_func func,
if (sign) {
if (i64 < 0) {
*p++ = '-';
- ui64 = (guint64) -i64;
+ ui64 = (uint64_t) -i64;
}
else {
- ui64 = (guint64) i64;
+ ui64 = (uint64_t) i64;
}
}
diff --git a/src/libutil/printf.h b/src/libutil/printf.h
index a9420b2d8..b4db34b8e 100644
--- a/src/libutil/printf.h
+++ b/src/libutil/printf.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,
@@ -29,8 +29,8 @@ extern "C" {
* %[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]l long
- * %[0][width][u][x|X|h|H|b|B]D gint32/guint32
- * %[0][width][u][x|X|h|H|b|B]L gint64/guint64
+ * %[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
* %[0][width][.width]f double
* %[0][width][.width]F long double
* %[0][width][.width]g double
diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c
index 9f143acfc..63ce73f5f 100644
--- a/src/libutil/regexp.c
+++ b/src/libutil/regexp.c
@@ -65,7 +65,7 @@ struct rspamd_regexp_s {
ref_entry_t ref;
gpointer ud;
gpointer re_class;
- guint64 cache_id;
+ uint64_t cache_id;
gsize match_limit;
guint max_hits;
gint flags;
@@ -901,7 +901,7 @@ guint rspamd_regexp_set_maxhits(rspamd_regexp_t *re, guint new_maxhits)
return old_hits;
}
-guint64
+uint64_t
rspamd_regexp_get_cache_id(const rspamd_regexp_t *re)
{
g_assert(re != NULL);
@@ -909,10 +909,10 @@ rspamd_regexp_get_cache_id(const rspamd_regexp_t *re)
return re->cache_id;
}
-guint64
-rspamd_regexp_set_cache_id(rspamd_regexp_t *re, guint64 id)
+uint64_t
+rspamd_regexp_set_cache_id(rspamd_regexp_t *re, uint64_t id)
{
- guint64 old;
+ uint64_t old;
g_assert(re != NULL);
old = re->cache_id;
@@ -999,11 +999,11 @@ rspamd_regexp_equal(gconstpointer a, gconstpointer b)
return (memcmp(ia, ib, sizeof(regexp_id_t)) == 0);
}
-guint32
+uint32_t
rspamd_regexp_hash(gconstpointer a)
{
const guchar *ia = a;
- guint32 res;
+ uint32_t res;
memcpy(&res, ia, sizeof(res));
diff --git a/src/libutil/regexp.h b/src/libutil/regexp.h
index 6222ba69a..5be9046be 100644
--- a/src/libutil/regexp.h
+++ b/src/libutil/regexp.h
@@ -27,7 +27,7 @@
#define PCRE_FLAG(x) G_PASTE(PCRE2_, x)
#endif
-#define RSPAMD_INVALID_ID ((guint64) -1LL)
+#define RSPAMD_INVALID_ID ((uint64_t) -1LL)
#define RSPAMD_REGEXP_FLAG_RAW (1 << 1)
#define RSPAMD_REGEXP_FLAG_NOOPT (1 << 2)
#define RSPAMD_REGEXP_FLAG_FULL_MATCH (1 << 3)
@@ -164,12 +164,12 @@ guint rspamd_regexp_set_maxhits(rspamd_regexp_t *re, guint new_maxhits);
/**
* Returns cache id for a regexp
*/
-guint64 rspamd_regexp_get_cache_id(const rspamd_regexp_t *re);
+uint64_t rspamd_regexp_get_cache_id(const rspamd_regexp_t *re);
/**
* Sets cache id for a regexp
*/
-guint64 rspamd_regexp_set_cache_id(rspamd_regexp_t *re, guint64 id);
+uint64_t rspamd_regexp_set_cache_id(rspamd_regexp_t *re, uint64_t id);
/**
* Returns match limit for a regexp
@@ -241,7 +241,7 @@ void rspamd_regexp_cache_destroy(struct rspamd_regexp_cache *cache);
* @param a
* @return
*/
-guint32 rspamd_regexp_hash(gconstpointer a);
+uint32_t rspamd_regexp_hash(gconstpointer a);
/**
* Compare two regexp objects based on theirs ID
diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c
index 42d51686d..f074c76ff 100644
--- a/src/libutil/shingles.c
+++ b/src/libutil/shingles.c
@@ -120,11 +120,11 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
enum rspamd_shingle_alg alg)
{
struct rspamd_shingle *res;
- guint64 **hashes;
+ uint64_t **hashes;
guchar **keys;
rspamd_fstring_t *row;
rspamd_stat_token_t *word;
- guint64 val;
+ uint64_t val;
gint i, j, k;
gsize hlen, ilen = 0, beg = 0, widx = 0;
enum rspamd_cryptobox_fast_hash_type ht;
@@ -152,7 +152,7 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
keys = rspamd_shingles_get_keys_cached(key);
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) {
- hashes[i] = g_malloc(hlen * sizeof(guint64));
+ hashes[i] = g_malloc(hlen * sizeof(uint64_t));
}
/* Now parse input words into a vector of hashes using rolling window */
@@ -210,7 +210,7 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
}
}
else {
- guint64 window[SHINGLES_WINDOW * RSPAMD_SHINGLE_SIZE], seed;
+ uint64_t window[SHINGLES_WINDOW * RSPAMD_SHINGLE_SIZE], seed;
switch (alg) {
case RSPAMD_SHINGLES_XXHASH:
@@ -309,14 +309,14 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
enum rspamd_shingle_alg alg)
{
struct rspamd_shingle *shingle;
- guint64 **hashes;
+ uint64_t **hashes;
guchar **keys;
- guint64 d;
- guint64 val;
+ uint64_t d;
+ uint64_t val;
gint i, j;
gsize hlen, beg = 0;
enum rspamd_cryptobox_fast_hash_type ht;
- guint64 res[SHINGLES_WINDOW * RSPAMD_SHINGLE_SIZE], seed;
+ uint64_t res[SHINGLES_WINDOW * RSPAMD_SHINGLE_SIZE], seed;
if (pool != NULL) {
shingle = rspamd_mempool_alloc(pool, sizeof(*shingle));
@@ -331,7 +331,7 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
keys = rspamd_shingles_get_keys_cached(key);
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) {
- hashes[i] = g_malloc(hlen * sizeof(guint64));
+ hashes[i] = g_malloc(hlen * sizeof(uint64_t));
}
switch (alg) {
@@ -380,11 +380,11 @@ struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
return shingle;
}
-guint64
-rspamd_shingles_default_filter(guint64 *input, gsize count,
+uint64_t
+rspamd_shingles_default_filter(uint64_t *input, gsize count,
gint shno, const guchar *key, gpointer ud)
{
- guint64 minimal = G_MAXUINT64;
+ uint64_t minimal = G_MAXUINT64;
gsize i;
for (i = 0; i < count; i++) {
diff --git a/src/libutil/shingles.h b/src/libutil/shingles.h
index 9a0ca697c..d0da3fc04 100644
--- a/src/libutil/shingles.h
+++ b/src/libutil/shingles.h
@@ -26,7 +26,7 @@ extern "C" {
#endif
struct rspamd_shingle {
- guint64 hashes[RSPAMD_SHINGLE_SIZE];
+ uint64_t hashes[RSPAMD_SHINGLE_SIZE];
};
enum rspamd_shingle_alg {
@@ -42,8 +42,8 @@ enum rspamd_shingle_alg {
* @param count number of hashes in the vector
* @return shingle value
*/
-typedef guint64 (*rspamd_shingles_filter)(guint64 *input, gsize count,
- gint shno, const guchar *key, gpointer ud);
+typedef uint64_t (*rspamd_shingles_filter)(uint64_t *input, gsize count,
+ gint shno, const guchar *key, gpointer ud);
/**
* Generate shingles from the input of fixed size strings using lemmatizer
@@ -91,8 +91,8 @@ gdouble rspamd_shingles_compare(const struct rspamd_shingle *a,
/**
* Default filtering function
*/
-guint64 rspamd_shingles_default_filter(guint64 *input, gsize count,
- gint shno, const guchar *key, gpointer ud);
+uint64_t rspamd_shingles_default_filter(uint64_t *input, gsize count,
+ gint shno, const guchar *key, gpointer ud);
#ifdef __cplusplus
}
diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c
index 8aeb5982b..0c9b4463f 100644
--- a/src/libutil/sqlite_utils.c
+++ b/src/libutil/sqlite_utils.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,
@@ -64,7 +64,7 @@ int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts
va_list ap;
sqlite3_stmt *stmt;
gint i, rowid, nargs, j;
- gint64 len;
+ int64_t len;
gpointer p;
struct rspamd_sqlite3_prstmt *nst;
const char *argtypes;
@@ -101,7 +101,7 @@ int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts
case 'B':
for (j = 0; j < nargs; j++, rowid++) {
- len = va_arg(ap, gint64);
+ len = va_arg(ap, int64_t);
sqlite3_bind_text(stmt, rowid, va_arg(ap, const char *), len,
SQLITE_STATIC);
}
@@ -111,7 +111,7 @@ int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts
case 'I':
for (j = 0; j < nargs; j++, rowid++) {
- sqlite3_bind_int64(stmt, rowid, va_arg(ap, gint64));
+ sqlite3_bind_int64(stmt, rowid, va_arg(ap, int64_t));
}
nargs = 1;
@@ -141,20 +141,20 @@ int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts
*va_arg(ap, char **) = g_strdup(sqlite3_column_text(stmt, i));
break;
case 'I':
- *va_arg(ap, gint64 *) = sqlite3_column_int64(stmt, i);
+ *va_arg(ap, int64_t *) = sqlite3_column_int64(stmt, i);
break;
case 'S':
*va_arg(ap, int *) = sqlite3_column_int(stmt, i);
break;
case 'L':
- *va_arg(ap, gint64 *) = sqlite3_last_insert_rowid(db);
+ *va_arg(ap, int64_t *) = sqlite3_last_insert_rowid(db);
break;
case 'B':
len = sqlite3_column_bytes(stmt, i);
g_assert(len >= 0);
p = g_malloc(len);
memcpy(p, sqlite3_column_blob(stmt, i), len);
- *va_arg(ap, gint64 *) = len;
+ *va_arg(ap, int64_t *) = len;
*va_arg(ap, gpointer *) = p;
break;
}
@@ -464,7 +464,7 @@ rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, const gchar *path, const g
else if (has_lock && version > 0) {
/* Check user version */
sqlite3_stmt *stmt = NULL;
- guint32 db_ver;
+ uint32_t db_ver;
GString *new_ver_sql;
if (sqlite3_prepare(sqlite, db_version, -1, &stmt, NULL) != SQLITE_OK) {
diff --git a/src/libutil/sqlite_utils.h b/src/libutil/sqlite_utils.h
index 5411a476e..4bb8dea17 100644
--- a/src/libutil/sqlite_utils.h
+++ b/src/libutil/sqlite_utils.h
@@ -74,7 +74,7 @@ void rspamd_sqlite3_close_prstmt(sqlite3 *db, GArray *stmts);
*/
sqlite3 *rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool,
const gchar *path, const gchar *create_sql,
- guint32 version, GError **err);
+ uint32_t version, GError **err);
/**
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index bc99f2a51..77fa20f54 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.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,
@@ -143,7 +143,7 @@ gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l)
guchar c1, c2, c3, c4;
union {
guchar c[4];
- guint32 n;
+ uint32_t n;
} cmp1, cmp2;
gsize leftover = l % 4;
gint ret = 0;
@@ -188,7 +188,7 @@ gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l)
guint rspamd_str_lc_utf8(gchar *str, guint size)
{
guchar *d = (guchar *) str, tst[6];
- gint32 i = 0, prev = 0;
+ int32_t i = 0, prev = 0;
UChar32 uc;
while (i < size) {
@@ -197,7 +197,7 @@ guint rspamd_str_lc_utf8(gchar *str, guint size)
U8_NEXT((guint8 *) str, i, size, uc);
uc = u_tolower(uc);
- gint32 olen = 0;
+ int32_t olen = 0;
U8_APPEND_UNSAFE(tst, olen, uc);
if (olen <= (i - prev)) {
@@ -223,19 +223,19 @@ rspamd_strcase_equal(gconstpointer v, gconstpointer v2)
return FALSE;
}
-guint64
-rspamd_icase_hash(const gchar *in, gsize len, guint64 seed)
+uint64_t
+rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed)
{
- guint leftover = len % sizeof(guint64);
+ guint leftover = len % sizeof(uint64_t);
guint fp, i;
const uint8_t *s = (const uint8_t *) in;
union {
struct {
guchar c1, c2, c3, c4, c5, c6, c7, c8;
} c;
- guint64 pp;
+ uint64_t pp;
} u;
- guint64 h = seed;
+ uint64_t h = seed;
fp = len - leftover;
@@ -346,10 +346,10 @@ guint rspamd_gstring_icase_hash(gconstpointer key)
/* https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord */
#define MEM_ALIGN (sizeof(gsize) - 1)
#if defined(__LP64__) || defined(_LP64)
-#define WORD_TYPE guint64
+#define WORD_TYPE uint64_t
#define ZEROMASK 0x7F7F7F7F7F7F7F7FLLU
#else
-#define WORD_TYPE guint32
+#define WORD_TYPE uint32_t
#define ZEROMASK 0x7F7F7F7FU
#endif
@@ -535,12 +535,12 @@ rspamd_strtoul(const gchar *s, gsize len, gulong *value)
}
gboolean
-rspamd_strtou64(const gchar *s, gsize len, guint64 *value)
+rspamd_strtou64(const gchar *s, gsize len, uint64_t *value)
{
const gchar *p = s, *end = s + len;
gchar c;
- guint64 v = 0;
- const guint64 cutoff = G_MAXUINT64 / 10, cutlim = G_MAXUINT64 % 10;
+ uint64_t v = 0;
+ const uint64_t cutoff = G_MAXUINT64 / 10, cutlim = G_MAXUINT64 % 10;
/* Some preparations for range errors */
CONV_STR_LIM_DECIMAL(G_MAXUINT64);
@@ -1265,8 +1265,8 @@ rspamd_encode_base64_common(const guchar *in, gsize inlen, gint str_len,
gsize allocated_len = (inlen / 3) * 4 + 5;
gchar *out, *o;
- guint64 n;
- guint32 rem, t, carry;
+ uint64_t n;
+ uint32_t rem, t, carry;
gint cols, shift;
static const char b64_enc[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -3508,7 +3508,7 @@ rspamd_str_regexp_escape(const gchar *pattern, gsize slen,
else {
if (flags & (RSPAMD_REGEXP_ESCAPE_RE | RSPAMD_REGEXP_ESCAPE_GLOB)) {
UChar32 uc;
- gint32 off = p - pattern - 1;
+ int32_t off = p - pattern - 1;
U8_NEXT(pattern, off, slen, uc);
if (uc > 0) {
@@ -3821,11 +3821,11 @@ rspamd_str_has_8bit_u64(const guchar *beg, gsize len)
guint8 orb = 0;
if (len >= 16) {
- const guchar *nextd = beg + sizeof(guint64);
- guint64 n1 = 0, n2 = 0;
+ const guchar *nextd = beg + sizeof(uint64_t);
+ uint64_t n1 = 0, n2 = 0;
do {
- guint64 t;
+ uint64_t t;
memcpy(&t, beg, sizeof(t));
n1 |= t;
memcpy(&t, nextd, sizeof(t));
diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h
index 07560cc2f..ff5827a0b 100644
--- a/src/libutil/str_util.h
+++ b/src/libutil/str_util.h
@@ -59,7 +59,7 @@ guint rspamd_str_lc_utf8(gchar *str, guint size);
/*
* Hash table utility functions for case insensitive hashing
*/
-guint64 rspamd_icase_hash(const gchar *in, gsize len, guint64 seed);
+uint64_t rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed);
guint rspamd_strcase_hash(gconstpointer key);
@@ -140,7 +140,7 @@ gboolean rspamd_strtol(const gchar *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, guint64 *value);
+gboolean rspamd_strtou64(const gchar *s, gsize len, uint64_t *value);
/*
* Try to convert a hex string of length to unsigned long
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index f536a2c6d..a004a298b 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -97,7 +97,7 @@ struct upstream_list {
GPtrArray *ups;
GPtrArray *alive;
struct upstream_list_watcher *watchers;
- guint64 hash_seed;
+ uint64_t hash_seed;
const struct upstream_limits *limits;
enum rspamd_upstream_flag flags;
guint cur_elt;
@@ -1492,10 +1492,10 @@ rspamd_upstream_get_round_robin(struct upstream_list *ups,
*
* http://arxiv.org/abs/1406.2294
*/
-static guint32
-rspamd_consistent_hash(guint64 key, guint32 nbuckets)
+static uint32_t
+rspamd_consistent_hash(uint64_t key, uint32_t nbuckets)
{
- gint64 b = -1, j = 0;
+ int64_t b = -1, j = 0;
while (j < nbuckets) {
b = j;
@@ -1511,8 +1511,8 @@ rspamd_upstream_get_hashed(struct upstream_list *ups,
struct upstream *except,
const guint8 *key, guint keylen)
{
- guint64 k;
- guint32 idx;
+ uint64_t k;
+ uint32_t idx;
static const guint max_tries = 20;
struct upstream *up = NULL;
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 04200e36d..10aeebf45 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -1091,11 +1091,11 @@ void g_ptr_array_unref(GPtrArray *array)
gboolean
g_int64_equal(gconstpointer v1, gconstpointer v2)
{
- return *((const gint64 *) v1) == *((const gint64 *) v2);
+ return *((const int64_t *) v1) == *((const int64_t *) v2);
}
guint g_int64_hash(gconstpointer v)
{
- guint64 v64 = *(guint64 *) v;
+ uint64_t v64 = *(uint64_t *) v;
return (guint) (v ^ (v >> 32));
}
@@ -1467,7 +1467,7 @@ rspamd_get_ticks(gboolean rdtsc_ok)
#ifdef HAVE_RDTSC
#ifdef __x86_64__
- guint64 r64;
+ uint64_t r64;
if (rdtsc_ok) {
__builtin_ia32_lfence();
@@ -1586,16 +1586,16 @@ rspamd_get_calendar_ticks(void)
return res;
}
-void rspamd_random_hex(gchar *buf, guint64 len)
+void rspamd_random_hex(gchar *buf, uint64_t len)
{
static const gchar hexdigests[16] = "0123456789abcdef";
- gint64 i;
+ int64_t i;
g_assert(len > 0);
ottery_rand_bytes((void *) buf, ceil(len / 2.0));
- for (i = (gint64) len - 1; i >= 0; i -= 2) {
+ for (i = (int64_t) len - 1; i >= 0; i -= 2) {
buf[i] = hexdigests[buf[i / 2] & 0xf];
if (i > 0) {
@@ -1698,11 +1698,11 @@ RSPAMD_CONSTRUCTOR(blis_thread_fix_ctor)
}
#endif
-guint64
+uint64_t
rspamd_hash_seed(void)
{
#if 0
- static guint64 seed;
+ static uint64_t seed;
if (seed == 0) {
seed = ottery_rand_uint64 ();
@@ -1719,10 +1719,10 @@ rspamd_hash_seed(void)
}
static inline gdouble
-rspamd_double_from_int64(guint64 x)
+rspamd_double_from_int64(uint64_t x)
{
const union {
- guint64 i;
+ uint64_t i;
double d;
} u = {
.i = G_GUINT64_CONSTANT(0x3FF) << 52 | x >> 12};
@@ -1733,7 +1733,7 @@ rspamd_double_from_int64(guint64 x)
gdouble
rspamd_random_double(void)
{
- guint64 rnd_int;
+ uint64_t rnd_int;
rnd_int = ottery_rand_uint64();
@@ -1741,10 +1741,10 @@ rspamd_random_double(void)
}
-static guint64 *
+static uint64_t *
rspamd_fast_random_seed(void)
{
- static guint64 seed;
+ static uint64_t seed;
if (G_UNLIKELY(seed == 0)) {
ottery_rand_bytes((void *) &seed, sizeof(seed));
@@ -1799,12 +1799,12 @@ rspamd_random_double_fast(void)
/* xoshiro256+ */
inline gdouble
-rspamd_random_double_fast_seed(guint64 *seed)
+rspamd_random_double_fast_seed(uint64_t *seed)
{
return rspamd_double_from_int64(rspamd_random_uint64_fast_seed(seed));
}
-guint64
+uint64_t
rspamd_random_uint64_fast(void)
{
return rspamd_random_uint64_fast_seed(rspamd_fast_random_seed());
@@ -1852,7 +1852,7 @@ rspamd_constant_memcmp(const void *a, const void *b, gsize len)
r |= (d & m);
}
- return (((gint32) (guint16) ((guint32) r + 0x8000) - 0x8000) == 0);
+ return (((int32_t) (guint16) ((uint32_t) r + 0x8000) - 0x8000) == 0);
}
int rspamd_file_xopen(const char *fname, int oflags, guint mode,
@@ -2032,10 +2032,10 @@ rspamd_normalize_probability(gdouble x, gdouble bias)
/*
* Calculations from musl libc
*/
-guint64
+uint64_t
rspamd_tm_to_time(const struct tm *tm, glong tz)
{
- guint64 result;
+ uint64_t result;
gboolean is_leap = FALSE;
gint leaps, y = tm->tm_year, cycles, rem, centuries;
glong offset = (tz / 100) * 3600 + (tz % 100) * 60;
@@ -2125,19 +2125,19 @@ rspamd_tm_to_time(const struct tm *tm, glong tz)
}
-void rspamd_gmtime(gint64 ts, struct tm *dest)
+void rspamd_gmtime(int64_t ts, struct tm *dest)
{
- guint64 days, secs, years;
+ uint64_t days, secs, years;
int remdays, remsecs, remyears;
int leap_400_cycles, leap_100_cycles, leap_4_cycles;
int months;
int wday, yday, leap;
/* From March */
static const uint8_t days_in_month[] = {31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29};
- static const guint64 leap_epoch = 946684800ULL + 86400 * (31 + 29);
- static const guint64 days_per_400y = 365 * 400 + 97;
- static const guint64 days_per_100y = 365 * 100 + 24;
- static const guint64 days_per_4y = 365 * 4 + 1;
+ static const uint64_t leap_epoch = 946684800ULL + 86400 * (31 + 29);
+ static const uint64_t days_per_400y = 365 * 400 + 97;
+ static const uint64_t days_per_100y = 365 * 100 + 24;
+ static const uint64_t days_per_4y = 365 * 4 + 1;
secs = ts - leap_epoch;
days = secs / 86400;
@@ -2218,7 +2218,7 @@ void rspamd_gmtime(gint64 ts, struct tm *dest)
#endif
}
-void rspamd_localtime(gint64 ts, struct tm *dest)
+void rspamd_localtime(int64_t ts, struct tm *dest)
{
time_t t = ts;
localtime_r(&t, dest);
diff --git a/src/libutil/util.h b/src/libutil/util.h
index 7111a079e..54e86d3bb 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -370,14 +370,14 @@ void rspamd_gstring_free_soft(gpointer p);
* Returns some statically initialized random hash seed
* @return hash seed
*/
-guint64 rspamd_hash_seed(void);
+uint64_t rspamd_hash_seed(void);
/**
* Returns random hex string of the specified length
* @param buf
* @param len
*/
-void rspamd_random_hex(gchar *buf, guint64 len);
+void rspamd_random_hex(gchar *buf, uint64_t len);
/**
* Returns
@@ -402,9 +402,9 @@ gdouble rspamd_random_double(void);
* @return
*/
gdouble rspamd_random_double_fast(void);
-gdouble rspamd_random_double_fast_seed(guint64 *seed);
+gdouble rspamd_random_double_fast_seed(uint64_t *seed);
uint64_t rspamd_random_uint64_fast_seed(uint64_t *seed);
-guint64 rspamd_random_uint64_fast(void);
+uint64_t rspamd_random_uint64_fast(void);
/**
* Seed fast rng
@@ -459,21 +459,21 @@ gdouble rspamd_normalize_probability(gdouble x, gdouble bias);
* @param tz timezone in format (hours * 100) + minutes
* @return
*/
-guint64 rspamd_tm_to_time(const struct tm *tm, glong tz);
+uint64_t rspamd_tm_to_time(const struct tm *tm, glong tz);
/**
* Splits unix timestamp into struct tm using GMT timezone
* @param ts
* @param dest
*/
-void rspamd_gmtime(gint64 ts, struct tm *dest);
+void rspamd_gmtime(int64_t ts, struct tm *dest);
/**
* Split unix timestamp into struct tm using local timezone
* @param ts
* @param dest
*/
-void rspamd_localtime(gint64 ts, struct tm *dest);
+void rspamd_localtime(int64_t ts, struct tm *dest);
#define PTR_ARRAY_FOREACH(ar, i, cur) for ((i) = 0; (ar) != NULL && (i) < (ar)->len && (((cur) = (__typeof__(cur)) g_ptr_array_index((ar), (i))) || 1); ++(i))
@@ -509,7 +509,7 @@ GPtrArray *rspamd_glob_path(const gchar *dir,
struct rspamd_counter_data {
float mean;
float stddev;
- guint64 number;
+ uint64_t number;
};
/**