From 0f4779e2a095b72b7ec7fc0f2abe2cc57f152b76 Mon Sep 17 00:00:00 2001 From: default Date: Sat, 8 Oct 2022 07:00:05 +0200 Subject: [PATCH] Backport from xs. --- xs.h | 26 +++++++++++++------------- xs_mime.h | 4 ++-- xs_openssl.h | 16 ++++++++-------- xs_set.h | 6 +++--- xs_socket.h | 4 ++-- xs_version.h | 1 + 6 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 xs_version.h diff --git a/xs.h b/xs.h index 89f2ca9..45abfae 100644 --- a/xs.h +++ b/xs.h @@ -41,7 +41,7 @@ void _xs_destroy(char **var); #define xs_debug() raise(SIGTRAP) xstype xs_type(const char *data); int xs_size(const char *data); -int xs_is_null(char *data); +int xs_is_null(const char *data); d_char *xs_dup(const char *data); void *xs_realloc(void *ptr, size_t size); d_char *xs_expand(d_char *data, int offset, int size); @@ -54,9 +54,9 @@ d_char *xs_str_new(const char *str); d_char *xs_replace_i(d_char *str, const char *sfrom, const char *sto); #define xs_replace(str, sfrom, sto) xs_replace_i(xs_dup(str), sfrom, sto) d_char *xs_fmt(const char *fmt, ...); -int xs_str_in(char *haystack, char *needle); -int xs_startswith(char *str, char *prefix); -int xs_endswith(char *str, char *postfix); +int xs_str_in(const char *haystack, const char *needle); +int xs_startswith(const char *str, const char *prefix); +int xs_endswith(const char *str, const char *postfix); d_char *xs_crop(d_char *str, int start, int end); d_char *xs_strip(d_char *str); d_char *xs_tolower(d_char *str); @@ -79,8 +79,8 @@ d_char *xs_dict_del(d_char *dict, const char *key); d_char *xs_dict_set(d_char *dict, const char *key, const char *data); d_char *xs_val_new(xstype t); d_char *xs_number_new(double f); -double xs_number_get(char *v); -char *xs_number_str(char *v); +double xs_number_get(const char *v); +const char *xs_number_str(const char *v); extern int _xs_debug; @@ -189,7 +189,7 @@ int xs_size(const char *data) } -int xs_is_null(char *data) +int xs_is_null(const char *data) /* checks for null */ { return !!(data == NULL || xs_type(data) == XSTYPE_NULL); @@ -323,7 +323,7 @@ d_char *xs_fmt(const char *fmt, ...) } -int xs_str_in(char *haystack, char *needle) +int xs_str_in(const char *haystack, const char *needle) /* finds needle in haystack and returns the offset or -1 */ { char *s; @@ -336,14 +336,14 @@ int xs_str_in(char *haystack, char *needle) } -int xs_startswith(char *str, char *prefix) +int xs_startswith(const char *str, const char *prefix) /* returns true if str starts with prefix */ { return !!(xs_str_in(str, prefix) == 0); } -int xs_endswith(char *str, char *postfix) +int xs_endswith(const char *str, const char *postfix) /* returns true if str ends with postfix */ { int ssz = strlen(str); @@ -732,7 +732,7 @@ d_char *xs_number_new(double f) } -double xs_number_get(char *v) +double xs_number_get(const char *v) /* gets the number as a double */ { double f = 0.0; @@ -744,10 +744,10 @@ double xs_number_get(char *v) } -char *xs_number_str(char *v) +const char *xs_number_str(const char *v) /* gets the number as a string */ { - char *p = NULL; + const char *p = NULL; if (v[0] == XSTYPE_NUMBER) p = &v[1]; diff --git a/xs_mime.h b/xs_mime.h index 699ab39..072a98a 100644 --- a/xs_mime.h +++ b/xs_mime.h @@ -4,7 +4,7 @@ #define _XS_MIME -char *xs_mime_by_ext(char *file); +char *xs_mime_by_ext(const char *file); #ifdef XS_IMPLEMENTATION @@ -27,7 +27,7 @@ struct _mime_info { }; -char *xs_mime_by_ext(char *file) +char *xs_mime_by_ext(const char *file) /* returns the MIME type by file extension */ { struct _mime_info *mi = mime_info; diff --git a/xs_openssl.h b/xs_openssl.h index 9b0f71e..0652637 100644 --- a/xs_openssl.h +++ b/xs_openssl.h @@ -9,10 +9,10 @@ d_char *xs_sha1_hex(const void *input, int size); d_char *xs_sha256_hex(const void *input, int size); d_char *xs_sha256_base64(const void *input, int size); d_char *xs_rsa_genkey(int bits); -d_char *xs_rsa_sign(char *secret, char *mem, int size); -int xs_rsa_verify(char *pubkey, char *mem, int size, char *b64sig); -d_char *xs_evp_sign(char *secret, char *mem, int size); -int xs_evp_verify(char *pubkey, char *mem, int size, char *b64sig); +d_char *xs_rsa_sign(const char *secret, const char *mem, int size); +int xs_rsa_verify(const char *pubkey, const char *mem, int size, const char *b64sig); +d_char *xs_evp_sign(const char *secret, const char *mem, int size); +int xs_evp_verify(const char *pubkey, const char *mem, int size, const char *b64sig); #ifdef XS_IMPLEMENTATION @@ -119,7 +119,7 @@ d_char *xs_rsa_genkey(int bits) } -d_char *xs_rsa_sign(char *secret, char *mem, int size) +d_char *xs_rsa_sign(const char *secret, const char *mem, int size) /* signs a memory block (secret is in PEM format) */ { d_char *signature = NULL; @@ -146,7 +146,7 @@ d_char *xs_rsa_sign(char *secret, char *mem, int size) } -int xs_rsa_verify(char *pubkey, char *mem, int size, char *b64sig) +int xs_rsa_verify(const char *pubkey, const char *mem, int size, const char *b64sig) /* verifies a base64 block, returns non-zero on ok */ { int r = 0; @@ -176,7 +176,7 @@ int xs_rsa_verify(char *pubkey, char *mem, int size, char *b64sig) } -d_char *xs_evp_sign(char *secret, char *mem, int size) +d_char *xs_evp_sign(const char *secret, const char *mem, int size) /* signs a memory block (secret is in PEM format) */ { d_char *signature = NULL; @@ -217,7 +217,7 @@ d_char *xs_evp_sign(char *secret, char *mem, int size) } -int xs_evp_verify(char *pubkey, char *mem, int size, char *b64sig) +int xs_evp_verify(const char *pubkey, const char *mem, int size, const char *b64sig) /* verifies a base64 block, returns non-zero on ok */ { int r = 0; diff --git a/xs_set.h b/xs_set.h index 7d7a762..2beb454 100644 --- a/xs_set.h +++ b/xs_set.h @@ -13,7 +13,7 @@ typedef struct _xs_set { xs_set *xs_set_new(int elems); void xs_set_free(xs_set *s); -int xs_set_add(xs_set *s, char *data); +int xs_set_add(xs_set *s, const char *data); #ifdef XS_IMPLEMENTATION @@ -40,7 +40,7 @@ void xs_set_free(xs_set *s) } -unsigned int _xs_set_hash(char *data, int size) +unsigned int _xs_set_hash(const char *data, int size) { unsigned int hash = 0x666; int n; @@ -54,7 +54,7 @@ unsigned int _xs_set_hash(char *data, int size) } -int xs_set_add(xs_set *s, char *data) +int xs_set_add(xs_set *s, const char *data) /* adds the data to the set */ /* returns: 1 if added, 0 if already there, -1 if it's full */ { diff --git a/xs_socket.h b/xs_socket.h index a3fe6a4..d2853a2 100644 --- a/xs_socket.h +++ b/xs_socket.h @@ -5,7 +5,7 @@ #define _XS_SOCKET_H int xs_socket_timeout(int s, double rto, double sto); -int xs_socket_server(char *addr, int port); +int xs_socket_server(const char *addr, int port); FILE *xs_socket_accept(int rs); @@ -40,7 +40,7 @@ int xs_socket_timeout(int s, double rto, double sto) } -int xs_socket_server(char *addr, int port) +int xs_socket_server(const char *addr, int port) /* opens a server socket */ { int rs = -1; diff --git a/xs_version.h b/xs_version.h new file mode 100644 index 0000000..ca721ea --- /dev/null +++ b/xs_version.h @@ -0,0 +1 @@ +/* b6512569814e4b409191a24193abe54d00427df2 */