[Rework] Remove some of the GLib types in lieu of standard onespull/4882/head
@@ -1,3 +1,19 @@ | |||
/* | |||
* Copyright 2024 Vsevolod Stakhov | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* | |||
** Copyright (C) 2009-2014 Mischa Sandberg <mischasan@gmail.com> | |||
** | |||
@@ -22,103 +38,104 @@ | |||
#include "_acism.h" | |||
#include "unix-std.h" | |||
#define BACK ((SYMBOL)0) | |||
#define BACK ((SYMBOL) 0) | |||
#define ROOT ((STATE) 0) | |||
extern const guchar lc_map[256]; | |||
extern const unsigned char lc_map[256]; | |||
int | |||
acism_lookup(ac_trie_t const *psp, const char *text, size_t len, | |||
ACISM_ACTION *cb, void *context, int *statep, bool caseless) | |||
int acism_lookup(ac_trie_t const *psp, const char *text, size_t len, | |||
ACISM_ACTION *cb, void *context, int *statep, bool caseless) | |||
{ | |||
char const *cp = text, *endp = cp + len; | |||
uint8_t s; | |||
STATE state = *statep; | |||
int ret = 0; | |||
while (cp < endp) { | |||
s = caseless ? lc_map[(guint8)*cp++] : *cp++; | |||
_SYMBOL sym = psp->symv[s]; | |||
if (!sym) { | |||
// Input byte is not in any pattern string. | |||
state = ROOT; | |||
continue; | |||
} | |||
// Search for a valid transition from this (state, sym), | |||
// following the backref chain. | |||
TRAN next; | |||
while (!t_valid(psp, next = p_tran(psp, state, sym)) && state != ROOT) { | |||
TRAN back = p_tran(psp, state, BACK); | |||
state = t_valid(psp, back) ? t_next(psp, back) : ROOT; | |||
} | |||
if (!t_valid(psp, next)) | |||
continue; | |||
if (!(next & (IS_MATCH | IS_SUFFIX))) { | |||
// No complete match yet; keep going. | |||
state = t_next(psp, next); | |||
continue; | |||
} | |||
// At this point, one or more patterns have matched. | |||
// Find all matches by following the backref chain. | |||
// A valid node for (sym) with no SUFFIX flag marks the | |||
// end of the suffix chain. | |||
// In the same backref traversal, find a new (state), | |||
// if the original transition is to a leaf. | |||
STATE s = state; | |||
// Initially state is ROOT. The chain search saves the | |||
// first state from which the next char has a transition. | |||
state = t_isleaf(psp, next) ? 0 : t_next(psp, next); | |||
while (1) { | |||
if (t_valid(psp, next)) { | |||
if (next & IS_MATCH) { | |||
unsigned strno, ss = s + sym, i; | |||
if (t_isleaf(psp, psp->tranv[ss])) { | |||
strno = t_strno(psp, psp->tranv[ss]); | |||
} else { | |||
for (i = p_hash(psp, ss); psp->hashv[i].state != ss; ++i); | |||
strno = psp->hashv[i].strno; | |||
} | |||
if ((ret = cb(strno, cp - text, context))) | |||
goto EXIT; | |||
} | |||
if (!state && !t_isleaf(psp, next)) | |||
state = t_next(psp, next); | |||
if ( state && !(next & IS_SUFFIX)) | |||
break; | |||
} | |||
if (s == ROOT) | |||
break; | |||
TRAN b = p_tran(psp, s, BACK); | |||
s = t_valid(psp, b) ? t_next(psp, b) : ROOT; | |||
next = p_tran(psp, s, sym); | |||
} | |||
} | |||
char const *cp = text, *endp = cp + len; | |||
uint8_t s; | |||
STATE state = *statep; | |||
int ret = 0; | |||
while (cp < endp) { | |||
s = caseless ? lc_map[(uint8_t) *cp++] : *cp++; | |||
_SYMBOL sym = psp->symv[s]; | |||
if (!sym) { | |||
// Input byte is not in any pattern string. | |||
state = ROOT; | |||
continue; | |||
} | |||
// Search for a valid transition from this (state, sym), | |||
// following the backref chain. | |||
TRAN next; | |||
while (!t_valid(psp, next = p_tran(psp, state, sym)) && state != ROOT) { | |||
TRAN back = p_tran(psp, state, BACK); | |||
state = t_valid(psp, back) ? t_next(psp, back) : ROOT; | |||
} | |||
if (!t_valid(psp, next)) | |||
continue; | |||
if (!(next & (IS_MATCH | IS_SUFFIX))) { | |||
// No complete match yet; keep going. | |||
state = t_next(psp, next); | |||
continue; | |||
} | |||
// At this point, one or more patterns have matched. | |||
// Find all matches by following the backref chain. | |||
// A valid node for (sym) with no SUFFIX flag marks the | |||
// end of the suffix chain. | |||
// In the same backref traversal, find a new (state), | |||
// if the original transition is to a leaf. | |||
STATE s = state; | |||
// Initially state is ROOT. The chain search saves the | |||
// first state from which the next char has a transition. | |||
state = t_isleaf(psp, next) ? 0 : t_next(psp, next); | |||
while (1) { | |||
if (t_valid(psp, next)) { | |||
if (next & IS_MATCH) { | |||
unsigned strno, ss = s + sym, i; | |||
if (t_isleaf(psp, psp->tranv[ss])) { | |||
strno = t_strno(psp, psp->tranv[ss]); | |||
} | |||
else { | |||
for (i = p_hash(psp, ss); psp->hashv[i].state != ss; ++i) | |||
; | |||
strno = psp->hashv[i].strno; | |||
} | |||
if ((ret = cb(strno, cp - text, context))) | |||
goto EXIT; | |||
} | |||
if (!state && !t_isleaf(psp, next)) | |||
state = t_next(psp, next); | |||
if (state && !(next & IS_SUFFIX)) | |||
break; | |||
} | |||
if (s == ROOT) | |||
break; | |||
TRAN b = p_tran(psp, s, BACK); | |||
s = t_valid(psp, b) ? t_next(psp, b) : ROOT; | |||
next = p_tran(psp, s, sym); | |||
} | |||
} | |||
EXIT: | |||
*statep = state; | |||
return ret; | |||
return ret; | |||
} | |||
void | |||
acism_destroy(ac_trie_t *psp) | |||
void acism_destroy(ac_trie_t *psp) | |||
{ | |||
if (!psp) return; | |||
if (psp->flags & IS_MMAP) | |||
munmap((char*)psp->tranv - sizeof(ac_trie_t), | |||
sizeof(ac_trie_t) + p_size(psp)); | |||
else g_free(psp->tranv); | |||
munmap((char *) psp->tranv - sizeof(ac_trie_t), | |||
sizeof(ac_trie_t) + p_size(psp)); | |||
else | |||
g_free(psp->tranv); | |||
g_free(psp); | |||
} | |||
//EOF |
@@ -18,8 +18,7 @@ cdb_hash(const void *buf, unsigned len) | |||
return hash; | |||
} | |||
int | |||
cdb_init(struct cdb *cdbp, int fd) | |||
int cdb_init(struct cdb *cdbp, int fd) | |||
{ | |||
struct stat st; | |||
unsigned char *mem; | |||
@@ -29,7 +28,7 @@ cdb_init(struct cdb *cdbp, int fd) | |||
#endif | |||
/* get file size */ | |||
if (fstat (fd, &st) < 0) | |||
if (fstat(fd, &st) < 0) | |||
return -1; | |||
/* trivial sanity check: at least toc should be here */ | |||
if (st.st_size < 2048) | |||
@@ -39,16 +38,16 @@ cdb_init(struct cdb *cdbp, int fd) | |||
#ifdef _WIN32 | |||
hFile = (HANDLE) _get_osfhandle(fd); | |||
if (hFile == (HANDLE) -1) | |||
return -1; | |||
return -1; | |||
hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); | |||
if (!hMapping) | |||
return -1; | |||
mem = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); | |||
return -1; | |||
mem = (unsigned char *) MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); | |||
CloseHandle(hMapping); | |||
if (!mem) | |||
return -1; | |||
return -1; | |||
#else | |||
mem = (unsigned char*) mmap (NULL, fsize, PROT_READ, MAP_SHARED, fd, 0); | |||
mem = (unsigned char *) mmap(NULL, fsize, PROT_READ, MAP_SHARED, fd, 0); | |||
if (mem == MAP_FAILED) | |||
return -1; | |||
#endif /* _WIN32 */ | |||
@@ -60,7 +59,7 @@ cdb_init(struct cdb *cdbp, int fd) | |||
cdbp->cdb_vpos = cdbp->cdb_vlen = 0; | |||
cdbp->cdb_kpos = cdbp->cdb_klen = 0; | |||
dend = cdb_unpack (mem); | |||
dend = cdb_unpack(mem); | |||
if (dend < 2048) | |||
dend = 2048; | |||
else if (dend >= fsize) | |||
@@ -70,21 +69,20 @@ cdb_init(struct cdb *cdbp, int fd) | |||
return 0; | |||
} | |||
void | |||
cdb_free(struct cdb *cdbp) | |||
void cdb_free(struct cdb *cdbp) | |||
{ | |||
if (cdbp->cdb_mem) { | |||
#ifdef _WIN32 | |||
UnmapViewOfFile((void*) cdbp->cdb_mem); | |||
UnmapViewOfFile((void *) cdbp->cdb_mem); | |||
#else | |||
munmap ((void*) cdbp->cdb_mem, cdbp->cdb_fsize); | |||
munmap((void *) cdbp->cdb_mem, cdbp->cdb_fsize); | |||
#endif /* _WIN32 */ | |||
cdbp->cdb_mem = NULL; | |||
} | |||
cdbp->cdb_fsize = 0; | |||
if (cdbp->loop) { | |||
ev_stat_stop (cdbp->loop, &cdbp->stat_ev); | |||
ev_stat_stop(cdbp->loop, &cdbp->stat_ev); | |||
} | |||
} | |||
@@ -98,43 +96,41 @@ cdb_get(const struct cdb *cdbp, unsigned len, unsigned pos) | |||
return cdbp->cdb_mem + pos; | |||
} | |||
int | |||
cdb_read(const struct cdb *cdbp, void *buf, unsigned len, unsigned pos) | |||
int cdb_read(const struct cdb *cdbp, void *buf, unsigned len, unsigned pos) | |||
{ | |||
const void *data = cdb_get (cdbp, len, pos); | |||
const void *data = cdb_get(cdbp, len, pos); | |||
if (!data) | |||
return -1; | |||
memcpy (buf, data, len); | |||
memcpy(buf, data, len); | |||
return 0; | |||
} | |||
static void | |||
cdb_timer_callback (EV_P_ ev_stat *w, int revents) | |||
cdb_timer_callback(EV_P_ ev_stat *w, int revents) | |||
{ | |||
struct cdb *cdbp = w->data; | |||
gint nfd; | |||
int nfd; | |||
/* Check cdb file for modifications */ | |||
if ((nfd = open (cdbp->filename, O_RDONLY)) != -1) { | |||
if ((nfd = open(cdbp->filename, O_RDONLY)) != -1) { | |||
if (cdbp->cdb_mem) { | |||
#ifdef _WIN32 | |||
UnmapViewOfFile((void*) cdbp->cdb_mem); | |||
UnmapViewOfFile((void *) cdbp->cdb_mem); | |||
#else | |||
munmap ((void*) cdbp->cdb_mem, cdbp->cdb_fsize); | |||
munmap((void *) cdbp->cdb_mem, cdbp->cdb_fsize); | |||
#endif /* _WIN32 */ | |||
cdbp->cdb_mem = NULL; | |||
} | |||
(void)close (cdbp->cdb_fd); | |||
(void) close(cdbp->cdb_fd); | |||
cdbp->cdb_fsize = 0; | |||
(void)cdb_init (cdbp, nfd); | |||
(void) cdb_init(cdbp, nfd); | |||
} | |||
} | |||
void | |||
cdb_add_timer (struct cdb *cdbp, EV_P_ ev_tstamp seconds) | |||
void cdb_add_timer(struct cdb *cdbp, EV_P_ ev_tstamp seconds) | |||
{ | |||
cdbp->loop = loop; | |||
ev_stat_init (&cdbp->stat_ev, cdb_timer_callback, cdbp->filename, seconds); | |||
ev_stat_init(&cdbp->stat_ev, cdb_timer_callback, cdbp->filename, seconds); | |||
cdbp->stat_ev.data = cdbp; | |||
ev_stat_start (EV_A_ &cdbp->stat_ev); | |||
ev_stat_start(EV_A_ & cdbp->stat_ev); | |||
} |
@@ -50,34 +50,33 @@ typedef uint8_t btrie_oct_t; | |||
* in btrie_walk() --- btrie_add_prefix() and btrie_lookup() impose no | |||
* limit on the length of bitstrings | |||
*/ | |||
#define BTRIE_MAX_PREFIX 128 | |||
#define BTRIE_MAX_PREFIX 128 | |||
struct btrie; | |||
struct memory_pool_s; | |||
struct btrie * btrie_init(struct memory_pool_s *mp); | |||
struct btrie *btrie_init(struct memory_pool_s *mp); | |||
enum btrie_result | |||
{ | |||
enum btrie_result { | |||
BTRIE_OKAY = 0, | |||
BTRIE_ALLOC_FAILED = -1, | |||
BTRIE_DUPLICATE_PREFIX = 1 | |||
}; | |||
enum btrie_result btrie_add_prefix(struct btrie *btrie, | |||
const btrie_oct_t *prefix, unsigned len, const void *data); | |||
const btrie_oct_t *prefix, unsigned len, const void *data); | |||
const void *btrie_lookup(const struct btrie *btrie, const btrie_oct_t *pfx, | |||
unsigned len); | |||
unsigned len); | |||
const char *btrie_stats(const struct btrie *btrie, guint duplicates); | |||
const char *btrie_stats(const struct btrie *btrie, unsigned int duplicates); | |||
#ifndef NO_MASTER_DUMP | |||
typedef void btrie_walk_cb_t(const btrie_oct_t *prefix, unsigned len, | |||
const void *data, int post, void *user_data); | |||
const void *data, int post, void *user_data); | |||
void btrie_walk(const struct btrie *btrie, btrie_walk_cb_t *callback, | |||
void *user_data); | |||
void *user_data); | |||
#endif /* not NO_MASTER_DUMP */ | |||
#endif /* _BTRIE_H_INCLUDED */ |
@@ -45,7 +45,7 @@ struct ucl_hash_struct { | |||
}; | |||
static uint64_t | |||
ucl_hash_seed (void) | |||
ucl_hash_seed(void) | |||
{ | |||
static uint64_t seed; | |||
if (seed == 0) { | |||
@@ -53,41 +53,41 @@ ucl_hash_seed (void) | |||
seed = UCL_RANDOM_FUNCTION; | |||
#else | |||
/* Not very random but can be useful for our purposes */ | |||
seed = time (NULL); | |||
seed = time(NULL); | |||
#endif | |||
} | |||
return seed; | |||
} | |||
extern const guchar lc_map[256]; | |||
extern const unsigned char lc_map[256]; | |||
static inline uint32_t | |||
ucl_hash_func (const ucl_object_t *o) | |||
ucl_hash_func(const ucl_object_t *o) | |||
{ | |||
return (uint32_t)rspamd_cryptobox_fast_hash (o->key, o->keylen, 0xb9a1ef83c4561c95ULL); | |||
return (uint32_t) rspamd_cryptobox_fast_hash(o->key, o->keylen, 0xb9a1ef83c4561c95ULL); | |||
} | |||
static inline int | |||
ucl_hash_equal (const ucl_object_t *k1, const ucl_object_t *k2) | |||
ucl_hash_equal(const ucl_object_t *k1, const ucl_object_t *k2) | |||
{ | |||
if (k1->keylen == k2->keylen) { | |||
return memcmp (k1->key, k2->key, k1->keylen) == 0; | |||
return memcmp(k1->key, k2->key, k1->keylen) == 0; | |||
} | |||
return 0; | |||
} | |||
KHASH_INIT (ucl_hash_node, const ucl_object_t *, struct ucl_hash_elt *, 1, | |||
ucl_hash_func, ucl_hash_equal) | |||
KHASH_INIT(ucl_hash_node, const ucl_object_t *, struct ucl_hash_elt *, 1, | |||
ucl_hash_func, ucl_hash_equal) | |||
static inline uint32_t | |||
ucl_hash_caseless_func (const ucl_object_t *o) | |||
ucl_hash_caseless_func(const ucl_object_t *o) | |||
{ | |||
unsigned len = o->keylen; | |||
unsigned leftover = o->keylen % 4; | |||
unsigned fp, i; | |||
const uint8_t* s = (const uint8_t*)o->key; | |||
const uint8_t *s = (const uint8_t *) o->key; | |||
union { | |||
struct { | |||
unsigned char c1, c2, c3, c4; | |||
@@ -98,7 +98,7 @@ ucl_hash_caseless_func (const ucl_object_t *o) | |||
rspamd_cryptobox_fast_hash_state_t hst; | |||
fp = len - leftover; | |||
rspamd_cryptobox_fast_hash_init (&hst, h); | |||
rspamd_cryptobox_fast_hash_init(&hst, h); | |||
for (i = 0; i != fp; i += 4) { | |||
u.c.c1 = s[i], u.c.c2 = s[i + 1], u.c.c3 = s[i + 2], u.c.c4 = s[i + 3]; | |||
@@ -106,58 +106,58 @@ ucl_hash_caseless_func (const ucl_object_t *o) | |||
u.c.c2 = lc_map[u.c.c2]; | |||
u.c.c3 = lc_map[u.c.c3]; | |||
u.c.c4 = lc_map[u.c.c4]; | |||
rspamd_cryptobox_fast_hash_update (&hst, &u, sizeof (u)); | |||
rspamd_cryptobox_fast_hash_update(&hst, &u, sizeof(u)); | |||
} | |||
u.pp = 0; | |||
switch (leftover) { | |||
case 3: | |||
u.c.c3 = lc_map[(unsigned char)s[i++]]; | |||
u.c.c3 = lc_map[(unsigned char) s[i++]]; | |||
case 2: | |||
/* fallthrough */ | |||
u.c.c2 = lc_map[(unsigned char)s[i++]]; | |||
u.c.c2 = lc_map[(unsigned char) s[i++]]; | |||
case 1: | |||
/* fallthrough */ | |||
u.c.c1 = lc_map[(unsigned char)s[i]]; | |||
rspamd_cryptobox_fast_hash_update (&hst, &u, sizeof (u)); | |||
u.c.c1 = lc_map[(unsigned char) s[i]]; | |||
rspamd_cryptobox_fast_hash_update(&hst, &u, sizeof(u)); | |||
break; | |||
} | |||
return (uint32_t)rspamd_cryptobox_fast_hash_final (&hst); | |||
return (uint32_t) rspamd_cryptobox_fast_hash_final(&hst); | |||
} | |||
static inline bool | |||
ucl_hash_caseless_equal (const ucl_object_t *k1, const ucl_object_t *k2) | |||
ucl_hash_caseless_equal(const ucl_object_t *k1, const ucl_object_t *k2) | |||
{ | |||
if (k1->keylen == k2->keylen) { | |||
return rspamd_lc_cmp (k1->key, k2->key, k1->keylen) == 0; | |||
return rspamd_lc_cmp(k1->key, k2->key, k1->keylen) == 0; | |||
} | |||
return false; | |||
} | |||
KHASH_INIT (ucl_hash_caseless_node, const ucl_object_t *, struct ucl_hash_elt *, 1, | |||
ucl_hash_caseless_func, ucl_hash_caseless_equal) | |||
KHASH_INIT(ucl_hash_caseless_node, const ucl_object_t *, struct ucl_hash_elt *, 1, | |||
ucl_hash_caseless_func, ucl_hash_caseless_equal) | |||
ucl_hash_t* | |||
ucl_hash_create (bool ignore_case) | |||
ucl_hash_t * | |||
ucl_hash_create(bool ignore_case) | |||
{ | |||
ucl_hash_t *new; | |||
new = UCL_ALLOC (sizeof (ucl_hash_t)); | |||
new = UCL_ALLOC(sizeof(ucl_hash_t)); | |||
if (new != NULL) { | |||
void *h; | |||
new->head = NULL; | |||
new->caseless = ignore_case; | |||
if (ignore_case) { | |||
h = (void *)kh_init (ucl_hash_caseless_node); | |||
h = (void *) kh_init(ucl_hash_caseless_node); | |||
} | |||
else { | |||
h = (void *)kh_init (ucl_hash_node); | |||
h = (void *) kh_init(ucl_hash_node); | |||
} | |||
if (h == NULL) { | |||
UCL_FREE (sizeof (ucl_hash_t), new); | |||
UCL_FREE(sizeof(ucl_hash_t), new); | |||
return NULL; | |||
} | |||
new->hash = h; | |||
@@ -165,7 +165,7 @@ ucl_hash_create (bool ignore_case) | |||
return new; | |||
} | |||
void ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func func) | |||
void ucl_hash_destroy(ucl_hash_t *hashlin, ucl_hash_free_func func) | |||
{ | |||
if (hashlin == NULL) { | |||
@@ -175,16 +175,16 @@ void ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func func) | |||
if (func != NULL) { | |||
/* Iterate over the hash first */ | |||
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) | |||
hashlin->hash; | |||
hashlin->hash; | |||
khiter_t k; | |||
const ucl_object_t *cur, *tmp; | |||
for (k = kh_begin (h); k != kh_end (h); ++k) { | |||
if (kh_exist (h, k)) { | |||
cur = (kh_value (h, k))->obj; | |||
for (k = kh_begin(h); k != kh_end(h); ++k) { | |||
if (kh_exist(h, k)) { | |||
cur = (kh_value(h, k))->obj; | |||
while (cur != NULL) { | |||
tmp = cur->next; | |||
func (__DECONST (ucl_object_t *, cur)); | |||
func(__DECONST(ucl_object_t *, cur)); | |||
cur = tmp; | |||
} | |||
} | |||
@@ -193,27 +193,27 @@ void ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func func) | |||
if (hashlin->caseless) { | |||
khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *) | |||
hashlin->hash; | |||
kh_destroy (ucl_hash_caseless_node, h); | |||
hashlin->hash; | |||
kh_destroy(ucl_hash_caseless_node, h); | |||
} | |||
else { | |||
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) | |||
hashlin->hash; | |||
kh_destroy (ucl_hash_node, h); | |||
hashlin->hash; | |||
kh_destroy(ucl_hash_node, h); | |||
} | |||
struct ucl_hash_elt *cur, *tmp; | |||
DL_FOREACH_SAFE(hashlin->head, cur, tmp) { | |||
DL_FOREACH_SAFE(hashlin->head, cur, tmp) | |||
{ | |||
UCL_FREE(sizeof(*cur), cur); | |||
} | |||
UCL_FREE (sizeof (*hashlin), hashlin); | |||
UCL_FREE(sizeof(*hashlin), hashlin); | |||
} | |||
bool | |||
ucl_hash_insert (ucl_hash_t* hashlin, const ucl_object_t *obj, | |||
const char *key, unsigned keylen) | |||
bool ucl_hash_insert(ucl_hash_t *hashlin, const ucl_object_t *obj, | |||
const char *key, unsigned keylen) | |||
{ | |||
khiter_t k; | |||
int ret; | |||
@@ -225,11 +225,11 @@ ucl_hash_insert (ucl_hash_t* hashlin, const ucl_object_t *obj, | |||
if (hashlin->caseless) { | |||
khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *) | |||
hashlin->hash; | |||
k = kh_put (ucl_hash_caseless_node, h, obj, &ret); | |||
hashlin->hash; | |||
k = kh_put(ucl_hash_caseless_node, h, obj, &ret); | |||
if (ret > 0) { | |||
elt = UCL_ALLOC(sizeof(*elt)); | |||
pelt = &kh_value (h, k); | |||
pelt = &kh_value(h, k); | |||
*pelt = elt; | |||
DL_APPEND(hashlin->head, elt); | |||
elt->obj = obj; | |||
@@ -240,25 +240,26 @@ ucl_hash_insert (ucl_hash_t* hashlin, const ucl_object_t *obj, | |||
} | |||
else { | |||
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) | |||
hashlin->hash; | |||
k = kh_put (ucl_hash_node, h, obj, &ret); | |||
hashlin->hash; | |||
k = kh_put(ucl_hash_node, h, obj, &ret); | |||
if (ret > 0) { | |||
elt = UCL_ALLOC(sizeof(*elt)); | |||
pelt = &kh_value (h, k); | |||
pelt = &kh_value(h, k); | |||
*pelt = elt; | |||
DL_APPEND(hashlin->head, elt); | |||
elt->obj = obj; | |||
} else if (ret < 0) { | |||
} | |||
else if (ret < 0) { | |||
goto e0; | |||
} | |||
} | |||
return true; | |||
e0: | |||
e0: | |||
return false; | |||
} | |||
void ucl_hash_replace (ucl_hash_t* hashlin, const ucl_object_t *old, | |||
const ucl_object_t *new) | |||
void ucl_hash_replace(ucl_hash_t *hashlin, const ucl_object_t *old, | |||
const ucl_object_t *new) | |||
{ | |||
khiter_t k; | |||
int ret; | |||
@@ -270,12 +271,12 @@ void ucl_hash_replace (ucl_hash_t* hashlin, const ucl_object_t *old, | |||
if (hashlin->caseless) { | |||
khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *) | |||
hashlin->hash; | |||
k = kh_put (ucl_hash_caseless_node, h, old, &ret); | |||
hashlin->hash; | |||
k = kh_put(ucl_hash_caseless_node, h, old, &ret); | |||
if (ret == 0) { | |||
elt = kh_value(h, k); | |||
kh_del (ucl_hash_caseless_node, h, k); | |||
k = kh_put (ucl_hash_caseless_node, h, new, &ret); | |||
kh_del(ucl_hash_caseless_node, h, k); | |||
k = kh_put(ucl_hash_caseless_node, h, new, &ret); | |||
nelt = UCL_ALLOC(sizeof(*nelt)); | |||
nelt->obj = new; | |||
kh_value(h, k) = nelt; | |||
@@ -285,12 +286,12 @@ void ucl_hash_replace (ucl_hash_t* hashlin, const ucl_object_t *old, | |||
} | |||
else { | |||
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) | |||
hashlin->hash; | |||
k = kh_put (ucl_hash_node, h, old, &ret); | |||
hashlin->hash; | |||
k = kh_put(ucl_hash_node, h, old, &ret); | |||
if (ret == 0) { | |||
elt = kh_value (h, k); | |||
kh_del (ucl_hash_node, h, k); | |||
k = kh_put (ucl_hash_node, h, new, &ret); | |||
elt = kh_value(h, k); | |||
kh_del(ucl_hash_node, h, k); | |||
k = kh_put(ucl_hash_node, h, new, &ret); | |||
nelt = UCL_ALLOC(sizeof(*nelt)); | |||
nelt->obj = new; | |||
kh_value(h, k) = nelt; | |||
@@ -304,12 +305,15 @@ struct ucl_hash_real_iter { | |||
const struct ucl_hash_elt *cur; | |||
}; | |||
#define UHI_SETERR(ep, ern) {if (ep != NULL) *ep = (ern);} | |||
#define UHI_SETERR(ep, ern) \ | |||
{ \ | |||
if (ep != NULL) *ep = (ern); \ | |||
} | |||
const void* | |||
ucl_hash_iterate2 (ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep) | |||
const void * | |||
ucl_hash_iterate2(ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep) | |||
{ | |||
struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *)(*iter); | |||
struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *) (*iter); | |||
const ucl_object_t *ret = NULL; | |||
if (hashlin == NULL) { | |||
@@ -318,7 +322,7 @@ ucl_hash_iterate2 (ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep) | |||
} | |||
if (it == NULL) { | |||
it = UCL_ALLOC (sizeof (*it)); | |||
it = UCL_ALLOC(sizeof(*it)); | |||
if (it == NULL) { | |||
UHI_SETERR(ep, ENOMEM); | |||
@@ -334,7 +338,7 @@ ucl_hash_iterate2 (ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep) | |||
it->cur = it->cur->next; | |||
} | |||
else { | |||
UCL_FREE (sizeof (*it), it); | |||
UCL_FREE(sizeof(*it), it); | |||
*iter = NULL; | |||
return NULL; | |||
} | |||
@@ -344,17 +348,16 @@ ucl_hash_iterate2 (ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep) | |||
return ret; | |||
} | |||
bool | |||
ucl_hash_iter_has_next (ucl_hash_t *hashlin, ucl_hash_iter_t iter) | |||
bool ucl_hash_iter_has_next(ucl_hash_t *hashlin, ucl_hash_iter_t iter) | |||
{ | |||
struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *)(iter); | |||
struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *) (iter); | |||
return it->cur != NULL; | |||
} | |||
const ucl_object_t* | |||
ucl_hash_search (ucl_hash_t* hashlin, const char *key, unsigned keylen) | |||
const ucl_object_t * | |||
ucl_hash_search(ucl_hash_t *hashlin, const char *key, unsigned keylen) | |||
{ | |||
khiter_t k; | |||
const ucl_object_t *ret = NULL; | |||
@@ -370,20 +373,20 @@ ucl_hash_search (ucl_hash_t* hashlin, const char *key, unsigned keylen) | |||
if (hashlin->caseless) { | |||
khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *) | |||
hashlin->hash; | |||
hashlin->hash; | |||
k = kh_get (ucl_hash_caseless_node, h, &search); | |||
if (k != kh_end (h)) { | |||
elt = kh_value (h, k); | |||
k = kh_get(ucl_hash_caseless_node, h, &search); | |||
if (k != kh_end(h)) { | |||
elt = kh_value(h, k); | |||
ret = elt->obj; | |||
} | |||
} | |||
else { | |||
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) | |||
hashlin->hash; | |||
k = kh_get (ucl_hash_node, h, &search); | |||
if (k != kh_end (h)) { | |||
elt = kh_value (h, k); | |||
hashlin->hash; | |||
k = kh_get(ucl_hash_node, h, &search); | |||
if (k != kh_end(h)) { | |||
elt = kh_value(h, k); | |||
ret = elt->obj; | |||
} | |||
} | |||
@@ -391,8 +394,7 @@ ucl_hash_search (ucl_hash_t* hashlin, const char *key, unsigned keylen) | |||
return ret; | |||
} | |||
void | |||
ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj) | |||
void ucl_hash_delete(ucl_hash_t *hashlin, const ucl_object_t *obj) | |||
{ | |||
khiter_t k; | |||
struct ucl_hash_elt *elt; | |||
@@ -403,46 +405,46 @@ ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj) | |||
if (hashlin->caseless) { | |||
khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *) | |||
hashlin->hash; | |||
hashlin->hash; | |||
k = kh_get (ucl_hash_caseless_node, h, obj); | |||
if (k != kh_end (h)) { | |||
elt = kh_value (h, k); | |||
k = kh_get(ucl_hash_caseless_node, h, obj); | |||
if (k != kh_end(h)) { | |||
elt = kh_value(h, k); | |||
DL_DELETE(hashlin->head, elt); | |||
kh_del (ucl_hash_caseless_node, h, k); | |||
kh_del(ucl_hash_caseless_node, h, k); | |||
UCL_FREE(sizeof(*elt), elt); | |||
} | |||
} | |||
else { | |||
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) | |||
hashlin->hash; | |||
k = kh_get (ucl_hash_node, h, obj); | |||
if (k != kh_end (h)) { | |||
elt = kh_value (h, k); | |||
hashlin->hash; | |||
k = kh_get(ucl_hash_node, h, obj); | |||
if (k != kh_end(h)) { | |||
elt = kh_value(h, k); | |||
DL_DELETE(hashlin->head, elt); | |||
kh_del (ucl_hash_node, h, k); | |||
kh_del(ucl_hash_node, h, k); | |||
UCL_FREE(sizeof(*elt), elt); | |||
} | |||
} | |||
} | |||
bool | |||
ucl_hash_reserve (ucl_hash_t *hashlin, size_t sz) | |||
bool ucl_hash_reserve(ucl_hash_t *hashlin, size_t sz) | |||
{ | |||
if (hashlin == NULL) { | |||
return false; | |||
} | |||
if (sz > kh_size((khash_t(ucl_hash_node) *)hashlin->hash)) { | |||
if (sz > kh_size((khash_t(ucl_hash_node) *) hashlin->hash)) { | |||
if (hashlin->caseless) { | |||
khash_t(ucl_hash_caseless_node) *h = (khash_t( | |||
ucl_hash_caseless_node) *) | |||
hashlin->hash; | |||
kh_resize (ucl_hash_caseless_node, h, sz * 2); | |||
} else { | |||
ucl_hash_caseless_node) *) | |||
hashlin->hash; | |||
kh_resize(ucl_hash_caseless_node, h, sz * 2); | |||
} | |||
else { | |||
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *) | |||
hashlin->hash; | |||
kh_resize (ucl_hash_node, h, sz * 2); | |||
hashlin->hash; | |||
kh_resize(ucl_hash_node, h, sz * 2); | |||
} | |||
} | |||
@@ -450,33 +452,32 @@ ucl_hash_reserve (ucl_hash_t *hashlin, size_t sz) | |||
} | |||
static int | |||
ucl_hash_cmp_icase (const void *a, const void *b) | |||
ucl_hash_cmp_icase(const void *a, const void *b) | |||
{ | |||
const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *)a, | |||
*ob = (const struct ucl_hash_elt *)b; | |||
const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *) a, | |||
*ob = (const struct ucl_hash_elt *) b; | |||
if (oa->obj->keylen == ob->obj->keylen) { | |||
return rspamd_lc_cmp (oa->obj->key, ob->obj->key, oa->obj->keylen); | |||
return rspamd_lc_cmp(oa->obj->key, ob->obj->key, oa->obj->keylen); | |||
} | |||
return ((int)(oa->obj->keylen)) - ob->obj->keylen; | |||
return ((int) (oa->obj->keylen)) - ob->obj->keylen; | |||
} | |||
static int | |||
ucl_hash_cmp_case_sens (const void *a, const void *b) | |||
ucl_hash_cmp_case_sens(const void *a, const void *b) | |||
{ | |||
const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *)a, | |||
*ob = (const struct ucl_hash_elt *)b; | |||
const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *) a, | |||
*ob = (const struct ucl_hash_elt *) b; | |||
if (oa->obj->keylen == ob->obj->keylen) { | |||
return memcmp (oa->obj->key, ob->obj->key, oa->obj->keylen); | |||
return memcmp(oa->obj->key, ob->obj->key, oa->obj->keylen); | |||
} | |||
return ((int)(oa->obj->keylen)) - ob->obj->keylen; | |||
return ((int) (oa->obj->keylen)) - ob->obj->keylen; | |||
} | |||
void | |||
ucl_hash_sort (ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl) | |||
void ucl_hash_sort(ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl) | |||
{ | |||
if (fl & UCL_SORT_KEYS_ICASE) { | |||
@@ -489,9 +490,10 @@ ucl_hash_sort (ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl) | |||
if (fl & UCL_SORT_KEYS_RECURSIVE) { | |||
struct ucl_hash_elt *elt; | |||
DL_FOREACH(hashlin->head, elt) { | |||
if (ucl_object_type (elt->obj) == UCL_OBJECT) { | |||
ucl_hash_sort (elt->obj->value.ov, fl); | |||
DL_FOREACH(hashlin->head, elt) | |||
{ | |||
if (ucl_object_type(elt->obj) == UCL_OBJECT) { | |||
ucl_hash_sort(elt->obj->value.ov, fl); | |||
} | |||
} | |||
} |
@@ -91,10 +91,10 @@ std::vector<GPid> children; | |||
static GPatternSpec **exclude_compiled = nullptr; | |||
static struct rspamd_http_context *http_ctx; | |||
static gint retcode = EXIT_SUCCESS; | |||
static int retcode = EXIT_SUCCESS; | |||
static gboolean rspamc_password_callback(const gchar *option_name, | |||
const gchar *value, | |||
static gboolean rspamc_password_callback(const char *option_name, | |||
const char *value, | |||
gpointer data, | |||
GError **error); | |||
@@ -496,8 +496,8 @@ auto sort_ucl_container_with_default(T &cont, const char *default_sort, | |||
static gboolean | |||
rspamc_password_callback(const gchar *option_name, | |||
const gchar *value, | |||
rspamc_password_callback(const char *option_name, | |||
const char *value, | |||
gpointer data, | |||
GError **error) | |||
{ | |||
@@ -558,7 +558,7 @@ rspamc_password_callback(const gchar *option_name, | |||
* Parse command line | |||
*/ | |||
static void | |||
read_cmd_line(gint *argc, gchar ***argv) | |||
read_cmd_line(int *argc, char ***argv) | |||
{ | |||
GError *error = nullptr; | |||
GOptionContext *context; | |||
@@ -672,7 +672,7 @@ check_rspamc_command(const char *cmd) -> std::optional<rspamc_command> | |||
static void | |||
print_commands_list() | |||
{ | |||
guint cmd_len = 0; | |||
unsigned int cmd_len = 0; | |||
rspamc_print(stdout, "Rspamc commands summary:\n"); | |||
@@ -1584,10 +1584,10 @@ rspamc_output_headers(FILE *out, struct rspamd_http_message *msg) | |||
static void | |||
rspamc_mime_output(FILE *out, ucl_object_t *result, GString *input, | |||
gdouble time, GError *err) | |||
double time, GError *err) | |||
{ | |||
const gchar *action = "no action", *line_end = "\r\n", *p; | |||
gdouble score = 0.0, required_score = 0.0; | |||
const char *action = "no action", *line_end = "\r\n", *p; | |||
double score = 0.0, required_score = 0.0; | |||
gboolean is_spam = FALSE; | |||
auto nl_type = RSPAMD_TASK_NEWLINES_CRLF; | |||
@@ -1748,10 +1748,10 @@ rspamc_mime_output(FILE *out, ucl_object_t *result, GString *input, | |||
static void | |||
rspamc_client_execute_cmd(const struct rspamc_command &cmd, ucl_object_t *result, | |||
GString *input, gdouble time, GError *err) | |||
GString *input, double time, GError *err) | |||
{ | |||
gchar **eargv; | |||
gint eargc, infd, outfd, errfd; | |||
char **eargv; | |||
int eargc, infd, outfd, errfd; | |||
GError *exec_err = nullptr; | |||
GPid cld; | |||
@@ -1814,13 +1814,13 @@ static void | |||
rspamc_client_cb(struct rspamd_client_connection *conn, | |||
struct rspamd_http_message *msg, | |||
const char *name, ucl_object_t *result, GString *input, | |||
gpointer ud, gdouble start_time, gdouble send_time, | |||
gpointer ud, double start_time, double send_time, | |||
const char *body, gsize bodylen, | |||
GError *err) | |||
{ | |||
struct rspamc_callback_data *cbdata = (struct rspamc_callback_data *) ud; | |||
FILE *out = stdout; | |||
gdouble finish = rspamd_get_ticks(FALSE), diff; | |||
double finish = rspamd_get_ticks(FALSE), diff; | |||
auto &cmd = cbdata->cmd; | |||
@@ -1939,7 +1939,7 @@ rspamc_process_input(struct ev_loop *ev_base, const struct rspamc_command &cmd, | |||
{ | |||
struct rspamd_client_connection *conn; | |||
const char *p; | |||
guint16 port; | |||
uint16_t port; | |||
GError *err = nullptr; | |||
std::string hostbuf; | |||
@@ -38,7 +38,7 @@ struct rspamd_client_request; | |||
* Since rspamd uses untagged HTTP we can pass a single message per socket | |||
*/ | |||
struct rspamd_client_connection { | |||
gint fd; | |||
int fd; | |||
GString *server_name; | |||
struct rspamd_cryptobox_pubkey *key; | |||
struct rspamd_cryptobox_keypair *keypair; | |||
@@ -46,8 +46,8 @@ struct rspamd_client_connection { | |||
ev_tstamp timeout; | |||
struct rspamd_http_connection *http_conn; | |||
gboolean req_sent; | |||
gdouble start_time; | |||
gdouble send_time; | |||
double start_time; | |||
double send_time; | |||
struct rspamd_client_request *req; | |||
struct rspamd_keypair_cache *keys_cache; | |||
}; | |||
@@ -82,10 +82,10 @@ rspamd_client_request_free(struct rspamd_client_request *req) | |||
} | |||
} | |||
static gint | |||
static int | |||
rspamd_client_body_handler(struct rspamd_http_connection *conn, | |||
struct rspamd_http_message *msg, | |||
const gchar *chunk, gsize len) | |||
const char *chunk, gsize len) | |||
{ | |||
/* Do nothing here */ | |||
return 0; | |||
@@ -104,7 +104,7 @@ rspamd_client_error_handler(struct rspamd_http_connection *conn, GError *err) | |||
c->start_time, c->send_time, NULL, 0, err); | |||
} | |||
static gint | |||
static int | |||
rspamd_client_finish_handler(struct rspamd_http_connection *conn, | |||
struct rspamd_http_message *msg) | |||
{ | |||
@@ -114,8 +114,8 @@ rspamd_client_finish_handler(struct rspamd_http_connection *conn, | |||
struct ucl_parser *parser; | |||
GError *err; | |||
const rspamd_ftok_t *tok; | |||
const gchar *start, *body = NULL; | |||
guchar *out = NULL; | |||
const char *start, *body = NULL; | |||
unsigned char *out = NULL; | |||
gsize len, bodylen = 0; | |||
c = req->conn; | |||
@@ -134,7 +134,7 @@ rspamd_client_finish_handler(struct rspamd_http_connection *conn, | |||
if (rspamd_http_message_get_body(msg, NULL) == NULL || msg->code / 100 != 2) { | |||
err = g_error_new(RCLIENT_ERROR, msg->code, "HTTP error: %d, %.*s", | |||
msg->code, | |||
(gint) msg->status->len, msg->status->str); | |||
(int) msg->status->len, msg->status->str); | |||
req->cb(c, msg, c->server_name->str, NULL, req->input, req->ud, | |||
c->start_time, c->send_time, body, bodylen, err); | |||
g_error_free(err); | |||
@@ -263,11 +263,11 @@ end: | |||
struct rspamd_client_connection * | |||
rspamd_client_init(struct rspamd_http_context *http_ctx, | |||
struct ev_loop *ev_base, const gchar *name, | |||
guint16 port, gdouble timeout, const gchar *key) | |||
struct ev_loop *ev_base, const char *name, | |||
uint16_t port, double timeout, const char *key) | |||
{ | |||
struct rspamd_client_connection *conn; | |||
gint fd; | |||
int fd; | |||
fd = rspamd_socket(name, port, SOCK_STREAM, TRUE, FALSE, TRUE); | |||
@@ -321,21 +321,21 @@ rspamd_client_init(struct rspamd_http_context *http_ctx, | |||
gboolean | |||
rspamd_client_command(struct rspamd_client_connection *conn, | |||
const gchar *command, GQueue *attrs, | |||
const char *command, GQueue *attrs, | |||
FILE *in, rspamd_client_callback cb, | |||
gpointer ud, gboolean compressed, | |||
const gchar *comp_dictionary, | |||
const gchar *filename, | |||
const char *comp_dictionary, | |||
const char *filename, | |||
GError **err) | |||
{ | |||
struct rspamd_client_request *req; | |||
struct rspamd_http_client_header *nh; | |||
gchar *p; | |||
char *p; | |||
gsize remain, old_len; | |||
GList *cur; | |||
GString *input = NULL; | |||
rspamd_fstring_t *body; | |||
guint dict_id = 0; | |||
unsigned int dict_id = 0; | |||
gsize dict_len = 0; | |||
void *dict = NULL; | |||
ZSTD_CCtx *zctx; | |||
@@ -445,7 +445,7 @@ rspamd_client_command(struct rspamd_client_connection *conn, | |||
rspamd_http_message_add_header(req->msg, COMPRESSION_HEADER, "zstd"); | |||
if (dict_id != 0) { | |||
gchar dict_str[32]; | |||
char dict_str[32]; | |||
rspamd_snprintf(dict_str, sizeof(dict_str), "%ud", dict_id); | |||
rspamd_http_message_add_header(req->msg, "Dictionary", dict_str); |
@@ -1,11 +1,11 @@ | |||
/*- | |||
* Copyright 2016 Vsevolod Stakhov | |||
/* | |||
* Copyright 2024 Vsevolod Stakhov | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
@@ -28,8 +28,8 @@ struct rspamd_client_connection; | |||
struct rspamd_http_message; | |||
struct rspamd_http_client_header { | |||
gchar *name; | |||
gchar *value; | |||
char *name; | |||
char *value; | |||
}; | |||
/** | |||
@@ -43,13 +43,13 @@ struct rspamd_http_client_header { | |||
typedef void (*rspamd_client_callback)( | |||
struct rspamd_client_connection *conn, | |||
struct rspamd_http_message *msg, | |||
const gchar *name, | |||
const char *name, | |||
ucl_object_t *result, | |||
GString *input, | |||
gpointer ud, | |||
gdouble start_time, | |||
gdouble send_time, | |||
const gchar *body, | |||
double start_time, | |||
double send_time, | |||
const char *body, | |||
gsize body_len, | |||
GError *err); | |||
@@ -66,10 +66,10 @@ struct rspamd_http_context; | |||
struct rspamd_client_connection *rspamd_client_init( | |||
struct rspamd_http_context *http_ctx, | |||
struct ev_loop *ev_base, | |||
const gchar *name, | |||
guint16 port, | |||
gdouble timeout, | |||
const gchar *key); | |||
const char *name, | |||
uint16_t port, | |||
double timeout, | |||
const char *key); | |||
/** | |||
* | |||
@@ -83,14 +83,14 @@ struct rspamd_client_connection *rspamd_client_init( | |||
*/ | |||
gboolean rspamd_client_command( | |||
struct rspamd_client_connection *conn, | |||
const gchar *command, | |||
const char *command, | |||
GQueue *attrs, | |||
FILE *in, | |||
rspamd_client_callback cb, | |||
gpointer ud, | |||
gboolean compressed, | |||
const gchar *comp_dictionary, | |||
const gchar *filename, | |||
const char *comp_dictionary, | |||
const char *filename, | |||
GError **err); | |||
/** |
@@ -108,7 +108,7 @@ INIT_LOG_MODULE(controller) | |||
#define COLOR_REJECT "#CB4B4B" | |||
#define COLOR_TOTAL "#9440ED" | |||
static const guint64 rspamd_controller_ctx_magic = 0xf72697805e6941faULL; | |||
static const uint64_t rspamd_controller_ctx_magic = 0xf72697805e6941faULL; | |||
extern void fuzzy_stat_command(struct rspamd_task *task); | |||
@@ -128,7 +128,7 @@ worker_t controller_worker = { | |||
* Worker's context | |||
*/ | |||
struct rspamd_controller_worker_ctx { | |||
guint64 magic; | |||
uint64_t magic; | |||
/* Events base */ | |||
struct ev_loop *event_loop; | |||
/* DNS resolver */ | |||
@@ -140,9 +140,9 @@ struct rspamd_controller_worker_ctx { | |||
/* Whether we use ssl for this server */ | |||
gboolean use_ssl; | |||
/* Webui password */ | |||
gchar *password; | |||
char *password; | |||
/* Privileged password */ | |||
gchar *enable_password; | |||
char *enable_password; | |||
/* Cached versions of the passwords */ | |||
rspamd_ftok_t cached_password; | |||
rspamd_ftok_t cached_enable_password; | |||
@@ -154,15 +154,15 @@ struct rspamd_controller_worker_ctx { | |||
/* Main server */ | |||
struct rspamd_main *srv; | |||
/* SSL cert */ | |||
gchar *ssl_cert; | |||
char *ssl_cert; | |||
/* SSL private key */ | |||
gchar *ssl_key; | |||
char *ssl_key; | |||
/* A map of secure IP */ | |||
const ucl_object_t *secure_ip; | |||
struct rspamd_radix_map_helper *secure_map; | |||
/* Static files dir */ | |||
gchar *static_files_dir; | |||
char *static_files_dir; | |||
/* Custom commands registered by plugins */ | |||
GHashTable *custom_commands; | |||
@@ -178,32 +178,32 @@ struct rspamd_controller_worker_ctx { | |||
struct rspamd_rrd_file *rrd; | |||
struct rspamd_lang_detector *lang_det; | |||
gdouble task_timeout; | |||
double task_timeout; | |||
/* Health check stuff */ | |||
guint workers_count; | |||
guint scanners_count; | |||
guint workers_hb_lost; | |||
unsigned int workers_count; | |||
unsigned int scanners_count; | |||
unsigned int workers_hb_lost; | |||
ev_timer health_check_timer; | |||
}; | |||
struct rspamd_controller_plugin_cbdata { | |||
lua_State *L; | |||
struct rspamd_controller_worker_ctx *ctx; | |||
gchar *plugin; | |||
char *plugin; | |||
struct ucl_lua_funcdata *handler; | |||
ucl_object_t *obj; | |||
gboolean is_enable; | |||
gboolean need_task; | |||
guint version; | |||
unsigned int version; | |||
}; | |||
static gboolean | |||
rspamd_is_encrypted_password(const gchar *password, | |||
rspamd_is_encrypted_password(const char *password, | |||
struct rspamd_controller_pbkdf const **pbkdf) | |||
{ | |||
const gchar *start, *end; | |||
gint64 id; | |||
const char *start, *end; | |||
int64_t id; | |||
gsize size, i; | |||
gboolean ret = FALSE; | |||
const struct rspamd_controller_pbkdf *p; | |||
@@ -220,7 +220,7 @@ rspamd_is_encrypted_password(const gchar *password, | |||
} | |||
if (size > 0) { | |||
gchar *endptr; | |||
char *endptr; | |||
id = strtoul(start, &endptr, 10); | |||
if ((endptr == NULL || *endptr == *end)) { | |||
@@ -243,11 +243,11 @@ rspamd_is_encrypted_password(const gchar *password, | |||
return ret; | |||
} | |||
static const gchar * | |||
rspamd_encrypted_password_get_str(const gchar *password, gsize skip, | |||
static const char * | |||
rspamd_encrypted_password_get_str(const char *password, gsize skip, | |||
gsize *length) | |||
{ | |||
const gchar *str, *start, *end; | |||
const char *str, *start, *end; | |||
gsize size; | |||
start = password + skip; | |||
@@ -272,15 +272,15 @@ rspamd_encrypted_password_get_str(const gchar *password, gsize skip, | |||
static gboolean | |||
rspamd_check_encrypted_password(struct rspamd_controller_worker_ctx *ctx, | |||
const rspamd_ftok_t *password, const gchar *check, | |||
const rspamd_ftok_t *password, const char *check, | |||
const struct rspamd_controller_pbkdf *pbkdf, | |||
gboolean is_enable) | |||
{ | |||
const gchar *salt, *hash; | |||
gchar *salt_decoded, *key_decoded; | |||
const char *salt, *hash; | |||
char *salt_decoded, *key_decoded; | |||
gsize salt_len = 0, key_len = 0; | |||
gboolean ret = TRUE; | |||
guchar *local_key; | |||
unsigned char *local_key; | |||
rspamd_ftok_t *cache; | |||
gpointer m; | |||
@@ -412,17 +412,17 @@ check_uncached: | |||
* @return 0 if no forwarded found, 1 if forwarded found and it is yet trusted | |||
* and -1 if forwarded is denied | |||
*/ | |||
static gint | |||
static int | |||
rspamd_controller_check_forwarded(struct rspamd_controller_session *session, | |||
struct rspamd_http_message *msg, | |||
struct rspamd_controller_worker_ctx *ctx) | |||
{ | |||
const rspamd_ftok_t *hdr; | |||
const gchar *comma; | |||
const char *comma; | |||
const char *hdr_name = "X-Forwarded-For", *alt_hdr_name = "X-Real-IP"; | |||
char ip_buf[INET6_ADDRSTRLEN + 1]; | |||
rspamd_inet_addr_t *addr = NULL; | |||
gint ret = 0; | |||
int ret = 0; | |||
hdr = rspamd_http_message_find_header(msg, hdr_name); | |||
@@ -508,7 +508,7 @@ rspamd_controller_check_password(struct rspamd_http_connection_entry *entry, | |||
struct rspamd_controller_session *session, | |||
struct rspamd_http_message *msg, gboolean is_enable) | |||
{ | |||
const gchar *check; | |||
const char *check; | |||
const rspamd_ftok_t *password; | |||
rspamd_ftok_t lookup; | |||
GHashTable *query_args = NULL; | |||
@@ -562,7 +562,7 @@ rspamd_controller_check_password(struct rspamd_http_connection_entry *entry, | |||
/* Try to get password from query args */ | |||
query_args = rspamd_http_message_parse_query(msg); | |||
lookup.begin = (gchar *) "password"; | |||
lookup.begin = (char *) "password"; | |||
lookup.len = sizeof("password") - 1; | |||
password = g_hash_table_lookup(query_args, &lookup); | |||
@@ -830,7 +830,7 @@ rspamd_controller_handle_symbols(struct rspamd_http_connection_entry *conn_ent, | |||
group_symbols = ucl_object_typed_new(UCL_ARRAY); | |||
while (g_hash_table_iter_next(&sit, &k, &v)) { | |||
gdouble tm = 0.0, freq = 0, freq_dev = 0; | |||
double tm = 0.0, freq = 0, freq_dev = 0; | |||
sym = v; | |||
sym_obj = ucl_object_typed_new(UCL_OBJECT); | |||
@@ -918,7 +918,7 @@ rspamd_controller_handle_actions(struct rspamd_http_connection_entry *conn_ent, | |||
static gboolean | |||
rspamd_controller_can_edit_map(struct rspamd_map_backend *bk) | |||
{ | |||
gchar *fpath; | |||
char *fpath; | |||
if (access(bk->uri, W_OK) == 0) { | |||
return TRUE; | |||
@@ -961,7 +961,7 @@ rspamd_controller_handle_maps(struct rspamd_http_connection_entry *conn_ent, | |||
GList *cur; | |||
struct rspamd_map *map; | |||
struct rspamd_map_backend *bk; | |||
guint i; | |||
unsigned int i; | |||
gboolean editable; | |||
ucl_object_t *obj, *top; | |||
@@ -1026,7 +1026,7 @@ rspamd_controller_handle_get_map(struct rspamd_http_connection_entry *conn_ent, | |||
struct rspamd_map_backend *bk = NULL; | |||
const rspamd_ftok_t *idstr; | |||
struct stat st; | |||
gint fd; | |||
int fd; | |||
gulong id, i; | |||
gboolean found = FALSE; | |||
struct rspamd_http_message *reply; | |||
@@ -1111,7 +1111,7 @@ rspamd_controller_handle_get_map(struct rspamd_http_connection_entry *conn_ent, | |||
static ucl_object_t * | |||
rspamd_controller_pie_element(enum rspamd_action_type action, | |||
const char *label, gdouble data) | |||
const char *label, double data) | |||
{ | |||
ucl_object_t *res = ucl_object_typed_new(UCL_OBJECT); | |||
const char *colors[METRIC_ACTION_MAX] = { | |||
@@ -1148,7 +1148,7 @@ rspamd_controller_handle_pie_chart( | |||
{ | |||
struct rspamd_controller_session *session = conn_ent->ud; | |||
struct rspamd_controller_worker_ctx *ctx; | |||
gdouble data[5], total; | |||
double data[5], total; | |||
ucl_object_t *top; | |||
ctx = session->ctx; | |||
@@ -1190,13 +1190,13 @@ rspamd_controller_handle_pie_chart( | |||
void rspamd_controller_graph_point(gulong t, gulong step, | |||
struct rspamd_rrd_query_result *rrd_result, | |||
gdouble *acc, | |||
double *acc, | |||
ucl_object_t **elt) | |||
{ | |||
guint nan_cnt; | |||
gdouble sum = 0.0, yval; | |||
unsigned int nan_cnt; | |||
double sum = 0.0, yval; | |||
ucl_object_t *data_elt; | |||
guint i, j; | |||
unsigned int i, j; | |||
for (i = 0; i < rrd_result->ds_count; i++) { | |||
sum = 0.0; | |||
@@ -1219,7 +1219,7 @@ void rspamd_controller_graph_point(gulong t, gulong step, | |||
} | |||
else { | |||
ucl_object_insert_key(data_elt, | |||
ucl_object_fromdouble(sum / (gdouble) step), "y", 1, | |||
ucl_object_fromdouble(sum / (double) step), "y", 1, | |||
false); | |||
} | |||
ucl_array_append(elt[i], data_elt); | |||
@@ -1247,7 +1247,7 @@ rspamd_controller_handle_graph( | |||
rspamd_ftok_t srch, *value; | |||
struct rspamd_rrd_query_result *rrd_result; | |||
gulong i, k, start_row, cnt, t, ts, step; | |||
gdouble *acc; | |||
double *acc; | |||
ucl_object_t *res, *elt[METRIC_ACTION_MAX]; | |||
enum { | |||
rra_day = 0, | |||
@@ -1257,7 +1257,7 @@ rspamd_controller_handle_graph( | |||
rra_invalid | |||
} rra_num = rra_invalid; | |||
/* How many points are we going to send to display */ | |||
static const guint desired_points = 500; | |||
static const unsigned int desired_points = 500; | |||
ctx = session->ctx; | |||
@@ -1273,7 +1273,7 @@ rspamd_controller_handle_graph( | |||
} | |||
query = rspamd_http_message_parse_query(msg); | |||
srch.begin = (gchar *) "type"; | |||
srch.begin = (char *) "type"; | |||
srch.len = 4; | |||
if (query == NULL || (value = g_hash_table_lookup(query, &srch)) == NULL) { | |||
@@ -1333,7 +1333,7 @@ rspamd_controller_handle_graph( | |||
k = 0; | |||
/* Create window */ | |||
step = ceil(((gdouble) rrd_result->rra_rows) / desired_points); | |||
step = ceil(((double) rrd_result->rra_rows) / desired_points); | |||
g_assert(step >= 1); | |||
acc = g_malloc0(sizeof(double) * rrd_result->ds_count * step); | |||
@@ -1342,7 +1342,7 @@ rspamd_controller_handle_graph( | |||
memcpy(&acc[k * rrd_result->ds_count], | |||
&rrd_result->data[i * rrd_result->ds_count], | |||
sizeof(gdouble) * rrd_result->ds_count); | |||
sizeof(double) * rrd_result->ds_count); | |||
if (k < step - 1) { | |||
k++; | |||
@@ -1389,9 +1389,9 @@ rspamd_controller_handle_legacy_history( | |||
struct rspamd_http_message *msg) | |||
{ | |||
struct roll_history_row *row, *copied_rows; | |||
guint i, rows_proc, row_num; | |||
unsigned int i, rows_proc, row_num; | |||
struct tm tm; | |||
gchar timebuf[32], **syms; | |||
char timebuf[32], **syms; | |||
ucl_object_t *top, *obj; | |||
top = ucl_object_typed_new(UCL_ARRAY); | |||
@@ -1446,11 +1446,11 @@ rspamd_controller_handle_legacy_history( | |||
syms = g_strsplit_set(row->symbols, ", ", -1); | |||
if (syms) { | |||
guint nelts = g_strv_length(syms); | |||
unsigned int nelts = g_strv_length(syms); | |||
ucl_object_t *syms_obj = ucl_object_typed_new(UCL_OBJECT); | |||
ucl_object_reserve(syms_obj, nelts); | |||
for (guint j = 0; j < nelts; j++) { | |||
for (unsigned int j = 0; j < nelts; j++) { | |||
g_strstrip(syms[j]); | |||
if (strlen(syms[j]) == 0) { | |||
@@ -1755,7 +1755,7 @@ rspamd_controller_handle_history_reset(struct rspamd_http_connection_entry *conn | |||
struct rspamd_controller_session *session = conn_ent->ud; | |||
struct rspamd_controller_worker_ctx *ctx; | |||
struct roll_history_row *row; | |||
guint completed_rows, i, t; | |||
unsigned int completed_rows, i, t; | |||
lua_State *L; | |||
ctx = session->ctx; | |||
@@ -1820,7 +1820,7 @@ rspamd_controller_handle_lua(struct rspamd_http_connection_entry *conn_ent, | |||
struct rspamd_task *task, **ptask; | |||
struct rspamd_http_connection_entry **pconn; | |||
struct rspamd_controller_worker_ctx *ctx; | |||
gchar filebuf[PATH_MAX], realbuf[PATH_MAX]; | |||
char filebuf[PATH_MAX], realbuf[PATH_MAX]; | |||
struct http_parser_url u; | |||
rspamd_ftok_t lookup; | |||
struct stat st; | |||
@@ -2237,9 +2237,9 @@ rspamd_controller_handle_saveactions( | |||
ucl_object_t *obj; | |||
const ucl_object_t *cur; | |||
struct rspamd_controller_worker_ctx *ctx; | |||
const gchar *error; | |||
gdouble score; | |||
gint i, added = 0; | |||
const char *error; | |||
double score; | |||
int i, added = 0; | |||
enum rspamd_action_type act; | |||
ucl_object_iter_t it = NULL; | |||
@@ -2361,8 +2361,8 @@ rspamd_controller_handle_savesymbols( | |||
const ucl_object_t *cur, *jname, *jvalue; | |||
ucl_object_iter_t iter = NULL; | |||
struct rspamd_controller_worker_ctx *ctx; | |||
const gchar *error; | |||
gdouble val; | |||
const char *error; | |||
double val; | |||
struct rspamd_symbol *sym; | |||
int added = 0; | |||
@@ -2492,8 +2492,8 @@ rspamd_controller_handle_savemap(struct rspamd_http_connection_entry *conn_ent, | |||
const rspamd_ftok_t *idstr; | |||
gulong id, i; | |||
gboolean found = FALSE; | |||
gchar tempname[PATH_MAX]; | |||
gint fd; | |||
char tempname[PATH_MAX]; | |||
int fd; | |||
ctx = session->ctx; | |||
@@ -2590,7 +2590,7 @@ struct rspamd_stat_cbdata { | |||
ucl_object_t *top; | |||
ucl_object_t *stat; | |||
struct rspamd_task *task; | |||
guint64 learned; | |||
uint64_t learned; | |||
}; | |||
static gboolean | |||
@@ -2658,9 +2658,9 @@ rspamd_controller_handle_stat_common( | |||
{ | |||
struct rspamd_controller_session *session = conn_ent->ud; | |||
ucl_object_t *top, *sub; | |||
gint i; | |||
int i; | |||
int64_t uptime; | |||
guint64 spam = 0, ham = 0; | |||
uint64_t spam = 0, ham = 0; | |||
rspamd_mempool_stat_t mem_st; | |||
struct rspamd_stat *stat, stat_copy; | |||
struct rspamd_controller_worker_ctx *ctx; | |||
@@ -2839,7 +2839,7 @@ rspamd_controller_metrics_fin_task(void *ud) | |||
ucl_object_t *top; | |||
struct rspamd_fuzzy_stat_entry *entry; | |||
rspamd_fstring_t *output; | |||
gint i; | |||
int i; | |||
conn_ent = cbdata->conn_ent; | |||
top = cbdata->top; | |||
@@ -3095,9 +3095,9 @@ rspamd_controller_handle_metrics_common( | |||
{ | |||
struct rspamd_controller_session *session = conn_ent->ud; | |||
ucl_object_t *top, *sub; | |||
gint i; | |||
int i; | |||
int64_t uptime; | |||
guint64 spam = 0, ham = 0; | |||
uint64_t spam = 0, ham = 0; | |||
rspamd_mempool_stat_t mem_st; | |||
struct rspamd_stat *stat, stat_copy; | |||
struct rspamd_controller_worker_ctx *ctx; | |||
@@ -3270,7 +3270,7 @@ rspamd_controller_handle_custom(struct rspamd_http_connection_entry *conn_ent, | |||
{ | |||
struct rspamd_controller_session *session = conn_ent->ud; | |||
struct rspamd_custom_controller_command *cmd; | |||
gchar *url_str; | |||
char *url_str; | |||
struct http_parser_url u; | |||
rspamd_ftok_t lookup; | |||
@@ -3281,7 +3281,7 @@ rspamd_controller_handle_custom(struct rspamd_http_connection_entry *conn_ent, | |||
lookup.begin = msg->url->str + u.field_data[UF_PATH].off; | |||
lookup.len = u.field_data[UF_PATH].len; | |||
rspamd_normalize_path_inplace((gchar *) lookup.begin, | |||
rspamd_normalize_path_inplace((char *) lookup.begin, | |||
lookup.len, | |||
&unnorm_len); | |||
lookup.len = unnorm_len; | |||
@@ -3488,7 +3488,7 @@ rspamd_controller_handle_lua_plugin(struct rspamd_http_connection_entry *conn_en | |||
lookup.begin = msg->url->str + u.field_data[UF_PATH].off; | |||
lookup.len = u.field_data[UF_PATH].len; | |||
rspamd_normalize_path_inplace((gchar *) lookup.begin, | |||
rspamd_normalize_path_inplace((char *) lookup.begin, | |||
lookup.len, | |||
&unnorm_len); | |||
lookup.len = unnorm_len; | |||
@@ -3631,7 +3631,7 @@ rspamd_controller_accept_socket(EV_P_ ev_io *w, int revents) | |||
struct rspamd_controller_worker_ctx *ctx; | |||
struct rspamd_controller_session *session; | |||
rspamd_inet_addr_t *addr = NULL; | |||
gint nfd; | |||
int nfd; | |||
ctx = worker->ctx; | |||
@@ -3664,7 +3664,7 @@ rspamd_controller_accept_socket(EV_P_ ev_io *w, int revents) | |||
static void | |||
rspamd_controller_password_sane(struct rspamd_controller_worker_ctx *ctx, | |||
const gchar *password, const gchar *type) | |||
const char *password, const char *type) | |||
{ | |||
const struct rspamd_controller_pbkdf *pbkdf = &pbkdf_list[0]; | |||
@@ -3833,7 +3833,7 @@ luaopen_controller(lua_State *L) | |||
} | |||
struct rspamd_http_connection_entry * | |||
lua_check_controller_entry(lua_State *L, gint pos) | |||
lua_check_controller_entry(lua_State *L, int pos) | |||
{ | |||
void *ud = rspamd_lua_check_udata(L, pos, rspamd_csession_classname); | |||
luaL_argcheck(L, ud != NULL, pos, "'csession' expected"); | |||
@@ -3903,8 +3903,8 @@ static int | |||
lua_csession_send_error(lua_State *L) | |||
{ | |||
struct rspamd_http_connection_entry *c = lua_check_controller_entry(L, 1); | |||
guint err_code = lua_tonumber(L, 2); | |||
const gchar *err_str = lua_tostring(L, 3); | |||
unsigned int err_code = lua_tonumber(L, 2); | |||
const char *err_str = lua_tostring(L, 3); | |||
if (c) { | |||
rspamd_controller_send_error(c, err_code, "%s", err_str); | |||
@@ -3920,7 +3920,7 @@ static int | |||
lua_csession_send_string(lua_State *L) | |||
{ | |||
struct rspamd_http_connection_entry *c = lua_check_controller_entry(L, 1); | |||
const gchar *str = lua_tostring(L, 2); | |||
const char *str = lua_tostring(L, 2); | |||
if (c) { | |||
rspamd_controller_send_string(c, str); | |||
@@ -3947,8 +3947,8 @@ rspamd_controller_register_plugin_path(lua_State *L, | |||
struct rspamd_controller_worker_ctx *ctx, | |||
const ucl_object_t *webui_data, | |||
const ucl_object_t *handler, | |||
const gchar *path, | |||
const gchar *plugin_name) | |||
const char *path, | |||
const char *plugin_name) | |||
{ | |||
struct rspamd_controller_plugin_cbdata *cbd; | |||
const ucl_object_t *elt; | |||
@@ -4040,7 +4040,7 @@ rspamd_controller_register_plugins_paths(struct rspamd_controller_worker_ctx *ct | |||
static void | |||
rspamd_controller_health_rep(struct rspamd_worker *worker, | |||
struct rspamd_srv_reply *rep, gint rep_fd, | |||
struct rspamd_srv_reply *rep, int rep_fd, | |||
gpointer ud) | |||
{ | |||
struct rspamd_controller_worker_ctx *ctx = (struct rspamd_controller_worker_ctx *) ud; | |||
@@ -4075,7 +4075,7 @@ start_controller_worker(struct rspamd_worker *worker) | |||
struct module_ctx *mctx; | |||
GHashTableIter iter; | |||
gpointer key, value; | |||
guint i; | |||
unsigned int i; | |||
gpointer m; | |||
g_assert(rspamd_worker_check_context(worker->ctx, rspamd_controller_ctx_magic)); |
@@ -51,7 +51,7 @@ | |||
/* Update stats on keys each 1 hour */ | |||
#define KEY_STAT_INTERVAL 3600.0 | |||
static const gchar *local_db_name = "local"; | |||
static const char *local_db_name = "local"; | |||
/* Init functions */ | |||
gpointer init_fuzzy(struct rspamd_config *cfg); | |||
@@ -67,33 +67,33 @@ worker_t fuzzy_worker = { | |||
}; | |||
struct fuzzy_global_stat { | |||
guint64 fuzzy_hashes; | |||
uint64_t fuzzy_hashes; | |||
/**< number of fuzzy hashes stored */ | |||
guint64 fuzzy_hashes_expired; | |||
uint64_t fuzzy_hashes_expired; | |||
/**< number of fuzzy hashes expired */ | |||
guint64 fuzzy_hashes_checked[RSPAMD_FUZZY_EPOCH_MAX]; | |||
uint64_t fuzzy_hashes_checked[RSPAMD_FUZZY_EPOCH_MAX]; | |||
/**< amount of check requests for each epoch */ | |||
guint64 fuzzy_shingles_checked[RSPAMD_FUZZY_EPOCH_MAX]; | |||
uint64_t fuzzy_shingles_checked[RSPAMD_FUZZY_EPOCH_MAX]; | |||
/**< amount of shingle check requests for each epoch */ | |||
guint64 fuzzy_hashes_found[RSPAMD_FUZZY_EPOCH_MAX]; | |||
uint64_t fuzzy_hashes_found[RSPAMD_FUZZY_EPOCH_MAX]; | |||
/**< amount of invalid requests */ | |||
guint64 invalid_requests; | |||
uint64_t invalid_requests; | |||
/**< amount of delayed hashes found */ | |||
guint64 delayed_hashes; | |||
uint64_t delayed_hashes; | |||
}; | |||
struct fuzzy_key_stat { | |||
guint64 checked; | |||
guint64 matched; | |||
guint64 added; | |||
guint64 deleted; | |||
guint64 errors; | |||
uint64_t checked; | |||
uint64_t matched; | |||
uint64_t added; | |||
uint64_t deleted; | |||
uint64_t errors; | |||
/* Store averages for checked/matched per minute */ | |||
struct rspamd_counter_data checked_ctr; | |||
struct rspamd_counter_data matched_ctr; | |||
gdouble last_checked_time; | |||
guint64 last_checked_count; | |||
guint64 last_matched_count; | |||
double last_checked_time; | |||
uint64_t last_checked_count; | |||
uint64_t last_matched_count; | |||
struct rspamd_cryptobox_keypair *keypair; | |||
rspamd_lru_hash_t *last_ips; | |||
@@ -102,11 +102,11 @@ struct fuzzy_key_stat { | |||
struct rspamd_leaky_bucket_elt { | |||
rspamd_inet_addr_t *addr; | |||
gdouble last; | |||
gdouble cur; | |||
double last; | |||
double cur; | |||
}; | |||
static const guint64 rspamd_fuzzy_storage_magic = 0x291a3253eb1b3ea5ULL; | |||
static const uint64_t rspamd_fuzzy_storage_magic = 0x291a3253eb1b3ea5ULL; | |||
static int64_t | |||
fuzzy_kp_hash(const unsigned char *p) | |||
@@ -119,7 +119,7 @@ fuzzy_kp_hash(const unsigned char *p) | |||
static bool | |||
fuzzy_kp_equal(gconstpointer a, gconstpointer b) | |||
{ | |||
const guchar *pa = a, *pb = b; | |||
const unsigned char *pa = a, *pb = b; | |||
return (memcmp(pa, pb, RSPAMD_FUZZY_KEYLEN) == 0); | |||
} | |||
@@ -141,7 +141,7 @@ KHASH_INIT(rspamd_fuzzy_keys_hash, | |||
fuzzy_kp_hash, fuzzy_kp_equal); | |||
struct rspamd_fuzzy_storage_ctx { | |||
guint64 magic; | |||
uint64_t magic; | |||
/* Events base */ | |||
struct ev_loop *event_loop; | |||
/* DNS resolver */ | |||
@@ -150,9 +150,9 @@ struct rspamd_fuzzy_storage_ctx { | |||
struct rspamd_config *cfg; | |||
/* END OF COMMON PART */ | |||
struct fuzzy_global_stat stat; | |||
gdouble expire; | |||
gdouble sync_timeout; | |||
gdouble delay; | |||
double expire; | |||
double sync_timeout; | |||
double delay; | |||
struct rspamd_radix_map_helper *update_ips; | |||
struct rspamd_hash_map_helper *update_keys; | |||
struct rspamd_radix_map_helper *blocked_ips; | |||
@@ -166,7 +166,7 @@ struct rspamd_fuzzy_storage_ctx { | |||
const ucl_object_t *ratelimit_whitelist_map; | |||
const ucl_object_t *dynamic_keys_map; | |||
guint keypair_cache_size; | |||
unsigned int keypair_cache_size; | |||
ev_timer stat_ev; | |||
ev_io peer_ev; | |||
@@ -186,25 +186,25 @@ struct rspamd_fuzzy_storage_ctx { | |||
rspamd_lru_hash_t *ratelimit_buckets; | |||
struct rspamd_fuzzy_backend *backend; | |||
GArray *updates_pending; | |||
guint updates_failed; | |||
guint updates_maxfail; | |||
unsigned int updates_failed; | |||
unsigned int updates_maxfail; | |||
/* Used to send data between workers */ | |||
gint peer_fd; | |||
int peer_fd; | |||
/* Ratelimits */ | |||
guint leaky_bucket_ttl; | |||
guint leaky_bucket_mask; | |||
guint max_buckets; | |||
unsigned int leaky_bucket_ttl; | |||
unsigned int leaky_bucket_mask; | |||
unsigned int max_buckets; | |||
gboolean ratelimit_log_only; | |||
gdouble leaky_bucket_burst; | |||
gdouble leaky_bucket_rate; | |||
double leaky_bucket_burst; | |||
double leaky_bucket_rate; | |||
struct rspamd_worker *worker; | |||
const ucl_object_t *skip_map; | |||
struct rspamd_hash_map_helper *skip_hashes; | |||
gint lua_pre_handler_cbref; | |||
gint lua_post_handler_cbref; | |||
gint lua_blacklist_cbref; | |||
int lua_pre_handler_cbref; | |||
int lua_post_handler_cbref; | |||
int lua_blacklist_cbref; | |||
khash_t(fuzzy_key_ids_set) * default_forbidden_ids; | |||
/* Ids that should not override other ids */ | |||
khash_t(fuzzy_key_ids_set) * weak_ids; | |||
@@ -228,13 +228,13 @@ struct fuzzy_session { | |||
enum rspamd_fuzzy_epoch epoch; | |||
enum fuzzy_cmd_type cmd_type; | |||
gint fd; | |||
int fd; | |||
ev_tstamp timestamp; | |||
struct ev_io io; | |||
ref_entry_t ref; | |||
struct fuzzy_key *key; | |||
struct rspamd_fuzzy_cmd_extension *extensions; | |||
guchar nm[rspamd_cryptobox_MAX_NMBYTES]; | |||
unsigned char nm[rspamd_cryptobox_MAX_NMBYTES]; | |||
}; | |||
struct fuzzy_peer_request { | |||
@@ -245,19 +245,19 @@ struct fuzzy_peer_request { | |||
struct rspamd_updates_cbdata { | |||
GArray *updates_pending; | |||
struct rspamd_fuzzy_storage_ctx *ctx; | |||
gchar *source; | |||
char *source; | |||
gboolean final; | |||
}; | |||
static void rspamd_fuzzy_write_reply(struct fuzzy_session *session); | |||
static gboolean rspamd_fuzzy_process_updates_queue(struct rspamd_fuzzy_storage_ctx *ctx, | |||
const gchar *source, gboolean final); | |||
const char *source, gboolean final); | |||
static gboolean rspamd_fuzzy_check_client(struct rspamd_fuzzy_storage_ctx *ctx, | |||
rspamd_inet_addr_t *addr); | |||
static void rspamd_fuzzy_maybe_call_blacklisted(struct rspamd_fuzzy_storage_ctx *ctx, | |||
rspamd_inet_addr_t *addr, | |||
const gchar *reason); | |||
const char *reason); | |||
static struct fuzzy_key *fuzzy_add_keypair_from_ucl(const ucl_object_t *obj, | |||
khash_t(rspamd_fuzzy_keys_hash) * target); | |||
@@ -267,9 +267,9 @@ struct fuzzy_keymap_ucl_buf { | |||
}; | |||
/* Callbacks for reading json dynamic rules */ | |||
static gchar * | |||
ucl_keymap_read_cb(gchar *chunk, | |||
gint len, | |||
static char * | |||
ucl_keymap_read_cb(char *chunk, | |||
int len, | |||
struct map_cb_data *data, | |||
gboolean final) | |||
{ | |||
@@ -540,11 +540,11 @@ rspamd_fuzzy_check_ratelimit(struct fuzzy_session *session) | |||
static void | |||
rspamd_fuzzy_maybe_call_blacklisted(struct rspamd_fuzzy_storage_ctx *ctx, | |||
rspamd_inet_addr_t *addr, | |||
const gchar *reason) | |||
const char *reason) | |||
{ | |||
if (ctx->lua_blacklist_cbref != -1) { | |||
lua_State *L = ctx->cfg->lua_state; | |||
gint err_idx, ret; | |||
int err_idx, ret; | |||
lua_pushcfunction(L, &rspamd_lua_traceback); | |||
err_idx = lua_gettop(L); | |||
@@ -601,13 +601,13 @@ rspamd_fuzzy_check_write(struct fuzzy_session *session) | |||
} | |||
if (session->ctx->update_keys != NULL && session->key->stat && session->key->key) { | |||
static gchar base32_buf[rspamd_cryptobox_HASHBYTES * 2 + 1]; | |||
guint raw_len; | |||
const guchar *pk_raw = rspamd_keypair_component(session->key->key, | |||
RSPAMD_KEYPAIR_COMPONENT_ID, &raw_len); | |||
gint encoded_len = rspamd_encode_base32_buf(pk_raw, raw_len, | |||
base32_buf, sizeof(base32_buf), | |||
RSPAMD_BASE32_DEFAULT); | |||
static char base32_buf[rspamd_cryptobox_HASHBYTES * 2 + 1]; | |||
unsigned int raw_len; | |||
const unsigned char *pk_raw = rspamd_keypair_component(session->key->key, | |||
RSPAMD_KEYPAIR_COMPONENT_ID, &raw_len); | |||
int encoded_len = rspamd_encode_base32_buf(pk_raw, raw_len, | |||
base32_buf, sizeof(base32_buf), | |||
RSPAMD_BASE32_DEFAULT); | |||
if (rspamd_match_hash_map(session->ctx->update_keys, base32_buf, encoded_len)) { | |||
return TRUE; | |||
@@ -674,7 +674,7 @@ fuzzy_hash_table_dtor(khash_t(rspamd_fuzzy_keys_hash) * hash) | |||
} | |||
static void | |||
fuzzy_count_callback(guint64 count, void *ud) | |||
fuzzy_count_callback(uint64_t count, void *ud) | |||
{ | |||
struct rspamd_fuzzy_storage_ctx *ctx = ud; | |||
@@ -691,7 +691,7 @@ fuzzy_rl_bucket_free(gpointer p) | |||
} | |||
static void | |||
fuzzy_stat_count_callback(guint64 count, void *ud) | |||
fuzzy_stat_count_callback(uint64_t count, void *ud) | |||
{ | |||
struct rspamd_fuzzy_storage_ctx *ctx = ud; | |||
@@ -709,21 +709,21 @@ rspamd_fuzzy_stat_callback(EV_P_ ev_timer *w, int revents) | |||
static void | |||
fuzzy_update_version_callback(guint64 ver, void *ud) | |||
fuzzy_update_version_callback(uint64_t ver, void *ud) | |||
{ | |||
} | |||
static void | |||
rspamd_fuzzy_updates_cb(gboolean success, | |||
guint nadded, | |||
guint ndeleted, | |||
guint nextended, | |||
guint nignored, | |||
unsigned int nadded, | |||
unsigned int ndeleted, | |||
unsigned int nextended, | |||
unsigned int nignored, | |||
void *ud) | |||
{ | |||
struct rspamd_updates_cbdata *cbdata = ud; | |||
struct rspamd_fuzzy_storage_ctx *ctx; | |||
const gchar *source; | |||
const char *source; | |||
ctx = cbdata->ctx; | |||
source = cbdata->source; | |||
@@ -798,7 +798,7 @@ rspamd_fuzzy_updates_cb(gboolean success, | |||
static gboolean | |||
rspamd_fuzzy_process_updates_queue(struct rspamd_fuzzy_storage_ctx *ctx, | |||
const gchar *source, gboolean final) | |||
const char *source, gboolean final) | |||
{ | |||
struct rspamd_updates_cbdata *cbdata; | |||
@@ -886,7 +886,7 @@ rspamd_fuzzy_write_reply(struct fuzzy_session *session) | |||
static void | |||
rspamd_fuzzy_update_key_stat(gboolean matched, | |||
struct fuzzy_key_stat *key_stat, | |||
guint cmd, | |||
unsigned int cmd, | |||
struct rspamd_fuzzy_reply *res, | |||
ev_tstamp timestamp) | |||
{ | |||
@@ -907,8 +907,8 @@ rspamd_fuzzy_update_key_stat(gboolean matched, | |||
key_stat->last_matched_count = key_stat->matched; | |||
} | |||
else if (G_UNLIKELY(timestamp > key_stat->last_checked_time + KEY_STAT_INTERVAL)) { | |||
guint64 nchecked = key_stat->checked - key_stat->last_checked_count; | |||
guint64 nmatched = key_stat->matched - key_stat->last_matched_count; | |||
uint64_t nchecked = key_stat->checked - key_stat->last_checked_count; | |||
uint64_t nmatched = key_stat->matched - key_stat->last_matched_count; | |||
rspamd_set_counter_ema(&key_stat->checked_ctr, nchecked, 0.5f); | |||
rspamd_set_counter_ema(&key_stat->matched_ctr, nmatched, 0.5f); | |||
@@ -934,7 +934,7 @@ rspamd_fuzzy_update_stats(struct rspamd_fuzzy_storage_ctx *ctx, | |||
gboolean is_delayed, | |||
struct fuzzy_key *key, | |||
struct fuzzy_key_stat *ip_stat, | |||
guint cmd, | |||
unsigned int cmd, | |||
struct rspamd_fuzzy_reply *res, | |||
ev_tstamp timestamp) | |||
{ | |||
@@ -1003,7 +1003,7 @@ static void | |||
rspamd_fuzzy_make_reply(struct rspamd_fuzzy_cmd *cmd, | |||
struct rspamd_fuzzy_reply *result, | |||
struct fuzzy_session *session, | |||
gint flags) | |||
int flags) | |||
{ | |||
gsize len; | |||
@@ -1084,7 +1084,7 @@ rspamd_fuzzy_make_reply(struct rspamd_fuzzy_cmd *cmd, | |||
session->timestamp); | |||
} | |||
rspamd_cryptobox_encrypt_nm_inplace((guchar *) &session->reply.rep, | |||
rspamd_cryptobox_encrypt_nm_inplace((unsigned char *) &session->reply.rep, | |||
len, | |||
session->reply.hdr.nonce, | |||
session->nm, | |||
@@ -1118,7 +1118,7 @@ rspamd_fuzzy_make_reply(struct rspamd_fuzzy_cmd *cmd, | |||
} | |||
static gboolean | |||
fuzzy_peer_try_send(gint fd, struct fuzzy_peer_request *up_req) | |||
fuzzy_peer_try_send(int fd, struct fuzzy_peer_request *up_req) | |||
{ | |||
gssize r; | |||
@@ -1184,7 +1184,7 @@ rspamd_fuzzy_check_callback(struct rspamd_fuzzy_reply *result, void *ud) | |||
struct rspamd_fuzzy_cmd *cmd = NULL; | |||
const struct rspamd_shingle *shingle = NULL; | |||
struct rspamd_shingle sgl_cpy; | |||
gint send_flags = 0; | |||
int send_flags = 0; | |||
switch (session->cmd_type) { | |||
case CMD_ENCRYPTED_NORMAL: | |||
@@ -1211,7 +1211,7 @@ rspamd_fuzzy_check_callback(struct rspamd_fuzzy_reply *result, void *ud) | |||
if (session->ctx->lua_post_handler_cbref != -1) { | |||
/* Start lua post handler */ | |||
lua_State *L = session->ctx->cfg->lua_state; | |||
gint err_idx, ret; | |||
int err_idx, ret; | |||
lua_pushcfunction(L, &rspamd_lua_traceback); | |||
err_idx = lua_gettop(L); | |||
@@ -1287,9 +1287,9 @@ rspamd_fuzzy_check_callback(struct rspamd_fuzzy_reply *result, void *ud) | |||
if (!isnan(session->ctx->delay) && | |||
rspamd_match_radix_map_addr(session->ctx->delay_whitelist, | |||
session->addr) == NULL) { | |||
gdouble hash_age = rspamd_get_calendar_ticks() - result->ts; | |||
gdouble jittered_age = rspamd_time_jitter(session->ctx->delay, | |||
session->ctx->delay / 2.0); | |||
double hash_age = rspamd_get_calendar_ticks() - result->ts; | |||
double jittered_age = rspamd_time_jitter(session->ctx->delay, | |||
session->ctx->delay / 2.0); | |||
if (hash_age < jittered_age) { | |||
send_flags |= RSPAMD_FUZZY_REPLY_DELAY; | |||
@@ -1360,11 +1360,11 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session) | |||
struct fuzzy_peer_cmd up_cmd; | |||
struct fuzzy_peer_request *up_req; | |||
struct fuzzy_key_stat *ip_stat = NULL; | |||
gchar hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; | |||
char hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; | |||
rspamd_inet_addr_t *naddr; | |||
gpointer ptr; | |||
gsize up_len = 0; | |||
gint send_flags = 0; | |||
int send_flags = 0; | |||
cmd = &session->cmd.basic; | |||
@@ -1401,7 +1401,7 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session) | |||
if (session->ctx->lua_pre_handler_cbref != -1) { | |||
/* Start lua pre handler */ | |||
lua_State *L = session->ctx->cfg->lua_state; | |||
gint err_idx, ret; | |||
int err_idx, ret; | |||
lua_pushcfunction(L, &rspamd_lua_traceback); | |||
err_idx = lua_gettop(L); | |||
@@ -1515,8 +1515,8 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session) | |||
/* Store approximation (if needed) */ | |||
result.v1.prob = session->ctx->stat.fuzzy_hashes; | |||
/* Store high qword in value and low qword in flag */ | |||
result.v1.value = (gint32) ((guint64) session->ctx->stat.fuzzy_hashes >> 32); | |||
result.v1.flag = (guint32) (session->ctx->stat.fuzzy_hashes & G_MAXUINT32); | |||
result.v1.value = (int32_t) ((uint64_t) session->ctx->stat.fuzzy_hashes >> 32); | |||
result.v1.flag = (uint32_t) (session->ctx->stat.fuzzy_hashes & G_MAXUINT32); | |||
rspamd_fuzzy_make_reply(cmd, &result, session, send_flags); | |||
} | |||
else if (cmd->cmd == FUZZY_PING) { | |||
@@ -1585,7 +1585,7 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session) | |||
static enum rspamd_fuzzy_epoch | |||
rspamd_fuzzy_command_valid(struct rspamd_fuzzy_cmd *cmd, gint r) | |||
rspamd_fuzzy_command_valid(struct rspamd_fuzzy_cmd *cmd, int r) | |||
{ | |||
enum rspamd_fuzzy_epoch ret = RSPAMD_FUZZY_EPOCH_MAX; | |||
@@ -1622,7 +1622,7 @@ rspamd_fuzzy_command_valid(struct rspamd_fuzzy_cmd *cmd, gint r) | |||
} | |||
static gboolean | |||
rspamd_fuzzy_decrypt_command(struct fuzzy_session *s, guchar *buf, gsize buflen) | |||
rspamd_fuzzy_decrypt_command(struct fuzzy_session *s, unsigned char *buf, gsize buflen) | |||
{ | |||
struct rspamd_fuzzy_encrypted_req_hdr hdr; | |||
struct rspamd_cryptobox_pubkey *rk; | |||
@@ -1702,20 +1702,20 @@ rspamd_fuzzy_decrypt_command(struct fuzzy_session *s, guchar *buf, gsize buflen) | |||
static gboolean | |||
rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize buflen) | |||
rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, unsigned char *buf, gsize buflen) | |||
{ | |||
struct rspamd_fuzzy_cmd_extension *ext, *prev_ext; | |||
guchar *storage, *p = buf, *end = buf + buflen; | |||
unsigned char *storage, *p = buf, *end = buf + buflen; | |||
gsize st_len = 0, n_ext = 0; | |||
/* Read number of extensions to allocate array */ | |||
while (p < end) { | |||
guchar cmd = *p++; | |||
unsigned char cmd = *p++; | |||
if (p < end) { | |||
if (cmd == RSPAMD_FUZZY_EXT_SOURCE_DOMAIN) { | |||
/* Next byte is buf length */ | |||
guchar dom_len = *p++; | |||
unsigned char dom_len = *p++; | |||
if (dom_len <= (end - p)) { | |||
st_len += dom_len; | |||
@@ -1772,19 +1772,19 @@ rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize bu | |||
storage = g_malloc(n_ext * sizeof(struct rspamd_fuzzy_cmd_extension) + | |||
st_len); | |||
guchar *data_buf = storage + | |||
n_ext * sizeof(struct rspamd_fuzzy_cmd_extension); | |||
unsigned char *data_buf = storage + | |||
n_ext * sizeof(struct rspamd_fuzzy_cmd_extension); | |||
ext = (struct rspamd_fuzzy_cmd_extension *) storage; | |||
/* All validation has been done, so we can just go further */ | |||
while (p < end) { | |||
prev_ext = ext; | |||
guchar cmd = *p++; | |||
unsigned char cmd = *p++; | |||
if (cmd == RSPAMD_FUZZY_EXT_SOURCE_DOMAIN) { | |||
/* Next byte is buf length */ | |||
guchar dom_len = *p++; | |||
guchar *dest = data_buf; | |||
unsigned char dom_len = *p++; | |||
unsigned char *dest = data_buf; | |||
ext->ext = RSPAMD_FUZZY_EXT_SOURCE_DOMAIN; | |||
ext->next = ext + 1; | |||
@@ -1796,7 +1796,7 @@ rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize bu | |||
ext = ext->next; | |||
} | |||
else if (cmd == RSPAMD_FUZZY_EXT_SOURCE_IP4) { | |||
guchar *dest = data_buf; | |||
unsigned char *dest = data_buf; | |||
ext->ext = RSPAMD_FUZZY_EXT_SOURCE_IP4; | |||
ext->next = ext + 1; | |||
@@ -1808,7 +1808,7 @@ rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize bu | |||
ext = ext->next; | |||
} | |||
else if (cmd == RSPAMD_FUZZY_EXT_SOURCE_IP6) { | |||
guchar *dest = data_buf; | |||
unsigned char *dest = data_buf; | |||
ext->ext = RSPAMD_FUZZY_EXT_SOURCE_IP6; | |||
ext->next = ext + 1; | |||
@@ -1836,7 +1836,7 @@ rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize bu | |||
} | |||
static gboolean | |||
rspamd_fuzzy_cmd_from_wire(guchar *buf, guint buflen, struct fuzzy_session *s) | |||
rspamd_fuzzy_cmd_from_wire(unsigned char *buf, unsigned int buflen, struct fuzzy_session *s) | |||
{ | |||
enum rspamd_fuzzy_epoch epoch; | |||
gboolean encrypted = FALSE; | |||
@@ -1980,9 +1980,9 @@ accept_fuzzy_socket(EV_P_ ev_io *w, int revents) | |||
struct rspamd_fuzzy_storage_ctx *ctx; | |||
struct fuzzy_session *session; | |||
gssize r, msg_len; | |||
guint64 *nerrors; | |||
uint64_t *nerrors; | |||
struct iovec iovs[MSGVEC_LEN]; | |||
guint8 bufs[MSGVEC_LEN][FUZZY_INPUT_BUFLEN]; | |||
uint8_t bufs[MSGVEC_LEN][FUZZY_INPUT_BUFLEN]; | |||
union sa_union peer_sa[MSGVEC_LEN]; | |||
socklen_t salen = sizeof(peer_sa[0]); | |||
#ifdef HAVE_RECVMMSG | |||
@@ -2120,8 +2120,8 @@ rspamd_fuzzy_storage_periodic_callback(void *ud) | |||
static gboolean | |||
rspamd_fuzzy_storage_sync(struct rspamd_main *rspamd_main, | |||
struct rspamd_worker *worker, gint fd, | |||
gint attached_fd, | |||
struct rspamd_worker *worker, int fd, | |||
int attached_fd, | |||
struct rspamd_control_command *cmd, | |||
gpointer ud) | |||
{ | |||
@@ -2147,8 +2147,8 @@ rspamd_fuzzy_storage_sync(struct rspamd_main *rspamd_main, | |||
static gboolean | |||
rspamd_fuzzy_control_blocked(struct rspamd_main *rspamd_main, | |||
struct rspamd_worker *worker, gint fd, | |||
gint attached_fd, | |||
struct rspamd_worker *worker, int fd, | |||
int attached_fd, | |||
struct rspamd_control_command *cmd, | |||
gpointer ud) | |||
{ | |||
@@ -2223,8 +2223,8 @@ rspamd_fuzzy_control_blocked(struct rspamd_main *rspamd_main, | |||
static gboolean | |||
rspamd_fuzzy_storage_reload(struct rspamd_main *rspamd_main, | |||
struct rspamd_worker *worker, gint fd, | |||
gint attached_fd, | |||
struct rspamd_worker *worker, int fd, | |||
int attached_fd, | |||
struct rspamd_control_command *cmd, | |||
gpointer ud) | |||
{ | |||
@@ -2295,7 +2295,7 @@ static void | |||
rspamd_fuzzy_key_stat_iter(const unsigned char *pk_iter, struct fuzzy_key *fuzzy_key, ucl_object_t *keys_obj, gboolean ip_stat) | |||
{ | |||
struct fuzzy_key_stat *key_stat = fuzzy_key->stat; | |||
gchar keyname[17]; | |||
char keyname[17]; | |||
if (key_stat) { | |||
rspamd_snprintf(keyname, sizeof(keyname), "%8bs", pk_iter); | |||
@@ -2382,7 +2382,7 @@ rspamd_fuzzy_stat_to_ucl(struct rspamd_fuzzy_storage_ctx *ctx, gboolean ip_stat) | |||
while ((i = rspamd_lru_hash_foreach(ctx->errors_ips, i, &k, &v)) != -1) { | |||
ucl_object_insert_key(ip_elt, | |||
ucl_object_fromint(*(guint64 *) v), | |||
ucl_object_fromint(*(uint64_t *) v), | |||
rspamd_inet_address_to_string(k), 0, true); | |||
} | |||
@@ -2447,7 +2447,7 @@ rspamd_fuzzy_maybe_load_ratelimits(struct rspamd_fuzzy_storage_ctx *ctx) | |||
while ((cur = ucl_object_iterate(obj, &it, true)) != NULL) { | |||
const ucl_object_t *ip, *value, *last; | |||
const gchar *ip_str; | |||
const char *ip_str; | |||
double limit_val, last_val; | |||
ip = ucl_object_find_key(cur, "ip"); | |||
@@ -2642,8 +2642,8 @@ lua_fuzzy_add_blacklist_handler(lua_State *L) | |||
static gboolean | |||
rspamd_fuzzy_storage_stat(struct rspamd_main *rspamd_main, | |||
struct rspamd_worker *worker, gint fd, | |||
gint attached_fd, | |||
struct rspamd_worker *worker, int fd, | |||
int attached_fd, | |||
struct rspamd_control_command *cmd, | |||
gpointer ud) | |||
{ | |||
@@ -2651,13 +2651,13 @@ rspamd_fuzzy_storage_stat(struct rspamd_main *rspamd_main, | |||
struct rspamd_control_reply rep; | |||
ucl_object_t *obj; | |||
struct ucl_emitter_functions *emit_subr; | |||
guchar fdspace[CMSG_SPACE(sizeof(int))]; | |||
unsigned char fdspace[CMSG_SPACE(sizeof(int))]; | |||
struct iovec iov; | |||
struct msghdr msg; | |||
struct cmsghdr *cmsg; | |||
gint outfd = -1; | |||
gchar tmppath[PATH_MAX]; | |||
int outfd = -1; | |||
char tmppath[PATH_MAX]; | |||
memset(&rep, 0, sizeof(rep)); | |||
rep.type = RSPAMD_CONTROL_FUZZY_STAT; | |||
@@ -2732,12 +2732,12 @@ fuzzy_parse_ids(rspamd_mempool_t *pool, | |||
struct rspamd_rcl_struct_parser *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
khash_t(fuzzy_key_ids_set) * target; | |||
target = *(khash_t(fuzzy_key_ids_set) **) ((gchar *) pd->user_struct + pd->offset); | |||
target = *(khash_t(fuzzy_key_ids_set) **) ((char *) pd->user_struct + pd->offset); | |||
if (ucl_object_type(obj) == UCL_ARRAY) { | |||
const ucl_object_t *cur; | |||
ucl_object_iter_t it = NULL; | |||
guint64 id; | |||
uint64_t id; | |||
while ((cur = ucl_object_iterate(obj, &it, true)) != NULL) { | |||
if (ucl_object_toint_safe(cur, &id)) { | |||
@@ -2790,8 +2790,8 @@ fuzzy_add_keypair_from_ucl(const ucl_object_t *obj, khash_t(rspamd_fuzzy_keys_ha | |||
key->flags_stat = kh_init(fuzzy_key_flag_stat); | |||
/* Preallocate some space for flags */ | |||
kh_resize(fuzzy_key_flag_stat, key->flags_stat, 8); | |||
const guchar *pk = rspamd_keypair_component(kp, RSPAMD_KEYPAIR_COMPONENT_PK, | |||
NULL); | |||
const unsigned char *pk = rspamd_keypair_component(kp, RSPAMD_KEYPAIR_COMPONENT_PK, | |||
NULL); | |||
keystat->keypair = rspamd_keypair_ref(kp); | |||
/* We map entries by pubkey in binary form for faster lookup */ | |||
khiter_t k; | |||
@@ -3174,7 +3174,7 @@ rspamd_fuzzy_peer_io(EV_P_ ev_io *w, int revents) | |||
static void | |||
fuzzy_peer_rep(struct rspamd_worker *worker, | |||
struct rspamd_srv_reply *rep, gint rep_fd, | |||
struct rspamd_srv_reply *rep, int rep_fd, | |||
gpointer ud) | |||
{ | |||
struct rspamd_fuzzy_storage_ctx *ctx = ud; | |||
@@ -3434,14 +3434,14 @@ start_fuzzy(struct rspamd_worker *worker) | |||
memset(srv_cmd.cmd.spair.pair_id, 0, sizeof(srv_cmd.cmd.spair.pair_id)); | |||
/* 6 bytes of id (including \0) and bind_conf id */ | |||
G_STATIC_ASSERT(sizeof(srv_cmd.cmd.spair.pair_id) >= | |||
sizeof("fuzzy") + sizeof(guint64)); | |||
sizeof("fuzzy") + sizeof(uint64_t)); | |||
memcpy(srv_cmd.cmd.spair.pair_id, "fuzzy", sizeof("fuzzy")); | |||
/* Distinguish workers from each others... */ | |||
if (worker->cf->bind_conf && worker->cf->bind_conf->bind_line) { | |||
guint64 bind_hash = rspamd_cryptobox_fast_hash(worker->cf->bind_conf->bind_line, | |||
strlen(worker->cf->bind_conf->bind_line), 0xdeadbabe); | |||
uint64_t bind_hash = rspamd_cryptobox_fast_hash(worker->cf->bind_conf->bind_line, | |||
strlen(worker->cf->bind_conf->bind_line), 0xdeadbabe); | |||
/* 8 more bytes */ | |||
memcpy(srv_cmd.cmd.spair.pair_id + sizeof("fuzzy"), &bind_hash, |
@@ -37,15 +37,15 @@ worker_t hs_helper_worker = { | |||
RSPAMD_WORKER_VER /* Version info */ | |||
}; | |||
static const gdouble default_max_time = 1.0; | |||
static const gdouble default_recompile_time = 60.0; | |||
static const guint64 rspamd_hs_helper_magic = 0x22d310157a2288a0ULL; | |||
static const double default_max_time = 1.0; | |||
static const double default_recompile_time = 60.0; | |||
static const uint64_t rspamd_hs_helper_magic = 0x22d310157a2288a0ULL; | |||
/* | |||
* Worker's context | |||
*/ | |||
struct hs_helper_ctx { | |||
guint64 magic; | |||
uint64_t magic; | |||
/* Events base */ | |||
struct ev_loop *event_loop; | |||
/* DNS resolver */ | |||
@@ -53,10 +53,10 @@ struct hs_helper_ctx { | |||
/* Config */ | |||
struct rspamd_config *cfg; | |||
/* END OF COMMON PART */ | |||
gchar *hs_dir; | |||
char *hs_dir; | |||
gboolean loaded; | |||
gdouble max_time; | |||
gdouble recompile_time; | |||
double max_time; | |||
double recompile_time; | |||
ev_timer recompile_timer; | |||
}; | |||
@@ -119,9 +119,9 @@ rspamd_hs_helper_cleanup_dir(struct hs_helper_ctx *ctx, gboolean forced) | |||
{ | |||
struct stat st; | |||
glob_t globbuf; | |||
guint len, i; | |||
gint rc; | |||
gchar *pattern; | |||
unsigned int len, i; | |||
int rc; | |||
char *pattern; | |||
gboolean ret = TRUE; | |||
pid_t our_pid = getpid(); | |||
@@ -186,9 +186,9 @@ rspamd_hs_helper_cleanup_dir(struct hs_helper_ctx *ctx, gboolean forced) | |||
if ((rc = glob(pattern, 0, NULL, &globbuf)) == 0) { | |||
for (i = 0; i < globbuf.gl_pathc; i++) { | |||
/* Check if we have a pid in the filename */ | |||
const gchar *end_num = globbuf.gl_pathv[i] + | |||
strlen(globbuf.gl_pathv[i]) - (sizeof(".hs.new") - 1); | |||
const gchar *p = end_num - 1; | |||
const char *end_num = globbuf.gl_pathv[i] + | |||
strlen(globbuf.gl_pathv[i]) - (sizeof(".hs.new") - 1); | |||
const char *p = end_num - 1; | |||
pid_t foreign_pid = -1; | |||
while (p > globbuf.gl_pathv[i]) { | |||
@@ -270,7 +270,7 @@ rspamd_rs_delayed_cb(EV_P_ ev_timer *w, int revents) | |||
} | |||
static void | |||
rspamd_rs_compile_cb(guint ncompiled, GError *err, void *cbd) | |||
rspamd_rs_compile_cb(unsigned int ncompiled, GError *err, void *cbd) | |||
{ | |||
struct rspamd_worker *worker = (struct rspamd_worker *) cbd; | |||
ev_timer *tm; | |||
@@ -343,8 +343,8 @@ rspamd_rs_compile(struct hs_helper_ctx *ctx, struct rspamd_worker *worker, | |||
static gboolean | |||
rspamd_hs_helper_reload(struct rspamd_main *rspamd_main, | |||
struct rspamd_worker *worker, gint fd, | |||
gint attached_fd, | |||
struct rspamd_worker *worker, int fd, | |||
int attached_fd, | |||
struct rspamd_control_command *cmd, | |||
gpointer ud) | |||
{ |
@@ -340,7 +340,7 @@ static const base64_impl_t *base64_ref = &base64_list[0]; | |||
const char * | |||
base64_load(void) | |||
{ | |||
guint i; | |||
unsigned int i; | |||
const base64_impl_t *opt_impl = base64_ref; | |||
/* Enable reference */ | |||
@@ -360,12 +360,12 @@ base64_load(void) | |||
} | |||
gboolean | |||
rspamd_cryptobox_base64_decode(const gchar *in, gsize inlen, | |||
guchar *out, gsize *outlen) | |||
rspamd_cryptobox_base64_decode(const char *in, gsize inlen, | |||
unsigned char *out, gsize *outlen) | |||
{ | |||
const base64_impl_t *opt_impl = base64_ref; | |||
for (gint i = G_N_ELEMENTS(base64_list) - 1; i > 0; i--) { | |||
for (int i = G_N_ELEMENTS(base64_list) - 1; i > 0; i--) { | |||
if (base64_list[i].enabled && base64_list[i].min_len <= inlen) { | |||
opt_impl = &base64_list[i]; | |||
break; | |||
@@ -379,8 +379,8 @@ double | |||
base64_test(bool generic, size_t niters, size_t len, size_t str_len) | |||
{ | |||
size_t cycles; | |||
guchar *in, *out, *tmp; | |||
gdouble t1, t2, total = 0; | |||
unsigned char *in, *out, *tmp; | |||
double t1, t2, total = 0; | |||
gsize outlen; | |||
g_assert(len > 0); | |||
@@ -421,9 +421,9 @@ base64_test(bool generic, size_t niters, size_t len, size_t str_len) | |||
gboolean | |||
rspamd_cryptobox_base64_is_valid(const gchar *in, gsize inlen) | |||
rspamd_cryptobox_base64_is_valid(const char *in, gsize inlen) | |||
{ | |||
const guchar *p, *end; | |||
const unsigned char *p, *end; | |||
if (inlen == 0) { | |||
return FALSE; |
@@ -1,23 +1,17 @@ | |||
/*- | |||
* Copyright 2016 Vsevolod Stakhov | |||
* Copyright (c) 2014 cforler | |||
/* | |||
* Copyright 2024 Vsevolod Stakhov | |||
* | |||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | |||
* this software and associated documentation files (the "Software"), to deal in | |||
* the Software without restriction, including without limitation the rights to | |||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |||
* the Software, and to permit persons to whom the Software is furnished to do so, | |||
* subject to the following conditions: | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* The above copyright notice and this permission notice shall be included in all | |||
* copies or substantial portions of the Software. | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
#include "config.h" | |||
@@ -424,16 +418,16 @@ int simple_catena(const uint8_t *pwd, const uint32_t pwdlen, | |||
int catena_test(void) | |||
{ | |||
/* From catena-v3.1 spec */ | |||
guint8 pw[] = {0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64}; | |||
guint8 salt[] = {0x73, 0x61, 0x6c, 0x74}; | |||
guint8 ad[] = {0x64, 0x61, 0x74, 0x61}; | |||
guint8 expected[] = { | |||
uint8_t pw[] = {0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64}; | |||
uint8_t salt[] = {0x73, 0x61, 0x6c, 0x74}; | |||
uint8_t ad[] = {0x64, 0x61, 0x74, 0x61}; | |||
uint8_t expected[] = { | |||
0x20, 0xc5, 0x91, 0x93, 0x8f, 0xc3, 0xaf, 0xcc, 0x3b, 0xba, 0x91, 0xd2, 0xfb, | |||
0x84, 0xbf, 0x7b, 0x44, 0x04, 0xf9, 0x4c, 0x45, 0xed, 0x4d, 0x11, 0xa7, 0xe2, | |||
0xb4, 0x12, 0x3e, 0xab, 0x0b, 0x77, 0x4a, 0x12, 0xb4, 0x22, 0xd0, 0xda, 0xb5, | |||
0x25, 0x29, 0x02, 0xfc, 0x54, 0x47, 0xea, 0x82, 0x63, 0x8c, 0x1a, 0xfb, 0xa7, | |||
0xa9, 0x94, 0x24, 0x13, 0x0e, 0x44, 0x36, 0x3b, 0x9d, 0x9f, 0xc9, 0x60}; | |||
guint8 real[H_LEN]; | |||
uint8_t real[H_LEN]; | |||
if (catena(pw, sizeof(pw), salt, sizeof(salt), ad, sizeof(ad), | |||
4, 10, 10, H_LEN, real) != 0) { |
@@ -94,7 +94,7 @@ chacha_is_aligned(const void *p) | |||
const char * | |||
chacha_load(void) | |||
{ | |||
guint i; | |||
unsigned int i; | |||
if (cpu_config != 0) { | |||
for (i = 0; i < G_N_ELEMENTS(chacha_list); i++) { |
@@ -5,7 +5,7 @@ | |||
#if defined(HAVE_INT32) | |||
typedef uint32_t chacha_int32; | |||
#else | |||
typedef guint32 chacha_int32; | |||
typedef uint32_t chacha_int32; | |||
#endif | |||
/* interpret four 8 bit unsigned integers as a 32 bit unsigned integer in little endian */ |
@@ -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, | |||
@@ -63,16 +63,16 @@ unsigned cpu_config = 0; | |||
static gboolean cryptobox_loaded = FALSE; | |||
static const guchar n0[16] = {0}; | |||
static const unsigned char n0[16] = {0}; | |||
#define CRYPTOBOX_ALIGNMENT 16 | |||
#define cryptobox_align_ptr(p, a) \ | |||
(void *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1)) | |||
static void | |||
rspamd_cryptobox_cpuid(gint cpu[4], gint info) | |||
rspamd_cryptobox_cpuid(int cpu[4], int info) | |||
{ | |||
guint32 __attribute__((unused)) eax, __attribute__((unused)) ecx = 0, __attribute__((unused)) ebx = 0, __attribute__((unused)) edx = 0; | |||
uint32_t __attribute__((unused)) eax, __attribute__((unused)) ecx = 0, __attribute__((unused)) ebx = 0, __attribute__((unused)) edx = 0; | |||
eax = info; | |||
#if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) | |||
@@ -93,7 +93,7 @@ rspamd_cryptobox_cpuid(gint cpu[4], gint info) | |||
cpu[2] = ecx; | |||
cpu[3] = edx; | |||
#else | |||
memset(cpu, 0, sizeof(gint) * 4); | |||
memset(cpu, 0, sizeof(int) * 4); | |||
#endif | |||
} | |||
@@ -108,10 +108,10 @@ rspamd_cryptobox_ill_handler(int signo) | |||
} | |||
static gboolean | |||
rspamd_cryptobox_test_instr(gint instr) | |||
rspamd_cryptobox_test_instr(int instr) | |||
{ | |||
void (*old_handler)(int); | |||
guint32 rd; | |||
uint32_t rd; | |||
#if defined(__GNUC__) | |||
ok = 1; | |||
@@ -186,10 +186,10 @@ rspamd_cryptobox_test_instr(gint instr) | |||
struct rspamd_cryptobox_library_ctx * | |||
rspamd_cryptobox_init(void) | |||
{ | |||
gint cpu[4], nid; | |||
const guint32 osxsave_mask = (1 << 27); | |||
const guint32 fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27)); | |||
const guint32 avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8); | |||
int cpu[4], nid; | |||
const uint32_t osxsave_mask = (1 << 27); | |||
const uint32_t fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27)); | |||
const uint32_t avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8); | |||
gulong bit; | |||
static struct rspamd_cryptobox_library_ctx *ctx; | |||
GString *buf; | |||
@@ -207,32 +207,32 @@ rspamd_cryptobox_init(void) | |||
rspamd_cryptobox_cpuid(cpu, 1); | |||
if (nid > 1) { | |||
if ((cpu[3] & ((guint32) 1 << 26))) { | |||
if ((cpu[3] & ((uint32_t) 1 << 26))) { | |||
if (rspamd_cryptobox_test_instr(CPUID_SSE2)) { | |||
cpu_config |= CPUID_SSE2; | |||
} | |||
} | |||
if ((cpu[2] & ((guint32) 1 << 0))) { | |||
if ((cpu[2] & ((uint32_t) 1 << 0))) { | |||
if (rspamd_cryptobox_test_instr(CPUID_SSE3)) { | |||
cpu_config |= CPUID_SSE3; | |||
} | |||
} | |||
if ((cpu[2] & ((guint32) 1 << 9))) { | |||
if ((cpu[2] & ((uint32_t) 1 << 9))) { | |||
if (rspamd_cryptobox_test_instr(CPUID_SSSE3)) { | |||
cpu_config |= CPUID_SSSE3; | |||
} | |||
} | |||
if ((cpu[2] & ((guint32) 1 << 19))) { | |||
if ((cpu[2] & ((uint32_t) 1 << 19))) { | |||
if (rspamd_cryptobox_test_instr(CPUID_SSE41)) { | |||
cpu_config |= CPUID_SSE41; | |||
} | |||
} | |||
if ((cpu[2] & ((guint32) 1 << 20))) { | |||
if ((cpu[2] & ((uint32_t) 1 << 20))) { | |||
if (rspamd_cryptobox_test_instr(CPUID_SSE42)) { | |||
cpu_config |= CPUID_SSE42; | |||
} | |||
} | |||
if ((cpu[2] & ((guint32) 1 << 30))) { | |||
if ((cpu[2] & ((uint32_t) 1 << 30))) { | |||
if (rspamd_cryptobox_test_instr(CPUID_RDRAND)) { | |||
cpu_config |= CPUID_RDRAND; | |||
} | |||
@@ -240,7 +240,7 @@ rspamd_cryptobox_init(void) | |||
/* OSXSAVE */ | |||
if ((cpu[2] & osxsave_mask) == osxsave_mask) { | |||
if ((cpu[2] & ((guint32) 1 << 28))) { | |||
if ((cpu[2] & ((uint32_t) 1 << 28))) { | |||
if (rspamd_cryptobox_test_instr(CPUID_AVX)) { | |||
cpu_config |= CPUID_AVX; | |||
} | |||
@@ -357,7 +357,7 @@ void rspamd_cryptobox_keypair(rspamd_pk_t pk, rspamd_sk_t sk, | |||
unsigned char *buf = NULL; /* Thanks openssl for this API (no) */ | |||
len = EC_POINT_point2buf(EC_KEY_get0_group(ec_sec), ec_pub, | |||
POINT_CONVERSION_UNCOMPRESSED, &buf, NULL); | |||
g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode)); | |||
g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode)); | |||
memcpy(pk, buf, len); | |||
OPENSSL_free(buf); | |||
#else | |||
@@ -365,13 +365,13 @@ void rspamd_cryptobox_keypair(rspamd_pk_t pk, rspamd_sk_t sk, | |||
bn_pub = EC_POINT_point2bn(EC_KEY_get0_group(ec_sec), | |||
ec_pub, POINT_CONVERSION_UNCOMPRESSED, NULL, NULL); | |||
len = BN_num_bytes(bn_pub); | |||
g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode)); | |||
g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode)); | |||
BN_bn2bin(bn_pub, pk); | |||
BN_free(bn_pub); | |||
#endif | |||
len = BN_num_bytes(bn_sec); | |||
g_assert(len <= (gint) sizeof(rspamd_sk_t)); | |||
g_assert(len <= (int) sizeof(rspamd_sk_t)); | |||
BN_bn2bin(bn_sec, sk); | |||
EC_KEY_free(ec_sec); | |||
@@ -407,7 +407,7 @@ void rspamd_cryptobox_keypair_sig(rspamd_sig_pk_t pk, rspamd_sig_sk_t sk, | |||
unsigned char *buf = NULL; /* Thanks openssl for this API (no) */ | |||
len = EC_POINT_point2buf(EC_KEY_get0_group(ec_sec), ec_pub, | |||
POINT_CONVERSION_UNCOMPRESSED, &buf, NULL); | |||
g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode)); | |||
g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode)); | |||
memcpy(pk, buf, len); | |||
OPENSSL_free(buf); | |||
#else | |||
@@ -415,13 +415,13 @@ void rspamd_cryptobox_keypair_sig(rspamd_sig_pk_t pk, rspamd_sig_sk_t sk, | |||
bn_pub = EC_POINT_point2bn(EC_KEY_get0_group(ec_sec), | |||
ec_pub, POINT_CONVERSION_UNCOMPRESSED, NULL, NULL); | |||
len = BN_num_bytes(bn_pub); | |||
g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode)); | |||
g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode)); | |||
BN_bn2bin(bn_pub, pk); | |||
BN_free(bn_pub); | |||
#endif | |||
len = BN_num_bytes(bn_sec); | |||
g_assert(len <= (gint) sizeof(rspamd_sk_t)); | |||
g_assert(len <= (int) sizeof(rspamd_sk_t)); | |||
BN_bn2bin(bn_sec, sk); | |||
EC_KEY_free(ec_sec); | |||
#endif | |||
@@ -476,8 +476,8 @@ void rspamd_cryptobox_nm(rspamd_nm_t nm, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
guchar s[32]; | |||
guchar e[32]; | |||
unsigned char s[32]; | |||
unsigned char e[32]; | |||
memcpy(e, sk, 32); | |||
e[0] &= 248; | |||
@@ -497,8 +497,8 @@ void rspamd_cryptobox_nm(rspamd_nm_t nm, | |||
EC_KEY *lk; | |||
EC_POINT *ec_pub; | |||
BIGNUM *bn_pub, *bn_sec; | |||
gint len; | |||
guchar s[32]; | |||
int len; | |||
unsigned char s[32]; | |||
lk = EC_KEY_new_by_curve_name(CRYPTOBOX_CURVE_NID); | |||
g_assert(lk != NULL); | |||
@@ -525,8 +525,8 @@ void rspamd_cryptobox_nm(rspamd_nm_t nm, | |||
} | |||
} | |||
void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p, | |||
const guchar *m, gsize mlen, | |||
void rspamd_cryptobox_sign(unsigned char *sig, unsigned long long *siglen_p, | |||
const unsigned char *m, gsize mlen, | |||
const rspamd_sk_t sk, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
@@ -541,7 +541,7 @@ void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p, | |||
BIGNUM *bn_sec; | |||
EVP_MD_CTX *sha_ctx; | |||
unsigned char h[64]; | |||
guint diglen = rspamd_cryptobox_signature_bytes(mode); | |||
unsigned int diglen = rspamd_cryptobox_signature_bytes(mode); | |||
/* Prehash */ | |||
sha_ctx = EVP_MD_CTX_create(); | |||
@@ -571,9 +571,9 @@ void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p, | |||
} | |||
} | |||
bool rspamd_cryptobox_verify(const guchar *sig, | |||
bool rspamd_cryptobox_verify(const unsigned char *sig, | |||
gsize siglen, | |||
const guchar *m, | |||
const unsigned char *m, | |||
gsize mlen, | |||
const rspamd_pk_t pk, | |||
enum rspamd_cryptobox_mode mode) | |||
@@ -700,7 +700,7 @@ rspamd_cryptobox_auth_init(void *auth_ctx, void *enc_ctx, | |||
{ | |||
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
crypto_onetimeauth_state *mac_ctx; | |||
guchar RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; | |||
unsigned char RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; | |||
mac_ctx = cryptobox_align_ptr(auth_ctx, CRYPTOBOX_ALIGNMENT); | |||
memset(subkey, 0, sizeof(subkey)); | |||
@@ -724,8 +724,8 @@ rspamd_cryptobox_auth_init(void *auth_ctx, void *enc_ctx, | |||
} | |||
static gboolean | |||
rspamd_cryptobox_encrypt_update(void *enc_ctx, const guchar *in, gsize inlen, | |||
guchar *out, gsize *outlen, | |||
rspamd_cryptobox_encrypt_update(void *enc_ctx, const unsigned char *in, gsize inlen, | |||
unsigned char *out, gsize *outlen, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
@@ -747,7 +747,7 @@ rspamd_cryptobox_encrypt_update(void *enc_ctx, const guchar *in, gsize inlen, | |||
g_assert(0); | |||
#else | |||
EVP_CIPHER_CTX **s = enc_ctx; | |||
gint r; | |||
int r; | |||
r = inlen; | |||
g_assert(EVP_EncryptUpdate(*s, out, &r, in, inlen) == 1); | |||
@@ -764,7 +764,7 @@ rspamd_cryptobox_encrypt_update(void *enc_ctx, const guchar *in, gsize inlen, | |||
} | |||
static gboolean | |||
rspamd_cryptobox_auth_update(void *auth_ctx, const guchar *in, gsize inlen, | |||
rspamd_cryptobox_auth_update(void *auth_ctx, const unsigned char *in, gsize inlen, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
@@ -787,7 +787,7 @@ rspamd_cryptobox_auth_update(void *auth_ctx, const guchar *in, gsize inlen, | |||
} | |||
static gsize | |||
rspamd_cryptobox_encrypt_final(void *enc_ctx, guchar *out, gsize remain, | |||
rspamd_cryptobox_encrypt_final(void *enc_ctx, unsigned char *out, gsize remain, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
@@ -801,7 +801,7 @@ rspamd_cryptobox_encrypt_final(void *enc_ctx, guchar *out, gsize remain, | |||
g_assert(0); | |||
#else | |||
EVP_CIPHER_CTX **s = enc_ctx; | |||
gint r = remain; | |||
int r = remain; | |||
g_assert(EVP_EncryptFinal_ex(*s, out, &r) == 1); | |||
@@ -884,7 +884,7 @@ rspamd_cryptobox_auth_verify_init(void *auth_ctx, void *enc_ctx, | |||
{ | |||
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
crypto_onetimeauth_state *mac_ctx; | |||
guchar RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; | |||
unsigned char RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES]; | |||
mac_ctx = cryptobox_align_ptr(auth_ctx, CRYPTOBOX_ALIGNMENT); | |||
memset(subkey, 0, sizeof(subkey)); | |||
@@ -908,8 +908,8 @@ rspamd_cryptobox_auth_verify_init(void *auth_ctx, void *enc_ctx, | |||
} | |||
static gboolean | |||
rspamd_cryptobox_decrypt_update(void *enc_ctx, const guchar *in, gsize inlen, | |||
guchar *out, gsize *outlen, | |||
rspamd_cryptobox_decrypt_update(void *enc_ctx, const unsigned char *in, gsize inlen, | |||
unsigned char *out, gsize *outlen, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
@@ -930,7 +930,7 @@ rspamd_cryptobox_decrypt_update(void *enc_ctx, const guchar *in, gsize inlen, | |||
g_assert(0); | |||
#else | |||
EVP_CIPHER_CTX **s = enc_ctx; | |||
gint r; | |||
int r; | |||
r = outlen ? *outlen : inlen; | |||
g_assert(EVP_DecryptUpdate(*s, out, &r, in, inlen) == 1); | |||
@@ -946,7 +946,7 @@ rspamd_cryptobox_decrypt_update(void *enc_ctx, const guchar *in, gsize inlen, | |||
static gboolean | |||
rspamd_cryptobox_auth_verify_update(void *auth_ctx, | |||
const guchar *in, gsize inlen, | |||
const unsigned char *in, gsize inlen, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
@@ -969,7 +969,7 @@ rspamd_cryptobox_auth_verify_update(void *auth_ctx, | |||
} | |||
static gboolean | |||
rspamd_cryptobox_decrypt_final(void *enc_ctx, guchar *out, gsize remain, | |||
rspamd_cryptobox_decrypt_final(void *enc_ctx, unsigned char *out, gsize remain, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
@@ -985,7 +985,7 @@ rspamd_cryptobox_decrypt_final(void *enc_ctx, guchar *out, gsize remain, | |||
g_assert(0); | |||
#else | |||
EVP_CIPHER_CTX **s = enc_ctx; | |||
gint r = remain; | |||
int r = remain; | |||
if (EVP_DecryptFinal_ex(*s, out, &r) < 0) { | |||
return FALSE; | |||
@@ -1021,7 +1021,7 @@ rspamd_cryptobox_auth_verify_final(void *auth_ctx, const rspamd_mac_t sig, | |||
#else | |||
EVP_CIPHER_CTX **s = auth_ctx; | |||
if (EVP_CIPHER_CTX_ctrl(*s, EVP_CTRL_GCM_SET_TAG, 16, (guchar *) sig) != 1) { | |||
if (EVP_CIPHER_CTX_ctrl(*s, EVP_CTRL_GCM_SET_TAG, 16, (unsigned char *) sig) != 1) { | |||
return FALSE; | |||
} | |||
@@ -1055,7 +1055,7 @@ rspamd_cryptobox_cleanup(void *enc_ctx, void *auth_ctx, | |||
} | |||
} | |||
void rspamd_cryptobox_encrypt_nm_inplace(guchar *data, gsize len, | |||
void rspamd_cryptobox_encrypt_nm_inplace(unsigned char *data, gsize len, | |||
const rspamd_nonce_t nonce, | |||
const rspamd_nm_t nm, | |||
rspamd_mac_t sig, | |||
@@ -1081,7 +1081,7 @@ void rspamd_cryptobox_encrypt_nm_inplace(guchar *data, gsize len, | |||
static void | |||
rspamd_cryptobox_flush_outbuf(struct rspamd_cryptobox_segment *st, | |||
const guchar *buf, gsize len, gsize offset) | |||
const unsigned char *buf, gsize len, gsize offset) | |||
{ | |||
gsize cpy_len; | |||
@@ -1102,9 +1102,9 @@ void rspamd_cryptobox_encryptv_nm_inplace(struct rspamd_cryptobox_segment *segme | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
struct rspamd_cryptobox_segment *cur = segments, *start_seg = segments; | |||
guchar outbuf[CHACHA_BLOCKBYTES * 16]; | |||
unsigned char outbuf[CHACHA_BLOCKBYTES * 16]; | |||
void *enc_ctx, *auth_ctx; | |||
guchar *out, *in; | |||
unsigned char *out, *in; | |||
gsize r, remain, inremain, seg_offset; | |||
enc_ctx = g_alloca(rspamd_cryptobox_encrypt_ctx_len(mode)); | |||
@@ -1119,7 +1119,7 @@ void rspamd_cryptobox_encryptv_nm_inplace(struct rspamd_cryptobox_segment *segme | |||
seg_offset = 0; | |||
for (;;) { | |||
if (cur - segments == (gint) cnt) { | |||
if (cur - segments == (int) cnt) { | |||
break; | |||
} | |||
@@ -1205,7 +1205,7 @@ void rspamd_cryptobox_encryptv_nm_inplace(struct rspamd_cryptobox_segment *segme | |||
} | |||
gboolean | |||
rspamd_cryptobox_decrypt_nm_inplace(guchar *data, gsize len, | |||
rspamd_cryptobox_decrypt_nm_inplace(unsigned char *data, gsize len, | |||
const rspamd_nonce_t nonce, const rspamd_nm_t nm, | |||
const rspamd_mac_t sig, enum rspamd_cryptobox_mode mode) | |||
{ | |||
@@ -1235,13 +1235,13 @@ rspamd_cryptobox_decrypt_nm_inplace(guchar *data, gsize len, | |||
} | |||
gboolean | |||
rspamd_cryptobox_decrypt_inplace(guchar *data, gsize len, | |||
rspamd_cryptobox_decrypt_inplace(unsigned char *data, gsize len, | |||
const rspamd_nonce_t nonce, | |||
const rspamd_pk_t pk, const rspamd_sk_t sk, | |||
const rspamd_mac_t sig, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
guchar nm[rspamd_cryptobox_MAX_NMBYTES]; | |||
unsigned char nm[rspamd_cryptobox_MAX_NMBYTES]; | |||
gboolean ret; | |||
rspamd_cryptobox_nm(nm, pk, sk, mode); | |||
@@ -1252,13 +1252,13 @@ rspamd_cryptobox_decrypt_inplace(guchar *data, gsize len, | |||
return ret; | |||
} | |||
void rspamd_cryptobox_encrypt_inplace(guchar *data, gsize len, | |||
void rspamd_cryptobox_encrypt_inplace(unsigned char *data, gsize len, | |||
const rspamd_nonce_t nonce, | |||
const rspamd_pk_t pk, const rspamd_sk_t sk, | |||
rspamd_mac_t sig, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
guchar nm[rspamd_cryptobox_MAX_NMBYTES]; | |||
unsigned char nm[rspamd_cryptobox_MAX_NMBYTES]; | |||
rspamd_cryptobox_nm(nm, pk, sk, mode); | |||
rspamd_cryptobox_encrypt_nm_inplace(data, len, nonce, nm, sig, mode); | |||
@@ -1272,7 +1272,7 @@ void rspamd_cryptobox_encryptv_inplace(struct rspamd_cryptobox_segment *segments | |||
rspamd_mac_t sig, | |||
enum rspamd_cryptobox_mode mode) | |||
{ | |||
guchar nm[rspamd_cryptobox_MAX_NMBYTES]; | |||
unsigned char nm[rspamd_cryptobox_MAX_NMBYTES]; | |||
rspamd_cryptobox_nm(nm, pk, sk, mode); | |||
rspamd_cryptobox_encryptv_nm_inplace(segments, cnt, nonce, nm, sig, mode); | |||
@@ -1293,11 +1293,11 @@ void rspamd_cryptobox_siphash(unsigned char *out, const unsigned char *in, | |||
*/ | |||
static gboolean | |||
rspamd_cryptobox_pbkdf2(const char *pass, gsize pass_len, | |||
const guint8 *salt, gsize salt_len, guint8 *key, gsize key_len, | |||
const uint8_t *salt, gsize salt_len, uint8_t *key, gsize key_len, | |||
unsigned int rounds) | |||
{ | |||
guint8 *asalt, obuf[crypto_generichash_blake2b_BYTES_MAX]; | |||
guint8 d1[crypto_generichash_blake2b_BYTES_MAX], | |||
uint8_t *asalt, obuf[crypto_generichash_blake2b_BYTES_MAX]; | |||
uint8_t d1[crypto_generichash_blake2b_BYTES_MAX], | |||
d2[crypto_generichash_blake2b_BYTES_MAX]; | |||
unsigned int i, j; | |||
unsigned int count; | |||
@@ -1324,7 +1324,7 @@ rspamd_cryptobox_pbkdf2(const char *pass, gsize pass_len, | |||
pass, pass_len); | |||
} | |||
else { | |||
guint8 k[crypto_generichash_blake2b_BYTES_MAX]; | |||
uint8_t k[crypto_generichash_blake2b_BYTES_MAX]; | |||
/* | |||
* We use additional blake2 iteration to store large key | |||
@@ -1344,7 +1344,7 @@ rspamd_cryptobox_pbkdf2(const char *pass, gsize pass_len, | |||
pass, pass_len); | |||
} | |||
else { | |||
guint8 k[crypto_generichash_blake2b_BYTES_MAX]; | |||
uint8_t k[crypto_generichash_blake2b_BYTES_MAX]; | |||
/* | |||
* We use additional blake2 iteration to store large key | |||
@@ -1380,7 +1380,7 @@ rspamd_cryptobox_pbkdf2(const char *pass, gsize pass_len, | |||
gboolean | |||
rspamd_cryptobox_pbkdf(const char *pass, gsize pass_len, | |||
const guint8 *salt, gsize salt_len, guint8 *key, gsize key_len, | |||
const uint8_t *salt, gsize salt_len, uint8_t *key, gsize key_len, | |||
unsigned int complexity, enum rspamd_cryptobox_pbkdf_type type) | |||
{ | |||
gboolean ret = FALSE; | |||
@@ -1402,7 +1402,7 @@ rspamd_cryptobox_pbkdf(const char *pass, gsize pass_len, | |||
return ret; | |||
} | |||
guint rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode) | |||
unsigned int rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
return 32; | |||
@@ -1412,7 +1412,7 @@ guint rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode) | |||
} | |||
} | |||
guint rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode) | |||
unsigned int rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
return 32; | |||
@@ -1422,7 +1422,7 @@ guint rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode) | |||
} | |||
} | |||
guint rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode) | |||
unsigned int rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
return 24; | |||
@@ -1433,12 +1433,12 @@ guint rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode) | |||
} | |||
guint rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode) | |||
unsigned int rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode) | |||
{ | |||
return 32; | |||
} | |||
guint rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode) | |||
unsigned int rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode) | |||
{ | |||
if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
return 64; | |||
@@ -1448,9 +1448,9 @@ guint rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode) | |||
} | |||
} | |||
guint rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode) | |||
unsigned int rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode) | |||
{ | |||
static guint ssl_keylen; | |||
static unsigned int ssl_keylen; | |||
if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) { | |||
return 64; | |||
@@ -1470,17 +1470,17 @@ guint rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode) | |||
} | |||
} | |||
guint rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode) | |||
unsigned int rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode) | |||
{ | |||
return 32; | |||
} | |||
guint rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode) | |||
unsigned int rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode) | |||
{ | |||
return 16; | |||
} | |||
void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *p, const guchar *key, gsize keylen) | |||
void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *p, const unsigned char *key, gsize keylen) | |||
{ | |||
crypto_generichash_blake2b_state *st = cryptobox_align_ptr(p, | |||
RSPAMD_ALIGNOF(crypto_generichash_blake2b_state)); | |||
@@ -1491,7 +1491,7 @@ void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *p, const guchar * | |||
/** | |||
* Update hash with data portion | |||
*/ | |||
void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *p, const guchar *data, gsize len) | |||
void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *p, const unsigned char *data, gsize len) | |||
{ | |||
crypto_generichash_blake2b_state *st = cryptobox_align_ptr(p, | |||
RSPAMD_ALIGNOF(crypto_generichash_blake2b_state)); | |||
@@ -1501,7 +1501,7 @@ void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *p, const guchar | |||
/** | |||
* Output hash to the buffer of rspamd_cryptobox_HASHBYTES length | |||
*/ | |||
void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *p, guchar *out) | |||
void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *p, unsigned char *out) | |||
{ | |||
crypto_generichash_blake2b_state *st = cryptobox_align_ptr(p, | |||
RSPAMD_ALIGNOF(crypto_generichash_blake2b_state)); | |||
@@ -1511,10 +1511,10 @@ void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *p, guchar *out) | |||
/** | |||
* One in all function | |||
*/ | |||
void rspamd_cryptobox_hash(guchar *out, | |||
const guchar *data, | |||
void rspamd_cryptobox_hash(unsigned char *out, | |||
const unsigned char *data, | |||
gsize len, | |||
const guchar *key, | |||
const unsigned char *key, | |||
gsize keylen) | |||
{ | |||
crypto_generichash_blake2b(out, crypto_generichash_blake2b_BYTES_MAX, | |||
@@ -1529,10 +1529,10 @@ G_STATIC_ASSERT(sizeof(struct XXH3_state_s) <= | |||
struct RSPAMD_ALIGNED(16) _mum_iuf { | |||
union { | |||
gint64 ll; | |||
unsigned char b[sizeof(guint64)]; | |||
int64_t ll; | |||
unsigned char b[sizeof(uint64_t)]; | |||
} buf; | |||
gint64 h; | |||
int64_t h; | |||
unsigned rem; | |||
}; | |||
@@ -1556,7 +1556,7 @@ void rspamd_cryptobox_fast_hash_free(rspamd_cryptobox_fast_hash_state_t *st) | |||
} | |||
void rspamd_cryptobox_fast_hash_init(rspamd_cryptobox_fast_hash_state_t *st, | |||
guint64 seed) | |||
uint64_t seed) | |||
{ | |||
XXH3_state_t *xst = (XXH3_state_t *) st->opaque; | |||
st->type = RSPAMD_CRYPTOBOX_XXHASH3; | |||
@@ -1566,7 +1566,7 @@ void rspamd_cryptobox_fast_hash_init(rspamd_cryptobox_fast_hash_state_t *st, | |||
void rspamd_cryptobox_fast_hash_init_specific(rspamd_cryptobox_fast_hash_state_t *st, | |||
enum rspamd_cryptobox_fast_hash_type type, | |||
guint64 seed) | |||
uint64_t seed) | |||
{ | |||
switch (type) { | |||
case RSPAMD_CRYPTOBOX_T1HA: | |||
@@ -1636,7 +1636,7 @@ void rspamd_cryptobox_fast_hash_update(rspamd_cryptobox_fast_hash_state_t *st, | |||
case RSPAMD_CRYPTOBOX_MUMHASH: { | |||
struct _mum_iuf *iuf = (struct _mum_iuf *) st->opaque; | |||
gsize drem = len; | |||
const guchar *p = data; | |||
const unsigned char *p = data; | |||
if (iuf->rem > 0) { | |||
/* Process remainder */ | |||
@@ -1664,7 +1664,7 @@ void rspamd_cryptobox_fast_hash_update(rspamd_cryptobox_fast_hash_state_t *st, | |||
/* Leftover */ | |||
if (drem > 0) { | |||
iuf->rem = sizeof(guint64) - drem; | |||
iuf->rem = sizeof(uint64_t) - drem; | |||
iuf->buf.ll = 0; | |||
memcpy(iuf->buf.b, p, drem); | |||
} | |||
@@ -1681,10 +1681,10 @@ void rspamd_cryptobox_fast_hash_update(rspamd_cryptobox_fast_hash_state_t *st, | |||
} | |||
} | |||
guint64 | |||
uint64_t | |||
rspamd_cryptobox_fast_hash_final(rspamd_cryptobox_fast_hash_state_t *st) | |||
{ | |||
guint64 ret; | |||
uint64_t ret; | |||
if (st->type == RSPAMD_CRYPTOBOX_T1HA) { | |||
t1ha_context_t *rst = (t1ha_context_t *) st->opaque; | |||
@@ -1731,32 +1731,32 @@ rspamd_cryptobox_fast_hash_final(rspamd_cryptobox_fast_hash_state_t *st) | |||
/** | |||
* One in all function | |||
*/ | |||
static inline guint64 | |||
static inline uint64_t | |||
rspamd_cryptobox_fast_hash_machdep(const void *data, | |||
gsize len, guint64 seed) | |||
gsize len, uint64_t seed) | |||
{ | |||
return XXH3_64bits_withSeed(data, len, seed); | |||
} | |||
static inline guint64 | |||
static inline uint64_t | |||
rspamd_cryptobox_fast_hash_indep(const void *data, | |||
gsize len, guint64 seed) | |||
gsize len, uint64_t seed) | |||
{ | |||
return XXH3_64bits_withSeed(data, len, seed); | |||
} | |||
guint64 | |||
uint64_t | |||
rspamd_cryptobox_fast_hash(const void *data, | |||
gsize len, guint64 seed) | |||
gsize len, uint64_t seed) | |||
{ | |||
return rspamd_cryptobox_fast_hash_machdep(data, len, seed); | |||
} | |||
guint64 | |||
uint64_t | |||
rspamd_cryptobox_fast_hash_specific( | |||
enum rspamd_cryptobox_fast_hash_type type, | |||
const void *data, | |||
gsize len, guint64 seed) | |||
gsize len, uint64_t seed) | |||
{ | |||
switch (type) { | |||
case RSPAMD_CRYPTOBOX_XXHASH32: |
@@ -1,11 +1,11 @@ | |||
/*- | |||
* Copyright 2016 Vsevolod Stakhov | |||
/* | |||
* Copyright 2024 Vsevolod Stakhov | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
@@ -25,7 +25,7 @@ extern "C" { | |||
#endif | |||
struct rspamd_cryptobox_segment { | |||
guchar *data; | |||
unsigned char *data; | |||
gsize len; | |||
}; | |||
@@ -57,15 +57,15 @@ struct rspamd_cryptobox_segment { | |||
#define CPUID_SSE42 0x40 | |||
#define CPUID_RDRAND 0x80 | |||
typedef guchar rspamd_pk_t[rspamd_cryptobox_MAX_PKBYTES]; | |||
typedef guchar rspamd_sk_t[rspamd_cryptobox_MAX_SKBYTES]; | |||
typedef guchar rspamd_mac_t[rspamd_cryptobox_MAX_MACBYTES]; | |||
typedef guchar rspamd_nm_t[rspamd_cryptobox_MAX_NMBYTES]; | |||
typedef guchar rspamd_nonce_t[rspamd_cryptobox_MAX_NONCEBYTES]; | |||
typedef guchar rspamd_sipkey_t[rspamd_cryptobox_SIPKEYBYTES]; | |||
typedef guchar rspamd_signature_t[rspamd_cryptobox_MAX_SIGBYTES]; | |||
typedef guchar rspamd_sig_pk_t[rspamd_cryptobox_MAX_SIGPKBYTES]; | |||
typedef guchar rspamd_sig_sk_t[rspamd_cryptobox_MAX_SIGSKBYTES]; | |||
typedef unsigned char rspamd_pk_t[rspamd_cryptobox_MAX_PKBYTES]; | |||
typedef unsigned char rspamd_sk_t[rspamd_cryptobox_MAX_SKBYTES]; | |||
typedef unsigned char rspamd_mac_t[rspamd_cryptobox_MAX_MACBYTES]; | |||
typedef unsigned char rspamd_nm_t[rspamd_cryptobox_MAX_NMBYTES]; | |||
typedef unsigned char rspamd_nonce_t[rspamd_cryptobox_MAX_NONCEBYTES]; | |||
typedef unsigned char rspamd_sipkey_t[rspamd_cryptobox_SIPKEYBYTES]; | |||
typedef unsigned char rspamd_signature_t[rspamd_cryptobox_MAX_SIGBYTES]; | |||
typedef unsigned char rspamd_sig_pk_t[rspamd_cryptobox_MAX_SIGPKBYTES]; | |||
typedef unsigned char rspamd_sig_sk_t[rspamd_cryptobox_MAX_SIGSKBYTES]; | |||
enum rspamd_cryptobox_mode { | |||
RSPAMD_CRYPTOBOX_MODE_25519 = 0, | |||
@@ -73,9 +73,9 @@ enum rspamd_cryptobox_mode { | |||
}; | |||
struct rspamd_cryptobox_library_ctx { | |||
gchar *cpu_extensions; | |||
const gchar *chacha20_impl; | |||
const gchar *base64_impl; | |||
char *cpu_extensions; | |||
const char *chacha20_impl; | |||
const char *base64_impl; | |||
unsigned long cpu_config; | |||
}; | |||
@@ -108,7 +108,7 @@ void rspamd_cryptobox_keypair_sig(rspamd_sig_pk_t pk, rspamd_sig_sk_t sk, | |||
* @param sk local secret key | |||
* @param sig output signature | |||
*/ | |||
void rspamd_cryptobox_encrypt_inplace(guchar *data, gsize len, | |||
void rspamd_cryptobox_encrypt_inplace(unsigned char *data, gsize len, | |||
const rspamd_nonce_t nonce, | |||
const rspamd_pk_t pk, const rspamd_sk_t sk, rspamd_mac_t sig, | |||
enum rspamd_cryptobox_mode mode); | |||
@@ -137,7 +137,7 @@ void rspamd_cryptobox_encryptv_inplace(struct rspamd_cryptobox_segment *segments | |||
* @param sig signature input | |||
* @return TRUE if input has been verified successfully | |||
*/ | |||
gboolean rspamd_cryptobox_decrypt_inplace(guchar *data, gsize len, | |||
gboolean rspamd_cryptobox_decrypt_inplace(unsigned char *data, gsize len, | |||
const rspamd_nonce_t nonce, | |||
const rspamd_pk_t pk, const rspamd_sk_t sk, const rspamd_mac_t sig, | |||
enum rspamd_cryptobox_mode mode); | |||
@@ -150,7 +150,7 @@ gboolean rspamd_cryptobox_decrypt_inplace(guchar *data, gsize len, | |||
* @param sk local secret key | |||
* @param sig output signature | |||
*/ | |||
void rspamd_cryptobox_encrypt_nm_inplace(guchar *data, gsize len, | |||
void rspamd_cryptobox_encrypt_nm_inplace(unsigned char *data, gsize len, | |||
const rspamd_nonce_t nonce, | |||
const rspamd_nm_t nm, rspamd_mac_t sig, | |||
enum rspamd_cryptobox_mode mode); | |||
@@ -179,7 +179,7 @@ void rspamd_cryptobox_encryptv_nm_inplace(struct rspamd_cryptobox_segment *segme | |||
* @param sig signature input | |||
* @return TRUE if input has been verified successfully | |||
*/ | |||
gboolean rspamd_cryptobox_decrypt_nm_inplace(guchar *data, gsize len, | |||
gboolean rspamd_cryptobox_decrypt_nm_inplace(unsigned char *data, gsize len, | |||
const rspamd_nonce_t nonce, | |||
const rspamd_nm_t nm, const rspamd_mac_t sig, | |||
enum rspamd_cryptobox_mode mode); | |||
@@ -201,8 +201,8 @@ void rspamd_cryptobox_nm(rspamd_nm_t nm, const rspamd_pk_t pk, | |||
* @param mlen input length | |||
* @param sk secret key | |||
*/ | |||
void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p, | |||
const guchar *m, gsize mlen, | |||
void rspamd_cryptobox_sign(unsigned char *sig, unsigned long long *siglen_p, | |||
const unsigned char *m, gsize mlen, | |||
const rspamd_sk_t sk, | |||
enum rspamd_cryptobox_mode mode); | |||
@@ -215,9 +215,9 @@ void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p, | |||
* @param pk public key for verification | |||
* @return true if signature is valid, false otherwise | |||
*/ | |||
bool rspamd_cryptobox_verify(const guchar *sig, | |||
bool rspamd_cryptobox_verify(const unsigned char *sig, | |||
gsize siglen, | |||
const guchar *m, | |||
const unsigned char *m, | |||
gsize mlen, | |||
const rspamd_pk_t pk, | |||
enum rspamd_cryptobox_mode mode); | |||
@@ -268,8 +268,8 @@ enum rspamd_cryptobox_pbkdf_type { | |||
* @return TRUE in case of success and FALSE if failed | |||
*/ | |||
gboolean rspamd_cryptobox_pbkdf(const char *pass, gsize pass_len, | |||
const guint8 *salt, gsize salt_len, | |||
guint8 *key, gsize key_len, | |||
const uint8_t *salt, gsize salt_len, | |||
uint8_t *key, gsize key_len, | |||
unsigned int complexity, | |||
enum rspamd_cryptobox_pbkdf_type type); | |||
@@ -277,42 +277,42 @@ gboolean rspamd_cryptobox_pbkdf(const char *pass, gsize pass_len, | |||
/** | |||
* Real size of rspamd cryptobox public key | |||
*/ | |||
guint rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode); | |||
unsigned int rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode); | |||
/** | |||
* Real size of rspamd cryptobox signing public key | |||
*/ | |||
guint rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode); | |||
unsigned int rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode); | |||
/** | |||
* Real size of crypto nonce | |||
*/ | |||
guint rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode); | |||
unsigned int rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode); | |||
/** | |||
* Real size of rspamd cryptobox secret key | |||
*/ | |||
guint rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode); | |||
unsigned int rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode); | |||
/** | |||
* Real size of rspamd cryptobox signing secret key | |||
*/ | |||
guint rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode); | |||
unsigned int rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode); | |||
/** | |||
* Real size of rspamd cryptobox shared key | |||
*/ | |||
guint rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode); | |||
unsigned int rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode); | |||
/** | |||
* Real size of rspamd cryptobox MAC signature | |||
*/ | |||
guint rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode); | |||
unsigned int rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode); | |||
/** | |||
* Real size of rspamd cryptobox digital signature | |||
*/ | |||
guint rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode); | |||
unsigned int rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode); | |||
/* Hash IUF interface */ | |||
typedef crypto_generichash_blake2b_state rspamd_cryptobox_hash_state_t; | |||
@@ -323,26 +323,26 @@ typedef crypto_generichash_blake2b_state rspamd_cryptobox_hash_state_t; | |||
* non-keyed hash is generated | |||
*/ | |||
void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *st, | |||
const guchar *key, gsize keylen); | |||
const unsigned char *key, gsize keylen); | |||
/** | |||
* Update hash with data portion | |||
*/ | |||
void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *st, | |||
const guchar *data, gsize len); | |||
const unsigned char *data, gsize len); | |||
/** | |||
* Output hash to the buffer of rspamd_cryptobox_HASHBYTES length | |||
*/ | |||
void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *st, guchar *out); | |||
void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *st, unsigned char *out); | |||
/** | |||
* One in all function | |||
*/ | |||
void rspamd_cryptobox_hash(guchar *out, | |||
const guchar *data, | |||
void rspamd_cryptobox_hash(unsigned char *out, | |||
const unsigned char *data, | |||
gsize len, | |||
const guchar *key, | |||
const unsigned char *key, | |||
gsize keylen); | |||
enum rspamd_cryptobox_fast_hash_type { | |||
@@ -357,7 +357,7 @@ enum rspamd_cryptobox_fast_hash_type { | |||
/* Non crypto hash IUF interface */ | |||
typedef struct CRYPTO_ALIGN(64) rspamd_cryptobox_fast_hash_state_s { | |||
guchar opaque[576]; /* Required for xxhash3 */ | |||
unsigned char opaque[576]; /* Required for xxhash3 */ | |||
enum rspamd_cryptobox_fast_hash_type type; | |||
} rspamd_cryptobox_fast_hash_state_t; | |||
@@ -375,7 +375,7 @@ void rspamd_cryptobox_fast_hash_free(rspamd_cryptobox_fast_hash_state_t *st); | |||
* non-keyed hash is generated | |||
*/ | |||
void rspamd_cryptobox_fast_hash_init(rspamd_cryptobox_fast_hash_state_t *st, | |||
guint64 seed); | |||
uint64_t seed); | |||
/** | |||
* Init cryptobox hash state using key if needed, `st` must point to the buffer | |||
@@ -384,7 +384,7 @@ void rspamd_cryptobox_fast_hash_init(rspamd_cryptobox_fast_hash_state_t *st, | |||
*/ | |||
void rspamd_cryptobox_fast_hash_init_specific(rspamd_cryptobox_fast_hash_state_t *st, | |||
enum rspamd_cryptobox_fast_hash_type type, | |||
guint64 seed); | |||
uint64_t seed); | |||
/** | |||
* Update hash with data portion | |||
@@ -395,21 +395,21 @@ void rspamd_cryptobox_fast_hash_update(rspamd_cryptobox_fast_hash_state_t *st, | |||
/** | |||
* Output hash to the buffer of rspamd_cryptobox_HASHBYTES length | |||
*/ | |||
guint64 rspamd_cryptobox_fast_hash_final(rspamd_cryptobox_fast_hash_state_t *st); | |||
uint64_t rspamd_cryptobox_fast_hash_final(rspamd_cryptobox_fast_hash_state_t *st); | |||
/** | |||
* One in all function | |||
*/ | |||
guint64 rspamd_cryptobox_fast_hash(const void *data, | |||
gsize len, guint64 seed); | |||
uint64_t rspamd_cryptobox_fast_hash(const void *data, | |||
gsize len, uint64_t seed); | |||
/** | |||
* Platform independent version | |||
*/ | |||
guint64 rspamd_cryptobox_fast_hash_specific( | |||
uint64_t rspamd_cryptobox_fast_hash_specific( | |||
enum rspamd_cryptobox_fast_hash_type type, | |||
const void *data, | |||
gsize len, guint64 seed); | |||
gsize len, uint64_t seed); | |||
/** | |||
* Decode base64 using platform optimized code | |||
@@ -419,8 +419,8 @@ guint64 rspamd_cryptobox_fast_hash_specific( | |||
* @param outlen | |||
* @return | |||
*/ | |||
gboolean rspamd_cryptobox_base64_decode(const gchar *in, gsize inlen, | |||
guchar *out, gsize *outlen); | |||
gboolean rspamd_cryptobox_base64_decode(const char *in, gsize inlen, | |||
unsigned char *out, gsize *outlen); | |||
/** | |||
* Returns TRUE if data looks like a valid base64 string | |||
@@ -428,7 +428,7 @@ gboolean rspamd_cryptobox_base64_decode(const gchar *in, gsize inlen, | |||
* @param inlen | |||
* @return | |||
*/ | |||
gboolean rspamd_cryptobox_base64_is_valid(const gchar *in, gsize inlen); | |||
gboolean rspamd_cryptobox_base64_is_valid(const char *in, gsize inlen); | |||
#ifdef __cplusplus | |||
} |
@@ -21,7 +21,7 @@ | |||
#include "libutil/printf.h" | |||
#include "contrib/libottery/ottery.h" | |||
const guchar encrypted_magic[7] = {'r', 'u', 'c', 'l', 'e', 'v', '1'}; | |||
const unsigned char encrypted_magic[7] = {'r', 'u', 'c', 'l', 'e', 'v', '1'}; | |||
static GQuark | |||
rspamd_keypair_quark(void) | |||
@@ -34,7 +34,7 @@ rspamd_keypair_quark(void) | |||
*/ | |||
static void * | |||
rspamd_cryptobox_keypair_sk(struct rspamd_cryptobox_keypair *kp, | |||
guint *len) | |||
unsigned int *len) | |||
{ | |||
g_assert(kp != NULL); | |||
@@ -65,7 +65,7 @@ rspamd_cryptobox_keypair_sk(struct rspamd_cryptobox_keypair *kp, | |||
static void * | |||
rspamd_cryptobox_keypair_pk(struct rspamd_cryptobox_keypair *kp, | |||
guint *len) | |||
unsigned int *len) | |||
{ | |||
g_assert(kp != NULL); | |||
@@ -96,7 +96,7 @@ rspamd_cryptobox_keypair_pk(struct rspamd_cryptobox_keypair *kp, | |||
static void * | |||
rspamd_cryptobox_pubkey_pk(const struct rspamd_cryptobox_pubkey *kp, | |||
guint *len) | |||
unsigned int *len) | |||
{ | |||
g_assert(kp != NULL); | |||
@@ -130,7 +130,7 @@ rspamd_cryptobox_keypair_alloc(enum rspamd_cryptobox_keypair_type type, | |||
enum rspamd_cryptobox_mode alg) | |||
{ | |||
struct rspamd_cryptobox_keypair *kp; | |||
guint size = 0; | |||
unsigned int size = 0; | |||
if (alg == RSPAMD_CRYPTOBOX_MODE_25519) { | |||
if (type == RSPAMD_KEYPAIR_KEX) { | |||
@@ -165,7 +165,7 @@ rspamd_cryptobox_pubkey_alloc(enum rspamd_cryptobox_keypair_type type, | |||
enum rspamd_cryptobox_mode alg) | |||
{ | |||
struct rspamd_cryptobox_pubkey *pk; | |||
guint size = 0; | |||
unsigned int size = 0; | |||
if (alg == RSPAMD_CRYPTOBOX_MODE_25519) { | |||
if (type == RSPAMD_KEYPAIR_KEX) { | |||
@@ -205,7 +205,7 @@ void rspamd_cryptobox_nm_dtor(struct rspamd_cryptobox_nm *nm) | |||
void rspamd_cryptobox_keypair_dtor(struct rspamd_cryptobox_keypair *kp) | |||
{ | |||
void *sk; | |||
guint len = 0; | |||
unsigned int len = 0; | |||
sk = rspamd_cryptobox_keypair_sk(kp, &len); | |||
g_assert(sk != NULL && len > 0); | |||
@@ -235,7 +235,7 @@ rspamd_keypair_new(enum rspamd_cryptobox_keypair_type type, | |||
{ | |||
struct rspamd_cryptobox_keypair *kp; | |||
void *pk, *sk; | |||
guint size; | |||
unsigned int size; | |||
kp = rspamd_cryptobox_keypair_alloc(type, alg); | |||
kp->alg = alg; | |||
@@ -319,16 +319,16 @@ rspamd_pubkey_alg(struct rspamd_cryptobox_pubkey *p) | |||
} | |||
struct rspamd_cryptobox_pubkey * | |||
rspamd_pubkey_from_base32(const gchar *b32, | |||
rspamd_pubkey_from_base32(const char *b32, | |||
gsize len, | |||
enum rspamd_cryptobox_keypair_type type, | |||
enum rspamd_cryptobox_mode alg) | |||
{ | |||
guchar *decoded; | |||
unsigned char *decoded; | |||
gsize dlen, expected_len; | |||
guint pklen; | |||
unsigned int pklen; | |||
struct rspamd_cryptobox_pubkey *pk; | |||
guchar *pk_data; | |||
unsigned char *pk_data; | |||
g_assert(b32 != NULL); | |||
@@ -363,16 +363,16 @@ rspamd_pubkey_from_base32(const gchar *b32, | |||
} | |||
struct rspamd_cryptobox_pubkey * | |||
rspamd_pubkey_from_hex(const gchar *hex, | |||
rspamd_pubkey_from_hex(const char *hex, | |||
gsize len, | |||
enum rspamd_cryptobox_keypair_type type, | |||
enum rspamd_cryptobox_mode alg) | |||
{ | |||
guchar *decoded; | |||
unsigned char *decoded; | |||
gsize dlen, expected_len; | |||
guint pklen; | |||
unsigned int pklen; | |||
struct rspamd_cryptobox_pubkey *pk; | |||
guchar *pk_data; | |||
unsigned char *pk_data; | |||
g_assert(hex != NULL); | |||
@@ -409,15 +409,15 @@ rspamd_pubkey_from_hex(const gchar *hex, | |||
} | |||
struct rspamd_cryptobox_pubkey * | |||
rspamd_pubkey_from_bin(const guchar *raw, | |||
rspamd_pubkey_from_bin(const unsigned char *raw, | |||
gsize len, | |||
enum rspamd_cryptobox_keypair_type type, | |||
enum rspamd_cryptobox_mode alg) | |||
{ | |||
gsize expected_len; | |||
guint pklen; | |||
unsigned int pklen; | |||
struct rspamd_cryptobox_pubkey *pk; | |||
guchar *pk_data; | |||
unsigned char *pk_data; | |||
g_assert(raw != NULL && len > 0); | |||
@@ -440,14 +440,14 @@ rspamd_pubkey_from_bin(const guchar *raw, | |||
} | |||
const guchar * | |||
const unsigned char * | |||
rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p, | |||
struct rspamd_cryptobox_keypair *kp) | |||
{ | |||
g_assert(p != NULL); | |||
if (p->nm) { | |||
if (memcmp(kp->id, (const guchar *) &p->nm->sk_id, sizeof(guint64)) == 0) { | |||
if (memcmp(kp->id, (const unsigned char *) &p->nm->sk_id, sizeof(uint64_t)) == 0) { | |||
return p->nm->nm; | |||
} | |||
@@ -459,7 +459,7 @@ rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p, | |||
return NULL; | |||
} | |||
const guchar * | |||
const unsigned char * | |||
rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p, | |||
struct rspamd_cryptobox_keypair *kp) | |||
{ | |||
@@ -472,7 +472,7 @@ rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p, | |||
abort(); | |||
} | |||
memcpy(&p->nm->sk_id, kp->id, sizeof(guint64)); | |||
memcpy(&p->nm->sk_id, kp->id, sizeof(uint64_t)); | |||
REF_INIT_RETAIN(p->nm, rspamd_cryptobox_nm_dtor); | |||
} | |||
@@ -496,7 +496,7 @@ rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p, | |||
return p->nm->nm; | |||
} | |||
const guchar * | |||
const unsigned char * | |||
rspamd_keypair_get_id(struct rspamd_cryptobox_keypair *kp) | |||
{ | |||
g_assert(kp != NULL); | |||
@@ -512,7 +512,7 @@ rspamd_keypair_get_extensions(struct rspamd_cryptobox_keypair *kp) | |||
return kp->extensions; | |||
} | |||
const guchar * | |||
const unsigned char * | |||
rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk) | |||
{ | |||
g_assert(pk != NULL); | |||
@@ -520,12 +520,12 @@ rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk) | |||
return pk->id; | |||
} | |||
const guchar * | |||
const unsigned char * | |||
rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk, | |||
guint *len) | |||
unsigned int *len) | |||
{ | |||
guchar *ret = NULL; | |||
guint rlen; | |||
unsigned char *ret = NULL; | |||
unsigned int rlen; | |||
ret = rspamd_cryptobox_pubkey_pk(pk, &rlen); | |||
@@ -537,10 +537,10 @@ rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk, | |||
} | |||
static void | |||
rspamd_keypair_print_component(guchar *data, gsize datalen, | |||
GString *res, guint how, const gchar *description) | |||
rspamd_keypair_print_component(unsigned char *data, gsize datalen, | |||
GString *res, unsigned int how, const char *description) | |||
{ | |||
gint olen, b32_len; | |||
int olen, b32_len; | |||
if (how & RSPAMD_KEYPAIR_HUMAN) { | |||
rspamd_printf_gstring(res, "%s: ", description); | |||
@@ -559,7 +559,7 @@ rspamd_keypair_print_component(guchar *data, gsize datalen, | |||
} | |||
} | |||
else if (how & RSPAMD_KEYPAIR_HEX) { | |||
rspamd_printf_gstring(res, "%*xs", (gint) datalen, data); | |||
rspamd_printf_gstring(res, "%*xs", (int) datalen, data); | |||
} | |||
else { | |||
g_string_append_len(res, data, datalen); | |||
@@ -571,10 +571,10 @@ rspamd_keypair_print_component(guchar *data, gsize datalen, | |||
} | |||
GString * | |||
rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, guint how) | |||
rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, unsigned int how) | |||
{ | |||
GString *res; | |||
guint len; | |||
unsigned int len; | |||
gpointer p; | |||
g_assert(kp != NULL); | |||
@@ -601,10 +601,10 @@ rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, guint how) | |||
} | |||
GString * | |||
rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, guint how) | |||
rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, unsigned int how) | |||
{ | |||
GString *res; | |||
guint len; | |||
unsigned int len; | |||
gpointer p; | |||
g_assert(pk != NULL); | |||
@@ -627,12 +627,12 @@ rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, guint how) | |||
return res; | |||
} | |||
const guchar * | |||
const unsigned char * | |||
rspamd_keypair_component(struct rspamd_cryptobox_keypair *kp, | |||
guint ncomp, guint *len) | |||
unsigned int ncomp, unsigned int *len) | |||
{ | |||
guint rlen = 0; | |||
const guchar *ret = NULL; | |||
unsigned int rlen = 0; | |||
const unsigned char *ret = NULL; | |||
g_assert(kp != NULL); | |||
@@ -660,14 +660,14 @@ struct rspamd_cryptobox_keypair * | |||
rspamd_keypair_from_ucl(const ucl_object_t *obj) | |||
{ | |||
const ucl_object_t *privkey, *pubkey, *elt; | |||
const gchar *str; | |||
const char *str; | |||
enum rspamd_cryptobox_keypair_type type = RSPAMD_KEYPAIR_KEX; | |||
enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519; | |||
gboolean is_hex = FALSE; | |||
struct rspamd_cryptobox_keypair *kp; | |||
guint len; | |||
unsigned int len; | |||
gsize ucl_len; | |||
gint dec_len; | |||
int dec_len; | |||
gpointer target; | |||
if (ucl_object_type(obj) != UCL_OBJECT) { | |||
@@ -744,7 +744,7 @@ rspamd_keypair_from_ucl(const ucl_object_t *obj) | |||
dec_len = rspamd_decode_base32_buf(str, ucl_len, target, len, RSPAMD_BASE32_DEFAULT); | |||
} | |||
if (dec_len != (gint) len) { | |||
if (dec_len != (int) len) { | |||
rspamd_keypair_unref(kp); | |||
return NULL; | |||
@@ -760,7 +760,7 @@ rspamd_keypair_from_ucl(const ucl_object_t *obj) | |||
dec_len = rspamd_decode_base32_buf(str, ucl_len, target, len, RSPAMD_BASE32_DEFAULT); | |||
} | |||
if (dec_len != (gint) len) { | |||
if (dec_len != (int) len) { | |||
rspamd_keypair_unref(kp); | |||
return NULL; | |||
@@ -782,9 +782,9 @@ rspamd_keypair_to_ucl(struct rspamd_cryptobox_keypair *kp, | |||
enum rspamd_keypair_dump_flags flags) | |||
{ | |||
ucl_object_t *ucl_out, *elt; | |||
gint how = 0; | |||
int how = 0; | |||
GString *keypair_out; | |||
const gchar *encoding; | |||
const char *encoding; | |||
g_assert(kp != NULL); | |||
@@ -857,11 +857,11 @@ rspamd_keypair_to_ucl(struct rspamd_cryptobox_keypair *kp, | |||
gboolean | |||
rspamd_keypair_decrypt(struct rspamd_cryptobox_keypair *kp, | |||
const guchar *in, gsize inlen, | |||
guchar **out, gsize *outlen, | |||
const unsigned char *in, gsize inlen, | |||
unsigned char **out, gsize *outlen, | |||
GError **err) | |||
{ | |||
const guchar *nonce, *mac, *data, *pubkey; | |||
const unsigned char *nonce, *mac, *data, *pubkey; | |||
g_assert(kp != NULL); | |||
g_assert(in != NULL); | |||
@@ -924,11 +924,11 @@ rspamd_keypair_decrypt(struct rspamd_cryptobox_keypair *kp, | |||
gboolean | |||
rspamd_keypair_encrypt(struct rspamd_cryptobox_keypair *kp, | |||
const guchar *in, gsize inlen, | |||
guchar **out, gsize *outlen, | |||
const unsigned char *in, gsize inlen, | |||
unsigned char **out, gsize *outlen, | |||
GError **err) | |||
{ | |||
guchar *nonce, *mac, *data, *pubkey; | |||
unsigned char *nonce, *mac, *data, *pubkey; | |||
struct rspamd_cryptobox_keypair *local; | |||
gsize olen; | |||
@@ -973,11 +973,11 @@ rspamd_keypair_encrypt(struct rspamd_cryptobox_keypair *kp, | |||
gboolean | |||
rspamd_pubkey_encrypt(struct rspamd_cryptobox_pubkey *pk, | |||
const guchar *in, gsize inlen, | |||
guchar **out, gsize *outlen, | |||
const unsigned char *in, gsize inlen, | |||
unsigned char **out, gsize *outlen, | |||
GError **err) | |||
{ | |||
guchar *nonce, *mac, *data, *pubkey; | |||
unsigned char *nonce, *mac, *data, *pubkey; | |||
struct rspamd_cryptobox_keypair *local; | |||
gsize olen; | |||
@@ -32,7 +32,7 @@ enum rspamd_cryptobox_keypair_type { | |||
RSPAMD_KEYPAIR_SIGN | |||
}; | |||
extern const guchar encrypted_magic[7]; | |||
extern const unsigned char encrypted_magic[7]; | |||
/** | |||
* Opaque structure for the full (public + private) keypair | |||
@@ -82,7 +82,7 @@ struct rspamd_cryptobox_pubkey *rspamd_pubkey_ref( | |||
* @param alg algorithm of the key (nist or curve25519) | |||
* @return new pubkey or NULL in case of error | |||
*/ | |||
struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_base32(const gchar *b32, | |||
struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_base32(const char *b32, | |||
gsize len, | |||
enum rspamd_cryptobox_keypair_type type, | |||
enum rspamd_cryptobox_mode alg); | |||
@@ -94,7 +94,7 @@ struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_base32(const gchar *b32, | |||
* @param alg algorithm of the key (nist or curve25519) | |||
* @return new pubkey or NULL in case of error | |||
*/ | |||
struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_hex(const gchar *hex, | |||
struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_hex(const char *hex, | |||
gsize len, | |||
enum rspamd_cryptobox_keypair_type type, | |||
enum rspamd_cryptobox_mode alg); | |||
@@ -106,7 +106,7 @@ struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_hex(const gchar *hex, | |||
* @param alg algorithm of the key (nist or curve25519) | |||
* @return new pubkey or NULL in case of error | |||
*/ | |||
struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_bin(const guchar *raw, | |||
struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_bin(const unsigned char *raw, | |||
gsize len, | |||
enum rspamd_cryptobox_keypair_type type, | |||
enum rspamd_cryptobox_mode alg); | |||
@@ -145,23 +145,23 @@ enum rspamd_cryptobox_mode rspamd_pubkey_alg(struct rspamd_cryptobox_pubkey *p); | |||
* @param p | |||
* @return | |||
*/ | |||
const guchar *rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p, | |||
struct rspamd_cryptobox_keypair *kp); | |||
const unsigned char *rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p, | |||
struct rspamd_cryptobox_keypair *kp); | |||
/** | |||
* Calculate and store nm value for the specified local key (performs ECDH) | |||
* @param p | |||
* @return | |||
*/ | |||
const guchar *rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p, | |||
struct rspamd_cryptobox_keypair *kp); | |||
const unsigned char *rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p, | |||
struct rspamd_cryptobox_keypair *kp); | |||
/** | |||
* Get raw public key id for a specified keypair (rspamd_cryptobox_HASHBYTES) | |||
* @param kp | |||
* @return | |||
*/ | |||
const guchar *rspamd_keypair_get_id(struct rspamd_cryptobox_keypair *kp); | |||
const unsigned char *rspamd_keypair_get_id(struct rspamd_cryptobox_keypair *kp); | |||
/** | |||
* Returns keypair extensions if any | |||
@@ -175,7 +175,7 @@ const ucl_object_t *rspamd_keypair_get_extensions(struct rspamd_cryptobox_keypai | |||
* @param kp | |||
* @return | |||
*/ | |||
const guchar *rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk); | |||
const unsigned char *rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk); | |||
/** | |||
* Get raw public key from pubkey opaque structure | |||
@@ -183,8 +183,8 @@ const guchar *rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk); | |||
* @param len | |||
* @return | |||
*/ | |||
const guchar *rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk, | |||
guint *len); | |||
const unsigned char *rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk, | |||
unsigned int *len); | |||
/** Short ID characters count */ | |||
#define RSPAMD_KEYPAIR_SHORT_ID_LEN 5 | |||
@@ -209,7 +209,7 @@ const guchar *rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk, | |||
* @return newly allocated string with keypair | |||
*/ | |||
GString *rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, | |||
guint how); | |||
unsigned int how); | |||
/** | |||
* Print pubkey encoding it if needed | |||
@@ -218,7 +218,7 @@ GString *rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, | |||
* @return newly allocated string with keypair | |||
*/ | |||
GString *rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, | |||
guint how); | |||
unsigned int how); | |||
/** Get keypair pubkey ID */ | |||
#define RSPAMD_KEYPAIR_COMPONENT_ID 0 | |||
@@ -234,8 +234,8 @@ GString *rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, | |||
* @param len length of input | |||
* @return raw content of the component | |||
*/ | |||
const guchar *rspamd_keypair_component(struct rspamd_cryptobox_keypair *kp, | |||
guint ncomp, guint *len); | |||
const unsigned char *rspamd_keypair_component(struct rspamd_cryptobox_keypair *kp, | |||
unsigned int ncomp, unsigned int *len); | |||
/** | |||
* Create a new keypair from ucl object | |||
@@ -272,8 +272,8 @@ ucl_object_t *rspamd_keypair_to_ucl(struct rspamd_cryptobox_keypair *kp, | |||
* @return TRUE if decryption is completed, out must be freed in this case | |||
*/ | |||
gboolean rspamd_keypair_decrypt(struct rspamd_cryptobox_keypair *kp, | |||
const guchar *in, gsize inlen, | |||
guchar **out, gsize *outlen, | |||
const unsigned char *in, gsize inlen, | |||
unsigned char **out, gsize *outlen, | |||
GError **err); | |||
/** | |||
@@ -289,8 +289,8 @@ gboolean rspamd_keypair_decrypt(struct rspamd_cryptobox_keypair *kp, | |||
* @return TRUE if encryption has been completed, out must be freed in this case | |||
*/ | |||
gboolean rspamd_keypair_encrypt(struct rspamd_cryptobox_keypair *kp, | |||
const guchar *in, gsize inlen, | |||
guchar **out, gsize *outlen, | |||
const unsigned char *in, gsize inlen, | |||
unsigned char **out, gsize *outlen, | |||
GError **err); | |||
/** | |||
@@ -306,8 +306,8 @@ gboolean rspamd_keypair_encrypt(struct rspamd_cryptobox_keypair *kp, | |||
* @return TRUE if encryption has been completed, out must be freed in this case | |||
*/ | |||
gboolean rspamd_pubkey_encrypt(struct rspamd_cryptobox_pubkey *pk, | |||
const guchar *in, gsize inlen, | |||
guchar **out, gsize *outlen, | |||
const unsigned char *in, gsize inlen, | |||
unsigned char **out, gsize *outlen, | |||
GError **err); | |||
#ifdef __cplusplus |
@@ -27,8 +27,8 @@ extern "C" { | |||
* KEX cached data | |||
*/ | |||
struct rspamd_cryptobox_nm { | |||
guchar nm[rspamd_cryptobox_MAX_NMBYTES]; | |||
guint64 sk_id; /* Used to store secret key id */ | |||
unsigned char nm[rspamd_cryptobox_MAX_NMBYTES]; | |||
uint64_t sk_id; /* Used to store secret key id */ | |||
ref_entry_t ref; | |||
}; | |||
@@ -36,7 +36,7 @@ struct rspamd_cryptobox_nm { | |||
* Generic keypair | |||
*/ | |||
struct rspamd_cryptobox_keypair { | |||
guchar id[rspamd_cryptobox_HASHBYTES]; | |||
unsigned char id[rspamd_cryptobox_HASHBYTES]; | |||
enum rspamd_cryptobox_keypair_type type; | |||
enum rspamd_cryptobox_mode alg; | |||
ucl_object_t *extensions; | |||
@@ -49,8 +49,8 @@ struct rspamd_cryptobox_keypair { | |||
#define RSPAMD_CRYPTOBOX_KEYPAIR_NIST(x) ((struct rspamd_cryptobox_keypair_nist *) (x)) | |||
struct rspamd_cryptobox_keypair_nist { | |||
struct rspamd_cryptobox_keypair parent; | |||
guchar sk[32]; | |||
guchar pk[65]; | |||
unsigned char sk[32]; | |||
unsigned char pk[65]; | |||
}; | |||
/* | |||
@@ -59,8 +59,8 @@ struct rspamd_cryptobox_keypair_nist { | |||
#define RSPAMD_CRYPTOBOX_KEYPAIR_25519(x) ((struct rspamd_cryptobox_keypair_25519 *) (x)) | |||
struct rspamd_cryptobox_keypair_25519 { | |||
struct rspamd_cryptobox_keypair parent; | |||
guchar sk[32]; | |||
guchar pk[32]; | |||
unsigned char sk[32]; | |||
unsigned char pk[32]; | |||
}; | |||
/* | |||
@@ -69,8 +69,8 @@ struct rspamd_cryptobox_keypair_25519 { | |||
#define RSPAMD_CRYPTOBOX_KEYPAIR_SIG_NIST(x) ((struct rspamd_cryptobox_keypair_sig_nist *) (x)) | |||
struct rspamd_cryptobox_keypair_sig_nist { | |||
struct rspamd_cryptobox_keypair parent; | |||
guchar sk[32]; | |||
guchar pk[65]; | |||
unsigned char sk[32]; | |||
unsigned char pk[65]; | |||
}; | |||
/* | |||
@@ -79,15 +79,15 @@ struct rspamd_cryptobox_keypair_sig_nist { | |||
#define RSPAMD_CRYPTOBOX_KEYPAIR_SIG_25519(x) ((struct rspamd_cryptobox_keypair_sig_25519 *) (x)) | |||
struct rspamd_cryptobox_keypair_sig_25519 { | |||
struct rspamd_cryptobox_keypair parent; | |||
guchar sk[64]; | |||
guchar pk[32]; | |||
unsigned char sk[64]; | |||
unsigned char pk[32]; | |||
}; | |||
/* | |||
* Public component of the keypair | |||
*/ | |||
struct rspamd_cryptobox_pubkey { | |||
guchar id[rspamd_cryptobox_HASHBYTES]; | |||
unsigned char id[rspamd_cryptobox_HASHBYTES]; | |||
struct rspamd_cryptobox_nm *nm; | |||
enum rspamd_cryptobox_keypair_type type; | |||
enum rspamd_cryptobox_mode alg; | |||
@@ -100,7 +100,7 @@ struct rspamd_cryptobox_pubkey { | |||
#define RSPAMD_CRYPTOBOX_PUBKEY_NIST(x) ((struct rspamd_cryptobox_pubkey_nist *) (x)) | |||
struct rspamd_cryptobox_pubkey_nist { | |||
struct rspamd_cryptobox_pubkey parent; | |||
guchar pk[65]; | |||
unsigned char pk[65]; | |||
}; | |||
/* | |||
@@ -109,7 +109,7 @@ struct rspamd_cryptobox_pubkey_nist { | |||
#define RSPAMD_CRYPTOBOX_PUBKEY_25519(x) ((struct rspamd_cryptobox_pubkey_25519 *) (x)) | |||
struct rspamd_cryptobox_pubkey_25519 { | |||
struct rspamd_cryptobox_pubkey parent; | |||
guchar pk[32]; | |||
unsigned char pk[32]; | |||
}; | |||
/* | |||
@@ -118,7 +118,7 @@ struct rspamd_cryptobox_pubkey_25519 { | |||
#define RSPAMD_CRYPTOBOX_PUBKEY_SIG_NIST(x) ((struct rspamd_cryptobox_pubkey_sig_nist *) (x)) | |||
struct rspamd_cryptobox_pubkey_sig_nist { | |||
struct rspamd_cryptobox_pubkey parent; | |||
guchar pk[65]; | |||
unsigned char pk[65]; | |||
}; | |||
/* | |||
@@ -127,7 +127,7 @@ struct rspamd_cryptobox_pubkey_sig_nist { | |||
#define RSPAMD_CRYPTOBOX_PUBKEY_SIG_25519(x) ((struct rspamd_cryptobox_pubkey_sig_25519 *) (x)) | |||
struct rspamd_cryptobox_pubkey_sig_25519 { | |||
struct rspamd_cryptobox_pubkey parent; | |||
guchar pk[32]; | |||
unsigned char pk[32]; | |||
}; | |||
void rspamd_cryptobox_nm_dtor(struct rspamd_cryptobox_nm *nm); |
@@ -21,7 +21,7 @@ | |||
struct rspamd_keypair_elt { | |||
struct rspamd_cryptobox_nm *nm; | |||
guchar pair[rspamd_cryptobox_HASHBYTES * 2]; | |||
unsigned char pair[rspamd_cryptobox_HASHBYTES * 2]; | |||
}; | |||
struct rspamd_keypair_cache { | |||
@@ -37,7 +37,7 @@ rspamd_keypair_destroy(gpointer ptr) | |||
g_free(elt); | |||
} | |||
static guint | |||
static unsigned int | |||
rspamd_keypair_hash(gconstpointer ptr) | |||
{ | |||
struct rspamd_keypair_elt *elt = (struct rspamd_keypair_elt *) ptr; | |||
@@ -56,7 +56,7 @@ rspamd_keypair_equal(gconstpointer p1, gconstpointer p2) | |||
} | |||
struct rspamd_keypair_cache * | |||
rspamd_keypair_cache_new(guint max_items) | |||
rspamd_keypair_cache_new(unsigned int max_items) | |||
{ | |||
struct rspamd_keypair_cache *c; | |||
@@ -104,7 +104,7 @@ void rspamd_keypair_cache_process(struct rspamd_keypair_cache *c, | |||
memcpy(new->pair, rk->id, rspamd_cryptobox_HASHBYTES); | |||
memcpy(&new->pair[rspamd_cryptobox_HASHBYTES], lk->id, | |||
rspamd_cryptobox_HASHBYTES); | |||
memcpy(&new->nm->sk_id, lk->id, sizeof(guint64)); | |||
memcpy(&new->nm->sk_id, lk->id, sizeof(uint64_t)); | |||
if (rk->alg == RSPAMD_CRYPTOBOX_MODE_25519) { | |||
struct rspamd_cryptobox_pubkey_25519 *rk_25519 = |
@@ -31,7 +31,7 @@ struct rspamd_keypair_cache; | |||
* @param max_items defines maximum count of elements in the cache | |||
* @return new cache | |||
*/ | |||
struct rspamd_keypair_cache *rspamd_keypair_cache_new(guint max_items); | |||
struct rspamd_keypair_cache *rspamd_keypair_cache_new(unsigned int max_items); | |||
/** |
@@ -39,7 +39,7 @@ rspamd_archive_dtor(gpointer p) | |||
{ | |||
struct rspamd_archive *arch = p; | |||
struct rspamd_archive_file *f; | |||
guint i; | |||
unsigned int i; | |||
for (i = 0; i < arch->files->len; i++) { | |||
f = g_ptr_array_index(arch->files, i); | |||
@@ -58,9 +58,9 @@ static bool | |||
rspamd_archive_file_try_utf(struct rspamd_task *task, | |||
struct rspamd_archive *arch, | |||
struct rspamd_archive_file *fentry, | |||
const gchar *in, gsize inlen) | |||
const char *in, gsize inlen) | |||
{ | |||
const gchar *charset = NULL, *p, *end; | |||
const char *charset = NULL, *p, *end; | |||
GString *res; | |||
charset = rspamd_mime_charset_find_by_content(in, inlen, TRUE); | |||
@@ -68,7 +68,7 @@ rspamd_archive_file_try_utf(struct rspamd_task *task, | |||
if (charset) { | |||
UChar *tmp; | |||
UErrorCode uc_err = U_ZERO_ERROR; | |||
gint32 r, clen, dlen; | |||
int32_t r, clen, dlen; | |||
struct rspamd_charset_converter *conv; | |||
UConverter *utf8_converter; | |||
@@ -173,12 +173,12 @@ static void | |||
rspamd_archive_process_zip(struct rspamd_task *task, | |||
struct rspamd_mime_part *part) | |||
{ | |||
const guchar *p, *start, *end, *eocd = NULL, *cd; | |||
const guint32 eocd_magic = 0x06054b50, cd_basic_len = 46; | |||
const guchar cd_magic[] = {0x50, 0x4b, 0x01, 0x02}; | |||
const guint max_processed = 1024; | |||
guint32 cd_offset, cd_size, comp_size, uncomp_size, processed = 0; | |||
guint16 extra_len, fname_len, comment_len; | |||
const unsigned char *p, *start, *end, *eocd = NULL, *cd; | |||
const uint32_t eocd_magic = 0x06054b50, cd_basic_len = 46; | |||
const unsigned char cd_magic[] = {0x50, 0x4b, 0x01, 0x02}; | |||
const unsigned int max_processed = 1024; | |||
uint32_t cd_offset, cd_size, comp_size, uncomp_size, processed = 0; | |||
uint16_t extra_len, fname_len, comment_len; | |||
struct rspamd_archive *arch; | |||
struct rspamd_archive_file *f = NULL; | |||
@@ -193,8 +193,8 @@ rspamd_archive_process_zip(struct rspamd_task *task, | |||
*/ | |||
p -= 21; | |||
while (p > start + sizeof(guint32)) { | |||
guint32 t; | |||
while (p > start + sizeof(uint32_t)) { | |||
uint32_t t; | |||
if (processed > max_processed) { | |||
break; | |||
@@ -233,7 +233,7 @@ rspamd_archive_process_zip(struct rspamd_task *task, | |||
cd_offset = GUINT32_FROM_LE(cd_offset); | |||
/* We need to check sanity as well */ | |||
if (cd_offset + cd_size > (guint) (eocd - start)) { | |||
if (cd_offset + cd_size > (unsigned int) (eocd - start)) { | |||
msg_info_task("zip archive is invalid (bad size/offset for CD)"); | |||
return; | |||
@@ -251,7 +251,7 @@ rspamd_archive_process_zip(struct rspamd_task *task, | |||
arch); | |||
while (cd < start + cd_offset + cd_size) { | |||
guint16 flags; | |||
uint16_t flags; | |||
/* Read central directory record */ | |||
if (eocd - cd < cd_basic_len || | |||
@@ -261,11 +261,11 @@ rspamd_archive_process_zip(struct rspamd_task *task, | |||
return; | |||
} | |||
memcpy(&flags, cd + 8, sizeof(guint16)); | |||
memcpy(&flags, cd + 8, sizeof(uint16_t)); | |||
flags = GUINT16_FROM_LE(flags); | |||
memcpy(&comp_size, cd + 20, sizeof(guint32)); | |||
memcpy(&comp_size, cd + 20, sizeof(uint32_t)); | |||
comp_size = GUINT32_FROM_LE(comp_size); | |||
memcpy(&uncomp_size, cd + 24, sizeof(guint32)); | |||
memcpy(&uncomp_size, cd + 24, sizeof(uint32_t)); | |||
uncomp_size = GUINT32_FROM_LE(uncomp_size); | |||
memcpy(&fname_len, cd + 28, sizeof(fname_len)); | |||
fname_len = GUINT16_FROM_LE(fname_len); | |||
@@ -305,22 +305,22 @@ rspamd_archive_process_zip(struct rspamd_task *task, | |||
} | |||
/* Process extra fields */ | |||
const guchar *extra = cd + fname_len + cd_basic_len; | |||
const unsigned char *extra = cd + fname_len + cd_basic_len; | |||
p = extra; | |||
while (p + sizeof(guint16) * 2 < extra + extra_len) { | |||
guint16 hid, hlen; | |||
while (p + sizeof(uint16_t) * 2 < extra + extra_len) { | |||
uint16_t hid, hlen; | |||
memcpy(&hid, p, sizeof(guint16)); | |||
memcpy(&hid, p, sizeof(uint16_t)); | |||
hid = GUINT16_FROM_LE(hid); | |||
memcpy(&hlen, p + sizeof(guint16), sizeof(guint16)); | |||
memcpy(&hlen, p + sizeof(uint16_t), sizeof(uint16_t)); | |||
hlen = GUINT16_FROM_LE(hlen); | |||
if (hid == 0x0017) { | |||
f->flags |= RSPAMD_ARCHIVE_FILE_ENCRYPTED; | |||
} | |||
p += hlen + sizeof(guint16) * 2; | |||
p += hlen + sizeof(uint16_t) * 2; | |||
} | |||
cd += fname_len + comment_len + extra_len + cd_basic_len; | |||
@@ -332,8 +332,8 @@ rspamd_archive_process_zip(struct rspamd_task *task, | |||
arch->size = part->parsed_data.len; | |||
} | |||
static inline gint | |||
rspamd_archive_rar_read_vint(const guchar *start, gsize remain, guint64 *res) | |||
static inline int | |||
rspamd_archive_rar_read_vint(const unsigned char *start, gsize remain, uint64_t *res) | |||
{ | |||
/* | |||
* From http://www.rarlab.com/technote.htm: | |||
@@ -344,16 +344,16 @@ rspamd_archive_rar_read_vint(const guchar *start, gsize remain, guint64 *res) | |||
* So first byte contains 7 least significant bits of integer and | |||
* continuation flag. Second byte, if present, contains next 7 bits and so on. | |||
*/ | |||
guint64 t = 0; | |||
guint shift = 0; | |||
const guchar *p = start; | |||
uint64_t t = 0; | |||
unsigned int shift = 0; | |||
const unsigned char *p = start; | |||
while (remain > 0 && shift <= 57) { | |||
if (*p & 0x80) { | |||
t |= ((guint64) (*p & 0x7f)) << shift; | |||
t |= ((uint64_t) (*p & 0x7f)) << shift; | |||
} | |||
else { | |||
t |= ((guint64) (*p & 0x7f)) << shift; | |||
t |= ((uint64_t) (*p & 0x7f)) << shift; | |||
p++; | |||
break; | |||
} | |||
@@ -410,32 +410,32 @@ rspamd_archive_rar_read_vint(const guchar *start, gsize remain, guint64 *res) | |||
#define RAR_READ_UINT16(n) \ | |||
do { \ | |||
if (end - p < (glong) sizeof(guint16)) { \ | |||
if (end - p < (glong) sizeof(uint16_t)) { \ | |||
msg_debug_archive("rar archive is invalid (bad int16)"); \ | |||
return; \ | |||
} \ | |||
n = p[0] + (p[1] << 8); \ | |||
p += sizeof(guint16); \ | |||
p += sizeof(uint16_t); \ | |||
} while (0) | |||
#define RAR_READ_UINT32(n) \ | |||
do { \ | |||
if (end - p < (glong) sizeof(guint32)) { \ | |||
msg_debug_archive("rar archive is invalid (bad int32)"); \ | |||
return; \ | |||
} \ | |||
n = (guint) p[0] + ((guint) p[1] << 8) + ((guint) p[2] << 16) + ((guint) p[3] << 24); \ | |||
p += sizeof(guint32); \ | |||
#define RAR_READ_UINT32(n) \ | |||
do { \ | |||
if (end - p < (glong) sizeof(uint32_t)) { \ | |||
msg_debug_archive("rar archive is invalid (bad int32)"); \ | |||
return; \ | |||
} \ | |||
n = (unsigned int) p[0] + ((unsigned int) p[1] << 8) + ((unsigned int) p[2] << 16) + ((unsigned int) p[3] << 24); \ | |||
p += sizeof(uint32_t); \ | |||
} while (0) | |||
static void | |||
rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, | |||
const guchar *end, struct rspamd_mime_part *part) | |||
rspamd_archive_process_rar_v4(struct rspamd_task *task, const unsigned char *start, | |||
const unsigned char *end, struct rspamd_mime_part *part) | |||
{ | |||
const guchar *p = start, *start_section; | |||
guint8 type; | |||
guint flags; | |||
guint64 sz, comp_sz = 0, uncomp_sz = 0; | |||
const unsigned char *p = start, *start_section; | |||
uint8_t type; | |||
unsigned int flags; | |||
uint64_t sz, comp_sz = 0, uncomp_sz = 0; | |||
struct rspamd_archive *arch; | |||
struct rspamd_archive_file *f; | |||
@@ -451,7 +451,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, | |||
while (p < end) { | |||
/* Crc16 */ | |||
start_section = p; | |||
RAR_SKIP_BYTES(sizeof(guint16)); | |||
RAR_SKIP_BYTES(sizeof(uint16_t)); | |||
type = *p; | |||
p++; | |||
RAR_READ_UINT16(flags); | |||
@@ -468,7 +468,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, | |||
if (flags & 0x8000) { | |||
/* We also need to read ADD_SIZE element */ | |||
guint32 tmp; | |||
uint32_t tmp; | |||
RAR_READ_UINT32(tmp); | |||
sz += tmp; | |||
@@ -484,7 +484,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, | |||
} | |||
if (type == 0x74) { | |||
guint fname_len; | |||
unsigned int fname_len; | |||
/* File header */ | |||
/* Uncompressed size */ | |||
@@ -505,7 +505,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, | |||
if (flags & 0x100) { | |||
/* We also need to read HIGH_PACK_SIZE */ | |||
guint32 tmp; | |||
uint32_t tmp; | |||
RAR_READ_UINT32(tmp); | |||
sz += tmp; | |||
@@ -519,7 +519,7 @@ rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start, | |||
if (flags & 0x200) { | |||
/* We have unicode + normal version */ | |||
guchar *tmp; | |||
unsigned char *tmp; | |||
tmp = memchr(p, '\0', fname_len); | |||
@@ -574,16 +574,16 @@ static void | |||
rspamd_archive_process_rar(struct rspamd_task *task, | |||
struct rspamd_mime_part *part) | |||
{ | |||
const guchar *p, *end, *section_start; | |||
const guchar rar_v5_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00}, | |||
rar_v4_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00}; | |||
const guint rar_encrypted_header = 4, rar_main_header = 1, | |||
rar_file_header = 2; | |||
guint64 vint, sz, comp_sz = 0, uncomp_sz = 0, flags = 0, type = 0, | |||
extra_sz = 0; | |||
const unsigned char *p, *end, *section_start; | |||
const unsigned char rar_v5_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00}, | |||
rar_v4_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00}; | |||
const unsigned int rar_encrypted_header = 4, rar_main_header = 1, | |||
rar_file_header = 2; | |||
uint64_t vint, sz, comp_sz = 0, uncomp_sz = 0, flags = 0, type = 0, | |||
extra_sz = 0; | |||
struct rspamd_archive *arch; | |||
struct rspamd_archive_file *f; | |||
gint r; | |||
int r; | |||
p = part->parsed_data.begin; | |||
end = p + part->parsed_data.len; | |||
@@ -621,7 +621,7 @@ rspamd_archive_process_rar(struct rspamd_task *task, | |||
/* Now we can have either encryption header or archive header */ | |||
/* Crc 32 */ | |||
RAR_SKIP_BYTES(sizeof(guint32)); | |||
RAR_SKIP_BYTES(sizeof(uint32_t)); | |||
/* Size */ | |||
RAR_READ_VINT_SKIP(); | |||
sz = vint; | |||
@@ -662,7 +662,7 @@ rspamd_archive_process_rar(struct rspamd_task *task, | |||
gboolean has_extra = FALSE; | |||
/* Read the next header */ | |||
/* Crc 32 */ | |||
RAR_SKIP_BYTES(sizeof(guint32)); | |||
RAR_SKIP_BYTES(sizeof(uint32_t)); | |||
/* Size */ | |||
RAR_READ_VINT_SKIP(); | |||
@@ -702,7 +702,7 @@ rspamd_archive_process_rar(struct rspamd_task *task, | |||
} | |||
else { | |||
/* We have a file header, go forward */ | |||
guint64 fname_len; | |||
uint64_t fname_len; | |||
bool is_directory = false; | |||
/* File header specific flags */ | |||
@@ -717,11 +717,11 @@ rspamd_archive_process_rar(struct rspamd_task *task, | |||
if (flags & 0x2) { | |||
/* Unix mtime */ | |||
RAR_SKIP_BYTES(sizeof(guint32)); | |||
RAR_SKIP_BYTES(sizeof(uint32_t)); | |||
} | |||
if (flags & 0x4) { | |||
/* Crc32 */ | |||
RAR_SKIP_BYTES(sizeof(guint32)); | |||
RAR_SKIP_BYTES(sizeof(uint32_t)); | |||
} | |||
if (flags & 0x1) { | |||
/* Ignore directories for sanity purposes */ | |||
@@ -764,11 +764,11 @@ rspamd_archive_process_rar(struct rspamd_task *task, | |||
if (f && has_extra && extra_sz > 0 && | |||
p + fname_len + extra_sz < end) { | |||
/* Try to find encryption record in extra field */ | |||
const guchar *ex = p + fname_len; | |||
const unsigned char *ex = p + fname_len; | |||
while (ex < p + extra_sz) { | |||
const guchar *t; | |||
gint64 cur_sz = 0, sec_type = 0; | |||
const unsigned char *t; | |||
int64_t cur_sz = 0, sec_type = 0; | |||
r = rspamd_archive_rar_read_vint(ex, extra_sz, &cur_sz); | |||
if (r == -1) { | |||
@@ -807,8 +807,8 @@ end: | |||
arch->size = part->parsed_data.len; | |||
} | |||
static inline gint | |||
rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, guint64 *res) | |||
static inline int | |||
rspamd_archive_7zip_read_vint(const unsigned char *start, gsize remain, uint64_t *res) | |||
{ | |||
/* | |||
* REAL_UINT64 means real UINT64. | |||
@@ -825,7 +825,7 @@ rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, guint64 *res) | |||
* 11111110 BYTE y[7] : y | |||
* 11111111 BYTE y[8] : y | |||
*/ | |||
guchar t; | |||
unsigned char t; | |||
if (remain == 0) { | |||
return -1; | |||
@@ -839,17 +839,17 @@ rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, guint64 *res) | |||
return 1; | |||
} | |||
else if (t == 0xFF) { | |||
if (remain >= sizeof(guint64) + 1) { | |||
memcpy(res, start + 1, sizeof(guint64)); | |||
if (remain >= sizeof(uint64_t) + 1) { | |||
memcpy(res, start + 1, sizeof(uint64_t)); | |||
*res = GUINT64_FROM_LE(*res); | |||
return sizeof(guint64) + 1; | |||
return sizeof(uint64_t) + 1; | |||
} | |||
} | |||
else { | |||
gint cur_bit = 6, intlen = 1; | |||
const guchar bmask = 0xFF; | |||
guint64 tgt; | |||
int cur_bit = 6, intlen = 1; | |||
const unsigned char bmask = 0xFF; | |||
uint64_t tgt; | |||
while (cur_bit > 0) { | |||
if (!isset(&t, cur_bit)) { | |||
@@ -859,7 +859,7 @@ rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, guint64 *res) | |||
/* Shift back */ | |||
tgt >>= sizeof(tgt) - NBBY * intlen; | |||
/* Add masked value */ | |||
tgt += (guint64) (t & (bmask >> (NBBY - cur_bit))) | |||
tgt += (uint64_t) (t & (bmask >> (NBBY - cur_bit))) | |||
<< (NBBY * intlen); | |||
*res = tgt; | |||
@@ -896,23 +896,23 @@ rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, guint64 *res) | |||
#define SZ_READ_UINT64(n) \ | |||
do { \ | |||
if (end - p < (goffset) sizeof(guint64)) { \ | |||
if (end - p < (goffset) sizeof(uint64_t)) { \ | |||
msg_debug_archive("7zip archive is invalid (bad uint64): %s", G_STRLOC); \ | |||
return; \ | |||
} \ | |||
memcpy(&(n), p, sizeof(guint64)); \ | |||
memcpy(&(n), p, sizeof(uint64_t)); \ | |||
n = GUINT64_FROM_LE(n); \ | |||
p += sizeof(guint64); \ | |||
p += sizeof(uint64_t); \ | |||
} while (0) | |||
#define SZ_SKIP_BYTES(n) \ | |||
do { \ | |||
if (end - p >= (n)) { \ | |||
p += (n); \ | |||
} \ | |||
else { \ | |||
msg_debug_archive("7zip archive is invalid (truncated); wanted to read %d bytes, %d avail: %s", (gint) (n), (gint) (end - p), G_STRLOC); \ | |||
return NULL; \ | |||
} \ | |||
#define SZ_SKIP_BYTES(n) \ | |||
do { \ | |||
if (end - p >= (n)) { \ | |||
p += (n); \ | |||
} \ | |||
else { \ | |||
msg_debug_archive("7zip archive is invalid (truncated); wanted to read %d bytes, %d avail: %s", (int) (n), (int) (end - p), G_STRLOC); \ | |||
return NULL; \ | |||
} \ | |||
} while (0) | |||
enum rspamd_7zip_header_mark { | |||
@@ -953,11 +953,11 @@ enum rspamd_7zip_header_mark { | |||
((codec_id) == _7Z_CRYPTO_RAR_29) || \ | |||
((codec_id) == _7Z_CRYPTO_AES_256_SHA_256)) | |||
static const guchar * | |||
static const unsigned char * | |||
rspamd_7zip_read_bits(struct rspamd_task *task, | |||
const guchar *p, const guchar *end, | |||
struct rspamd_archive *arch, guint nbits, | |||
guint *pbits_set) | |||
const unsigned char *p, const unsigned char *end, | |||
struct rspamd_archive *arch, unsigned int nbits, | |||
unsigned int *pbits_set) | |||
{ | |||
unsigned mask = 0, avail = 0, i; | |||
gboolean bit_set = 0; | |||
@@ -981,16 +981,16 @@ rspamd_7zip_read_bits(struct rspamd_task *task, | |||
return p; | |||
} | |||
static const guchar * | |||
static const unsigned char * | |||
rspamd_7zip_read_digest(struct rspamd_task *task, | |||
const guchar *p, const guchar *end, | |||
const unsigned char *p, const unsigned char *end, | |||
struct rspamd_archive *arch, | |||
guint64 num_streams, | |||
guint *pdigest_read) | |||
uint64_t num_streams, | |||
unsigned int *pdigest_read) | |||
{ | |||
guchar all_defined = *p; | |||
guint64 i; | |||
guint num_defined = 0; | |||
unsigned char all_defined = *p; | |||
uint64_t i; | |||
unsigned int num_defined = 0; | |||
/* | |||
* BYTE AllAreDefined | |||
* if (AllAreDefined == 0) | |||
@@ -1019,7 +1019,7 @@ rspamd_7zip_read_digest(struct rspamd_task *task, | |||
} | |||
for (i = 0; i < num_defined; i++) { | |||
SZ_SKIP_BYTES(sizeof(guint32)); | |||
SZ_SKIP_BYTES(sizeof(uint32_t)); | |||
} | |||
if (pdigest_read) { | |||
@@ -1029,14 +1029,14 @@ rspamd_7zip_read_digest(struct rspamd_task *task, | |||
return p; | |||
} | |||
static const guchar * | |||
static const unsigned char * | |||
rspamd_7zip_read_pack_info(struct rspamd_task *task, | |||
const guchar *p, const guchar *end, | |||
const unsigned char *p, const unsigned char *end, | |||
struct rspamd_archive *arch) | |||
{ | |||
guint64 pack_pos = 0, pack_streams = 0, i, cur_sz; | |||
guint num_digests = 0; | |||
guchar t; | |||
uint64_t pack_pos = 0, pack_streams = 0, i, cur_sz; | |||
unsigned int num_digests = 0; | |||
unsigned char t; | |||
/* | |||
* UINT64 PackPos | |||
* UINT64 NumPackStreams | |||
@@ -1089,18 +1089,18 @@ end: | |||
return p; | |||
} | |||
static const guchar * | |||
static const unsigned char * | |||
rspamd_7zip_read_folder(struct rspamd_task *task, | |||
const guchar *p, const guchar *end, | |||
struct rspamd_archive *arch, guint *pnstreams, guint *ndigests) | |||
const unsigned char *p, const unsigned char *end, | |||
struct rspamd_archive *arch, unsigned int *pnstreams, unsigned int *ndigests) | |||
{ | |||
guint64 ncoders = 0, i, j, noutstreams = 0, ninstreams = 0; | |||
uint64_t ncoders = 0, i, j, noutstreams = 0, ninstreams = 0; | |||
SZ_READ_VINT(ncoders); | |||
for (i = 0; i < ncoders && p != NULL && p < end; i++) { | |||
guint64 sz, tmp; | |||
guchar t; | |||
uint64_t sz, tmp; | |||
unsigned char t; | |||
/* | |||
* BYTE | |||
* { | |||
@@ -1163,21 +1163,21 @@ rspamd_7zip_read_folder(struct rspamd_task *task, | |||
if (noutstreams > 1) { | |||
/* BindPairs, WTF, huh */ | |||
for (i = 0; i < noutstreams - 1; i++) { | |||
guint64 tmp; | |||
uint64_t tmp; | |||
SZ_READ_VINT(tmp); | |||
SZ_READ_VINT(tmp); | |||
} | |||
} | |||
gint64 npacked = (gint64) ninstreams - (gint64) noutstreams + 1; | |||
int64_t npacked = (int64_t) ninstreams - (int64_t) noutstreams + 1; | |||
msg_debug_archive("7zip: instreams=%L, outstreams=%L, packed=%L", | |||
ninstreams, noutstreams, npacked); | |||
if (npacked > 1) { | |||
/* Gah... */ | |||
for (i = 0; i < npacked; i++) { | |||
guint64 tmp; | |||
uint64_t tmp; | |||
SZ_READ_VINT(tmp); | |||
} | |||
@@ -1189,15 +1189,15 @@ rspamd_7zip_read_folder(struct rspamd_task *task, | |||
return p; | |||
} | |||
static const guchar * | |||
static const unsigned char * | |||
rspamd_7zip_read_coders_info(struct rspamd_task *task, | |||
const guchar *p, const guchar *end, | |||
const unsigned char *p, const unsigned char *end, | |||
struct rspamd_archive *arch, | |||
guint *pnum_folders, guint *pnum_nodigest) | |||
unsigned int *pnum_folders, unsigned int *pnum_nodigest) | |||
{ | |||
guint64 num_folders = 0, i, tmp; | |||
guchar t; | |||
guint *folder_nstreams = NULL, num_digests = 0, digests_read = 0; | |||
uint64_t num_folders = 0, i, tmp; | |||
unsigned char t; | |||
unsigned int *folder_nstreams = NULL, num_digests = 0, digests_read = 0; | |||
while (p != NULL && p < end) { | |||
/* | |||
@@ -1259,11 +1259,11 @@ rspamd_7zip_read_coders_info(struct rspamd_task *task, | |||
case kCodersUnPackSize: | |||
for (i = 0; i < num_folders && p != NULL && p < end; i++) { | |||
if (folder_nstreams) { | |||
for (guint j = 0; j < folder_nstreams[i]; j++) { | |||
for (unsigned int j = 0; j < folder_nstreams[i]; j++) { | |||
SZ_READ_VINT(tmp); /* Unpacked size */ | |||
msg_debug_archive("7zip: unpacked size " | |||
"(folder=%d, stream=%d) = %L", | |||
(gint) i, j, tmp); | |||
(int) i, j, tmp); | |||
} | |||
} | |||
else { | |||
@@ -1315,23 +1315,23 @@ end: | |||
return p; | |||
} | |||
static const guchar * | |||
static const unsigned char * | |||
rspamd_7zip_read_substreams_info(struct rspamd_task *task, | |||
const guchar *p, const guchar *end, | |||
const unsigned char *p, const unsigned char *end, | |||
struct rspamd_archive *arch, | |||
guint num_folders, guint num_nodigest) | |||
unsigned int num_folders, unsigned int num_nodigest) | |||
{ | |||
guchar t; | |||
guint i; | |||
guint64 *folder_nstreams; | |||
unsigned char t; | |||
unsigned int i; | |||
uint64_t *folder_nstreams; | |||
if (num_folders > 8192) { | |||
/* Gah */ | |||
return NULL; | |||
} | |||
folder_nstreams = g_alloca(sizeof(guint64) * num_folders); | |||
memset(folder_nstreams, 0, sizeof(guint64) * num_folders); | |||
folder_nstreams = g_alloca(sizeof(uint64_t) * num_folders); | |||
memset(folder_nstreams, 0, sizeof(uint64_t) * num_folders); | |||
while (p != NULL && p < end) { | |||
/* | |||
@@ -1360,7 +1360,7 @@ rspamd_7zip_read_substreams_info(struct rspamd_task *task, | |||
switch (t) { | |||
case kNumUnPackStream: | |||
for (i = 0; i < num_folders; i++) { | |||
guint64 tmp; | |||
uint64_t tmp; | |||
SZ_READ_VINT(tmp); | |||
folder_nstreams[i] = tmp; | |||
@@ -1380,8 +1380,8 @@ rspamd_7zip_read_substreams_info(struct rspamd_task *task, | |||
* In fact, it is just absent in the real life... | |||
*/ | |||
for (i = 0; i < num_folders; i++) { | |||
for (guint j = 0; j < folder_nstreams[i]; j++) { | |||
guint64 tmp; | |||
for (unsigned int j = 0; j < folder_nstreams[i]; j++) { | |||
uint64_t tmp; | |||
SZ_READ_VINT(tmp); /* Who cares indeed */ | |||
} | |||
@@ -1402,13 +1402,13 @@ end: | |||
return p; | |||
} | |||
static const guchar * | |||
static const unsigned char * | |||
rspamd_7zip_read_main_streams_info(struct rspamd_task *task, | |||
const guchar *p, const guchar *end, | |||
const unsigned char *p, const unsigned char *end, | |||
struct rspamd_archive *arch) | |||
{ | |||
guchar t; | |||
guint num_folders = 0, unknown_digests = 0; | |||
unsigned char t; | |||
unsigned int num_folders = 0, unknown_digests = 0; | |||
while (p != NULL && p < end) { | |||
t = *p; | |||
@@ -1459,13 +1459,13 @@ end: | |||
return p; | |||
} | |||
static const guchar * | |||
static const unsigned char * | |||
rspamd_7zip_read_archive_props(struct rspamd_task *task, | |||
const guchar *p, const guchar *end, | |||
const unsigned char *p, const unsigned char *end, | |||
struct rspamd_archive *arch) | |||
{ | |||
guchar proptype; | |||
guint64 proplen; | |||
unsigned char proptype; | |||
uint64_t proplen; | |||
/* | |||
* for (;;) | |||
@@ -1501,18 +1501,18 @@ rspamd_7zip_read_archive_props(struct rspamd_task *task, | |||
} | |||
static GString * | |||
rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const guchar *p, | |||
const guchar *end) | |||
rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const unsigned char *p, | |||
const unsigned char *end) | |||
{ | |||
GString *res; | |||
goffset dest_pos = 0, src_pos = 0; | |||
const gsize len = (end - p) / sizeof(guint16); | |||
guint16 *up; | |||
const gsize len = (end - p) / sizeof(uint16_t); | |||
uint16_t *up; | |||
UChar32 wc; | |||
UBool is_error = 0; | |||
res = g_string_sized_new((end - p) * 3 / 2 + sizeof(wc) + 1); | |||
up = (guint16 *) p; | |||
up = (uint16_t *) p; | |||
while (src_pos < len) { | |||
U16_NEXT(up, src_pos, len, wc); | |||
@@ -1538,13 +1538,13 @@ rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const guchar *p, | |||
return res; | |||
} | |||
static const guchar * | |||
static const unsigned char * | |||
rspamd_7zip_read_files_info(struct rspamd_task *task, | |||
const guchar *p, const guchar *end, | |||
const unsigned char *p, const unsigned char *end, | |||
struct rspamd_archive *arch) | |||
{ | |||
guint64 nfiles = 0, sz, i; | |||
guchar t, b; | |||
uint64_t nfiles = 0, sz, i; | |||
unsigned char t, b; | |||
struct rspamd_archive_file *fentry; | |||
SZ_READ_VINT(nfiles); | |||
@@ -1584,7 +1584,7 @@ rspamd_7zip_read_files_info(struct rspamd_task *task, | |||
/* TODO: for the god sake, do something about external | |||
* filenames... | |||
*/ | |||
guint64 tmp; | |||
uint64_t tmp; | |||
SZ_READ_VINT(tmp); | |||
} | |||
@@ -1592,7 +1592,7 @@ rspamd_7zip_read_files_info(struct rspamd_task *task, | |||
for (i = 0; i < nfiles; i++) { | |||
/* Zero terminated wchar_t: happy converting... */ | |||
/* First, find terminator */ | |||
const guchar *fend = NULL, *tp = p; | |||
const unsigned char *fend = NULL, *tp = p; | |||
GString *res; | |||
while (tp < end - 1) { | |||
@@ -1644,13 +1644,13 @@ end: | |||
return p; | |||
} | |||
static const guchar * | |||
static const unsigned char * | |||
rspamd_7zip_read_next_section(struct rspamd_task *task, | |||
const guchar *p, const guchar *end, | |||
const unsigned char *p, const unsigned char *end, | |||
struct rspamd_archive *arch, | |||
struct rspamd_mime_part *part) | |||
{ | |||
guchar t = *p; | |||
unsigned char t = *p; | |||
SZ_SKIP_BYTES(1); | |||
@@ -1732,15 +1732,15 @@ rspamd_archive_process_7zip(struct rspamd_task *task, | |||
struct rspamd_mime_part *part) | |||
{ | |||
struct rspamd_archive *arch; | |||
const guchar *start, *p, *end; | |||
const guchar sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; | |||
guint64 section_offset = 0, section_length = 0; | |||
const unsigned char *start, *p, *end; | |||
const unsigned char sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; | |||
uint64_t section_offset = 0, section_length = 0; | |||
start = part->parsed_data.begin; | |||
p = start; | |||
end = p + part->parsed_data.len; | |||
if (end - p <= sizeof(guint64) + sizeof(guint32) || | |||
if (end - p <= sizeof(uint64_t) + sizeof(uint32_t) || | |||
memcmp(p, sz_magic, sizeof(sz_magic)) != 0) { | |||
msg_debug_archive("7z archive is invalid (no 7z magic)"); | |||
@@ -1754,13 +1754,13 @@ rspamd_archive_process_7zip(struct rspamd_task *task, | |||
arch); | |||
/* Magic (6 bytes) + version (2 bytes) + crc32 (4 bytes) */ | |||
p += sizeof(guint64) + sizeof(guint32); | |||
p += sizeof(uint64_t) + sizeof(uint32_t); | |||
SZ_READ_UINT64(section_offset); | |||
SZ_READ_UINT64(section_length); | |||
if (end - p > sizeof(guint32)) { | |||
p += sizeof(guint32); | |||
if (end - p > sizeof(uint32_t)) { | |||
p += sizeof(uint32_t); | |||
} | |||
else { | |||
msg_debug_archive("7z archive is invalid (truncated crc)"); | |||
@@ -1793,9 +1793,9 @@ rspamd_archive_process_gzip(struct rspamd_task *task, | |||
struct rspamd_mime_part *part) | |||
{ | |||
struct rspamd_archive *arch; | |||
const guchar *start, *p, *end; | |||
const guchar gz_magic[] = {0x1F, 0x8B}; | |||
guchar flags; | |||
const unsigned char *start, *p, *end; | |||
const unsigned char gz_magic[] = {0x1F, 0x8B}; | |||
unsigned char flags; | |||
start = part->parsed_data.begin; | |||
p = start; | |||
@@ -1834,7 +1834,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, | |||
if (flags & (1u << 2)) { | |||
/* Optional section */ | |||
guint16 optlen = 0; | |||
uint16_t optlen = 0; | |||
RAR_READ_UINT16(optlen); | |||
@@ -1849,7 +1849,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, | |||
} | |||
/* Read file name */ | |||
const guchar *fname_start = p; | |||
const unsigned char *fname_start = p; | |||
while (p < end) { | |||
if (*p == '\0') { | |||
@@ -1889,7 +1889,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, | |||
/* Fallback, we need to extract file name from archive name if possible */ | |||
if (part->cd && part->cd->filename.len > 0) { | |||
const gchar *dot_pos, *slash_pos; | |||
const char *dot_pos, *slash_pos; | |||
dot_pos = rspamd_memrchr(part->cd->filename.begin, '.', | |||
part->cd->filename.len); | |||
@@ -1914,7 +1914,7 @@ rspamd_archive_process_gzip(struct rspamd_task *task, | |||
goto set; | |||
} | |||
else { | |||
const gchar *fname_start = part->cd->filename.begin; | |||
const char *fname_start = part->cd->filename.begin; | |||
f = g_malloc0(sizeof(*f)); | |||
@@ -1951,11 +1951,11 @@ set: | |||
} | |||
static gboolean | |||
rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const gchar *str, | |||
const guchar *magic_start, gsize magic_len) | |||
rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const char *str, | |||
const unsigned char *magic_start, gsize magic_len) | |||
{ | |||
struct rspamd_content_type *ct; | |||
const gchar *p; | |||
const char *p; | |||
rspamd_ftok_t srch, *fname; | |||
ct = part->ct; | |||
@@ -2024,12 +2024,12 @@ rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const gchar *str, | |||
void rspamd_archives_process(struct rspamd_task *task) | |||
{ | |||
guint i; | |||
unsigned int i; | |||
struct rspamd_mime_part *part; | |||
const guchar rar_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07}; | |||
const guchar zip_magic[] = {0x50, 0x4b, 0x03, 0x04}; | |||
const guchar sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; | |||
const guchar gz_magic[] = {0x1F, 0x8B, 0x08}; | |||
const unsigned char rar_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07}; | |||
const unsigned char zip_magic[] = {0x50, 0x4b, 0x03, 0x04}; | |||
const unsigned char sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; | |||
const unsigned char gz_magic[] = {0x1F, 0x8B, 0x08}; | |||
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) | |||
{ | |||
@@ -2071,10 +2071,10 @@ void rspamd_archives_process(struct rspamd_task *task) | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_archive_type_str(enum rspamd_archive_type type) | |||
{ | |||
const gchar *ret = "unknown"; | |||
const char *ret = "unknown"; | |||
switch (type) { | |||
case RSPAMD_ARCHIVE_ZIP: |
@@ -63,7 +63,7 @@ void rspamd_archives_process(struct rspamd_task *task); | |||
/** | |||
* Get textual representation of an archive's type | |||
*/ | |||
const gchar *rspamd_archive_type_str(enum rspamd_archive_type type); | |||
const char *rspamd_archive_type_str(enum rspamd_archive_type type); | |||
#ifdef __cplusplus | |||
} |
@@ -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, | |||
@@ -23,9 +23,9 @@ | |||
static gboolean | |||
rspamd_rfc2231_decode(rspamd_mempool_t *pool, | |||
struct rspamd_content_type_param *param, | |||
gchar *value_start, gchar *value_end) | |||
char *value_start, char *value_end) | |||
{ | |||
gchar *quote_pos; | |||
char *quote_pos; | |||
quote_pos = memchr(value_start, '\'', value_end - value_start); | |||
@@ -42,7 +42,7 @@ rspamd_rfc2231_decode(rspamd_mempool_t *pool, | |||
* encoding'data (in theory). | |||
* Try to handle both... | |||
*/ | |||
const gchar *charset = NULL; | |||
const char *charset = NULL; | |||
rspamd_ftok_t ctok; | |||
ctok.begin = value_start; | |||
@@ -102,10 +102,10 @@ rspamd_rfc2231_decode(rspamd_mempool_t *pool, | |||
static gboolean | |||
rspamd_param_maybe_rfc2231_process(rspamd_mempool_t *pool, | |||
struct rspamd_content_type_param *param, | |||
gchar *name_start, gchar *name_end, | |||
gchar *value_start, gchar *value_end) | |||
char *name_start, char *name_end, | |||
char *value_start, char *value_end) | |||
{ | |||
const gchar *star_pos; | |||
const char *star_pos; | |||
star_pos = memchr(name_start, '*', name_end - name_start); | |||
@@ -163,7 +163,7 @@ rspamd_param_maybe_rfc2231_process(rspamd_mempool_t *pool, | |||
return TRUE; | |||
} | |||
static gint32 | |||
static int32_t | |||
rspamd_cmp_pieces(struct rspamd_content_type_param *p1, struct rspamd_content_type_param *p2) | |||
{ | |||
return p1->rfc2231_id - p2->rfc2231_id; | |||
@@ -191,7 +191,7 @@ rspamd_postprocess_ct_attributes(rspamd_mempool_t *pool, | |||
if (param->flags & RSPAMD_CONTENT_PARAM_PIECEWISE) { | |||
/* Reconstruct param */ | |||
gsize tlen = 0; | |||
gchar *ndata, *pos; | |||
char *ndata, *pos; | |||
sorted = param; | |||
DL_SORT(sorted, rspamd_cmp_pieces); | |||
@@ -267,7 +267,7 @@ rspamd_content_type_postprocess(rspamd_mempool_t *pool, | |||
if (rspamd_ftok_icase_equal(¶m->name, &srch)) { | |||
found = param; | |||
gchar *lc_boundary; | |||
char *lc_boundary; | |||
/* Adjust boundary */ | |||
lc_boundary = rspamd_mempool_alloc(pool, param->value.len); | |||
memcpy(lc_boundary, param->value.begin, param->value.len); | |||
@@ -283,7 +283,7 @@ rspamd_content_type_postprocess(rspamd_mempool_t *pool, | |||
RSPAMD_FTOK_ASSIGN(&srch, "name"); | |||
if (!rspamd_ftok_icase_equal(¶m->name, &srch)) { | |||
/* Just lowercase */ | |||
rspamd_str_lc_utf8((gchar *) param->value.begin, param->value.len); | |||
rspamd_str_lc_utf8((char *) param->value.begin, param->value.len); | |||
} | |||
} | |||
} | |||
@@ -308,8 +308,8 @@ rspamd_content_disposition_postprocess(rspamd_mempool_t *pool, | |||
void rspamd_content_type_add_param(rspamd_mempool_t *pool, | |||
struct rspamd_content_type *ct, | |||
gchar *name_start, gchar *name_end, | |||
gchar *value_start, gchar *value_end) | |||
char *name_start, char *name_end, | |||
char *value_start, char *value_end) | |||
{ | |||
struct rspamd_content_type_param *nparam; | |||
rspamd_ftok_t srch; | |||
@@ -349,10 +349,10 @@ void rspamd_content_type_add_param(rspamd_mempool_t *pool, | |||
} | |||
static struct rspamd_content_type * | |||
rspamd_content_type_parser(gchar *in, gsize len, rspamd_mempool_t *pool) | |||
rspamd_content_type_parser(char *in, gsize len, rspamd_mempool_t *pool) | |||
{ | |||
guint obraces = 0, ebraces = 0, qlen = 0; | |||
gchar *p, *c, *end, *pname_start = NULL, *pname_end = NULL; | |||
unsigned int obraces = 0, ebraces = 0, qlen = 0; | |||
char *p, *c, *end, *pname_start = NULL, *pname_end = NULL; | |||
struct rspamd_content_type *res = NULL, val; | |||
gboolean eqsign_seen = FALSE; | |||
enum { | |||
@@ -662,7 +662,7 @@ rspamd_content_type_parser(gchar *in, gsize len, rspamd_mempool_t *pool) | |||
} | |||
if (val.type.len > 0) { | |||
gchar *tmp; | |||
char *tmp; | |||
res = rspamd_mempool_alloc(pool, sizeof(val)); | |||
memcpy(res, &val, sizeof(val)); | |||
@@ -688,12 +688,12 @@ rspamd_content_type_parser(gchar *in, gsize len, rspamd_mempool_t *pool) | |||
} | |||
struct rspamd_content_type * | |||
rspamd_content_type_parse(const gchar *in, | |||
rspamd_content_type_parse(const char *in, | |||
gsize len, rspamd_mempool_t *pool) | |||
{ | |||
struct rspamd_content_type *res = NULL; | |||
rspamd_ftok_t srch; | |||
gchar *cpy; | |||
char *cpy; | |||
cpy = rspamd_mempool_alloc(pool, len + 1); | |||
rspamd_strlcpy(cpy, in, len + 1); | |||
@@ -793,7 +793,7 @@ rspamd_content_type_parse(const gchar *in, | |||
} | |||
} | |||
else { | |||
msg_warn_pool("cannot parse content type: %*s", (gint) len, cpy); | |||
msg_warn_pool("cannot parse content type: %*s", (int) len, cpy); | |||
} | |||
return res; | |||
@@ -801,11 +801,11 @@ rspamd_content_type_parse(const gchar *in, | |||
void rspamd_content_disposition_add_param(rspamd_mempool_t *pool, | |||
struct rspamd_content_disposition *cd, | |||
const gchar *name_start, const gchar *name_end, | |||
const gchar *value_start, const gchar *value_end) | |||
const char *name_start, const char *name_end, | |||
const char *value_start, const char *value_end) | |||
{ | |||
rspamd_ftok_t srch; | |||
gchar *name_cpy, *value_cpy, *name_cpy_end, *value_cpy_end; | |||
char *name_cpy, *value_cpy, *name_cpy_end, *value_cpy_end; | |||
struct rspamd_content_type_param *found = NULL, *nparam; | |||
g_assert(cd != NULL); | |||
@@ -850,7 +850,7 @@ void rspamd_content_disposition_add_param(rspamd_mempool_t *pool, | |||
} | |||
struct rspamd_content_disposition * | |||
rspamd_content_disposition_parse(const gchar *in, | |||
rspamd_content_disposition_parse(const char *in, | |||
gsize len, rspamd_mempool_t *pool) | |||
{ | |||
struct rspamd_content_disposition *res = NULL, val; | |||
@@ -877,7 +877,7 @@ rspamd_content_disposition_parse(const gchar *in, | |||
} | |||
else { | |||
msg_warn_pool("cannot parse content disposition: %*s", | |||
(gint) len, in); | |||
(int) len, in); | |||
} | |||
return res; |
@@ -46,13 +46,13 @@ enum rspamd_content_param_flags { | |||
struct rspamd_content_type_param { | |||
rspamd_ftok_t name; | |||
rspamd_ftok_t value; | |||
guint rfc2231_id; | |||
unsigned int rfc2231_id; | |||
enum rspamd_content_param_flags flags; | |||
struct rspamd_content_type_param *prev, *next; | |||
}; | |||
struct rspamd_content_type { | |||
gchar *cpy; | |||
char *cpy; | |||
rspamd_ftok_t type; | |||
rspamd_ftok_t subtype; | |||
rspamd_ftok_t charset; | |||
@@ -69,7 +69,7 @@ enum rspamd_content_disposition_type { | |||
}; | |||
struct rspamd_content_disposition { | |||
gchar *lc_data; | |||
char *lc_data; | |||
enum rspamd_content_disposition_type type; | |||
rspamd_ftok_t filename; | |||
GHashTable *attrs; /* Can be empty */ | |||
@@ -85,8 +85,8 @@ struct rspamd_content_disposition { | |||
*/ | |||
void rspamd_content_type_add_param(rspamd_mempool_t *pool, | |||
struct rspamd_content_type *ct, | |||
gchar *name_start, gchar *name_end, | |||
gchar *value_start, gchar *value_end); | |||
char *name_start, char *name_end, | |||
char *value_start, char *value_end); | |||
/** | |||
* Parse content type from the header (performs copy + lowercase) | |||
@@ -95,7 +95,7 @@ void rspamd_content_type_add_param(rspamd_mempool_t *pool, | |||
* @param pool | |||
* @return | |||
*/ | |||
struct rspamd_content_type *rspamd_content_type_parse(const gchar *in, | |||
struct rspamd_content_type *rspamd_content_type_parse(const char *in, | |||
gsize len, rspamd_mempool_t *pool); | |||
/** | |||
@@ -109,8 +109,8 @@ struct rspamd_content_type *rspamd_content_type_parse(const gchar *in, | |||
*/ | |||
void rspamd_content_disposition_add_param(rspamd_mempool_t *pool, | |||
struct rspamd_content_disposition *cd, | |||
const gchar *name_start, const gchar *name_end, | |||
const gchar *value_start, const gchar *value_end); | |||
const char *name_start, const char *name_end, | |||
const char *value_start, const char *value_end); | |||
/** | |||
* Parse content-disposition header | |||
@@ -119,7 +119,7 @@ void rspamd_content_disposition_add_param(rspamd_mempool_t *pool, | |||
* @param pool | |||
* @return | |||
*/ | |||
struct rspamd_content_disposition *rspamd_content_disposition_parse(const gchar *in, | |||
struct rspamd_content_disposition *rspamd_content_disposition_parse(const char *in, | |||
gsize len, | |||
rspamd_mempool_t *pool); | |||
@@ -48,7 +48,7 @@ rspamd_email_address_unescape(struct rspamd_email_address *addr) | |||
} | |||
struct rspamd_email_address * | |||
rspamd_email_address_from_smtp(const gchar *str, guint len) | |||
rspamd_email_address_from_smtp(const char *str, unsigned int len) | |||
{ | |||
struct rspamd_email_address addr, *ret; | |||
gsize nlen; | |||
@@ -73,8 +73,8 @@ rspamd_email_address_from_smtp(const gchar *str, guint len) | |||
nlen = ret->domain_len + ret->user_len + 2; | |||
ret->addr = g_malloc(nlen + 1); | |||
ret->addr_len = rspamd_snprintf((char *) ret->addr, nlen, "%*s@%*s", | |||
(gint) ret->user_len, ret->user, | |||
(gint) ret->domain_len, ret->domain); | |||
(int) ret->user_len, ret->user, | |||
(int) ret->domain_len, ret->domain); | |||
ret->flags |= RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED; | |||
} | |||
@@ -106,7 +106,7 @@ rspamd_email_address_add(rspamd_mempool_t *pool, | |||
GString *name) | |||
{ | |||
struct rspamd_email_address *elt; | |||
guint nlen; | |||
unsigned int nlen; | |||
elt = g_malloc0(sizeof(*elt)); | |||
rspamd_mempool_notify_alloc(pool, sizeof(*elt)); | |||
@@ -134,8 +134,8 @@ rspamd_email_address_add(rspamd_mempool_t *pool, | |||
elt->addr = g_malloc(nlen + 1); | |||
rspamd_mempool_notify_alloc(pool, nlen + 1); | |||
elt->addr_len = rspamd_snprintf((char *) elt->addr, nlen, "%*s@%*s", | |||
(gint) elt->user_len, elt->user, | |||
(gint) elt->domain_len, elt->domain); | |||
(int) elt->user_len, elt->user, | |||
(int) elt->domain_len, elt->domain); | |||
elt->flags |= RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED; | |||
} | |||
@@ -155,7 +155,7 @@ static gboolean | |||
rspamd_email_address_parse_heuristic(const char *data, size_t len, | |||
struct rspamd_email_address *addr) | |||
{ | |||
const gchar *p = data, *at = NULL, *end = data + len; | |||
const char *p = data, *at = NULL, *end = data + len; | |||
gboolean ret = FALSE; | |||
memset(addr, 0, sizeof(*addr)); | |||
@@ -199,11 +199,11 @@ rspamd_email_address_parse_heuristic(const char *data, size_t len, | |||
} | |||
static inline int | |||
rspamd_email_address_check_and_add(const gchar *start, gsize len, | |||
rspamd_email_address_check_and_add(const char *start, gsize len, | |||
GPtrArray *res, | |||
rspamd_mempool_t *pool, | |||
GString *ns, | |||
gint max_elements) | |||
int max_elements) | |||
{ | |||
struct rspamd_email_address addr; | |||
@@ -241,17 +241,17 @@ rspamd_email_address_check_and_add(const gchar *start, gsize len, | |||
} | |||
GPtrArray * | |||
rspamd_email_address_from_mime(rspamd_mempool_t *pool, const gchar *hdr, | |||
guint len, | |||
rspamd_email_address_from_mime(rspamd_mempool_t *pool, const char *hdr, | |||
unsigned int len, | |||
GPtrArray *src, | |||
gint max_elements) | |||
int max_elements) | |||
{ | |||
GPtrArray *res = src; | |||
gboolean seen_at = FALSE, seen_obrace = FALSE; | |||
const gchar *p = hdr, *end = hdr + len, *c = hdr, *t; | |||
const char *p = hdr, *end = hdr + len, *c = hdr, *t; | |||
GString *ns, *cpy; | |||
gint obraces, ebraces; | |||
int obraces, ebraces; | |||
enum { | |||
parse_name = 0, | |||
parse_quoted, | |||
@@ -343,7 +343,7 @@ rspamd_email_address_from_mime(rspamd_mempool_t *pool, const gchar *hdr, | |||
if (*p == '"') { | |||
/* We need to strip last spaces and update `ns` */ | |||
if (p > c) { | |||
guint nspaces = 0; | |||
unsigned int nspaces = 0; | |||
t = p - 1; | |||
@@ -551,7 +551,7 @@ end: | |||
void rspamd_email_address_list_destroy(gpointer ptr) | |||
{ | |||
GPtrArray *ar = ptr; | |||
guint i; | |||
unsigned int i; | |||
struct rspamd_email_address *addr; | |||
PTR_ARRAY_FOREACH(ar, i, addr) |
@@ -45,17 +45,17 @@ enum rspamd_email_address_flags { | |||
* Structure that represents email address in a convenient way | |||
*/ | |||
struct rspamd_email_address { | |||
const gchar *raw; | |||
const gchar *addr; | |||
const gchar *user; | |||
const gchar *domain; | |||
const gchar *name; | |||
const char *raw; | |||
const char *addr; | |||
const char *user; | |||
const char *domain; | |||
const char *name; | |||
guint raw_len; | |||
guint addr_len; | |||
guint domain_len; | |||
guint user_len; | |||
guint flags; | |||
unsigned int raw_len; | |||
unsigned int addr_len; | |||
unsigned int domain_len; | |||
unsigned int user_len; | |||
unsigned int flags; | |||
}; | |||
struct rspamd_task; | |||
@@ -66,7 +66,7 @@ struct rspamd_task; | |||
* @param len length of string | |||
* @return | |||
*/ | |||
struct rspamd_email_address *rspamd_email_address_from_smtp(const gchar *str, guint len); | |||
struct rspamd_email_address *rspamd_email_address_from_smtp(const char *str, unsigned int len); | |||
/** | |||
* Parses email address from the mime header, decodes names and return the array | |||
@@ -78,8 +78,8 @@ struct rspamd_email_address *rspamd_email_address_from_smtp(const gchar *str, gu | |||
* @return | |||
*/ | |||
GPtrArray * | |||
rspamd_email_address_from_mime(rspamd_mempool_t *pool, const gchar *hdr, guint len, | |||
GPtrArray *src, gint max_elements); | |||
rspamd_email_address_from_mime(rspamd_mempool_t *pool, const char *hdr, unsigned int len, | |||
GPtrArray *src, int max_elements); | |||
/** | |||
* Destroys list of email addresses |
@@ -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, | |||
@@ -36,12 +36,12 @@ INIT_LOG_MODULE(images) | |||
static rspamd_lru_hash_t *images_hash = NULL; | |||
#endif | |||
static const guint8 png_signature[] = {137, 80, 78, 71, 13, 10, 26, 10}; | |||
static const guint8 jpg_sig1[] = {0xff, 0xd8}; | |||
static const guint8 jpg_sig_jfif[] = {0xff, 0xe0}; | |||
static const guint8 jpg_sig_exif[] = {0xff, 0xe1}; | |||
static const guint8 gif_signature[] = {'G', 'I', 'F', '8'}; | |||
static const guint8 bmp_signature[] = {'B', 'M'}; | |||
static const uint8_t png_signature[] = {137, 80, 78, 71, 13, 10, 26, 10}; | |||
static const uint8_t jpg_sig1[] = {0xff, 0xd8}; | |||
static const uint8_t jpg_sig_jfif[] = {0xff, 0xe0}; | |||
static const uint8_t jpg_sig_exif[] = {0xff, 0xe1}; | |||
static const uint8_t gif_signature[] = {'G', 'I', 'F', '8'}; | |||
static const uint8_t bmp_signature[] = {'B', 'M'}; | |||
static bool process_image(struct rspamd_task *task, struct rspamd_mime_part *part); | |||
@@ -63,7 +63,7 @@ bool rspamd_images_process_mime_part_maybe(struct rspamd_task *task, | |||
void rspamd_images_process(struct rspamd_task *task) | |||
{ | |||
guint i; | |||
unsigned int i; | |||
struct rspamd_mime_part *part; | |||
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) | |||
@@ -107,8 +107,8 @@ static struct rspamd_image * | |||
process_png_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) | |||
{ | |||
struct rspamd_image *img; | |||
guint32 t; | |||
const guint8 *p; | |||
uint32_t t; | |||
const uint8_t *p; | |||
if (data->len < 24) { | |||
msg_info_pool("bad png detected (maybe striped)"); | |||
@@ -128,10 +128,10 @@ process_png_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) | |||
img->data = data; | |||
p += 4; | |||
memcpy(&t, p, sizeof(guint32)); | |||
memcpy(&t, p, sizeof(uint32_t)); | |||
img->width = ntohl(t); | |||
p += 4; | |||
memcpy(&t, p, sizeof(guint32)); | |||
memcpy(&t, p, sizeof(uint32_t)); | |||
img->height = ntohl(t); | |||
return img; | |||
@@ -140,8 +140,8 @@ process_png_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) | |||
static struct rspamd_image * | |||
process_jpg_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) | |||
{ | |||
const guint8 *p, *end; | |||
guint16 h, w; | |||
const uint8_t *p, *end; | |||
uint16_t h, w; | |||
struct rspamd_image *img; | |||
img = rspamd_mempool_alloc0(pool, sizeof(struct rspamd_image)); | |||
@@ -154,13 +154,13 @@ process_jpg_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) | |||
while (p < end) { | |||
if (p[0] == 0xFF && p[1] != 0xFF) { | |||
guint len = p[2] * 256 + p[3]; | |||
unsigned int len = p[2] * 256 + p[3]; | |||
p++; | |||
if (*p == 0xc0 || *p == 0xc1 || *p == 0xc2 || *p == 0xc3 || | |||
*p == 0xc9 || *p == 0xca || *p == 0xcb) { | |||
memcpy(&h, p + 4, sizeof(guint16)); | |||
memcpy(&h, p + 4, sizeof(uint16_t)); | |||
h = p[4] * 0xff + p[5]; | |||
img->height = h; | |||
w = p[6] * 0xff + p[7]; | |||
@@ -184,8 +184,8 @@ static struct rspamd_image * | |||
process_gif_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) | |||
{ | |||
struct rspamd_image *img; | |||
const guint8 *p; | |||
guint16 t; | |||
const uint8_t *p; | |||
uint16_t t; | |||
if (data->len < 10) { | |||
msg_info_pool("bad gif detected (maybe striped)"); | |||
@@ -197,9 +197,9 @@ process_gif_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) | |||
img->data = data; | |||
p = data->begin + 6; | |||
memcpy(&t, p, sizeof(guint16)); | |||
memcpy(&t, p, sizeof(uint16_t)); | |||
img->width = GUINT16_FROM_LE(t); | |||
memcpy(&t, p + 2, sizeof(guint16)); | |||
memcpy(&t, p + 2, sizeof(uint16_t)); | |||
img->height = GUINT16_FROM_LE(t); | |||
return img; | |||
@@ -209,8 +209,8 @@ static struct rspamd_image * | |||
process_bmp_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) | |||
{ | |||
struct rspamd_image *img; | |||
gint32 t; | |||
const guint8 *p; | |||
int32_t t; | |||
const uint8_t *p; | |||
if (data->len < 28) { | |||
msg_info_pool("bad bmp detected (maybe striped)"); | |||
@@ -221,9 +221,9 @@ process_bmp_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) | |||
img->type = IMAGE_TYPE_BMP; | |||
img->data = data; | |||
p = data->begin + 18; | |||
memcpy(&t, p, sizeof(guint32)); | |||
memcpy(&t, p, sizeof(uint32_t)); | |||
img->width = GUINT32_FROM_LE(t); | |||
memcpy(&t, p + 4, sizeof(gint32)); | |||
memcpy(&t, p + 4, sizeof(int32_t)); | |||
img->height = GUINT32_FROM_LE(t); | |||
return img; | |||
@@ -235,20 +235,20 @@ process_bmp_image(rspamd_mempool_t *pool, rspamd_ftok_t *data) | |||
* http://unix4lyfe.org/dct/ | |||
*/ | |||
static void | |||
rspamd_image_dct_block(gint pixels[8][8], gdouble *out) | |||
rspamd_image_dct_block(int pixels[8][8], double *out) | |||
{ | |||
gint i; | |||
gint rows[8][8]; | |||
int i; | |||
int rows[8][8]; | |||
static const gint c1 = 1004 /* cos(pi/16) << 10 */, | |||
s1 = 200 /* sin(pi/16) */, | |||
c3 = 851 /* cos(3pi/16) << 10 */, | |||
s3 = 569 /* sin(3pi/16) << 10 */, | |||
r2c6 = 554 /* sqrt(2)*cos(6pi/16) << 10 */, | |||
r2s6 = 1337 /* sqrt(2)*sin(6pi/16) << 10 */, | |||
r2 = 181; /* sqrt(2) << 7*/ | |||
static const int c1 = 1004 /* cos(pi/16) << 10 */, | |||
s1 = 200 /* sin(pi/16) */, | |||
c3 = 851 /* cos(3pi/16) << 10 */, | |||
s3 = 569 /* sin(3pi/16) << 10 */, | |||
r2c6 = 554 /* sqrt(2)*cos(6pi/16) << 10 */, | |||
r2s6 = 1337 /* sqrt(2)*sin(6pi/16) << 10 */, | |||
r2 = 181; /* sqrt(2) << 7*/ | |||
gint x0, x1, x2, x3, x4, x5, x6, x7, x8; | |||
int x0, x1, x2, x3, x4, x5, x6, x7, x8; | |||
/* transform rows */ | |||
for (i = 0; i < 8; i++) { | |||
@@ -362,8 +362,8 @@ rspamd_image_dct_block(gint pixels[8][8], gdouble *out) | |||
} | |||
struct rspamd_image_cache_entry { | |||
guchar digest[64]; | |||
guchar dct[RSPAMD_DCT_LEN / NBBY]; | |||
unsigned char digest[64]; | |||
unsigned char dct[RSPAMD_DCT_LEN / NBBY]; | |||
}; | |||
static void | |||
@@ -373,7 +373,7 @@ rspamd_image_cache_entry_dtor(gpointer p) | |||
g_free(entry); | |||
} | |||
static guint32 | |||
static uint32_t | |||
rspamd_image_dct_hash(gconstpointer p) | |||
{ | |||
return rspamd_cryptobox_fast_hash(p, rspamd_cryptobox_HASHBYTES, | |||
@@ -447,8 +447,8 @@ void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img) | |||
{ | |||
#ifdef USABLE_GD | |||
gdImagePtr src = NULL, dst = NULL; | |||
guint i, j, k, l; | |||
gdouble *dct; | |||
unsigned int i, j, k, l; | |||
double *dct; | |||
if (img->data->len == 0 || img->data->len > G_MAXINT32) { | |||
return; | |||
@@ -496,7 +496,7 @@ void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img) | |||
gdImageDestroy(src); | |||
img->is_normalized = TRUE; | |||
dct = g_malloc0(sizeof(gdouble) * RSPAMD_DCT_LEN); | |||
dct = g_malloc0(sizeof(double) * RSPAMD_DCT_LEN); | |||
img->dct = g_malloc0(RSPAMD_DCT_LEN / NBBY); | |||
rspamd_mempool_add_destructor(task->task_pool, g_free, | |||
img->dct); | |||
@@ -520,7 +520,7 @@ void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img) | |||
*/ | |||
for (i = 0; i < RSPAMD_NORMALIZED_DIM; i += 8) { | |||
for (j = 0; j < RSPAMD_NORMALIZED_DIM; j += 8) { | |||
gint p[8][8]; | |||
int p[8][8]; | |||
for (k = 0; k < 8; k++) { | |||
p[k][0] = gdImageGetPixel(dst, i + k, j); | |||
@@ -536,20 +536,20 @@ void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img) | |||
rspamd_image_dct_block(p, | |||
dct + i * RSPAMD_NORMALIZED_DIM + j); | |||
gdouble avg = 0.0; | |||
double avg = 0.0; | |||
for (k = 0; k < 8; k++) { | |||
for (l = 0; l < 8; l++) { | |||
gdouble x = *(dct + | |||
i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l); | |||
avg += (x - avg) / (gdouble) (k * 8 + l + 1); | |||
double x = *(dct + | |||
i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l); | |||
avg += (x - avg) / (double) (k * 8 + l + 1); | |||
} | |||
} | |||
for (k = 0; k < 8; k++) { | |||
for (l = 0; l < 8; l++) { | |||
guint idx = i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l; | |||
unsigned int idx = i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l; | |||
if (dct[idx] >= avg) { | |||
setbit(img->dct, idx); | |||
@@ -623,7 +623,7 @@ process_image(struct rspamd_task *task, struct rspamd_mime_part *part) | |||
return false; | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_image_type_str(enum rspamd_image_type type) | |||
{ | |||
switch (type) { | |||
@@ -652,8 +652,8 @@ rspamd_image_process_part(struct rspamd_task *task, struct rspamd_mime_part *par | |||
struct rspamd_mime_header *rh; | |||
struct rspamd_mime_text_part *tp; | |||
struct html_image *himg; | |||
const gchar *cid; | |||
guint cid_len, i; | |||
const char *cid; | |||
unsigned int cid_len, i; | |||
struct rspamd_image *img; | |||
img = (struct rspamd_image *) part->specific.img; | |||
@@ -707,7 +707,7 @@ rspamd_image_process_part(struct rspamd_task *task, struct rspamd_mime_part *par | |||
void rspamd_images_link(struct rspamd_task *task) | |||
{ | |||
struct rspamd_mime_part *part; | |||
guint i; | |||
unsigned int i; | |||
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) | |||
{ |
@@ -28,10 +28,10 @@ struct rspamd_image { | |||
rspamd_ftok_t *filename; | |||
struct html_image *html_image; | |||
enum rspamd_image_type type; | |||
guint32 width; | |||
guint32 height; | |||
uint32_t width; | |||
uint32_t height; | |||
gboolean is_normalized; | |||
guchar *dct; | |||
unsigned char *dct; | |||
}; | |||
/* | |||
@@ -65,7 +65,7 @@ struct rspamd_image *rspamd_maybe_process_image(rspamd_mempool_t *pool, | |||
/* | |||
* Get textual representation of an image's type | |||
*/ | |||
const gchar *rspamd_image_type_str(enum rspamd_image_type type); | |||
const char *rspamd_image_type_str(enum rspamd_image_type type); | |||
void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img); | |||
@@ -33,14 +33,14 @@ | |||
static const gsize default_short_text_limit = 10; | |||
static const gsize default_words = 80; | |||
static const gdouble update_prob = 0.6; | |||
static const gchar *default_languages_path = RSPAMD_SHAREDIR "/languages"; | |||
static const double update_prob = 0.6; | |||
static const char *default_languages_path = RSPAMD_SHAREDIR "/languages"; | |||
#undef EXTRA_LANGDET_DEBUG | |||
struct rspamd_language_unicode_match { | |||
const gchar *lang; | |||
gint unicode_code; | |||
const char *lang; | |||
int unicode_code; | |||
}; | |||
/* | |||
@@ -63,10 +63,10 @@ static const struct rspamd_language_unicode_match unicode_langs[] = { | |||
/* | |||
* Top languages | |||
*/ | |||
static const gchar *tier0_langs[] = { | |||
static const char *tier0_langs[] = { | |||
"en", | |||
}; | |||
static const gchar *tier1_langs[] = { | |||
static const char *tier1_langs[] = { | |||
"fr", "it", "de", "es", "nl", | |||
"pt", "ru", "pl", "tk", "th", "ar"}; | |||
@@ -79,31 +79,31 @@ enum rspamd_language_category { | |||
}; | |||
struct rspamd_language_elt { | |||
const gchar *name; /* e.g. "en" or "ru" */ | |||
gint flags; /* enum rspamd_language_elt_flags */ | |||
const char *name; /* e.g. "en" or "ru" */ | |||
int flags; /* enum rspamd_language_elt_flags */ | |||
enum rspamd_language_category category; | |||
guint trigrams_words; | |||
guint stop_words; | |||
gdouble mean; | |||
gdouble std; | |||
guint occurrences; /* total number of parts with this language */ | |||
unsigned int trigrams_words; | |||
unsigned int stop_words; | |||
double mean; | |||
double std; | |||
unsigned int occurrences; /* total number of parts with this language */ | |||
}; | |||
struct rspamd_ngramm_elt { | |||
struct rspamd_language_elt *elt; | |||
gdouble prob; | |||
double prob; | |||
}; | |||
struct rspamd_ngramm_chain { | |||
GPtrArray *languages; | |||
gdouble mean; | |||
gdouble std; | |||
gchar *utf; | |||
double mean; | |||
double std; | |||
char *utf; | |||
}; | |||
struct rspamd_stop_word_range { | |||
guint start; | |||
guint stop; | |||
unsigned int start; | |||
unsigned int stop; | |||
struct rspamd_language_elt *elt; | |||
}; | |||
@@ -124,7 +124,7 @@ struct rspamd_stop_word_elt { | |||
INIT_LOG_MODULE_PUBLIC(langdet) | |||
static const struct rspamd_language_unicode_match * | |||
rspamd_language_search_unicode_match(const gchar *key, | |||
rspamd_language_search_unicode_match(const char *key, | |||
const struct rspamd_language_unicode_match *elts, size_t nelts) | |||
{ | |||
size_t i; | |||
@@ -139,7 +139,7 @@ rspamd_language_search_unicode_match(const gchar *key, | |||
} | |||
static gboolean | |||
rspamd_language_search_str(const gchar *key, const gchar *elts[], size_t nelts) | |||
rspamd_language_search_str(const char *key, const char *elts[], size_t nelts) | |||
{ | |||
size_t i; | |||
@@ -151,7 +151,7 @@ rspamd_language_search_str(const gchar *key, const gchar *elts[], size_t nelts) | |||
return FALSE; | |||
} | |||
static guint | |||
static unsigned int | |||
rspamd_trigram_hash_func(gconstpointer key) | |||
{ | |||
return rspamd_cryptobox_fast_hash(key, 3 * sizeof(UChar32), | |||
@@ -166,14 +166,14 @@ rspamd_trigram_equal_func(gconstpointer v, gconstpointer v2) | |||
KHASH_INIT(rspamd_trigram_hash, const UChar32 *, struct rspamd_ngramm_chain, true, | |||
rspamd_trigram_hash_func, rspamd_trigram_equal_func); | |||
KHASH_INIT(rspamd_candidates_hash, const gchar *, | |||
KHASH_INIT(rspamd_candidates_hash, const char *, | |||
struct rspamd_lang_detector_res *, true, | |||
rspamd_str_hash, rspamd_str_equal); | |||
KHASH_INIT(rspamd_stopwords_hash, rspamd_ftok_t *, | |||
char, false, | |||
rspamd_ftok_hash, rspamd_ftok_equal); | |||
KHASH_INIT(rspamd_languages_hash, const gchar *, struct rspamd_language_elt *, true, | |||
KHASH_INIT(rspamd_languages_hash, const char *, struct rspamd_language_elt *, true, | |||
rspamd_str_hash, rspamd_str_equal); | |||
struct rspamd_lang_detector { | |||
khash_t(rspamd_languages_hash) * languages; | |||
@@ -215,8 +215,8 @@ rspamd_language_detector_ucs_is_latin(const UChar32 *s, gsize len) | |||
} | |||
struct rspamd_language_ucs_elt { | |||
guint freq; | |||
const gchar *utf; | |||
unsigned int freq; | |||
const char *utf; | |||
UChar32 s[0]; | |||
}; | |||
@@ -225,15 +225,15 @@ rspamd_language_detector_init_ngramm(struct rspamd_config *cfg, | |||
struct rspamd_lang_detector *d, | |||
struct rspamd_language_elt *lelt, | |||
struct rspamd_language_ucs_elt *ucs, | |||
guint len, | |||
guint freq, | |||
guint total, | |||
unsigned int len, | |||
unsigned int freq, | |||
unsigned int total, | |||
khash_t(rspamd_trigram_hash) * htb) | |||
{ | |||
struct rspamd_ngramm_chain *chain = NULL, st_chain; | |||
struct rspamd_ngramm_elt *elt; | |||
khiter_t k; | |||
guint i; | |||
unsigned int i; | |||
gboolean found; | |||
switch (len) { | |||
@@ -262,7 +262,7 @@ rspamd_language_detector_init_ngramm(struct rspamd_config *cfg, | |||
chain->utf = rspamd_mempool_strdup(cfg->cfg_pool, ucs->utf); | |||
elt = rspamd_mempool_alloc(cfg->cfg_pool, sizeof(*elt)); | |||
elt->elt = lelt; | |||
elt->prob = ((gdouble) freq) / ((gdouble) total); | |||
elt->prob = ((double) freq) / ((double) total); | |||
g_ptr_array_add(chain->languages, elt); | |||
k = kh_put(rspamd_trigram_hash, htb, ucs->s, &i); | |||
@@ -276,7 +276,7 @@ rspamd_language_detector_init_ngramm(struct rspamd_config *cfg, | |||
{ | |||
if (strcmp(elt->elt->name, lelt->name) == 0) { | |||
found = TRUE; | |||
elt->prob += ((gdouble) freq) / ((gdouble) total); | |||
elt->prob += ((double) freq) / ((double) total); | |||
break; | |||
} | |||
} | |||
@@ -284,14 +284,14 @@ rspamd_language_detector_init_ngramm(struct rspamd_config *cfg, | |||
if (!found) { | |||
elt = rspamd_mempool_alloc(cfg->cfg_pool, sizeof(*elt)); | |||
elt->elt = lelt; | |||
elt->prob = ((gdouble) freq) / ((gdouble) total); | |||
elt->prob = ((double) freq) / ((double) total); | |||
g_ptr_array_add(chain->languages, elt); | |||
} | |||
} | |||
} | |||
static inline enum rspamd_language_category | |||
rspamd_language_detector_get_category(guint uflags) | |||
rspamd_language_detector_get_category(unsigned int uflags) | |||
{ | |||
enum rspamd_language_category cat = RSPAMD_LANGUAGE_LATIN; | |||
@@ -308,10 +308,10 @@ rspamd_language_detector_get_category(guint uflags) | |||
return cat; | |||
} | |||
static const gchar * | |||
static const char * | |||
rspamd_language_detector_print_flags(struct rspamd_language_elt *elt) | |||
{ | |||
static gchar flags_buf[256]; | |||
static char flags_buf[256]; | |||
goffset r = 0; | |||
if (elt->flags & RS_LANGUAGE_TIER1) { | |||
@@ -334,19 +334,19 @@ rspamd_language_detector_print_flags(struct rspamd_language_elt *elt) | |||
return flags_buf; | |||
} | |||
static gint | |||
static int | |||
rspamd_language_detector_cmp_ngramm(gconstpointer a, gconstpointer b) | |||
{ | |||
struct rspamd_language_ucs_elt *e1 = *(struct rspamd_language_ucs_elt **) a; | |||
struct rspamd_language_ucs_elt *e2 = *(struct rspamd_language_ucs_elt **) b; | |||
return (gint) e2->freq - (gint) e1->freq; | |||
return (int) e2->freq - (int) e1->freq; | |||
} | |||
static void | |||
rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
struct rspamd_lang_detector *d, | |||
const gchar *path, | |||
const char *path, | |||
const ucl_object_t *stop_words) | |||
{ | |||
struct ucl_parser *parser; | |||
@@ -357,10 +357,10 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
struct rspamd_language_elt *nelt; | |||
struct rspamd_language_ucs_elt *ucs_elt; | |||
khash_t(rspamd_trigram_hash) *htb = NULL; | |||
gchar *pos; | |||
guint total = 0, total_latin = 0, total_ngramms = 0, i, skipped, | |||
loaded; | |||
gdouble mean = 0, std = 0, delta = 0, delta2 = 0, m2 = 0; | |||
char *pos; | |||
unsigned int total = 0, total_latin = 0, total_ngramms = 0, i, skipped, | |||
loaded; | |||
double mean = 0, std = 0, delta = 0, delta2 = 0, m2 = 0; | |||
enum rspamd_language_category cat = RSPAMD_LANGUAGE_MAX; | |||
parser = ucl_parser_new(UCL_PARSER_NO_FILEVARS); | |||
@@ -416,7 +416,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
return; | |||
} | |||
else { | |||
const gchar *stype = ucl_object_tostring(type); | |||
const char *stype = ucl_object_tostring(type); | |||
if (strcmp(stype, "latin") == 0) { | |||
cat = RSPAMD_LANGUAGE_LATIN; | |||
@@ -445,7 +445,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
const ucl_object_t *cur; | |||
while ((cur = ucl_object_iterate(flags, &it, true)) != NULL) { | |||
const gchar *fl = ucl_object_tostring(cur); | |||
const char *fl = ucl_object_tostring(cur); | |||
if (cur) { | |||
if (strcmp(fl, "diacritics") == 0) { | |||
@@ -473,7 +473,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
struct sb_stemmer *stem = NULL; | |||
it = NULL; | |||
const ucl_object_t *w; | |||
guint start, stop; | |||
unsigned int start, stop; | |||
stem = sb_stemmer_new(nelt->name, "UTF_8"); | |||
start = rspamd_multipattern_get_npatterns(d->stop_words[cat].mp); | |||
@@ -482,7 +482,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
gsize wlen; | |||
const char *word = ucl_object_tolstring(w, &wlen); | |||
const char *saved; | |||
guint mp_flags = RSPAMD_MULTIPATTERN_ICASE | RSPAMD_MULTIPATTERN_UTF8; | |||
unsigned int mp_flags = RSPAMD_MULTIPATTERN_ICASE | RSPAMD_MULTIPATTERN_UTF8; | |||
if (rspamd_multipattern_has_hyperscan()) { | |||
mp_flags |= RSPAMD_MULTIPATTERN_RE; | |||
@@ -511,13 +511,13 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
} | |||
if (saved) { | |||
gint rc; | |||
int rc; | |||
rspamd_ftok_t *tok; | |||
gchar *dst; | |||
char *dst; | |||
tok = rspamd_mempool_alloc(cfg->cfg_pool, | |||
sizeof(*tok) + wlen + 1); | |||
dst = ((gchar *) tok) + sizeof(*tok); | |||
dst = ((char *) tok) + sizeof(*tok); | |||
rspamd_strlcpy(dst, saved, wlen + 1); | |||
tok->begin = dst; | |||
tok->len = wlen; | |||
@@ -548,7 +548,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
htb = d->trigrams[cat]; | |||
GPtrArray *ngramms; | |||
guint nsym; | |||
unsigned int nsym; | |||
if (rspamd_language_search_str(nelt->name, tier1_langs, | |||
G_N_ELEMENTS(tier1_langs))) { | |||
@@ -567,9 +567,9 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
loaded = 0; | |||
while ((cur = ucl_object_iterate(freqs, &it, true)) != NULL) { | |||
const gchar *key; | |||
const char *key; | |||
gsize keylen; | |||
guint freq; | |||
unsigned int freq; | |||
key = ucl_object_keyl(cur, &keylen); | |||
freq = ucl_object_toint(cur); | |||
@@ -603,7 +603,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
if (!U_SUCCESS(uc_err)) { | |||
msg_warn_config("cannot convert key %*s to unicode: %s", | |||
(gint) keylen, key, u_errorName(uc_err)); | |||
(int) keylen, key, u_errorName(uc_err)); | |||
continue; | |||
} | |||
@@ -684,7 +684,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
"std=%.2f, mean=%.2f, skipped=%d, loaded=%d, stop_words=%d; " | |||
"(%s)", | |||
nelt->name, | |||
(gint) nelt->trigrams_words, | |||
(int) nelt->trigrams_words, | |||
total, | |||
std, mean, | |||
skipped, loaded, nelt->stop_words, | |||
@@ -698,7 +698,7 @@ rspamd_language_detector_read_file(struct rspamd_config *cfg, | |||
} | |||
static gboolean | |||
rspamd_ucl_array_find_str(const gchar *str, const ucl_object_t *ar) | |||
rspamd_ucl_array_find_str(const char *str, const ucl_object_t *ar) | |||
{ | |||
ucl_object_iter_t it = NULL; | |||
const ucl_object_t *cur; | |||
@@ -722,8 +722,8 @@ rspamd_language_detector_process_chain(struct rspamd_config *cfg, | |||
struct rspamd_ngramm_chain *chain) | |||
{ | |||
struct rspamd_ngramm_elt *elt; | |||
guint i; | |||
gdouble delta, mean = 0, delta2, m2 = 0, std; | |||
unsigned int i; | |||
double delta, mean = 0, delta2, m2 = 0, std; | |||
if (chain->languages->len > 3) { | |||
PTR_ARRAY_FOREACH(chain->languages, i, elt) | |||
@@ -767,7 +767,7 @@ static void | |||
rspamd_language_detector_dtor(struct rspamd_lang_detector *d) | |||
{ | |||
if (d) { | |||
for (guint i = 0; i < RSPAMD_LANGUAGE_MAX; i++) { | |||
for (unsigned int i = 0; i < RSPAMD_LANGUAGE_MAX; i++) { | |||
kh_destroy(rspamd_trigram_hash, d->trigrams[i]); | |||
rspamd_multipattern_destroy(d->stop_words[i].mp); | |||
g_array_free(d->stop_words[i].ranges, TRUE); | |||
@@ -787,13 +787,13 @@ rspamd_language_detector_init(struct rspamd_config *cfg) | |||
{ | |||
const ucl_object_t *section, *elt, *languages_enable = NULL, | |||
*languages_disable = NULL; | |||
const gchar *languages_path = default_languages_path; | |||
const char *languages_path = default_languages_path; | |||
glob_t gl; | |||
size_t i, short_text_limit = default_short_text_limit, total = 0; | |||
UErrorCode uc_err = U_ZERO_ERROR; | |||
GString *languages_pattern; | |||
struct rspamd_ngramm_chain *chain, schain; | |||
gchar *fname; | |||
char *fname; | |||
struct rspamd_lang_detector *ret = NULL; | |||
struct ucl_parser *parser; | |||
ucl_object_t *stop_words; | |||
@@ -912,8 +912,8 @@ rspamd_language_detector_init(struct rspamd_config *cfg) | |||
msg_info_config("loaded %d languages, " | |||
"%d trigrams; %s", | |||
(gint) kh_size(ret->languages), | |||
(gint) total, fasttext_status); | |||
(int) kh_size(ret->languages), | |||
(int) total, fasttext_status); | |||
g_free(fasttext_status); | |||
if (stop_words) { | |||
@@ -936,12 +936,12 @@ end: | |||
} | |||
static void | |||
rspamd_language_detector_random_select(GArray *ucs_tokens, guint nwords, | |||
rspamd_language_detector_random_select(GArray *ucs_tokens, unsigned int nwords, | |||
goffset *offsets_out, | |||
guint64 *seed) | |||
uint64_t *seed) | |||
{ | |||
guint step_len, remainder, i, out_idx; | |||
guint64 coin, sel; | |||
unsigned int step_len, remainder, i, out_idx; | |||
uint64_t coin, sel; | |||
rspamd_stat_token_t *tok; | |||
g_assert(nwords != 0); | |||
@@ -973,7 +973,7 @@ rspamd_language_detector_random_select(GArray *ucs_tokens, guint nwords, | |||
for (i = step_len + remainder; i < ucs_tokens->len; | |||
i += step_len, out_idx++) { | |||
guint ntries = 0; | |||
unsigned int ntries = 0; | |||
coin = rspamd_random_uint64_fast_seed(seed); | |||
sel = (coin % step_len) + i; | |||
@@ -1028,9 +1028,9 @@ rspamd_language_detector_random_select(GArray *ucs_tokens, guint nwords, | |||
static goffset | |||
rspamd_language_detector_next_ngramm(rspamd_stat_token_t *tok, UChar32 *window, | |||
guint wlen, goffset cur_off) | |||
unsigned int wlen, goffset cur_off) | |||
{ | |||
guint i; | |||
unsigned int i; | |||
if (wlen > 1) { | |||
/* Deal with spaces at the beginning and ending */ | |||
@@ -1081,13 +1081,13 @@ rspamd_language_detector_process_ngramm_full(struct rspamd_task *task, | |||
khash_t(rspamd_candidates_hash) * candidates, | |||
khash_t(rspamd_trigram_hash) * trigrams) | |||
{ | |||
guint i; | |||
gint ret; | |||
unsigned int i; | |||
int ret; | |||
struct rspamd_ngramm_chain *chain = NULL; | |||
struct rspamd_ngramm_elt *elt; | |||
struct rspamd_lang_detector_res *cand; | |||
khiter_t k; | |||
gdouble prob; | |||
double prob; | |||
k = kh_get(rspamd_trigram_hash, trigrams, window); | |||
if (k != kh_end(trigrams)) { | |||
@@ -1140,7 +1140,7 @@ rspamd_language_detector_detect_word(struct rspamd_task *task, | |||
khash_t(rspamd_candidates_hash) * candidates, | |||
khash_t(rspamd_trigram_hash) * trigrams) | |||
{ | |||
const guint wlen = 3; | |||
const unsigned int wlen = 3; | |||
UChar32 window[3]; | |||
goffset cur = 0; | |||
@@ -1151,7 +1151,7 @@ rspamd_language_detector_detect_word(struct rspamd_task *task, | |||
} | |||
} | |||
static const gdouble cutoff_limit = -8.0; | |||
static const double cutoff_limit = -8.0; | |||
/* | |||
* Converts frequencies to log probabilities, filter those candidates who | |||
* has the lowest probabilities | |||
@@ -1160,7 +1160,7 @@ static const gdouble cutoff_limit = -8.0; | |||
static inline void | |||
rspamd_language_detector_filter_step1(struct rspamd_task *task, | |||
struct rspamd_lang_detector_res *cand, | |||
gdouble *max_prob, guint *filtered) | |||
double *max_prob, unsigned int *filtered) | |||
{ | |||
if (!isnan(cand->prob)) { | |||
if (cand->prob == 0) { | |||
@@ -1189,7 +1189,7 @@ rspamd_language_detector_filter_step1(struct rspamd_task *task, | |||
static inline void | |||
rspamd_language_detector_filter_step2(struct rspamd_task *task, | |||
struct rspamd_lang_detector_res *cand, | |||
gdouble max_prob, guint *filtered) | |||
double max_prob, unsigned int *filtered) | |||
{ | |||
/* | |||
* Probabilities are logarithmic, so if prob1 - prob2 > 4, it means that | |||
@@ -1208,8 +1208,8 @@ rspamd_language_detector_filter_negligible(struct rspamd_task *task, | |||
khash_t(rspamd_candidates_hash) * candidates) | |||
{ | |||
struct rspamd_lang_detector_res *cand; | |||
guint filtered = 0; | |||
gdouble max_prob = -(G_MAXDOUBLE); | |||
unsigned int filtered = 0; | |||
double max_prob = -(G_MAXDOUBLE); | |||
kh_foreach_value(candidates, cand, | |||
rspamd_language_detector_filter_step1(task, cand, &max_prob, &filtered)); | |||
@@ -1221,18 +1221,18 @@ rspamd_language_detector_filter_negligible(struct rspamd_task *task, | |||
static void | |||
rspamd_language_detector_detect_type(struct rspamd_task *task, | |||
guint nwords, | |||
unsigned int nwords, | |||
struct rspamd_lang_detector *d, | |||
GArray *words, | |||
enum rspamd_language_category cat, | |||
khash_t(rspamd_candidates_hash) * candidates, | |||
struct rspamd_mime_text_part *part) | |||
{ | |||
guint nparts = MIN(words->len, nwords); | |||
unsigned int nparts = MIN(words->len, nwords); | |||
goffset *selected_words; | |||
rspamd_stat_token_t *tok; | |||
guint i; | |||
guint64 seed; | |||
unsigned int i; | |||
uint64_t seed; | |||
/* Seed PRNG with part digest to provide some sort of determinism */ | |||
memcpy(&seed, part->mime_part->digest, sizeof(seed)); | |||
@@ -1255,7 +1255,7 @@ rspamd_language_detector_detect_type(struct rspamd_task *task, | |||
g_free(selected_words); | |||
} | |||
static gint | |||
static int | |||
rspamd_language_detector_cmp(gconstpointer a, gconstpointer b) | |||
{ | |||
const struct rspamd_lang_detector_res | |||
@@ -1280,14 +1280,14 @@ enum rspamd_language_detected_type { | |||
static enum rspamd_language_detected_type | |||
rspamd_language_detector_try_ngramm(struct rspamd_task *task, | |||
guint nwords, | |||
unsigned int nwords, | |||
struct rspamd_lang_detector *d, | |||
GArray *ucs_tokens, | |||
enum rspamd_language_category cat, | |||
khash_t(rspamd_candidates_hash) * candidates, | |||
struct rspamd_mime_text_part *part) | |||
{ | |||
guint cand_len = 0; | |||
unsigned int cand_len = 0; | |||
struct rspamd_lang_detector_res *cand; | |||
rspamd_language_detector_detect_type(task, | |||
@@ -1322,15 +1322,15 @@ enum rspamd_language_sort_flags { | |||
struct rspamd_frequency_sort_cbdata { | |||
struct rspamd_lang_detector *d; | |||
enum rspamd_language_sort_flags flags; | |||
gdouble std; | |||
gdouble mean; | |||
double std; | |||
double mean; | |||
}; | |||
static const gdouble tier0_adjustment = 1.2; | |||
static const gdouble tier1_adjustment = 0.8; | |||
static const gdouble frequency_adjustment = 0.8; | |||
static const double tier0_adjustment = 1.2; | |||
static const double tier1_adjustment = 0.8; | |||
static const double frequency_adjustment = 0.8; | |||
static gint | |||
static int | |||
rspamd_language_detector_cmp_heuristic(gconstpointer a, gconstpointer b, | |||
gpointer ud) | |||
{ | |||
@@ -1338,18 +1338,18 @@ rspamd_language_detector_cmp_heuristic(gconstpointer a, gconstpointer b, | |||
struct rspamd_lang_detector_res | |||
*canda = *(struct rspamd_lang_detector_res **) a, | |||
*candb = *(struct rspamd_lang_detector_res **) b; | |||
gdouble adj; | |||
gdouble proba_adjusted, probb_adjusted, freqa, freqb; | |||
double adj; | |||
double proba_adjusted, probb_adjusted, freqa, freqb; | |||
if (cbd->d->total_occurrences == 0) { | |||
/* Not enough data, compare directly */ | |||
return rspamd_language_detector_cmp(a, b); | |||
} | |||
freqa = ((gdouble) canda->elt->occurrences) / | |||
(gdouble) cbd->d->total_occurrences; | |||
freqb = ((gdouble) candb->elt->occurrences) / | |||
(gdouble) cbd->d->total_occurrences; | |||
freqa = ((double) canda->elt->occurrences) / | |||
(double) cbd->d->total_occurrences; | |||
freqb = ((double) candb->elt->occurrences) / | |||
(double) cbd->d->total_occurrences; | |||
proba_adjusted = canda->prob; | |||
probb_adjusted = candb->prob; | |||
@@ -1405,20 +1405,20 @@ rspamd_language_detector_cmp_heuristic(gconstpointer a, gconstpointer b, | |||
static void | |||
rspamd_language_detector_unicode_scripts(struct rspamd_task *task, | |||
struct rspamd_mime_text_part *part, | |||
guint *pchinese, | |||
guint *pspecial) | |||
unsigned int *pchinese, | |||
unsigned int *pspecial) | |||
{ | |||
const gchar *p = part->utf_stripped_content->data, *end; | |||
guint i = 0, cnt = 0; | |||
const char *p = part->utf_stripped_content->data, *end; | |||
unsigned int i = 0, cnt = 0; | |||
end = p + part->utf_stripped_content->len; | |||
gint32 uc, sc; | |||
guint nlatin = 0, nchinese = 0, nspecial = 0; | |||
const guint cutoff_limit = 32; | |||
int32_t uc, sc; | |||
unsigned int nlatin = 0, nchinese = 0, nspecial = 0; | |||
const unsigned int cutoff_limit = 32; | |||
while (p + i < end) { | |||
U8_NEXT(p, i, part->utf_stripped_content->len, uc); | |||
if (((gint32) uc) < 0) { | |||
if (((int32_t) uc) < 0) { | |||
break; | |||
} | |||
@@ -1527,7 +1527,7 @@ rspamd_language_detector_unicode_scripts(struct rspamd_task *task, | |||
static inline void | |||
rspamd_language_detector_set_language(struct rspamd_task *task, | |||
struct rspamd_mime_text_part *part, | |||
const gchar *code, | |||
const char *code, | |||
struct rspamd_language_elt *elt) | |||
{ | |||
struct rspamd_lang_detector_res *r; | |||
@@ -1548,10 +1548,10 @@ rspamd_language_detector_set_language(struct rspamd_task *task, | |||
static gboolean | |||
rspamd_language_detector_try_uniscript(struct rspamd_task *task, | |||
struct rspamd_mime_text_part *part, | |||
guint nchinese, | |||
guint nspecial) | |||
unsigned int nchinese, | |||
unsigned int nspecial) | |||
{ | |||
guint i; | |||
unsigned int i; | |||
for (i = 0; i < G_N_ELEMENTS(unicode_langs); i++) { | |||
if (unicode_langs[i].unicode_code & part->unicode_scripts) { | |||
@@ -1598,7 +1598,7 @@ rspamd_language_detector_try_uniscript(struct rspamd_task *task, | |||
return FALSE; | |||
} | |||
static guint | |||
static unsigned int | |||
rspamd_langelt_hash_func(gconstpointer key) | |||
{ | |||
const struct rspamd_language_elt *elt = (const struct rspamd_language_elt *) key; | |||
@@ -1626,10 +1626,10 @@ struct rspamd_sw_cbdata { | |||
GArray *ranges; | |||
}; | |||
static gint | |||
static int | |||
rspamd_ranges_cmp(const void *k, const void *memb) | |||
{ | |||
gint pos = GPOINTER_TO_INT(k); | |||
int pos = GPOINTER_TO_INT(k); | |||
const struct rspamd_stop_word_range *r = (struct rspamd_stop_word_range *) memb; | |||
if (pos >= r->start && pos < r->stop) { | |||
@@ -1642,17 +1642,17 @@ rspamd_ranges_cmp(const void *k, const void *memb) | |||
return 1; | |||
} | |||
static gint | |||
static int | |||
rspamd_language_detector_sw_cb(struct rspamd_multipattern *mp, | |||
guint strnum, | |||
gint match_start, | |||
gint match_pos, | |||
const gchar *text, | |||
unsigned int strnum, | |||
int match_start, | |||
int match_pos, | |||
const char *text, | |||
gsize len, | |||
void *context) | |||
{ | |||
/* Check if boundary */ | |||
const gchar *prev = text, *next = text + len; | |||
const char *prev = text, *next = text + len; | |||
struct rspamd_stop_word_range *r; | |||
struct rspamd_sw_cbdata *cbdata = (struct rspamd_sw_cbdata *) context; | |||
khiter_t k; | |||
@@ -1683,7 +1683,7 @@ rspamd_language_detector_sw_cb(struct rspamd_multipattern *mp, | |||
g_assert(r != NULL); | |||
k = kh_get(rspamd_sw_hash, cbdata->res, r->elt); | |||
gint nwords = 1; | |||
int nwords = 1; | |||
if (k != kh_end(cbdata->res)) { | |||
khiter_t set_k; | |||
@@ -1704,7 +1704,7 @@ rspamd_language_detector_sw_cb(struct rspamd_multipattern *mp, | |||
} | |||
} | |||
else { | |||
gint tt; | |||
int tt; | |||
k = kh_put(rspamd_sw_hash, cbdata->res, r->elt, &tt); | |||
kh_value(cbdata->res, k) = kh_init(rspamd_sw_res_set); | |||
@@ -1824,8 +1824,8 @@ rspamd_language_detector_detect(struct rspamd_task *task, | |||
{ | |||
khash_t(rspamd_candidates_hash) * candidates; | |||
GPtrArray *result; | |||
gdouble mean, std, start_ticks, end_ticks; | |||
guint cand_len; | |||
double mean, std, start_ticks, end_ticks; | |||
unsigned int cand_len; | |||
enum rspamd_language_category cat; | |||
struct rspamd_lang_detector_res *cand; | |||
enum rspamd_language_detected_type r; | |||
@@ -1839,7 +1839,7 @@ rspamd_language_detector_detect(struct rspamd_task *task, | |||
start_ticks = rspamd_get_ticks(TRUE); | |||
guint nchinese = 0, nspecial = 0; | |||
unsigned int nchinese = 0, nspecial = 0; | |||
rspamd_language_detector_unicode_scripts(task, part, &nchinese, &nspecial); | |||
/* Disable internal language detection heuristics if we have fasttext */ | |||
@@ -1968,7 +1968,7 @@ rspamd_language_detector_detect(struct rspamd_task *task, | |||
mean /= cand_len; | |||
kh_foreach_value(candidates, cand, { | |||
gdouble err; | |||
double err; | |||
if (!isnan(cand->prob)) { | |||
err = cand->prob - mean; | |||
std += fabs(err); | |||
@@ -2076,7 +2076,7 @@ void rspamd_language_detector_unref(struct rspamd_lang_detector *d) | |||
gboolean | |||
rspamd_language_detector_is_stop_word(struct rspamd_lang_detector *d, | |||
const gchar *word, gsize wlen) | |||
const char *word, gsize wlen) | |||
{ | |||
khiter_t k; | |||
rspamd_ftok_t search; | |||
@@ -2093,7 +2093,7 @@ rspamd_language_detector_is_stop_word(struct rspamd_lang_detector *d, | |||
return FALSE; | |||
} | |||
gint rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt) | |||
int rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt) | |||
{ | |||
if (elt) { | |||
return elt->flags; |
@@ -60,8 +60,8 @@ enum rspamd_language_elt_flags { | |||
}; | |||
struct rspamd_lang_detector_res { | |||
gdouble prob; | |||
const gchar *lang; | |||
double prob; | |||
const char *lang; | |||
struct rspamd_language_elt *elt; | |||
}; | |||
@@ -95,14 +95,14 @@ gboolean rspamd_language_detector_detect(struct rspamd_task *task, | |||
* @return | |||
*/ | |||
gboolean rspamd_language_detector_is_stop_word(struct rspamd_lang_detector *d, | |||
const gchar *word, gsize wlen); | |||
const char *word, gsize wlen); | |||
/** | |||
* Return language flags for a specific language elt | |||
* @param elt | |||
* @return | |||
*/ | |||
gint rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt); | |||
int rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt); | |||
#ifdef __cplusplus | |||
} | |||
#endif |
@@ -187,7 +187,7 @@ rspamd_fasttext_predict_result_t rspamd_lang_detection_fasttext_detect(void *ud, | |||
return nullptr; | |||
#else | |||
/* Avoid too long inputs */ | |||
static const guint max_fasttext_input_len = 1024 * 1024; | |||
static const unsigned int max_fasttext_input_len = 1024 * 1024; | |||
auto *real_model = FASTTEXT_MODEL_TO_C_API(ud); | |||
std::vector<std::int32_t> words_vec; | |||
words_vec.reserve(utf_words->len); | |||
@@ -215,7 +215,7 @@ void rspamd_lang_detection_fasttext_destroy(void *ud) | |||
} | |||
guint rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t res) | |||
unsigned int rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t res) | |||
{ | |||
#ifdef WITH_FASTTEXT | |||
auto *real_res = FASTTEXT_RESULT_TO_C_API(res); |
@@ -60,7 +60,7 @@ rspamd_fasttext_predict_result_t rspamd_lang_detection_fasttext_detect(void *ud, | |||
* @param ud | |||
* @return | |||
*/ | |||
guint rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t ud); | |||
unsigned int rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t ud); | |||
/** | |||
* Get language from fasttext result | |||
* @param res |
@@ -46,16 +46,16 @@ | |||
#define SET_PART_RAW(part) ((part)->flags &= ~RSPAMD_MIME_TEXT_PART_FLAG_UTF) | |||
#define SET_PART_UTF(part) ((part)->flags |= RSPAMD_MIME_TEXT_PART_FLAG_UTF) | |||
static const gchar gtube_pattern_reject[] = "XJS*C4JDBQADN1.NSBN3*2IDNEN*" | |||
"GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; | |||
static const gchar gtube_pattern_add_header[] = "YJS*C4JDBQADN1.NSBN3*2IDNEN*" | |||
"GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; | |||
static const gchar gtube_pattern_rewrite_subject[] = "ZJS*C4JDBQADN1.NSBN3*2IDNEN*" | |||
"GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; | |||
static const gchar gtube_pattern_no_action[] = "AJS*C4JDBQADN1.NSBN3*2IDNEN*" | |||
static const char gtube_pattern_reject[] = "XJS*C4JDBQADN1.NSBN3*2IDNEN*" | |||
"GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; | |||
static const char gtube_pattern_add_header[] = "YJS*C4JDBQADN1.NSBN3*2IDNEN*" | |||
"GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; | |||
static const char gtube_pattern_rewrite_subject[] = "ZJS*C4JDBQADN1.NSBN3*2IDNEN*" | |||
"GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; | |||
static const char gtube_pattern_no_action[] = "AJS*C4JDBQADN1.NSBN3*2IDNEN*" | |||
"GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; | |||
struct rspamd_multipattern *gtube_matcher = NULL; | |||
static const guint64 words_hash_seed = 0xdeadbabe; | |||
static const uint64_t words_hash_seed = 0xdeadbabe; | |||
static void | |||
free_byte_array_callback(void *pointer) | |||
@@ -69,14 +69,14 @@ rspamd_mime_part_extract_words(struct rspamd_task *task, | |||
struct rspamd_mime_text_part *part) | |||
{ | |||
rspamd_stat_token_t *w; | |||
guint i, total_len = 0, short_len = 0; | |||
unsigned int i, total_len = 0, short_len = 0; | |||
if (part->utf_words) { | |||
rspamd_stem_words(part->utf_words, task->task_pool, part->language, | |||
task->lang_det); | |||
for (i = 0; i < part->utf_words->len; i++) { | |||
guint64 h; | |||
uint64_t h; | |||
w = &g_array_index(part->utf_words, rspamd_stat_token_t, i); | |||
@@ -109,7 +109,7 @@ rspamd_mime_part_extract_words(struct rspamd_task *task, | |||
} | |||
if (part->utf_words->len) { | |||
gdouble *avg_len_p, *short_len_p; | |||
double *avg_len_p, *short_len_p; | |||
avg_len_p = rspamd_mempool_get_variable(task->task_pool, | |||
RSPAMD_MEMPOOL_AVG_WORDS_LEN); | |||
@@ -152,17 +152,17 @@ rspamd_mime_part_create_words(struct rspamd_task *task, | |||
#if U_ICU_VERSION_MAJOR_NUM < 50 | |||
/* Hack to prevent hang with Thai in old libicu */ | |||
const gchar *p = part->utf_stripped_content->data, *end; | |||
guint i = 0; | |||
const char *p = part->utf_stripped_content->data, *end; | |||
unsigned int i = 0; | |||
end = p + part->utf_stripped_content->len; | |||
gint32 uc, sc; | |||
int32_t uc, sc; | |||
tok_type = RSPAMD_TOKENIZE_UTF; | |||
while (p + i < end) { | |||
U8_NEXT(p, i, part->utf_stripped_content->len, uc); | |||
if (((gint32) uc) < 0) { | |||
if (((int32_t) uc) < 0) { | |||
tok_type = RSPAMD_TOKENIZE_RAW; | |||
break; | |||
} | |||
@@ -198,7 +198,7 @@ rspamd_mime_part_create_words(struct rspamd_task *task, | |||
if (part->utf_words) { | |||
part->normalized_hashes = g_array_sized_new(FALSE, FALSE, | |||
sizeof(guint64), part->utf_words->len); | |||
sizeof(uint64_t), part->utf_words->len); | |||
rspamd_normalize_words(part->utf_words, task->task_pool); | |||
} | |||
} | |||
@@ -225,10 +225,10 @@ rspamd_mime_part_detect_language(struct rspamd_task *task, | |||
static void | |||
rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
const gchar *begin, const gchar *pe, | |||
const char *begin, const char *pe, | |||
struct rspamd_mime_text_part *part) | |||
{ | |||
const gchar *p = begin, *c = begin; | |||
const char *p = begin, *c = begin; | |||
gboolean crlf_added = FALSE, is_utf = IS_TEXT_PART_UTF(part); | |||
gboolean url_open_bracket = FALSE; | |||
UChar32 uc; | |||
@@ -241,7 +241,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
while (p < pe) { | |||
if (U8_IS_LEAD(*p) && is_utf) { | |||
gint32 off = p - begin; | |||
int32_t off = p - begin; | |||
U8_NEXT(begin, off, pe - begin, uc); | |||
if (uc != -1) { | |||
@@ -253,7 +253,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
if (p > c) { | |||
g_byte_array_append(part->utf_stripped_content, | |||
(const guint8 *) c, p - c); | |||
(const uint8_t *) c, p - c); | |||
c = begin + off; | |||
p = c; | |||
} | |||
@@ -290,7 +290,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
state = seen_cr; | |||
if (p > c) { | |||
g_byte_array_append(part->utf_stripped_content, | |||
(const guint8 *) c, p - c); | |||
(const uint8_t *) c, p - c); | |||
} | |||
crlf_added = FALSE; | |||
@@ -300,7 +300,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
/* Double \r\r */ | |||
if (!crlf_added) { | |||
g_byte_array_append(part->utf_stripped_content, | |||
(const guint8 *) " ", 1); | |||
(const uint8_t *) " ", 1); | |||
crlf_added = TRUE; | |||
g_ptr_array_add(part->newlines, | |||
(((gpointer) (goffset) (part->utf_stripped_content->len)))); | |||
@@ -328,14 +328,14 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
if (p > c) { | |||
g_byte_array_append(part->utf_stripped_content, | |||
(const guint8 *) c, p - c); | |||
(const uint8_t *) c, p - c); | |||
} | |||
c = p + 1; | |||
if (IS_TEXT_PART_HTML(part) || !url_open_bracket) { | |||
g_byte_array_append(part->utf_stripped_content, | |||
(const guint8 *) " ", 1); | |||
(const uint8_t *) " ", 1); | |||
g_ptr_array_add(part->newlines, | |||
(((gpointer) (goffset) (part->utf_stripped_content->len)))); | |||
crlf_added = TRUE; | |||
@@ -350,7 +350,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
if (!crlf_added) { | |||
if (IS_TEXT_PART_HTML(part) || !url_open_bracket) { | |||
g_byte_array_append(part->utf_stripped_content, | |||
(const guint8 *) " ", 1); | |||
(const uint8_t *) " ", 1); | |||
crlf_added = TRUE; | |||
} | |||
@@ -366,7 +366,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
/* Double \n\n */ | |||
if (!crlf_added) { | |||
g_byte_array_append(part->utf_stripped_content, | |||
(const guint8 *) " ", 1); | |||
(const uint8_t *) " ", 1); | |||
crlf_added = TRUE; | |||
g_ptr_array_add(part->newlines, | |||
(((gpointer) (goffset) (part->utf_stripped_content->len)))); | |||
@@ -430,7 +430,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
if (*p == ' ') { | |||
if (!crlf_added) { | |||
g_byte_array_append(part->utf_stripped_content, | |||
(const guint8 *) " ", 1); | |||
(const uint8_t *) " ", 1); | |||
} | |||
while (p < pe && *p == ' ') { | |||
@@ -461,7 +461,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
switch (state) { | |||
case normal_char: | |||
g_byte_array_append(part->utf_stripped_content, | |||
(const guint8 *) c, p - c); | |||
(const uint8_t *) c, p - c); | |||
while (c < p) { | |||
if (*c == ' ') { | |||
@@ -489,7 +489,7 @@ rspamd_strip_newlines_parse(struct rspamd_task *task, | |||
if (!crlf_added) { | |||
g_byte_array_append(part->utf_stripped_content, | |||
(const guint8 *) " ", 1); | |||
(const uint8_t *) " ", 1); | |||
g_ptr_array_add(part->newlines, | |||
(((gpointer) (goffset) (part->utf_stripped_content->len)))); | |||
} | |||
@@ -510,8 +510,8 @@ static void | |||
rspamd_normalize_text_part(struct rspamd_task *task, | |||
struct rspamd_mime_text_part *part) | |||
{ | |||
const gchar *p, *end; | |||
guint i; | |||
const char *p, *end; | |||
unsigned int i; | |||
goffset off; | |||
struct rspamd_process_exception *ex; | |||
UErrorCode uc_err = U_ZERO_ERROR; | |||
@@ -524,7 +524,7 @@ rspamd_normalize_text_part(struct rspamd_task *task, | |||
else { | |||
part->utf_stripped_content = g_byte_array_sized_new(part->utf_content.len); | |||
p = (const gchar *) part->utf_content.begin; | |||
p = (const char *) part->utf_content.begin; | |||
end = p + part->utf_content.len; | |||
rspamd_strip_newlines_parse(task, p, end, part); | |||
@@ -569,15 +569,15 @@ rspamd_normalize_text_part(struct rspamd_task *task, | |||
#define MIN3(a, b, c) ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c))) | |||
static guint | |||
static unsigned int | |||
rspamd_words_levenshtein_distance(struct rspamd_task *task, | |||
GArray *w1, GArray *w2) | |||
{ | |||
guint s1len, s2len, x, y, lastdiag, olddiag; | |||
guint *column, ret; | |||
guint64 h1, h2; | |||
gint eq; | |||
static const guint max_words = 8192; | |||
unsigned int s1len, s2len, x, y, lastdiag, olddiag; | |||
unsigned int *column, ret; | |||
uint64_t h1, h2; | |||
int eq; | |||
static const unsigned int max_words = 8192; | |||
s1len = w1->len; | |||
s2len = w2->len; | |||
@@ -596,7 +596,7 @@ rspamd_words_levenshtein_distance(struct rspamd_task *task, | |||
} | |||
} | |||
column = g_malloc0((s1len + 1) * sizeof(guint)); | |||
column = g_malloc0((s1len + 1) * sizeof(unsigned int)); | |||
for (y = 1; y <= s1len; y++) { | |||
column[y] = y; | |||
@@ -607,8 +607,8 @@ rspamd_words_levenshtein_distance(struct rspamd_task *task, | |||
for (y = 1, lastdiag = x - 1; y <= s1len; y++) { | |||
olddiag = column[y]; | |||
h1 = g_array_index(w1, guint64, y - 1); | |||
h2 = g_array_index(w2, guint64, x - 1); | |||
h1 = g_array_index(w1, uint64_t, y - 1); | |||
h2 = g_array_index(w2, uint64_t, x - 1); | |||
eq = (h1 == h2) ? 1 : 0; | |||
/* | |||
* Cost of replacement is twice higher than cost of add/delete | |||
@@ -626,12 +626,12 @@ rspamd_words_levenshtein_distance(struct rspamd_task *task, | |||
return ret; | |||
} | |||
static gint | |||
static int | |||
rspamd_multipattern_gtube_cb(struct rspamd_multipattern *mp, | |||
guint strnum, | |||
gint match_start, | |||
gint match_pos, | |||
const gchar *text, | |||
unsigned int strnum, | |||
int match_start, | |||
int match_pos, | |||
const char *text, | |||
gsize len, | |||
void *context) | |||
{ | |||
@@ -652,7 +652,7 @@ static enum rspamd_action_type | |||
rspamd_check_gtube(struct rspamd_task *task, struct rspamd_mime_text_part *part) | |||
{ | |||
static const gsize max_check_size = 8 * 1024; | |||
gint ret; | |||
int ret; | |||
enum rspamd_action_type act = METRIC_ACTION_NOACTION; | |||
enum rspamd_gtube_patterns_policy policy = task->cfg ? task->cfg->gtube_patterns_policy : RSPAMD_GTUBE_REJECT; | |||
g_assert(part != NULL); | |||
@@ -719,7 +719,7 @@ rspamd_check_gtube(struct rspamd_task *task, struct rspamd_mime_text_part *part) | |||
return act; | |||
} | |||
static gint | |||
static int | |||
exceptions_compare_func(gconstpointer a, gconstpointer b) | |||
{ | |||
const struct rspamd_process_exception *ea = a, *eb = b; | |||
@@ -741,7 +741,7 @@ rspamd_message_process_plain_text_part(struct rspamd_task *task, | |||
if (text_part->utf_raw_content != NULL) { | |||
/* Just have the same content */ | |||
text_part->utf_content.begin = (const gchar *) text_part->utf_raw_content->data; | |||
text_part->utf_content.begin = (const char *) text_part->utf_raw_content->data; | |||
text_part->utf_content.len = text_part->utf_raw_content->len; | |||
} | |||
else { | |||
@@ -845,7 +845,7 @@ rspamd_message_process_text_part_maybe(struct rspamd_task *task, | |||
uint16_t *cur_url_order) | |||
{ | |||
struct rspamd_mime_text_part *text_part; | |||
guint flags = 0; | |||
unsigned int flags = 0; | |||
enum rspamd_action_type act; | |||
/* Skip attachments */ | |||
@@ -881,7 +881,7 @@ rspamd_message_process_text_part_maybe(struct rspamd_task *task, | |||
act = rspamd_check_gtube(task, text_part); | |||
if (act != METRIC_ACTION_NOACTION) { | |||
struct rspamd_action *action; | |||
gdouble score = NAN; | |||
double score = NAN; | |||
action = rspamd_config_get_action_by_type(task->cfg, act); | |||
@@ -950,15 +950,15 @@ rspamd_message_process_text_part_maybe(struct rspamd_task *task, | |||
/* Creates message from various data using libmagic to detect type */ | |||
static void | |||
rspamd_message_from_data(struct rspamd_task *task, const guchar *start, | |||
rspamd_message_from_data(struct rspamd_task *task, const unsigned char *start, | |||
gsize len) | |||
{ | |||
struct rspamd_content_type *ct = NULL; | |||
struct rspamd_mime_part *part; | |||
const char *mb = "application/octet-stream"; | |||
gchar *mid; | |||
char *mid; | |||
rspamd_ftok_t srch, *tok; | |||
gchar cdbuf[1024]; | |||
char cdbuf[1024]; | |||
g_assert(start != NULL); | |||
@@ -1075,7 +1075,7 @@ rspamd_message_from_data(struct rspamd_task *task, const guchar *start, | |||
static void | |||
rspamd_message_dtor(struct rspamd_message *msg) | |||
{ | |||
guint i; | |||
unsigned int i; | |||
struct rspamd_mime_part *p; | |||
struct rspamd_mime_text_part *tp; | |||
@@ -1146,11 +1146,11 @@ rspamd_message_new(struct rspamd_task *task) | |||
gboolean | |||
rspamd_message_parse(struct rspamd_task *task) | |||
{ | |||
const gchar *p; | |||
const char *p; | |||
gsize len; | |||
guint i; | |||
unsigned int i; | |||
GError *err = NULL; | |||
guint64 n[2], seed; | |||
uint64_t n[2], seed; | |||
if (RSPAMD_TASK_IS_EMPTY(task)) { | |||
/* Don't do anything with empty task */ | |||
@@ -1205,7 +1205,7 @@ rspamd_message_parse(struct rspamd_task *task) | |||
enum rspamd_mime_parse_error ret; | |||
debug_task("construct mime parser from string length %d", | |||
(gint) task->msg.len); | |||
(int) task->msg.len); | |||
ret = rspamd_mime_parse_task(task, &err); | |||
switch (ret) { | |||
@@ -1257,7 +1257,7 @@ rspamd_message_parse(struct rspamd_task *task) | |||
struct rspamd_mime_part *part; | |||
/* Blake2b applied to string 'rspamd' */ | |||
static const guchar RSPAMD_ALIGNED(32) hash_key[] = { | |||
static const unsigned char RSPAMD_ALIGNED(32) hash_key[] = { | |||
0xef, | |||
0x43, | |||
0xae, | |||
@@ -1350,13 +1350,13 @@ rspamd_message_parse(struct rspamd_task *task) | |||
msg_info_task("loaded message; id: <%s>; queue-id: <%s>; size: %z; " | |||
"checksum: <%*xs>", | |||
MESSAGE_FIELD(task, message_id), task->queue_id, task->msg.len, | |||
(gint) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest)); | |||
(int) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest)); | |||
} | |||
else { | |||
msg_info_task("loaded message; id: <%s>; size: %z; " | |||
"checksum: <%*xs>", | |||
MESSAGE_FIELD(task, message_id), task->msg.len, | |||
(gint) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest)); | |||
(int) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest)); | |||
} | |||
return TRUE; | |||
@@ -1394,13 +1394,13 @@ rspamd_mime_text_part_position_compare_func(const void *v1, const void *v2) | |||
void rspamd_message_process(struct rspamd_task *task) | |||
{ | |||
guint i; | |||
unsigned int i; | |||
struct rspamd_mime_text_part *p1, *p2; | |||
gdouble diff, *pdiff; | |||
guint tw, *ptw, dw; | |||
double diff, *pdiff; | |||
unsigned int tw, *ptw, dw; | |||
struct rspamd_mime_part *part; | |||
lua_State *L = NULL; | |||
gint magic_func_pos = -1, content_func_pos = -1, old_top = -1, funcs_top = -1; | |||
int magic_func_pos = -1, content_func_pos = -1, old_top = -1, funcs_top = -1; | |||
if (task->cfg) { | |||
L = task->cfg->lua_state; | |||
@@ -1441,7 +1441,7 @@ void rspamd_message_process(struct rspamd_task *task) | |||
struct rspamd_task **ptask; | |||
lua_pushcfunction(L, &rspamd_lua_traceback); | |||
gint err_idx = lua_gettop(L); | |||
int err_idx = lua_gettop(L); | |||
lua_pushvalue(L, magic_func_pos); | |||
pmime = lua_newuserdata(L, sizeof(struct rspamd_mime_part *)); | |||
rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); | |||
@@ -1455,7 +1455,7 @@ void rspamd_message_process(struct rspamd_task *task) | |||
} | |||
else { | |||
if (lua_istable(L, -1)) { | |||
const gchar *mb; | |||
const char *mb; | |||
/* First returned value */ | |||
part->detected_ext = rspamd_mempool_strdup(task->task_pool, | |||
@@ -1513,7 +1513,7 @@ void rspamd_message_process(struct rspamd_task *task) | |||
struct rspamd_task **ptask; | |||
lua_pushcfunction(L, &rspamd_lua_traceback); | |||
gint err_idx = lua_gettop(L); | |||
int err_idx = lua_gettop(L); | |||
lua_pushvalue(L, content_func_pos); | |||
pmime = lua_newuserdata(L, sizeof(struct rspamd_mime_part *)); | |||
rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); | |||
@@ -1572,8 +1572,8 @@ void rspamd_message_process(struct rspamd_task *task) | |||
/* Calculate average words length and number of short words */ | |||
struct rspamd_mime_text_part *text_part; | |||
gdouble *var; | |||
guint total_words = 0; | |||
double *var; | |||
unsigned int total_words = 0; | |||
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, text_part) | |||
{ | |||
@@ -1651,7 +1651,7 @@ void rspamd_message_process(struct rspamd_task *task) | |||
dw = rspamd_words_levenshtein_distance(task, | |||
p1->normalized_hashes, | |||
p2->normalized_hashes); | |||
diff = dw / (gdouble) tw; | |||
diff = dw / (double) tw; | |||
msg_debug_task( | |||
"different words: %d, total words: %d, " | |||
@@ -1660,14 +1660,14 @@ void rspamd_message_process(struct rspamd_task *task) | |||
diff); | |||
pdiff = rspamd_mempool_alloc(task->task_pool, | |||
sizeof(gdouble)); | |||
sizeof(double)); | |||
*pdiff = diff; | |||
rspamd_mempool_set_variable(task->task_pool, | |||
"parts_distance", | |||
pdiff, | |||
NULL); | |||
ptw = rspamd_mempool_alloc(task->task_pool, | |||
sizeof(gint)); | |||
sizeof(int)); | |||
*ptw = tw; | |||
rspamd_mempool_set_variable(task->task_pool, | |||
"total_words", | |||
@@ -1722,7 +1722,7 @@ void rspamd_message_unref(struct rspamd_message *msg) | |||
void rspamd_message_update_digest(struct rspamd_message *msg, | |||
const void *input, gsize len) | |||
{ | |||
guint64 n[2]; | |||
uint64_t n[2]; | |||
/* Sanity */ | |||
G_STATIC_ASSERT(sizeof(n) == sizeof(msg->digest)); | |||
@@ -75,15 +75,15 @@ enum rspamd_lua_specific_type { | |||
}; | |||
struct rspamd_lua_specific_part { | |||
gint cbref; | |||
int cbref; | |||
enum rspamd_lua_specific_type type; | |||
}; | |||
struct rspamd_mime_part { | |||
struct rspamd_content_type *ct; | |||
struct rspamd_content_type *detected_ct; | |||
gchar *detected_type; | |||
gchar *detected_ext; | |||
char *detected_type; | |||
char *detected_ext; | |||
struct rspamd_content_disposition *cd; | |||
rspamd_ftok_t raw_data; | |||
rspamd_ftok_t parsed_data; | |||
@@ -93,13 +93,13 @@ struct rspamd_mime_part { | |||
struct rspamd_mime_headers_table *raw_headers; | |||
GPtrArray *urls; | |||
gchar *raw_headers_str; | |||
char *raw_headers_str; | |||
gsize raw_headers_len; | |||
enum rspamd_cte cte; | |||
guint flags; | |||
unsigned int flags; | |||
enum rspamd_mime_part_type part_type; | |||
guint part_number; | |||
unsigned int part_number; | |||
union { | |||
struct rspamd_mime_multipart *mp; | |||
@@ -109,7 +109,7 @@ struct rspamd_mime_part { | |||
struct rspamd_lua_specific_part lua_specific; | |||
} specific; | |||
guchar digest[rspamd_cryptobox_HASHBYTES]; | |||
unsigned char digest[rspamd_cryptobox_HASHBYTES]; | |||
}; | |||
#define RSPAMD_MIME_TEXT_PART_FLAG_UTF (1 << 0) | |||
@@ -126,9 +126,9 @@ struct rspamd_mime_part { | |||
struct rspamd_mime_text_part { | |||
const gchar *language; | |||
const char *language; | |||
GPtrArray *languages; | |||
const gchar *real_charset; | |||
const char *real_charset; | |||
/* Raw data in native encoding */ | |||
rspamd_ftok_t raw; | |||
@@ -138,7 +138,7 @@ struct rspamd_mime_text_part { | |||
rspamd_ftok_t utf_content; /* utf8 encoded processed content */ | |||
GByteArray *utf_raw_content; /* utf raw content */ | |||
GByteArray *utf_stripped_content; /* utf content with no newlines */ | |||
GArray *normalized_hashes; /* Array of guint64 */ | |||
GArray *normalized_hashes; /* Array of uint64_t */ | |||
GArray *utf_words; /* Array of rspamd_stat_token_t */ | |||
UText utf_stripped_text; /* Used by libicu to represent the utf8 content */ | |||
@@ -147,29 +147,29 @@ struct rspamd_mime_text_part { | |||
GList *exceptions; /**< list of offsets of urls */ | |||
struct rspamd_mime_part *mime_part; | |||
guint flags; | |||
guint nlines; | |||
guint spaces; | |||
guint nwords; | |||
guint non_ascii_chars; | |||
guint ascii_chars; | |||
guint double_spaces; | |||
guint non_spaces; | |||
guint empty_lines; | |||
guint capital_letters; | |||
guint numeric_characters; | |||
guint unicode_scripts; | |||
unsigned int flags; | |||
unsigned int nlines; | |||
unsigned int spaces; | |||
unsigned int nwords; | |||
unsigned int non_ascii_chars; | |||
unsigned int ascii_chars; | |||
unsigned int double_spaces; | |||
unsigned int non_spaces; | |||
unsigned int empty_lines; | |||
unsigned int capital_letters; | |||
unsigned int numeric_characters; | |||
unsigned int unicode_scripts; | |||
}; | |||
struct rspamd_message_raw_headers_content { | |||
const gchar *begin; | |||
const char *begin; | |||
gsize len; | |||
const gchar *body_start; | |||
const char *body_start; | |||
}; | |||
struct rspamd_message { | |||
const gchar *message_id; | |||
gchar *subject; | |||
const char *message_id; | |||
char *subject; | |||
GPtrArray *parts; /**< list of parsed parts */ | |||
GPtrArray *text_parts; /**< list of text parts */ | |||
@@ -181,7 +181,7 @@ struct rspamd_message { | |||
struct rspamd_task *task; | |||
GPtrArray *rcpt_mime; | |||
GPtrArray *from_mime; | |||
guchar digest[16]; | |||
unsigned char digest[16]; | |||
enum rspamd_newlines_type nlines_type; /**< type of newlines (detected on most of headers */ | |||
ref_entry_t ref; | |||
}; | |||
@@ -208,14 +208,14 @@ void rspamd_message_process(struct rspamd_task *task); | |||
* @param str | |||
* @return | |||
*/ | |||
enum rspamd_cte rspamd_cte_from_string(const gchar *str); | |||
enum rspamd_cte rspamd_cte_from_string(const char *str); | |||
/** | |||
* Converts cte to string | |||
* @param ct | |||
* @return | |||
*/ | |||
const gchar *rspamd_cte_to_string(enum rspamd_cte ct); | |||
const char *rspamd_cte_to_string(enum rspamd_cte ct); | |||
struct rspamd_message *rspamd_message_new(struct rspamd_task *task); | |||
@@ -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, | |||
@@ -44,9 +44,9 @@ | |||
static rspamd_regexp_t *utf_compatible_re = NULL; | |||
struct rspamd_charset_substitution { | |||
const gchar *input; | |||
const gchar *canon; | |||
gint flags; | |||
const char *input; | |||
const char *canon; | |||
int flags; | |||
}; | |||
#include "mime_encoding_list.h" | |||
@@ -72,7 +72,7 @@ static const UChar iso_8859_16_map[] = { | |||
0x0171, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0119, 0x021B, 0x00FF}; | |||
struct rspamd_charset_converter { | |||
gchar *canon_name; | |||
char *canon_name; | |||
union { | |||
UConverter *conv; | |||
const UChar *cnv_table; | |||
@@ -115,7 +115,7 @@ rspamd_converter_to_uchars(struct rspamd_charset_converter *cnv, | |||
} | |||
else { | |||
UChar *d = dest, *dend = dest + destCapacity; | |||
const guchar *p = src, *end = src + srcLength; | |||
const unsigned char *p = src, *end = src + srcLength; | |||
while (p < end && d < dend) { | |||
if (*p <= 127) { | |||
@@ -134,12 +134,12 @@ rspamd_converter_to_uchars(struct rspamd_charset_converter *cnv, | |||
struct rspamd_charset_converter * | |||
rspamd_mime_get_converter_cached(const gchar *enc, | |||
rspamd_mime_get_converter_cached(const char *enc, | |||
rspamd_mempool_t *pool, | |||
gboolean is_canon, | |||
UErrorCode *err) | |||
{ | |||
const gchar *canon_name; | |||
const char *canon_name; | |||
static rspamd_lru_hash_t *cache; | |||
struct rspamd_charset_converter *conv; | |||
@@ -208,7 +208,7 @@ rspamd_mime_get_converter_cached(const gchar *enc, | |||
static void | |||
rspamd_mime_encoding_substitute_init(void) | |||
{ | |||
guint i; | |||
unsigned int i; | |||
sub_hash = g_hash_table_new(rspamd_strcase_hash, rspamd_strcase_equal); | |||
@@ -218,14 +218,14 @@ rspamd_mime_encoding_substitute_init(void) | |||
} | |||
static void | |||
rspamd_charset_normalize(gchar *in) | |||
rspamd_charset_normalize(char *in) | |||
{ | |||
/* | |||
* This is a simple routine to validate input charset | |||
* we just check that charset starts with alphanumeric and ends | |||
* with alphanumeric | |||
*/ | |||
gchar *begin, *end; | |||
char *begin, *end; | |||
gboolean changed = FALSE; | |||
begin = in; | |||
@@ -248,12 +248,12 @@ rspamd_charset_normalize(gchar *in) | |||
} | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_mime_detect_charset(const rspamd_ftok_t *in, rspamd_mempool_t *pool) | |||
{ | |||
gchar *ret = NULL, *h, *t; | |||
char *ret = NULL, *h, *t; | |||
struct rspamd_charset_substitution *s; | |||
const gchar *cset; | |||
const char *cset; | |||
rspamd_ftok_t utf8_tok; | |||
UErrorCode uc_err = U_ZERO_ERROR; | |||
@@ -321,13 +321,13 @@ rspamd_mime_detect_charset(const rspamd_ftok_t *in, rspamd_mempool_t *pool) | |||
return cset; | |||
} | |||
gchar * | |||
char * | |||
rspamd_mime_text_to_utf8(rspamd_mempool_t *pool, | |||
gchar *input, gsize len, const gchar *in_enc, | |||
char *input, gsize len, const char *in_enc, | |||
gsize *olen, GError **err) | |||
{ | |||
gchar *d; | |||
gint32 r, clen, dlen; | |||
char *d; | |||
int32_t r, clen, dlen; | |||
UChar *tmp_buf; | |||
UErrorCode uc_err = U_ZERO_ERROR; | |||
@@ -403,11 +403,11 @@ static gboolean | |||
rspamd_mime_text_part_utf8_convert(struct rspamd_task *task, | |||
struct rspamd_mime_text_part *text_part, | |||
GByteArray *input, | |||
const gchar *charset, | |||
const char *charset, | |||
GError **err) | |||
{ | |||
gchar *d; | |||
gint32 r, clen, dlen, uc_len; | |||
char *d; | |||
int32_t r, clen, dlen, uc_len; | |||
UChar *tmp_buf; | |||
UErrorCode uc_err = U_ZERO_ERROR; | |||
UConverter *utf8_converter; | |||
@@ -482,9 +482,9 @@ gboolean | |||
rspamd_mime_to_utf8_byte_array(GByteArray *in, | |||
GByteArray *out, | |||
rspamd_mempool_t *pool, | |||
const gchar *enc) | |||
const char *enc) | |||
{ | |||
gint32 r, clen, dlen; | |||
int32_t r, clen, dlen; | |||
UChar *tmp_buf; | |||
UErrorCode uc_err = U_ZERO_ERROR; | |||
UConverter *utf8_converter; | |||
@@ -511,7 +511,7 @@ rspamd_mime_to_utf8_byte_array(GByteArray *in, | |||
RSPAMD_FTOK_FROM_STR(&charset_tok, enc); | |||
if (rspamd_mime_charset_utf_check(&charset_tok, (gchar *) in->data, in->len, | |||
if (rspamd_mime_charset_utf_check(&charset_tok, (char *) in->data, in->len, | |||
FALSE)) { | |||
g_byte_array_set_size(out, in->len); | |||
memcpy(out->data, in->data, out->len); | |||
@@ -556,9 +556,9 @@ rspamd_mime_to_utf8_byte_array(GByteArray *in, | |||
return TRUE; | |||
} | |||
void rspamd_mime_charset_utf_enforce(gchar *in, gsize len) | |||
void rspamd_mime_charset_utf_enforce(char *in, gsize len) | |||
{ | |||
gchar *p, *end; | |||
char *p, *end; | |||
goffset err_offset; | |||
UChar32 uc = 0; | |||
@@ -568,10 +568,10 @@ void rspamd_mime_charset_utf_enforce(gchar *in, gsize len) | |||
while (p < end && len > 0 && (err_offset = rspamd_fast_utf8_validate(p, len)) > 0) { | |||
err_offset--; /* As it returns it 1 indexed */ | |||
gint32 cur_offset = err_offset; | |||
int32_t cur_offset = err_offset; | |||
while (cur_offset < len) { | |||
gint32 tmp = cur_offset; | |||
int32_t tmp = cur_offset; | |||
U8_NEXT(p, cur_offset, len, uc); | |||
@@ -594,12 +594,12 @@ void rspamd_mime_charset_utf_enforce(gchar *in, gsize len) | |||
} | |||
const char * | |||
rspamd_mime_charset_find_by_content(const gchar *in, gsize inlen, | |||
rspamd_mime_charset_find_by_content(const char *in, gsize inlen, | |||
bool check_utf8) | |||
{ | |||
int nconsumed; | |||
bool is_reliable; | |||
const gchar *ced_name; | |||
const char *ced_name; | |||
if (check_utf8) { | |||
if (rspamd_fast_utf8_validate(in, inlen) == 0) { | |||
@@ -621,13 +621,13 @@ rspamd_mime_charset_find_by_content(const gchar *in, gsize inlen, | |||
} | |||
static const char * | |||
rspamd_mime_charset_find_by_content_maybe_split(const gchar *in, gsize inlen) | |||
rspamd_mime_charset_find_by_content_maybe_split(const char *in, gsize inlen) | |||
{ | |||
if (inlen < RSPAMD_CHARSET_MAX_CONTENT * 3) { | |||
return rspamd_mime_charset_find_by_content(in, inlen, false); | |||
} | |||
else { | |||
const gchar *c1, *c2, *c3; | |||
const char *c1, *c2, *c3; | |||
c1 = rspamd_mime_charset_find_by_content(in, RSPAMD_CHARSET_MAX_CONTENT, false); | |||
c2 = rspamd_mime_charset_find_by_content(in + inlen / 2, | |||
@@ -678,9 +678,9 @@ rspamd_mime_charset_find_by_content_maybe_split(const gchar *in, gsize inlen) | |||
gboolean | |||
rspamd_mime_charset_utf_check(rspamd_ftok_t *charset, | |||
gchar *in, gsize len, gboolean content_check) | |||
char *in, gsize len, gboolean content_check) | |||
{ | |||
const gchar *real_charset; | |||
const char *real_charset; | |||
if (utf_compatible_re == NULL) { | |||
utf_compatible_re = rspamd_regexp_new( | |||
@@ -729,7 +729,7 @@ void rspamd_mime_text_part_maybe_convert(struct rspamd_task *task, | |||
struct rspamd_mime_text_part *text_part) | |||
{ | |||
GError *err = NULL; | |||
const gchar *charset = NULL; | |||
const char *charset = NULL; | |||
gboolean checked = FALSE, need_charset_heuristic = TRUE, valid_utf8 = FALSE; | |||
GByteArray *part_content; | |||
rspamd_ftok_t charset_tok; |
@@ -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, | |||
@@ -36,8 +36,8 @@ struct rspamd_charset_converter; | |||
* @param in | |||
* @return | |||
*/ | |||
const gchar *rspamd_mime_detect_charset(const rspamd_ftok_t *in, | |||
rspamd_mempool_t *pool); | |||
const char *rspamd_mime_detect_charset(const rspamd_ftok_t *in, | |||
rspamd_mempool_t *pool); | |||
/** | |||
* Convert text chunk to utf-8. Input encoding is substituted using | |||
@@ -52,9 +52,9 @@ const gchar *rspamd_mime_detect_charset(const rspamd_ftok_t *in, | |||
* @param err | |||
* @return | |||
*/ | |||
gchar *rspamd_mime_text_to_utf8(rspamd_mempool_t *pool, | |||
gchar *input, gsize len, const gchar *in_enc, | |||
gsize *olen, GError **err); | |||
char *rspamd_mime_text_to_utf8(rspamd_mempool_t *pool, | |||
char *input, gsize len, const char *in_enc, | |||
gsize *olen, GError **err); | |||
/** | |||
* Converts data from `in` to `out`, | |||
@@ -70,7 +70,7 @@ gchar *rspamd_mime_text_to_utf8(rspamd_mempool_t *pool, | |||
gboolean rspamd_mime_to_utf8_byte_array(GByteArray *in, | |||
GByteArray *out, | |||
rspamd_mempool_t *pool, | |||
const gchar *enc); | |||
const char *enc); | |||
/** | |||
* Maybe convert part to utf-8 | |||
@@ -89,7 +89,7 @@ void rspamd_mime_text_part_maybe_convert(struct rspamd_task *task, | |||
* @return | |||
*/ | |||
gboolean rspamd_mime_charset_utf_check(rspamd_ftok_t *charset, | |||
gchar *in, gsize len, | |||
char *in, gsize len, | |||
gboolean content_check); | |||
/** | |||
@@ -98,7 +98,7 @@ gboolean rspamd_mime_charset_utf_check(rspamd_ftok_t *charset, | |||
* @param in | |||
* @param len | |||
*/ | |||
void rspamd_mime_charset_utf_enforce(gchar *in, gsize len); | |||
void rspamd_mime_charset_utf_enforce(char *in, gsize len); | |||
/** | |||
* Gets cached converter | |||
@@ -109,7 +109,7 @@ void rspamd_mime_charset_utf_enforce(gchar *in, gsize len); | |||
* @return converter | |||
*/ | |||
struct rspamd_charset_converter *rspamd_mime_get_converter_cached( | |||
const gchar *enc, | |||
const char *enc, | |||
rspamd_mempool_t *pool, | |||
gboolean is_canon, | |||
UErrorCode *err); | |||
@@ -124,12 +124,12 @@ struct rspamd_charset_converter *rspamd_mime_get_converter_cached( | |||
* @param pErrorCode | |||
* @return | |||
*/ | |||
gint32 | |||
int32_t | |||
rspamd_converter_to_uchars(struct rspamd_charset_converter *cnv, | |||
UChar *dest, | |||
gint32 destCapacity, | |||
int32_t destCapacity, | |||
const char *src, | |||
gint32 srcLength, | |||
int32_t srcLength, | |||
UErrorCode *pErrorCode); | |||
/** | |||
@@ -138,7 +138,7 @@ rspamd_converter_to_uchars(struct rspamd_charset_converter *cnv, | |||
* @param inlen | |||
* @return detected charset name or NULL | |||
*/ | |||
const char *rspamd_mime_charset_find_by_content(const gchar *in, gsize inlen, | |||
const char *rspamd_mime_charset_find_by_content(const char *in, gsize inlen, | |||
bool check_utf8); | |||
#ifdef __cplusplus |
@@ -88,10 +88,10 @@ static gboolean rspamd_has_symbol_expr(struct rspamd_task *task, | |||
GArray *args, | |||
void *unused); | |||
static rspamd_expression_atom_t *rspamd_mime_expr_parse(const gchar *line, gsize len, | |||
static rspamd_expression_atom_t *rspamd_mime_expr_parse(const char *line, gsize len, | |||
rspamd_mempool_t *pool, gpointer ud, GError **err); | |||
static gdouble rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom); | |||
static gint rspamd_mime_expr_priority(rspamd_expression_atom_t *atom); | |||
static double rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom); | |||
static int rspamd_mime_expr_priority(rspamd_expression_atom_t *atom); | |||
static void rspamd_mime_expr_destroy(rspamd_expression_atom_t *atom); | |||
/** | |||
@@ -99,11 +99,11 @@ static void rspamd_mime_expr_destroy(rspamd_expression_atom_t *atom); | |||
*/ | |||
struct rspamd_regexp_atom { | |||
enum rspamd_re_type type; /**< regexp type */ | |||
gchar *regexp_text; /**< regexp text representation */ | |||
char *regexp_text; /**< regexp text representation */ | |||
rspamd_regexp_t *regexp; /**< regexp structure */ | |||
union { | |||
const gchar *header; /**< header name for header regexps */ | |||
const gchar *selector; /**< selector name for lua selector regexp */ | |||
const char *header; /**< header name for header regexps */ | |||
const char *selector; /**< selector name for lua selector regexp */ | |||
} extra; | |||
gboolean is_test; /**< true if this expression must be tested */ | |||
gboolean is_strong; /**< true if headers search must be case sensitive */ | |||
@@ -114,7 +114,7 @@ struct rspamd_regexp_atom { | |||
* Rspamd expression function | |||
*/ | |||
struct rspamd_function_atom { | |||
gchar *name; /**< name of function */ | |||
char *name; /**< name of function */ | |||
GArray *args; /**< its args */ | |||
}; | |||
@@ -126,12 +126,12 @@ enum rspamd_mime_atom_type { | |||
}; | |||
struct rspamd_mime_atom { | |||
gchar *str; | |||
char *str; | |||
union { | |||
struct rspamd_regexp_atom *re; | |||
struct rspamd_function_atom *func; | |||
const gchar *lua_function; | |||
gint lua_cbref; | |||
const char *lua_function; | |||
int lua_cbref; | |||
} d; | |||
enum rspamd_mime_atom_type type; | |||
}; | |||
@@ -141,7 +141,7 @@ struct rspamd_mime_atom { | |||
* Sorted by name to use bsearch | |||
*/ | |||
static struct _fl { | |||
const gchar *name; | |||
const char *name; | |||
rspamd_internal_func_t func; | |||
void *user_data; | |||
} rspamd_functions_list[] = { | |||
@@ -175,12 +175,12 @@ const struct rspamd_atom_subr mime_expr_subr = { | |||
.destroy = rspamd_mime_expr_destroy}; | |||
static struct _fl *list_ptr = &rspamd_functions_list[0]; | |||
static guint32 functions_number = sizeof(rspamd_functions_list) / | |||
sizeof(struct _fl); | |||
static uint32_t functions_number = sizeof(rspamd_functions_list) / | |||
sizeof(struct _fl); | |||
static gboolean list_allocated = FALSE; | |||
/* Bsearch routine */ | |||
static gint | |||
static int | |||
fl_cmp(const void *s1, const void *s2) | |||
{ | |||
struct _fl *fl1 = (struct _fl *) s1; | |||
@@ -196,7 +196,7 @@ rspamd_mime_expr_quark(void) | |||
#define TYPE_CHECK(str, type, len) (sizeof(type) - 1 == (len) && rspamd_lc_cmp((str), (type), (len)) == 0) | |||
static gboolean | |||
rspamd_parse_long_option(const gchar *start, gsize len, | |||
rspamd_parse_long_option(const char *start, gsize len, | |||
struct rspamd_regexp_atom *a) | |||
{ | |||
gboolean ret = FALSE; | |||
@@ -277,11 +277,11 @@ rspamd_parse_long_option(const gchar *start, gsize len, | |||
* Rspamd regexp utility functions | |||
*/ | |||
static struct rspamd_regexp_atom * | |||
rspamd_mime_expr_parse_regexp_atom(rspamd_mempool_t *pool, const gchar *line, | |||
rspamd_mime_expr_parse_regexp_atom(rspamd_mempool_t *pool, const char *line, | |||
struct rspamd_config *cfg) | |||
{ | |||
const gchar *begin, *end, *p, *src, *start, *brace; | |||
gchar *dbegin, *dend, *extra = NULL; | |||
const char *begin, *end, *p, *src, *start, *brace; | |||
char *dbegin, *dend, *extra = NULL; | |||
struct rspamd_regexp_atom *result; | |||
GError *err = NULL; | |||
GString *re_flags; | |||
@@ -531,11 +531,11 @@ rspamd_mime_expr_parse_regexp_atom(rspamd_mempool_t *pool, const gchar *line, | |||
} | |||
struct rspamd_function_atom * | |||
rspamd_mime_expr_parse_function_atom(rspamd_mempool_t *pool, const gchar *input) | |||
rspamd_mime_expr_parse_function_atom(rspamd_mempool_t *pool, const char *input) | |||
{ | |||
const gchar *obrace, *ebrace, *p, *c; | |||
gchar t, *databuf; | |||
guint len; | |||
const char *obrace, *ebrace, *p, *c; | |||
char t, *databuf; | |||
unsigned int len; | |||
struct rspamd_function_atom *res; | |||
struct expression_argument arg; | |||
GError *err = NULL; | |||
@@ -645,17 +645,17 @@ rspamd_mime_expr_parse_function_atom(rspamd_mempool_t *pool, const gchar *input) | |||
} | |||
static rspamd_expression_atom_t * | |||
rspamd_mime_expr_parse(const gchar *line, gsize len, | |||
rspamd_mime_expr_parse(const char *line, gsize len, | |||
rspamd_mempool_t *pool, gpointer ud, GError **err) | |||
{ | |||
rspamd_expression_atom_t *a = NULL; | |||
struct rspamd_mime_atom *mime_atom = NULL; | |||
const gchar *p, *end, *c = NULL; | |||
const char *p, *end, *c = NULL; | |||
struct rspamd_mime_expr_ud *real_ud = (struct rspamd_mime_expr_ud *) ud; | |||
struct rspamd_config *cfg; | |||
rspamd_regexp_t *own_re; | |||
gchar t; | |||
gint type = MIME_ATOM_REGEXP, obraces = 0, ebraces = 0; | |||
char t; | |||
int type = MIME_ATOM_REGEXP, obraces = 0, ebraces = 0; | |||
enum { | |||
in_header = 0, | |||
got_slash, | |||
@@ -786,8 +786,8 @@ rspamd_mime_expr_parse(const gchar *line, gsize len, | |||
g_set_error(err, rspamd_mime_expr_quark(), 100, "cannot parse" | |||
" mime atom '%s' when reading symbol '%c' at offset %d, " | |||
"near %.*s", | |||
line, t, (gint) (p - line), | |||
(gint) MIN(end - p, 10), p); | |||
line, t, (int) (p - line), | |||
(int) MIN(end - p, 10), p); | |||
return NULL; | |||
case end_atom: | |||
goto set; | |||
@@ -817,7 +817,7 @@ set: | |||
goto err; | |||
} | |||
else { | |||
gint lua_cbref = -1; | |||
int lua_cbref = -1; | |||
/* Check regexp condition */ | |||
if (real_ud->conf_obj != NULL) { | |||
@@ -1011,11 +1011,11 @@ err: | |||
return NULL; | |||
} | |||
static gint | |||
static int | |||
rspamd_mime_expr_process_regexp(struct rspamd_regexp_atom *re, | |||
struct rspamd_task *task) | |||
{ | |||
gint ret; | |||
int ret; | |||
if (re == NULL) { | |||
msg_info_task("invalid regexp passed"); | |||
@@ -1057,11 +1057,11 @@ rspamd_mime_expr_process_regexp(struct rspamd_regexp_atom *re, | |||
} | |||
static gint | |||
static int | |||
rspamd_mime_expr_priority(rspamd_expression_atom_t *atom) | |||
{ | |||
struct rspamd_mime_atom *mime_atom = atom->data; | |||
gint ret = 0; | |||
int ret = 0; | |||
switch (mime_atom->type) { | |||
case MIME_ATOM_INTERNAL_FUNCTION: | |||
@@ -1137,13 +1137,13 @@ rspamd_mime_expr_process_function(struct rspamd_function_atom *func, | |||
return selected->func(task, func->args, selected->user_data); | |||
} | |||
static gdouble | |||
static double | |||
rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom) | |||
{ | |||
struct rspamd_task *task = (struct rspamd_task *) ud; | |||
struct rspamd_mime_atom *mime_atom; | |||
lua_State *L; | |||
gdouble ret = 0; | |||
double ret = 0; | |||
g_assert(task != NULL); | |||
g_assert(atom != NULL); | |||
@@ -1181,7 +1181,7 @@ rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom) | |||
} | |||
} | |||
else if (mime_atom->type == MIME_ATOM_LOCAL_LUA_FUNCTION) { | |||
gint err_idx; | |||
int err_idx; | |||
L = task->cfg->lua_state; | |||
lua_pushcfunction(L, &rspamd_lua_traceback); | |||
@@ -1218,7 +1218,7 @@ rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom) | |||
return ret; | |||
} | |||
void register_expression_function(const gchar *name, | |||
void register_expression_function(const char *name, | |||
rspamd_internal_func_t func, | |||
void *user_data) | |||
{ | |||
@@ -1276,9 +1276,9 @@ rspamd_header_exists(struct rspamd_task *task, GArray *args, void *unused) | |||
} | |||
rh = rspamd_message_get_header_array(task, | |||
(gchar *) arg->data, FALSE); | |||
(char *) arg->data, FALSE); | |||
debug_task("try to get header %s: %d", (gchar *) arg->data, | |||
debug_task("try to get header %s: %d", (char *) arg->data, | |||
(rh != NULL)); | |||
if (rh) { | |||
@@ -1298,9 +1298,9 @@ rspamd_header_exists(struct rspamd_task *task, GArray *args, void *unused) | |||
gboolean | |||
rspamd_parts_distance(struct rspamd_task *task, GArray *args, void *unused) | |||
{ | |||
gint threshold, threshold2 = -1; | |||
int threshold, threshold2 = -1; | |||
struct expression_argument *arg; | |||
gdouble *pdiff, diff; | |||
double *pdiff, diff; | |||
if (args == NULL || args->len == 0) { | |||
debug_task("no threshold is specified, assume it 100"); | |||
@@ -1314,10 +1314,10 @@ rspamd_parts_distance(struct rspamd_task *task, GArray *args, void *unused) | |||
return FALSE; | |||
} | |||
threshold = strtoul((gchar *) arg->data, NULL, 10); | |||
threshold = strtoul((char *) arg->data, NULL, 10); | |||
if (errno != 0) { | |||
msg_info_task("bad numeric value for threshold \"%s\", assume it 100", | |||
(gchar *) arg->data); | |||
(char *) arg->data); | |||
threshold = 100; | |||
} | |||
if (args->len >= 2) { | |||
@@ -1328,10 +1328,10 @@ rspamd_parts_distance(struct rspamd_task *task, GArray *args, void *unused) | |||
} | |||
errno = 0; | |||
threshold2 = strtoul((gchar *) arg->data, NULL, 10); | |||
threshold2 = strtoul((char *) arg->data, NULL, 10); | |||
if (errno != 0) { | |||
msg_info_task("bad numeric value for threshold \"%s\", ignore it", | |||
(gchar *) arg->data); | |||
(char *) arg->data); | |||
threshold2 = -1; | |||
} | |||
} | |||
@@ -1366,13 +1366,13 @@ rspamd_parts_distance(struct rspamd_task *task, GArray *args, void *unused) | |||
} | |||
struct addr_list { | |||
const gchar *name; | |||
guint namelen; | |||
const gchar *addr; | |||
guint addrlen; | |||
const char *name; | |||
unsigned int namelen; | |||
const char *addr; | |||
unsigned int addrlen; | |||
}; | |||
static gint | |||
static int | |||
addr_list_cmp_func(const void *a, const void *b) | |||
{ | |||
const struct addr_list *addra = (struct addr_list *) a, | |||
@@ -1396,7 +1396,7 @@ rspamd_recipients_distance(struct rspamd_task *task, GArray *args, | |||
struct rspamd_email_address *cur; | |||
double threshold; | |||
struct addr_list *ar; | |||
gint num, i, hits = 0; | |||
int num, i, hits = 0; | |||
if (args == NULL) { | |||
msg_warn_task("no parameters to function"); | |||
@@ -1410,11 +1410,11 @@ rspamd_recipients_distance(struct rspamd_task *task, GArray *args, | |||
} | |||
errno = 0; | |||
threshold = strtod((gchar *) arg->data, NULL); | |||
threshold = strtod((char *) arg->data, NULL); | |||
if (errno != 0) { | |||
msg_warn_task("invalid numeric value '%s': %s", | |||
(gchar *) arg->data, | |||
(char *) arg->data, | |||
strerror(errno)); | |||
return FALSE; | |||
} | |||
@@ -1469,7 +1469,7 @@ rspamd_has_only_html_part(struct rspamd_task *task, GArray *args, | |||
void *unused) | |||
{ | |||
struct rspamd_mime_text_part *p; | |||
guint i, cnt_html = 0, cnt_txt = 0; | |||
unsigned int i, cnt_html = 0, cnt_txt = 0; | |||
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, p) | |||
{ | |||
@@ -1492,7 +1492,7 @@ is_recipient_list_sorted(GPtrArray *ar) | |||
struct rspamd_email_address *addr; | |||
gboolean res = TRUE; | |||
rspamd_ftok_t cur, prev; | |||
gint i; | |||
int i; | |||
/* Do not check to short address lists */ | |||
if (ar == NULL || ar->len < MIN_RCPT_TO_COMPARE) { | |||
@@ -1540,7 +1540,7 @@ rspamd_compare_transfer_encoding(struct rspamd_task *task, | |||
void *unused) | |||
{ | |||
struct expression_argument *arg; | |||
guint i; | |||
unsigned int i; | |||
struct rspamd_mime_part *part; | |||
enum rspamd_cte cte; | |||
@@ -1586,7 +1586,7 @@ rspamd_has_html_tag(struct rspamd_task *task, GArray *args, void *unused) | |||
{ | |||
struct rspamd_mime_text_part *p; | |||
struct expression_argument *arg; | |||
guint i; | |||
unsigned int i; | |||
gboolean res = FALSE; | |||
if (args == NULL) { | |||
@@ -1618,7 +1618,7 @@ gboolean | |||
rspamd_has_fake_html(struct rspamd_task *task, GArray *args, void *unused) | |||
{ | |||
struct rspamd_mime_text_part *p; | |||
guint i; | |||
unsigned int i; | |||
gboolean res = FALSE; | |||
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, p) | |||
@@ -1656,10 +1656,10 @@ rspamd_raw_header_exists(struct rspamd_task *task, GArray *args, void *unused) | |||
static gboolean | |||
match_smtp_data(struct rspamd_task *task, | |||
struct expression_argument *arg, | |||
const gchar *what, gsize len) | |||
const char *what, gsize len) | |||
{ | |||
rspamd_regexp_t *re; | |||
gint r = 0; | |||
int r = 0; | |||
if (arg->type == EXPRESSION_ARGUMENT_REGEXP) { | |||
/* This is a regexp */ | |||
@@ -1690,8 +1690,8 @@ rspamd_check_smtp_data(struct rspamd_task *task, GArray *args, void *unused) | |||
struct expression_argument *arg; | |||
struct rspamd_email_address *addr = NULL; | |||
GPtrArray *rcpts = NULL; | |||
const gchar *type, *str = NULL; | |||
guint i; | |||
const char *type, *str = NULL; | |||
unsigned int i; | |||
if (args == NULL) { | |||
msg_warn_task("no parameters to function"); | |||
@@ -1799,7 +1799,7 @@ rspamd_check_smtp_data(struct rspamd_task *task, GArray *args, void *unused) | |||
} | |||
static inline gboolean | |||
rspamd_check_ct_attr(const gchar *begin, gsize len, | |||
rspamd_check_ct_attr(const char *begin, gsize len, | |||
struct expression_argument *arg_pattern) | |||
{ | |||
rspamd_regexp_t *re; | |||
@@ -1840,10 +1840,10 @@ rspamd_content_type_compare_param(struct rspamd_task *task, | |||
struct expression_argument *arg, *arg1, *arg_pattern; | |||
gboolean recursive = FALSE; | |||
struct rspamd_mime_part *cur_part; | |||
guint i; | |||
unsigned int i; | |||
rspamd_ftok_t srch; | |||
struct rspamd_content_type_param *found = NULL, *cur; | |||
const gchar *param_name; | |||
const char *param_name; | |||
if (args == NULL || args->len < 2) { | |||
msg_warn_task("no parameters to function"); | |||
@@ -1923,10 +1923,10 @@ rspamd_content_type_has_param(struct rspamd_task *task, | |||
struct expression_argument *arg, *arg1; | |||
gboolean recursive = FALSE; | |||
struct rspamd_mime_part *cur_part; | |||
guint i; | |||
unsigned int i; | |||
rspamd_ftok_t srch; | |||
struct rspamd_content_type_param *found = NULL; | |||
const gchar *param_name; | |||
const char *param_name; | |||
if (args == NULL || args->len < 1) { | |||
msg_warn_task("no parameters to function"); | |||
@@ -1999,8 +1999,8 @@ rspamd_content_type_check(struct rspamd_task *task, | |||
rspamd_regexp_t *re; | |||
struct expression_argument *arg1, *arg_pattern; | |||
struct rspamd_content_type *ct; | |||
gint r = 0; | |||
guint i; | |||
int r = 0; | |||
unsigned int i; | |||
gboolean recursive = FALSE; | |||
struct rspamd_mime_part *cur_part; | |||
@@ -2092,7 +2092,7 @@ compare_subtype(struct rspamd_task *task, struct rspamd_content_type *ct, | |||
{ | |||
rspamd_regexp_t *re; | |||
rspamd_ftok_t srch; | |||
gint r = 0; | |||
int r = 0; | |||
if (subtype == NULL || ct == NULL) { | |||
msg_warn_task("invalid parameters passed"); | |||
@@ -2120,7 +2120,7 @@ compare_subtype(struct rspamd_task *task, struct rspamd_content_type *ct, | |||
} | |||
static gboolean | |||
compare_len(struct rspamd_mime_part *part, guint min, guint max) | |||
compare_len(struct rspamd_mime_part *part, unsigned int min, unsigned int max) | |||
{ | |||
if (min == 0 && max == 0) { | |||
return TRUE; | |||
@@ -2141,15 +2141,15 @@ static gboolean | |||
common_has_content_part(struct rspamd_task *task, | |||
struct expression_argument *param_type, | |||
struct expression_argument *param_subtype, | |||
gint min_len, | |||
gint max_len) | |||
int min_len, | |||
int max_len) | |||
{ | |||
rspamd_regexp_t *re; | |||
struct rspamd_mime_part *part; | |||
struct rspamd_content_type *ct; | |||
rspamd_ftok_t srch; | |||
gint r = 0; | |||
guint i; | |||
int r = 0; | |||
unsigned int i; | |||
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) | |||
{ | |||
@@ -2224,7 +2224,7 @@ rspamd_has_content_part_len(struct rspamd_task *task, | |||
void *unused) | |||
{ | |||
struct expression_argument *param_type = NULL, *param_subtype = NULL; | |||
gint min = 0, max = 0; | |||
int min = 0, max = 0; | |||
struct expression_argument *arg; | |||
if (args == NULL) { | |||
@@ -2245,7 +2245,7 @@ rspamd_has_content_part_len(struct rspamd_task *task, | |||
if (errno != 0) { | |||
msg_warn_task("invalid numeric value '%s': %s", | |||
(gchar *) arg->data, | |||
(char *) arg->data, | |||
strerror(errno)); | |||
return FALSE; | |||
} | |||
@@ -2257,7 +2257,7 @@ rspamd_has_content_part_len(struct rspamd_task *task, | |||
if (errno != 0) { | |||
msg_warn_task("invalid numeric value '%s': %s", | |||
(gchar *) arg->data, | |||
(char *) arg->data, | |||
strerror(errno)); | |||
return FALSE; | |||
} | |||
@@ -2274,7 +2274,7 @@ rspamd_is_empty_body(struct rspamd_task *task, | |||
void *unused) | |||
{ | |||
struct rspamd_mime_part *part; | |||
guint i; | |||
unsigned int i; | |||
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part) | |||
{ | |||
@@ -2320,7 +2320,7 @@ rspamd_has_flag_expr(struct rspamd_task *task, | |||
{ | |||
gboolean found = FALSE, result = FALSE; | |||
struct expression_argument *flag_arg; | |||
const gchar *flag_str; | |||
const char *flag_str; | |||
if (args == NULL) { | |||
msg_warn_task("no parameters to function"); | |||
@@ -2334,7 +2334,7 @@ rspamd_has_flag_expr(struct rspamd_task *task, | |||
return FALSE; | |||
} | |||
flag_str = (const gchar *) flag_arg->data; | |||
flag_str = (const char *) flag_arg->data; | |||
TASK_GET_FLAG(flag_str, "pass_all", RSPAMD_TASK_FLAG_PASS_ALL); | |||
TASK_GET_FLAG(flag_str, "no_log", RSPAMD_TASK_FLAG_NO_LOG); | |||
@@ -2368,7 +2368,7 @@ rspamd_has_symbol_expr(struct rspamd_task *task, | |||
void *unused) | |||
{ | |||
struct expression_argument *sym_arg; | |||
const gchar *symbol_str; | |||
const char *symbol_str; | |||
if (args == NULL) { | |||
msg_warn_task("no parameters to function"); | |||
@@ -2382,7 +2382,7 @@ rspamd_has_symbol_expr(struct rspamd_task *task, | |||
return FALSE; | |||
} | |||
symbol_str = (const gchar *) sym_arg->data; | |||
symbol_str = (const char *) sym_arg->data; | |||
if (rspamd_task_find_symbol_result(task, symbol_str, NULL)) { | |||
return TRUE; |
@@ -47,7 +47,7 @@ typedef gboolean (*rspamd_internal_func_t)(struct rspamd_task *, | |||
* @param name name of function | |||
* @param func pointer to function | |||
*/ | |||
void register_expression_function(const gchar *name, | |||
void register_expression_function(const char *name, | |||
rspamd_internal_func_t func, | |||
void *user_data); | |||
@@ -56,7 +56,7 @@ void register_expression_function(const gchar *name, | |||
* @param limit new limit in bytes | |||
* @return old limit value | |||
*/ | |||
guint rspamd_mime_expression_set_re_limit(guint limit); | |||
unsigned int rspamd_mime_expression_set_re_limit(unsigned int limit); | |||
#ifdef __cplusplus | |||
} |
@@ -24,7 +24,7 @@ | |||
#include "libutil/util.h" | |||
#include <unicode/utf8.h> | |||
KHASH_INIT(rspamd_mime_headers_htb, gchar *, | |||
KHASH_INIT(rspamd_mime_headers_htb, char *, | |||
struct rspamd_mime_header *, 1, | |||
rspamd_strcase_hash, rspamd_strcase_equal); | |||
@@ -37,10 +37,10 @@ static void | |||
rspamd_mime_header_check_special(struct rspamd_task *task, | |||
struct rspamd_mime_header *rh) | |||
{ | |||
guint64 h; | |||
const gchar *p, *end; | |||
gchar *id; | |||
gint max_recipients = -1, len; | |||
uint64_t h; | |||
const char *p, *end; | |||
char *id; | |||
int max_recipients = -1, len; | |||
if (task->cfg) { | |||
max_recipients = task->cfg->max_recipients; | |||
@@ -93,7 +93,7 @@ rspamd_mime_header_check_special(struct rspamd_task *task, | |||
} | |||
if (end > p) { | |||
gchar *d; | |||
char *d; | |||
if (*(end - 1) == '>') { | |||
end--; | |||
@@ -186,16 +186,16 @@ rspamd_mime_header_add(struct rspamd_task *task, | |||
void rspamd_mime_headers_process(struct rspamd_task *task, | |||
struct rspamd_mime_headers_table *target, | |||
struct rspamd_mime_header **order_ptr, | |||
const gchar *in, gsize len, | |||
const char *in, gsize len, | |||
gboolean check_newlines) | |||
{ | |||
struct rspamd_mime_header *nh = NULL; | |||
const gchar *p, *c, *end; | |||
gchar *tmp, *tp; | |||
gint state = 0, l, next_state = 100, err_state = 100, t_state; | |||
const char *p, *c, *end; | |||
char *tmp, *tp; | |||
int state = 0, l, next_state = 100, err_state = 100, t_state; | |||
gboolean valid_folding = FALSE, shift_by_one = FALSE; | |||
guint nlines_count[RSPAMD_TASK_NEWLINES_MAX]; | |||
guint norder = 0; | |||
unsigned int nlines_count[RSPAMD_TASK_NEWLINES_MAX]; | |||
unsigned int norder = 0; | |||
p = in; | |||
end = p + len; | |||
@@ -485,12 +485,12 @@ void rspamd_mime_headers_process(struct rspamd_task *task, | |||
LL_REVERSE(*order_ptr); | |||
if (check_newlines) { | |||
guint max_cnt = 0; | |||
gint sel = 0; | |||
unsigned int max_cnt = 0; | |||
int sel = 0; | |||
rspamd_cryptobox_hash_state_t hs; | |||
guchar hout[rspamd_cryptobox_HASHBYTES], *hexout; | |||
unsigned char hout[rspamd_cryptobox_HASHBYTES], *hexout; | |||
for (gint i = RSPAMD_TASK_NEWLINES_CR; i < RSPAMD_TASK_NEWLINES_MAX; i++) { | |||
for (int i = RSPAMD_TASK_NEWLINES_CR; i < RSPAMD_TASK_NEWLINES_MAX; i++) { | |||
if (nlines_count[i] > max_cnt) { | |||
max_cnt = nlines_count[i]; | |||
sel = i; | |||
@@ -572,7 +572,7 @@ static void | |||
rspamd_mime_header_sanity_check(GString *str) | |||
{ | |||
gsize i; | |||
gchar t; | |||
char t; | |||
for (i = 0; i < str->len; i++) { | |||
t = str->str[i]; | |||
@@ -588,20 +588,20 @@ rspamd_mime_header_sanity_check(GString *str) | |||
} | |||
} | |||
gchar * | |||
rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in, | |||
char * | |||
rspamd_mime_header_decode(rspamd_mempool_t *pool, const char *in, | |||
gsize inlen, gboolean *invalid_utf) | |||
{ | |||
GString *out; | |||
const guchar *c, *p, *end; | |||
const gchar *tok_start = NULL; | |||
const unsigned char *c, *p, *end; | |||
const char *tok_start = NULL; | |||
gsize tok_len = 0, pos; | |||
GByteArray *token = NULL, *decoded; | |||
rspamd_ftok_t cur_charset = {0, NULL}, old_charset = {0, NULL}; | |||
gint encoding; | |||
int encoding; | |||
gssize r; | |||
guint qmarks = 0; | |||
gchar *ret; | |||
unsigned int qmarks = 0; | |||
char *ret; | |||
enum { | |||
parse_normal = 0, | |||
got_eqsign, | |||
@@ -628,7 +628,7 @@ rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in, | |||
state = got_eqsign; | |||
} | |||
else if (*p >= 128) { | |||
gint off = 0; | |||
int off = 0; | |||
UChar32 uc; | |||
/* Unencoded character */ | |||
g_string_append_len(out, c, p - c); | |||
@@ -815,17 +815,17 @@ rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in, | |||
return ret; | |||
} | |||
gchar * | |||
rspamd_mime_header_encode(const gchar *in, gsize len) | |||
char * | |||
rspamd_mime_header_encode(const char *in, gsize len) | |||
{ | |||
const gchar *p = in, *end = in + len; | |||
gchar *out, encode_buf[80 * sizeof(guint32)]; | |||
const char *p = in, *end = in + len; | |||
char *out, encode_buf[80 * sizeof(uint32_t)]; | |||
GString *res; | |||
gboolean need_encoding = FALSE; | |||
/* Check if we need to encode */ | |||
while (p < end) { | |||
if ((((guchar) *p) & 0x80) != 0) { | |||
if ((((unsigned char) *p) & 0x80) != 0) { | |||
need_encoding = TRUE; | |||
break; | |||
} | |||
@@ -839,17 +839,17 @@ rspamd_mime_header_encode(const gchar *in, gsize len) | |||
else { | |||
/* Need encode */ | |||
gsize ulen, pos; | |||
gint r; | |||
const gchar *prev; | |||
int r; | |||
const char *prev; | |||
/* Choose step: =?UTF-8?Q?<qp>?= should be less than 76 chars */ | |||
guint step = (76 - 12) / 3 + 1; | |||
unsigned int step = (76 - 12) / 3 + 1; | |||
ulen = g_utf8_strlen(in, len); | |||
res = g_string_sized_new(len * 2 + 1); | |||
pos = 0; | |||
prev = in; | |||
/* Adjust chunk size for unicode average length */ | |||
step *= 1.0 * ulen / (gdouble) len; | |||
step *= 1.0 * ulen / (double) len; | |||
while (pos < ulen) { | |||
p = g_utf8_offset_to_pointer(in, pos); | |||
@@ -898,19 +898,19 @@ rspamd_mime_header_encode(const gchar *in, gsize len) | |||
return out; | |||
} | |||
gchar * | |||
rspamd_mime_message_id_generate(const gchar *fqdn) | |||
char * | |||
rspamd_mime_message_id_generate(const char *fqdn) | |||
{ | |||
GString *out; | |||
guint64 rnd, clk; | |||
uint64_t rnd, clk; | |||
out = g_string_sized_new(strlen(fqdn) + 22); | |||
rnd = ottery_rand_uint64(); | |||
clk = rspamd_get_calendar_ticks() * 1e6; | |||
rspamd_printf_gstring(out, "%*bs.%*bs@%s", | |||
(gint) sizeof(guint64) - 3, (guchar *) &clk, | |||
(gint) sizeof(guint64), (gchar *) &rnd, | |||
(int) sizeof(uint64_t) - 3, (unsigned char *) &clk, | |||
(int) sizeof(uint64_t), (char *) &rnd, | |||
fqdn); | |||
return g_string_free(out, FALSE); | |||
@@ -918,7 +918,7 @@ rspamd_mime_message_id_generate(const gchar *fqdn) | |||
struct rspamd_mime_header * | |||
rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs, | |||
const gchar *field, | |||
const char *field, | |||
gboolean need_modified) | |||
{ | |||
if (hdrs == NULL) { | |||
@@ -930,7 +930,7 @@ rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs, | |||
struct rspamd_mime_header *hdr; | |||
if (htb) { | |||
k = kh_get(rspamd_mime_headers_htb, htb, (gchar *) field); | |||
k = kh_get(rspamd_mime_headers_htb, htb, (char *) field); | |||
if (k == kh_end(htb)) { | |||
return NULL; | |||
@@ -958,7 +958,7 @@ rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs, | |||
} | |||
struct rspamd_mime_header * | |||
rspamd_message_get_header_array(struct rspamd_task *task, const gchar *field, | |||
rspamd_message_get_header_array(struct rspamd_task *task, const char *field, | |||
gboolean need_modified) | |||
{ | |||
return rspamd_message_get_header_from_hash( | |||
@@ -978,7 +978,7 @@ gsize rspamd_mime_headers_count(struct rspamd_mime_headers_table *hdrs) | |||
bool rspamd_mime_headers_foreach(const struct rspamd_mime_headers_table *hdrs, | |||
rspamd_hdr_traverse_func_t func, void *ud) | |||
{ | |||
const gchar *name; | |||
const char *name; | |||
struct rspamd_mime_header *hdr; | |||
kh_foreach(&hdrs->htb, name, hdr, { | |||
@@ -1097,7 +1097,7 @@ gsize rspamd_message_header_unfold_inplace(char *hdr, gsize len) | |||
void rspamd_message_set_modified_header(struct rspamd_task *task, | |||
struct rspamd_mime_headers_table *hdrs, | |||
const gchar *hdr_name, | |||
const char *hdr_name, | |||
const ucl_object_t *obj, | |||
struct rspamd_mime_header **order_ptr) | |||
{ | |||
@@ -1107,7 +1107,7 @@ void rspamd_message_set_modified_header(struct rspamd_task *task, | |||
int i; | |||
if (htb) { | |||
k = kh_get(rspamd_mime_headers_htb, htb, (gchar *) hdr_name); | |||
k = kh_get(rspamd_mime_headers_htb, htb, (char *) hdr_name); | |||
if (k == kh_end(htb)) { | |||
hdr_elt = rspamd_mempool_alloc0(task->task_pool, sizeof(*hdr_elt)); | |||
@@ -1353,7 +1353,7 @@ void rspamd_message_set_modified_header(struct rspamd_task *task, | |||
} | |||
} | |||
gsize rspamd_strip_smtp_comments_inplace(gchar *input, gsize len) | |||
gsize rspamd_strip_smtp_comments_inplace(char *input, gsize len) | |||
{ | |||
enum parser_state { | |||
parse_normal, | |||
@@ -1363,8 +1363,8 @@ gsize rspamd_strip_smtp_comments_inplace(gchar *input, gsize len) | |||
parse_quoted_ignore, | |||
} state = parse_normal, | |||
next_state = parse_normal; | |||
gchar *d = input, *end = input + len, *start = input; | |||
gchar t; | |||
char *d = input, *end = input + len, *start = input; | |||
char t; | |||
int obraces = 0, ebraces = 0; | |||
while (input < end) { |
@@ -56,15 +56,15 @@ enum rspamd_mime_header_flags { | |||
}; | |||
struct rspamd_mime_header { | |||
const gchar *raw_value; /* As it is in the message (unfolded and unparsed) */ | |||
const char *raw_value; /* As it is in the message (unfolded and unparsed) */ | |||
gsize raw_len; | |||
guint order; | |||
unsigned int order; | |||
int flags; /* see enum rspamd_mime_header_flags */ | |||
/* These are zero terminated (historically) */ | |||
gchar *name; /* Also used for key */ | |||
gchar *value; | |||
gchar *separator; | |||
gchar *decoded; | |||
char *name; /* Also used for key */ | |||
char *value; | |||
char *separator; | |||
char *decoded; | |||
struct rspamd_mime_header *modified_chain; /* Headers modified during transform */ | |||
struct rspamd_mime_header *prev, *next; /* Headers with the same name */ | |||
struct rspamd_mime_header *ord_next; /* Overall order of headers, slist */ | |||
@@ -83,7 +83,7 @@ struct rspamd_mime_headers_table; | |||
void rspamd_mime_headers_process(struct rspamd_task *task, | |||
struct rspamd_mime_headers_table *target, | |||
struct rspamd_mime_header **order_ptr, | |||
const gchar *in, gsize len, | |||
const char *in, gsize len, | |||
gboolean check_newlines); | |||
/** | |||
@@ -93,8 +93,8 @@ void rspamd_mime_headers_process(struct rspamd_task *task, | |||
* @param inlen | |||
* @return | |||
*/ | |||
gchar *rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in, | |||
gsize inlen, gboolean *invalid_utf); | |||
char *rspamd_mime_header_decode(rspamd_mempool_t *pool, const char *in, | |||
gsize inlen, gboolean *invalid_utf); | |||
/** | |||
* Encode mime header if needed | |||
@@ -102,14 +102,14 @@ gchar *rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in, | |||
* @param len | |||
* @return newly allocated encoded header | |||
*/ | |||
gchar *rspamd_mime_header_encode(const gchar *in, gsize len); | |||
char *rspamd_mime_header_encode(const char *in, gsize len); | |||
/** | |||
* Generate new unique message id | |||
* @param fqdn | |||
* @return | |||
*/ | |||
gchar *rspamd_mime_message_id_generate(const gchar *fqdn); | |||
char *rspamd_mime_message_id_generate(const char *fqdn); | |||
/** | |||
* Get an array of header's values with specified header's name using raw headers | |||
@@ -119,7 +119,7 @@ gchar *rspamd_mime_message_id_generate(const gchar *fqdn); | |||
*/ | |||
struct rspamd_mime_header * | |||
rspamd_message_get_header_array(struct rspamd_task *task, | |||
const gchar *field, | |||
const char *field, | |||
gboolean need_modified); | |||
/** | |||
@@ -130,7 +130,7 @@ rspamd_message_get_header_array(struct rspamd_task *task, | |||
*/ | |||
struct rspamd_mime_header * | |||
rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs, | |||
const gchar *field, | |||
const char *field, | |||
gboolean need_modified); | |||
/** | |||
@@ -142,7 +142,7 @@ rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs, | |||
*/ | |||
void rspamd_message_set_modified_header(struct rspamd_task *task, | |||
struct rspamd_mime_headers_table *hdrs, | |||
const gchar *hdr_name, | |||
const char *hdr_name, | |||
const ucl_object_t *obj, | |||
struct rspamd_mime_header **order_ptr); | |||
@@ -167,7 +167,7 @@ struct rspamd_mime_headers_table *rspamd_message_headers_new(void); | |||
*/ | |||
gsize rspamd_mime_headers_count(struct rspamd_mime_headers_table *hdrs); | |||
typedef bool(rspamd_hdr_traverse_func_t)(const gchar *, const struct rspamd_mime_header *, void *); | |||
typedef bool(rspamd_hdr_traverse_func_t)(const char *, const struct rspamd_mime_header *, void *); | |||
/** | |||
* Traverse all headers in a table | |||
* @param func | |||
@@ -183,7 +183,7 @@ bool rspamd_mime_headers_foreach(const struct rspamd_mime_headers_table *, | |||
* @param len length of the input | |||
* @return new length of the input | |||
*/ | |||
gsize rspamd_strip_smtp_comments_inplace(gchar *input, gsize len); | |||
gsize rspamd_strip_smtp_comments_inplace(char *input, gsize len); | |||
/** | |||
* Unfold header in place |
@@ -29,14 +29,14 @@ | |||
struct rspamd_mime_parser_lib_ctx { | |||
struct rspamd_multipattern *mp_boundary; | |||
guchar hkey[rspamd_cryptobox_SIPKEYBYTES]; /* Key for hashing */ | |||
guint key_usages; | |||
unsigned char hkey[rspamd_cryptobox_SIPKEYBYTES]; /* Key for hashing */ | |||
unsigned int key_usages; | |||
}; | |||
struct rspamd_mime_parser_lib_ctx *lib_ctx = NULL; | |||
static const guint max_nested = 64; | |||
static const guint max_key_usages = 10000; | |||
static const unsigned int max_nested = 64; | |||
static const unsigned int max_key_usages = 10000; | |||
#define msg_debug_mime(...) rspamd_conditional_debug_fast(NULL, task->from_addr, \ | |||
rspamd_mime_log_id, "mime", task->task_pool->tag.uid, \ | |||
@@ -51,19 +51,19 @@ INIT_LOG_MODULE(mime) | |||
struct rspamd_mime_boundary { | |||
goffset boundary; | |||
goffset start; | |||
guint64 hash; | |||
guint64 closed_hash; | |||
gint flags; | |||
uint64_t hash; | |||
uint64_t closed_hash; | |||
int flags; | |||
}; | |||
struct rspamd_mime_parser_ctx { | |||
GPtrArray *stack; /* Stack of parts */ | |||
GArray *boundaries; /* Boundaries found in the whole message */ | |||
const gchar *start; | |||
const gchar *pos; | |||
const gchar *end; | |||
const char *start; | |||
const char *pos; | |||
const char *end; | |||
struct rspamd_task *task; | |||
guint nesting; | |||
unsigned int nesting; | |||
}; | |||
static enum rspamd_mime_parse_error | |||
@@ -87,7 +87,7 @@ static enum rspamd_mime_parse_error | |||
rspamd_mime_process_multipart_node(struct rspamd_task *task, | |||
struct rspamd_mime_parser_ctx *st, | |||
struct rspamd_mime_part *multipart, | |||
const gchar *start, const gchar *end, | |||
const char *start, const char *end, | |||
gboolean is_finished, | |||
GError **err); | |||
@@ -99,10 +99,10 @@ rspamd_mime_parser_quark(void) | |||
return g_quark_from_static_string("mime-parser"); | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_cte_to_string(enum rspamd_cte ct) | |||
{ | |||
const gchar *ret = "unknown"; | |||
const char *ret = "unknown"; | |||
switch (ct) { | |||
case RSPAMD_CTE_7BIT: | |||
@@ -128,7 +128,7 @@ rspamd_cte_to_string(enum rspamd_cte ct) | |||
} | |||
enum rspamd_cte | |||
rspamd_cte_from_string(const gchar *str) | |||
rspamd_cte_from_string(const char *str) | |||
{ | |||
enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN; | |||
@@ -178,9 +178,9 @@ rspamd_mime_parser_init_lib(void) | |||
} | |||
static enum rspamd_cte | |||
rspamd_mime_parse_cte(const gchar *in, gsize len) | |||
rspamd_mime_parse_cte(const char *in, gsize len) | |||
{ | |||
guint64 h; | |||
uint64_t h; | |||
enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN; | |||
in = rspamd_string_len_strip(in, &len, " \t;,.+-#!`~'"); | |||
@@ -216,15 +216,15 @@ static enum rspamd_cte | |||
rspamd_mime_part_get_cte_heuristic(struct rspamd_task *task, | |||
struct rspamd_mime_part *part) | |||
{ | |||
const guint check_len = 128; | |||
guint real_len, nspaces = 0, neqsign = 0, n8bit = 0, nqpencoded = 0, | |||
padeqsign = 0, nupper = 0, nlower = 0; | |||
const unsigned int check_len = 128; | |||
unsigned int real_len, nspaces = 0, neqsign = 0, n8bit = 0, nqpencoded = 0, | |||
padeqsign = 0, nupper = 0, nlower = 0; | |||
gboolean b64_chars = TRUE; | |||
const guchar *p, *end; | |||
const unsigned char *p, *end; | |||
enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN; | |||
real_len = MIN(check_len, part->raw_data.len); | |||
p = (const guchar *) part->raw_data.begin; | |||
p = (const unsigned char *) part->raw_data.begin; | |||
end = p + part->raw_data.len; | |||
while (p < end && g_ascii_isspace(*p)) { | |||
@@ -232,7 +232,7 @@ rspamd_mime_part_get_cte_heuristic(struct rspamd_task *task, | |||
} | |||
if (end - p > sizeof("begin-base64 ")) { | |||
const guchar *uue_start; | |||
const unsigned char *uue_start; | |||
if (memcmp(p, "begin ", sizeof("begin ") - 1) == 0) { | |||
uue_start = p + sizeof("begin ") - 1; | |||
@@ -342,7 +342,7 @@ rspamd_mime_part_get_cte_heuristic(struct rspamd_task *task, | |||
} | |||
else { | |||
if (((end - (const guchar *) part->raw_data.begin) + padeqsign) % 4 == 0) { | |||
if (((end - (const unsigned char *) part->raw_data.begin) + padeqsign) % 4 == 0) { | |||
if (padeqsign == 0) { | |||
/* | |||
* It can be either base64 or plain text, hard to say | |||
@@ -421,7 +421,7 @@ rspamd_mime_part_get_cte(struct rspamd_task *task, | |||
DL_FOREACH(hdr, cur) | |||
{ | |||
gsize hlen; | |||
gchar lc_buf[128]; | |||
char lc_buf[128]; | |||
hlen = rspamd_snprintf(lc_buf, sizeof(lc_buf), "%s", cur->value); | |||
rspamd_str_lc(lc_buf, hlen); | |||
@@ -571,7 +571,7 @@ rspamd_mime_part_get_cd(struct rspamd_task *task, struct rspamd_mime_part *part) | |||
void rspamd_mime_parser_calc_digest(struct rspamd_mime_part *part) | |||
{ | |||
/* Blake2b applied to string 'rspamd' */ | |||
static const guchar hash_key[] = { | |||
static const unsigned char hash_key[] = { | |||
0xef, | |||
0x43, | |||
0xae, | |||
@@ -815,8 +815,8 @@ rspamd_mime_parse_normal_part(struct rspamd_task *task, | |||
* Since ASN.1 structures are freed, we need to copy | |||
* the content | |||
*/ | |||
gchar *cpy = rspamd_mempool_alloc(task->task_pool, | |||
p7_signed_content->d.data->length); | |||
char *cpy = rspamd_mempool_alloc(task->task_pool, | |||
p7_signed_content->d.data->length); | |||
memcpy(cpy, p7_signed_content->d.data->data, | |||
p7_signed_content->d.data->length); | |||
ret = rspamd_mime_process_multipart_node(task, | |||
@@ -849,9 +849,9 @@ struct rspamd_mime_multipart_cbdata { | |||
struct rspamd_task *task; | |||
struct rspamd_mime_part *multipart; | |||
struct rspamd_mime_parser_ctx *st; | |||
const gchar *part_start; | |||
const char *part_start; | |||
rspamd_ftok_t *cur_boundary; | |||
guint64 bhash; | |||
uint64_t bhash; | |||
GError **err; | |||
}; | |||
@@ -859,7 +859,7 @@ static enum rspamd_mime_parse_error | |||
rspamd_mime_process_multipart_node(struct rspamd_task *task, | |||
struct rspamd_mime_parser_ctx *st, | |||
struct rspamd_mime_part *multipart, | |||
const gchar *start, const gchar *end, | |||
const char *start, const char *end, | |||
gboolean is_finished, | |||
GError **err) | |||
{ | |||
@@ -871,7 +871,7 @@ rspamd_mime_process_multipart_node(struct rspamd_task *task, | |||
enum rspamd_mime_parse_error ret = RSPAMD_MIME_PARSE_FATAL; | |||
str.str = (gchar *) start; | |||
str.str = (char *) start; | |||
str.len = end - start; | |||
if (*start == '\n' || *start == '\r') { | |||
@@ -885,7 +885,7 @@ rspamd_mime_process_multipart_node(struct rspamd_task *task, | |||
if (!is_finished) { | |||
/* Ignore garbage */ | |||
const gchar *p = start; | |||
const char *p = start; | |||
gboolean seen_something = FALSE; | |||
while (p < end) { | |||
@@ -1009,7 +1009,7 @@ rspamd_mime_parse_multipart_cb(struct rspamd_task *task, | |||
struct rspamd_mime_multipart_cbdata *cb, | |||
struct rspamd_mime_boundary *b) | |||
{ | |||
const gchar *pos = st->start + b->boundary; | |||
const char *pos = st->start + b->boundary; | |||
enum rspamd_mime_parse_error ret; | |||
task = cb->task; | |||
@@ -1053,7 +1053,7 @@ rspamd_multipart_boundaries_filter(struct rspamd_task *task, | |||
{ | |||
struct rspamd_mime_boundary *cur; | |||
goffset last_offset; | |||
guint i, sel = 0; | |||
unsigned int i, sel = 0; | |||
enum rspamd_mime_parse_error ret; | |||
last_offset = (multipart->raw_data.begin - st->start) + | |||
@@ -1183,7 +1183,7 @@ rspamd_mime_parse_multipart_part(struct rspamd_task *task, | |||
if (part->ct->boundary.len > 0) { | |||
/* We know our boundary */ | |||
cbdata.cur_boundary = &part->ct->boundary; | |||
rspamd_cryptobox_siphash((guchar *) &cbdata.bhash, | |||
rspamd_cryptobox_siphash((unsigned char *) &cbdata.bhash, | |||
cbdata.cur_boundary->begin, cbdata.cur_boundary->len, | |||
lib_ctx->hkey); | |||
msg_debug_mime("hash: %T -> %L", cbdata.cur_boundary, cbdata.bhash); | |||
@@ -1203,16 +1203,16 @@ rspamd_mime_parse_multipart_part(struct rspamd_task *task, | |||
} | |||
/* Process boundary like structures in a message */ | |||
static gint | |||
static int | |||
rspamd_mime_preprocess_cb(struct rspamd_multipattern *mp, | |||
guint strnum, | |||
gint match_start, | |||
gint match_pos, | |||
const gchar *text, | |||
unsigned int strnum, | |||
int match_start, | |||
int match_pos, | |||
const char *text, | |||
gsize len, | |||
void *context) | |||
{ | |||
const gchar *end = text + len, *p = text + match_pos, *bend; | |||
const char *end = text + len, *p = text + match_pos, *bend; | |||
gsize blen; | |||
gboolean closing = FALSE; | |||
struct rspamd_mime_boundary b; | |||
@@ -1281,7 +1281,7 @@ rspamd_mime_preprocess_cb(struct rspamd_multipattern *mp, | |||
b.start = bend - st->start; | |||
/* Small optimisation as boundaries are usually short strings */ | |||
gchar *lc_copy, lc_copy_buf[128]; | |||
char *lc_copy, lc_copy_buf[128]; | |||
if (blen + 2 < sizeof(lc_copy_buf)) { | |||
lc_copy = lc_copy_buf; | |||
@@ -1299,18 +1299,18 @@ rspamd_mime_preprocess_cb(struct rspamd_multipattern *mp, | |||
rspamd_str_lc(lc_copy, blen); | |||
} | |||
rspamd_cryptobox_siphash((guchar *) &b.hash, lc_copy, blen, | |||
rspamd_cryptobox_siphash((unsigned char *) &b.hash, lc_copy, blen, | |||
lib_ctx->hkey); | |||
msg_debug_mime("normal hash: %*s -> %L, %d boffset, %d data offset", | |||
(gint) blen, lc_copy, b.hash, (int) b.boundary, (int) b.start); | |||
(int) blen, lc_copy, b.hash, (int) b.boundary, (int) b.start); | |||
if (closing) { | |||
b.flags = RSPAMD_MIME_BOUNDARY_FLAG_CLOSED; | |||
rspamd_cryptobox_siphash((guchar *) &b.closed_hash, lc_copy, | |||
rspamd_cryptobox_siphash((unsigned char *) &b.closed_hash, lc_copy, | |||
blen + 2, | |||
lib_ctx->hkey); | |||
msg_debug_mime("closing hash: %*s -> %L, %d boffset, %d data offset", | |||
(gint) blen + 2, lc_copy, | |||
(int) blen + 2, lc_copy, | |||
b.closed_hash, | |||
(int) b.boundary, (int) b.start); | |||
} | |||
@@ -1335,7 +1335,7 @@ rspamd_mime_parser_headers_heuristic(GString *input, goffset *body_start) | |||
{ | |||
const gsize default_max_len = 76; | |||
gsize max_len = MIN(input->len, default_max_len); | |||
const gchar *p, *end; | |||
const char *p, *end; | |||
enum { | |||
st_before_colon = 0, | |||
st_colon, | |||
@@ -1434,11 +1434,11 @@ rspamd_mime_parse_message(struct rspamd_task *task, | |||
{ | |||
struct rspamd_content_type *ct, *sel = NULL; | |||
struct rspamd_mime_header *hdr = NULL, *cur; | |||
const gchar *pbegin, *p; | |||
const char *pbegin, *p; | |||
gsize plen, len; | |||
struct rspamd_mime_part *npart; | |||
goffset hdr_pos, body_pos; | |||
guint i; | |||
unsigned int i; | |||
enum rspamd_mime_parse_error ret = RSPAMD_MIME_PARSE_OK; | |||
GString str; | |||
struct rspamd_mime_parser_ctx *nst = st; | |||
@@ -1458,7 +1458,7 @@ rspamd_mime_parse_message(struct rspamd_task *task, | |||
p = task->msg.begin; | |||
len = task->msg.len; | |||
str.str = (gchar *) p; | |||
str.str = (char *) p; | |||
str.len = len; | |||
hdr_pos = rspamd_string_find_eoh(&str, &body_pos); | |||
@@ -1545,7 +1545,7 @@ rspamd_mime_parse_message(struct rspamd_task *task, | |||
nst->nesting = st->nesting; | |||
st->nesting++; | |||
str.str = (gchar *) part->parsed_data.begin; | |||
str.str = (char *) part->parsed_data.begin; | |||
str.len = part->parsed_data.len; | |||
hdr_pos = rspamd_string_find_eoh(&str, &body_pos); | |||
@@ -1660,7 +1660,7 @@ rspamd_mime_parse_message(struct rspamd_task *task, | |||
*end_boundary = NULL; | |||
goffset cur_offset = nst->pos - nst->start, | |||
end_offset = st->end - st->start; | |||
guint sel_idx = 0; | |||
unsigned int sel_idx = 0; | |||
for (;;) { | |||
start_boundary = NULL; | |||
@@ -1679,7 +1679,7 @@ rspamd_mime_parse_message(struct rspamd_task *task, | |||
} | |||
if (start_boundary) { | |||
const gchar *start, *end; | |||
const char *start, *end; | |||
if (nst->boundaries->len > sel_idx + 1) { | |||
end_boundary = &g_array_index(nst->boundaries, |
@@ -50,7 +50,7 @@ struct received_part { | |||
}; | |||
static inline auto | |||
received_part_set_or_append(const gchar *begin, | |||
received_part_set_or_append(const char *begin, | |||
gsize len, | |||
mime_string &dest) -> void | |||
{ | |||
@@ -427,7 +427,7 @@ received_process_rdns(rspamd_mempool_t *pool, | |||
RSPAMD_INET_ADDRESS_PARSE_RECEIVED); | |||
if (addr) { | |||
const gchar *addr_str; | |||
const char *addr_str; | |||
if (rspamd_inet_address_get_port(addr) != 0) { | |||
addr_str = rspamd_inet_address_to_string_pretty(addr); |
@@ -73,7 +73,7 @@ rspamd_metric_actions_foreach_cb(int i, struct rspamd_action *act, void *cbd) | |||
struct rspamd_scan_result * | |||
rspamd_create_metric_result(struct rspamd_task *task, | |||
const gchar *name, gint lua_sym_cbref) | |||
const char *name, int lua_sym_cbref) | |||
{ | |||
struct rspamd_scan_result *metric_res; | |||
@@ -127,10 +127,10 @@ rspamd_pr_sort(const struct rspamd_passthrough_result *pra, | |||
bool rspamd_add_passthrough_result(struct rspamd_task *task, | |||
struct rspamd_action *action, | |||
guint priority, | |||
unsigned int priority, | |||
double target_score, | |||
const gchar *message, | |||
const gchar *module, | |||
const char *message, | |||
const char *module, | |||
uint flags, | |||
struct rspamd_scan_result *scan_result) | |||
{ | |||
@@ -194,12 +194,12 @@ bool rspamd_add_passthrough_result(struct rspamd_task *task, | |||
return true; | |||
} | |||
static inline gdouble | |||
static inline double | |||
rspamd_check_group_score(struct rspamd_task *task, | |||
const gchar *symbol, | |||
const char *symbol, | |||
struct rspamd_symbols_group *gr, | |||
gdouble *group_score, | |||
gdouble w) | |||
double *group_score, | |||
double w) | |||
{ | |||
if (gr != NULL && group_score && gr->max_score > 0.0 && w > 0.0) { | |||
if (*group_score >= gr->max_score && w > 0) { | |||
@@ -223,23 +223,23 @@ rspamd_check_group_score(struct rspamd_task *task, | |||
static struct rspamd_symbol_result * | |||
insert_metric_result(struct rspamd_task *task, | |||
const gchar *symbol, | |||
const char *symbol, | |||
double weight, | |||
const gchar *opt, | |||
const char *opt, | |||
struct rspamd_scan_result *metric_res, | |||
enum rspamd_symbol_insert_flags flags, | |||
bool *new_sym) | |||
{ | |||
struct rspamd_symbol_result *symbol_result = NULL; | |||
gdouble final_score, *gr_score = NULL, next_gf = 1.0, diff; | |||
double final_score, *gr_score = NULL, next_gf = 1.0, diff; | |||
struct rspamd_symbol *sdef; | |||
struct rspamd_symbols_group *gr = NULL; | |||
const ucl_object_t *mobj, *sobj; | |||
gint max_shots = G_MAXINT, ret; | |||
guint i; | |||
int max_shots = G_MAXINT, ret; | |||
unsigned int i; | |||
khiter_t k; | |||
gboolean single = !!(flags & RSPAMD_SYMBOL_INSERT_SINGLE); | |||
gchar *sym_cpy; | |||
char *sym_cpy; | |||
if (!isfinite(weight)) { | |||
msg_warn_task("detected %s score for symbol %s, replace it with zero", | |||
@@ -290,7 +290,7 @@ insert_metric_result(struct rspamd_task *task, | |||
} | |||
if (task->settings) { | |||
gdouble corr; | |||
double corr; | |||
mobj = ucl_object_lookup(task->settings, "scores"); | |||
if (!mobj) { | |||
@@ -383,7 +383,7 @@ insert_metric_result(struct rspamd_task *task, | |||
if (sdef) { | |||
PTR_ARRAY_FOREACH(sdef->groups, i, gr) | |||
{ | |||
gdouble cur_diff; | |||
double cur_diff; | |||
k = kh_get(rspamd_symbols_group_hash, | |||
metric_res->sym_groups, gr); | |||
@@ -467,7 +467,7 @@ insert_metric_result(struct rspamd_task *task, | |||
/* Check group limits */ | |||
PTR_ARRAY_FOREACH(sdef->groups, i, gr) | |||
{ | |||
gdouble cur_score; | |||
double cur_score; | |||
k = kh_get(rspamd_symbols_group_hash, metric_res->sym_groups, gr); | |||
g_assert(k != kh_end(metric_res->sym_groups)); | |||
@@ -535,9 +535,9 @@ insert_metric_result(struct rspamd_task *task, | |||
struct rspamd_symbol_result * | |||
rspamd_task_insert_result_full(struct rspamd_task *task, | |||
const gchar *symbol, | |||
const char *symbol, | |||
double weight, | |||
const gchar *opt, | |||
const char *opt, | |||
enum rspamd_symbol_insert_flags flags, | |||
struct rspamd_scan_result *result) | |||
{ | |||
@@ -638,13 +638,13 @@ rspamd_task_insert_result_full(struct rspamd_task *task, | |||
return ret; | |||
} | |||
static gchar * | |||
static char * | |||
rspamd_task_option_safe_copy(struct rspamd_task *task, | |||
const gchar *val, | |||
const char *val, | |||
gsize vlen, | |||
gsize *outlen) | |||
{ | |||
const gchar *p, *end; | |||
const char *p, *end; | |||
p = val; | |||
end = val + vlen; | |||
@@ -653,7 +653,7 @@ rspamd_task_option_safe_copy(struct rspamd_task *task, | |||
while (p < end) { | |||
if (*p & 0x80) { | |||
UChar32 uc; | |||
gint off = 0; | |||
int off = 0; | |||
U8_NEXT(p, off, end - p, uc); | |||
@@ -683,7 +683,7 @@ rspamd_task_option_safe_copy(struct rspamd_task *task, | |||
} | |||
} | |||
gchar *dest, *d; | |||
char *dest, *d; | |||
dest = rspamd_mempool_alloc(task->task_pool, vlen + 1); | |||
d = dest; | |||
@@ -692,7 +692,7 @@ rspamd_task_option_safe_copy(struct rspamd_task *task, | |||
while (p < end) { | |||
if (*p & 0x80) { | |||
UChar32 uc; | |||
gint off = 0; | |||
int off = 0; | |||
U8_NEXT(p, off, end - p, uc); | |||
@@ -737,15 +737,15 @@ rspamd_task_option_safe_copy(struct rspamd_task *task, | |||
gboolean | |||
rspamd_task_add_result_option(struct rspamd_task *task, | |||
struct rspamd_symbol_result *s, | |||
const gchar *val, | |||
const char *val, | |||
gsize vlen) | |||
{ | |||
struct rspamd_symbol_option *opt, srch; | |||
gboolean ret = FALSE; | |||
gchar *opt_cpy = NULL; | |||
char *opt_cpy = NULL; | |||
gsize cpy_len; | |||
khiter_t k; | |||
gint r; | |||
int r; | |||
struct rspamd_symbol_result *cur; | |||
if (s && val) { | |||
@@ -779,14 +779,14 @@ rspamd_task_add_result_option(struct rspamd_task *task, | |||
if (!(cur->sym && (cur->sym->flags & RSPAMD_SYMBOL_FLAG_ONEPARAM))) { | |||
srch.option = (gchar *) val; | |||
srch.option = (char *) val; | |||
srch.optlen = vlen; | |||
k = kh_get(rspamd_options_hash, cur->options, &srch); | |||
if (k == kh_end(cur->options)) { | |||
opt_cpy = rspamd_task_option_safe_copy(task, val, vlen, &cpy_len); | |||
if (cpy_len != vlen) { | |||
srch.option = (gchar *) opt_cpy; | |||
srch.option = (char *) opt_cpy; | |||
srch.optlen = cpy_len; | |||
k = kh_get(rspamd_options_hash, cur->options, &srch); | |||
} | |||
@@ -1013,7 +1013,7 @@ rspamd_task_find_symbol_result(struct rspamd_task *task, const char *sym, | |||
struct rspamd_symbol_result *rspamd_task_remove_symbol_result( | |||
struct rspamd_task *task, | |||
const gchar *symbol, | |||
const char *symbol, | |||
struct rspamd_scan_result *result) | |||
{ | |||
struct rspamd_symbol_result *res = NULL; | |||
@@ -1036,12 +1036,12 @@ struct rspamd_symbol_result *rspamd_task_remove_symbol_result( | |||
/* Also check the group limit */ | |||
if (result->sym_groups && res->sym) { | |||
struct rspamd_symbol_group *gr; | |||
gint i; | |||
int i; | |||
khiter_t k_groups; | |||
PTR_ARRAY_FOREACH(res->sym->groups, i, gr) | |||
{ | |||
gdouble *gr_score; | |||
double *gr_score; | |||
k_groups = kh_get(rspamd_symbols_group_hash, | |||
result->sym_groups, gr); | |||
@@ -1070,7 +1070,7 @@ void rspamd_task_symbol_result_foreach(struct rspamd_task *task, | |||
struct rspamd_scan_result *result, GHFunc func, | |||
gpointer ud) | |||
{ | |||
const gchar *kk; | |||
const char *kk; | |||
struct rspamd_symbol_result *res; | |||
if (result == NULL) { | |||
@@ -1087,7 +1087,7 @@ void rspamd_task_symbol_result_foreach(struct rspamd_task *task, | |||
struct rspamd_scan_result * | |||
rspamd_find_metric_result(struct rspamd_task *task, | |||
const gchar *name) | |||
const char *name) | |||
{ | |||
struct rspamd_scan_result *res; | |||
@@ -35,7 +35,7 @@ struct rspamd_settings; | |||
struct rspamd_classifier_config; | |||
struct rspamd_symbol_option { | |||
gchar *option; | |||
char *option; | |||
gsize optlen; | |||
struct rspamd_symbol_option *prev, *next; | |||
}; | |||
@@ -54,10 +54,10 @@ struct rspamd_symbol_result { | |||
double score; /**< symbol's score */ | |||
struct kh_rspamd_options_hash_s *options; /**< list of symbol's options */ | |||
struct rspamd_symbol_option *opts_head; /**< head of linked list of options */ | |||
const gchar *name; | |||
const char *name; | |||
struct rspamd_symbol *sym; /**< symbol configuration */ | |||
gssize opts_len; /**< total size of all options (negative if truncated option is added) */ | |||
guint nshots; | |||
unsigned int nshots; | |||
int flags; | |||
struct rspamd_symbol_result *next; /**< for shadow results */ | |||
}; | |||
@@ -74,11 +74,11 @@ struct rspamd_symbol_result { | |||
struct rspamd_passthrough_result { | |||
struct rspamd_action *action; | |||
guint priority; | |||
guint flags; | |||
unsigned int priority; | |||
unsigned int flags; | |||
double target_score; | |||
const gchar *message; | |||
const gchar *module; | |||
const char *message; | |||
const char *module; | |||
struct rspamd_passthrough_result *prev, *next; | |||
}; | |||
@@ -89,7 +89,7 @@ enum rspamd_action_config_flags { | |||
RSPAMD_ACTION_RESULT_DISABLED = (1u << 1u), | |||
}; | |||
struct rspamd_action_config { | |||
gdouble cur_limit; | |||
double cur_limit; | |||
int flags; | |||
struct rspamd_action *action; | |||
}; | |||
@@ -107,14 +107,14 @@ struct rspamd_scan_result { | |||
struct kh_rspamd_symbols_hash_s *symbols; /**< symbols of metric */ | |||
struct kh_rspamd_symbols_group_hash_s *sym_groups; /**< groups of symbols */ | |||
struct rspamd_action_config *actions_config; | |||
const gchar *name; /**< for named results, NULL is the default result */ | |||
const char *name; /**< for named results, NULL is the default result */ | |||
struct rspamd_task *task; /**< back reference */ | |||
gint symbol_cbref; /**< lua function that defines if a symbol can be inserted, -1 if unused */ | |||
guint nactions; | |||
guint npositive; | |||
guint nnegative; | |||
guint nresults; /**< all results: positive, negative, passthrough etc */ | |||
guint nresults_postfilters; /**< how many results are there before postfilters stage */ | |||
int symbol_cbref; /**< lua function that defines if a symbol can be inserted, -1 if unused */ | |||
unsigned int nactions; | |||
unsigned int npositive; | |||
unsigned int nnegative; | |||
unsigned int nresults; /**< all results: positive, negative, passthrough etc */ | |||
unsigned int nresults_postfilters; /**< how many results are there before postfilters stage */ | |||
struct rspamd_scan_result *prev, *next; /**< double linked list of results */ | |||
}; | |||
@@ -124,7 +124,7 @@ struct rspamd_scan_result { | |||
* @return metric result or NULL if metric `name` has not been found | |||
*/ | |||
struct rspamd_scan_result *rspamd_create_metric_result(struct rspamd_task *task, | |||
const gchar *name, gint lua_sym_cbref); | |||
const char *name, int lua_sym_cbref); | |||
/** | |||
* Find result with a specific name (NULL means the default result) | |||
@@ -133,7 +133,7 @@ struct rspamd_scan_result *rspamd_create_metric_result(struct rspamd_task *task, | |||
* @return | |||
*/ | |||
struct rspamd_scan_result *rspamd_find_metric_result(struct rspamd_task *task, | |||
const gchar *name); | |||
const char *name); | |||
/** | |||
* Adds a new passthrough result to a task | |||
@@ -145,9 +145,9 @@ struct rspamd_scan_result *rspamd_find_metric_result(struct rspamd_task *task, | |||
* @param module | |||
*/ | |||
bool rspamd_add_passthrough_result(struct rspamd_task *task, | |||
struct rspamd_action *action, guint priority, | |||
double target_score, const gchar *message, | |||
const gchar *module, guint flags, | |||
struct rspamd_action *action, unsigned int priority, | |||
double target_score, const char *message, | |||
const char *module, unsigned int flags, | |||
struct rspamd_scan_result *scan_result); | |||
enum rspamd_symbol_insert_flags { | |||
@@ -165,9 +165,9 @@ enum rspamd_symbol_insert_flags { | |||
* @param opts list of symbol's options | |||
*/ | |||
struct rspamd_symbol_result *rspamd_task_insert_result_full(struct rspamd_task *task, | |||
const gchar *symbol, | |||
const char *symbol, | |||
double weight, | |||
const gchar *opts, | |||
const char *opts, | |||
enum rspamd_symbol_insert_flags flags, | |||
struct rspamd_scan_result *result); | |||
@@ -185,7 +185,7 @@ struct rspamd_symbol_result *rspamd_task_insert_result_full(struct rspamd_task * | |||
*/ | |||
struct rspamd_symbol_result *rspamd_task_remove_symbol_result( | |||
struct rspamd_task *task, | |||
const gchar *symbol, | |||
const char *symbol, | |||
struct rspamd_scan_result *result); | |||
/** | |||
* Adds new option to symbol | |||
@@ -195,7 +195,7 @@ struct rspamd_symbol_result *rspamd_task_remove_symbol_result( | |||
*/ | |||
gboolean rspamd_task_add_result_option(struct rspamd_task *task, | |||
struct rspamd_symbol_result *s, | |||
const gchar *opt, | |||
const char *opt, | |||
gsize vlen); | |||
/** | |||
@@ -227,8 +227,8 @@ void rspamd_task_symbol_result_foreach(struct rspamd_task *task, | |||
* @return result metric weight | |||
*/ | |||
double rspamd_factor_consolidation_func(struct rspamd_task *task, | |||
const gchar *metric_name, | |||
const gchar *unused); | |||
const char *metric_name, | |||
const char *unused); | |||
/** |
@@ -35,14 +35,14 @@ gboolean rspamd_content_disposition_parser(const char *data, size_t len, | |||
rspamd_mempool_t *pool); | |||
gboolean | |||
rspamd_rfc2047_parser(const gchar *in, gsize len, gint *pencoding, | |||
const gchar **charset, gsize *charset_len, | |||
const gchar **encoded, gsize *encoded_len); | |||
rspamd_rfc2047_parser(const char *in, gsize len, int *pencoding, | |||
const char **charset, gsize *charset_len, | |||
const char **encoded, gsize *encoded_len); | |||
rspamd_inet_addr_t *rspamd_parse_smtp_ip(const char *data, size_t len, | |||
rspamd_mempool_t *pool); | |||
guint64 rspamd_parse_smtp_date(const unsigned char *data, size_t len, GError **err); | |||
uint64_t rspamd_parse_smtp_date(const unsigned char *data, size_t len, GError **err); | |||
#ifdef __cplusplus | |||
} |
@@ -49,8 +49,8 @@ static struct rspamd_counter_data events_count; | |||
struct rspamd_async_event { | |||
const gchar *subsystem; | |||
const gchar *event_source; | |||
const char *subsystem; | |||
const char *event_source; | |||
event_finalizer_t fin; | |||
void *user_data; | |||
}; | |||
@@ -61,7 +61,7 @@ rspamd_event_equal(const struct rspamd_async_event *ev1, const struct rspamd_asy | |||
return ev1->fin == ev2->fin && ev1->user_data == ev2->user_data; | |||
} | |||
static inline guint64 | |||
static inline uint64_t | |||
rspamd_event_hash(const struct rspamd_async_event *ev) | |||
{ | |||
union _pointer_fp_thunk { | |||
@@ -94,7 +94,7 @@ struct rspamd_async_session { | |||
khash_t(rspamd_events_hash) * events; | |||
void *user_data; | |||
rspamd_mempool_t *pool; | |||
guint flags; | |||
unsigned int flags; | |||
}; | |||
static void | |||
@@ -134,11 +134,11 @@ struct rspamd_async_event * | |||
rspamd_session_add_event_full(struct rspamd_async_session *session, | |||
event_finalizer_t fin, | |||
gpointer user_data, | |||
const gchar *subsystem, | |||
const gchar *event_source) | |||
const char *subsystem, | |||
const char *event_source) | |||
{ | |||
struct rspamd_async_event *new_event; | |||
gint ret; | |||
int ret; | |||
if (session == NULL) { | |||
msg_err("session is NULL"); | |||
@@ -176,7 +176,7 @@ rspamd_session_add_event_full(struct rspamd_async_session *session, | |||
void rspamd_session_remove_event_full(struct rspamd_async_session *session, | |||
event_finalizer_t fin, | |||
void *ud, | |||
const gchar *event_source) | |||
const char *event_source) | |||
{ | |||
struct rspamd_async_event search_ev, *found_ev; | |||
khiter_t k; | |||
@@ -335,9 +335,9 @@ rspamd_session_pending(struct rspamd_async_session *session) | |||
return ret; | |||
} | |||
guint rspamd_session_events_pending(struct rspamd_async_session *session) | |||
unsigned int rspamd_session_events_pending(struct rspamd_async_session *session) | |||
{ | |||
guint npending; | |||
unsigned int npending; | |||
g_assert(session != NULL); | |||
@@ -54,8 +54,8 @@ struct rspamd_async_event * | |||
rspamd_session_add_event_full(struct rspamd_async_session *session, | |||
event_finalizer_t fin, | |||
gpointer user_data, | |||
const gchar *subsystem, | |||
const gchar *event_source); | |||
const char *subsystem, | |||
const char *event_source); | |||
#define rspamd_session_add_event(session, fin, user_data, subsystem) \ | |||
rspamd_session_add_event_full(session, fin, user_data, subsystem, G_STRLOC) | |||
@@ -69,7 +69,7 @@ rspamd_session_add_event_full(struct rspamd_async_session *session, | |||
void rspamd_session_remove_event_full(struct rspamd_async_session *session, | |||
event_finalizer_t fin, | |||
gpointer ud, | |||
const gchar *event_source); | |||
const char *event_source); | |||
#define rspamd_session_remove_event(session, fin, user_data) \ | |||
rspamd_session_remove_event_full(session, fin, user_data, G_STRLOC) | |||
@@ -104,7 +104,7 @@ gboolean rspamd_session_pending(struct rspamd_async_session *session); | |||
* @param session | |||
* @return | |||
*/ | |||
guint rspamd_session_events_pending(struct rspamd_async_session *session); | |||
unsigned int rspamd_session_events_pending(struct rspamd_async_session *session); | |||
/** |
@@ -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. | |||
@@ -71,8 +71,8 @@ enum rspamd_log_cfg_flags { | |||
}; | |||
struct rspamd_worker_log_pipe { | |||
gint fd; | |||
gint type; | |||
int fd; | |||
int type; | |||
struct rspamd_worker_log_pipe *prev, *next; | |||
}; | |||
@@ -80,9 +80,9 @@ struct rspamd_worker_log_pipe { | |||
* script module list item | |||
*/ | |||
struct script_module { | |||
gchar *name; /**< name of module */ | |||
gchar *path; /**< path to module */ | |||
gchar *digest; | |||
char *name; /**< name of module */ | |||
char *path; /**< path to module */ | |||
char *digest; | |||
}; | |||
enum rspamd_symbol_group_flags { | |||
@@ -98,11 +98,11 @@ enum rspamd_symbol_group_flags { | |||
*/ | |||
struct rspamd_symbol; | |||
struct rspamd_symbols_group { | |||
gchar *name; | |||
gchar *description; | |||
char *name; | |||
char *description; | |||
GHashTable *symbols; | |||
gdouble max_score; | |||
guint flags; | |||
double max_score; | |||
unsigned int flags; | |||
}; | |||
enum rspamd_symbol_flags { | |||
@@ -118,24 +118,24 @@ enum rspamd_symbol_flags { | |||
* Symbol config definition | |||
*/ | |||
struct rspamd_symbol { | |||
gchar *name; | |||
gchar *description; | |||
gdouble *weight_ptr; | |||
gdouble score; | |||
guint priority; | |||
char *name; | |||
char *description; | |||
double *weight_ptr; | |||
double score; | |||
unsigned int priority; | |||
struct rspamd_symbols_group *gr; /* Main group */ | |||
GPtrArray *groups; /* Other groups */ | |||
guint flags; | |||
unsigned int flags; | |||
void *cache_item; | |||
gint nshots; | |||
int nshots; | |||
}; | |||
/** | |||
* Statfile config definition | |||
*/ | |||
struct rspamd_statfile_config { | |||
gchar *symbol; /**< symbol of statfile */ | |||
gchar *label; /**< label of this statfile */ | |||
char *symbol; /**< symbol of statfile */ | |||
char *label; /**< label of this statfile */ | |||
ucl_object_t *opts; /**< other options */ | |||
gboolean is_spam; /**< spam flag */ | |||
struct rspamd_classifier_config *clcf; /**< parent pointer of classifier configuration */ | |||
@@ -144,7 +144,7 @@ struct rspamd_statfile_config { | |||
struct rspamd_tokenizer_config { | |||
const ucl_object_t *opts; /**< other options */ | |||
const gchar *name; /**< name of tokenizer */ | |||
const char *name; /**< name of tokenizer */ | |||
}; | |||
@@ -166,33 +166,33 @@ struct rspamd_tokenizer_config { | |||
struct rspamd_classifier_config { | |||
GList *statfiles; /**< statfiles list */ | |||
GHashTable *labels; /**< statfiles with labels */ | |||
gchar *metric; /**< metric of this classifier */ | |||
gchar *classifier; /**< classifier interface */ | |||
char *metric; /**< metric of this classifier */ | |||
char *classifier; /**< classifier interface */ | |||
struct rspamd_tokenizer_config *tokenizer; /**< tokenizer used for classifier */ | |||
const gchar *backend; /**< name of statfile's backend */ | |||
const char *backend; /**< name of statfile's backend */ | |||
ucl_object_t *opts; /**< other options */ | |||
GList *learn_conditions; /**< list of learn condition callbacks */ | |||
GList *classify_conditions; /**< list of classify condition callbacks */ | |||
gchar *name; /**< unique name of classifier */ | |||
guint32 min_tokens; /**< minimal number of tokens to process classifier */ | |||
guint32 max_tokens; /**< maximum number of tokens */ | |||
guint min_token_hits; /**< minimum number of hits for a token to be considered */ | |||
gdouble min_prob_strength; /**< use only tokens with probability in [0.5 - MPS, 0.5 + MPS] */ | |||
guint min_learns; /**< minimum number of learns for each statfile */ | |||
guint flags; | |||
char *name; /**< unique name of classifier */ | |||
uint32_t min_tokens; /**< minimal number of tokens to process classifier */ | |||
uint32_t max_tokens; /**< maximum number of tokens */ | |||
unsigned int min_token_hits; /**< minimum number of hits for a token to be considered */ | |||
double min_prob_strength; /**< use only tokens with probability in [0.5 - MPS, 0.5 + MPS] */ | |||
unsigned int min_learns; /**< minimum number of learns for each statfile */ | |||
unsigned int flags; | |||
}; | |||
struct rspamd_worker_bind_conf { | |||
GPtrArray *addrs; | |||
guint cnt; | |||
gchar *name; | |||
gchar *bind_line; | |||
unsigned int cnt; | |||
char *name; | |||
char *bind_line; | |||
gboolean is_systemd; | |||
struct rspamd_worker_bind_conf *next; | |||
}; | |||
struct rspamd_worker_lua_script { | |||
gint cbref; | |||
int cbref; | |||
struct rspamd_worker_lua_script *prev, *next; | |||
}; | |||
@@ -203,10 +203,10 @@ struct rspamd_worker_conf { | |||
struct worker_s *worker; /**< pointer to worker type */ | |||
GQuark type; /**< type of worker */ | |||
struct rspamd_worker_bind_conf *bind_conf; /**< bind configuration */ | |||
gint16 count; /**< number of workers */ | |||
int16_t count; /**< number of workers */ | |||
GList *listen_socks; /**< listening sockets descriptors */ | |||
guint64 rlimit_nofile; /**< max files limit */ | |||
guint64 rlimit_maxcore; /**< maximum core file size */ | |||
uint64_t rlimit_nofile; /**< max files limit */ | |||
uint64_t rlimit_maxcore; /**< maximum core file size */ | |||
GHashTable *params; /**< params for worker */ | |||
GQueue *active_workers; /**< linked list of spawned workers */ | |||
gpointer ctx; /**< worker's context */ | |||
@@ -258,7 +258,7 @@ enum rspamd_log_format_flags { | |||
struct rspamd_log_format { | |||
enum rspamd_log_format_type type; | |||
guint flags; | |||
unsigned int flags; | |||
gsize len; | |||
gpointer data; | |||
struct rspamd_log_format *prev, *next; | |||
@@ -292,14 +292,14 @@ enum rspamd_action_flags { | |||
struct rspamd_action; | |||
struct rspamd_config_cfg_lua_script { | |||
gint cbref; | |||
gint priority; | |||
gchar *lua_src_pos; | |||
int cbref; | |||
int priority; | |||
char *lua_src_pos; | |||
struct rspamd_config_cfg_lua_script *prev, *next; | |||
}; | |||
struct rspamd_config_post_init_script { | |||
gint cbref; | |||
int cbref; | |||
struct rspamd_config_post_init_script *prev, *next; | |||
}; | |||
@@ -319,9 +319,9 @@ enum rspamd_gtube_patterns_policy { | |||
}; | |||
struct rspamd_config_settings_elt { | |||
guint32 id; | |||
uint32_t id; | |||
enum rspamd_config_settings_policy policy; | |||
const gchar *name; | |||
const char *name; | |||
ucl_object_t *symbols_enabled; | |||
ucl_object_t *symbols_disabled; | |||
struct rspamd_config_settings_elt *prev, *next; | |||
@@ -332,23 +332,23 @@ struct rspamd_config_settings_elt { | |||
* Structure that stores all config data | |||
*/ | |||
struct rspamd_config { | |||
gchar *rspamd_user; /**< user to run as */ | |||
gchar *rspamd_group; /**< group to run as */ | |||
char *rspamd_user; /**< user to run as */ | |||
char *rspamd_group; /**< group to run as */ | |||
rspamd_mempool_t *cfg_pool; /**< memory pool for config */ | |||
gchar *cfg_name; /**< name of config file */ | |||
gchar *pid_file; /**< name of pid file */ | |||
gchar *temp_dir; /**< dir for temp files */ | |||
gchar *control_socket_path; /**< path to the control socket */ | |||
char *cfg_name; /**< name of config file */ | |||
char *pid_file; /**< name of pid file */ | |||
char *temp_dir; /**< dir for temp files */ | |||
char *control_socket_path; /**< path to the control socket */ | |||
const ucl_object_t *local_addrs; /**< tree of local addresses */ | |||
#ifdef WITH_GPERF_TOOLS | |||
gchar *profile_path; | |||
char *profile_path; | |||
#endif | |||
gdouble unknown_weight; /**< weight of unknown symbols */ | |||
gdouble grow_factor; /**< grow factor for metric */ | |||
GHashTable *symbols; /**< weights of symbols in metric */ | |||
const gchar *subject; /**< subject rewrite string */ | |||
GHashTable *groups; /**< groups of symbols */ | |||
void *actions; /**< all actions of the metric (opaque type) */ | |||
double unknown_weight; /**< weight of unknown symbols */ | |||
double grow_factor; /**< grow factor for metric */ | |||
GHashTable *symbols; /**< weights of symbols in metric */ | |||
const char *subject; /**< subject rewrite string */ | |||
GHashTable *groups; /**< groups of symbols */ | |||
void *actions; /**< all actions of the metric (opaque type) */ | |||
gboolean one_shot_mode; /**< rules add only one symbol */ | |||
gboolean check_text_attachements; /**< check text attachements as text */ | |||
@@ -367,32 +367,32 @@ struct rspamd_config { | |||
enum rspamd_gtube_patterns_policy gtube_patterns_policy; /**< Enable test patterns */ | |||
gboolean enable_css_parser; /**< Enable css parsing in HTML */ | |||
gsize max_cores_size; /**< maximum size occupied by rspamd core files */ | |||
gsize max_cores_count; /**< maximum number of core files */ | |||
gchar *cores_dir; /**< directory for core files */ | |||
gsize max_message; /**< maximum size for messages */ | |||
gsize max_pic_size; /**< maximum size for a picture to process */ | |||
gsize images_cache_size; /**< size of LRU cache for DCT data from images */ | |||
gdouble task_timeout; /**< maximum message processing time */ | |||
gint default_max_shots; /**< default maximum count of symbols hits permitted (-1 for unlimited) */ | |||
gint32 heartbeats_loss_max; /**< number of heartbeats lost to consider worker's termination */ | |||
gdouble heartbeat_interval; /**< interval for heartbeats for workers */ | |||
gsize max_cores_size; /**< maximum size occupied by rspamd core files */ | |||
gsize max_cores_count; /**< maximum number of core files */ | |||
char *cores_dir; /**< directory for core files */ | |||
gsize max_message; /**< maximum size for messages */ | |||
gsize max_pic_size; /**< maximum size for a picture to process */ | |||
gsize images_cache_size; /**< size of LRU cache for DCT data from images */ | |||
double task_timeout; /**< maximum message processing time */ | |||
int default_max_shots; /**< default maximum count of symbols hits permitted (-1 for unlimited) */ | |||
int32_t heartbeats_loss_max; /**< number of heartbeats lost to consider worker's termination */ | |||
double heartbeat_interval; /**< interval for heartbeats for workers */ | |||
enum rspamd_log_type log_type; /**< log type */ | |||
gint log_facility; /**< log facility in case of syslog */ | |||
gint log_level; /**< log level trigger */ | |||
gchar *log_file; /**< path to logfile in case of file logging */ | |||
int log_facility; /**< log facility in case of syslog */ | |||
int log_level; /**< log level trigger */ | |||
char *log_file; /**< path to logfile in case of file logging */ | |||
gboolean log_buffered; /**< whether logging is buffered */ | |||
gboolean log_silent_workers; /**< silence info messages from workers */ | |||
guint32 log_buf_size; /**< length of log buffer */ | |||
uint32_t log_buf_size; /**< length of log buffer */ | |||
const ucl_object_t *debug_ip_map; /**< turn on debugging for specified ip addresses */ | |||
gboolean log_urls; /**< whether we should log URLs */ | |||
GHashTable *debug_modules; /**< logging modules to debug */ | |||
struct rspamd_cryptobox_pubkey *log_encryption_key; /**< encryption key for logs */ | |||
guint log_flags; /**< logging flags */ | |||
guint log_error_elts; /**< number of elements in error logbuf */ | |||
guint log_error_elt_maxlen; /**< maximum size of error log element */ | |||
guint log_task_max_elts; /**< maximum number of elements in task logging */ | |||
unsigned int log_flags; /**< logging flags */ | |||
unsigned int log_error_elts; /**< number of elements in error logbuf */ | |||
unsigned int log_error_elt_maxlen; /**< maximum size of error log element */ | |||
unsigned int log_task_max_elts; /**< maximum number of elements in task logging */ | |||
struct rspamd_worker_log_pipe *log_pipes; | |||
gboolean compat_messages; /**< use old messages in the protocol (array) */ | |||
@@ -412,66 +412,66 @@ struct rspamd_config { | |||
GList *statfiles; /**< list of all statfiles in config file order */ | |||
GHashTable *classifiers_symbols; /**< hashtable indexed by symbol name of classifiers */ | |||
GHashTable *cfg_params; /**< all cfg params indexed by its name in this structure */ | |||
gchar *dynamic_conf; /**< path to dynamic configuration */ | |||
char *dynamic_conf; /**< path to dynamic configuration */ | |||
ucl_object_t *current_dynamic_conf; /**< currently loaded dynamic configuration */ | |||
gint clock_res; /**< resolution of clock used */ | |||
int clock_res; /**< resolution of clock used */ | |||
GList *maps; /**< maps active */ | |||
gdouble map_timeout; /**< maps watch timeout */ | |||
gdouble map_file_watch_multiplier; /**< multiplier for watch timeout when maps are files */ | |||
gchar *maps_cache_dir; /**< where to save HTTP cached data */ | |||
GList *maps; /**< maps active */ | |||
double map_timeout; /**< maps watch timeout */ | |||
double map_file_watch_multiplier; /**< multiplier for watch timeout when maps are files */ | |||
char *maps_cache_dir; /**< where to save HTTP cached data */ | |||
gdouble monitored_interval; /**< interval between monitored checks */ | |||
double monitored_interval; /**< interval between monitored checks */ | |||
gboolean disable_monitored; /**< disable monitoring completely */ | |||
gboolean fips_mode; /**< turn on fips mode for openssl */ | |||
struct rspamd_symcache *cache; /**< symbols cache object */ | |||
gchar *cache_filename; /**< filename of cache file */ | |||
gdouble cache_reload_time; /**< how often cache reload should be performed */ | |||
gchar *checksum; /**< real checksum of config file */ | |||
char *cache_filename; /**< filename of cache file */ | |||
double cache_reload_time; /**< how often cache reload should be performed */ | |||
char *checksum; /**< real checksum of config file */ | |||
gpointer lua_state; /**< pointer to lua state */ | |||
gpointer lua_thread_pool; /**< pointer to lua thread (coroutine) pool */ | |||
gchar *rrd_file; /**< rrd file to store statistics */ | |||
gchar *history_file; /**< file to save rolling history */ | |||
gchar *stats_file; /**< file to save stats */ | |||
gchar *tld_file; /**< file to load effective tld list from */ | |||
gchar *hs_cache_dir; /**< directory to save hyperscan databases */ | |||
gchar *events_backend; /**< string representation of the events backend used */ | |||
char *rrd_file; /**< rrd file to store statistics */ | |||
char *history_file; /**< file to save rolling history */ | |||
char *stats_file; /**< file to save stats */ | |||
char *tld_file; /**< file to load effective tld list from */ | |||
char *hs_cache_dir; /**< directory to save hyperscan databases */ | |||
char *events_backend; /**< string representation of the events backend used */ | |||
gdouble dns_timeout; /**< timeout in milliseconds for waiting for dns reply */ | |||
guint32 dns_retransmits; /**< maximum retransmits count */ | |||
guint32 dns_io_per_server; /**< number of sockets per DNS server */ | |||
double dns_timeout; /**< timeout in milliseconds for waiting for dns reply */ | |||
uint32_t dns_retransmits; /**< maximum retransmits count */ | |||
uint32_t dns_io_per_server; /**< number of sockets per DNS server */ | |||
const ucl_object_t *nameservers; /**< list of nameservers or NULL to parse resolv.conf */ | |||
guint32 dns_max_requests; /**< limit of DNS requests per task */ | |||
uint32_t dns_max_requests; /**< limit of DNS requests per task */ | |||
gboolean enable_dnssec; /**< enable dnssec stub resolver */ | |||
guint upstream_max_errors; /**< upstream max errors before shutting off */ | |||
gdouble upstream_error_time; /**< rate of upstream errors */ | |||
gdouble upstream_revive_time; /**< revive timeout for upstreams */ | |||
gdouble upstream_lazy_resolve_time; /**< lazy resolve time for upstreams */ | |||
unsigned int upstream_max_errors; /**< upstream max errors before shutting off */ | |||
double upstream_error_time; /**< rate of upstream errors */ | |||
double upstream_revive_time; /**< revive timeout for upstreams */ | |||
double upstream_lazy_resolve_time; /**< lazy resolve time for upstreams */ | |||
struct upstream_ctx *ups_ctx; /**< upstream context */ | |||
struct rspamd_dns_resolver *dns_resolver; /**< dns resolver if loaded */ | |||
guint min_word_len; /**< minimum length of the word to be considered */ | |||
guint max_word_len; /**< maximum length of the word to be considered */ | |||
guint words_decay; /**< limit for words for starting adaptive ignoring */ | |||
guint history_rows; /**< number of history rows stored */ | |||
guint max_sessions_cache; /**< maximum number of sessions cache elts */ | |||
guint lua_gc_step; /**< lua gc step */ | |||
guint lua_gc_pause; /**< lua gc pause */ | |||
guint full_gc_iters; /**< iterations between full gc cycle */ | |||
guint max_lua_urls; /**< maximum number of urls to be passed to Lua */ | |||
guint max_urls; /**< maximum number of urls to be processed in general */ | |||
gint max_recipients; /**< maximum number of recipients to be processed */ | |||
guint max_blas_threads; /**< maximum threads for openblas when learning ANN */ | |||
guint max_opts_len; /**< maximum length for all options for a symbol */ | |||
gsize max_html_len; /**< maximum length of HTML document */ | |||
unsigned int min_word_len; /**< minimum length of the word to be considered */ | |||
unsigned int max_word_len; /**< maximum length of the word to be considered */ | |||
unsigned int words_decay; /**< limit for words for starting adaptive ignoring */ | |||
unsigned int history_rows; /**< number of history rows stored */ | |||
unsigned int max_sessions_cache; /**< maximum number of sessions cache elts */ | |||
unsigned int lua_gc_step; /**< lua gc step */ | |||
unsigned int lua_gc_pause; /**< lua gc pause */ | |||
unsigned int full_gc_iters; /**< iterations between full gc cycle */ | |||
unsigned int max_lua_urls; /**< maximum number of urls to be passed to Lua */ | |||
unsigned int max_urls; /**< maximum number of urls to be processed in general */ | |||
int max_recipients; /**< maximum number of recipients to be processed */ | |||
unsigned int max_blas_threads; /**< maximum threads for openblas when learning ANN */ | |||
unsigned int max_opts_len; /**< maximum length for all options for a symbol */ | |||
gsize max_html_len; /**< maximum length of HTML document */ | |||
struct module_s **compiled_modules; /**< list of compiled C modules */ | |||
struct worker_s **compiled_workers; /**< list of compiled C modules */ | |||
struct rspamd_log_format *log_format; /**< parsed log format */ | |||
gchar *log_format_str; /**< raw log format string */ | |||
char *log_format_str; /**< raw log format string */ | |||
struct rspamd_external_libs_ctx *libs_ctx; /**< context for external libraries */ | |||
struct rspamd_monitored_ctx *monitored_ctx; /**< context for monitored resources */ | |||
@@ -486,11 +486,11 @@ struct rspamd_config { | |||
struct rspamd_config_cfg_lua_script *on_term_scripts; /**< list of callbacks called on worker's termination */ | |||
struct rspamd_config_cfg_lua_script *config_unload_scripts; /**< list of scripts executed on config unload */ | |||
gchar *ssl_ca_path; /**< path to CA certs */ | |||
gchar *ssl_ciphers; /**< set of preferred ciphers */ | |||
gchar *zstd_input_dictionary; /**< path to zstd input dictionary */ | |||
gchar *zstd_output_dictionary; /**< path to zstd output dictionary */ | |||
ucl_object_t *neighbours; /**< other servers in the cluster */ | |||
char *ssl_ca_path; /**< path to CA certs */ | |||
char *ssl_ciphers; /**< set of preferred ciphers */ | |||
char *zstd_input_dictionary; /**< path to zstd input dictionary */ | |||
char *zstd_output_dictionary; /**< path to zstd output dictionary */ | |||
ucl_object_t *neighbours; /**< other servers in the cluster */ | |||
struct rspamd_config_settings_elt *setting_ids; /**< preprocessed settings ids */ | |||
struct rspamd_lang_detector *lang_det; /**< language detector */ | |||
@@ -508,7 +508,7 @@ struct rspamd_config { | |||
* @return 1 if line was successfully parsed and 0 in case of error | |||
*/ | |||
gboolean rspamd_parse_bind_line(struct rspamd_config *cfg, | |||
struct rspamd_worker_conf *cf, const gchar *str); | |||
struct rspamd_worker_conf *cf, const char *str); | |||
enum rspamd_config_init_flags { | |||
@@ -537,8 +537,8 @@ void rspamd_config_free(struct rspamd_config *cfg); | |||
* @return module value or NULL if option does not defined | |||
*/ | |||
const ucl_object_t *rspamd_config_get_module_opt(struct rspamd_config *cfg, | |||
const gchar *module_name, | |||
const gchar *opt_name) G_GNUC_WARN_UNUSED_RESULT; | |||
const char *module_name, | |||
const char *opt_name) G_GNUC_WARN_UNUSED_RESULT; | |||
/** | |||
@@ -546,7 +546,7 @@ const ucl_object_t *rspamd_config_get_module_opt(struct rspamd_config *cfg, | |||
* @param str string representation of flag (eg. 'on') | |||
* @return numeric value of flag (0 or 1) | |||
*/ | |||
gint rspamd_config_parse_flag(const gchar *str, guint len); | |||
int rspamd_config_parse_flag(const char *str, unsigned int len); | |||
enum rspamd_post_load_options { | |||
RSPAMD_CONFIG_INIT_URL = 1 << 0, | |||
@@ -595,7 +595,7 @@ void rspamd_config_init_metric(struct rspamd_config *cfg); | |||
*/ | |||
struct rspamd_symbols_group *rspamd_config_new_group( | |||
struct rspamd_config *cfg, | |||
const gchar *name); | |||
const char *name); | |||
/* | |||
* Return a new statfile structure, setting default and non-conflicting attributes | |||
@@ -619,7 +619,7 @@ gboolean rspamd_config_check_statfiles(struct rspamd_classifier_config *cf); | |||
*/ | |||
struct rspamd_classifier_config *rspamd_config_find_classifier( | |||
struct rspamd_config *cfg, | |||
const gchar *name); | |||
const char *name); | |||
void rspamd_ucl_add_conf_macros(struct ucl_parser *parser, | |||
struct rspamd_config *cfg); | |||
@@ -649,13 +649,13 @@ gboolean rspamd_init_filters(struct rspamd_config *cfg, bool reconfig, bool stri | |||
* @return TRUE if symbol has been inserted or FALSE if symbol already exists with higher priority | |||
*/ | |||
gboolean rspamd_config_add_symbol(struct rspamd_config *cfg, | |||
const gchar *symbol, | |||
gdouble score, | |||
const gchar *description, | |||
const gchar *group, | |||
guint flags, | |||
guint priority, | |||
gint nshots); | |||
const char *symbol, | |||
double score, | |||
const char *description, | |||
const char *group, | |||
unsigned int flags, | |||
unsigned int priority, | |||
int nshots); | |||
/** | |||
* Adds new group for a symbol | |||
@@ -665,8 +665,8 @@ gboolean rspamd_config_add_symbol(struct rspamd_config *cfg, | |||
* @return | |||
*/ | |||
gboolean rspamd_config_add_symbol_group(struct rspamd_config *cfg, | |||
const gchar *symbol, | |||
const gchar *group); | |||
const char *symbol, | |||
const char *group); | |||
/** | |||
* Sets action score for a specified metric with the specified priority | |||
@@ -677,7 +677,7 @@ gboolean rspamd_config_add_symbol_group(struct rspamd_config *cfg, | |||
* @return TRUE if symbol has been inserted or FALSE if action already exists with higher priority | |||
*/ | |||
gboolean rspamd_config_set_action_score(struct rspamd_config *cfg, | |||
const gchar *action_name, | |||
const char *action_name, | |||
const ucl_object_t *obj); | |||
/** | |||
@@ -688,8 +688,8 @@ gboolean rspamd_config_set_action_score(struct rspamd_config *cfg, | |||
* @return | |||
*/ | |||
gboolean rspamd_config_maybe_disable_action(struct rspamd_config *cfg, | |||
const gchar *action_name, | |||
guint priority); | |||
const char *action_name, | |||
unsigned int priority); | |||
/** | |||
* Checks if a specified C or lua module is enabled or disabled in the config. | |||
@@ -705,7 +705,7 @@ gboolean rspamd_config_maybe_disable_action(struct rspamd_config *cfg, | |||
* @return TRUE if a module is enabled | |||
*/ | |||
gboolean rspamd_config_is_module_enabled(struct rspamd_config *cfg, | |||
const gchar *module_name); | |||
const char *module_name); | |||
/** | |||
* Verifies enabled/disabled combination in the specified object | |||
@@ -718,14 +718,14 @@ gboolean rspamd_config_is_enabled_from_ucl(rspamd_mempool_t *pool, | |||
/* | |||
* Get action from a string | |||
*/ | |||
gboolean rspamd_action_from_str(const gchar *data, enum rspamd_action_type *result); | |||
gboolean rspamd_action_from_str(const char *data, enum rspamd_action_type *result); | |||
/* | |||
* Return textual representation of action enumeration | |||
*/ | |||
const gchar *rspamd_action_to_str(enum rspamd_action_type action); | |||
const char *rspamd_action_to_str(enum rspamd_action_type action); | |||
const gchar *rspamd_action_to_str_alt(enum rspamd_action_type action); | |||
const char *rspamd_action_to_str_alt(enum rspamd_action_type action); | |||
/** | |||
* Parse radix tree or radix map from ucl object | |||
@@ -737,9 +737,9 @@ const gchar *rspamd_action_to_str_alt(enum rspamd_action_type action); | |||
*/ | |||
struct rspamd_radix_map_helper; | |||
gboolean rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const gchar *description, | |||
gboolean rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const char *description, | |||
struct rspamd_radix_map_helper **target, GError **err, | |||
struct rspamd_worker *worker, const gchar *map_name); | |||
struct rspamd_worker *worker, const char *map_name); | |||
/** | |||
* Adds new settings id to be preprocessed | |||
@@ -749,7 +749,7 @@ gboolean rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_objec | |||
* @param symbols_disabled (ownership is transferred to callee) | |||
*/ | |||
void rspamd_config_register_settings_id(struct rspamd_config *cfg, | |||
const gchar *name, | |||
const char *name, | |||
ucl_object_t *symbols_enabled, | |||
ucl_object_t *symbols_disabled, | |||
enum rspamd_config_settings_policy policy); | |||
@@ -760,7 +760,7 @@ void rspamd_config_register_settings_id(struct rspamd_config *cfg, | |||
* @param namelen | |||
* @return | |||
*/ | |||
guint32 rspamd_config_name_to_id(const gchar *name, gsize namelen); | |||
uint32_t rspamd_config_name_to_id(const char *name, gsize namelen); | |||
/** | |||
* Finds settings id element and obtain reference count (must be unrefed by caller) | |||
@@ -770,7 +770,7 @@ guint32 rspamd_config_name_to_id(const gchar *name, gsize namelen); | |||
*/ | |||
struct rspamd_config_settings_elt *rspamd_config_find_settings_id_ref( | |||
struct rspamd_config *cfg, | |||
guint32 id); | |||
uint32_t id); | |||
/** | |||
* Finds settings id element and obtain reference count (must be unrefed by callee) | |||
@@ -780,7 +780,7 @@ struct rspamd_config_settings_elt *rspamd_config_find_settings_id_ref( | |||
*/ | |||
struct rspamd_config_settings_elt *rspamd_config_find_settings_name_ref( | |||
struct rspamd_config *cfg, | |||
const gchar *name, gsize namelen); | |||
const char *name, gsize namelen); | |||
/** | |||
* Returns action object by name | |||
@@ -789,7 +789,7 @@ struct rspamd_config_settings_elt *rspamd_config_find_settings_name_ref( | |||
* @return | |||
*/ | |||
struct rspamd_action *rspamd_config_get_action(struct rspamd_config *cfg, | |||
const gchar *name); | |||
const char *name); | |||
struct rspamd_action *rspamd_config_get_action_by_type(struct rspamd_config *cfg, | |||
enum rspamd_action_type type); | |||
@@ -821,7 +821,7 @@ void rspamd_config_actions_foreach_enumerate(struct rspamd_config *cfg, | |||
gsize rspamd_config_actions_size(struct rspamd_config *cfg); | |||
int rspamd_config_ev_backend_get(struct rspamd_config *cfg); | |||
const gchar *rspamd_config_ev_backend_to_string(int ev_backend, gboolean *effective); | |||
const char *rspamd_config_ev_backend_to_string(int ev_backend, gboolean *effective); | |||
struct rspamd_external_libs_ctx; | |||
@@ -864,9 +864,9 @@ gboolean rspamd_config_libs(struct rspamd_external_libs_ctx *ctx, | |||
cfg->cfg_pool->tag.tagname, cfg->checksum, \ | |||
RSPAMD_LOG_FUNC, \ | |||
__VA_ARGS__) | |||
#define msg_err_config_forced(...) rspamd_default_log_function((gint) G_LOG_LEVEL_CRITICAL | (gint) RSPAMD_LOG_FORCED, \ | |||
cfg->cfg_pool->tag.tagname, cfg->checksum, \ | |||
RSPAMD_LOG_FUNC, \ | |||
#define msg_err_config_forced(...) rspamd_default_log_function((int) G_LOG_LEVEL_CRITICAL | (int) RSPAMD_LOG_FORCED, \ | |||
cfg->cfg_pool->tag.tagname, cfg->checksum, \ | |||
RSPAMD_LOG_FUNC, \ | |||
__VA_ARGS__) | |||
#define msg_warn_config(...) rspamd_default_log_function(G_LOG_LEVEL_WARNING, \ | |||
cfg->cfg_pool->tag.tagname, cfg->checksum, \ | |||
@@ -876,7 +876,7 @@ gboolean rspamd_config_libs(struct rspamd_external_libs_ctx *ctx, | |||
cfg->cfg_pool->tag.tagname, cfg->checksum, \ | |||
RSPAMD_LOG_FUNC, \ | |||
__VA_ARGS__) | |||
extern guint rspamd_config_log_id; | |||
extern unsigned int rspamd_config_log_id; | |||
#define msg_debug_config(...) rspamd_conditional_debug_fast(NULL, NULL, \ | |||
rspamd_config_log_id, "config", cfg->checksum, \ | |||
RSPAMD_LOG_FUNC, \ |
@@ -29,9 +29,9 @@ extern "C" { | |||
struct rspamd_action { | |||
enum rspamd_action_type action_type; | |||
int flags; /* enum rspamd_action_flags */ | |||
guint priority; | |||
gdouble threshold; | |||
gchar *name; | |||
unsigned int priority; | |||
double threshold; | |||
char *name; | |||
}; | |||
#ifdef __cplusplus |
@@ -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. | |||
@@ -95,7 +95,7 @@ struct rspamd_worker_cfg_parser { | |||
ankerl::unordered_dense::map<std::pair<std::string, gpointer>, | |||
rspamd_worker_param_parser, pair_hash> | |||
parsers; /**< parsers hash */ | |||
gint type; /**< workers quark */ | |||
int type; /**< workers quark */ | |||
gboolean (*def_obj_parser)(ucl_object_t *obj, gpointer ud); /**< default object parser */ | |||
gpointer def_ud; | |||
}; | |||
@@ -122,11 +122,11 @@ rspamd_rcl_section_parse_defaults(struct rspamd_config *cfg, | |||
*/ | |||
static gboolean | |||
rspamd_rcl_logging_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
const gchar *key, gpointer ud, struct rspamd_rcl_section *section, | |||
const char *key, gpointer ud, struct rspamd_rcl_section *section, | |||
GError **err) | |||
{ | |||
const ucl_object_t *val; | |||
const gchar *facility = nullptr, *log_type = nullptr, *log_level = nullptr; | |||
const char *facility = nullptr, *log_type = nullptr, *log_level = nullptr; | |||
auto *cfg = (struct rspamd_config *) ud; | |||
val = ucl_object_lookup(obj, "type"); | |||
@@ -305,7 +305,7 @@ rspamd_rcl_logging_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
static gboolean | |||
rspamd_rcl_options_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
const gchar *key, gpointer ud, | |||
const char *key, gpointer ud, | |||
struct rspamd_rcl_section *section, GError **err) | |||
{ | |||
const ucl_object_t *dns, *upstream, *neighbours; | |||
@@ -402,7 +402,7 @@ struct rspamd_rcl_symbol_data { | |||
static gboolean | |||
rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
const gchar *key, gpointer ud, | |||
const char *key, gpointer ud, | |||
struct rspamd_rcl_section *section, GError **err) | |||
{ | |||
auto *cfg = static_cast<rspamd_config *>(ud); | |||
@@ -523,16 +523,16 @@ rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
static gboolean | |||
rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
const gchar *key, gpointer ud, | |||
const char *key, gpointer ud, | |||
struct rspamd_rcl_section *section, GError **err) | |||
{ | |||
auto *sd = static_cast<rspamd_rcl_symbol_data *>(ud); | |||
struct rspamd_config *cfg; | |||
const ucl_object_t *elt; | |||
const gchar *description = nullptr; | |||
gdouble score = NAN; | |||
guint priority = 1, flags = 0; | |||
gint nshots = 0; | |||
const char *description = nullptr; | |||
double score = NAN; | |||
unsigned int priority = 1, flags = 0; | |||
int nshots = 0; | |||
g_assert(key != nullptr); | |||
cfg = sd->cfg; | |||
@@ -697,7 +697,7 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
static gboolean | |||
rspamd_rcl_actions_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
const gchar *key, gpointer ud, | |||
const char *key, gpointer ud, | |||
struct rspamd_rcl_section *section, GError **err) | |||
{ | |||
auto *cfg = static_cast<rspamd_config *>(ud); | |||
@@ -707,7 +707,7 @@ rspamd_rcl_actions_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
it = ucl_object_iterate_new(obj); | |||
while ((cur = ucl_object_iterate_safe(it, true)) != nullptr) { | |||
gint type = ucl_object_type(cur); | |||
int type = ucl_object_type(cur); | |||
if (type == UCL_NULL) { | |||
rspamd_config_maybe_disable_action(cfg, ucl_object_key(cur), | |||
@@ -759,7 +759,7 @@ constexpr const auto known_worker_attributes = frozen::make_unordered_set<frozen | |||
}); | |||
static gboolean | |||
rspamd_rcl_worker_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
const gchar *key, gpointer ud, | |||
const char *key, gpointer ud, | |||
struct rspamd_rcl_section *section, GError **err) | |||
{ | |||
auto *cfg = static_cast<rspamd_config *>(ud); | |||
@@ -883,7 +883,7 @@ rspamd_rcl_worker_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
static gboolean | |||
rspamd_rcl_lua_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
const gchar *key, gpointer ud, | |||
const char *key, gpointer ud, | |||
struct rspamd_rcl_section *section, GError **err) | |||
{ | |||
namespace fs = std::filesystem; | |||
@@ -973,7 +973,7 @@ rspamd_lua_mod_sort_fn(gconstpointer a, gconstpointer b) | |||
gboolean | |||
rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections, | |||
struct rspamd_config *cfg, | |||
const gchar *path, | |||
const char *path, | |||
gboolean main_path, | |||
GError **err) | |||
{ | |||
@@ -1040,7 +1040,7 @@ rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections, | |||
static gboolean | |||
rspamd_rcl_modules_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
const gchar *key, gpointer ud, | |||
const char *key, gpointer ud, | |||
struct rspamd_rcl_section *section, GError **err) | |||
{ | |||
auto *cfg = static_cast<rspamd_config *>(ud); | |||
@@ -1134,7 +1134,7 @@ struct statfile_parser_data { | |||
static gboolean | |||
rspamd_rcl_statfile_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
const gchar *key, gpointer ud, | |||
const char *key, gpointer ud, | |||
struct rspamd_rcl_section *section, GError **err) | |||
{ | |||
auto *stud = (struct statfile_parser_data *) ud; | |||
@@ -1211,7 +1211,7 @@ rspamd_rcl_statfile_handler(rspamd_mempool_t *pool, const ucl_object_t *obj, | |||
static gboolean | |||
rspamd_rcl_classifier_handler(rspamd_mempool_t *pool, | |||
const ucl_object_t *obj, | |||
const gchar *key, | |||
const char *key, | |||
gpointer ud, | |||
struct rspamd_rcl_section *section, | |||
GError **err) | |||
@@ -1305,9 +1305,9 @@ rspamd_rcl_classifier_handler(rspamd_mempool_t *pool, | |||
LL_FOREACH(val, cur) | |||
{ | |||
if (ucl_object_type(cur) == UCL_STRING) { | |||
const gchar *lua_script; | |||
const char *lua_script; | |||
gsize slen; | |||
gint ref_idx; | |||
int ref_idx; | |||
lua_script = ucl_object_tolstring(cur, &slen); | |||
ref_idx = rspamd_lua_function_ref_from_str(RSPAMD_LUA_CFG_STATE(cfg), | |||
@@ -1333,9 +1333,9 @@ rspamd_rcl_classifier_handler(rspamd_mempool_t *pool, | |||
LL_FOREACH(val, cur) | |||
{ | |||
if (ucl_object_type(cur) == UCL_STRING) { | |||
const gchar *lua_script; | |||
const char *lua_script; | |||
gsize slen; | |||
gint ref_idx; | |||
int ref_idx; | |||
lua_script = ucl_object_tolstring(cur, &slen); | |||
ref_idx = rspamd_lua_function_ref_from_str(RSPAMD_LUA_CFG_STATE(cfg), | |||
@@ -1363,14 +1363,14 @@ rspamd_rcl_classifier_handler(rspamd_mempool_t *pool, | |||
static gboolean | |||
rspamd_rcl_composite_handler(rspamd_mempool_t *pool, | |||
const ucl_object_t *obj, | |||
const gchar *key, | |||
const char *key, | |||
gpointer ud, | |||
struct rspamd_rcl_section *section, | |||
GError **err) | |||
{ | |||
auto *cfg = static_cast<rspamd_config *>(ud); | |||
void *composite; | |||
const gchar *composite_name; | |||
const char *composite_name; | |||
g_assert(key != nullptr); | |||
@@ -1394,7 +1394,7 @@ rspamd_rcl_composite_handler(rspamd_mempool_t *pool, | |||
static gboolean | |||
rspamd_rcl_composites_handler(rspamd_mempool_t *pool, | |||
const ucl_object_t *obj, | |||
const gchar *key, | |||
const char *key, | |||
gpointer ud, | |||
struct rspamd_rcl_section *section, | |||
GError **err) | |||
@@ -1420,14 +1420,14 @@ rspamd_rcl_composites_handler(rspamd_mempool_t *pool, | |||
static gboolean | |||
rspamd_rcl_neighbours_handler(rspamd_mempool_t *pool, | |||
const ucl_object_t *obj, | |||
const gchar *key, | |||
const char *key, | |||
gpointer ud, | |||
struct rspamd_rcl_section *section, | |||
GError **err) | |||
{ | |||
auto *cfg = static_cast<rspamd_config *>(ud); | |||
auto has_port = FALSE, has_proto = FALSE; | |||
const gchar *p; | |||
const char *p; | |||
if (key == nullptr) { | |||
g_set_error(err, | |||
@@ -1493,7 +1493,7 @@ rspamd_rcl_neighbours_handler(rspamd_mempool_t *pool, | |||
struct rspamd_rcl_section * | |||
rspamd_rcl_add_section(struct rspamd_rcl_sections_map **top, | |||
struct rspamd_rcl_section *parent_section, | |||
const gchar *name, const gchar *key_attr, rspamd_rcl_handler_t handler, | |||
const char *name, const char *key_attr, rspamd_rcl_handler_t handler, | |||
enum ucl_type type, gboolean required, gboolean strict_type) | |||
{ | |||
return rspamd_rcl_add_section_doc(top, parent_section, name, key_attr, handler, | |||
@@ -1503,10 +1503,10 @@ rspamd_rcl_add_section(struct rspamd_rcl_sections_map **top, | |||
struct rspamd_rcl_section * | |||
rspamd_rcl_add_section_doc(struct rspamd_rcl_sections_map **top, | |||
struct rspamd_rcl_section *parent_section, | |||
const gchar *name, const gchar *key_attr, rspamd_rcl_handler_t handler, | |||
const char *name, const char *key_attr, rspamd_rcl_handler_t handler, | |||
enum ucl_type type, gboolean required, gboolean strict_type, | |||
ucl_object_t *doc_target, | |||
const gchar *doc_string) | |||
const char *doc_string) | |||
{ | |||
if (top == nullptr) { | |||
g_error("invalid arguments to rspamd_rcl_add_section"); | |||
@@ -1581,11 +1581,11 @@ rspamd_rcl_add_section_doc(struct rspamd_rcl_sections_map **top, | |||
struct rspamd_rcl_default_handler_data * | |||
rspamd_rcl_add_default_handler(struct rspamd_rcl_section *section, | |||
const gchar *name, | |||
const char *name, | |||
rspamd_rcl_default_handler_t handler, | |||
goffset offset, | |||
gint flags, | |||
const gchar *doc_string) | |||
int flags, | |||
const char *doc_string) | |||
{ | |||
auto it = section->default_parser.emplace(std::make_pair(std::string{name}, rspamd_rcl_default_handler_data{})); | |||
@@ -2529,7 +2529,7 @@ rspamd_rcl_process_section(struct rspamd_config *cfg, | |||
ucl_object_iter_t it; | |||
const ucl_object_t *cur; | |||
auto is_nested = true; | |||
const gchar *key = nullptr; | |||
const char *key = nullptr; | |||
if (sec.processed) { | |||
/* Section has been already processed */ | |||
@@ -2746,22 +2746,22 @@ rspamd_rcl_parse_struct_string(rspamd_mempool_t *pool, | |||
auto *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
const gsize num_str_len = 32; | |||
auto target = (gchar **) (((gchar *) pd->user_struct) + pd->offset); | |||
auto target = (char **) (((char *) pd->user_struct) + pd->offset); | |||
switch (obj->type) { | |||
case UCL_STRING: | |||
*target = | |||
rspamd_mempool_strdup(pool, ucl_copy_value_trash(obj)); | |||
break; | |||
case UCL_INT: | |||
*target = (gchar *) rspamd_mempool_alloc(pool, num_str_len); | |||
*target = (char *) rspamd_mempool_alloc(pool, num_str_len); | |||
rspamd_snprintf(*target, num_str_len, "%L", obj->value.iv); | |||
break; | |||
case UCL_FLOAT: | |||
*target = (gchar *) rspamd_mempool_alloc(pool, num_str_len); | |||
*target = (char *) rspamd_mempool_alloc(pool, num_str_len); | |||
rspamd_snprintf(*target, num_str_len, "%f", obj->value.dv); | |||
break; | |||
case UCL_BOOLEAN: | |||
*target = (gchar *) rspamd_mempool_alloc(pool, num_str_len); | |||
*target = (char *) rspamd_mempool_alloc(pool, num_str_len); | |||
rspamd_snprintf(*target, num_str_len, "%s", | |||
((gboolean) obj->value.iv) ? "true" : "false"); | |||
break; | |||
@@ -2791,17 +2791,17 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, | |||
{ | |||
auto *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
union { | |||
gint *ip; | |||
gint32 *i32p; | |||
gint16 *i16p; | |||
gint64 *i64p; | |||
guint *up; | |||
int *ip; | |||
int32_t *i32p; | |||
int16_t *i16p; | |||
int64_t *i64p; | |||
unsigned int *up; | |||
gsize *sp; | |||
} target; | |||
int64_t val; | |||
if (pd->flags == RSPAMD_CL_FLAG_INT_32) { | |||
target.i32p = (gint32 *) (((gchar *) pd->user_struct) + pd->offset); | |||
target.i32p = (int32_t *) (((char *) pd->user_struct) + pd->offset); | |||
if (!ucl_object_toint_safe(obj, &val)) { | |||
g_set_error(err, | |||
CFG_RCL_ERROR, | |||
@@ -2814,7 +2814,7 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, | |||
*target.i32p = val; | |||
} | |||
else if (pd->flags == RSPAMD_CL_FLAG_INT_64) { | |||
target.i64p = (gint64 *) (((gchar *) pd->user_struct) + pd->offset); | |||
target.i64p = (int64_t *) (((char *) pd->user_struct) + pd->offset); | |||
if (!ucl_object_toint_safe(obj, &val)) { | |||
g_set_error(err, | |||
CFG_RCL_ERROR, | |||
@@ -2827,7 +2827,7 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, | |||
*target.i64p = val; | |||
} | |||
else if (pd->flags == RSPAMD_CL_FLAG_INT_SIZE) { | |||
target.sp = (gsize *) (((gchar *) pd->user_struct) + pd->offset); | |||
target.sp = (gsize *) (((char *) pd->user_struct) + pd->offset); | |||
if (!ucl_object_toint_safe(obj, &val)) { | |||
g_set_error(err, | |||
CFG_RCL_ERROR, | |||
@@ -2840,7 +2840,7 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, | |||
*target.sp = val; | |||
} | |||
else if (pd->flags == RSPAMD_CL_FLAG_INT_16) { | |||
target.i16p = (gint16 *) (((gchar *) pd->user_struct) + pd->offset); | |||
target.i16p = (int16_t *) (((char *) pd->user_struct) + pd->offset); | |||
if (!ucl_object_toint_safe(obj, &val)) { | |||
g_set_error(err, | |||
CFG_RCL_ERROR, | |||
@@ -2853,7 +2853,7 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, | |||
*target.i16p = val; | |||
} | |||
else if (pd->flags == RSPAMD_CL_FLAG_UINT) { | |||
target.up = (guint *) (((gchar *) pd->user_struct) + pd->offset); | |||
target.up = (unsigned int *) (((char *) pd->user_struct) + pd->offset); | |||
if (!ucl_object_toint_safe(obj, &val)) { | |||
g_set_error(err, | |||
CFG_RCL_ERROR, | |||
@@ -2866,7 +2866,7 @@ rspamd_rcl_parse_struct_integer(rspamd_mempool_t *pool, | |||
*target.up = val; | |||
} | |||
else { | |||
target.ip = (gint *) (((gchar *) pd->user_struct) + pd->offset); | |||
target.ip = (int *) (((char *) pd->user_struct) + pd->offset); | |||
if (!ucl_object_toint_safe(obj, &val)) { | |||
g_set_error(err, | |||
CFG_RCL_ERROR, | |||
@@ -2890,9 +2890,9 @@ rspamd_rcl_parse_struct_double(rspamd_mempool_t *pool, | |||
GError **err) | |||
{ | |||
auto *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
gdouble *target; | |||
double *target; | |||
target = (gdouble *) (((gchar *) pd->user_struct) + pd->offset); | |||
target = (double *) (((char *) pd->user_struct) + pd->offset); | |||
if (!ucl_object_todouble_safe(obj, target)) { | |||
g_set_error(err, | |||
@@ -2916,13 +2916,13 @@ rspamd_rcl_parse_struct_time(rspamd_mempool_t *pool, | |||
{ | |||
auto *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
union { | |||
gint *psec; | |||
guint32 *pu32; | |||
gdouble *pdv; | |||
int *psec; | |||
uint32_t *pu32; | |||
double *pdv; | |||
struct timeval *ptv; | |||
struct timespec *pts; | |||
} target; | |||
gdouble val; | |||
double val; | |||
if (!ucl_object_todouble_safe(obj, &val)) { | |||
g_set_error(err, | |||
@@ -2936,26 +2936,26 @@ rspamd_rcl_parse_struct_time(rspamd_mempool_t *pool, | |||
if (pd->flags == RSPAMD_CL_FLAG_TIME_TIMEVAL) { | |||
target.ptv = | |||
(struct timeval *) (((gchar *) pd->user_struct) + pd->offset); | |||
(struct timeval *) (((char *) pd->user_struct) + pd->offset); | |||
target.ptv->tv_sec = (glong) val; | |||
target.ptv->tv_usec = (val - (glong) val) * 1000000; | |||
} | |||
else if (pd->flags == RSPAMD_CL_FLAG_TIME_TIMESPEC) { | |||
target.pts = | |||
(struct timespec *) (((gchar *) pd->user_struct) + pd->offset); | |||
(struct timespec *) (((char *) pd->user_struct) + pd->offset); | |||
target.pts->tv_sec = (glong) val; | |||
target.pts->tv_nsec = (val - (glong) val) * 1000000000000LL; | |||
} | |||
else if (pd->flags == RSPAMD_CL_FLAG_TIME_FLOAT) { | |||
target.pdv = (double *) (((gchar *) pd->user_struct) + pd->offset); | |||
target.pdv = (double *) (((char *) pd->user_struct) + pd->offset); | |||
*target.pdv = val; | |||
} | |||
else if (pd->flags == RSPAMD_CL_FLAG_TIME_INTEGER) { | |||
target.psec = (gint *) (((gchar *) pd->user_struct) + pd->offset); | |||
target.psec = (int *) (((char *) pd->user_struct) + pd->offset); | |||
*target.psec = val * 1000; | |||
} | |||
else if (pd->flags == RSPAMD_CL_FLAG_TIME_UINT_32) { | |||
target.pu32 = (guint32 *) (((gchar *) pd->user_struct) + pd->offset); | |||
target.pu32 = (uint32_t *) (((char *) pd->user_struct) + pd->offset); | |||
*target.pu32 = val * 1000; | |||
} | |||
else { | |||
@@ -2981,7 +2981,7 @@ rspamd_rcl_parse_struct_keypair(rspamd_mempool_t *pool, | |||
auto *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
struct rspamd_cryptobox_keypair **target, *kp; | |||
target = (struct rspamd_cryptobox_keypair **) (((gchar *) pd->user_struct) + | |||
target = (struct rspamd_cryptobox_keypair **) (((char *) pd->user_struct) + | |||
pd->offset); | |||
if (obj->type == UCL_OBJECT) { | |||
kp = rspamd_keypair_from_ucl(obj); | |||
@@ -2992,7 +2992,7 @@ rspamd_rcl_parse_struct_keypair(rspamd_mempool_t *pool, | |||
*target = kp; | |||
} | |||
else { | |||
gchar *dump = (char *) ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT); | |||
char *dump = (char *) ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT); | |||
g_set_error(err, | |||
CFG_RCL_ERROR, | |||
EINVAL, | |||
@@ -3025,7 +3025,7 @@ rspamd_rcl_parse_struct_pubkey(rspamd_mempool_t *pool, | |||
auto *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
struct rspamd_cryptobox_pubkey **target, *pk; | |||
gsize len; | |||
const gchar *str; | |||
const char *str; | |||
rspamd_cryptobox_keypair_type keypair_type = RSPAMD_KEYPAIR_KEX; | |||
rspamd_cryptobox_mode keypair_mode = RSPAMD_CRYPTOBOX_MODE_25519; | |||
@@ -3036,7 +3036,7 @@ rspamd_rcl_parse_struct_pubkey(rspamd_mempool_t *pool, | |||
keypair_mode = RSPAMD_CRYPTOBOX_MODE_NIST; | |||
} | |||
target = (struct rspamd_cryptobox_pubkey **) (((gchar *) pd->user_struct) + | |||
target = (struct rspamd_cryptobox_pubkey **) (((char *) pd->user_struct) + | |||
pd->offset); | |||
if (obj->type == UCL_STRING) { | |||
str = ucl_object_tolstring(obj, &len); | |||
@@ -3079,7 +3079,7 @@ rspamd_rcl_insert_string_list_item(gpointer *target, rspamd_mempool_t *pool, | |||
GList *lv; | |||
gpointer p; | |||
} d; | |||
gchar *val; | |||
char *val; | |||
d.p = *target; | |||
@@ -3114,7 +3114,7 @@ rspamd_rcl_parse_struct_string_list(rspamd_mempool_t *pool, | |||
auto is_hash = pd->flags & RSPAMD_CL_FLAG_STRING_LIST_HASH; | |||
auto *target = (gpointer *) (((gchar *) pd->user_struct) + pd->offset); | |||
auto *target = (gpointer *) (((char *) pd->user_struct) + pd->offset); | |||
if (!is_hash && *target != nullptr) { | |||
need_destructor = FALSE; | |||
@@ -3134,19 +3134,19 @@ rspamd_rcl_parse_struct_string_list(rspamd_mempool_t *pool, | |||
continue; | |||
} | |||
case UCL_INT: { | |||
auto *val = (gchar *) rspamd_mempool_alloc(pool, num_str_len); | |||
auto *val = (char *) rspamd_mempool_alloc(pool, num_str_len); | |||
rspamd_snprintf(val, num_str_len, "%L", cur->value.iv); | |||
rspamd_rcl_insert_string_list_item(target, pool, val, is_hash); | |||
break; | |||
} | |||
case UCL_FLOAT: { | |||
auto *val = (gchar *) rspamd_mempool_alloc(pool, num_str_len); | |||
auto *val = (char *) rspamd_mempool_alloc(pool, num_str_len); | |||
rspamd_snprintf(val, num_str_len, "%f", cur->value.dv); | |||
rspamd_rcl_insert_string_list_item(target, pool, val, is_hash); | |||
break; | |||
} | |||
case UCL_BOOLEAN: { | |||
auto *val = (gchar *) rspamd_mempool_alloc(pool, num_str_len); | |||
auto *val = (char *) rspamd_mempool_alloc(pool, num_str_len); | |||
rspamd_snprintf(val, num_str_len, "%s", | |||
((gboolean) cur->value.iv) ? "true" : "false"); | |||
rspamd_rcl_insert_string_list_item(target, pool, val, is_hash); | |||
@@ -3204,7 +3204,7 @@ rspamd_rcl_parse_struct_ucl(rspamd_mempool_t *pool, | |||
auto *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
const ucl_object_t **target; | |||
target = (const ucl_object_t **) (((gchar *) pd->user_struct) + pd->offset); | |||
target = (const ucl_object_t **) (((char *) pd->user_struct) + pd->offset); | |||
*target = obj; | |||
@@ -3222,7 +3222,7 @@ rspamd_rcl_parse_struct_boolean(rspamd_mempool_t *pool, | |||
auto *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
gboolean *target; | |||
target = (gboolean *) (((gchar *) pd->user_struct) + pd->offset); | |||
target = (gboolean *) (((char *) pd->user_struct) + pd->offset); | |||
if (obj->type == UCL_BOOLEAN) { | |||
*target = obj->value.iv; | |||
@@ -3256,10 +3256,10 @@ rspamd_rcl_parse_struct_addr(rspamd_mempool_t *pool, | |||
{ | |||
auto *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
rspamd_inet_addr_t **target; | |||
const gchar *val; | |||
const char *val; | |||
gsize size; | |||
target = (rspamd_inet_addr_t **) (((gchar *) pd->user_struct) + pd->offset); | |||
target = (rspamd_inet_addr_t **) (((char *) pd->user_struct) + pd->offset); | |||
if (ucl_object_type(obj) == UCL_STRING) { | |||
val = ucl_object_tolstring(obj, &size); | |||
@@ -3295,11 +3295,11 @@ rspamd_rcl_parse_struct_mime_addr(rspamd_mempool_t *pool, | |||
{ | |||
auto *pd = (struct rspamd_rcl_struct_parser *) ud; | |||
GPtrArray **target, *tmp_addr = nullptr; | |||
const gchar *val; | |||
const char *val; | |||
ucl_object_iter_t it; | |||
const ucl_object_t *cur; | |||
target = (GPtrArray **) (((gchar *) pd->user_struct) + pd->offset); | |||
target = (GPtrArray **) (((char *) pd->user_struct) + pd->offset); | |||
it = ucl_object_iterate_new(obj); | |||
while ((cur = ucl_object_iterate_safe(it, true)) != nullptr) { | |||
@@ -3328,12 +3328,12 @@ rspamd_rcl_parse_struct_mime_addr(rspamd_mempool_t *pool, | |||
void rspamd_rcl_register_worker_option(struct rspamd_config *cfg, | |||
GQuark type, | |||
const gchar *name, | |||
const char *name, | |||
rspamd_rcl_default_handler_t handler, | |||
gpointer target, | |||
glong offset, | |||
gint flags, | |||
const gchar *doc_string) | |||
int flags, | |||
const char *doc_string) | |||
{ | |||
auto parser_it = cfg->rcl_top_section->workers_parser.try_emplace(type, rspamd_worker_cfg_parser{}); | |||
auto &parser = parser_it.first->second; | |||
@@ -3385,12 +3385,12 @@ static int | |||
rspamd_rcl_emitter_append_c(unsigned char c, size_t nchars, void *ud) | |||
{ | |||
auto *hs = (rspamd_cryptobox_hash_state_t *) ud; | |||
guint64 d[2]; | |||
uint64_t d[2]; | |||
d[0] = nchars; | |||
d[1] = c; | |||
rspamd_cryptobox_hash_update(hs, (const guchar *) d, sizeof(d)); | |||
rspamd_cryptobox_hash_update(hs, (const unsigned char *) d, sizeof(d)); | |||
return 0; | |||
} | |||
@@ -3409,7 +3409,7 @@ rspamd_rcl_emitter_append_int(int64_t elt, void *ud) | |||
{ | |||
auto *hs = (rspamd_cryptobox_hash_state_t *) ud; | |||
rspamd_cryptobox_hash_update(hs, (const guchar *) &elt, sizeof(elt)); | |||
rspamd_cryptobox_hash_update(hs, (const unsigned char *) &elt, sizeof(elt)); | |||
return 0; | |||
} | |||
@@ -3419,7 +3419,7 @@ rspamd_rcl_emitter_append_double(double elt, void *ud) | |||
{ | |||
auto *hs = (rspamd_cryptobox_hash_state_t *) ud; | |||
rspamd_cryptobox_hash_update(hs, (const guchar *) &elt, sizeof(elt)); | |||
rspamd_cryptobox_hash_update(hs, (const unsigned char *) &elt, sizeof(elt)); | |||
return 0; | |||
} | |||
@@ -3597,7 +3597,7 @@ void rspamd_config_calculate_cksum(struct rspamd_config *cfg) | |||
gboolean | |||
rspamd_config_parse_ucl(struct rspamd_config *cfg, | |||
const gchar *filename, | |||
const char *filename, | |||
GHashTable *vars, | |||
ucl_include_trace_func_t inc_trace, | |||
void *trace_data, | |||
@@ -3691,12 +3691,12 @@ rspamd_config_parse_ucl(struct rspamd_config *cfg, | |||
gboolean | |||
rspamd_config_read(struct rspamd_config *cfg, | |||
const gchar *filename, | |||
const char *filename, | |||
rspamd_rcl_section_fin_t logger_fin, | |||
gpointer logger_ud, | |||
GHashTable *vars, | |||
gboolean skip_jinja, | |||
gchar **lua_env) | |||
char **lua_env) | |||
{ | |||
GError *err = nullptr; | |||
@@ -3802,7 +3802,7 @@ rspamd_config_read(struct rspamd_config *cfg, | |||
static void | |||
rspamd_rcl_doc_obj_from_handler(ucl_object_t *doc_obj, | |||
rspamd_rcl_default_handler_t handler, | |||
gint flags) | |||
int flags) | |||
{ | |||
auto has_example = ucl_object_lookup(doc_obj, "example") != nullptr; | |||
auto has_type = ucl_object_lookup(doc_obj, "type") != nullptr; | |||
@@ -3920,7 +3920,7 @@ rspamd_rcl_add_doc_obj(ucl_object_t *doc_target, | |||
const char *doc_name, | |||
ucl_type_t type, | |||
rspamd_rcl_default_handler_t handler, | |||
gint flags, | |||
int flags, | |||
const char *default_value, | |||
gboolean required) | |||
{ | |||
@@ -3968,12 +3968,12 @@ rspamd_rcl_add_doc_obj(ucl_object_t *doc_target, | |||
ucl_object_t * | |||
rspamd_rcl_add_doc_by_path(struct rspamd_config *cfg, | |||
const gchar *doc_path, | |||
const char *doc_path, | |||
const char *doc_string, | |||
const char *doc_name, | |||
ucl_type_t type, | |||
rspamd_rcl_default_handler_t handler, | |||
gint flags, | |||
int flags, | |||
const char *default_value, | |||
gboolean required) | |||
{ | |||
@@ -4080,10 +4080,10 @@ rspamd_rcl_add_doc_from_comments(struct rspamd_config *cfg, | |||
ucl_object_t * | |||
rspamd_rcl_add_doc_by_example(struct rspamd_config *cfg, | |||
const gchar *root_path, | |||
const gchar *doc_string, | |||
const gchar *doc_name, | |||
const gchar *example_data, gsize example_len) | |||
const char *root_path, | |||
const char *doc_string, | |||
const char *doc_name, | |||
const char *example_data, gsize example_len) | |||
{ | |||
auto parser = std::shared_ptr<ucl_parser>(ucl_parser_new(UCL_PARSER_NO_FILEVARS | UCL_PARSER_SAVE_COMMENTS), ucl_parser_free); | |||
@@ -74,7 +74,7 @@ struct rspamd_rcl_struct_parser { | |||
*/ | |||
typedef gboolean (*rspamd_rcl_handler_t)(rspamd_mempool_t *pool, | |||
const ucl_object_t *obj, | |||
const gchar *key, | |||
const char *key, | |||
gpointer ud, | |||
struct rspamd_rcl_section *section, | |||
GError **err); | |||
@@ -103,11 +103,11 @@ typedef void (*rspamd_rcl_section_fin_t)(rspamd_mempool_t *pool, gpointer ud); | |||
*/ | |||
struct rspamd_rcl_default_handler_data *rspamd_rcl_add_default_handler( | |||
struct rspamd_rcl_section *section, | |||
const gchar *name, | |||
const char *name, | |||
rspamd_rcl_default_handler_t handler, | |||
goffset offset, | |||
gint flags, | |||
const gchar *doc_string); | |||
int flags, | |||
const char *doc_string); | |||
/** | |||
* Add new section to the configuration | |||
@@ -123,8 +123,8 @@ struct rspamd_rcl_default_handler_data *rspamd_rcl_add_default_handler( | |||
struct rspamd_rcl_section *rspamd_rcl_add_section( | |||
struct rspamd_rcl_sections_map **top, | |||
struct rspamd_rcl_section *parent_section, | |||
const gchar *name, | |||
const gchar *key_attr, | |||
const char *name, | |||
const char *key_attr, | |||
rspamd_rcl_handler_t handler, | |||
enum ucl_type type, | |||
gboolean required, | |||
@@ -133,12 +133,12 @@ struct rspamd_rcl_section *rspamd_rcl_add_section( | |||
struct rspamd_rcl_section *rspamd_rcl_add_section_doc( | |||
struct rspamd_rcl_sections_map **top, | |||
struct rspamd_rcl_section *parent_section, | |||
const gchar *name, const gchar *key_attr, | |||
const char *name, const char *key_attr, | |||
rspamd_rcl_handler_t handler, | |||
enum ucl_type type, gboolean required, | |||
gboolean strict_type, | |||
ucl_object_t *doc_target, | |||
const gchar *doc_string); | |||
const char *doc_string); | |||
/** | |||
* Init common sections known to rspamd | |||
@@ -350,12 +350,12 @@ gboolean rspamd_rcl_parse_struct_ucl(rspamd_mempool_t *pool, | |||
*/ | |||
void rspamd_rcl_register_worker_option(struct rspamd_config *cfg, | |||
GQuark type, | |||
const gchar *name, | |||
const char *name, | |||
rspamd_rcl_default_handler_t handler, | |||
gpointer target, | |||
glong offset, | |||
gint flags, | |||
const gchar *doc_string); | |||
int flags, | |||
const char *doc_string); | |||
/** | |||
* Adds new documentation object to the configuration | |||
@@ -367,7 +367,7 @@ ucl_object_t *rspamd_rcl_add_doc_obj(ucl_object_t *doc_target, | |||
const char *doc_name, | |||
ucl_type_t type, | |||
rspamd_rcl_default_handler_t handler, | |||
gint flags, | |||
int flags, | |||
const char *default_value, | |||
gboolean required); | |||
@@ -376,12 +376,12 @@ ucl_object_t *rspamd_rcl_add_doc_obj(ucl_object_t *doc_target, | |||
* split by dots | |||
*/ | |||
ucl_object_t *rspamd_rcl_add_doc_by_path(struct rspamd_config *cfg, | |||
const gchar *doc_path, | |||
const char *doc_path, | |||
const char *doc_string, | |||
const char *doc_name, | |||
ucl_type_t type, | |||
rspamd_rcl_default_handler_t handler, | |||
gint flags, | |||
int flags, | |||
const char *default_value, | |||
gboolean required); | |||
@@ -408,10 +408,10 @@ ucl_object_t *rspamd_rcl_add_doc_by_path(struct rspamd_config *cfg, | |||
* @return | |||
*/ | |||
ucl_object_t *rspamd_rcl_add_doc_by_example(struct rspamd_config *cfg, | |||
const gchar *root_path, | |||
const gchar *doc_string, | |||
const gchar *doc_name, | |||
const gchar *example_data, gsize example_len); | |||
const char *root_path, | |||
const char *doc_string, | |||
const char *doc_name, | |||
const char *example_data, gsize example_len); | |||
/** | |||
* Add lua modules path | |||
@@ -422,7 +422,7 @@ ucl_object_t *rspamd_rcl_add_doc_by_example(struct rspamd_config *cfg, | |||
*/ | |||
gboolean rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections, | |||
struct rspamd_config *cfg, | |||
const gchar *path, | |||
const char *path, | |||
gboolean main_path, | |||
GError **err); | |||
@@ -455,19 +455,19 @@ void rspamd_config_calculate_cksum(struct rspamd_config *cfg); | |||
* Read configuration file | |||
*/ | |||
gboolean rspamd_config_parse_ucl(struct rspamd_config *cfg, | |||
const gchar *filename, | |||
const char *filename, | |||
GHashTable *vars, | |||
ucl_include_trace_func_t inc_trace, | |||
void *trace_data, | |||
gboolean skip_jinja, | |||
GError **err); | |||
gboolean rspamd_config_read(struct rspamd_config *cfg, | |||
const gchar *filename, | |||
const char *filename, | |||
rspamd_rcl_section_fin_t logger_fin, | |||
gpointer logger_ud, | |||
GHashTable *vars, | |||
gboolean skip_jinja, | |||
gchar **lua_env); | |||
char **lua_env); | |||
#ifdef __cplusplus | |||
} |
@@ -101,14 +101,14 @@ struct rspamd_ucl_map_cbdata { | |||
{ | |||
} | |||
}; | |||
static gchar *rspamd_ucl_read_cb(gchar *chunk, | |||
gint len, | |||
struct map_cb_data *data, | |||
gboolean final); | |||
static char *rspamd_ucl_read_cb(char *chunk, | |||
int len, | |||
struct map_cb_data *data, | |||
gboolean final); | |||
static void rspamd_ucl_fin_cb(struct map_cb_data *data, void **target); | |||
static void rspamd_ucl_dtor_cb(struct map_cb_data *data); | |||
guint rspamd_config_log_id = (guint) -1; | |||
unsigned int rspamd_config_log_id = (unsigned int) -1; | |||
RSPAMD_CONSTRUCTOR(rspamd_config_log_init) | |||
{ | |||
rspamd_config_log_id = rspamd_logger_add_debug_module("config"); | |||
@@ -162,10 +162,10 @@ struct rspamd_actions_list { | |||
gboolean | |||
rspamd_parse_bind_line(struct rspamd_config *cfg, | |||
struct rspamd_worker_conf *cf, | |||
const gchar *str) | |||
const char *str) | |||
{ | |||
struct rspamd_worker_bind_conf *cnf; | |||
const gchar *fdname; | |||
const char *fdname; | |||
gboolean ret = TRUE; | |||
if (str == nullptr) { | |||
@@ -437,8 +437,8 @@ void rspamd_config_free(struct rspamd_config *cfg) | |||
const ucl_object_t * | |||
rspamd_config_get_module_opt(struct rspamd_config *cfg, | |||
const gchar *module_name, | |||
const gchar *opt_name) | |||
const char *module_name, | |||
const char *opt_name) | |||
{ | |||
const ucl_object_t *res = nullptr, *sec; | |||
@@ -450,9 +450,9 @@ rspamd_config_get_module_opt(struct rspamd_config *cfg, | |||
return res; | |||
} | |||
gint rspamd_config_parse_flag(const gchar *str, guint len) | |||
int rspamd_config_parse_flag(const char *str, unsigned int len) | |||
{ | |||
gint c; | |||
int c; | |||
if (!str || !*str) { | |||
return -1; | |||
@@ -627,8 +627,8 @@ rspamd_config_process_var(struct rspamd_config *cfg, const rspamd_ftok_t *var, | |||
static gboolean | |||
rspamd_config_parse_log_format(struct rspamd_config *cfg) | |||
{ | |||
const gchar *p, *c, *end, *s; | |||
gchar *d; | |||
const char *p, *c, *end, *s; | |||
char *d; | |||
struct rspamd_log_format *lf = nullptr; | |||
rspamd_ftok_t var, var_content; | |||
enum { | |||
@@ -637,7 +637,7 @@ rspamd_config_parse_log_format(struct rspamd_config *cfg) | |||
parse_var_name, | |||
parse_var_content, | |||
} state = parse_str; | |||
gint braces = 0; | |||
int braces = 0; | |||
g_assert(cfg != nullptr); | |||
c = cfg->log_format_str; | |||
@@ -1026,7 +1026,7 @@ void rspamd_config_init_metric(struct rspamd_config *cfg) | |||
} | |||
struct rspamd_symbols_group * | |||
rspamd_config_new_group(struct rspamd_config *cfg, const gchar *name) | |||
rspamd_config_new_group(struct rspamd_config *cfg, const char *name) | |||
{ | |||
struct rspamd_symbols_group *gr; | |||
@@ -1093,7 +1093,7 @@ rspamd_config_new_worker(struct rspamd_config *cfg, | |||
static bool | |||
rspamd_include_map_handler(const guchar *data, gsize len, | |||
rspamd_include_map_handler(const unsigned char *data, gsize len, | |||
const ucl_object_t *args, void *ud) | |||
{ | |||
auto *cfg = (struct rspamd_config *) ud; | |||
@@ -1236,7 +1236,7 @@ void rspamd_config_insert_classify_symbols(struct rspamd_config *cfg) | |||
} | |||
struct rspamd_classifier_config * | |||
rspamd_config_find_classifier(struct rspamd_config *cfg, const gchar *name) | |||
rspamd_config_find_classifier(struct rspamd_config *cfg, const char *name) | |||
{ | |||
if (name == nullptr) { | |||
return nullptr; | |||
@@ -1312,9 +1312,9 @@ rspamd_config_check_statfiles(struct rspamd_classifier_config *cf) | |||
return res; | |||
} | |||
static gchar * | |||
rspamd_ucl_read_cb(gchar *chunk, | |||
gint len, | |||
static char * | |||
rspamd_ucl_read_cb(char *chunk, | |||
int len, | |||
struct map_cb_data *data, | |||
gboolean final) | |||
{ | |||
@@ -1388,7 +1388,7 @@ rspamd_check_module(struct rspamd_config *cfg, module_t *mod) | |||
if (mod != nullptr) { | |||
if (mod->module_version != RSPAMD_CUR_MODULE_VERSION) { | |||
msg_err_config("module %s has incorrect version %xd (%xd expected)", | |||
mod->name, (gint) mod->module_version, RSPAMD_CUR_MODULE_VERSION); | |||
mod->name, (int) mod->module_version, RSPAMD_CUR_MODULE_VERSION); | |||
ret = FALSE; | |||
} | |||
if (ret && mod->rspamd_version != RSPAMD_VERSION_NUM) { | |||
@@ -1443,7 +1443,7 @@ rspamd_init_filters(struct rspamd_config *cfg, bool reconfig, bool strict) | |||
{ | |||
GList *cur; | |||
module_t *mod, **pmod; | |||
guint i = 0; | |||
unsigned int i = 0; | |||
struct module_ctx *mod_ctx, *cur_ctx; | |||
gboolean ret = TRUE; | |||
@@ -1470,7 +1470,7 @@ rspamd_init_filters(struct rspamd_config *cfg, bool reconfig, bool strict) | |||
PTR_ARRAY_FOREACH(cfg->c_modules, i, cur_ctx) | |||
{ | |||
if (g_ascii_strcasecmp(cur_ctx->mod->name, | |||
(const gchar *) cur->data) == 0) { | |||
(const char *) cur->data) == 0) { | |||
mod_ctx = cur_ctx; | |||
break; | |||
} | |||
@@ -1513,9 +1513,9 @@ rspamd_init_filters(struct rspamd_config *cfg, bool reconfig, bool strict) | |||
} | |||
static void | |||
rspamd_config_new_symbol(struct rspamd_config *cfg, const gchar *symbol, | |||
gdouble score, const gchar *description, const gchar *group, | |||
guint flags, guint priority, gint nshots) | |||
rspamd_config_new_symbol(struct rspamd_config *cfg, const char *symbol, | |||
double score, const char *description, const char *group, | |||
unsigned int flags, unsigned int priority, int nshots) | |||
{ | |||
struct rspamd_symbols_group *sym_group; | |||
struct rspamd_symbol *sym_def; | |||
@@ -1585,17 +1585,17 @@ rspamd_config_new_symbol(struct rspamd_config *cfg, const gchar *symbol, | |||
gboolean | |||
rspamd_config_add_symbol(struct rspamd_config *cfg, | |||
const gchar *symbol, | |||
gdouble score, | |||
const gchar *description, | |||
const gchar *group, | |||
guint flags, | |||
guint priority, | |||
gint nshots) | |||
const char *symbol, | |||
double score, | |||
const char *description, | |||
const char *group, | |||
unsigned int flags, | |||
unsigned int priority, | |||
int nshots) | |||
{ | |||
struct rspamd_symbol *sym_def; | |||
struct rspamd_symbols_group *sym_group; | |||
guint i; | |||
unsigned int i; | |||
g_assert(cfg != nullptr); | |||
g_assert(symbol != nullptr); | |||
@@ -1724,12 +1724,12 @@ rspamd_config_add_symbol(struct rspamd_config *cfg, | |||
gboolean | |||
rspamd_config_add_symbol_group(struct rspamd_config *cfg, | |||
const gchar *symbol, | |||
const gchar *group) | |||
const char *symbol, | |||
const char *group) | |||
{ | |||
struct rspamd_symbol *sym_def; | |||
struct rspamd_symbols_group *sym_group; | |||
guint i; | |||
unsigned int i; | |||
g_assert(cfg != nullptr); | |||
g_assert(symbol != nullptr); | |||
@@ -1787,7 +1787,7 @@ rspamd_config_is_enabled_from_ucl(rspamd_mempool_t *pool, | |||
return ucl_object_toboolean(enabled); | |||
} | |||
else if (ucl_object_type(enabled) == UCL_STRING) { | |||
gint ret = rspamd_config_parse_flag(ucl_object_tostring(enabled), 0); | |||
int ret = rspamd_config_parse_flag(ucl_object_tostring(enabled), 0); | |||
if (ret == 0) { | |||
return FALSE; | |||
@@ -1811,7 +1811,7 @@ rspamd_config_is_enabled_from_ucl(rspamd_mempool_t *pool, | |||
return !ucl_object_toboolean(disabled); | |||
} | |||
else if (ucl_object_type(disabled) == UCL_STRING) { | |||
gint ret = rspamd_config_parse_flag(ucl_object_tostring(disabled), 0); | |||
int ret = rspamd_config_parse_flag(ucl_object_tostring(disabled), 0); | |||
if (ret == 0) { | |||
return TRUE; | |||
@@ -1831,7 +1831,7 @@ rspamd_config_is_enabled_from_ucl(rspamd_mempool_t *pool, | |||
gboolean | |||
rspamd_config_is_module_enabled(struct rspamd_config *cfg, | |||
const gchar *module_name) | |||
const char *module_name) | |||
{ | |||
gboolean is_c = FALSE, enabled; | |||
const ucl_object_t *conf; | |||
@@ -1839,7 +1839,7 @@ rspamd_config_is_module_enabled(struct rspamd_config *cfg, | |||
struct rspamd_symbols_group *gr; | |||
lua_State *L = RSPAMD_LUA_CFG_STATE(cfg); | |||
struct module_ctx *cur_ctx; | |||
guint i; | |||
unsigned int i; | |||
PTR_ARRAY_FOREACH(cfg->c_modules, i, cur_ctx) | |||
{ | |||
@@ -1931,7 +1931,7 @@ static gboolean | |||
rspamd_config_action_from_ucl(struct rspamd_config *cfg, | |||
struct rspamd_action *act, | |||
const ucl_object_t *obj, | |||
guint priority) | |||
unsigned int priority) | |||
{ | |||
auto threshold = NAN; | |||
int flags = 0; | |||
@@ -1955,7 +1955,7 @@ rspamd_config_action_from_ucl(struct rspamd_config *cfg, | |||
while ((cur = ucl_object_iterate(elt, &it, true)) != nullptr) { | |||
if (ucl_object_type(cur) == UCL_STRING) { | |||
const gchar *fl_str = ucl_object_tostring(cur); | |||
const char *fl_str = ucl_object_tostring(cur); | |||
if (g_ascii_strcasecmp(fl_str, "no_threshold") == 0) { | |||
flags |= RSPAMD_ACTION_NO_THRESHOLD; | |||
@@ -1976,7 +1976,7 @@ rspamd_config_action_from_ucl(struct rspamd_config *cfg, | |||
elt = ucl_object_lookup(obj, "milter"); | |||
if (elt) { | |||
const gchar *milter_action = ucl_object_tostring(elt); | |||
const char *milter_action = ucl_object_tostring(elt); | |||
if (strcmp(milter_action, "discard") == 0) { | |||
flags |= RSPAMD_ACTION_MILTER; | |||
@@ -2024,12 +2024,12 @@ rspamd_config_action_from_ucl(struct rspamd_config *cfg, | |||
gboolean | |||
rspamd_config_set_action_score(struct rspamd_config *cfg, | |||
const gchar *action_name, | |||
const char *action_name, | |||
const ucl_object_t *obj) | |||
{ | |||
enum rspamd_action_type std_act; | |||
const ucl_object_t *elt; | |||
guint priority = ucl_object_get_priority(obj), obj_type; | |||
unsigned int priority = ucl_object_get_priority(obj), obj_type; | |||
g_assert(cfg != nullptr); | |||
g_assert(action_name != nullptr); | |||
@@ -2107,8 +2107,8 @@ rspamd_config_set_action_score(struct rspamd_config *cfg, | |||
gboolean | |||
rspamd_config_maybe_disable_action(struct rspamd_config *cfg, | |||
const gchar *action_name, | |||
guint priority) | |||
const char *action_name, | |||
unsigned int priority) | |||
{ | |||
auto actions = RSPAMD_CFG_ACTIONS(cfg); | |||
auto maybe_act = rspamd::find_map(actions->actions_by_name, action_name); | |||
@@ -2140,7 +2140,7 @@ rspamd_config_maybe_disable_action(struct rspamd_config *cfg, | |||
} | |||
struct rspamd_action * | |||
rspamd_config_get_action(struct rspamd_config *cfg, const gchar *name) | |||
rspamd_config_get_action(struct rspamd_config *cfg, const char *name) | |||
{ | |||
auto actions = RSPAMD_CFG_ACTIONS(cfg); | |||
auto maybe_act = rspamd::find_map(actions->actions_by_name, name); | |||
@@ -2189,14 +2189,14 @@ gsize rspamd_config_actions_size(struct rspamd_config *cfg) | |||
} | |||
gboolean | |||
rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const gchar *description, | |||
rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const char *description, | |||
struct rspamd_radix_map_helper **target, GError **err, | |||
struct rspamd_worker *worker, const gchar *map_name) | |||
struct rspamd_worker *worker, const char *map_name) | |||
{ | |||
ucl_type_t type; | |||
ucl_object_iter_t it = nullptr; | |||
const ucl_object_t *cur, *cur_elt; | |||
const gchar *str; | |||
const char *str; | |||
/* Cleanup */ | |||
*target = nullptr; | |||
@@ -2317,7 +2317,7 @@ constexpr const auto action_types = frozen::make_unordered_map<frozen::string, e | |||
}); | |||
gboolean | |||
rspamd_action_from_str(const gchar *data, enum rspamd_action_type *result) | |||
rspamd_action_from_str(const char *data, enum rspamd_action_type *result) | |||
{ | |||
auto maybe_action = rspamd::find_map(action_types, std::string_view{data}); | |||
@@ -2330,7 +2330,7 @@ rspamd_action_from_str(const gchar *data, enum rspamd_action_type *result) | |||
} | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_action_to_str(enum rspamd_action_type action) | |||
{ | |||
switch (action) { | |||
@@ -2359,7 +2359,7 @@ rspamd_action_to_str(enum rspamd_action_type action) | |||
return "unknown action"; | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_action_to_str_alt(enum rspamd_action_type action) | |||
{ | |||
switch (action) { | |||
@@ -2399,20 +2399,20 @@ rspamd_config_settings_elt_dtor(struct rspamd_config_settings_elt *e) | |||
} | |||
} | |||
guint32 | |||
rspamd_config_name_to_id(const gchar *name, gsize namelen) | |||
uint32_t | |||
rspamd_config_name_to_id(const char *name, gsize namelen) | |||
{ | |||
guint64 h; | |||
uint64_t h; | |||
h = rspamd_cryptobox_fast_hash_specific(RSPAMD_CRYPTOBOX_XXHASH64, | |||
name, namelen, 0x0); | |||
/* Take the lower part of hash as LE number */ | |||
return ((guint32) GUINT64_TO_LE(h)); | |||
return ((uint32_t) GUINT64_TO_LE(h)); | |||
} | |||
struct rspamd_config_settings_elt * | |||
rspamd_config_find_settings_id_ref(struct rspamd_config *cfg, | |||
guint32 id) | |||
uint32_t id) | |||
{ | |||
struct rspamd_config_settings_elt *cur; | |||
@@ -2429,9 +2429,9 @@ rspamd_config_find_settings_id_ref(struct rspamd_config *cfg, | |||
struct rspamd_config_settings_elt *rspamd_config_find_settings_name_ref( | |||
struct rspamd_config *cfg, | |||
const gchar *name, gsize namelen) | |||
const char *name, gsize namelen) | |||
{ | |||
guint32 id; | |||
uint32_t id; | |||
id = rspamd_config_name_to_id(name, namelen); | |||
@@ -2439,13 +2439,13 @@ struct rspamd_config_settings_elt *rspamd_config_find_settings_name_ref( | |||
} | |||
void rspamd_config_register_settings_id(struct rspamd_config *cfg, | |||
const gchar *name, | |||
const char *name, | |||
ucl_object_t *symbols_enabled, | |||
ucl_object_t *symbols_disabled, | |||
enum rspamd_config_settings_policy policy) | |||
{ | |||
struct rspamd_config_settings_elt *elt; | |||
guint32 id; | |||
uint32_t id; | |||
id = rspamd_config_name_to_id(name, strlen(name)); | |||
elt = rspamd_config_find_settings_id_ref(cfg, id); | |||
@@ -2561,7 +2561,7 @@ int rspamd_config_ev_backend_get(struct rspamd_config *cfg) | |||
return AUTO_BACKEND; | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_config_ev_backend_to_string(int ev_backend, gboolean *effective) | |||
{ | |||
#define SET_EFFECTIVE(b) \ | |||
@@ -2638,7 +2638,7 @@ rspamd_init_libs(void) | |||
#endif | |||
/* Configure utf8 library */ | |||
guint utf8_flags = 0; | |||
unsigned int utf8_flags = 0; | |||
if ((ctx->crypto_ctx->cpu_config & CPUID_SSE41)) { | |||
utf8_flags |= RSPAMD_FAST_UTF8_FLAG_SSE41; |
@@ -51,11 +51,11 @@ INIT_LOG_MODULE(composites) | |||
namespace rspamd::composites { | |||
static rspamd_expression_atom_t *rspamd_composite_expr_parse(const gchar *line, gsize len, | |||
static rspamd_expression_atom_t *rspamd_composite_expr_parse(const char *line, gsize len, | |||
rspamd_mempool_t *pool, | |||
gpointer ud, GError **err); | |||
static gdouble rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom); | |||
static gint rspamd_composite_expr_priority(rspamd_expression_atom_t *atom); | |||
static double rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom); | |||
static int rspamd_composite_expr_priority(rspamd_expression_atom_t *atom); | |||
static void rspamd_composite_expr_destroy(rspamd_expression_atom_t *atom); | |||
static void composites_foreach_callback(gpointer key, gpointer value, void *data); | |||
@@ -234,12 +234,12 @@ rspamd_composite_atom_dtor(void *ptr) | |||
} | |||
static rspamd_expression_atom_t * | |||
rspamd_composite_expr_parse(const gchar *line, gsize len, | |||
rspamd_composite_expr_parse(const char *line, gsize len, | |||
rspamd_mempool_t *pool, | |||
gpointer ud, GError **err) | |||
{ | |||
gsize clen = 0; | |||
const gchar *p, *end; | |||
const char *p, *end; | |||
enum composite_expr_state { | |||
comp_state_read_symbol = 0, | |||
comp_state_read_obrace, | |||
@@ -350,7 +350,7 @@ rspamd_composite_expr_parse(const gchar *line, gsize len, | |||
res->str = line; | |||
/* Full state machine to fill a composite atom */ | |||
const gchar *opt_start = nullptr; | |||
const char *opt_start = nullptr; | |||
while (p < end) { | |||
if (state == comp_state_read_end) { | |||
@@ -406,7 +406,7 @@ rspamd_composite_expr_parse(const gchar *line, gsize len, | |||
case comp_state_read_option: | |||
if (*p == ',' || *p == ']') { | |||
/* Plain match, copy option to ensure string_view validity */ | |||
gint opt_len = p - opt_start; | |||
int opt_len = p - opt_start; | |||
auto *opt_buf = rspamd_mempool_alloc_buffer(pool, opt_len + 1); | |||
rspamd_strlcpy(opt_buf, opt_start, opt_len + 1); | |||
opt_buf = g_strstrip(opt_buf); | |||
@@ -573,7 +573,7 @@ process_single_symbol(struct composites_data *cd, | |||
struct rspamd_composite_atom *atom) -> double | |||
{ | |||
struct rspamd_symbol_result *ms = nullptr; | |||
gdouble rc = 0; | |||
double rc = 0; | |||
struct rspamd_task *task = cd->task; | |||
if ((ms = rspamd_task_find_symbol_result(cd->task, sym.data(), cd->metric_res)) == nullptr) { | |||
@@ -674,7 +674,7 @@ rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom) -> doubl | |||
struct rspamd_symbol_result *ms = NULL; | |||
struct rspamd_task *task = cd->task; | |||
gdouble rc = 0; | |||
double rc = 0; | |||
if (cd->checked[cd->composite->id * 2]) { | |||
/* We have already checked this composite, so just return its value */ | |||
@@ -784,7 +784,7 @@ rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom) -> doubl | |||
/* | |||
* We don't have preferences for composites | |||
*/ | |||
static gint | |||
static int | |||
rspamd_composite_expr_priority(rspamd_expression_atom_t *atom) | |||
{ | |||
return 0; | |||
@@ -801,9 +801,9 @@ composites_foreach_callback(gpointer key, gpointer value, void *data) | |||
{ | |||
auto *cd = (struct composites_data *) data; | |||
auto *comp = (struct rspamd_composite *) value; | |||
auto *str_key = (const gchar *) key; | |||
auto *str_key = (const char *) key; | |||
struct rspamd_task *task; | |||
gdouble rc; | |||
double rc; | |||
cd->composite = comp; | |||
task = cd->task; | |||
@@ -869,8 +869,8 @@ remove_symbols(const composites_data &cd, const std::vector<symbol_remove_data> | |||
want_remove_score = TRUE, | |||
want_remove_symbol = TRUE, | |||
want_forced = FALSE; | |||
const gchar *disable_score_reason = "no policy", | |||
*disable_symbol_reason = "no policy"; | |||
const char *disable_score_reason = "no policy", | |||
*disable_symbol_reason = "no policy"; | |||
task = cd.task; | |||
@@ -45,7 +45,7 @@ struct rspamd_composite { | |||
std::string str_expr; | |||
std::string sym; | |||
struct rspamd_expression *expr; | |||
gint id; | |||
int id; | |||
rspamd_composite_policy policy; | |||
}; | |||
@@ -141,10 +141,10 @@ std::string_view unescape_css(rspamd_mempool_t *pool, | |||
}// namespace rspamd::css | |||
/* C API */ | |||
const gchar *rspamd_css_unescape(rspamd_mempool_t *pool, | |||
const guchar *begin, | |||
gsize len, | |||
gsize *outlen) | |||
const char *rspamd_css_unescape(rspamd_mempool_t *pool, | |||
const unsigned char *begin, | |||
gsize len, | |||
gsize *outlen) | |||
{ | |||
auto sv = rspamd::css::unescape_css(pool, {(const char *) begin, len}); | |||
const auto *v = sv.begin(); |
@@ -118,10 +118,10 @@ struct rspamd_dkim_check_result { | |||
enum rspamd_dkim_check_rcode rcode; | |||
rspamd_dkim_context_t *ctx; | |||
/* Processed parts */ | |||
const gchar *selector; | |||
const gchar *domain; | |||
const gchar *short_b; | |||
const gchar *fail_reason; | |||
const char *selector; | |||
const char *domain; | |||
const char *short_b; | |||
const char *fail_reason; | |||
}; | |||
@@ -137,10 +137,10 @@ typedef void (*dkim_key_handler_f)(rspamd_dkim_key_t *key, gsize keylen, | |||
* @param err pointer to error object | |||
* @return new context or NULL | |||
*/ | |||
rspamd_dkim_context_t *rspamd_create_dkim_context(const gchar *sig, | |||
rspamd_dkim_context_t *rspamd_create_dkim_context(const char *sig, | |||
rspamd_mempool_t *pool, | |||
struct rspamd_dns_resolver *resolver, | |||
guint time_jitter, | |||
unsigned int time_jitter, | |||
enum rspamd_dkim_type type, | |||
GError **err); | |||
@@ -153,9 +153,9 @@ rspamd_dkim_context_t *rspamd_create_dkim_context(const gchar *sig, | |||
*/ | |||
rspamd_dkim_sign_context_t *rspamd_create_dkim_sign_context(struct rspamd_task *task, | |||
rspamd_dkim_sign_key_t *priv_key, | |||
gint headers_canon, | |||
gint body_canon, | |||
const gchar *dkim_headers, | |||
int headers_canon, | |||
int body_canon, | |||
const char *dkim_headers, | |||
enum rspamd_dkim_type type, | |||
GError **err); | |||
@@ -165,7 +165,7 @@ rspamd_dkim_sign_context_t *rspamd_create_dkim_sign_context(struct rspamd_task * | |||
* @param err | |||
* @return | |||
*/ | |||
rspamd_dkim_sign_key_t *rspamd_dkim_sign_key_load(const gchar *what, gsize len, | |||
rspamd_dkim_sign_key_t *rspamd_dkim_sign_key_load(const char *what, gsize len, | |||
enum rspamd_dkim_key_format type, | |||
GError **err); | |||
@@ -206,12 +206,12 @@ rspamd_dkim_create_result(rspamd_dkim_context_t *ctx, | |||
struct rspamd_task *task); | |||
GString *rspamd_dkim_sign(struct rspamd_task *task, | |||
const gchar *selector, | |||
const gchar *domain, | |||
const char *selector, | |||
const char *domain, | |||
time_t expire, | |||
gsize len, | |||
guint idx, | |||
const gchar *arc_cv, | |||
unsigned int idx, | |||
const char *arc_cv, | |||
rspamd_dkim_sign_context_t *ctx); | |||
rspamd_dkim_key_t *rspamd_dkim_key_ref(rspamd_dkim_key_t *k); | |||
@@ -222,13 +222,13 @@ rspamd_dkim_sign_key_t *rspamd_dkim_sign_key_ref(rspamd_dkim_sign_key_t *k); | |||
void rspamd_dkim_sign_key_unref(rspamd_dkim_sign_key_t *k); | |||
const gchar *rspamd_dkim_get_domain(rspamd_dkim_context_t *ctx); | |||
const char *rspamd_dkim_get_domain(rspamd_dkim_context_t *ctx); | |||
const gchar *rspamd_dkim_get_selector(rspamd_dkim_context_t *ctx); | |||
const char *rspamd_dkim_get_selector(rspamd_dkim_context_t *ctx); | |||
const gchar *rspamd_dkim_get_dns_key(rspamd_dkim_context_t *ctx); | |||
const char *rspamd_dkim_get_dns_key(rspamd_dkim_context_t *ctx); | |||
guint rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k); | |||
unsigned int rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k); | |||
/** | |||
* Create DKIM public key from a raw data | |||
@@ -238,7 +238,7 @@ guint rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k); | |||
* @param err | |||
* @return | |||
*/ | |||
rspamd_dkim_key_t *rspamd_dkim_make_key(const gchar *keydata, guint keylen, | |||
rspamd_dkim_key_t *rspamd_dkim_make_key(const char *keydata, unsigned int keylen, | |||
enum rspamd_dkim_key_type type, | |||
GError **err); | |||
@@ -249,7 +249,7 @@ rspamd_dkim_key_t *rspamd_dkim_make_key(const gchar *keydata, guint keylen, | |||
* @param key | |||
* @return | |||
*/ | |||
const guchar *rspamd_dkim_key_id(rspamd_dkim_key_t *key); | |||
const unsigned char *rspamd_dkim_key_id(rspamd_dkim_key_t *key); | |||
/** | |||
* Parse DKIM public key from a TXT record | |||
@@ -258,7 +258,7 @@ const guchar *rspamd_dkim_key_id(rspamd_dkim_key_t *key); | |||
* @param err | |||
* @return | |||
*/ | |||
rspamd_dkim_key_t *rspamd_dkim_parse_key(const gchar *txt, gsize *keylen, | |||
rspamd_dkim_key_t *rspamd_dkim_parse_key(const char *txt, gsize *keylen, | |||
GError **err); | |||
/** | |||
@@ -269,9 +269,9 @@ rspamd_dkim_key_t *rspamd_dkim_parse_key(const gchar *txt, gsize *keylen, | |||
* @param outlen | |||
* @return | |||
*/ | |||
goffset rspamd_dkim_canonize_header_relaxed_str(const gchar *hname, | |||
const gchar *hvalue, | |||
gchar *out, | |||
goffset rspamd_dkim_canonize_header_relaxed_str(const char *hname, | |||
const char *hvalue, | |||
char *out, | |||
gsize outlen); | |||
/** |
@@ -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. | |||
@@ -28,7 +28,7 @@ | |||
#include <unicode/uidna.h> | |||
static const gchar *M = "rspamd dns"; | |||
static const char *M = "rspamd dns"; | |||
static struct rdns_upstream_elt *rspamd_dns_select_upstream(const char *name, | |||
size_t len, void *ups_data); | |||
@@ -40,7 +40,7 @@ static struct rdns_upstream_elt *rspamd_dns_select_upstream_retransmit( | |||
static void rspamd_dns_upstream_ok(struct rdns_upstream_elt *elt, | |||
void *ups_data); | |||
static void rspamd_dns_upstream_fail(struct rdns_upstream_elt *elt, | |||
void *ups_data, const gchar *reason); | |||
void *ups_data, const char *reason); | |||
static unsigned int rspamd_dns_upstream_count(void *ups_data); | |||
static struct rdns_upstream_context rspamd_ups_ctx = { | |||
@@ -64,11 +64,11 @@ struct rspamd_dns_request_ud { | |||
struct rspamd_dns_fail_cache_entry { | |||
const char *name; | |||
gint32 namelen; | |||
int32_t namelen; | |||
enum rdns_request_type type; | |||
}; | |||
static const gint8 ascii_dns_table[128] = { | |||
static const int8_t ascii_dns_table[128] = { | |||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
/* HYPHEN-MINUS..FULL STOP */ | |||
@@ -83,7 +83,7 @@ static const gint8 ascii_dns_table[128] = { | |||
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1}; | |||
static guint | |||
static unsigned int | |||
rspamd_dns_fail_hash(gconstpointer ptr) | |||
{ | |||
struct rspamd_dns_fail_cache_entry *elt = | |||
@@ -157,15 +157,15 @@ rspamd_dns_callback(struct rdns_reply *reply, gpointer ud) | |||
reqdata->task->resolver->fails_cache) { | |||
/* Add to cache... */ | |||
const gchar *name = reqdata->req->requested_names[0].name; | |||
gchar *target; | |||
const char *name = reqdata->req->requested_names[0].name; | |||
char *target; | |||
gsize namelen; | |||
struct rspamd_dns_fail_cache_entry *nentry; | |||
/* Allocate in a single entry to allow further free in a single call */ | |||
namelen = strlen(name); | |||
nentry = g_malloc(sizeof(nentry) + namelen + 1); | |||
target = ((gchar *) nentry) + sizeof(nentry); | |||
target = ((char *) nentry) + sizeof(nentry); | |||
rspamd_strlcpy(target, name, namelen + 1); | |||
nentry->type = reqdata->req->requested_names[0].type; | |||
nentry->name = target; | |||
@@ -206,8 +206,8 @@ rspamd_dns_resolver_request(struct rspamd_dns_resolver *resolver, | |||
{ | |||
struct rdns_request *req; | |||
struct rspamd_dns_request_ud *reqdata = NULL; | |||
guint nlen = strlen(name); | |||
gchar *real_name = NULL; | |||
unsigned int nlen = strlen(name); | |||
char *real_name = NULL; | |||
g_assert(resolver != NULL); | |||
@@ -419,7 +419,7 @@ static void rspamd_rnds_log_bridge( | |||
} | |||
static void | |||
rspamd_dns_server_init(struct upstream *up, guint idx, gpointer ud) | |||
rspamd_dns_server_init(struct upstream *up, unsigned int idx, gpointer ud) | |||
{ | |||
struct rspamd_dns_resolver *r = ud; | |||
rspamd_inet_addr_t *addr; | |||
@@ -447,7 +447,7 @@ rspamd_dns_server_init(struct upstream *up, guint idx, gpointer ud) | |||
} | |||
static void | |||
rspamd_dns_server_reorder(struct upstream *up, guint idx, gpointer ud) | |||
rspamd_dns_server_reorder(struct upstream *up, unsigned int idx, gpointer ud) | |||
{ | |||
struct rspamd_dns_resolver *r = ud; | |||
@@ -462,7 +462,7 @@ rspamd_dns_resolv_conf_on_server(struct rdns_resolver *resolver, | |||
struct rspamd_dns_resolver *dns_resolver = ud; | |||
struct rspamd_config *cfg; | |||
rspamd_inet_addr_t *addr; | |||
gint test_fd; | |||
int test_fd; | |||
cfg = dns_resolver->cfg; | |||
@@ -510,7 +510,7 @@ rspamd_process_fake_reply(struct rspamd_config *cfg, | |||
enum rdns_request_type rtype = RDNS_REQUEST_A; | |||
enum dns_rcode rcode = RDNS_RC_NOERROR; | |||
struct rdns_reply_entry *replies = NULL; | |||
const gchar *name = NULL; | |||
const char *name = NULL; | |||
if (ucl_object_type(cur) != UCL_OBJECT) { | |||
continue; | |||
@@ -560,9 +560,9 @@ rspamd_process_fake_reply(struct rspamd_config *cfg, | |||
rep_it = ucl_object_iterate_new(replies_obj); | |||
while ((rep_obj = ucl_object_iterate_safe(rep_it, true))) { | |||
const gchar *str_rep = ucl_object_tostring(rep_obj); | |||
const char *str_rep = ucl_object_tostring(rep_obj); | |||
struct rdns_reply_entry *rep; | |||
gchar **svec; | |||
char **svec; | |||
if (str_rep == NULL) { | |||
msg_err_config("invalid reply element for fake DNS record %s", | |||
@@ -666,7 +666,7 @@ rspamd_process_fake_reply(struct rspamd_config *cfg, | |||
if (replies) { | |||
struct rdns_reply_entry *tmp_entry; | |||
guint i = 0; | |||
unsigned int i = 0; | |||
DL_COUNT(replies, tmp_entry, i); | |||
msg_info_config("added fake record: %s(%s); %d replies", name, | |||
@@ -700,13 +700,13 @@ rspamd_process_fake_reply(struct rspamd_config *cfg, | |||
static bool | |||
rspamd_dns_read_hosts_file(struct rspamd_config *cfg, | |||
struct rspamd_dns_resolver *dns_resolver, | |||
const gchar *fname) | |||
const char *fname) | |||
{ | |||
gchar *linebuf = NULL; | |||
char *linebuf = NULL; | |||
gsize buflen = 0; | |||
gssize r; | |||
FILE *fp; | |||
guint nadded = 0; | |||
unsigned int nadded = 0; | |||
fp = fopen(fname, "r"); | |||
@@ -732,7 +732,7 @@ rspamd_dns_read_hosts_file(struct rspamd_config *cfg, | |||
g_strchomp(linebuf); | |||
gchar **elts = g_strsplit_set(linebuf, " \t\v", -1); | |||
char **elts = g_strsplit_set(linebuf, " \t\v", -1); | |||
rspamd_inet_addr_t *addr; | |||
if (!rspamd_parse_inet_address(&addr, elts[0], strlen(elts[0]), | |||
@@ -741,7 +741,7 @@ rspamd_dns_read_hosts_file(struct rspamd_config *cfg, | |||
} | |||
else { | |||
/* Add all FQDN + aliases if any */ | |||
gchar **cur_name = &elts[1]; | |||
char **cur_name = &elts[1]; | |||
while (*cur_name) { | |||
if (strlen(*cur_name) == 0) { | |||
@@ -1054,7 +1054,7 @@ rspamd_dns_upstream_ok(struct rdns_upstream_elt *elt, | |||
static void | |||
rspamd_dns_upstream_fail(struct rdns_upstream_elt *elt, | |||
void *ups_data, const gchar *reason) | |||
void *ups_data, const char *reason) | |||
{ | |||
struct upstream *up = elt->lib_data; | |||
@@ -1069,18 +1069,18 @@ rspamd_dns_upstream_count(void *ups_data) | |||
return rspamd_upstreams_alive(ups); | |||
} | |||
gchar * | |||
char * | |||
rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver, | |||
rspamd_mempool_t *pool, | |||
const char *name, | |||
gint namelen, | |||
guint *outlen) | |||
int namelen, | |||
unsigned int *outlen) | |||
{ | |||
if (resolver == NULL || resolver->uidna == NULL || name == NULL || namelen > DNS_D_MAXNAME) { | |||
return NULL; | |||
} | |||
guint dest_len; | |||
unsigned int dest_len; | |||
UErrorCode uc_err = U_ZERO_ERROR; | |||
UIDNAInfo info = UIDNA_INFO_INITIALIZER; | |||
/* Calculate length required */ | |||
@@ -1088,7 +1088,7 @@ rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver, | |||
NULL, 0, &info, &uc_err); | |||
if (uc_err == U_BUFFER_OVERFLOW_ERROR) { | |||
gchar *dest; | |||
char *dest; | |||
if (pool) { | |||
dest = rspamd_mempool_alloc(pool, dest_len + 1); |
@@ -41,8 +41,8 @@ struct rspamd_dns_resolver { | |||
double fails_cache_time; | |||
struct upstream_list *ups; | |||
struct rspamd_config *cfg; | |||
gdouble request_timeout; | |||
guint max_retransmits; | |||
double request_timeout; | |||
unsigned int max_retransmits; | |||
}; | |||
/* Rspamd DNS API */ | |||
@@ -97,11 +97,11 @@ gboolean rspamd_dns_resolver_request_task_forced(struct rspamd_task *task, | |||
* @param namelen length of input (-1 for zero terminated) | |||
* @return encoded string | |||
*/ | |||
gchar *rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver, | |||
rspamd_mempool_t *pool, | |||
const char *name, | |||
gint namelen, | |||
guint *outlen); | |||
char *rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver, | |||
rspamd_mempool_t *pool, | |||
const char *name, | |||
int namelen, | |||
unsigned int *outlen); | |||
#ifdef __cplusplus | |||
} |
@@ -39,9 +39,9 @@ apply_dynamic_conf(const ucl_object_t *top, struct rspamd_config *cfg) | |||
enum rspamd_action_type test_act; | |||
const ucl_object_t *cur_elt, *cur_nm, *it_val; | |||
ucl_object_iter_t it = NULL; | |||
const gchar *name; | |||
gdouble nscore; | |||
static const guint priority = 3; | |||
const char *name; | |||
double nscore; | |||
static const unsigned int priority = 3; | |||
while ((cur_elt = ucl_object_iterate(top, &it, true))) { | |||
if (ucl_object_type(cur_elt) != UCL_OBJECT) { | |||
@@ -143,9 +143,9 @@ apply_dynamic_conf(const ucl_object_t *top, struct rspamd_config *cfg) | |||
} | |||
/* Callbacks for reading json dynamic rules */ | |||
static gchar * | |||
json_config_read_cb(gchar *chunk, | |||
gint len, | |||
static char * | |||
json_config_read_cb(char *chunk, | |||
int len, | |||
struct map_cb_data *data, | |||
gboolean final) | |||
{ | |||
@@ -296,8 +296,8 @@ gboolean | |||
dump_dynamic_config(struct rspamd_config *cfg) | |||
{ | |||
struct stat st; | |||
gchar *dir, pathbuf[PATH_MAX]; | |||
gint fd; | |||
char *dir, pathbuf[PATH_MAX]; | |||
int fd; | |||
if (cfg->dynamic_conf == NULL || cfg->current_dynamic_conf == NULL) { | |||
/* No dynamic conf has been specified, so do not try to dump it */ | |||
@@ -377,7 +377,7 @@ dump_dynamic_config(struct rspamd_config *cfg) | |||
} | |||
static ucl_object_t * | |||
new_dynamic_metric(const gchar *metric_name, ucl_object_t *top) | |||
new_dynamic_metric(const char *metric_name, ucl_object_t *top) | |||
{ | |||
ucl_object_t *metric; | |||
@@ -396,7 +396,7 @@ new_dynamic_metric(const gchar *metric_name, ucl_object_t *top) | |||
} | |||
static ucl_object_t * | |||
dynamic_metric_find_elt(const ucl_object_t *arr, const gchar *name) | |||
dynamic_metric_find_elt(const ucl_object_t *arr, const char *name) | |||
{ | |||
ucl_object_iter_t it = NULL; | |||
const ucl_object_t *cur, *n; | |||
@@ -421,7 +421,7 @@ dynamic_metric_find_elt(const ucl_object_t *arr, const gchar *name) | |||
} | |||
static ucl_object_t * | |||
dynamic_metric_find_metric(const ucl_object_t *arr, const gchar *metric) | |||
dynamic_metric_find_metric(const ucl_object_t *arr, const char *metric) | |||
{ | |||
ucl_object_iter_t it = NULL; | |||
const ucl_object_t *cur, *n; | |||
@@ -446,7 +446,7 @@ dynamic_metric_find_metric(const ucl_object_t *arr, const gchar *metric) | |||
} | |||
static ucl_object_t * | |||
new_dynamic_elt(ucl_object_t *arr, const gchar *name, gdouble value) | |||
new_dynamic_elt(ucl_object_t *arr, const char *name, double value) | |||
{ | |||
ucl_object_t *n; | |||
@@ -461,13 +461,13 @@ new_dynamic_elt(ucl_object_t *arr, const gchar *name, gdouble value) | |||
return n; | |||
} | |||
static gint | |||
static int | |||
rspamd_maybe_add_lua_dynsym(struct rspamd_config *cfg, | |||
const gchar *sym, | |||
gdouble score) | |||
const char *sym, | |||
double score) | |||
{ | |||
lua_State *L = cfg->lua_state; | |||
gint ret = -1; | |||
int ret = -1; | |||
struct rspamd_config **pcfg; | |||
lua_getglobal(L, "rspamd_plugins"); | |||
@@ -509,13 +509,13 @@ rspamd_maybe_add_lua_dynsym(struct rspamd_config *cfg, | |||
return ret; | |||
} | |||
static gint | |||
static int | |||
rspamd_maybe_add_lua_dynact(struct rspamd_config *cfg, | |||
const gchar *action, | |||
gdouble score) | |||
const char *action, | |||
double score) | |||
{ | |||
lua_State *L = cfg->lua_state; | |||
gint ret = -1; | |||
int ret = -1; | |||
struct rspamd_config **pcfg; | |||
lua_getglobal(L, "rspamd_plugins"); | |||
@@ -567,12 +567,12 @@ rspamd_maybe_add_lua_dynact(struct rspamd_config *cfg, | |||
*/ | |||
gboolean | |||
add_dynamic_symbol(struct rspamd_config *cfg, | |||
const gchar *metric_name, | |||
const gchar *symbol, | |||
gdouble value) | |||
const char *metric_name, | |||
const char *symbol, | |||
double value) | |||
{ | |||
ucl_object_t *metric, *syms; | |||
gint ret; | |||
int ret; | |||
if ((ret = rspamd_maybe_add_lua_dynsym(cfg, symbol, value)) != -1) { | |||
return ret == 0 ? FALSE : TRUE; | |||
@@ -609,8 +609,8 @@ add_dynamic_symbol(struct rspamd_config *cfg, | |||
gboolean | |||
remove_dynamic_symbol(struct rspamd_config *cfg, | |||
const gchar *metric_name, | |||
const gchar *symbol) | |||
const char *metric_name, | |||
const char *symbol) | |||
{ | |||
ucl_object_t *metric, *syms; | |||
gboolean ret = FALSE; | |||
@@ -659,13 +659,13 @@ remove_dynamic_symbol(struct rspamd_config *cfg, | |||
*/ | |||
gboolean | |||
add_dynamic_action(struct rspamd_config *cfg, | |||
const gchar *metric_name, | |||
guint action, | |||
gdouble value) | |||
const char *metric_name, | |||
unsigned int action, | |||
double value) | |||
{ | |||
ucl_object_t *metric, *acts; | |||
const gchar *action_name = rspamd_action_to_str(action); | |||
gint ret; | |||
const char *action_name = rspamd_action_to_str(action); | |||
int ret; | |||
if ((ret = rspamd_maybe_add_lua_dynact(cfg, action_name, value)) != -1) { | |||
return ret == 0 ? FALSE : TRUE; | |||
@@ -702,11 +702,11 @@ add_dynamic_action(struct rspamd_config *cfg, | |||
gboolean | |||
remove_dynamic_action(struct rspamd_config *cfg, | |||
const gchar *metric_name, | |||
guint action) | |||
const char *metric_name, | |||
unsigned int action) | |||
{ | |||
ucl_object_t *metric, *acts; | |||
const gchar *action_name = rspamd_action_to_str(action); | |||
const char *action_name = rspamd_action_to_str(action); | |||
gboolean ret = FALSE; | |||
if (cfg->dynamic_conf == NULL) { |
@@ -46,13 +46,13 @@ gboolean dump_dynamic_config(struct rspamd_config *cfg); | |||
* @return | |||
*/ | |||
gboolean add_dynamic_symbol(struct rspamd_config *cfg, | |||
const gchar *metric, | |||
const gchar *symbol, | |||
gdouble value); | |||
const char *metric, | |||
const char *symbol, | |||
double value); | |||
gboolean remove_dynamic_symbol(struct rspamd_config *cfg, | |||
const gchar *metric, | |||
const gchar *symbol); | |||
const char *metric, | |||
const char *symbol); | |||
/** | |||
* Add action for specified metric | |||
@@ -63,16 +63,16 @@ gboolean remove_dynamic_symbol(struct rspamd_config *cfg, | |||
* @return | |||
*/ | |||
gboolean add_dynamic_action(struct rspamd_config *cfg, | |||
const gchar *metric, | |||
guint action, | |||
gdouble value); | |||
const char *metric, | |||
unsigned int action, | |||
double value); | |||
/** | |||
* Removes dynamic action | |||
*/ | |||
gboolean remove_dynamic_action(struct rspamd_config *cfg, | |||
const gchar *metric, | |||
guint action); | |||
const char *metric, | |||
unsigned int action); | |||
#ifdef __cplusplus | |||
} |
@@ -35,18 +35,18 @@ static void rspamd_fuzzy_backend_check_sqlite(struct rspamd_fuzzy_backend *bk, | |||
rspamd_fuzzy_check_cb cb, void *ud, | |||
void *subr_ud); | |||
static void rspamd_fuzzy_backend_update_sqlite(struct rspamd_fuzzy_backend *bk, | |||
GArray *updates, const gchar *src, | |||
GArray *updates, const char *src, | |||
rspamd_fuzzy_update_cb cb, void *ud, | |||
void *subr_ud); | |||
static void rspamd_fuzzy_backend_count_sqlite(struct rspamd_fuzzy_backend *bk, | |||
rspamd_fuzzy_count_cb cb, void *ud, | |||
void *subr_ud); | |||
static void rspamd_fuzzy_backend_version_sqlite(struct rspamd_fuzzy_backend *bk, | |||
const gchar *src, | |||
const char *src, | |||
rspamd_fuzzy_version_cb cb, void *ud, | |||
void *subr_ud); | |||
static const gchar *rspamd_fuzzy_backend_id_sqlite(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud); | |||
static const char *rspamd_fuzzy_backend_id_sqlite(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud); | |||
static void rspamd_fuzzy_backend_expire_sqlite(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud); | |||
static void rspamd_fuzzy_backend_close_sqlite(struct rspamd_fuzzy_backend *bk, | |||
@@ -61,17 +61,17 @@ struct rspamd_fuzzy_backend_subr { | |||
rspamd_fuzzy_check_cb cb, void *ud, | |||
void *subr_ud); | |||
void (*update)(struct rspamd_fuzzy_backend *bk, | |||
GArray *updates, const gchar *src, | |||
GArray *updates, const char *src, | |||
rspamd_fuzzy_update_cb cb, void *ud, | |||
void *subr_ud); | |||
void (*count)(struct rspamd_fuzzy_backend *bk, | |||
rspamd_fuzzy_count_cb cb, void *ud, | |||
void *subr_ud); | |||
void (*version)(struct rspamd_fuzzy_backend *bk, | |||
const gchar *src, | |||
const char *src, | |||
rspamd_fuzzy_version_cb cb, void *ud, | |||
void *subr_ud); | |||
const gchar *(*id)(struct rspamd_fuzzy_backend *bk, void *subr_ud); | |||
const char *(*id)(struct rspamd_fuzzy_backend *bk, void *subr_ud); | |||
void (*periodic)(struct rspamd_fuzzy_backend *bk, void *subr_ud); | |||
void (*close)(struct rspamd_fuzzy_backend *bk, void *subr_ud); | |||
}; | |||
@@ -100,8 +100,8 @@ static const struct rspamd_fuzzy_backend_subr fuzzy_subrs[] = { | |||
struct rspamd_fuzzy_backend { | |||
enum rspamd_fuzzy_backend_type type; | |||
gdouble expire; | |||
gdouble sync; | |||
double expire; | |||
double sync; | |||
struct ev_loop *event_loop; | |||
rspamd_fuzzy_periodic_cb periodic_cb; | |||
void *periodic_ud; | |||
@@ -153,17 +153,17 @@ rspamd_fuzzy_backend_check_sqlite(struct rspamd_fuzzy_backend *bk, | |||
static void | |||
rspamd_fuzzy_backend_update_sqlite(struct rspamd_fuzzy_backend *bk, | |||
GArray *updates, const gchar *src, | |||
GArray *updates, const char *src, | |||
rspamd_fuzzy_update_cb cb, void *ud, | |||
void *subr_ud) | |||
{ | |||
struct rspamd_fuzzy_backend_sqlite *sq = subr_ud; | |||
gboolean success = FALSE; | |||
guint i; | |||
unsigned int i; | |||
struct fuzzy_peer_cmd *io_cmd; | |||
struct rspamd_fuzzy_cmd *cmd; | |||
gpointer ptr; | |||
guint nupdates = 0, nadded = 0, ndeleted = 0, nextended = 0, nignored = 0; | |||
unsigned int nupdates = 0, nadded = 0, ndeleted = 0, nextended = 0, nignored = 0; | |||
if (rspamd_fuzzy_backend_sqlite_prepare_update(sq, src)) { | |||
for (i = 0; i < updates->len; i++) { | |||
@@ -215,7 +215,7 @@ rspamd_fuzzy_backend_count_sqlite(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud) | |||
{ | |||
struct rspamd_fuzzy_backend_sqlite *sq = subr_ud; | |||
guint64 nhashes; | |||
uint64_t nhashes; | |||
nhashes = rspamd_fuzzy_backend_sqlite_count(sq); | |||
@@ -226,12 +226,12 @@ rspamd_fuzzy_backend_count_sqlite(struct rspamd_fuzzy_backend *bk, | |||
static void | |||
rspamd_fuzzy_backend_version_sqlite(struct rspamd_fuzzy_backend *bk, | |||
const gchar *src, | |||
const char *src, | |||
rspamd_fuzzy_version_cb cb, void *ud, | |||
void *subr_ud) | |||
{ | |||
struct rspamd_fuzzy_backend_sqlite *sq = subr_ud; | |||
guint64 rev; | |||
uint64_t rev; | |||
rev = rspamd_fuzzy_backend_sqlite_version(sq, src); | |||
@@ -240,7 +240,7 @@ rspamd_fuzzy_backend_version_sqlite(struct rspamd_fuzzy_backend *bk, | |||
} | |||
} | |||
static const gchar * | |||
static const char * | |||
rspamd_fuzzy_backend_id_sqlite(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud) | |||
{ | |||
@@ -276,7 +276,7 @@ rspamd_fuzzy_backend_create(struct ev_loop *ev_base, | |||
struct rspamd_fuzzy_backend *bk; | |||
enum rspamd_fuzzy_backend_type type = RSPAMD_FUZZY_BACKEND_SQLITE; | |||
const ucl_object_t *elt; | |||
gdouble expire = DEFAULT_EXPIRE; | |||
double expire = DEFAULT_EXPIRE; | |||
if (config != NULL) { | |||
elt = ucl_object_lookup(config, "backend"); | |||
@@ -328,10 +328,10 @@ void rspamd_fuzzy_backend_check(struct rspamd_fuzzy_backend *bk, | |||
bk->subr->check(bk, cmd, cb, ud, bk->subr_ud); | |||
} | |||
static guint | |||
static unsigned int | |||
rspamd_fuzzy_digest_hash(gconstpointer key) | |||
{ | |||
guint ret; | |||
unsigned int ret; | |||
/* Distributed uniformly already */ | |||
memcpy(&ret, key, sizeof(ret)); | |||
@@ -352,8 +352,8 @@ rspamd_fuzzy_backend_deduplicate_queue(GArray *updates) | |||
rspamd_fuzzy_digest_equal); | |||
struct fuzzy_peer_cmd *io_cmd, *found; | |||
struct rspamd_fuzzy_cmd *cmd; | |||
guchar *digest; | |||
guint i; | |||
unsigned char *digest; | |||
unsigned int i; | |||
for (i = 0; i < updates->len; i++) { | |||
io_cmd = &g_array_index(updates, struct fuzzy_peer_cmd, i); | |||
@@ -428,7 +428,7 @@ rspamd_fuzzy_backend_deduplicate_queue(GArray *updates) | |||
} | |||
void rspamd_fuzzy_backend_process_updates(struct rspamd_fuzzy_backend *bk, | |||
GArray *updates, const gchar *src, rspamd_fuzzy_update_cb cb, | |||
GArray *updates, const char *src, rspamd_fuzzy_update_cb cb, | |||
void *ud) | |||
{ | |||
g_assert(bk != NULL); | |||
@@ -454,7 +454,7 @@ void rspamd_fuzzy_backend_count(struct rspamd_fuzzy_backend *bk, | |||
void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk, | |||
const gchar *src, | |||
const char *src, | |||
rspamd_fuzzy_version_cb cb, void *ud) | |||
{ | |||
g_assert(bk != NULL); | |||
@@ -462,7 +462,7 @@ void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk, | |||
bk->subr->version(bk, src, cb, ud, bk->subr_ud); | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_fuzzy_backend_id(struct rspamd_fuzzy_backend *bk) | |||
{ | |||
g_assert(bk != NULL); | |||
@@ -495,7 +495,7 @@ static void | |||
rspamd_fuzzy_backend_periodic_cb(EV_P_ ev_timer *w, int revents) | |||
{ | |||
struct rspamd_fuzzy_backend *bk = (struct rspamd_fuzzy_backend *) w->data; | |||
gdouble jittered; | |||
double jittered; | |||
jittered = rspamd_time_jitter(bk->sync, bk->sync / 2.0); | |||
w->repeat = jittered; | |||
@@ -504,11 +504,11 @@ rspamd_fuzzy_backend_periodic_cb(EV_P_ ev_timer *w, int revents) | |||
} | |||
void rspamd_fuzzy_backend_start_update(struct rspamd_fuzzy_backend *bk, | |||
gdouble timeout, | |||
double timeout, | |||
rspamd_fuzzy_periodic_cb cb, | |||
void *ud) | |||
{ | |||
gdouble jittered; | |||
double jittered; | |||
g_assert(bk != NULL); | |||
@@ -553,7 +553,7 @@ rspamd_fuzzy_backend_event_base(struct rspamd_fuzzy_backend *backend) | |||
return backend->event_loop; | |||
} | |||
gdouble | |||
double | |||
rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend) | |||
{ | |||
return backend->expire; |
@@ -33,15 +33,15 @@ struct rspamd_config; | |||
typedef void (*rspamd_fuzzy_check_cb)(struct rspamd_fuzzy_reply *rep, void *ud); | |||
typedef void (*rspamd_fuzzy_update_cb)(gboolean success, | |||
guint nadded, | |||
guint ndeleted, | |||
guint nextended, | |||
guint nignored, | |||
unsigned int nadded, | |||
unsigned int ndeleted, | |||
unsigned int nextended, | |||
unsigned int nignored, | |||
void *ud); | |||
typedef void (*rspamd_fuzzy_version_cb)(guint64 rev, void *ud); | |||
typedef void (*rspamd_fuzzy_version_cb)(uint64_t rev, void *ud); | |||
typedef void (*rspamd_fuzzy_count_cb)(guint64 count, void *ud); | |||
typedef void (*rspamd_fuzzy_count_cb)(uint64_t count, void *ud); | |||
typedef gboolean (*rspamd_fuzzy_periodic_cb)(void *ud); | |||
@@ -75,7 +75,7 @@ void rspamd_fuzzy_backend_check(struct rspamd_fuzzy_backend *bk, | |||
* @param src | |||
*/ | |||
void rspamd_fuzzy_backend_process_updates(struct rspamd_fuzzy_backend *bk, | |||
GArray *updates, const gchar *src, rspamd_fuzzy_update_cb cb, | |||
GArray *updates, const char *src, rspamd_fuzzy_update_cb cb, | |||
void *ud); | |||
/** | |||
@@ -95,7 +95,7 @@ void rspamd_fuzzy_backend_count(struct rspamd_fuzzy_backend *bk, | |||
* @param ud | |||
*/ | |||
void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk, | |||
const gchar *src, | |||
const char *src, | |||
rspamd_fuzzy_version_cb cb, void *ud); | |||
/** | |||
@@ -103,20 +103,20 @@ void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk, | |||
* @param backend | |||
* @return | |||
*/ | |||
const gchar *rspamd_fuzzy_backend_id(struct rspamd_fuzzy_backend *backend); | |||
const char *rspamd_fuzzy_backend_id(struct rspamd_fuzzy_backend *backend); | |||
/** | |||
* Starts expire process for the backend | |||
* @param backend | |||
*/ | |||
void rspamd_fuzzy_backend_start_update(struct rspamd_fuzzy_backend *backend, | |||
gdouble timeout, | |||
double timeout, | |||
rspamd_fuzzy_periodic_cb cb, | |||
void *ud); | |||
struct ev_loop *rspamd_fuzzy_backend_event_base(struct rspamd_fuzzy_backend *backend); | |||
gdouble rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend); | |||
double rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend); | |||
/** | |||
* Closes backend |
@@ -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. | |||
@@ -51,14 +51,14 @@ INIT_LOG_MODULE(fuzzy_redis) | |||
struct rspamd_fuzzy_backend_redis { | |||
lua_State *L; | |||
const gchar *redis_object; | |||
const gchar *username; | |||
const gchar *password; | |||
const gchar *dbname; | |||
gchar *id; | |||
const char *redis_object; | |||
const char *username; | |||
const char *password; | |||
const char *dbname; | |||
char *id; | |||
struct rspamd_redis_pool *pool; | |||
gdouble timeout; | |||
gint conf_ref; | |||
double timeout; | |||
int conf_ref; | |||
bool terminated; | |||
ref_entry_t ref; | |||
}; | |||
@@ -80,12 +80,12 @@ struct rspamd_fuzzy_redis_session { | |||
gboolean shingles_checked; | |||
enum rspamd_fuzzy_redis_command command; | |||
guint nargs; | |||
unsigned int nargs; | |||
guint nadded; | |||
guint ndeleted; | |||
guint nextended; | |||
guint nignored; | |||
unsigned int nadded; | |||
unsigned int ndeleted; | |||
unsigned int nextended; | |||
unsigned int nignored; | |||
union { | |||
rspamd_fuzzy_check_cb cb_check; | |||
@@ -95,15 +95,15 @@ struct rspamd_fuzzy_redis_session { | |||
} callback; | |||
void *cbdata; | |||
gchar **argv; | |||
char **argv; | |||
gsize *argv_lens; | |||
struct upstream *up; | |||
guchar found_digest[rspamd_cryptobox_HASHBYTES]; | |||
unsigned char found_digest[rspamd_cryptobox_HASHBYTES]; | |||
}; | |||
static inline struct upstream_list * | |||
rspamd_redis_get_servers(struct rspamd_fuzzy_backend_redis *ctx, | |||
const gchar *what) | |||
const char *what) | |||
{ | |||
lua_State *L = ctx->L; | |||
struct upstream_list *res = NULL; | |||
@@ -117,7 +117,7 @@ rspamd_redis_get_servers(struct rspamd_fuzzy_backend_redis *ctx, | |||
} | |||
else { | |||
struct lua_logger_trace tr; | |||
gchar outbuf[8192]; | |||
char outbuf[8192]; | |||
memset(&tr, 0, sizeof(tr)); | |||
lua_logger_out_type(L, -2, outbuf, sizeof(outbuf) - 1, &tr, | |||
@@ -135,7 +135,7 @@ rspamd_redis_get_servers(struct rspamd_fuzzy_backend_redis *ctx, | |||
static inline void | |||
rspamd_fuzzy_redis_session_free_args(struct rspamd_fuzzy_redis_session *session) | |||
{ | |||
guint i; | |||
unsigned int i; | |||
if (session->argv) { | |||
for (i = 0; i < session->nargs; i++) { | |||
@@ -190,10 +190,10 @@ rspamd_fuzzy_backend_init_redis(struct rspamd_fuzzy_backend *bk, | |||
struct rspamd_fuzzy_backend_redis *backend; | |||
const ucl_object_t *elt; | |||
gboolean ret = FALSE; | |||
guchar id_hash[rspamd_cryptobox_HASHBYTES]; | |||
unsigned char id_hash[rspamd_cryptobox_HASHBYTES]; | |||
rspamd_cryptobox_hash_state_t st; | |||
lua_State *L = (lua_State *) cfg->lua_state; | |||
gint conf_ref = -1; | |||
int conf_ref = -1; | |||
backend = g_malloc0(sizeof(*backend)); | |||
@@ -328,11 +328,11 @@ static void rspamd_fuzzy_redis_check_callback(redisAsyncContext *c, gpointer r, | |||
gpointer priv); | |||
struct _rspamd_fuzzy_shingles_helper { | |||
guchar digest[64]; | |||
guint found; | |||
unsigned char digest[64]; | |||
unsigned int found; | |||
}; | |||
static gint | |||
static int | |||
rspamd_fuzzy_backend_redis_shingles_cmp(const void *a, const void *b) | |||
{ | |||
const struct _rspamd_fuzzy_shingles_helper *sha = a, | |||
@@ -350,7 +350,7 @@ rspamd_fuzzy_redis_shingles_callback(redisAsyncContext *c, gpointer r, | |||
struct rspamd_fuzzy_reply rep; | |||
GString *key; | |||
struct _rspamd_fuzzy_shingles_helper *shingles, *prev = NULL, *sel = NULL; | |||
guint i, found = 0, max_found = 0, cur_found = 0; | |||
unsigned int i, found = 0, max_found = 0, cur_found = 0; | |||
ev_timer_stop(session->event_loop, &session->timeout); | |||
memset(&rep, 0, sizeof(rep)); | |||
@@ -413,7 +413,7 @@ rspamd_fuzzy_redis_shingles_callback(redisAsyncContext *c, gpointer r, | |||
/* Prepare new check command */ | |||
rspamd_fuzzy_redis_session_free_args(session); | |||
session->nargs = 5; | |||
session->argv = g_malloc(sizeof(gchar *) * session->nargs); | |||
session->argv = g_malloc(sizeof(char *) * session->nargs); | |||
session->argv_lens = g_malloc(sizeof(gsize) * session->nargs); | |||
key = g_string_new(session->backend->redis_object); | |||
@@ -436,7 +436,7 @@ rspamd_fuzzy_redis_shingles_callback(redisAsyncContext *c, gpointer r, | |||
if (redisAsyncCommandArgv(session->ctx, | |||
rspamd_fuzzy_redis_check_callback, | |||
session, session->nargs, | |||
(const gchar **) session->argv, | |||
(const char **) session->argv, | |||
session->argv_lens) != REDIS_OK) { | |||
if (session->callback.cb_check) { | |||
@@ -489,12 +489,12 @@ rspamd_fuzzy_backend_check_shingles(struct rspamd_fuzzy_redis_session *session) | |||
struct rspamd_fuzzy_reply rep; | |||
const struct rspamd_fuzzy_shingle_cmd *shcmd; | |||
GString *key; | |||
guint i, init_len; | |||
unsigned int i, init_len; | |||
rspamd_fuzzy_redis_session_free_args(session); | |||
/* First of all check digest */ | |||
session->nargs = RSPAMD_SHINGLE_SIZE + 1; | |||
session->argv = g_malloc(sizeof(gchar *) * session->nargs); | |||
session->argv = g_malloc(sizeof(char *) * session->nargs); | |||
session->argv_lens = g_malloc(sizeof(gsize) * session->nargs); | |||
shcmd = (const struct rspamd_fuzzy_shingle_cmd *) session->cmd; | |||
@@ -518,7 +518,7 @@ rspamd_fuzzy_backend_check_shingles(struct rspamd_fuzzy_redis_session *session) | |||
if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_shingles_callback, | |||
session, session->nargs, | |||
(const gchar **) session->argv, session->argv_lens) != REDIS_OK) { | |||
(const char **) session->argv, session->argv_lens) != REDIS_OK) { | |||
msg_err("cannot execute redis command on %s: %s", | |||
rspamd_inet_address_to_string_pretty(rspamd_upstream_addr_cur(session->up)), | |||
session->ctx->errstr); | |||
@@ -549,7 +549,7 @@ rspamd_fuzzy_redis_check_callback(redisAsyncContext *c, gpointer r, | |||
redisReply *reply = r, *cur; | |||
struct rspamd_fuzzy_reply rep; | |||
gulong value; | |||
guint found_elts = 0; | |||
unsigned int found_elts = 0; | |||
ev_timer_stop(session->event_loop, &session->timeout); | |||
memset(&rep, 0, sizeof(rep)); | |||
@@ -669,7 +669,7 @@ void rspamd_fuzzy_backend_check_redis(struct rspamd_fuzzy_backend *bk, | |||
/* First of all check digest */ | |||
session->nargs = 5; | |||
session->argv = g_malloc(sizeof(gchar *) * session->nargs); | |||
session->argv = g_malloc(sizeof(char *) * session->nargs); | |||
session->argv_lens = g_malloc(sizeof(gsize) * session->nargs); | |||
key = g_string_new(backend->redis_object); | |||
@@ -712,7 +712,7 @@ void rspamd_fuzzy_backend_check_redis(struct rspamd_fuzzy_backend *bk, | |||
else { | |||
if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_check_callback, | |||
session, session->nargs, | |||
(const gchar **) session->argv, session->argv_lens) != REDIS_OK) { | |||
(const char **) session->argv, session->argv_lens) != REDIS_OK) { | |||
rspamd_fuzzy_redis_session_dtor(session, TRUE); | |||
if (cb) { | |||
@@ -815,7 +815,7 @@ void rspamd_fuzzy_backend_count_redis(struct rspamd_fuzzy_backend *bk, | |||
session->event_loop = rspamd_fuzzy_backend_event_base(bk); | |||
session->nargs = 2; | |||
session->argv = g_malloc(sizeof(gchar *) * 2); | |||
session->argv = g_malloc(sizeof(char *) * 2); | |||
session->argv_lens = g_malloc(sizeof(gsize) * 2); | |||
key = g_string_new(backend->redis_object); | |||
g_string_append(key, "_count"); | |||
@@ -850,7 +850,7 @@ void rspamd_fuzzy_backend_count_redis(struct rspamd_fuzzy_backend *bk, | |||
else { | |||
if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_count_callback, | |||
session, session->nargs, | |||
(const gchar **) session->argv, session->argv_lens) != REDIS_OK) { | |||
(const char **) session->argv, session->argv_lens) != REDIS_OK) { | |||
rspamd_fuzzy_redis_session_dtor(session, TRUE); | |||
if (cb) { | |||
@@ -921,7 +921,7 @@ rspamd_fuzzy_redis_version_callback(redisAsyncContext *c, gpointer r, | |||
} | |||
void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk, | |||
const gchar *src, | |||
const char *src, | |||
rspamd_fuzzy_version_cb cb, void *ud, | |||
void *subr_ud) | |||
{ | |||
@@ -953,7 +953,7 @@ void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk, | |||
session->event_loop = rspamd_fuzzy_backend_event_base(bk); | |||
session->nargs = 2; | |||
session->argv = g_malloc(sizeof(gchar *) * 2); | |||
session->argv = g_malloc(sizeof(char *) * 2); | |||
session->argv_lens = g_malloc(sizeof(gsize) * 2); | |||
key = g_string_new(backend->redis_object); | |||
g_string_append(key, src); | |||
@@ -988,7 +988,7 @@ void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk, | |||
else { | |||
if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_version_callback, | |||
session, session->nargs, | |||
(const gchar **) session->argv, session->argv_lens) != REDIS_OK) { | |||
(const char **) session->argv, session->argv_lens) != REDIS_OK) { | |||
rspamd_fuzzy_redis_session_dtor(session, TRUE); | |||
if (cb) { | |||
@@ -1007,7 +1007,7 @@ void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk, | |||
} | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_fuzzy_backend_id_redis(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud) | |||
{ | |||
@@ -1028,11 +1028,11 @@ void rspamd_fuzzy_backend_expire_redis(struct rspamd_fuzzy_backend *bk, | |||
static gboolean | |||
rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
struct rspamd_fuzzy_redis_session *session, | |||
struct fuzzy_peer_cmd *io_cmd, guint *shift) | |||
struct fuzzy_peer_cmd *io_cmd, unsigned int *shift) | |||
{ | |||
GString *key, *value; | |||
guint cur_shift = *shift; | |||
guint i, klen; | |||
unsigned int cur_shift = *shift; | |||
unsigned int i, klen; | |||
struct rspamd_fuzzy_cmd *cmd; | |||
if (io_cmd->is_shingle) { | |||
@@ -1081,7 +1081,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
4, | |||
(const gchar **) &session->argv[cur_shift - 4], | |||
(const char **) &session->argv[cur_shift - 4], | |||
&session->argv_lens[cur_shift - 4]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1094,7 +1094,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
g_string_append(key, session->backend->redis_object); | |||
g_string_append_len(key, cmd->digest, sizeof(cmd->digest)); | |||
value = g_string_sized_new(sizeof("18446744073709551616")); | |||
rspamd_printf_gstring(value, "%L", (gint64) rspamd_get_calendar_ticks()); | |||
rspamd_printf_gstring(value, "%L", (int64_t) rspamd_get_calendar_ticks()); | |||
session->argv[cur_shift] = g_strdup("HSETNX"); | |||
session->argv_lens[cur_shift++] = sizeof("HSETNX") - 1; | |||
session->argv[cur_shift] = key->str; | |||
@@ -1108,7 +1108,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
4, | |||
(const gchar **) &session->argv[cur_shift - 4], | |||
(const char **) &session->argv[cur_shift - 4], | |||
&session->argv_lens[cur_shift - 4]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1133,7 +1133,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
4, | |||
(const gchar **) &session->argv[cur_shift - 4], | |||
(const char **) &session->argv[cur_shift - 4], | |||
&session->argv_lens[cur_shift - 4]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1145,7 +1145,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
g_string_append_len(key, cmd->digest, sizeof(cmd->digest)); | |||
value = g_string_sized_new(sizeof("4294967296")); | |||
rspamd_printf_gstring(value, "%d", | |||
(gint) rspamd_fuzzy_backend_get_expire(bk)); | |||
(int) rspamd_fuzzy_backend_get_expire(bk)); | |||
session->argv[cur_shift] = g_strdup("EXPIRE"); | |||
session->argv_lens[cur_shift++] = sizeof("EXPIRE") - 1; | |||
session->argv[cur_shift] = key->str; | |||
@@ -1157,7 +1157,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
3, | |||
(const gchar **) &session->argv[cur_shift - 3], | |||
(const char **) &session->argv[cur_shift - 3], | |||
&session->argv_lens[cur_shift - 3]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1175,7 +1175,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
2, | |||
(const gchar **) &session->argv[cur_shift - 2], | |||
(const char **) &session->argv[cur_shift - 2], | |||
&session->argv_lens[cur_shift - 2]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1197,7 +1197,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
2, | |||
(const gchar **) &session->argv[cur_shift - 2], | |||
(const char **) &session->argv[cur_shift - 2], | |||
&session->argv_lens[cur_shift - 2]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1215,7 +1215,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
2, | |||
(const gchar **) &session->argv[cur_shift - 2], | |||
(const char **) &session->argv[cur_shift - 2], | |||
&session->argv_lens[cur_shift - 2]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1237,7 +1237,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
g_string_append_len(key, cmd->digest, sizeof(cmd->digest)); | |||
value = g_string_sized_new(sizeof("4294967296")); | |||
rspamd_printf_gstring(value, "%d", | |||
(gint) rspamd_fuzzy_backend_get_expire(bk)); | |||
(int) rspamd_fuzzy_backend_get_expire(bk)); | |||
session->argv[cur_shift] = g_strdup("EXPIRE"); | |||
session->argv_lens[cur_shift++] = sizeof("EXPIRE") - 1; | |||
session->argv[cur_shift] = key->str; | |||
@@ -1249,7 +1249,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
3, | |||
(const gchar **) &session->argv[cur_shift - 3], | |||
(const char **) &session->argv[cur_shift - 3], | |||
&session->argv_lens[cur_shift - 3]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1268,7 +1268,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
64 + 1; | |||
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) { | |||
guchar *hval; | |||
unsigned char *hval; | |||
/* | |||
* For each command with shingles we additionally emit 32 commands: | |||
* SETEX <prefix>_<number>_<value> <expire> <digest> | |||
@@ -1282,7 +1282,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
io_cmd->cmd.shingle.sgl.hashes[i]); | |||
value = g_string_sized_new(sizeof("4294967296")); | |||
rspamd_printf_gstring(value, "%d", | |||
(gint) rspamd_fuzzy_backend_get_expire(bk)); | |||
(int) rspamd_fuzzy_backend_get_expire(bk)); | |||
hval = g_malloc(sizeof(io_cmd->cmd.shingle.basic.digest)); | |||
memcpy(hval, io_cmd->cmd.shingle.basic.digest, | |||
sizeof(io_cmd->cmd.shingle.basic.digest)); | |||
@@ -1299,7 +1299,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
4, | |||
(const gchar **) &session->argv[cur_shift - 4], | |||
(const char **) &session->argv[cur_shift - 4], | |||
&session->argv_lens[cur_shift - 4]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1324,7 +1324,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
2, | |||
(const gchar **) &session->argv[cur_shift - 2], | |||
(const char **) &session->argv[cur_shift - 2], | |||
&session->argv_lens[cur_shift - 2]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1349,7 +1349,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
io_cmd->cmd.shingle.sgl.hashes[i]); | |||
value = g_string_sized_new(sizeof("18446744073709551616")); | |||
rspamd_printf_gstring(value, "%d", | |||
(gint) rspamd_fuzzy_backend_get_expire(bk)); | |||
(int) rspamd_fuzzy_backend_get_expire(bk)); | |||
session->argv[cur_shift] = g_strdup("EXPIRE"); | |||
session->argv_lens[cur_shift++] = sizeof("EXPIRE") - 1; | |||
session->argv[cur_shift] = key->str; | |||
@@ -1361,7 +1361,7 @@ rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
3, | |||
(const gchar **) &session->argv[cur_shift - 3], | |||
(const char **) &session->argv[cur_shift - 3], | |||
&session->argv_lens[cur_shift - 3]) != REDIS_OK) { | |||
return FALSE; | |||
@@ -1431,7 +1431,7 @@ rspamd_fuzzy_redis_update_callback(redisAsyncContext *c, gpointer r, | |||
} | |||
void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, | |||
GArray *updates, const gchar *src, | |||
GArray *updates, const char *src, | |||
rspamd_fuzzy_update_cb cb, void *ud, | |||
void *subr_ud) | |||
{ | |||
@@ -1440,11 +1440,11 @@ void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, | |||
struct upstream *up; | |||
struct upstream_list *ups; | |||
rspamd_inet_addr_t *addr; | |||
guint i; | |||
unsigned int i; | |||
GString *key; | |||
struct fuzzy_peer_cmd *io_cmd; | |||
struct rspamd_fuzzy_cmd *cmd = NULL; | |||
guint nargs, cur_shift; | |||
unsigned int nargs, cur_shift; | |||
g_assert(backend != NULL); | |||
@@ -1532,7 +1532,7 @@ void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, | |||
/* First of all check digest */ | |||
session->nargs = nargs; | |||
session->argv = g_malloc0(sizeof(gchar *) * session->nargs); | |||
session->argv = g_malloc0(sizeof(char *) * session->nargs); | |||
session->argv_lens = g_malloc0(sizeof(gsize) * session->nargs); | |||
up = rspamd_upstream_get(ups, | |||
@@ -1564,7 +1564,7 @@ void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
1, | |||
(const gchar **) session->argv, | |||
(const char **) session->argv, | |||
session->argv_lens) != REDIS_OK) { | |||
if (cb) { | |||
@@ -1603,7 +1603,7 @@ void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, NULL, NULL, | |||
2, | |||
(const gchar **) &session->argv[cur_shift - 2], | |||
(const char **) &session->argv[cur_shift - 2], | |||
&session->argv_lens[cur_shift - 2]) != REDIS_OK) { | |||
if (cb) { | |||
@@ -1621,7 +1621,7 @@ void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, | |||
if (redisAsyncCommandArgv(session->ctx, | |||
rspamd_fuzzy_redis_update_callback, session, | |||
1, | |||
(const gchar **) &session->argv[cur_shift], | |||
(const char **) &session->argv[cur_shift], | |||
&session->argv_lens[cur_shift]) != REDIS_OK) { | |||
if (cb) { |
@@ -38,7 +38,7 @@ void rspamd_fuzzy_backend_check_redis(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud); | |||
void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk, | |||
GArray *updates, const gchar *src, | |||
GArray *updates, const char *src, | |||
rspamd_fuzzy_update_cb cb, void *ud, | |||
void *subr_ud); | |||
@@ -47,12 +47,12 @@ void rspamd_fuzzy_backend_count_redis(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud); | |||
void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk, | |||
const gchar *src, | |||
const char *src, | |||
rspamd_fuzzy_version_cb cb, void *ud, | |||
void *subr_ud); | |||
const gchar *rspamd_fuzzy_backend_id_redis(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud); | |||
const char *rspamd_fuzzy_backend_id_redis(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud); | |||
void rspamd_fuzzy_backend_expire_redis(struct rspamd_fuzzy_backend *bk, | |||
void *subr_ud); |
@@ -1,11 +1,11 @@ | |||
/*- | |||
* Copyright 2016 Vsevolod Stakhov | |||
/* | |||
* Copyright 2024 Vsevolod Stakhov | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
@@ -25,14 +25,14 @@ | |||
struct rspamd_fuzzy_backend_sqlite { | |||
sqlite3 *db; | |||
char *path; | |||
gchar id[MEMPOOL_UID_LEN]; | |||
char id[MEMPOOL_UID_LEN]; | |||
gsize count; | |||
gsize expired; | |||
rspamd_mempool_t *pool; | |||
}; | |||
static const gdouble sql_sleep_time = 0.1; | |||
static const guint max_retries = 10; | |||
static const double sql_sleep_time = 0.1; | |||
static const unsigned int max_retries = 10; | |||
#define msg_err_fuzzy_backend(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \ | |||
backend->pool->tag.tagname, backend->pool->tag.uid, \ | |||
@@ -107,10 +107,10 @@ enum rspamd_fuzzy_statement_idx { | |||
}; | |||
static struct rspamd_fuzzy_stmts { | |||
enum rspamd_fuzzy_statement_idx idx; | |||
const gchar *sql; | |||
const gchar *args; | |||
const char *sql; | |||
const char *args; | |||
sqlite3_stmt *stmt; | |||
gint result; | |||
int result; | |||
} prepared_stmts[RSPAMD_FUZZY_BACKEND_MAX] = | |||
{ | |||
{.idx = RSPAMD_FUZZY_BACKEND_TRANSACTION_START, | |||
@@ -267,7 +267,7 @@ rspamd_fuzzy_backend_sqlite_run_stmt(struct rspamd_fuzzy_backend_sqlite *backend | |||
sqlite3_stmt *stmt; | |||
int i; | |||
const char *argtypes; | |||
guint retries = 0; | |||
unsigned int retries = 0; | |||
struct timespec ts; | |||
if (idx < 0 || idx >= RSPAMD_FUZZY_BACKEND_MAX) { | |||
@@ -303,10 +303,10 @@ rspamd_fuzzy_backend_sqlite_run_stmt(struct rspamd_fuzzy_backend_sqlite *backend | |||
SQLITE_STATIC); | |||
break; | |||
case 'I': | |||
sqlite3_bind_int64(stmt, i + 1, va_arg(ap, gint64)); | |||
sqlite3_bind_int64(stmt, i + 1, va_arg(ap, int64_t)); | |||
break; | |||
case 'S': | |||
sqlite3_bind_int(stmt, i + 1, va_arg(ap, gint)); | |||
sqlite3_bind_int(stmt, i + 1, va_arg(ap, int)); | |||
break; | |||
case 'D': | |||
/* Special case for digests variable */ | |||
@@ -361,12 +361,12 @@ rspamd_fuzzy_backend_sqlite_close_stmts(struct rspamd_fuzzy_backend_sqlite *bk) | |||
} | |||
static gboolean | |||
rspamd_fuzzy_backend_sqlite_run_sql(const gchar *sql, struct rspamd_fuzzy_backend_sqlite *bk, | |||
rspamd_fuzzy_backend_sqlite_run_sql(const char *sql, struct rspamd_fuzzy_backend_sqlite *bk, | |||
GError **err) | |||
{ | |||
guint retries = 0; | |||
unsigned int retries = 0; | |||
struct timespec ts; | |||
gint ret; | |||
int ret; | |||
do { | |||
ret = sqlite3_exec(bk->db, sql, NULL, NULL, NULL); | |||
@@ -385,11 +385,11 @@ rspamd_fuzzy_backend_sqlite_run_sql(const gchar *sql, struct rspamd_fuzzy_backen | |||
} | |||
static struct rspamd_fuzzy_backend_sqlite * | |||
rspamd_fuzzy_backend_sqlite_open_db(const gchar *path, GError **err) | |||
rspamd_fuzzy_backend_sqlite_open_db(const char *path, GError **err) | |||
{ | |||
struct rspamd_fuzzy_backend_sqlite *bk; | |||
rspamd_cryptobox_hash_state_t st; | |||
guchar hash_out[rspamd_cryptobox_HASHBYTES]; | |||
unsigned char hash_out[rspamd_cryptobox_HASHBYTES]; | |||
g_assert(path != NULL); | |||
@@ -424,7 +424,7 @@ rspamd_fuzzy_backend_sqlite_open_db(const gchar *path, GError **err) | |||
} | |||
struct rspamd_fuzzy_backend_sqlite * | |||
rspamd_fuzzy_backend_sqlite_open(const gchar *path, | |||
rspamd_fuzzy_backend_sqlite_open(const char *path, | |||
gboolean vacuum, | |||
GError **err) | |||
{ | |||
@@ -451,23 +451,23 @@ rspamd_fuzzy_backend_sqlite_open(const gchar *path, | |||
return backend; | |||
} | |||
static gint | |||
static int | |||
rspamd_fuzzy_backend_sqlite_int64_cmp(const void *a, const void *b) | |||
{ | |||
gint64 ia = *(gint64 *) a, ib = *(gint64 *) b; | |||
int64_t ia = *(int64_t *) a, ib = *(int64_t *) b; | |||
return (ia - ib); | |||
} | |||
struct rspamd_fuzzy_reply | |||
rspamd_fuzzy_backend_sqlite_check(struct rspamd_fuzzy_backend_sqlite *backend, | |||
const struct rspamd_fuzzy_cmd *cmd, gint64 expire) | |||
const struct rspamd_fuzzy_cmd *cmd, int64_t expire) | |||
{ | |||
struct rspamd_fuzzy_reply rep; | |||
const struct rspamd_fuzzy_shingle_cmd *shcmd; | |||
int rc; | |||
gint64 timestamp; | |||
gint64 shingle_values[RSPAMD_SHINGLE_SIZE], i, sel_id, cur_id, | |||
int64_t timestamp; | |||
int64_t shingle_values[RSPAMD_SHINGLE_SIZE], i, sel_id, cur_id, | |||
cur_cnt, max_cnt; | |||
memset(&rep, 0, sizeof(rep)); | |||
@@ -524,7 +524,7 @@ rspamd_fuzzy_backend_sqlite_check(struct rspamd_fuzzy_backend_sqlite *backend, | |||
rspamd_fuzzy_backend_sqlite_cleanup_stmt(backend, | |||
RSPAMD_FUZZY_BACKEND_CHECK_SHINGLE); | |||
qsort(shingle_values, RSPAMD_SHINGLE_SIZE, sizeof(gint64), | |||
qsort(shingle_values, RSPAMD_SHINGLE_SIZE, sizeof(int64_t), | |||
rspamd_fuzzy_backend_sqlite_int64_cmp); | |||
sel_id = -1; | |||
cur_id = -1; | |||
@@ -605,9 +605,9 @@ rspamd_fuzzy_backend_sqlite_check(struct rspamd_fuzzy_backend_sqlite *backend, | |||
gboolean | |||
rspamd_fuzzy_backend_sqlite_prepare_update(struct rspamd_fuzzy_backend_sqlite *backend, | |||
const gchar *source) | |||
const char *source) | |||
{ | |||
gint rc; | |||
int rc; | |||
if (backend == NULL) { | |||
return FALSE; | |||
@@ -630,7 +630,7 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, | |||
const struct rspamd_fuzzy_cmd *cmd) | |||
{ | |||
int rc, i; | |||
gint64 id, flag; | |||
int64_t id, flag; | |||
const struct rspamd_fuzzy_shingle_cmd *shcmd; | |||
if (backend == NULL) { | |||
@@ -652,13 +652,13 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, | |||
/* We need to increase weight */ | |||
rc = rspamd_fuzzy_backend_sqlite_run_stmt(backend, TRUE, | |||
RSPAMD_FUZZY_BACKEND_UPDATE, | |||
(gint64) cmd->value, | |||
(int64_t) cmd->value, | |||
cmd->digest); | |||
if (rc != SQLITE_OK) { | |||
msg_warn_fuzzy_backend("cannot update hash to %d -> " | |||
"%*xs: %s", | |||
(gint) cmd->flag, | |||
(gint) sizeof(cmd->digest), cmd->digest, | |||
(int) cmd->flag, | |||
(int) sizeof(cmd->digest), cmd->digest, | |||
sqlite3_errmsg(backend->db)); | |||
} | |||
} | |||
@@ -667,15 +667,15 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, | |||
rc = rspamd_fuzzy_backend_sqlite_run_stmt(backend, TRUE, | |||
RSPAMD_FUZZY_BACKEND_UPDATE_FLAG, | |||
(gint64) cmd->value, | |||
(gint64) cmd->flag, | |||
(int64_t) cmd->value, | |||
(int64_t) cmd->flag, | |||
cmd->digest); | |||
if (rc != SQLITE_OK) { | |||
msg_warn_fuzzy_backend("cannot update hash to %d -> " | |||
"%*xs: %s", | |||
(gint) cmd->flag, | |||
(gint) sizeof(cmd->digest), cmd->digest, | |||
(int) cmd->flag, | |||
(int) sizeof(cmd->digest), cmd->digest, | |||
sqlite3_errmsg(backend->db)); | |||
} | |||
} | |||
@@ -684,9 +684,9 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, | |||
rspamd_fuzzy_backend_sqlite_cleanup_stmt(backend, RSPAMD_FUZZY_BACKEND_CHECK); | |||
rc = rspamd_fuzzy_backend_sqlite_run_stmt(backend, FALSE, | |||
RSPAMD_FUZZY_BACKEND_INSERT, | |||
(gint) cmd->flag, | |||
(int) cmd->flag, | |||
cmd->digest, | |||
(gint64) cmd->value); | |||
(int64_t) cmd->value); | |||
if (rc == SQLITE_OK) { | |||
if (cmd->shingles_count > 0) { | |||
@@ -696,7 +696,7 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, | |||
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) { | |||
rc = rspamd_fuzzy_backend_sqlite_run_stmt(backend, TRUE, | |||
RSPAMD_FUZZY_BACKEND_INSERT_SHINGLE, | |||
shcmd->sgl.hashes[i], (gint64) i, id); | |||
shcmd->sgl.hashes[i], (int64_t) i, id); | |||
msg_debug_fuzzy_backend("add shingle %d -> %L: %L", | |||
i, | |||
shcmd->sgl.hashes[i], | |||
@@ -715,8 +715,8 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, | |||
else { | |||
msg_warn_fuzzy_backend("cannot add hash to %d -> " | |||
"%*xs: %s", | |||
(gint) cmd->flag, | |||
(gint) sizeof(cmd->digest), cmd->digest, | |||
(int) cmd->flag, | |||
(int) sizeof(cmd->digest), cmd->digest, | |||
sqlite3_errmsg(backend->db)); | |||
} | |||
@@ -729,9 +729,9 @@ rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend, | |||
gboolean | |||
rspamd_fuzzy_backend_sqlite_finish_update(struct rspamd_fuzzy_backend_sqlite *backend, | |||
const gchar *source, gboolean version_bump) | |||
const char *source, gboolean version_bump) | |||
{ | |||
gint rc = SQLITE_OK, wal_frames, wal_checkpointed, ver; | |||
int rc = SQLITE_OK, wal_frames, wal_checkpointed, ver; | |||
/* Get and update version */ | |||
if (version_bump) { | |||
@@ -740,7 +740,7 @@ rspamd_fuzzy_backend_sqlite_finish_update(struct rspamd_fuzzy_backend_sqlite *ba | |||
rc = rspamd_fuzzy_backend_sqlite_run_stmt(backend, TRUE, | |||
RSPAMD_FUZZY_BACKEND_SET_VERSION, | |||
(gint64) ver, (gint64) time(NULL), source); | |||
(int64_t) ver, (int64_t) time(NULL), source); | |||
} | |||
if (rc == SQLITE_OK) { | |||
@@ -800,8 +800,8 @@ rspamd_fuzzy_backend_sqlite_del(struct rspamd_fuzzy_backend_sqlite *backend, | |||
if (rc != SQLITE_OK) { | |||
msg_warn_fuzzy_backend("cannot update hash to %d -> " | |||
"%*xs: %s", | |||
(gint) cmd->flag, | |||
(gint) sizeof(cmd->digest), cmd->digest, | |||
(int) cmd->flag, | |||
(int) sizeof(cmd->digest), cmd->digest, | |||
sqlite3_errmsg(backend->db)); | |||
} | |||
} | |||
@@ -815,25 +815,25 @@ rspamd_fuzzy_backend_sqlite_del(struct rspamd_fuzzy_backend_sqlite *backend, | |||
gboolean | |||
rspamd_fuzzy_backend_sqlite_sync(struct rspamd_fuzzy_backend_sqlite *backend, | |||
gint64 expire, | |||
int64_t expire, | |||
gboolean clean_orphaned) | |||
{ | |||
struct orphaned_shingle_elt { | |||
gint64 value; | |||
gint64 number; | |||
int64_t value; | |||
int64_t number; | |||
}; | |||
/* Do not do more than 5k ops per step */ | |||
const guint64 max_changes = 5000; | |||
const uint64_t max_changes = 5000; | |||
gboolean ret = FALSE; | |||
gint64 expire_lim, expired; | |||
gint rc, i, orphaned_cnt = 0; | |||
int64_t expire_lim, expired; | |||
int rc, i, orphaned_cnt = 0; | |||
GError *err = NULL; | |||
static const gchar orphaned_shingles[] = "SELECT shingles.value,shingles.number " | |||
"FROM shingles " | |||
"LEFT JOIN digests ON " | |||
"shingles.digest_id=digests.id WHERE " | |||
"digests.id IS NULL;"; | |||
static const char orphaned_shingles[] = "SELECT shingles.value,shingles.number " | |||
"FROM shingles " | |||
"LEFT JOIN digests ON " | |||
"shingles.digest_id=digests.id WHERE " | |||
"digests.id IS NULL;"; | |||
sqlite3_stmt *stmt; | |||
GArray *orphaned; | |||
struct orphaned_shingle_elt orphaned_elt, *pelt; | |||
@@ -925,7 +925,7 @@ rspamd_fuzzy_backend_sqlite_sync(struct rspamd_fuzzy_backend_sqlite *backend, | |||
"going to delete %ud orphaned shingles", | |||
orphaned_cnt); | |||
/* Need to delete orphaned elements */ | |||
for (i = 0; i < (gint) orphaned_cnt; i++) { | |||
for (i = 0; i < (int) orphaned_cnt; i++) { | |||
pelt = &g_array_index(orphaned, | |||
struct orphaned_shingle_elt, | |||
i); | |||
@@ -999,10 +999,10 @@ gsize rspamd_fuzzy_backend_sqlite_count(struct rspamd_fuzzy_backend_sqlite *back | |||
return 0; | |||
} | |||
gint rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, | |||
const gchar *source) | |||
int rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, | |||
const char *source) | |||
{ | |||
gint ret = 0; | |||
int ret = 0; | |||
if (backend) { | |||
if (rspamd_fuzzy_backend_sqlite_run_stmt(backend, FALSE, | |||
@@ -1022,7 +1022,7 @@ gsize rspamd_fuzzy_backend_sqlite_expired(struct rspamd_fuzzy_backend_sqlite *ba | |||
return backend != NULL ? backend->expired : 0; | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_fuzzy_sqlite_backend_id(struct rspamd_fuzzy_backend_sqlite *backend) | |||
{ | |||
return backend != NULL ? backend->id : 0; |
@@ -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, | |||
@@ -31,7 +31,7 @@ struct rspamd_fuzzy_backend_sqlite; | |||
* @param err error pointer | |||
* @return backend structure or NULL | |||
*/ | |||
struct rspamd_fuzzy_backend_sqlite *rspamd_fuzzy_backend_sqlite_open(const gchar *path, | |||
struct rspamd_fuzzy_backend_sqlite *rspamd_fuzzy_backend_sqlite_open(const char *path, | |||
gboolean vacuum, | |||
GError **err); | |||
@@ -44,13 +44,13 @@ struct rspamd_fuzzy_backend_sqlite *rspamd_fuzzy_backend_sqlite_open(const gchar | |||
struct rspamd_fuzzy_reply rspamd_fuzzy_backend_sqlite_check( | |||
struct rspamd_fuzzy_backend_sqlite *backend, | |||
const struct rspamd_fuzzy_cmd *cmd, | |||
gint64 expire); | |||
int64_t expire); | |||
/** | |||
* Prepare storage for updates (by starting transaction) | |||
*/ | |||
gboolean rspamd_fuzzy_backend_sqlite_prepare_update(struct rspamd_fuzzy_backend_sqlite *backend, | |||
const gchar *source); | |||
const char *source); | |||
/** | |||
* Add digest to the database | |||
@@ -75,7 +75,7 @@ gboolean rspamd_fuzzy_backend_sqlite_del( | |||
* Commit updates to storage | |||
*/ | |||
gboolean rspamd_fuzzy_backend_sqlite_finish_update(struct rspamd_fuzzy_backend_sqlite *backend, | |||
const gchar *source, gboolean version_bump); | |||
const char *source, gboolean version_bump); | |||
/** | |||
* Sync storage | |||
@@ -83,7 +83,7 @@ gboolean rspamd_fuzzy_backend_sqlite_finish_update(struct rspamd_fuzzy_backend_s | |||
* @return | |||
*/ | |||
gboolean rspamd_fuzzy_backend_sqlite_sync(struct rspamd_fuzzy_backend_sqlite *backend, | |||
gint64 expire, | |||
int64_t expire, | |||
gboolean clean_orphaned); | |||
/** | |||
@@ -94,11 +94,11 @@ void rspamd_fuzzy_backend_sqlite_close(struct rspamd_fuzzy_backend_sqlite *backe | |||
gsize rspamd_fuzzy_backend_sqlite_count(struct rspamd_fuzzy_backend_sqlite *backend); | |||
gint rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, const gchar *source); | |||
int rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, const char *source); | |||
gsize rspamd_fuzzy_backend_sqlite_expired(struct rspamd_fuzzy_backend_sqlite *backend); | |||
const gchar *rspamd_fuzzy_sqlite_backend_id(struct rspamd_fuzzy_backend_sqlite *backend); | |||
const char *rspamd_fuzzy_sqlite_backend_id(struct rspamd_fuzzy_backend_sqlite *backend); | |||
#ifdef __cplusplus | |||
} |
@@ -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. | |||
@@ -54,13 +54,13 @@ enum rspamd_fuzzy_epoch { | |||
RSPAMD_PACKED(rspamd_fuzzy_cmd) | |||
{ | |||
guint8 version; | |||
guint8 cmd; | |||
guint8 shingles_count; | |||
guint8 flag; | |||
gint32 value; | |||
guint32 tag; | |||
gchar digest[rspamd_cryptobox_HASHBYTES]; | |||
uint8_t version; | |||
uint8_t cmd; | |||
uint8_t shingles_count; | |||
uint8_t flag; | |||
int32_t value; | |||
uint32_t tag; | |||
char digest[rspamd_cryptobox_HASHBYTES]; | |||
}; | |||
RSPAMD_PACKED(rspamd_fuzzy_shingle_cmd) | |||
@@ -71,27 +71,27 @@ RSPAMD_PACKED(rspamd_fuzzy_shingle_cmd) | |||
RSPAMD_PACKED(rspamd_fuzzy_reply_v1) | |||
{ | |||
gint32 value; | |||
guint32 flag; | |||
guint32 tag; | |||
int32_t value; | |||
uint32_t flag; | |||
uint32_t tag; | |||
float prob; | |||
}; | |||
RSPAMD_PACKED(rspamd_fuzzy_reply) | |||
{ | |||
struct rspamd_fuzzy_reply_v1 v1; | |||
gchar digest[rspamd_cryptobox_HASHBYTES]; | |||
guint32 ts; | |||
guchar reserved[12]; | |||
char digest[rspamd_cryptobox_HASHBYTES]; | |||
uint32_t ts; | |||
unsigned char reserved[12]; | |||
}; | |||
RSPAMD_PACKED(rspamd_fuzzy_encrypted_req_hdr) | |||
{ | |||
guchar magic[4]; | |||
guchar key_id[RSPAMD_FUZZY_KEYLEN]; | |||
guchar pubkey[32]; | |||
guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES]; | |||
guchar mac[rspamd_cryptobox_MAX_MACBYTES]; | |||
unsigned char magic[4]; | |||
unsigned char key_id[RSPAMD_FUZZY_KEYLEN]; | |||
unsigned char pubkey[32]; | |||
unsigned char nonce[rspamd_cryptobox_MAX_NONCEBYTES]; | |||
unsigned char mac[rspamd_cryptobox_MAX_MACBYTES]; | |||
}; | |||
RSPAMD_PACKED(rspamd_fuzzy_encrypted_cmd) | |||
@@ -108,8 +108,8 @@ RSPAMD_PACKED(rspamd_fuzzy_encrypted_shingle_cmd) | |||
RSPAMD_PACKED(rspamd_fuzzy_encrypted_rep_hdr) | |||
{ | |||
guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES]; | |||
guchar mac[rspamd_cryptobox_MAX_MACBYTES]; | |||
unsigned char nonce[rspamd_cryptobox_MAX_NONCEBYTES]; | |||
unsigned char mac[rspamd_cryptobox_MAX_MACBYTES]; | |||
}; | |||
RSPAMD_PACKED(rspamd_fuzzy_encrypted_reply) | |||
@@ -118,7 +118,7 @@ RSPAMD_PACKED(rspamd_fuzzy_encrypted_reply) | |||
struct rspamd_fuzzy_reply rep; | |||
}; | |||
static const guchar fuzzy_encrypted_magic[4] = {'r', 's', 'f', 'e'}; | |||
static const unsigned char fuzzy_encrypted_magic[4] = {'r', 's', 'f', 'e'}; | |||
enum rspamd_fuzzy_extension_type { | |||
RSPAMD_FUZZY_EXT_SOURCE_DOMAIN = 'd', | |||
@@ -128,19 +128,19 @@ enum rspamd_fuzzy_extension_type { | |||
struct rspamd_fuzzy_cmd_extension { | |||
enum rspamd_fuzzy_extension_type ext; | |||
guint length; | |||
unsigned int length; | |||
struct rspamd_fuzzy_cmd_extension *next; | |||
guchar *payload; | |||
unsigned char *payload; | |||
}; | |||
struct rspamd_fuzzy_stat_entry { | |||
const gchar *name; | |||
guint64 fuzzy_cnt; | |||
const char *name; | |||
uint64_t fuzzy_cnt; | |||
}; | |||
RSPAMD_PACKED(fuzzy_peer_cmd) | |||
{ | |||
gint32 is_shingle; | |||
int32_t is_shingle; | |||
union { | |||
struct rspamd_fuzzy_cmd normal; | |||
struct rspamd_fuzzy_shingle_cmd shingle; |
@@ -43,7 +43,7 @@ | |||
namespace rspamd::html { | |||
static const guint max_tags = 8192; /* Ignore tags if this maximum is reached */ | |||
static const unsigned int max_tags = 8192; /* Ignore tags if this maximum is reached */ | |||
static const html_tags_storage html_tags_defs; | |||
@@ -658,7 +658,7 @@ html_process_url_tag(rspamd_mempool_t *pool, | |||
"%*s%s%*s", | |||
(int) hc->base_url->urllen, hc->base_url->string, | |||
need_slash ? "/" : "", | |||
(gint) orig_len, href_value.data()); | |||
(int) orig_len, href_value.data()); | |||
href_value = {buf, nlen}; | |||
} | |||
else if (href_value.size() > 2 && href_value[0] == '/' && href_value[1] != '/') { | |||
@@ -670,7 +670,7 @@ html_process_url_tag(rspamd_mempool_t *pool, | |||
auto nlen = (std::size_t) rspamd_snprintf(buf, len + 1, "%*s://%*s/%*s", | |||
(int) hc->base_url->protocollen, hc->base_url->string, | |||
(int) hc->base_url->hostlen, rspamd_url_host_unsafe(hc->base_url), | |||
(gint) orig_len, href_value.data()); | |||
(int) orig_len, href_value.data()); | |||
href_value = {buf, nlen}; | |||
} | |||
} | |||
@@ -769,21 +769,21 @@ html_process_data_image(rspamd_mempool_t *pool, | |||
* We ignore content type so far | |||
*/ | |||
struct rspamd_image *parsed_image; | |||
const gchar *semicolon_pos = input.data(), | |||
*end = input.data() + input.size(); | |||
const char *semicolon_pos = input.data(), | |||
*end = input.data() + input.size(); | |||
if ((semicolon_pos = (const gchar *) memchr(semicolon_pos, ';', end - semicolon_pos)) != NULL) { | |||
if ((semicolon_pos = (const char *) memchr(semicolon_pos, ';', end - semicolon_pos)) != NULL) { | |||
if (end - semicolon_pos > sizeof("base64,")) { | |||
if (memcmp(semicolon_pos + 1, "base64,", sizeof("base64,") - 1) == 0) { | |||
const gchar *data_pos = semicolon_pos + sizeof("base64,"); | |||
gchar *decoded; | |||
const char *data_pos = semicolon_pos + sizeof("base64,"); | |||
char *decoded; | |||
gsize encoded_len = end - data_pos, decoded_len; | |||
rspamd_ftok_t inp; | |||
decoded_len = (encoded_len / 4 * 3) + 12; | |||
decoded = rspamd_mempool_alloc_buffer(pool, decoded_len); | |||
rspamd_cryptobox_base64_decode(data_pos, encoded_len, | |||
reinterpret_cast<guchar *>(decoded), &decoded_len); | |||
reinterpret_cast<unsigned char *>(decoded), &decoded_len); | |||
inp.begin = decoded; | |||
inp.len = decoded_len; | |||
@@ -1108,7 +1108,7 @@ html_process_displayed_href_tag(rspamd_mempool_t *pool, | |||
static auto | |||
html_append_tag_content(rspamd_mempool_t *pool, | |||
const gchar *start, gsize len, | |||
const char *start, gsize len, | |||
struct html_content *hc, | |||
html_tag *tag, | |||
GList **exceptions, | |||
@@ -1329,12 +1329,12 @@ auto html_process_input(struct rspamd_task *task, | |||
bool allow_css, | |||
std::uint16_t *cur_url_order) -> html_content * | |||
{ | |||
const gchar *p, *c, *end, *start; | |||
guchar t; | |||
const char *p, *c, *end, *start; | |||
unsigned char t; | |||
auto closing = false; | |||
guint obrace = 0, ebrace = 0; | |||
unsigned int obrace = 0, ebrace = 0; | |||
struct rspamd_url *url = nullptr; | |||
gint href_offset = -1; | |||
int href_offset = -1; | |||
auto overflow_input = false; | |||
struct html_tag *cur_tag = nullptr, *parent_tag = nullptr, cur_closing_tag; | |||
struct tag_content_parser_state content_parser_env; | |||
@@ -1819,8 +1819,8 @@ auto html_process_input(struct rspamd_task *task, | |||
* Since closing tags must not have attributes, these assumptions | |||
* seems to be reasonable enough for our toy parser. | |||
*/ | |||
gint cur_lookahead = 1; | |||
gint max_lookahead = MIN(end - p, 30); | |||
int cur_lookahead = 1; | |||
int max_lookahead = MIN(end - p, 30); | |||
bool valid_closing_tag = true; | |||
if (p + 1 < end && !g_ascii_isalpha(p[1])) { | |||
@@ -1828,7 +1828,7 @@ auto html_process_input(struct rspamd_task *task, | |||
} | |||
else { | |||
while (cur_lookahead < max_lookahead) { | |||
gchar tt = p[cur_lookahead]; | |||
char tt = p[cur_lookahead]; | |||
if (tt == '>') { | |||
break; | |||
} | |||
@@ -2296,12 +2296,12 @@ rspamd_html_process_part(rspamd_mempool_t *pool, | |||
NULL, NULL, FALSE, &order); | |||
} | |||
guint rspamd_html_decode_entitles_inplace(gchar *s, gsize len) | |||
unsigned int rspamd_html_decode_entitles_inplace(char *s, gsize len) | |||
{ | |||
return rspamd::html::decode_html_entitles_inplace(s, len); | |||
} | |||
gint rspamd_html_tag_by_name(const gchar *name) | |||
int rspamd_html_tag_by_name(const char *name) | |||
{ | |||
const auto *td = rspamd::html::html_tags_defs.by_name(name); | |||
@@ -2313,9 +2313,9 @@ gint rspamd_html_tag_by_name(const gchar *name) | |||
} | |||
gboolean | |||
rspamd_html_tag_seen(void *ptr, const gchar *tagname) | |||
rspamd_html_tag_seen(void *ptr, const char *tagname) | |||
{ | |||
gint id; | |||
int id; | |||
auto *hc = rspamd::html::html_content::from_ptr(ptr); | |||
g_assert(hc != NULL); | |||
@@ -2329,8 +2329,8 @@ rspamd_html_tag_seen(void *ptr, const gchar *tagname) | |||
return FALSE; | |||
} | |||
const gchar * | |||
rspamd_html_tag_by_id(gint id) | |||
const char * | |||
rspamd_html_tag_by_id(int id) | |||
{ | |||
if (id > Tag_UNKNOWN && id < Tag_MAX) { | |||
const auto *td = rspamd::html::html_tags_defs.by_id(id); | |||
@@ -2343,7 +2343,7 @@ rspamd_html_tag_by_id(gint id) | |||
return nullptr; | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_html_tag_name(void *p, gsize *len) | |||
{ | |||
auto *tag = reinterpret_cast<rspamd::html::html_tag *>(p); |
@@ -49,10 +49,10 @@ extern "C" { | |||
struct rspamd_image; | |||
struct html_image { | |||
guint height; | |||
guint width; | |||
guint flags; | |||
gchar *src; | |||
unsigned int height; | |||
unsigned int width; | |||
unsigned int flags; | |||
char *src; | |||
struct rspamd_url *url; | |||
struct rspamd_image *embedded_image; | |||
void *tag; | |||
@@ -65,7 +65,7 @@ struct rspamd_task; | |||
/* | |||
* Decode HTML entitles in text. Text is modified in place. | |||
*/ | |||
guint rspamd_html_decode_entitles_inplace(gchar *s, gsize len); | |||
unsigned int rspamd_html_decode_entitles_inplace(char *s, gsize len); | |||
void *rspamd_html_process_part(rspamd_mempool_t *pool, | |||
GByteArray *in); | |||
@@ -80,21 +80,21 @@ void *rspamd_html_process_part_full(struct rspamd_task *task, | |||
/* | |||
* Returns true if a specified tag has been seen in a part | |||
*/ | |||
gboolean rspamd_html_tag_seen(void *ptr, const gchar *tagname); | |||
gboolean rspamd_html_tag_seen(void *ptr, const char *tagname); | |||
/** | |||
* Returns name for the specified tag id | |||
* @param id | |||
* @return | |||
*/ | |||
const gchar *rspamd_html_tag_by_id(gint id); | |||
const char *rspamd_html_tag_by_id(int id); | |||
/** | |||
* Returns HTML tag id by name | |||
* @param name | |||
* @return | |||
*/ | |||
gint rspamd_html_tag_by_name(const gchar *name); | |||
int rspamd_html_tag_by_name(const char *name); | |||
/** | |||
* Gets a name for a tag | |||
@@ -102,7 +102,7 @@ gint rspamd_html_tag_by_name(const gchar *name); | |||
* @param len | |||
* @return | |||
*/ | |||
const gchar *rspamd_html_tag_name(void *tag, gsize *len); | |||
const char *rspamd_html_tag_name(void *tag, gsize *len); | |||
/** | |||
* Find HTML image by content id |
@@ -42,7 +42,7 @@ struct html_block; | |||
struct html_content { | |||
struct rspamd_url *base_url = nullptr; | |||
struct html_tag *root_tag = nullptr; | |||
gint flags = 0; | |||
int flags = 0; | |||
std::vector<bool> tags_seen; | |||
std::vector<html_image *> images; | |||
std::vector<std::unique_ptr<struct html_tag>> all_tags; |
@@ -2237,7 +2237,7 @@ decode_html_entitles_inplace(char *s, std::size_t len, bool norm_spaces) | |||
* e - begin of entity | |||
*/ | |||
char *t = s, *h = s, *e = s; | |||
const gchar *end; | |||
const char *end; | |||
bool seen_hash = false, seen_hex = false; | |||
enum { | |||
do_undefined, |
@@ -28,7 +28,7 @@ namespace rspamd::html { | |||
struct html_tag_def { | |||
std::string name; | |||
tag_id_t id; | |||
guint flags; | |||
unsigned int flags; | |||
}; | |||
#define TAG_DEF(id, name, flags) \ |
@@ -1,11 +1,11 @@ | |||
/*- | |||
* Copyright 2021 Vsevolod Stakhov | |||
/* | |||
* Copyright 2024 Vsevolod Stakhov | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
@@ -59,7 +59,7 @@ TEST_SUITE("html") | |||
SUBCASE((std::string("extract tags from: ") + c.first).c_str()) | |||
{ | |||
GByteArray *tmp = g_byte_array_sized_new(c.first.size()); | |||
g_byte_array_append(tmp, (const guint8 *) c.first.data(), c.first.size()); | |||
g_byte_array_append(tmp, (const uint8_t *) c.first.data(), c.first.size()); | |||
auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, nullptr, true, nullptr); | |||
CHECK(hc != nullptr); | |||
auto dump = html_debug_structure(*hc); | |||
@@ -230,7 +230,7 @@ TEST_SUITE("html") | |||
SUBCASE((fmt::format("html extraction case {}", i)).c_str()) | |||
{ | |||
GByteArray *tmp = g_byte_array_sized_new(c.first.size()); | |||
g_byte_array_append(tmp, (const guint8 *) c.first.data(), c.first.size()); | |||
g_byte_array_append(tmp, (const uint8_t *) c.first.data(), c.first.size()); | |||
auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, nullptr, true, nullptr); | |||
CHECK(hc != nullptr); | |||
replace_newlines(hc->parsed); | |||
@@ -278,7 +278,7 @@ TEST_SUITE("html") | |||
GPtrArray *purls = g_ptr_array_new(); | |||
auto input = std::get<0>(c); | |||
GByteArray *tmp = g_byte_array_sized_new(input.size()); | |||
g_byte_array_append(tmp, (const guint8 *) input.data(), input.size()); | |||
g_byte_array_append(tmp, (const uint8_t *) input.data(), input.size()); | |||
auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, purls, true, nullptr); | |||
CHECK(hc != nullptr); | |||
auto &expected_text = std::get<2>(c); |
@@ -137,7 +137,7 @@ auto html_url_is_phished(rspamd_mempool_t *pool, | |||
struct rspamd_url *text_url; | |||
std::string_view disp_tok, href_tok; | |||
goffset url_pos; | |||
gchar *url_str = NULL; | |||
char *url_str = NULL; | |||
auto sz = text_data.size(); | |||
const auto *trimmed = rspamd_string_unicode_trim_inplace(text_data.data(), &sz); | |||
@@ -234,7 +234,7 @@ void html_check_displayed_url(rspamd_mempool_t *pool, | |||
struct rspamd_url *displayed_url = nullptr; | |||
struct rspamd_url *turl; | |||
struct rspamd_process_exception *ex; | |||
guint saved_flags = 0; | |||
unsigned int saved_flags = 0; | |||
gsize dlen; | |||
if (visible_part.empty()) { | |||
@@ -311,13 +311,13 @@ auto html_process_url(rspamd_mempool_t *pool, std::string_view &input) | |||
-> std::optional<struct rspamd_url *> | |||
{ | |||
struct rspamd_url *url; | |||
guint saved_flags = 0; | |||
gint rc; | |||
const gchar *s, *prefix = "http://"; | |||
gchar *d; | |||
unsigned int saved_flags = 0; | |||
int rc; | |||
const char *s, *prefix = "http://"; | |||
char *d; | |||
gsize dlen; | |||
gboolean has_bad_chars = FALSE, no_prefix = FALSE; | |||
static const gchar hexdigests[] = "0123456789abcdef"; | |||
static const char hexdigests[] = "0123456789abcdef"; | |||
auto sz = input.length(); | |||
const auto *trimmed = rspamd_string_unicode_trim_inplace(input.data(), &sz); | |||
@@ -328,7 +328,7 @@ auto html_process_url(rspamd_mempool_t *pool, std::string_view &input) | |||
dlen = 0; | |||
for (auto i = 0; i < sz; i++) { | |||
if (G_UNLIKELY(((guint) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) { | |||
if (G_UNLIKELY(((unsigned int) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) { | |||
dlen += 3; | |||
} | |||
else { | |||
@@ -397,7 +397,7 @@ auto html_process_url(rspamd_mempool_t *pool, std::string_view &input) | |||
if (G_UNLIKELY(g_ascii_isspace(s[i]))) { | |||
continue; | |||
} | |||
else if (G_UNLIKELY(((guint) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) { | |||
else if (G_UNLIKELY(((unsigned int) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) { | |||
/* URL encode */ | |||
*d++ = '%'; | |||
*d++ = hexdigests[(s[i] >> 4) & 0xf]; |
@@ -39,7 +39,7 @@ | |||
struct _rspamd_http_privbuf { | |||
rspamd_fstring_t *data; | |||
const gchar *zc_buf; | |||
const char *zc_buf; | |||
gsize zc_remain; | |||
ref_entry_t ref; | |||
}; | |||
@@ -72,7 +72,7 @@ struct rspamd_http_connection_private { | |||
ev_tstamp timeout; | |||
struct rspamd_http_message *msg; | |||
struct iovec *out; | |||
guint outlen; | |||
unsigned int outlen; | |||
enum rspamd_http_priv_flags flags; | |||
gsize wr_pos; | |||
gsize wr_total; | |||
@@ -111,8 +111,8 @@ rspamd_http_privbuf_dtor(gpointer ud) | |||
g_free(p); | |||
} | |||
static const gchar * | |||
rspamd_http_code_to_str(gint code) | |||
static const char * | |||
rspamd_http_code_to_str(int code) | |||
{ | |||
if (code == 200) { | |||
return "OK"; | |||
@@ -140,8 +140,8 @@ static void | |||
rspamd_http_parse_key(rspamd_ftok_t *data, struct rspamd_http_connection *conn, | |||
struct rspamd_http_connection_private *priv) | |||
{ | |||
guchar *decoded_id; | |||
const gchar *eq_pos; | |||
unsigned char *decoded_id; | |||
const char *eq_pos; | |||
gsize id_len; | |||
struct rspamd_cryptobox_pubkey *pk; | |||
@@ -203,8 +203,8 @@ rspamd_http_check_special_header(struct rspamd_http_connection *conn, | |||
} | |||
} | |||
static gint | |||
rspamd_http_on_url(http_parser *parser, const gchar *at, size_t length) | |||
static int | |||
rspamd_http_on_url(http_parser *parser, const char *at, size_t length) | |||
{ | |||
struct rspamd_http_connection *conn = | |||
(struct rspamd_http_connection *) parser->data; | |||
@@ -217,8 +217,8 @@ rspamd_http_on_url(http_parser *parser, const gchar *at, size_t length) | |||
return 0; | |||
} | |||
static gint | |||
rspamd_http_on_status(http_parser *parser, const gchar *at, size_t length) | |||
static int | |||
rspamd_http_on_status(http_parser *parser, const char *at, size_t length) | |||
{ | |||
struct rspamd_http_connection *conn = | |||
(struct rspamd_http_connection *) parser->data; | |||
@@ -243,7 +243,7 @@ rspamd_http_finish_header(struct rspamd_http_connection *conn, | |||
{ | |||
struct rspamd_http_header *hdr; | |||
khiter_t k; | |||
gint r; | |||
int r; | |||
priv->header->combined = rspamd_fstring_append(priv->header->combined, | |||
"\r\n", 2); | |||
@@ -276,9 +276,9 @@ rspamd_http_init_header(struct rspamd_http_connection_private *priv) | |||
priv->header->combined = rspamd_fstring_new(); | |||
} | |||
static gint | |||
static int | |||
rspamd_http_on_header_field(http_parser *parser, | |||
const gchar *at, | |||
const char *at, | |||
size_t length) | |||
{ | |||
struct rspamd_http_connection *conn = | |||
@@ -302,9 +302,9 @@ rspamd_http_on_header_field(http_parser *parser, | |||
return 0; | |||
} | |||
static gint | |||
static int | |||
rspamd_http_on_header_value(http_parser *parser, | |||
const gchar *at, | |||
const char *at, | |||
size_t length) | |||
{ | |||
struct rspamd_http_connection *conn = | |||
@@ -412,14 +412,14 @@ rspamd_http_switch_zc(struct _rspamd_http_privbuf *pbuf, | |||
} | |||
static int | |||
rspamd_http_on_body(http_parser *parser, const gchar *at, size_t length) | |||
rspamd_http_on_body(http_parser *parser, const char *at, size_t length) | |||
{ | |||
struct rspamd_http_connection *conn = | |||
(struct rspamd_http_connection *) parser->data; | |||
struct rspamd_http_connection_private *priv; | |||
struct rspamd_http_message *msg; | |||
struct _rspamd_http_privbuf *pbuf; | |||
const gchar *p; | |||
const char *p; | |||
priv = conn->priv; | |||
msg = priv->msg; | |||
@@ -457,7 +457,7 @@ rspamd_http_on_body(http_parser *parser, const gchar *at, size_t length) | |||
else { | |||
if (msg->body_buf.begin + msg->body_buf.len != at) { | |||
/* Likely chunked encoding */ | |||
memmove((gchar *) msg->body_buf.begin + msg->body_buf.len, at, length); | |||
memmove((char *) msg->body_buf.begin + msg->body_buf.len, at, length); | |||
p = msg->body_buf.begin + msg->body_buf.len; | |||
} | |||
@@ -481,7 +481,7 @@ rspamd_http_on_body(http_parser *parser, const gchar *at, size_t length) | |||
} | |||
static int | |||
rspamd_http_on_body_decrypted(http_parser *parser, const gchar *at, size_t length) | |||
rspamd_http_on_body_decrypted(http_parser *parser, const char *at, size_t length) | |||
{ | |||
struct rspamd_http_connection *conn = | |||
(struct rspamd_http_connection *) parser->data; | |||
@@ -565,8 +565,8 @@ rspamd_http_decrypt_message(struct rspamd_http_connection *conn, | |||
struct rspamd_http_connection_private *priv, | |||
struct rspamd_cryptobox_pubkey *peer_key) | |||
{ | |||
guchar *nonce, *m; | |||
const guchar *nm; | |||
unsigned char *nonce, *m; | |||
const unsigned char *nm; | |||
gsize dec_len; | |||
struct rspamd_http_message *msg = priv->msg; | |||
struct rspamd_http_header *hdr, *hcur, *hcurtmp; | |||
@@ -588,7 +588,7 @@ rspamd_http_decrypt_message(struct rspamd_http_connection *conn, | |||
if (!rspamd_cryptobox_decrypt_nm_inplace(m, dec_len, nonce, | |||
nm, m - rspamd_cryptobox_mac_bytes(mode), mode)) { | |||
msg_err("cannot verify encrypted message, first bytes of the input: %*xs", | |||
(gint) MIN(msg->body_buf.len, 64), msg->body_buf.begin); | |||
(int) MIN(msg->body_buf.len, 64), msg->body_buf.begin); | |||
return -1; | |||
} | |||
@@ -715,7 +715,7 @@ rspamd_http_simple_client_helper(struct rspamd_http_connection *conn) | |||
{ | |||
struct rspamd_http_connection_private *priv; | |||
gpointer ssl; | |||
gint request_method; | |||
int request_method; | |||
GString *prev_host = NULL; | |||
priv = conn->priv; | |||
@@ -760,8 +760,8 @@ rspamd_http_write_helper(struct rspamd_http_connection *conn) | |||
{ | |||
struct rspamd_http_connection_private *priv; | |||
struct iovec *start; | |||
guint niov, i; | |||
gint flags = 0; | |||
unsigned int niov, i; | |||
int flags = 0; | |||
gsize remain; | |||
gssize r; | |||
GError *err; | |||
@@ -864,14 +864,14 @@ call_finish_handler: | |||
} | |||
static gssize | |||
rspamd_http_try_read(gint fd, | |||
rspamd_http_try_read(int fd, | |||
struct rspamd_http_connection *conn, | |||
struct rspamd_http_connection_private *priv, | |||
struct _rspamd_http_privbuf *pbuf, | |||
const gchar **buf_ptr) | |||
const char **buf_ptr) | |||
{ | |||
gssize r; | |||
gchar *data; | |||
char *data; | |||
gsize len; | |||
struct rspamd_http_message *msg; | |||
@@ -882,13 +882,13 @@ rspamd_http_try_read(gint fd, | |||
len = priv->buf->data->allocated; | |||
} | |||
else { | |||
data = (gchar *) pbuf->zc_buf; | |||
data = (char *) pbuf->zc_buf; | |||
len = pbuf->zc_remain; | |||
if (len == 0) { | |||
rspamd_http_message_grow_body(priv->msg, priv->buf->data->allocated); | |||
rspamd_http_switch_zc(pbuf, msg); | |||
data = (gchar *) pbuf->zc_buf; | |||
data = (char *) pbuf->zc_buf; | |||
len = pbuf->zc_remain; | |||
} | |||
} | |||
@@ -936,7 +936,7 @@ rspamd_http_event_handler(int fd, short what, gpointer ud) | |||
struct rspamd_http_connection *conn = (struct rspamd_http_connection *) ud; | |||
struct rspamd_http_connection_private *priv; | |||
struct _rspamd_http_privbuf *pbuf; | |||
const gchar *d; | |||
const char *d; | |||
gssize r; | |||
GError *err; | |||
@@ -1104,7 +1104,7 @@ rspamd_http_parser_reset(struct rspamd_http_connection *conn) | |||
static struct rspamd_http_connection * | |||
rspamd_http_connection_new_common(struct rspamd_http_context *ctx, | |||
gint fd, | |||
int fd, | |||
rspamd_http_body_handler_t body_handler, | |||
rspamd_http_error_handler_t error_handler, | |||
rspamd_http_finish_handler_t finish_handler, | |||
@@ -1156,7 +1156,7 @@ rspamd_http_connection_new_common(struct rspamd_http_context *ctx, | |||
struct rspamd_http_connection * | |||
rspamd_http_connection_new_server(struct rspamd_http_context *ctx, | |||
gint fd, | |||
int fd, | |||
rspamd_http_body_handler_t body_handler, | |||
rspamd_http_error_handler_t error_handler, | |||
rspamd_http_finish_handler_t finish_handler, | |||
@@ -1172,7 +1172,7 @@ rspamd_http_connection_new_client_socket(struct rspamd_http_context *ctx, | |||
rspamd_http_error_handler_t error_handler, | |||
rspamd_http_finish_handler_t finish_handler, | |||
unsigned opts, | |||
gint fd) | |||
int fd) | |||
{ | |||
return rspamd_http_connection_new_common(ctx, fd, body_handler, | |||
error_handler, finish_handler, opts, RSPAMD_HTTP_CLIENT, 0, NULL); | |||
@@ -1186,7 +1186,7 @@ rspamd_http_connection_new_client(struct rspamd_http_context *ctx, | |||
unsigned opts, | |||
rspamd_inet_addr_t *addr) | |||
{ | |||
gint fd; | |||
int fd; | |||
if (ctx == NULL) { | |||
ctx = rspamd_http_context_default(); | |||
@@ -1243,7 +1243,7 @@ rspamd_http_connection_new_client_keepalive(struct rspamd_http_context *ctx, | |||
rspamd_http_finish_handler_t finish_handler, | |||
unsigned opts, | |||
rspamd_inet_addr_t *addr, | |||
const gchar *host) | |||
const char *host) | |||
{ | |||
struct rspamd_http_connection *conn; | |||
@@ -1336,7 +1336,7 @@ rspamd_http_connection_copy_msg(struct rspamd_http_message *msg, GError **err) | |||
{ | |||
struct rspamd_http_message *new_msg; | |||
struct rspamd_http_header *hdr, *nhdr, *nhdrs, *hcur; | |||
const gchar *old_body; | |||
const char *old_body; | |||
gsize old_len; | |||
struct stat st; | |||
union _rspamd_storage_u *storage; | |||
@@ -1448,7 +1448,7 @@ rspamd_http_connection_copy_msg(struct rspamd_http_message *msg, GError **err) | |||
DL_APPEND(nhdrs, nhdr); | |||
} | |||
gint r; | |||
int r; | |||
khiter_t k = kh_put(rspamd_http_headers_hash, new_msg->headers, | |||
&nhdrs->name, &r); | |||
@@ -1498,7 +1498,7 @@ void rspamd_http_connection_free(struct rspamd_http_connection *conn) | |||
static void | |||
rspamd_http_connection_read_message_common(struct rspamd_http_connection *conn, | |||
gpointer ud, ev_tstamp timeout, | |||
gint flags) | |||
int flags) | |||
{ | |||
struct rspamd_http_connection_private *priv = conn->priv; | |||
struct rspamd_http_message *req; | |||
@@ -1560,21 +1560,21 @@ rspamd_http_connection_encrypt_message( | |||
struct rspamd_http_connection *conn, | |||
struct rspamd_http_message *msg, | |||
struct rspamd_http_connection_private *priv, | |||
guchar *pbody, | |||
guint bodylen, | |||
guchar *pmethod, | |||
guint methodlen, | |||
guint preludelen, | |||
gint hdrcount, | |||
guchar *np, | |||
guchar *mp, | |||
unsigned char *pbody, | |||
unsigned int bodylen, | |||
unsigned char *pmethod, | |||
unsigned int methodlen, | |||
unsigned int preludelen, | |||
int hdrcount, | |||
unsigned char *np, | |||
unsigned char *mp, | |||
struct rspamd_cryptobox_pubkey *peer_key) | |||
{ | |||
struct rspamd_cryptobox_segment *segments; | |||
guchar *crlfp; | |||
const guchar *nm; | |||
gint i, cnt; | |||
guint outlen; | |||
unsigned char *crlfp; | |||
const unsigned char *nm; | |||
int i, cnt; | |||
unsigned int outlen; | |||
struct rspamd_http_header *hdr, *hcur; | |||
enum rspamd_cryptobox_mode mode; | |||
@@ -1669,16 +1669,16 @@ rspamd_http_detach_shared(struct rspamd_http_message *msg) | |||
rspamd_http_message_set_body_from_fstring_steal(msg, cpy_str); | |||
} | |||
gint rspamd_http_message_write_header(const gchar *mime_type, gboolean encrypted, | |||
gchar *repbuf, gsize replen, gsize bodylen, gsize enclen, const gchar *host, | |||
struct rspamd_http_connection *conn, struct rspamd_http_message *msg, | |||
rspamd_fstring_t **buf, | |||
struct rspamd_http_connection_private *priv, | |||
struct rspamd_cryptobox_pubkey *peer_key) | |||
int rspamd_http_message_write_header(const char *mime_type, gboolean encrypted, | |||
char *repbuf, gsize replen, gsize bodylen, gsize enclen, const char *host, | |||
struct rspamd_http_connection *conn, struct rspamd_http_message *msg, | |||
rspamd_fstring_t **buf, | |||
struct rspamd_http_connection_private *priv, | |||
struct rspamd_cryptobox_pubkey *peer_key) | |||
{ | |||
gchar datebuf[64]; | |||
gint meth_len = 0; | |||
const gchar *conn_type = "close"; | |||
char datebuf[64]; | |||
int meth_len = 0; | |||
const char *conn_type = "close"; | |||
if (conn->type == RSPAMD_HTTP_SERVER) { | |||
/* Format reply */ | |||
@@ -1789,7 +1789,7 @@ gint rspamd_http_message_write_header(const gchar *mime_type, gboolean encrypted | |||
GString tmp; | |||
/* Unfortunately, spamc protocol is deadly brain damaged */ | |||
tmp.str = (gchar *) msg->body_buf.begin; | |||
tmp.str = (char *) msg->body_buf.begin; | |||
tmp.len = msg->body_buf.len; | |||
if (rspamd_string_find_eoh(&tmp, &eoh_pos) != -1 && | |||
@@ -2011,21 +2011,21 @@ gint rspamd_http_message_write_header(const gchar *mime_type, gboolean encrypted | |||
static gboolean | |||
rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, | |||
struct rspamd_http_message *msg, | |||
const gchar *host, | |||
const gchar *mime_type, | |||
const char *host, | |||
const char *mime_type, | |||
gpointer ud, | |||
ev_tstamp timeout, | |||
gboolean allow_shared) | |||
{ | |||
struct rspamd_http_connection_private *priv = conn->priv; | |||
struct rspamd_http_header *hdr, *hcur; | |||
gchar repbuf[512], *pbody; | |||
gint i, hdrcount, meth_len = 0, preludelen = 0; | |||
char repbuf[512], *pbody; | |||
int i, hdrcount, meth_len = 0, preludelen = 0; | |||
gsize bodylen, enclen = 0; | |||
rspamd_fstring_t *buf; | |||
gboolean encrypted = FALSE; | |||
guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES], mac[rspamd_cryptobox_MAX_MACBYTES]; | |||
guchar *np = NULL, *mp = NULL, *meth_pos = NULL; | |||
unsigned char nonce[rspamd_cryptobox_MAX_NONCEBYTES], mac[rspamd_cryptobox_MAX_MACBYTES]; | |||
unsigned char *np = NULL, *mp = NULL, *meth_pos = NULL; | |||
struct rspamd_cryptobox_pubkey *peer_key = NULL; | |||
enum rspamd_cryptobox_mode mode; | |||
GError *err; | |||
@@ -2079,7 +2079,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, | |||
} | |||
if (allow_shared) { | |||
gchar tmpbuf[64]; | |||
char tmpbuf[64]; | |||
if (!(msg->flags & RSPAMD_HTTP_FLAG_SHMEM) || | |||
msg->body_buf.c.shared.name == NULL) { | |||
@@ -2103,7 +2103,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, | |||
if (priv->ctx->config.user_agent && conn->type == RSPAMD_HTTP_CLIENT) { | |||
rspamd_ftok_t srch; | |||
khiter_t k; | |||
gint r; | |||
int r; | |||
RSPAMD_FTOK_ASSIGN(&srch, "User-Agent"); | |||
@@ -2111,7 +2111,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, | |||
if (r != 0) { | |||
hdr = g_malloc0(sizeof(struct rspamd_http_header)); | |||
guint vlen = strlen(priv->ctx->config.user_agent); | |||
unsigned int vlen = strlen(priv->ctx->config.user_agent); | |||
hdr->combined = rspamd_fstring_sized_new(srch.len + vlen + 4); | |||
rspamd_printf_fstring(&hdr->combined, "%T: %*s\r\n", &srch, vlen, | |||
priv->ctx->config.user_agent); | |||
@@ -2136,7 +2136,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, | |||
msg->method = HTTP_GET; | |||
} | |||
else { | |||
pbody = (gchar *) msg->body_buf.begin; | |||
pbody = (char *) msg->body_buf.begin; | |||
bodylen = msg->body_buf.len; | |||
msg->method = HTTP_POST; | |||
} | |||
@@ -2219,7 +2219,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, | |||
} | |||
} | |||
else { | |||
pbody = (gchar *) msg->body_buf.begin; | |||
pbody = (char *) msg->body_buf.begin; | |||
bodylen = msg->body_buf.len; | |||
priv->outlen = 3; | |||
@@ -2230,7 +2230,7 @@ rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn, | |||
} | |||
else if (msg->body_buf.len > 0) { | |||
allow_shared = FALSE; | |||
pbody = (gchar *) msg->body_buf.begin; | |||
pbody = (char *) msg->body_buf.begin; | |||
bodylen = msg->body_buf.len; | |||
priv->outlen = 2; | |||
} | |||
@@ -2274,7 +2274,7 @@ priv->out[0].iov_len = buf->len; | |||
/* Buf will be used eventually for encryption */ | |||
if (encrypted) { | |||
gint meth_offset, nonce_offset, mac_offset; | |||
int meth_offset, nonce_offset, mac_offset; | |||
mode = rspamd_keypair_alg(priv->local_key); | |||
ottery_rand_bytes(nonce, rspamd_cryptobox_nonce_bytes(mode)); | |||
@@ -2417,8 +2417,8 @@ return TRUE; | |||
gboolean | |||
rspamd_http_connection_write_message(struct rspamd_http_connection *conn, | |||
struct rspamd_http_message *msg, | |||
const gchar *host, | |||
const gchar *mime_type, | |||
const char *host, | |||
const char *mime_type, | |||
gpointer ud, | |||
ev_tstamp timeout) | |||
{ | |||
@@ -2429,8 +2429,8 @@ rspamd_http_connection_write_message(struct rspamd_http_connection *conn, | |||
gboolean | |||
rspamd_http_connection_write_message_shared(struct rspamd_http_connection *conn, | |||
struct rspamd_http_message *msg, | |||
const gchar *host, | |||
const gchar *mime_type, | |||
const char *host, | |||
const char *mime_type, | |||
gpointer ud, | |||
ev_tstamp timeout) | |||
{ | |||
@@ -2497,7 +2497,7 @@ rspamd_http_message_parse_query(struct rspamd_http_message *msg) | |||
GHashTable *res; | |||
rspamd_fstring_t *key = NULL, *value = NULL; | |||
rspamd_ftok_t *key_tok = NULL, *value_tok = NULL; | |||
const gchar *p, *c, *end; | |||
const char *p, *c, *end; | |||
struct http_parser_url u; | |||
enum { | |||
parse_key, |
@@ -51,7 +51,7 @@ struct rspamd_http_connection_entry; | |||
struct rspamd_keepalive_hash_key; | |||
struct rspamd_storage_shmem { | |||
gchar *shm_name; | |||
char *shm_name; | |||
ref_entry_t ref; | |||
}; | |||
@@ -98,7 +98,7 @@ enum rspamd_http_options { | |||
typedef int (*rspamd_http_body_handler_t)(struct rspamd_http_connection *conn, | |||
struct rspamd_http_message *msg, | |||
const gchar *chunk, | |||
const char *chunk, | |||
gsize len); | |||
typedef void (*rspamd_http_error_handler_t)(struct rspamd_http_connection *conn, | |||
@@ -116,15 +116,15 @@ struct rspamd_http_connection { | |||
rspamd_http_error_handler_t error_handler; | |||
rspamd_http_finish_handler_t finish_handler; | |||
gpointer ud; | |||
const gchar *log_tag; | |||
const char *log_tag; | |||
/* Used for keepalive */ | |||
struct rspamd_keepalive_hash_key *keepalive_hash_key; | |||
gsize max_size; | |||
unsigned opts; | |||
enum rspamd_http_connection_type type; | |||
gboolean finished; | |||
gint fd; | |||
gint ref; | |||
int fd; | |||
int ref; | |||
}; | |||
/** | |||
@@ -139,7 +139,7 @@ struct rspamd_http_connection { | |||
*/ | |||
struct rspamd_http_connection *rspamd_http_connection_new_server( | |||
struct rspamd_http_context *ctx, | |||
gint fd, | |||
int fd, | |||
rspamd_http_body_handler_t body_handler, | |||
rspamd_http_error_handler_t error_handler, | |||
rspamd_http_finish_handler_t finish_handler, | |||
@@ -162,7 +162,7 @@ struct rspamd_http_connection *rspamd_http_connection_new_client_keepalive( | |||
rspamd_http_finish_handler_t finish_handler, | |||
unsigned opts, | |||
rspamd_inet_addr_t *addr, | |||
const gchar *host); | |||
const char *host); | |||
/** | |||
* Creates an ordinary connection using the address specified (if proxy is not set) | |||
@@ -198,7 +198,7 @@ struct rspamd_http_connection *rspamd_http_connection_new_client_socket( | |||
rspamd_http_error_handler_t error_handler, | |||
rspamd_http_finish_handler_t finish_handler, | |||
unsigned opts, | |||
gint fd); | |||
int fd); | |||
/** | |||
* Set key pointed by an opaque pointer | |||
@@ -255,16 +255,16 @@ void rspamd_http_connection_read_message_shared( | |||
gboolean rspamd_http_connection_write_message( | |||
struct rspamd_http_connection *conn, | |||
struct rspamd_http_message *msg, | |||
const gchar *host, | |||
const gchar *mime_type, | |||
const char *host, | |||
const char *mime_type, | |||
gpointer ud, | |||
ev_tstamp timeout); | |||
gboolean rspamd_http_connection_write_message_shared( | |||
struct rspamd_http_connection *conn, | |||
struct rspamd_http_message *msg, | |||
const gchar *host, | |||
const gchar *mime_type, | |||
const char *host, | |||
const char *mime_type, | |||
gpointer ud, | |||
ev_tstamp timeout); | |||
@@ -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. | |||
@@ -90,10 +90,10 @@ rspamd_http_context_new_default(struct rspamd_config *cfg, | |||
struct rspamd_http_context *ctx; | |||
static const int default_kp_size = 1024; | |||
static const gdouble default_rotate_time = 120; | |||
static const gdouble default_keepalive_interval = 65; | |||
static const gchar *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL; | |||
static const gchar *default_server_hdr = "rspamd/" RSPAMD_VERSION_FULL; | |||
static const double default_rotate_time = 120; | |||
static const double default_keepalive_interval = 65; | |||
static const char *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL; | |||
static const char *default_server_hdr = "rspamd/" RSPAMD_VERSION_FULL; | |||
ctx = g_malloc0(sizeof(*ctx)); | |||
ctx->config.kp_cache_size_client = default_kp_size; | |||
@@ -122,7 +122,7 @@ rspamd_http_context_new_default(struct rspamd_config *cfg, | |||
static void | |||
rspamd_http_context_parse_proxy(struct rspamd_http_context *ctx, | |||
const gchar *name, | |||
const char *name, | |||
struct upstream_list **pls) | |||
{ | |||
struct http_parser_url u; | |||
@@ -361,7 +361,7 @@ rspamd_http_context_default(void) | |||
return default_ctx; | |||
} | |||
gint32 | |||
int32_t | |||
rspamd_keep_alive_key_hash(struct rspamd_keepalive_hash_key *k) | |||
{ | |||
rspamd_cryptobox_fast_hash_state_t hst; | |||
@@ -401,7 +401,7 @@ bool rspamd_keep_alive_key_equal(struct rspamd_keepalive_hash_key *k1, | |||
struct rspamd_http_connection * | |||
rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx, | |||
const rspamd_inet_addr_t *addr, | |||
const gchar *host, | |||
const char *host, | |||
bool is_ssl) | |||
{ | |||
struct rspamd_keepalive_hash_key hk, *phk; | |||
@@ -412,7 +412,7 @@ rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx, | |||
} | |||
hk.addr = (rspamd_inet_addr_t *) addr; | |||
hk.host = (gchar *) host; | |||
hk.host = (char *) host; | |||
hk.port = rspamd_inet_address_get_port(addr); | |||
hk.is_ssl = is_ssl; | |||
@@ -427,8 +427,8 @@ rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx, | |||
if (g_queue_get_length(conns) > 0) { | |||
struct rspamd_http_keepalive_cbdata *cbd; | |||
struct rspamd_http_connection *conn; | |||
gint err; | |||
socklen_t len = sizeof(gint); | |||
int err; | |||
socklen_t len = sizeof(int); | |||
cbd = g_queue_pop_head(conns); | |||
rspamd_ev_watcher_stop(ctx->event_loop, &cbd->ev); | |||
@@ -475,7 +475,7 @@ rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx, | |||
const rspamd_inet_addr_t * | |||
rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx, | |||
const gchar *host, | |||
const char *host, | |||
unsigned port, | |||
bool is_ssl) | |||
{ | |||
@@ -486,7 +486,7 @@ rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx, | |||
ctx = rspamd_http_context_default(); | |||
} | |||
hk.host = (gchar *) host; | |||
hk.host = (char *) host; | |||
hk.port = port; | |||
hk.is_ssl = is_ssl; | |||
@@ -507,14 +507,14 @@ rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx, | |||
void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx, | |||
struct rspamd_http_connection *conn, | |||
const rspamd_inet_addr_t *addr, | |||
const gchar *host, | |||
const char *host, | |||
bool is_ssl) | |||
{ | |||
struct rspamd_keepalive_hash_key hk, *phk; | |||
khiter_t k; | |||
hk.addr = (rspamd_inet_addr_t *) addr; | |||
hk.host = (gchar *) host; | |||
hk.host = (char *) host; | |||
hk.is_ssl = is_ssl; | |||
hk.port = rspamd_inet_address_get_port(addr); | |||
@@ -530,7 +530,7 @@ void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx, | |||
else { | |||
/* Create new one */ | |||
GQueue empty_init = G_QUEUE_INIT; | |||
gint r; | |||
int r; | |||
phk = g_malloc(sizeof(*phk)); | |||
phk->conns = empty_init; | |||
@@ -550,7 +550,7 @@ void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx, | |||
} | |||
static void | |||
rspamd_http_keepalive_handler(gint fd, short what, gpointer ud) | |||
rspamd_http_keepalive_handler(int fd, short what, gpointer ud) | |||
{ | |||
struct rspamd_http_keepalive_cbdata *cbdata = | |||
(struct rspamd_http_keepalive_cbdata *) ud; /* | |||
@@ -607,7 +607,7 @@ void rspamd_http_context_push_keepalive(struct rspamd_http_context *ctx, | |||
struct ev_loop *event_loop) | |||
{ | |||
struct rspamd_http_keepalive_cbdata *cbdata; | |||
gdouble timeout = ctx->config.keepalive_interval; | |||
double timeout = ctx->config.keepalive_interval; | |||
g_assert(conn->keepalive_hash_key != NULL); | |||
@@ -33,14 +33,14 @@ struct rspamd_http_message; | |||
struct upstream_ctx; | |||
struct rspamd_http_context_cfg { | |||
guint kp_cache_size_client; | |||
guint kp_cache_size_server; | |||
guint ssl_cache_size; | |||
gdouble keepalive_interval; | |||
gdouble client_key_rotate_time; | |||
const gchar *user_agent; | |||
const gchar *http_proxy; | |||
const gchar *server_hdr; | |||
unsigned int kp_cache_size_client; | |||
unsigned int kp_cache_size_server; | |||
unsigned int ssl_cache_size; | |||
double keepalive_interval; | |||
double client_key_rotate_time; | |||
const char *user_agent; | |||
const char *http_proxy; | |||
const char *server_hdr; | |||
}; | |||
/** | |||
@@ -76,7 +76,7 @@ struct rspamd_http_context *rspamd_http_context_default(void); | |||
*/ | |||
struct rspamd_http_connection *rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx, | |||
const rspamd_inet_addr_t *addr, | |||
const gchar *host, | |||
const char *host, | |||
bool is_ssl); | |||
/** | |||
@@ -88,7 +88,7 @@ struct rspamd_http_connection *rspamd_http_context_check_keepalive(struct rspamd | |||
* @return | |||
*/ | |||
const rspamd_inet_addr_t *rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx, | |||
const gchar *host, | |||
const char *host, | |||
unsigned port, | |||
bool is_ssl); | |||
@@ -101,7 +101,7 @@ const rspamd_inet_addr_t *rspamd_http_context_has_keepalive(struct rspamd_http_c | |||
* @param host | |||
*/ | |||
void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx, struct rspamd_http_connection *conn, | |||
const rspamd_inet_addr_t *addr, const gchar *host, bool is_ssl); | |||
const rspamd_inet_addr_t *addr, const char *host, bool is_ssl); | |||
/** | |||
* Pushes a connection to keepalive pool after client request is finished, |
@@ -47,13 +47,13 @@ rspamd_http_new_message(enum rspamd_http_message_type type) | |||
} | |||
struct rspamd_http_message * | |||
rspamd_http_message_from_url(const gchar *url) | |||
rspamd_http_message_from_url(const char *url) | |||
{ | |||
struct http_parser_url pu; | |||
struct rspamd_http_message *msg; | |||
const gchar *host, *path; | |||
const char *host, *path; | |||
size_t pathlen, urllen; | |||
guint flags = 0; | |||
unsigned int flags = 0; | |||
if (url == NULL) { | |||
return NULL; | |||
@@ -127,11 +127,11 @@ rspamd_http_message_from_url(const gchar *url) | |||
return msg; | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_http_message_get_body(struct rspamd_http_message *msg, | |||
gsize *blen) | |||
{ | |||
const gchar *ret = NULL; | |||
const char *ret = NULL; | |||
if (msg->body_buf.len > 0) { | |||
ret = msg->body_buf.begin; | |||
@@ -169,7 +169,7 @@ rspamd_http_message_shmem_ref(struct rspamd_http_message *msg) | |||
return NULL; | |||
} | |||
guint rspamd_http_message_get_flags(struct rspamd_http_message *msg) | |||
unsigned int rspamd_http_message_get_flags(struct rspamd_http_message *msg) | |||
{ | |||
return msg->flags; | |||
} | |||
@@ -181,7 +181,7 @@ void rspamd_http_message_shmem_unref(struct rspamd_storage_shmem *p) | |||
gboolean | |||
rspamd_http_message_set_body(struct rspamd_http_message *msg, | |||
const gchar *data, gsize len) | |||
const char *data, gsize len) | |||
{ | |||
union _rspamd_storage_u *storage; | |||
storage = &msg->body_buf.c; | |||
@@ -264,9 +264,9 @@ rspamd_http_message_set_body(struct rspamd_http_message *msg, | |||
} | |||
void rspamd_http_message_set_method(struct rspamd_http_message *msg, | |||
const gchar *method) | |||
const char *method) | |||
{ | |||
gint i; | |||
int i; | |||
/* Linear search: not very efficient method */ | |||
for (i = 0; i < HTTP_METHOD_MAX; i++) { | |||
@@ -278,7 +278,7 @@ void rspamd_http_message_set_method(struct rspamd_http_message *msg, | |||
gboolean | |||
rspamd_http_message_set_body_from_fd(struct rspamd_http_message *msg, | |||
gint fd) | |||
int fd) | |||
{ | |||
union _rspamd_storage_u *storage; | |||
struct stat st; | |||
@@ -413,7 +413,7 @@ rspamd_http_message_grow_body(struct rspamd_http_message *msg, gsize len) | |||
gboolean | |||
rspamd_http_message_append_body(struct rspamd_http_message *msg, | |||
const gchar *data, gsize len) | |||
const char *data, gsize len) | |||
{ | |||
union _rspamd_storage_u *storage; | |||
@@ -522,14 +522,14 @@ void rspamd_http_message_set_peer_key(struct rspamd_http_message *msg, | |||
} | |||
void rspamd_http_message_add_header_len(struct rspamd_http_message *msg, | |||
const gchar *name, | |||
const gchar *value, | |||
const char *name, | |||
const char *value, | |||
gsize len) | |||
{ | |||
struct rspamd_http_header *hdr, *found; | |||
guint nlen, vlen; | |||
unsigned int nlen, vlen; | |||
khiter_t k; | |||
gint r; | |||
int r; | |||
if (msg != NULL && name != NULL && value != NULL) { | |||
hdr = g_malloc0(sizeof(struct rspamd_http_header)); | |||
@@ -541,7 +541,7 @@ void rspamd_http_message_add_header_len(struct rspamd_http_message *msg, | |||
} | |||
hdr->combined = rspamd_fstring_sized_new(nlen + vlen + 4); | |||
rspamd_printf_fstring(&hdr->combined, "%s: %*s\r\n", name, (gint) vlen, | |||
rspamd_printf_fstring(&hdr->combined, "%s: %*s\r\n", name, (int) vlen, | |||
value); | |||
hdr->name.begin = hdr->combined->str; | |||
hdr->name.len = nlen; | |||
@@ -564,8 +564,8 @@ void rspamd_http_message_add_header_len(struct rspamd_http_message *msg, | |||
} | |||
void rspamd_http_message_add_header(struct rspamd_http_message *msg, | |||
const gchar *name, | |||
const gchar *value) | |||
const char *name, | |||
const char *value) | |||
{ | |||
if (value) { | |||
rspamd_http_message_add_header_len(msg, name, value, strlen(value)); | |||
@@ -573,13 +573,13 @@ void rspamd_http_message_add_header(struct rspamd_http_message *msg, | |||
} | |||
void rspamd_http_message_add_header_fstr(struct rspamd_http_message *msg, | |||
const gchar *name, | |||
const char *name, | |||
rspamd_fstring_t *value) | |||
{ | |||
struct rspamd_http_header *hdr, *found = NULL; | |||
guint nlen, vlen; | |||
unsigned int nlen, vlen; | |||
khiter_t k; | |||
gint r; | |||
int r; | |||
if (msg != NULL && name != NULL && value != NULL) { | |||
hdr = g_malloc0(sizeof(struct rspamd_http_header)); | |||
@@ -609,11 +609,11 @@ void rspamd_http_message_add_header_fstr(struct rspamd_http_message *msg, | |||
const rspamd_ftok_t * | |||
rspamd_http_message_find_header(struct rspamd_http_message *msg, | |||
const gchar *name) | |||
const char *name) | |||
{ | |||
const rspamd_ftok_t *res = NULL; | |||
rspamd_ftok_t srch; | |||
guint slen = strlen(name); | |||
unsigned int slen = strlen(name); | |||
khiter_t k; | |||
if (msg != NULL) { | |||
@@ -633,15 +633,15 @@ rspamd_http_message_find_header(struct rspamd_http_message *msg, | |||
GPtrArray * | |||
rspamd_http_message_find_header_multiple( | |||
struct rspamd_http_message *msg, | |||
const gchar *name) | |||
const char *name) | |||
{ | |||
GPtrArray *res = NULL; | |||
struct rspamd_http_header *hdr, *cur; | |||
rspamd_ftok_t srch; | |||
khiter_t k; | |||
guint cnt = 0; | |||
unsigned int cnt = 0; | |||
guint slen = strlen(name); | |||
unsigned int slen = strlen(name); | |||
if (msg != NULL) { | |||
srch.begin = name; | |||
@@ -669,11 +669,11 @@ rspamd_http_message_find_header_multiple( | |||
gboolean | |||
rspamd_http_message_remove_header(struct rspamd_http_message *msg, | |||
const gchar *name) | |||
const char *name) | |||
{ | |||
struct rspamd_http_header *hdr, *hcur, *hcurtmp; | |||
gboolean res = FALSE; | |||
guint slen = strlen(name); | |||
unsigned int slen = strlen(name); | |||
rspamd_ftok_t srch; | |||
khiter_t k; | |||
@@ -699,7 +699,7 @@ rspamd_http_message_remove_header(struct rspamd_http_message *msg, | |||
return res; | |||
} | |||
const gchar * | |||
const char * | |||
rspamd_http_message_get_http_host(struct rspamd_http_message *msg, | |||
gsize *hostlen) | |||
{ | |||
@@ -738,7 +738,7 @@ bool rspamd_http_message_is_standard_port(struct rspamd_http_message *msg) | |||
return msg->port == 80; | |||
} | |||
const gchar *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len) | |||
const char *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len) | |||
{ | |||
if (msg->url) { | |||
*len = msg->url->len; |
@@ -83,7 +83,7 @@ void rspamd_http_message_set_peer_key(struct rspamd_http_message *msg, | |||
* @param url | |||
* @return new message or NULL | |||
*/ | |||
struct rspamd_http_message *rspamd_http_message_from_url(const gchar *url); | |||
struct rspamd_http_message *rspamd_http_message_from_url(const char *url); | |||
/** | |||
* Returns body for a message | |||
@@ -91,8 +91,8 @@ struct rspamd_http_message *rspamd_http_message_from_url(const gchar *url); | |||
* @param blen pointer where to save body length | |||
* @return pointer to body start | |||
*/ | |||
const gchar *rspamd_http_message_get_body(struct rspamd_http_message *msg, | |||
gsize *blen); | |||
const char *rspamd_http_message_get_body(struct rspamd_http_message *msg, | |||
gsize *blen); | |||
/** | |||
* Set message's body from the string | |||
@@ -102,7 +102,7 @@ const gchar *rspamd_http_message_get_body(struct rspamd_http_message *msg, | |||
* @return TRUE if a message's body has been set | |||
*/ | |||
gboolean rspamd_http_message_set_body(struct rspamd_http_message *msg, | |||
const gchar *data, gsize len); | |||
const char *data, gsize len); | |||
/** | |||
* Set message's method by name | |||
@@ -110,7 +110,7 @@ gboolean rspamd_http_message_set_body(struct rspamd_http_message *msg, | |||
* @param method | |||
*/ | |||
void rspamd_http_message_set_method(struct rspamd_http_message *msg, | |||
const gchar *method); | |||
const char *method); | |||
/** | |||
* Maps fd as message's body | |||
@@ -119,7 +119,7 @@ void rspamd_http_message_set_method(struct rspamd_http_message *msg, | |||
* @return TRUE if a message's body has been set | |||
*/ | |||
gboolean rspamd_http_message_set_body_from_fd(struct rspamd_http_message *msg, | |||
gint fd); | |||
int fd); | |||
/** | |||
* Uses rspamd_fstring_t as message's body, string is consumed by this operation | |||
@@ -147,7 +147,7 @@ gboolean rspamd_http_message_set_body_from_fstring_copy(struct rspamd_http_messa | |||
* @return TRUE if a message's body has been set | |||
*/ | |||
gboolean rspamd_http_message_append_body(struct rspamd_http_message *msg, | |||
const gchar *data, gsize len); | |||
const char *data, gsize len); | |||
/** | |||
* Append a header to http message | |||
@@ -156,16 +156,16 @@ gboolean rspamd_http_message_append_body(struct rspamd_http_message *msg, | |||
* @param value | |||
*/ | |||
void rspamd_http_message_add_header(struct rspamd_http_message *msg, | |||
const gchar *name, | |||
const gchar *value); | |||
const char *name, | |||
const char *value); | |||
void rspamd_http_message_add_header_len(struct rspamd_http_message *msg, | |||
const gchar *name, | |||
const gchar *value, | |||
const char *name, | |||
const char *value, | |||
gsize len); | |||
void rspamd_http_message_add_header_fstr(struct rspamd_http_message *msg, | |||
const gchar *name, | |||
const char *name, | |||
rspamd_fstring_t *value); | |||
/** | |||
@@ -175,7 +175,7 @@ void rspamd_http_message_add_header_fstr(struct rspamd_http_message *msg, | |||
*/ | |||
const rspamd_ftok_t *rspamd_http_message_find_header( | |||
struct rspamd_http_message *msg, | |||
const gchar *name); | |||
const char *name); | |||
/** | |||
* Search for a header that has multiple values | |||
@@ -185,7 +185,7 @@ const rspamd_ftok_t *rspamd_http_message_find_header( | |||
*/ | |||
GPtrArray *rspamd_http_message_find_header_multiple( | |||
struct rspamd_http_message *msg, | |||
const gchar *name); | |||
const char *name); | |||
/** | |||
* Remove specific header from a message | |||
@@ -194,7 +194,7 @@ GPtrArray *rspamd_http_message_find_header_multiple( | |||
* @return | |||
*/ | |||
gboolean rspamd_http_message_remove_header(struct rspamd_http_message *msg, | |||
const gchar *name); | |||
const char *name); | |||
/** | |||
* Free HTTP message | |||
@@ -228,7 +228,7 @@ void rspamd_http_message_shmem_unref(struct rspamd_storage_shmem *p); | |||
* @param msg | |||
* @return | |||
*/ | |||
guint rspamd_http_message_get_flags(struct rspamd_http_message *msg); | |||
unsigned int rspamd_http_message_get_flags(struct rspamd_http_message *msg); | |||
/** | |||
* Returns an HTTP hostname for a message, derived from a header if it has it | |||
@@ -237,8 +237,8 @@ guint rspamd_http_message_get_flags(struct rspamd_http_message *msg); | |||
* @param hostlen output of the host length | |||
* @return | |||
*/ | |||
const gchar *rspamd_http_message_get_http_host(struct rspamd_http_message *msg, | |||
gsize *hostlen); | |||
const char *rspamd_http_message_get_http_host(struct rspamd_http_message *msg, | |||
gsize *hostlen); | |||
/** | |||
* Returns true if a message has standard port (80 or 443 for https) | |||
@@ -247,7 +247,7 @@ const gchar *rspamd_http_message_get_http_host(struct rspamd_http_message *msg, | |||
*/ | |||
bool rspamd_http_message_is_standard_port(struct rspamd_http_message *msg); | |||
const gchar *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len); | |||
const char *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len); | |||
#ifdef __cplusplus | |||
} |
@@ -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, | |||
@@ -54,20 +54,20 @@ struct rspamd_http_message { | |||
struct _rspamd_body_buf_s { | |||
/* Data start */ | |||
const gchar *begin; | |||
const char *begin; | |||
/* Data len */ | |||
gsize len; | |||
/* Allocated len */ | |||
gsize allocated_len; | |||
/* Data buffer (used to write data inside) */ | |||
gchar *str; | |||
char *str; | |||
/* Internal storage */ | |||
union _rspamd_storage_u { | |||
rspamd_fstring_t *normal; | |||
struct _rspamd_storage_shared_s { | |||
struct rspamd_storage_shmem *name; | |||
gint shm_fd; | |||
int shm_fd; | |||
} shared; | |||
} c; | |||
} body_buf; | |||
@@ -77,21 +77,21 @@ struct rspamd_http_message { | |||
time_t last_modified; | |||
unsigned port; | |||
int type; | |||
gint code; | |||
int code; | |||
enum http_method method; | |||
gint flags; | |||
int flags; | |||
ref_entry_t ref; | |||
}; | |||
struct rspamd_keepalive_hash_key { | |||
rspamd_inet_addr_t *addr; | |||
gchar *host; | |||
char *host; | |||
gboolean is_ssl; | |||
unsigned port; | |||
GQueue conns; | |||
}; | |||
gint32 rspamd_keep_alive_key_hash(struct rspamd_keepalive_hash_key *k); | |||
int32_t rspamd_keep_alive_key_hash(struct rspamd_keepalive_hash_key *k); | |||
bool rspamd_keep_alive_key_equal(struct rspamd_keepalive_hash_key *k1, | |||
struct rspamd_keepalive_hash_key *k2); |
@@ -35,8 +35,8 @@ enum http_magic_type { | |||
}; | |||
static const struct _rspamd_http_magic { | |||
const gchar *ext; | |||
const gchar *ct; | |||
const char *ext; | |||
const char *ct; | |||
} http_file_types[] = { | |||
[HTTP_MAGIC_PLAIN] = {"txt", "text/plain"}, | |||
[HTTP_MAGIC_HTML] = {"html", "text/html"}, | |||
@@ -101,11 +101,11 @@ rspamd_http_router_error_handler(struct rspamd_http_connection *conn, | |||
} | |||
} | |||
static const gchar * | |||
rspamd_http_router_detect_ct(const gchar *path) | |||
static const char * | |||
rspamd_http_router_detect_ct(const char *path) | |||
{ | |||
const gchar *dot; | |||
guint i; | |||
const char *dot; | |||
unsigned int i; | |||
dot = strrchr(path, '.'); | |||
if (dot == NULL) { | |||
@@ -123,7 +123,7 @@ rspamd_http_router_detect_ct(const gchar *path) | |||
} | |||
static gboolean | |||
rspamd_http_router_is_subdir(const gchar *parent, const gchar *sub) | |||
rspamd_http_router_is_subdir(const char *parent, const char *sub) | |||
{ | |||
if (parent == NULL || sub == NULL || *parent == '\0') { | |||
return FALSE; | |||
@@ -150,8 +150,8 @@ rspamd_http_router_try_file(struct rspamd_http_connection_entry *entry, | |||
rspamd_ftok_t *lookup, gboolean expand_path) | |||
{ | |||
struct stat st; | |||
gint fd; | |||
gchar filebuf[PATH_MAX], realbuf[PATH_MAX], *dir; | |||
int fd; | |||
char filebuf[PATH_MAX], realbuf[PATH_MAX], *dir; | |||
struct rspamd_http_message *reply_msg; | |||
rspamd_snprintf(filebuf, sizeof(filebuf), "%s%c%T", | |||
@@ -256,10 +256,10 @@ rspamd_http_router_finish_handler(struct rspamd_http_connection *conn, | |||
rspamd_ftok_t lookup; | |||
const rspamd_ftok_t *encoding; | |||
struct http_parser_url u; | |||
guint i; | |||
unsigned int i; | |||
rspamd_regexp_t *re; | |||
struct rspamd_http_connection_router *router; | |||
gchar *pathbuf = NULL; | |||
char *pathbuf = NULL; | |||
G_STATIC_ASSERT(sizeof(rspamd_http_router_handler_t) == | |||
sizeof(gpointer)); | |||
@@ -439,7 +439,7 @@ void rspamd_http_router_set_key(struct rspamd_http_connection_router *router, | |||
} | |||
void rspamd_http_router_add_path(struct rspamd_http_connection_router *router, | |||
const gchar *path, rspamd_http_router_handler_t handler) | |||
const char *path, rspamd_http_router_handler_t handler) | |||
{ | |||
gpointer ptr; | |||
rspamd_ftok_t *key; | |||
@@ -466,7 +466,7 @@ void rspamd_http_router_set_unknown_handler(struct rspamd_http_connection_router | |||
} | |||
void rspamd_http_router_add_header(struct rspamd_http_connection_router *router, | |||
const gchar *name, const gchar *value) | |||
const char *name, const char *value) | |||
{ | |||
if (name != NULL && value != NULL && router != NULL) { | |||
g_hash_table_replace(router->response_headers, g_strdup(name), | |||
@@ -504,7 +504,7 @@ void rspamd_http_router_add_regexp(struct rspamd_http_connection_router *router, | |||
} | |||
void rspamd_http_router_handle_socket(struct rspamd_http_connection_router *router, | |||
gint fd, gpointer ud) | |||
int fd, gpointer ud) | |||
{ | |||
struct rspamd_http_connection_entry *conn; | |||
@@ -532,7 +532,7 @@ void rspamd_http_router_free(struct rspamd_http_connection_router *router) | |||
{ | |||
struct rspamd_http_connection_entry *conn, *tmp; | |||
rspamd_regexp_t *re; | |||
guint i; | |||
unsigned int i; | |||
if (router) { | |||
DL_FOREACH_SAFE(router->conns, conn, tmp) |
@@ -53,7 +53,7 @@ struct rspamd_http_connection_router { | |||
ev_tstamp timeout; | |||
struct ev_loop *event_loop; | |||
struct rspamd_http_context *ctx; | |||
gchar *default_fs_path; | |||
char *default_fs_path; | |||
rspamd_http_router_handler_t unknown_method_handler; | |||
struct rspamd_cryptobox_keypair *key; | |||
rspamd_http_router_error_handler_t error_handler; | |||
@@ -87,7 +87,7 @@ void rspamd_http_router_set_key(struct rspamd_http_connection_router *router, | |||
* Add new path to the router | |||
*/ | |||
void rspamd_http_router_add_path(struct rspamd_http_connection_router *router, | |||
const gchar *path, rspamd_http_router_handler_t handler); | |||
const char *path, rspamd_http_router_handler_t handler); | |||
/** | |||
* Add custom header to append to router replies | |||
@@ -96,7 +96,7 @@ void rspamd_http_router_add_path(struct rspamd_http_connection_router *router, | |||
* @param value | |||
*/ | |||
void rspamd_http_router_add_header(struct rspamd_http_connection_router *router, | |||
const gchar *name, const gchar *value); | |||
const char *name, const char *value); | |||
/** | |||
* Sets method to handle unknown request methods | |||
@@ -133,7 +133,7 @@ void rspamd_http_router_add_regexp(struct rspamd_http_connection_router *router, | |||
*/ | |||
void rspamd_http_router_handle_socket( | |||
struct rspamd_http_connection_router *router, | |||
gint fd, | |||
int fd, | |||
gpointer ud); | |||
/** |
@@ -18,23 +18,23 @@ | |||
#include "libutil/printf.h" | |||
#include "libutil/util.h" | |||
static const gchar *http_week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | |||
static const gchar *http_month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | |||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | |||
static const char *http_week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | |||
static const char *http_month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | |||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | |||
/* | |||
* Obtained from nginx | |||
* Copyright (C) Igor Sysoev | |||
*/ | |||
static guint mday[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | |||
static unsigned int mday[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | |||
time_t | |||
rspamd_http_parse_date(const gchar *header, gsize len) | |||
rspamd_http_parse_date(const char *header, gsize len) | |||
{ | |||
const gchar *p, *end; | |||
gint month; | |||
guint day, year, hour, min, sec; | |||
guint64 time; | |||
const char *p, *end; | |||
int month; | |||
unsigned int day, year, hour, min, sec; | |||
uint64_t time; | |||
enum { | |||
no = 0, | |||
rfc822, /* Tue, 10 Nov 2002 23:50:13 */ | |||
@@ -257,7 +257,7 @@ rspamd_http_parse_date(const gchar *header, gsize len) | |||
/* Gauss' formula for Gregorian days since March 1, 1 BC */ | |||
time = (guint64) ( | |||
time = (uint64_t) ( | |||
/* days in years including leap years since March 1, 1 BC */ | |||
365 * year + year / 4 - year / 100 + year / 400 | |||
@@ -282,7 +282,7 @@ rspamd_http_parse_date(const gchar *header, gsize len) | |||
return (time_t) time; | |||
} | |||
glong rspamd_http_date_format(gchar *buf, gsize len, time_t time) | |||
glong rspamd_http_date_format(char *buf, gsize len, time_t time) | |||
{ | |||
struct tm tms; | |||
@@ -29,7 +29,7 @@ extern "C" { | |||
* @param len length of header | |||
* @return time_t or (time_t)-1 in case of error | |||
*/ | |||
time_t rspamd_http_parse_date(const gchar *header, gsize len); | |||
time_t rspamd_http_parse_date(const char *header, gsize len); | |||
/** | |||
* Prints HTTP date from `time` to `buf` using standard HTTP date format | |||
@@ -38,7 +38,7 @@ time_t rspamd_http_parse_date(const gchar *header, gsize len); | |||
* @param time time in unix seconds | |||
* @return number of bytes written | |||
*/ | |||
glong rspamd_http_date_format(gchar *buf, gsize len, time_t time); | |||
glong rspamd_http_date_format(char *buf, gsize len, time_t time); | |||
#ifdef __cplusplus | |||
} |
@@ -24,10 +24,10 @@ enum rspamd_log_flags { | |||
}; | |||
typedef struct rspamd_logger_s rspamd_logger_t; | |||
typedef bool (*rspamd_log_func_t)(const gchar *module, const gchar *id, | |||
const gchar *function, | |||
gint level_flags, | |||
const gchar *message, | |||
typedef bool (*rspamd_log_func_t)(const char *module, const char *id, | |||
const char *function, | |||
int level_flags, | |||
const char *message, | |||
gsize mlen, | |||
rspamd_logger_t *logger, | |||
gpointer arg); | |||
@@ -68,7 +68,7 @@ struct rspamd_logger_funcs { | |||
* This logger is also used as an emergency logger | |||
* @return new rspamd logger object | |||
*/ | |||
rspamd_logger_t *rspamd_log_open_emergency(rspamd_mempool_t *pool, gint flags); | |||
rspamd_logger_t *rspamd_log_open_emergency(rspamd_mempool_t *pool, int flags); | |||
/** | |||
* Open specific (configured logging) | |||
@@ -80,7 +80,7 @@ rspamd_logger_t *rspamd_log_open_emergency(rspamd_mempool_t *pool, gint flags); | |||
*/ | |||
rspamd_logger_t *rspamd_log_open_specific(rspamd_mempool_t *pool, | |||
struct rspamd_config *config, | |||
const gchar *ptype, | |||
const char *ptype, | |||
uid_t uid, gid_t gid); | |||
/** | |||
@@ -88,15 +88,15 @@ rspamd_logger_t *rspamd_log_open_specific(rspamd_mempool_t *pool, | |||
* @param logger | |||
* @param level | |||
*/ | |||
void rspamd_log_set_log_level(rspamd_logger_t *logger, gint level); | |||
gint rspamd_log_get_log_level(rspamd_logger_t *logger); | |||
const gchar *rspamd_get_log_severity_string(gint level_flags); | |||
void rspamd_log_set_log_level(rspamd_logger_t *logger, int level); | |||
int rspamd_log_get_log_level(rspamd_logger_t *logger); | |||
const char *rspamd_get_log_severity_string(int level_flags); | |||
/** | |||
* Set log flags (from enum rspamd_log_flags) | |||
* @param logger | |||
* @param flags | |||
*/ | |||
void rspamd_log_set_log_flags(rspamd_logger_t *logger, gint flags); | |||
void rspamd_log_set_log_flags(rspamd_logger_t *logger, int flags); | |||
/** | |||
* Close log file or destroy other structures | |||
@@ -122,40 +122,40 @@ void rspamd_log_on_fork(GQuark ptype, struct rspamd_config *cfg, | |||
/** | |||
* Log function that is compatible for glib messages | |||
*/ | |||
void rspamd_glib_log_function(const gchar *log_domain, | |||
void rspamd_glib_log_function(const char *log_domain, | |||
GLogLevelFlags log_level, | |||
const gchar *message, | |||
const char *message, | |||
gpointer arg); | |||
/** | |||
* Log function for printing glib assertions | |||
*/ | |||
void rspamd_glib_printerr_function(const gchar *message); | |||
void rspamd_glib_printerr_function(const char *message); | |||
/** | |||
* Function with variable number of arguments support | |||
*/ | |||
bool rspamd_common_log_function(rspamd_logger_t *logger, | |||
gint level_flags, | |||
const gchar *module, const gchar *id, | |||
const gchar *function, const gchar *fmt, ...); | |||
int level_flags, | |||
const char *module, const char *id, | |||
const char *function, const char *fmt, ...); | |||
bool rspamd_common_logv(rspamd_logger_t *logger, gint level_flags, | |||
const gchar *module, const gchar *id, const gchar *function, | |||
const gchar *fmt, va_list args); | |||
bool rspamd_common_logv(rspamd_logger_t *logger, int level_flags, | |||
const char *module, const char *id, const char *function, | |||
const char *fmt, va_list args); | |||
/** | |||
* Add new logging module, returns module ID | |||
* @param mod | |||
* @return | |||
*/ | |||
gint rspamd_logger_add_debug_module(const gchar *mod); | |||
int rspamd_logger_add_debug_module(const char *mod); | |||
/* | |||
* Macro to use for faster debug modules | |||
*/ | |||
#define INIT_LOG_MODULE(mname) \ | |||
static gint rspamd_##mname##_log_id = -1; \ | |||
static int rspamd_##mname##_log_id = -1; \ | |||
RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) \ | |||
{ \ | |||
rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \ | |||
@@ -163,14 +163,14 @@ gint rspamd_logger_add_debug_module(const gchar *mod); | |||
#define INIT_LOG_MODULE_PUBLIC(mname) \ | |||
gint rspamd_##mname##_log_id = -1; \ | |||
int rspamd_##mname##_log_id = -1; \ | |||
RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) \ | |||
{ \ | |||
rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \ | |||
} | |||
#define EXTERN_LOG_MODULE_DEF(mname) \ | |||
extern gint rspamd_##mname##_log_id | |||
extern int rspamd_##mname##_log_id | |||
void rspamd_logger_configure_modules(GHashTable *mods_enabled); | |||
@@ -178,30 +178,30 @@ void rspamd_logger_configure_modules(GHashTable *mods_enabled); | |||
* Conditional debug function | |||
*/ | |||
bool rspamd_conditional_debug(rspamd_logger_t *logger, | |||
rspamd_inet_addr_t *addr, const gchar *module, const gchar *id, | |||
const gchar *function, const gchar *fmt, ...); | |||
rspamd_inet_addr_t *addr, const char *module, const char *id, | |||
const char *function, const char *fmt, ...); | |||
bool rspamd_conditional_debug_fast(rspamd_logger_t *logger, | |||
rspamd_inet_addr_t *addr, | |||
gint mod_id, | |||
const gchar *module, const gchar *id, | |||
const gchar *function, const gchar *fmt, ...); | |||
int mod_id, | |||
const char *module, const char *id, | |||
const char *function, const char *fmt, ...); | |||
bool rspamd_conditional_debug_fast_num_id(rspamd_logger_t *logger, | |||
rspamd_inet_addr_t *addr, | |||
gint mod_id, | |||
const gchar *module, guint64 id, | |||
const gchar *function, const gchar *fmt, ...); | |||
int mod_id, | |||
const char *module, uint64_t id, | |||
const char *function, const char *fmt, ...); | |||
gboolean rspamd_logger_need_log(rspamd_logger_t *rspamd_log, | |||
GLogLevelFlags log_level, | |||
gint module_id); | |||
int module_id); | |||
/** | |||
* Function with variable number of arguments support that uses static default logger | |||
*/ | |||
bool rspamd_default_log_function(gint level_flags, | |||
const gchar *module, const gchar *id, | |||
const gchar *function, | |||
const gchar *fmt, | |||
bool rspamd_default_log_function(int level_flags, | |||
const char *module, const char *id, | |||
const char *function, | |||
const char *fmt, | |||
...); | |||
/** | |||
@@ -211,10 +211,10 @@ bool rspamd_default_log_function(gint level_flags, | |||
* @param fmt | |||
* @param args | |||
*/ | |||
bool rspamd_default_logv(gint level_flags, | |||
const gchar *module, const gchar *id, | |||
const gchar *function, | |||
const gchar *fmt, | |||
bool rspamd_default_logv(int level_flags, | |||
const char *module, const char *id, | |||
const char *function, | |||
const char *fmt, | |||
va_list args); | |||
/** | |||
@@ -234,7 +234,7 @@ void rspamd_log_nodebug(rspamd_logger_t *logger); | |||
* 2 - info messages | |||
* 3 - debug messages | |||
*/ | |||
const guint64 *rspamd_log_counters(rspamd_logger_t *logger); | |||
const uint64_t *rspamd_log_counters(rspamd_logger_t *logger); | |||
/** | |||
* Returns errors ring buffer as ucl array | |||
@@ -254,7 +254,7 @@ struct rspamd_logger_funcs *rspamd_logger_set_log_function(rspamd_logger_t *logg | |||
/* Typical functions */ | |||
extern guint rspamd_task_log_id; | |||
extern unsigned int rspamd_task_log_id; | |||
#ifdef __cplusplus | |||
#define RSPAMD_LOG_FUNC __func__ | |||
#else |
@@ -27,9 +27,9 @@ static rspamd_logger_t *default_logger = NULL; | |||
static rspamd_logger_t *emergency_logger = NULL; | |||
static struct rspamd_log_modules *log_modules = NULL; | |||
static const gchar lf_chr = '\n'; | |||
static const char lf_chr = '\n'; | |||
guint rspamd_task_log_id = (guint) -1; | |||
unsigned int rspamd_task_log_id = (unsigned int) -1; | |||
RSPAMD_CONSTRUCTOR(rspamd_task_log_init) | |||
{ | |||
rspamd_task_log_id = rspamd_logger_add_debug_module("task"); | |||
@@ -47,7 +47,7 @@ rspamd_log_emergency_logger(void) | |||
return emergency_logger; | |||
} | |||
void rspamd_log_set_log_level(rspamd_logger_t *logger, gint level) | |||
void rspamd_log_set_log_level(rspamd_logger_t *logger, int level) | |||
{ | |||
if (logger == NULL) { | |||
logger = default_logger; | |||
@@ -56,7 +56,7 @@ void rspamd_log_set_log_level(rspamd_logger_t *logger, gint level) | |||
logger->log_level = level; | |||
} | |||
gint rspamd_log_get_log_level(rspamd_logger_t *logger) | |||
int rspamd_log_get_log_level(rspamd_logger_t *logger) | |||
{ | |||
if (logger == NULL) { | |||
logger = default_logger; | |||
@@ -65,7 +65,7 @@ gint rspamd_log_get_log_level(rspamd_logger_t *logger) | |||
return logger->log_level; | |||
} | |||
void rspamd_log_set_log_flags(rspamd_logger_t *logger, gint flags) | |||
void rspamd_log_set_log_flags(rspamd_logger_t *logger, int flags) | |||
{ | |||
g_assert(logger != NULL); | |||
@@ -139,7 +139,7 @@ rspamd_emergency_logger_dtor(gpointer d) | |||
} | |||
rspamd_logger_t * | |||
rspamd_log_open_emergency(rspamd_mempool_t *pool, gint flags) | |||
rspamd_log_open_emergency(rspamd_mempool_t *pool, int flags) | |||
{ | |||
rspamd_logger_t *logger; | |||
GError *err = NULL; | |||
@@ -185,7 +185,7 @@ rspamd_log_open_emergency(rspamd_mempool_t *pool, gint flags) | |||
rspamd_logger_t * | |||
rspamd_log_open_specific(rspamd_mempool_t *pool, | |||
struct rspamd_config *cfg, | |||
const gchar *ptype, | |||
const char *ptype, | |||
uid_t uid, gid_t gid) | |||
{ | |||
rspamd_logger_t *logger; | |||
@@ -314,7 +314,7 @@ void rspamd_log_on_fork(GQuark ptype, struct rspamd_config *cfg, | |||
inline gboolean | |||
rspamd_logger_need_log(rspamd_logger_t *rspamd_log, GLogLevelFlags log_level, | |||
gint module_id) | |||
int module_id) | |||
{ | |||
g_assert(rspamd_log != NULL); | |||
@@ -330,15 +330,15 @@ rspamd_logger_need_log(rspamd_logger_t *rspamd_log, GLogLevelFlags log_level, | |||
return FALSE; | |||
} | |||
static gchar * | |||
rspamd_log_encrypt_message(const gchar *begin, const gchar *end, gsize *enc_len, | |||
static char * | |||
rspamd_log_encrypt_message(const char *begin, const char *end, gsize *enc_len, | |||
rspamd_logger_t *rspamd_log) | |||
{ | |||
guchar *out; | |||
gchar *b64; | |||
guchar *p, *nonce, *mac; | |||
const guchar *comp; | |||
guint len, inlen; | |||
unsigned char *out; | |||
char *b64; | |||
unsigned char *p, *nonce, *mac; | |||
const unsigned char *comp; | |||
unsigned int len, inlen; | |||
g_assert(end > begin); | |||
/* base64 (pubkey | nonce | message) */ | |||
@@ -370,10 +370,10 @@ rspamd_log_encrypt_message(const gchar *begin, const gchar *end, gsize *enc_len, | |||
static void | |||
rspamd_log_write_ringbuffer(rspamd_logger_t *rspamd_log, | |||
const gchar *module, const gchar *id, | |||
const gchar *data, glong len) | |||
const char *module, const char *id, | |||
const char *data, glong len) | |||
{ | |||
guint32 row_num; | |||
uint32_t row_num; | |||
struct rspamd_logger_error_log *elog; | |||
struct rspamd_logger_error_elt *elt; | |||
@@ -391,7 +391,7 @@ rspamd_log_write_ringbuffer(rspamd_logger_t *rspamd_log, | |||
#endif | |||
if (row_num < elog->max_elts) { | |||
elt = (struct rspamd_logger_error_elt *) (((guchar *) elog->elts) + | |||
elt = (struct rspamd_logger_error_elt *) (((unsigned char *) elog->elts) + | |||
(sizeof(*elt) + elog->elt_len) * row_num); | |||
g_atomic_int_set(&elt->completed, 0); | |||
} | |||
@@ -423,14 +423,14 @@ rspamd_log_write_ringbuffer(rspamd_logger_t *rspamd_log, | |||
g_atomic_int_set(&elt->completed, 1); | |||
} | |||
bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags, | |||
const gchar *module, const gchar *id, const gchar *function, | |||
const gchar *fmt, va_list args) | |||
bool rspamd_common_logv(rspamd_logger_t *rspamd_log, int level_flags, | |||
const char *module, const char *id, const char *function, | |||
const char *fmt, va_list args) | |||
{ | |||
gchar *end; | |||
gint level = level_flags & (RSPAMD_LOG_LEVEL_MASK & G_LOG_LEVEL_MASK), mod_id; | |||
char *end; | |||
int level = level_flags & (RSPAMD_LOG_LEVEL_MASK & G_LOG_LEVEL_MASK), mod_id; | |||
bool ret = false; | |||
gchar logbuf[RSPAMD_LOGBUF_SIZE], *log_line; | |||
char logbuf[RSPAMD_LOGBUF_SIZE], *log_line; | |||
gsize nescaped; | |||
if (G_UNLIKELY(rspamd_log == NULL)) { | |||
@@ -443,7 +443,7 @@ bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags, | |||
/* Just fprintf message to stderr */ | |||
if (level >= G_LOG_LEVEL_INFO) { | |||
end = rspamd_vsnprintf(logbuf, sizeof(logbuf), fmt, args); | |||
rspamd_fprintf(stderr, "%*s\n", (gint) (end - log_line), | |||
rspamd_fprintf(stderr, "%*s\n", (int) (end - log_line), | |||
log_line); | |||
} | |||
} | |||
@@ -461,7 +461,7 @@ bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags, | |||
if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_RSPAMADM)) { | |||
if ((nescaped = rspamd_log_line_need_escape(logbuf, end - logbuf)) != 0) { | |||
gsize unescaped_len = end - logbuf; | |||
gchar *logbuf_escaped = g_alloca(unescaped_len + nescaped * 4); | |||
char *logbuf_escaped = g_alloca(unescaped_len + nescaped * 4); | |||
log_line = logbuf_escaped; | |||
end = rspamd_log_line_hex_escape(logbuf, unescaped_len, | |||
@@ -470,7 +470,7 @@ bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags, | |||
} | |||
if ((level_flags & RSPAMD_LOG_ENCRYPTED) && rspamd_log->pk) { | |||
gchar *encrypted; | |||
char *encrypted; | |||
gsize enc_len; | |||
encrypted = rspamd_log_encrypt_message(log_line, end, &enc_len, | |||
@@ -522,10 +522,10 @@ bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags, | |||
* This log functions select real logger and write message if level is less or equal to configured log level | |||
*/ | |||
bool rspamd_common_log_function(rspamd_logger_t *rspamd_log, | |||
gint level_flags, | |||
const gchar *module, const gchar *id, | |||
const gchar *function, | |||
const gchar *fmt, | |||
int level_flags, | |||
const char *module, const char *id, | |||
const char *function, | |||
const char *fmt, | |||
...) | |||
{ | |||
va_list vp; | |||
@@ -537,16 +537,16 @@ bool rspamd_common_log_function(rspamd_logger_t *rspamd_log, | |||
return ret; | |||
} | |||
bool rspamd_default_logv(gint level_flags, const gchar *module, const gchar *id, | |||
const gchar *function, | |||
const gchar *fmt, va_list args) | |||
bool rspamd_default_logv(int level_flags, const char *module, const char *id, | |||
const char *function, | |||
const char *fmt, va_list args) | |||
{ | |||
return rspamd_common_logv(NULL, level_flags, module, id, function, fmt, args); | |||
} | |||
bool rspamd_default_log_function(gint level_flags, | |||
const gchar *module, const gchar *id, | |||
const gchar *function, const gchar *fmt, ...) | |||
bool rspamd_default_log_function(int level_flags, | |||
const char *module, const char *id, | |||
const char *function, const char *fmt, ...) | |||
{ | |||
va_list vp; | |||
@@ -566,13 +566,13 @@ bool rspamd_default_log_function(gint level_flags, | |||
* Write log line depending on ip | |||
*/ | |||
bool rspamd_conditional_debug(rspamd_logger_t *rspamd_log, | |||
rspamd_inet_addr_t *addr, const gchar *module, const gchar *id, | |||
const gchar *function, const gchar *fmt, ...) | |||
rspamd_inet_addr_t *addr, const char *module, const char *id, | |||
const char *function, const char *fmt, ...) | |||
{ | |||
static gchar logbuf[LOGBUF_LEN]; | |||
static char logbuf[LOGBUF_LEN]; | |||
va_list vp; | |||
gchar *end; | |||
gint mod_id; | |||
char *end; | |||
int mod_id; | |||
if (rspamd_log == NULL) { | |||
rspamd_log = default_logger; | |||
@@ -607,12 +607,12 @@ bool rspamd_conditional_debug(rspamd_logger_t *rspamd_log, | |||
bool rspamd_conditional_debug_fast(rspamd_logger_t *rspamd_log, | |||
rspamd_inet_addr_t *addr, | |||
gint mod_id, const gchar *module, const gchar *id, | |||
const gchar *function, const gchar *fmt, ...) | |||
int mod_id, const char *module, const char *id, | |||
const char *function, const char *fmt, ...) | |||
{ | |||
static gchar logbuf[LOGBUF_LEN]; | |||
static char logbuf[LOGBUF_LEN]; | |||
va_list vp; | |||
gchar *end; | |||
char *end; | |||
if (rspamd_log == NULL) { | |||
rspamd_log = default_logger; | |||
@@ -644,12 +644,12 @@ bool rspamd_conditional_debug_fast(rspamd_logger_t *rspamd_log, | |||
bool rspamd_conditional_debug_fast_num_id(rspamd_logger_t *rspamd_log, | |||
rspamd_inet_addr_t *addr, | |||
gint mod_id, const gchar *module, guint64 id, | |||
const gchar *function, const gchar *fmt, ...) | |||
int mod_id, const char *module, uint64_t id, | |||
const char *function, const char *fmt, ...) | |||
{ | |||
static gchar logbuf[LOGBUF_LEN], idbuf[64]; | |||
static char logbuf[LOGBUF_LEN], idbuf[64]; | |||
va_list vp; | |||
gchar *end; | |||
char *end; | |||
if (rspamd_log == NULL) { | |||
rspamd_log = default_logger; | |||
@@ -683,9 +683,9 @@ bool rspamd_conditional_debug_fast_num_id(rspamd_logger_t *rspamd_log, | |||
/** | |||
* Wrapper for glib logger | |||
*/ | |||
void rspamd_glib_log_function(const gchar *log_domain, | |||
void rspamd_glib_log_function(const char *log_domain, | |||
GLogLevelFlags log_level, | |||
const gchar *message, | |||
const char *message, | |||
gpointer arg) | |||
{ | |||
rspamd_logger_t *rspamd_log = (rspamd_logger_t *) arg; | |||
@@ -702,7 +702,7 @@ void rspamd_glib_log_function(const gchar *log_domain, | |||
} | |||
} | |||
void rspamd_glib_printerr_function(const gchar *message) | |||
void rspamd_glib_printerr_function(const char *message) | |||
{ | |||
rspamd_common_log_function(NULL, G_LOG_LEVEL_CRITICAL, "glib", | |||
NULL, G_STRFUNC, | |||
@@ -725,7 +725,7 @@ void rspamd_log_nodebug(rspamd_logger_t *rspamd_log) | |||
rspamd_log->is_debug = FALSE; | |||
} | |||
const guint64 * | |||
const uint64_t * | |||
rspamd_log_counters(rspamd_logger_t *logger) | |||
{ | |||
if (logger) { | |||
@@ -735,7 +735,7 @@ rspamd_log_counters(rspamd_logger_t *logger) | |||
return NULL; | |||
} | |||
static gint | |||
static int | |||
rspamd_log_errlog_cmp(const ucl_object_t **o1, const ucl_object_t **o2) | |||
{ | |||
const ucl_object_t *ts1, *ts2; | |||
@@ -744,7 +744,7 @@ rspamd_log_errlog_cmp(const ucl_object_t **o1, const ucl_object_t **o2) | |||
ts2 = ucl_object_lookup(*o2, "ts"); | |||
if (ts1 && ts2) { | |||
gdouble t1 = ucl_object_todouble(ts1), t2 = ucl_object_todouble(ts2); | |||
double t1 = ucl_object_todouble(ts1), t2 = ucl_object_todouble(ts2); | |||
if (t1 > t2) { | |||
return -1; | |||
@@ -762,7 +762,7 @@ rspamd_log_errorbuf_export(const rspamd_logger_t *logger) | |||
{ | |||
struct rspamd_logger_error_elt *cpy, *cur; | |||
ucl_object_t *top = ucl_object_typed_new(UCL_ARRAY); | |||
guint i; | |||
unsigned int i; | |||
if (logger->errlog == NULL) { | |||
return top; | |||
@@ -773,7 +773,7 @@ rspamd_log_errorbuf_export(const rspamd_logger_t *logger) | |||
memcpy(cpy, logger->errlog->elts, logger->errlog->max_elts * (sizeof(*cpy) + logger->errlog->elt_len)); | |||
for (i = 0; i < logger->errlog->max_elts; i++) { | |||
cur = (struct rspamd_logger_error_elt *) ((guchar *) cpy + | |||
cur = (struct rspamd_logger_error_elt *) ((unsigned char *) cpy + | |||
i * ((sizeof(*cpy) + logger->errlog->elt_len))); | |||
if (cur->completed) { | |||
ucl_object_t *obj = ucl_object_typed_new(UCL_OBJECT); | |||
@@ -802,7 +802,7 @@ rspamd_log_errorbuf_export(const rspamd_logger_t *logger) | |||
return top; | |||
} | |||
static guint | |||
static unsigned int | |||
rspamd_logger_allocate_mod_bit(void) | |||
{ | |||
if (log_modules->bitset_allocated * NBBY > log_modules->bitset_len + 1) { | |||
@@ -828,7 +828,7 @@ RSPAMD_DESTRUCTOR(rspamd_debug_modules_dtor) | |||
} | |||
} | |||
gint rspamd_logger_add_debug_module(const gchar *mname) | |||
int rspamd_logger_add_debug_module(const char *mname) | |||
{ | |||
struct rspamd_log_module *m; | |||
@@ -864,7 +864,7 @@ void rspamd_logger_configure_modules(GHashTable *mods_enabled) | |||
{ | |||
GHashTableIter it; | |||
gpointer k, v; | |||
guint id; | |||
unsigned int id; | |||
/* Clear all in bitset_allocated -> this are bytes not bits */ | |||
memset(log_modules->bitset, 0, log_modules->bitset_allocated); | |||
@@ -872,16 +872,16 @@ void rspamd_logger_configure_modules(GHashTable *mods_enabled) | |||
g_hash_table_iter_init(&it, mods_enabled); | |||
while (g_hash_table_iter_next(&it, &k, &v)) { | |||
rspamd_logger_add_debug_module((const gchar *) k); | |||
rspamd_logger_add_debug_module((const char *) k); | |||
} | |||
g_hash_table_iter_init(&it, mods_enabled); | |||
while (g_hash_table_iter_next(&it, &k, &v)) { | |||
id = rspamd_logger_add_debug_module((const gchar *) k); | |||
id = rspamd_logger_add_debug_module((const char *) k); | |||
if (isclr(log_modules->bitset, id)) { | |||
msg_info("enable debugging for module %s (%d)", (const gchar *) k, | |||
msg_info("enable debugging for module %s (%d)", (const char *) k, | |||
id); | |||
setbit(log_modules->bitset, id); | |||
} | |||
@@ -898,14 +898,14 @@ rspamd_logger_set_log_function(rspamd_logger_t *logger, | |||
} | |||
gchar * | |||
rspamd_log_line_hex_escape(const guchar *src, gsize srclen, | |||
gchar *dst, gsize dstlen) | |||
char * | |||
rspamd_log_line_hex_escape(const unsigned char *src, gsize srclen, | |||
char *dst, gsize dstlen) | |||
{ | |||
static const gchar hexdigests[16] = "0123456789ABCDEF"; | |||
gchar *d = dst; | |||
static const char hexdigests[16] = "0123456789ABCDEF"; | |||
char *d = dst; | |||
static guint32 escape[] = { | |||
static uint32_t escape[] = { | |||
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |||
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ | |||
@@ -950,9 +950,9 @@ rspamd_log_line_hex_escape(const guchar *src, gsize srclen, | |||
return d; | |||
} | |||
gsize rspamd_log_line_need_escape(const guchar *src, gsize srclen) | |||
gsize rspamd_log_line_need_escape(const unsigned char *src, gsize srclen) | |||
{ | |||
static guint32 escape[] = { | |||
static uint32_t escape[] = { | |||
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | |||
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ | |||
@@ -984,8 +984,8 @@ gsize rspamd_log_line_need_escape(const guchar *src, gsize srclen) | |||
return n; | |||
} | |||
const gchar * | |||
rspamd_get_log_severity_string(gint level_flags) | |||
const char * | |||
rspamd_get_log_severity_string(int level_flags) | |||
{ | |||
unsigned int bitnum; | |||
static const char *level_strs[G_LOG_LEVEL_USER_SHIFT] = { | |||
@@ -1008,7 +1008,7 @@ rspamd_get_log_severity_string(gint level_flags) | |||
} | |||
static inline void | |||
log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, | |||
log_time(double now, rspamd_logger_t *rspamd_log, char *timebuf, | |||
size_t len) | |||
{ | |||
time_t sec = (time_t) now; | |||
@@ -1019,10 +1019,10 @@ log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, | |||
r = strftime(timebuf, len, "%F %H:%M:%S", &tms); | |||
if (rspamd_log->flags & RSPAMD_LOG_FLAG_USEC) { | |||
gchar usec_buf[16]; | |||
char usec_buf[16]; | |||
rspamd_snprintf(usec_buf, sizeof(usec_buf), "%.5f", | |||
now - (gdouble) sec); | |||
now - (double) sec); | |||
rspamd_snprintf(timebuf + r, len - r, | |||
"%s", usec_buf + 1); | |||
} | |||
@@ -1030,11 +1030,11 @@ log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, | |||
void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx, | |||
double ts, | |||
const gchar *module, | |||
const gchar *id, | |||
const gchar *function, | |||
gint level_flags, | |||
const gchar *message, | |||
const char *module, | |||
const char *id, | |||
const char *function, | |||
int level_flags, | |||
const char *message, | |||
gsize mlen, | |||
rspamd_logger_t *logger) | |||
{ | |||
@@ -1052,8 +1052,8 @@ void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx, | |||
} | |||
glong r; | |||
static gchar timebuf[64], modulebuf[64]; | |||
static gchar tmpbuf[256]; | |||
static char timebuf[64], modulebuf[64]; | |||
static char tmpbuf[256]; | |||
if (!log_json && !log_systemd) { | |||
log_time(ts, logger, timebuf, sizeof(timebuf)); | |||
@@ -1061,7 +1061,7 @@ void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx, | |||
if (G_UNLIKELY(log_json)) { | |||
/* Perform JSON logging */ | |||
guint slen = id ? strlen(id) : strlen("(NULL)"); | |||
unsigned int slen = id ? strlen(id) : strlen("(NULL)"); | |||
slen = MIN(RSPAMD_LOG_ID_LEN, slen); | |||
r = rspamd_snprintf(tmpbuf, sizeof(tmpbuf), "{\"ts\": %f, " | |||
"\"pid\": %P, " | |||
@@ -1237,7 +1237,7 @@ void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx, | |||
m = modulebuf; | |||
if (id != NULL) { | |||
guint slen = strlen(id); | |||
unsigned int slen = strlen(id); | |||
slen = MIN(RSPAMD_LOG_ID_LEN, slen); | |||
mr = rspamd_snprintf(m, mremain, "<%*.s>; ", slen, | |||
id); |
@@ -24,15 +24,15 @@ | |||
#define CONSOLE_LOG_QUARK g_quark_from_static_string("console_logger") | |||
static const gchar lf_chr = '\n'; | |||
static const char lf_chr = '\n'; | |||
struct rspamd_console_logger_priv { | |||
gint fd; | |||
gint crit_fd; | |||
int fd; | |||
int crit_fd; | |||
}; | |||
/* Copy & paste :( */ | |||
static inline void | |||
log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, | |||
log_time(double now, rspamd_logger_t *rspamd_log, char *timebuf, | |||
size_t len) | |||
{ | |||
time_t sec = (time_t) now; | |||
@@ -43,10 +43,10 @@ log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, | |||
r = strftime(timebuf, len, "%F %H:%M:%S", &tms); | |||
if (rspamd_log->flags & RSPAMD_LOG_FLAG_USEC) { | |||
gchar usec_buf[16]; | |||
char usec_buf[16]; | |||
rspamd_snprintf(usec_buf, sizeof(usec_buf), "%.5f", | |||
now - (gdouble) sec); | |||
now - (double) sec); | |||
rspamd_snprintf(timebuf + r, len - r, | |||
"%s", usec_buf + 1); | |||
} | |||
@@ -136,16 +136,16 @@ void rspamd_log_console_dtor(rspamd_logger_t *logger, gpointer arg) | |||
g_free(priv); | |||
} | |||
bool rspamd_log_console_log(const gchar *module, const gchar *id, | |||
const gchar *function, | |||
gint level_flags, | |||
const gchar *message, | |||
bool rspamd_log_console_log(const char *module, const char *id, | |||
const char *function, | |||
int level_flags, | |||
const char *message, | |||
gsize mlen, | |||
rspamd_logger_t *rspamd_log, | |||
gpointer arg) | |||
{ | |||
struct rspamd_console_logger_priv *priv = (struct rspamd_console_logger_priv *) arg; | |||
gint fd, r; | |||
int fd, r; | |||
double now; | |||
if (level_flags & G_LOG_LEVEL_CRITICAL) { |
@@ -25,32 +25,32 @@ | |||
#define FILE_LOG_QUARK g_quark_from_static_string("file_logger") | |||
struct rspamd_file_logger_priv { | |||
gint fd; | |||
int fd; | |||
struct { | |||
guint32 size; | |||
guint32 used; | |||
uint32_t size; | |||
uint32_t used; | |||
u_char *buf; | |||
} io_buf; | |||
gboolean throttling; | |||
gchar *log_file; | |||
char *log_file; | |||
gboolean is_buffered; | |||
gboolean log_severity; | |||
time_t throttling_time; | |||
guint32 repeats; | |||
guint64 last_line_cksum; | |||
gchar *saved_message; | |||
uint32_t repeats; | |||
uint64_t last_line_cksum; | |||
char *saved_message; | |||
gsize saved_mlen; | |||
gchar *saved_function; | |||
gchar *saved_module; | |||
gchar *saved_id; | |||
guint saved_loglevel; | |||
char *saved_function; | |||
char *saved_module; | |||
char *saved_id; | |||
unsigned int saved_loglevel; | |||
}; | |||
/** | |||
* Calculate checksum for log line (used for repeating logic) | |||
*/ | |||
static inline guint64 | |||
rspamd_log_calculate_cksum(const gchar *message, size_t mlen) | |||
static inline uint64_t | |||
rspamd_log_calculate_cksum(const char *message, size_t mlen) | |||
{ | |||
return rspamd_cryptobox_fast_hash(message, mlen, rspamd_hash_seed()); | |||
} | |||
@@ -64,12 +64,12 @@ direct_write_log_line(rspamd_logger_t *rspamd_log, | |||
void *data, | |||
gsize count, | |||
gboolean is_iov, | |||
gint level_flags) | |||
int level_flags) | |||
{ | |||
struct iovec *iov; | |||
const gchar *line; | |||
const char *line; | |||
glong r; | |||
gint fd; | |||
int fd; | |||
gboolean locked = FALSE; | |||
iov = (struct iovec *) data; | |||
@@ -81,7 +81,7 @@ direct_write_log_line(rspamd_logger_t *rspamd_log, | |||
if (is_iov) { | |||
tlen = 0; | |||
for (guint i = 0; i < count; i++) { | |||
for (unsigned int i = 0; i < count; i++) { | |||
tlen += iov[i].iov_len; | |||
} | |||
} | |||
@@ -109,7 +109,7 @@ direct_write_log_line(rspamd_logger_t *rspamd_log, | |||
r = writev(fd, iov, count); | |||
} | |||
else { | |||
line = (const gchar *) data; | |||
line = (const char *) data; | |||
r = write(fd, line, count); | |||
} | |||
@@ -159,9 +159,9 @@ direct_write_log_line(rspamd_logger_t *rspamd_log, | |||
static void | |||
fill_buffer(rspamd_logger_t *rspamd_log, | |||
struct rspamd_file_logger_priv *priv, | |||
const struct iovec *iov, gint iovcnt) | |||
const struct iovec *iov, int iovcnt) | |||
{ | |||
gint i; | |||
int i; | |||
for (i = 0; i < iovcnt; i++) { | |||
memcpy(priv->io_buf.buf + priv->io_buf.used, | |||
@@ -192,11 +192,11 @@ static bool | |||
file_log_helper(rspamd_logger_t *rspamd_log, | |||
struct rspamd_file_logger_priv *priv, | |||
const struct iovec *iov, | |||
guint iovcnt, | |||
gint level_flags) | |||
unsigned int iovcnt, | |||
int level_flags) | |||
{ | |||
size_t len = 0; | |||
guint i; | |||
unsigned int i; | |||
if (!priv->is_buffered) { | |||
/* Write string directly */ | |||
@@ -233,7 +233,7 @@ static void | |||
rspamd_log_reset_repeated(rspamd_logger_t *rspamd_log, | |||
struct rspamd_file_logger_priv *priv) | |||
{ | |||
gchar tmpbuf[256]; | |||
char tmpbuf[256]; | |||
gssize r; | |||
if (priv->repeats > REPEATS_MIN) { | |||
@@ -275,13 +275,13 @@ rspamd_log_reset_repeated(rspamd_logger_t *rspamd_log, | |||
} | |||
} | |||
static gint | |||
static int | |||
rspamd_try_open_log_fd(rspamd_logger_t *rspamd_log, | |||
struct rspamd_file_logger_priv *priv, | |||
uid_t uid, gid_t gid, | |||
GError **err) | |||
{ | |||
gint fd; | |||
int fd; | |||
fd = open(priv->log_file, | |||
O_CREAT | O_WRONLY | O_APPEND, | |||
@@ -366,17 +366,17 @@ void rspamd_log_file_dtor(rspamd_logger_t *logger, gpointer arg) | |||
g_free(priv); | |||
} | |||
bool rspamd_log_file_log(const gchar *module, const gchar *id, | |||
const gchar *function, | |||
gint level_flags, | |||
const gchar *message, | |||
bool rspamd_log_file_log(const char *module, const char *id, | |||
const char *function, | |||
int level_flags, | |||
const char *message, | |||
gsize mlen, | |||
rspamd_logger_t *rspamd_log, | |||
gpointer arg) | |||
{ | |||
struct rspamd_file_logger_priv *priv = (struct rspamd_file_logger_priv *) arg; | |||
gdouble now; | |||
guint64 cksum; | |||
double now; | |||
uint64_t cksum; | |||
gboolean got_time = FALSE; | |||
@@ -24,35 +24,35 @@ | |||
#define LOGBUF_LEN 8192 | |||
struct rspamd_log_module { | |||
gchar *mname; | |||
guint id; | |||
char *mname; | |||
unsigned int id; | |||
}; | |||
struct rspamd_log_modules { | |||
guchar *bitset; | |||
guint bitset_len; /* Number of BITS used in bitset */ | |||
guint bitset_allocated; /* Size of bitset allocated in BYTES */ | |||
unsigned char *bitset; | |||
unsigned int bitset_len; /* Number of BITS used in bitset */ | |||
unsigned int bitset_allocated; /* Size of bitset allocated in BYTES */ | |||
GHashTable *modules; | |||
}; | |||
struct rspamd_logger_error_elt { | |||
gint completed; | |||
int completed; | |||
GQuark ptype; | |||
pid_t pid; | |||
gdouble ts; | |||
gchar id[RSPAMD_LOG_ID_LEN + 1]; | |||
gchar module[9]; | |||
gchar message[]; | |||
double ts; | |||
char id[RSPAMD_LOG_ID_LEN + 1]; | |||
char module[9]; | |||
char message[]; | |||
}; | |||
struct rspamd_logger_error_log { | |||
struct rspamd_logger_error_elt *elts; | |||
rspamd_mempool_t *pool; | |||
guint32 max_elts; | |||
guint32 elt_len; | |||
uint32_t max_elts; | |||
uint32_t elt_len; | |||
/* Avoid false cache sharing */ | |||
guchar __padding[64 - sizeof(gpointer) * 2 - sizeof(guint64)]; | |||
guint cur_row; | |||
unsigned char __padding[64 - sizeof(gpointer) * 2 - sizeof(uint64_t)]; | |||
unsigned int cur_row; | |||
}; | |||
/** | |||
@@ -61,24 +61,24 @@ struct rspamd_logger_error_log { | |||
*/ | |||
struct rspamd_logger_s { | |||
struct rspamd_logger_funcs ops; | |||
gint log_level; | |||
int log_level; | |||
struct rspamd_logger_error_log *errlog; | |||
struct rspamd_cryptobox_pubkey *pk; | |||
struct rspamd_cryptobox_keypair *keypair; | |||
guint flags; | |||
unsigned int flags; | |||
gboolean closed; | |||
gboolean enabled; | |||
gboolean is_debug; | |||
gboolean no_lock; | |||
pid_t pid; | |||
const gchar *process_type; | |||
const char *process_type; | |||
struct rspamd_radix_map_helper *debug_ip; | |||
rspamd_mempool_mutex_t *mtx; | |||
rspamd_mempool_t *pool; | |||
guint64 log_cnt[4]; | |||
uint64_t log_cnt[4]; | |||
}; | |||
/* | |||
@@ -93,10 +93,10 @@ void *rspamd_log_file_init(rspamd_logger_t *logger, struct rspamd_config *cfg, | |||
void *rspamd_log_file_reload(rspamd_logger_t *logger, struct rspamd_config *cfg, | |||
gpointer arg, uid_t uid, gid_t gid, GError **err); | |||
void rspamd_log_file_dtor(rspamd_logger_t *logger, gpointer arg); | |||
bool rspamd_log_file_log(const gchar *module, const gchar *id, | |||
const gchar *function, | |||
gint level_flags, | |||
const gchar *message, | |||
bool rspamd_log_file_log(const char *module, const char *id, | |||
const char *function, | |||
int level_flags, | |||
const char *message, | |||
gsize mlen, | |||
rspamd_logger_t *rspamd_log, | |||
gpointer arg); | |||
@@ -128,10 +128,10 @@ struct rspamd_logger_iov_ctx { | |||
*/ | |||
void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx, | |||
double ts, | |||
const gchar *module, const gchar *id, | |||
const gchar *function, | |||
gint level_flags, | |||
const gchar *message, | |||
const char *module, const char *id, | |||
const char *function, | |||
int level_flags, | |||
const char *message, | |||
gsize mlen, | |||
rspamd_logger_t *rspamd_log); | |||
@@ -148,8 +148,8 @@ void rspamd_log_iov_free(struct rspamd_logger_iov_ctx *iov_ctx); | |||
* @param dstlen | |||
* @return end of the escaped buffer | |||
*/ | |||
gchar *rspamd_log_line_hex_escape(const guchar *src, gsize srclen, | |||
gchar *dst, gsize dstlen); | |||
char *rspamd_log_line_hex_escape(const unsigned char *src, gsize srclen, | |||
char *dst, gsize dstlen); | |||
/** | |||
* Returns number of characters to be escaped, e.g. a caller can allocate a new buffer | |||
* the desired number of characters | |||
@@ -157,7 +157,7 @@ gchar *rspamd_log_line_hex_escape(const guchar *src, gsize srclen, | |||
* @param srclen | |||
* @return number of characters to be escaped | |||
*/ | |||
gsize rspamd_log_line_need_escape(const guchar *src, gsize srclen); | |||
gsize rspamd_log_line_need_escape(const unsigned char *src, gsize srclen); | |||
static const struct rspamd_logger_funcs file_log_funcs = { | |||
.init = rspamd_log_file_init, | |||
@@ -175,10 +175,10 @@ void *rspamd_log_syslog_init(rspamd_logger_t *logger, struct rspamd_config *cfg, | |||
void *rspamd_log_syslog_reload(rspamd_logger_t *logger, struct rspamd_config *cfg, | |||
gpointer arg, uid_t uid, gid_t gid, GError **err); | |||
void rspamd_log_syslog_dtor(rspamd_logger_t *logger, gpointer arg); | |||
bool rspamd_log_syslog_log(const gchar *module, const gchar *id, | |||
const gchar *function, | |||
gint level_flags, | |||
const gchar *message, | |||
bool rspamd_log_syslog_log(const char *module, const char *id, | |||
const char *function, | |||
int level_flags, | |||
const char *message, | |||
gsize mlen, | |||
rspamd_logger_t *rspamd_log, | |||
gpointer arg); | |||
@@ -199,10 +199,10 @@ void *rspamd_log_console_init(rspamd_logger_t *logger, struct rspamd_config *cfg | |||
void *rspamd_log_console_reload(rspamd_logger_t *logger, struct rspamd_config *cfg, | |||
gpointer arg, uid_t uid, gid_t gid, GError **err); | |||
void rspamd_log_console_dtor(rspamd_logger_t *logger, gpointer arg); | |||
bool rspamd_log_console_log(const gchar *module, const gchar *id, | |||
const gchar *function, | |||
gint level_flags, | |||
const gchar *message, | |||
bool rspamd_log_console_log(const char *module, const char *id, | |||
const char *function, | |||
int level_flags, | |||
const char *message, | |||
gsize mlen, | |||
rspamd_logger_t *rspamd_log, | |||
gpointer arg); |
@@ -22,7 +22,7 @@ | |||
#define SYSLOG_LOG_QUARK g_quark_from_static_string("syslog_logger") | |||
struct rspamd_syslog_logger_priv { | |||
gint log_facility; | |||
int log_facility; | |||
}; | |||
#ifdef HAVE_SYSLOG_H | |||
@@ -55,24 +55,24 @@ void rspamd_log_syslog_dtor(rspamd_logger_t *logger, gpointer arg) | |||
closelog(); | |||
g_free(priv); | |||
} | |||
bool rspamd_log_syslog_log(const gchar *module, const gchar *id, | |||
const gchar *function, | |||
gint level_flags, | |||
const gchar *message, | |||
bool rspamd_log_syslog_log(const char *module, const char *id, | |||
const char *function, | |||
int level_flags, | |||
const char *message, | |||
gsize mlen, | |||
rspamd_logger_t *rspamd_log, | |||
gpointer arg) | |||
{ | |||
static const struct { | |||
GLogLevelFlags glib_level; | |||
gint syslog_level; | |||
int syslog_level; | |||
} levels_match[] = { | |||
{G_LOG_LEVEL_DEBUG, LOG_DEBUG}, | |||
{G_LOG_LEVEL_INFO, LOG_INFO}, | |||
{G_LOG_LEVEL_WARNING, LOG_WARNING}, | |||
{G_LOG_LEVEL_CRITICAL, LOG_ERR}}; | |||
unsigned i; | |||
gint syslog_level; | |||
int syslog_level; | |||
if (!(level_flags & RSPAMD_LOG_FORCED) && !rspamd_log->enabled) { | |||
return false; | |||
@@ -119,7 +119,7 @@ bool rspamd_log_syslog_log(const gchar *module, const gchar *id, | |||
idbuf, | |||
module != NULL ? module : "", | |||
function != NULL ? function : "", | |||
(gint) mlen, message); | |||
(int) mlen, message); | |||
} | |||
else { | |||
/* Escaped version */ | |||
@@ -228,7 +228,7 @@ bool rspamd_log_syslog_log(const gchar *module, const gchar *id, | |||
idbuf, | |||
module != NULL ? module : "", | |||
function != NULL ? function : "", | |||
(gint) mlen, message); | |||
(int) mlen, message); | |||
} | |||
return true; | |||
@@ -245,10 +245,10 @@ rspamd_log_syslog_init(rspamd_logger_t *logger, struct rspamd_config *cfg, | |||
return NULL; | |||
} | |||
bool rspamd_log_syslog_log(const gchar *module, const gchar *id, | |||
const gchar *function, | |||
gint level_flags, | |||
const gchar *message, | |||
bool rspamd_log_syslog_log(const char *module, const char *id, | |||
const char *function, | |||
int level_flags, | |||
const char *message, | |||
gsize mlen, | |||
rspamd_logger_t *rspamd_log, | |||
gpointer arg) |
@@ -65,19 +65,19 @@ static void rspamd_map_process_periodic(struct map_periodic_cbdata *cbd); | |||
static void rspamd_map_schedule_periodic(struct rspamd_map *map, int how); | |||
static gboolean read_map_file_chunks(struct rspamd_map *map, | |||
struct map_cb_data *cbdata, | |||
const gchar *fname, | |||
const char *fname, | |||
gsize len, | |||
goffset off); | |||
static gboolean rspamd_map_save_http_cached_file(struct rspamd_map *map, | |||
struct rspamd_map_backend *bk, | |||
struct http_map_data *htdata, | |||
const guchar *data, | |||
const unsigned char *data, | |||
gsize len); | |||
static gboolean rspamd_map_update_http_cached_file(struct rspamd_map *map, | |||
struct rspamd_map_backend *bk, | |||
struct http_map_data *htdata); | |||
guint rspamd_map_log_id = (guint) -1; | |||
unsigned int rspamd_map_log_id = (unsigned int) -1; | |||
RSPAMD_CONSTRUCTOR(rspamd_map_log_init) | |||
{ | |||
rspamd_map_log_id = rspamd_logger_add_debug_module("map"); | |||
@@ -89,7 +89,7 @@ RSPAMD_CONSTRUCTOR(rspamd_map_log_init) | |||
static void | |||
write_http_request(struct http_callback_data *cbd) | |||
{ | |||
gchar datebuf[128]; | |||
char datebuf[128]; | |||
struct rspamd_http_message *msg; | |||
msg = rspamd_http_new_message(HTTP_REQUEST); | |||
@@ -153,7 +153,7 @@ free_http_cbdata_common(struct http_callback_data *cbd, gboolean plan_new) | |||
if (cbd->addrs) { | |||
rspamd_inet_addr_t *addr; | |||
guint i; | |||
unsigned int i; | |||
PTR_ARRAY_FOREACH(cbd->addrs, i, addr) | |||
{ | |||
@@ -306,7 +306,7 @@ http_map_finish(struct rspamd_http_connection *conn, | |||
struct rspamd_http_map_cached_cbdata *cache_cbd; | |||
const rspamd_ftok_t *expires_hdr, *etag_hdr; | |||
char next_check_date[128]; | |||
guchar *in = NULL; | |||
unsigned char *in = NULL; | |||
gsize dlen = 0; | |||
map = cbd->map; | |||
@@ -444,7 +444,7 @@ http_map_finish(struct rspamd_http_connection *conn, | |||
ZSTD_DStream *zstream; | |||
ZSTD_inBuffer zin; | |||
ZSTD_outBuffer zout; | |||
guchar *out; | |||
unsigned char *out; | |||
gsize outlen, r; | |||
zstream = ZSTD_createDStream(); | |||
@@ -585,12 +585,12 @@ err: | |||
static gboolean | |||
read_map_file_chunks(struct rspamd_map *map, struct map_cb_data *cbdata, | |||
const gchar *fname, gsize len, goffset off) | |||
const char *fname, gsize len, goffset off) | |||
{ | |||
gint fd; | |||
int fd; | |||
gssize r, avail; | |||
gsize buflen = 1024 * 1024; | |||
gchar *pos, *bytes; | |||
char *pos, *bytes; | |||
fd = rspamd_file_xopen(fname, O_RDONLY, 0, TRUE); | |||
@@ -602,7 +602,7 @@ read_map_file_chunks(struct rspamd_map *map, struct map_cb_data *cbdata, | |||
if (lseek(fd, off, SEEK_SET) == -1) { | |||
msg_err_map("can't seek in map to pos %d for buffered reading %s: %s", | |||
(gint) off, fname, strerror(errno)); | |||
(int) off, fname, strerror(errno)); | |||
close(fd); | |||
return FALSE; | |||
@@ -614,13 +614,13 @@ read_map_file_chunks(struct rspamd_map *map, struct map_cb_data *cbdata, | |||
pos = bytes; | |||
while ((r = read(fd, pos, avail)) > 0) { | |||
gchar *end = bytes + (pos - bytes) + r; | |||
char *end = bytes + (pos - bytes) + r; | |||
msg_debug_map("%s: read map chunk, %z bytes", fname, | |||
r); | |||
pos = map->read_callback(bytes, end - bytes, cbdata, r == len); | |||
if (pos && pos > bytes && pos < end) { | |||
guint remain = end - pos; | |||
unsigned int remain = end - pos; | |||
memmove(bytes, pos, remain); | |||
pos = bytes + remain; | |||
@@ -660,10 +660,10 @@ read_map_file_chunks(struct rspamd_map *map, struct map_cb_data *cbdata, | |||
} | |||
static gboolean | |||
rspamd_map_check_sig_pk_mem(const guchar *sig, | |||
rspamd_map_check_sig_pk_mem(const unsigned char *sig, | |||
gsize siglen, | |||
struct rspamd_map *map, | |||
const guchar *input, | |||
const unsigned char *input, | |||
gsize inlen, | |||
struct rspamd_cryptobox_pubkey *pk) | |||
{ | |||
@@ -698,15 +698,15 @@ static gboolean | |||
rspamd_map_check_file_sig(const char *fname, | |||
struct rspamd_map *map, | |||
struct rspamd_map_backend *bk, | |||
const guchar *input, | |||
const unsigned char *input, | |||
gsize inlen) | |||
{ | |||
guchar *data; | |||
unsigned char *data; | |||
struct rspamd_cryptobox_pubkey *pk = NULL; | |||
GString *b32_key; | |||
gboolean ret = TRUE; | |||
gsize len = 0; | |||
gchar fpath[PATH_MAX]; | |||
char fpath[PATH_MAX]; | |||
if (bk->trusted_pubkey == NULL) { | |||
/* Try to load and check pubkey */ | |||
@@ -772,7 +772,7 @@ static gboolean | |||
read_map_file(struct rspamd_map *map, struct file_map_data *data, | |||
struct rspamd_map_backend *bk, struct map_periodic_cbdata *periodic) | |||
{ | |||
gchar *bytes; | |||
char *bytes; | |||
gsize len; | |||
struct stat st; | |||
@@ -836,7 +836,7 @@ read_map_file(struct rspamd_map *map, struct file_map_data *data, | |||
ZSTD_DStream *zstream; | |||
ZSTD_inBuffer zin; | |||
ZSTD_outBuffer zout; | |||
guchar *out; | |||
unsigned char *out; | |||
gsize outlen, r; | |||
zstream = ZSTD_createDStream(); | |||
@@ -908,7 +908,7 @@ static gboolean | |||
read_map_static(struct rspamd_map *map, struct static_map_data *data, | |||
struct rspamd_map_backend *bk, struct map_periodic_cbdata *periodic) | |||
{ | |||
guchar *bytes; | |||
unsigned char *bytes; | |||
gsize len; | |||
if (map->read_callback == NULL || map->fin_callback == NULL) { | |||
@@ -925,7 +925,7 @@ read_map_static(struct rspamd_map *map, struct static_map_data *data, | |||
ZSTD_DStream *zstream; | |||
ZSTD_inBuffer zin; | |||
ZSTD_outBuffer zout; | |||
guchar *out; | |||
unsigned char *out; | |||
gsize outlen, r; | |||
zstream = ZSTD_createDStream(); | |||
@@ -1041,11 +1041,11 @@ rspamd_map_periodic_callback(struct ev_loop *loop, ev_timer *w, int revents) | |||
static void | |||
rspamd_map_schedule_periodic(struct rspamd_map *map, int how) | |||
{ | |||
const gdouble error_mult = 20.0, lock_mult = 0.1; | |||
static const gdouble min_timer_interval = 2.0; | |||
const gchar *reason = "unknown reason"; | |||
gdouble jittered_sec; | |||
gdouble timeout; | |||
const double error_mult = 20.0, lock_mult = 0.1; | |||
static const double min_timer_interval = 2.0; | |||
const char *reason = "unknown reason"; | |||
double jittered_sec; | |||
double timeout; | |||
struct map_periodic_cbdata *cbd; | |||
if (map->scheduled_check || (map->wrk && | |||
@@ -1070,7 +1070,7 @@ rspamd_map_schedule_periodic(struct rspamd_map *map, int how) | |||
if (timeout > 0 && timeout < map->poll_timeout) { | |||
/* Early check case, jitter */ | |||
gdouble poll_timeout = map->poll_timeout; | |||
double poll_timeout = map->poll_timeout; | |||
if (how & RSPAMD_MAP_SCHEDULE_ERROR) { | |||
poll_timeout = map->poll_timeout * error_mult; | |||
@@ -1172,7 +1172,7 @@ rspamd_map_schedule_periodic(struct rspamd_map *map, int how) | |||
cbd, jittered_sec, map->name, reason); | |||
} | |||
static gint | |||
static int | |||
rspamd_map_af_to_weight(const rspamd_inet_addr_t *addr) | |||
{ | |||
int ret; | |||
@@ -1192,12 +1192,12 @@ rspamd_map_af_to_weight(const rspamd_inet_addr_t *addr) | |||
return ret; | |||
} | |||
static gint | |||
static int | |||
rspamd_map_dns_address_sort_func(gconstpointer a, gconstpointer b) | |||
{ | |||
const rspamd_inet_addr_t *ip1 = *(const rspamd_inet_addr_t **) a, | |||
*ip2 = *(const rspamd_inet_addr_t **) b; | |||
gint w1, w2; | |||
int w1, w2; | |||
w1 = rspamd_map_af_to_weight(ip1); | |||
w2 = rspamd_map_af_to_weight(ip2); | |||
@@ -1212,7 +1212,7 @@ rspamd_map_dns_callback(struct rdns_reply *reply, void *arg) | |||
struct http_callback_data *cbd = arg; | |||
struct rdns_reply_entry *cur_rep; | |||
struct rspamd_map *map; | |||
guint flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED; | |||
unsigned int flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED; | |||
map = cbd->map; | |||
@@ -1264,7 +1264,7 @@ rspamd_map_dns_callback(struct rdns_reply *reply, void *arg) | |||
if (cbd->stage == http_map_http_conn && cbd->addrs->len > 0) { | |||
rspamd_ptr_array_shuffle(cbd->addrs); | |||
gint idx = 0; | |||
int idx = 0; | |||
/* | |||
* For the existing addr we can just select any address as we have | |||
* data available | |||
@@ -1328,7 +1328,7 @@ rspamd_map_dns_callback(struct rdns_reply *reply, void *arg) | |||
static gboolean | |||
rspamd_map_read_cached(struct rspamd_map *map, struct rspamd_map_backend *bk, | |||
struct map_periodic_cbdata *periodic, const gchar *host) | |||
struct map_periodic_cbdata *periodic, const char *host) | |||
{ | |||
gsize mmap_len, len; | |||
gpointer in; | |||
@@ -1366,7 +1366,7 @@ rspamd_map_read_cached(struct rspamd_map *map, struct rspamd_map_backend *bk, | |||
ZSTD_DStream *zstream; | |||
ZSTD_inBuffer zin; | |||
ZSTD_outBuffer zout; | |||
guchar *out; | |||
unsigned char *out; | |||
gsize outlen, r; | |||
zstream = ZSTD_createDStream(); | |||
@@ -1429,8 +1429,8 @@ static gboolean | |||
rspamd_map_has_http_cached_file(struct rspamd_map *map, | |||
struct rspamd_map_backend *bk) | |||
{ | |||
gchar path[PATH_MAX]; | |||
guchar digest[rspamd_cryptobox_HASHBYTES]; | |||
char path[PATH_MAX]; | |||
unsigned char digest[rspamd_cryptobox_HASHBYTES]; | |||
struct rspamd_config *cfg = map->cfg; | |||
struct stat st; | |||
@@ -1454,13 +1454,13 @@ static gboolean | |||
rspamd_map_save_http_cached_file(struct rspamd_map *map, | |||
struct rspamd_map_backend *bk, | |||
struct http_map_data *htdata, | |||
const guchar *data, | |||
const unsigned char *data, | |||
gsize len) | |||
{ | |||
gchar path[PATH_MAX]; | |||
guchar digest[rspamd_cryptobox_HASHBYTES]; | |||
char path[PATH_MAX]; | |||
unsigned char digest[rspamd_cryptobox_HASHBYTES]; | |||
struct rspamd_config *cfg = map->cfg; | |||
gint fd; | |||
int fd; | |||
struct rspamd_http_file_data header; | |||
if (cfg->maps_cache_dir == NULL || cfg->maps_cache_dir[0] == '\0') { | |||
@@ -1539,10 +1539,10 @@ rspamd_map_update_http_cached_file(struct rspamd_map *map, | |||
struct rspamd_map_backend *bk, | |||
struct http_map_data *htdata) | |||
{ | |||
gchar path[PATH_MAX]; | |||
guchar digest[rspamd_cryptobox_HASHBYTES]; | |||
char path[PATH_MAX]; | |||
unsigned char digest[rspamd_cryptobox_HASHBYTES]; | |||
struct rspamd_config *cfg = map->cfg; | |||
gint fd; | |||
int fd; | |||
struct rspamd_http_file_data header; | |||
if (!rspamd_map_has_http_cached_file(map, bk)) { | |||
@@ -1612,10 +1612,10 @@ rspamd_map_read_http_cached_file(struct rspamd_map *map, | |||
struct http_map_data *htdata, | |||
struct map_cb_data *cbdata) | |||
{ | |||
gchar path[PATH_MAX]; | |||
guchar digest[rspamd_cryptobox_HASHBYTES]; | |||
char path[PATH_MAX]; | |||
unsigned char digest[rspamd_cryptobox_HASHBYTES]; | |||
struct rspamd_config *cfg = map->cfg; | |||
gint fd; | |||
int fd; | |||
struct stat st; | |||
struct rspamd_http_file_data header; | |||
@@ -1707,7 +1707,7 @@ rspamd_map_read_http_cached_file(struct rspamd_map *map, | |||
} | |||
struct tm tm; | |||
gchar ncheck_buf[32], lm_buf[32]; | |||
char ncheck_buf[32], lm_buf[32]; | |||
rspamd_localtime(map->next_check, &tm); | |||
strftime(ncheck_buf, sizeof(ncheck_buf) - 1, "%Y-%m-%d %H:%M:%S", &tm); | |||
@@ -1737,7 +1737,7 @@ rspamd_map_common_http_callback(struct rspamd_map *map, | |||
{ | |||
struct http_map_data *data; | |||
struct http_callback_data *cbd; | |||
guint flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED; | |||
unsigned int flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED; | |||
data = bk->data.hd; | |||
@@ -1846,7 +1846,7 @@ check: | |||
} | |||
else if (map->r->r) { | |||
/* Send both A and AAAA requests */ | |||
guint nreq = 0; | |||
unsigned int nreq = 0; | |||
if (rdns_make_request_full(map->r->r, rspamd_map_dns_callback, cbd, | |||
map->cfg->dns_timeout, map->cfg->dns_retransmits, 1, | |||
@@ -2107,7 +2107,7 @@ rspamd_map_on_stat(struct ev_loop *loop, ev_stat *w, int revents) | |||
/* Fire need modify flag */ | |||
struct rspamd_map_backend *bk; | |||
guint i; | |||
unsigned int i; | |||
PTR_ARRAY_FOREACH(map->backends, i, bk) | |||
{ | |||
@@ -2138,7 +2138,7 @@ void rspamd_map_watch(struct rspamd_config *cfg, | |||
GList *cur = cfg->maps; | |||
struct rspamd_map *map; | |||
struct rspamd_map_backend *bk; | |||
guint i; | |||
unsigned int i; | |||
g_assert(how > RSPAMD_MAP_WATCH_MIN && how < RSPAMD_MAP_WATCH_MAX); | |||
@@ -2228,7 +2228,7 @@ void rspamd_map_preload(struct rspamd_config *cfg) | |||
GList *cur = cfg->maps; | |||
struct rspamd_map *map; | |||
struct rspamd_map_backend *bk; | |||
guint i; | |||
unsigned int i; | |||
gboolean map_ok; | |||
/* First of all do synced read of data */ | |||
@@ -2337,7 +2337,7 @@ void rspamd_map_remove_all(struct rspamd_config *cfg) | |||
GList *cur; | |||
struct rspamd_map_backend *bk; | |||
struct map_cb_data cbdata; | |||
guint i; | |||
unsigned int i; | |||
for (cur = cfg->maps; cur != NULL; cur = g_list_next(cur)) { | |||
map = cur->data; | |||
@@ -2374,11 +2374,11 @@ void rspamd_map_remove_all(struct rspamd_config *cfg) | |||
cfg->maps = NULL; | |||
} | |||
static const gchar * | |||
static const char * | |||
rspamd_map_check_proto(struct rspamd_config *cfg, | |||
const gchar *map_line, struct rspamd_map_backend *bk) | |||
const char *map_line, struct rspamd_map_backend *bk) | |||
{ | |||
const gchar *pos = map_line, *end, *end_key; | |||
const char *pos = map_line, *end, *end_key; | |||
g_assert(bk != NULL); | |||
g_assert(pos != NULL); | |||
@@ -2489,7 +2489,7 @@ rspamd_map_check_proto(struct rspamd_config *cfg, | |||
} | |||
gboolean | |||
rspamd_map_is_map(const gchar *map_line) | |||
rspamd_map_is_map(const char *map_line) | |||
{ | |||
gboolean ret = FALSE; | |||
@@ -2589,14 +2589,14 @@ rspamd_map_backend_dtor(struct rspamd_map_backend *bk) | |||
} | |||
static struct rspamd_map_backend * | |||
rspamd_map_parse_backend(struct rspamd_config *cfg, const gchar *map_line) | |||
rspamd_map_parse_backend(struct rspamd_config *cfg, const char *map_line) | |||
{ | |||
struct rspamd_map_backend *bk; | |||
struct file_map_data *fdata = NULL; | |||
struct http_map_data *hdata = NULL; | |||
struct static_map_data *sdata = NULL; | |||
struct http_parser_url up; | |||
const gchar *end, *p; | |||
const char *end, *p; | |||
rspamd_ftok_t tok; | |||
bk = g_malloc0(sizeof(*bk)); | |||
@@ -2693,8 +2693,8 @@ rspamd_map_parse_backend(struct rspamd_config *cfg, const gchar *map_line) | |||
if (up.field_set & (1u << UF_USERINFO)) { | |||
/* Create authorisation header for basic auth */ | |||
guint len = sizeof("Basic ") + | |||
up.field_data[UF_USERINFO].len * 8 / 5 + 4; | |||
unsigned int len = sizeof("Basic ") + | |||
up.field_data[UF_USERINFO].len * 8 / 5 + 4; | |||
hdata->userinfo = g_malloc(len); | |||
rspamd_snprintf(hdata->userinfo, len, "Basic %*Bs", | |||
(int) up.field_data[UF_USERINFO].len, | |||
@@ -2731,7 +2731,7 @@ rspamd_map_parse_backend(struct rspamd_config *cfg, const gchar *map_line) | |||
ucl_object_type(user_obj) == UCL_STRING && | |||
ucl_object_type(password_obj) == UCL_STRING) { | |||
gchar *tmpbuf; | |||
char *tmpbuf; | |||
unsigned tlen; | |||
/* User + password + ':' */ | |||
@@ -2793,9 +2793,9 @@ static void | |||
rspamd_map_calculate_hash(struct rspamd_map *map) | |||
{ | |||
struct rspamd_map_backend *bk; | |||
guint i; | |||
unsigned int i; | |||
rspamd_cryptobox_hash_state_t st; | |||
gchar *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES]; | |||
char *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES]; | |||
rspamd_cryptobox_hash_init(&st, NULL, 0); | |||
@@ -2816,7 +2816,7 @@ rspamd_map_add_static_string(struct rspamd_config *cfg, | |||
GString *target) | |||
{ | |||
gsize sz; | |||
const gchar *dline; | |||
const char *dline; | |||
if (ucl_object_type(elt) != UCL_STRING) { | |||
msg_err_config("map has static backend but `data` is " | |||
@@ -2841,8 +2841,8 @@ rspamd_map_add_static_string(struct rspamd_config *cfg, | |||
struct rspamd_map * | |||
rspamd_map_add(struct rspamd_config *cfg, | |||
const gchar *map_line, | |||
const gchar *description, | |||
const char *map_line, | |||
const char *description, | |||
map_cb_t read_callback, | |||
map_fin_cb_t fin_callback, | |||
map_dtor_t dtor, | |||
@@ -2873,7 +2873,7 @@ rspamd_map_add(struct rspamd_config *cfg, | |||
map->cfg = cfg; | |||
map->id = rspamd_random_uint64_fast(); | |||
map->locked = | |||
rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(gint)); | |||
rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(int)); | |||
map->backends = g_ptr_array_sized_new(1); | |||
map->wrk = worker; | |||
rspamd_mempool_add_destructor(cfg->cfg_pool, rspamd_ptr_array_free_hard, | |||
@@ -2904,8 +2904,8 @@ rspamd_map_add(struct rspamd_config *cfg, | |||
struct rspamd_map * | |||
rspamd_map_add_fake(struct rspamd_config *cfg, | |||
const gchar *description, | |||
const gchar *name) | |||
const char *description, | |||
const char *name) | |||
{ | |||
struct rspamd_map *map; | |||
@@ -2943,19 +2943,19 @@ rspamd_map_add_backend(struct rspamd_map *map, struct rspamd_map_backend *bk) | |||
struct rspamd_map * | |||
rspamd_map_add_from_ucl(struct rspamd_config *cfg, | |||
const ucl_object_t *obj, | |||
const gchar *description, | |||
const char *description, | |||
map_cb_t read_callback, | |||
map_fin_cb_t fin_callback, | |||
map_dtor_t dtor, | |||
void **user_data, | |||
struct rspamd_worker *worker, | |||
gint flags) | |||
int flags) | |||
{ | |||
ucl_object_iter_t it = NULL; | |||
const ucl_object_t *cur, *elt; | |||
struct rspamd_map *map; | |||
struct rspamd_map_backend *bk; | |||
guint i; | |||
unsigned int i; | |||
g_assert(obj != NULL); | |||
@@ -2973,7 +2973,7 @@ rspamd_map_add_from_ucl(struct rspamd_config *cfg, | |||
map->cfg = cfg; | |||
map->id = rspamd_random_uint64_fast(); | |||
map->locked = | |||
rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(gint)); | |||
rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(int)); | |||
map->backends = g_ptr_array_new(); | |||
map->wrk = worker; | |||
map->no_file_read = (flags & RSPAMD_MAP_FILE_NO_READ); |
@@ -30,8 +30,8 @@ struct rspamd_map; | |||
/** | |||
* Callback types | |||
*/ | |||
typedef gchar *(*map_cb_t)(gchar *chunk, gint len, | |||
struct map_cb_data *data, gboolean final); | |||
typedef char *(*map_cb_t)(char *chunk, int len, | |||
struct map_cb_data *data, gboolean final); | |||
typedef void (*map_fin_cb_t)(struct map_cb_data *data, void **target); | |||
@@ -50,7 +50,7 @@ typedef void (*rspamd_map_on_load_function)(struct rspamd_map *map, gpointer ud) | |||
*/ | |||
struct map_cb_data { | |||
struct rspamd_map *map; | |||
gint state; | |||
int state; | |||
bool errored; | |||
void *prev_data; | |||
void *cur_data; | |||
@@ -61,7 +61,7 @@ struct map_cb_data { | |||
* @param map_line | |||
* @return | |||
*/ | |||
gboolean rspamd_map_is_map(const gchar *map_line); | |||
gboolean rspamd_map_is_map(const char *map_line); | |||
enum rspamd_map_flags { | |||
RSPAMD_MAP_DEFAULT = 0, | |||
@@ -73,8 +73,8 @@ enum rspamd_map_flags { | |||
* Add map from line | |||
*/ | |||
struct rspamd_map *rspamd_map_add(struct rspamd_config *cfg, | |||
const gchar *map_line, | |||
const gchar *description, | |||
const char *map_line, | |||
const char *description, | |||
map_cb_t read_callback, | |||
map_fin_cb_t fin_callback, | |||
map_dtor_t dtor, | |||
@@ -87,7 +87,7 @@ struct rspamd_map *rspamd_map_add(struct rspamd_config *cfg, | |||
*/ | |||
struct rspamd_map *rspamd_map_add_from_ucl(struct rspamd_config *cfg, | |||
const ucl_object_t *obj, | |||
const gchar *description, | |||
const char *description, | |||
map_cb_t read_callback, | |||
map_fin_cb_t fin_callback, | |||
map_dtor_t dtor, | |||
@@ -102,8 +102,8 @@ struct rspamd_map *rspamd_map_add_from_ucl(struct rspamd_config *cfg, | |||
* @return | |||
*/ | |||
struct rspamd_map *rspamd_map_add_fake(struct rspamd_config *cfg, | |||
const gchar *description, | |||
const gchar *name); | |||
const char *description, | |||
const char *name); | |||
enum rspamd_map_watch_type { |