diff options
Diffstat (limited to 'src/libutil/str_util.h')
-rw-r--r-- | src/libutil/str_util.h | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h index ff5827a0b..a7252f3bf 100644 --- a/src/libutil/str_util.h +++ b/src/libutil/str_util.h @@ -36,12 +36,12 @@ enum rspamd_newlines_type { /** * Compare two memory regions of size `l` using case insensitive matching */ -gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l); +int rspamd_lc_cmp(const char *s, const char *d, gsize l); /** * Convert string to lowercase in-place using ASCII conversion */ -guint rspamd_str_lc(gchar *str, guint size); +unsigned int rspamd_str_lc(char *str, unsigned int size); /** * Performs ascii copy & lowercase @@ -49,26 +49,26 @@ guint rspamd_str_lc(gchar *str, guint size); * @param size * @return */ -gsize rspamd_str_copy_lc(const gchar *src, gchar *dst, gsize size); +gsize rspamd_str_copy_lc(const char *src, char *dst, gsize size); /** * Convert string to lowercase in-place using utf (limited) conversion */ -guint rspamd_str_lc_utf8(gchar *str, guint size); +unsigned int rspamd_str_lc_utf8(char *str, unsigned int size); /* * Hash table utility functions for case insensitive hashing */ -uint64_t rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed); +uint64_t rspamd_icase_hash(const char *in, gsize len, uint64_t seed); -guint rspamd_strcase_hash(gconstpointer key); +unsigned int rspamd_strcase_hash(gconstpointer key); gboolean rspamd_strcase_equal(gconstpointer v, gconstpointer v2); /* * Hash table utility functions for case sensitive hashing */ -guint rspamd_str_hash(gconstpointer key); +unsigned int rspamd_str_hash(gconstpointer key); gboolean rspamd_str_equal(gconstpointer v, gconstpointer v2); @@ -76,7 +76,7 @@ gboolean rspamd_str_equal(gconstpointer v, gconstpointer v2); /* * Hash table utility functions for hashing fixed strings */ -guint rspamd_ftok_icase_hash(gconstpointer key); +unsigned int rspamd_ftok_icase_hash(gconstpointer key); gboolean rspamd_ftok_icase_equal(gconstpointer v, gconstpointer v2); @@ -84,7 +84,7 @@ gboolean rspamd_ftok_icase_equal(gconstpointer v, gconstpointer v2); #define rspamd_ftok_hash(key) _wyhash32((key)->begin, (key)->len, 0) #define rspamd_ftok_equal(v1, v2) ((v1)->len == (v2)->len && memcmp((v1)->begin, (v2)->begin, (v1)->len) == 0) -guint rspamd_gstring_icase_hash(gconstpointer key); +unsigned int rspamd_gstring_icase_hash(gconstpointer key); gboolean rspamd_gstring_icase_equal(gconstpointer v, gconstpointer v2); @@ -98,9 +98,9 @@ gboolean rspamd_gstring_icase_equal(gconstpointer v, gconstpointer v2); * @param siz length of destination buffer * @return bytes copied */ -gsize rspamd_strlcpy_fast(gchar *dst, const gchar *src, gsize siz); +gsize rspamd_strlcpy_fast(char *dst, const char *src, gsize siz); -gsize rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz); +gsize rspamd_strlcpy_safe(char *dst, const char *src, gsize siz); #if defined(__has_feature) #if __has_feature(address_sanitizer) @@ -128,24 +128,24 @@ gsize rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz); * @param destlen * @return number of bytes copied */ -gsize rspamd_null_safe_copy(const gchar *src, gsize srclen, - gchar *dest, gsize destlen); +gsize rspamd_null_safe_copy(const char *src, gsize srclen, + char *dest, gsize destlen); /* * Try to convert string of length to long */ -gboolean rspamd_strtol(const gchar *s, gsize len, glong *value); +gboolean rspamd_strtol(const char *s, gsize len, glong *value); /* * Try to convert a string of length to unsigned long */ -gboolean rspamd_strtoul(const gchar *s, gsize len, gulong *value); -gboolean rspamd_strtou64(const gchar *s, gsize len, uint64_t *value); +gboolean rspamd_strtoul(const char *s, gsize len, gulong *value); +gboolean rspamd_strtou64(const char *s, gsize len, uint64_t *value); /* * Try to convert a hex string of length to unsigned long */ -gboolean rspamd_xstrtoul(const gchar *s, gsize len, gulong *value); +gboolean rspamd_xstrtoul(const char *s, gsize len, gulong *value); /** * Utility function to provide mem_pool copy for rspamd_hash_table_copy function @@ -161,7 +161,7 @@ gpointer rspamd_str_pool_copy(gconstpointer data, gpointer ud); * @param inlen input length * @return freshly allocated base32 encoding of a specified string */ -gchar *rspamd_encode_hex(const guchar *in, gsize inlen); +char *rspamd_encode_hex(const unsigned char *in, gsize inlen); /** * Decode string using hex encoding @@ -169,7 +169,7 @@ gchar *rspamd_encode_hex(const guchar *in, gsize inlen); * @param inlen input length * @return freshly allocated base32 decoded value or NULL if input is invalid */ -guchar *rspamd_decode_hex(const gchar *in, gsize inlen); +unsigned char *rspamd_decode_hex(const char *in, gsize inlen); enum rspamd_base32_type { RSPAMD_BASE32_DEFAULT = 0, @@ -184,7 +184,7 @@ enum rspamd_base32_type { * @param str * @return */ -enum rspamd_base32_type rspamd_base32_decode_type_from_str(const gchar *str); +enum rspamd_base32_type rspamd_base32_decode_type_from_str(const char *str); /** * Encode string using base32 encoding @@ -192,8 +192,8 @@ enum rspamd_base32_type rspamd_base32_decode_type_from_str(const gchar *str); * @param inlen input length * @return freshly allocated base32 encoding of a specified string */ -gchar *rspamd_encode_base32(const guchar *in, gsize inlen, - enum rspamd_base32_type type); +char *rspamd_encode_base32(const unsigned char *in, gsize inlen, + enum rspamd_base32_type type); /** * Decode string using base32 encoding @@ -201,7 +201,7 @@ gchar *rspamd_encode_base32(const guchar *in, gsize inlen, * @param inlen input length * @return freshly allocated base32 decoded value or NULL if input is invalid */ -guchar *rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen, enum rspamd_base32_type type); +unsigned char *rspamd_decode_base32(const char *in, gsize inlen, gsize *outlen, enum rspamd_base32_type type); /** * Encode string using base32 encoding @@ -211,8 +211,8 @@ guchar *rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen, enum r * @param outlen output buf len * @return encoded len if `outlen` is enough to encode `inlen` */ -gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out, - gsize outlen, enum rspamd_base32_type type); +int rspamd_encode_base32_buf(const unsigned char *in, gsize inlen, char *out, + gsize outlen, enum rspamd_base32_type type); /** * Decode string using base32 encoding @@ -222,8 +222,8 @@ gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out, * @param outlen output buf len * @return decoded len if in is valid base32 and `outlen` is enough to encode `inlen` */ -gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, - gsize outlen, enum rspamd_base32_type type); +int rspamd_decode_base32_buf(const char *in, gsize inlen, unsigned char *out, + gsize outlen, enum rspamd_base32_type type); /** * Encode string using hex encoding @@ -233,8 +233,8 @@ gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, * @param outlen output buf len * @return encoded len if `outlen` is enough to encode `inlen` */ -gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out, - gsize outlen); +int rspamd_encode_hex_buf(const unsigned char *in, gsize inlen, char *out, + gsize outlen); /** @@ -245,8 +245,8 @@ gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out, * @param outlen output buf len * @return decoded len if in is valid hex and `outlen` is enough to encode `inlen` */ -gssize rspamd_decode_hex_buf(const gchar *in, gsize inlen, - guchar *out, gsize outlen); +gssize rspamd_decode_hex_buf(const char *in, gsize inlen, + unsigned char *out, gsize outlen); /** * Common version of base64 encoder @@ -258,10 +258,10 @@ gssize rspamd_decode_hex_buf(const gchar *in, gsize inlen, * @param how * @return */ -gchar * -rspamd_encode_base64_common(const guchar *in, +char * +rspamd_encode_base64_common(const unsigned char *in, gsize inlen, - gint str_len, + int str_len, gsize *outlen, gboolean fold, enum rspamd_newlines_type how); @@ -273,8 +273,8 @@ rspamd_encode_base64_common(const guchar *in, * @param str_len maximum string length (if <= 0 then no lines are split) * @return freshly allocated base64 encoded value or NULL if input is invalid */ -gchar *rspamd_encode_base64(const guchar *in, gsize inlen, gint str_len, - gsize *outlen); +char *rspamd_encode_base64(const unsigned char *in, gsize inlen, int str_len, + gsize *outlen); /** * Encode and fold string using base64 encoding @@ -283,8 +283,8 @@ gchar *rspamd_encode_base64(const guchar *in, gsize inlen, gint str_len, * @param str_len maximum string length (if <= 0 then no lines are split) * @return freshly allocated base64 encoded value or NULL if input is invalid */ -gchar *rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len, - gsize *outlen, enum rspamd_newlines_type how); +char *rspamd_encode_base64_fold(const unsigned char *in, gsize inlen, int str_len, + gsize *outlen, enum rspamd_newlines_type how); /** * Encode and fold string using quoted printable encoding @@ -293,8 +293,8 @@ gchar *rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len, * @param str_len maximum string length (if <= 0 then no lines are split) * @return freshly allocated base64 encoded value or NULL if input is invalid */ -gchar *rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len, - gsize *outlen, enum rspamd_newlines_type how); +char *rspamd_encode_qp_fold(const unsigned char *in, gsize inlen, int str_len, + gsize *outlen, enum rspamd_newlines_type how); /** * Decode quoted-printable encoded buffer, input and output must not overlap @@ -304,8 +304,8 @@ gchar *rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len, * @param outlen length of output * @return real size of decoded output or (-1) if outlen is not enough */ -gssize rspamd_decode_qp_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen); +gssize rspamd_decode_qp_buf(const char *in, gsize inlen, + char *out, gsize outlen); /** * Decode uuencode encoded buffer, input and output must not overlap @@ -315,8 +315,8 @@ gssize rspamd_decode_qp_buf(const gchar *in, gsize inlen, * @param outlen length of output * @return real size of decoded output or (-1) if outlen is not enough */ -gssize rspamd_decode_uue_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen); +gssize rspamd_decode_uue_buf(const char *in, gsize inlen, + char *out, gsize outlen); /** * Decode quoted-printable encoded buffer using rfc2047 format, input and output must not overlap @@ -326,8 +326,8 @@ gssize rspamd_decode_uue_buf(const gchar *in, gsize inlen, * @param outlen length of output * @return real size of decoded output or (-1) if outlen is not enough */ -gssize rspamd_decode_qp2047_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen); +gssize rspamd_decode_qp2047_buf(const char *in, gsize inlen, + char *out, gsize outlen); /** * Encode quoted-printable buffer using rfc2047 format, input and output must not overlap @@ -337,8 +337,8 @@ gssize rspamd_decode_qp2047_buf(const gchar *in, gsize inlen, * @param outlen * @return */ -gssize rspamd_encode_qp2047_buf(const gchar *in, gsize inlen, - gchar *out, gsize outlen); +gssize rspamd_encode_qp2047_buf(const char *in, gsize inlen, + char *out, gsize outlen); #ifndef g_tolower #define g_tolower(x) (((x) >= 'A' && (x) <= 'Z') ? (x) - 'A' + 'a' : (x)) @@ -352,8 +352,8 @@ gssize rspamd_encode_qp2047_buf(const gchar *in, gsize inlen, * @param s2len * @return */ -gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len, - const gchar *s2, gsize s2len, guint replace_cost); +int rspamd_strings_levenshtein_distance(const char *s1, gsize s1len, + const char *s2, gsize s2len, unsigned int replace_cost); /** * Fold header using rfc822 rules, return new GString from the previous one @@ -364,13 +364,13 @@ gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len, * @param fold_on_chars * @return new GString with the folded value */ -GString *rspamd_header_value_fold(const gchar *name, +GString *rspamd_header_value_fold(const char *name, gsize name_len, - const gchar *value, + const char *value, gsize value_len, - guint fold_max, + unsigned int fold_max, enum rspamd_newlines_type how, - const gchar *fold_on_chars); + const char *fold_on_chars); /** * Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm @@ -381,8 +381,8 @@ GString *rspamd_header_value_fold(const gchar *name, * @param srchlen length of the search string * @return position of the first substring match or (-1) if not found */ -goffset rspamd_substring_search(const gchar *in, gsize inlen, - const gchar *srch, gsize srchlen); +goffset rspamd_substring_search(const char *in, gsize inlen, + const char *srch, gsize srchlen); /** * Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm in caseless matter (ASCII only) @@ -393,8 +393,8 @@ goffset rspamd_substring_search(const gchar *in, gsize inlen, * @param srchlen length of the search string * @return position of the first substring match or (-1) if not found */ -goffset rspamd_substring_search_caseless(const gchar *in, gsize inlen, - const gchar *srch, gsize srchlen); +goffset rspamd_substring_search_caseless(const char *in, gsize inlen, + const char *srch, gsize srchlen); /** * Search for end-of-headers mark in the input string. Returns position just after @@ -435,7 +435,7 @@ void rspamd_ucl_emit_fstring_comments(const ucl_object_t *obj, rspamd_fstring_t **target, const ucl_object_t *comments); -extern const guchar lc_map[256]; +extern const unsigned char lc_map[256]; /** * Search for the last occurrence of character `c` in memory block of size `len` @@ -447,7 +447,7 @@ extern const guchar lc_map[256]; #ifdef HAVE_MEMRCHR #define rspamd_memrchr memrchr #else -void *rspamd_memrchr(const void *m, gint c, gsize len); +void *rspamd_memrchr(const void *m, int c, gsize len); #endif /** @@ -457,7 +457,7 @@ void *rspamd_memrchr(const void *m, gint c, gsize len); * @param len length of `s` * @return segment size */ -gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len); +gsize rspamd_memcspn(const char *s, const char *e, gsize len); /** * Return length of memory segment starting in `s` that contains only chars from `e` @@ -466,7 +466,7 @@ gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len); * @param len length of `s` * @return segment size */ -gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len); +gsize rspamd_memspn(const char *s, const char *e, gsize len); /* https://graphics.stanford.edu/~seander/bithacks.html#HasMoreInWord */ #define rspamd_str_hasmore(x, n) ((((x) + ~0UL / 255 * (127 - (n))) | (x)) & ~0UL / 255 * 128) @@ -475,7 +475,7 @@ gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len); */ #define rspamd_is_aligned(p, n) (((uintptr_t) (p) & ((uintptr_t) (n) -1)) == 0) #define rspamd_is_aligned_as(p, v) rspamd_is_aligned(p, RSPAMD_ALIGNOF(__typeof((v)))) -gboolean rspamd_str_has_8bit(const guchar *beg, gsize len); +gboolean rspamd_str_has_8bit(const unsigned char *beg, gsize len); struct UConverter; @@ -501,8 +501,8 @@ enum rspamd_regexp_escape_flags { * @param allow_glob allow glob expressions to be translated into pcre * @return newly allocated zero terminated escaped pattern */ -gchar * -rspamd_str_regexp_escape(const gchar *pattern, gsize slen, +char * +rspamd_str_regexp_escape(const char *pattern, gsize slen, gsize *dst_len, enum rspamd_regexp_escape_flags flags) G_GNUC_WARN_UNUSED_RESULT; /** @@ -513,23 +513,23 @@ rspamd_str_regexp_escape(const gchar *pattern, gsize slen, * @param dstelen * @return */ -gchar *rspamd_str_make_utf_valid(const guchar *src, gsize slen, gsize *dstlen, - rspamd_mempool_t *pool) G_GNUC_WARN_UNUSED_RESULT; +char *rspamd_str_make_utf_valid(const unsigned char *src, gsize slen, gsize *dstlen, + rspamd_mempool_t *pool) G_GNUC_WARN_UNUSED_RESULT; /** * Strips characters in `strip_chars` from start and end of the GString * @param s * @param strip_chars */ -gsize rspamd_gstring_strip(GString *s, const gchar *strip_chars); +gsize rspamd_gstring_strip(GString *s, const char *strip_chars); /** * Strips characters in `strip_chars` from start and end of the sized string * @param s * @param strip_chars */ -const gchar *rspamd_string_len_strip(const gchar *in, - gsize *len, const gchar *strip_chars) G_GNUC_WARN_UNUSED_RESULT; +const char *rspamd_string_len_strip(const char *in, + gsize *len, const char *strip_chars) G_GNUC_WARN_UNUSED_RESULT; /** * Returns a NULL terminated list of zero terminated strings based on splitting of @@ -542,8 +542,8 @@ const gchar *rspamd_string_len_strip(const gchar *in, * @param max_elts * @return */ -gchar **rspamd_string_len_split(const gchar *in, gsize len, - const gchar *spill, gint max_elts, rspamd_mempool_t *pool); +char **rspamd_string_len_split(const char *in, gsize len, + const char *spill, int max_elts, rspamd_mempool_t *pool); #define IS_ZERO_WIDTH_SPACE(uc) ((uc) == 0x200B || \ (uc) == 0x200C || \ |