1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 20:36:38 +02:00

core: merge functions string_hash_binary and string_hash into a single function string_hash

This commit is contained in:
Sébastien Helleu
2020-03-01 16:41:28 +01:00
parent 1ae2591458
commit c4ef3d6c2e
15 changed files with 305 additions and 675 deletions
-1
View File
@@ -623,7 +623,6 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->string_base_encode = &plugin_api_string_base_encode;
new_plugin->string_base_decode = &plugin_api_string_base_decode;
new_plugin->string_hex_dump = &string_hex_dump;
new_plugin->string_hash_binary = &string_hash_binary;
new_plugin->string_hash = &string_hash;
new_plugin->string_is_command_char = &string_is_command_char;
new_plugin->string_input_for_buffer = &string_input_for_buffer;
+2 -5
View File
@@ -187,7 +187,7 @@ char *
relay_websocket_build_handshake (struct t_relay_client *client)
{
const char *sec_websocket_key;
char *key, sec_websocket_accept[128], handshake[1024], *hash;
char *key, sec_websocket_accept[128], handshake[1024], hash[160 / 8];
int length, length_hash;
sec_websocket_key = weechat_hashtable_get (client->http_headers,
@@ -207,9 +207,7 @@ relay_websocket_build_handshake (struct t_relay_client *client)
snprintf (key, length, "%s%s", sec_websocket_key, WEBSOCKET_GUID);
/* compute 160-bit SHA1 on the key and encode it with base64 */
weechat_string_hash_binary (key, strlen (key), "sha1",
&hash, &length_hash);
if (!hash)
if (!weechat_string_hash (key, strlen (key), "sha1", hash, &length_hash))
{
free (key);
return NULL;
@@ -220,7 +218,6 @@ relay_websocket_build_handshake (struct t_relay_client *client)
sec_websocket_accept[0] = '\0';
}
free (hash);
free (key);
/* build the handshake (it will be sent as-is to client) */
+10 -3
View File
@@ -755,7 +755,8 @@ script_repo_sha512sum_file (const char *filename)
{
struct stat st;
FILE *file;
char *data, *hash;
char *data, hash[512 / 8], hash_hexa[((512 / 8) * 2) + 1];
int length_hash;
if (stat (filename, &st) == -1)
return NULL;
@@ -773,11 +774,17 @@ script_repo_sha512sum_file (const char *filename)
}
fclose (file);
hash = weechat_string_hash (data, st.st_size, "sha512");
if (!weechat_string_hash (data, st.st_size, "sha512", hash, &length_hash))
{
free (data);
return NULL;
}
weechat_string_base_encode (16, hash, length_hash, hash_hexa);
weechat_string_tolower (hash_hexa);
free (data);
return hash;
return strdup (hash_hexa);
}
/*
+7 -13
View File
@@ -67,7 +67,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
#define WEECHAT_PLUGIN_API_VERSION "20200229-01"
#define WEECHAT_PLUGIN_API_VERSION "20200301-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -341,11 +341,8 @@ struct t_weechat_plugin
char *(*string_hex_dump) (const char *data, int data_size,
int bytes_per_line, const char *prefix,
const char *suffix);
void (*string_hash_binary) (const char *data, int length_data,
const char *hash_algo,
char **hash, int *length_hash);
char *(*string_hash) (const char *data, int length_data,
const char *hash_algo);
int (*string_hash) (const void *data, int data_size,
const char *hash_algo, void *hash, int *hash_size);
int (*string_is_command_char) (const char *string);
const char *(*string_input_for_buffer) (const char *string);
char *(*string_eval_expression )(const char *expr,
@@ -1259,13 +1256,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
(weechat_plugin->string_hex_dump)(__data, __data_size, \
__bytes_per_line, __prefix, \
__suffix)
#define weechat_string_hash_binary(__data, __length_data, __hash_algo, \
__hash, __length_hash) \
(weechat_plugin->string_hash_binary)(__data, __length_data, \
__hash_algo, \
__hash, __length_hash)
#define weechat_string_hash(__data, __length_data, __hash_algo) \
(weechat_plugin->string_hash)(__data, __length_data, __hash_algo)
#define weechat_string_hash(__data, __data_size, __hash_algo, \
__hash, __hash_size) \
(weechat_plugin->string_hash)(__data, __data_size, __hash_algo, \
__hash, __hash_size)
#define weechat_string_is_command_char(__string) \
(weechat_plugin->string_is_command_char)(__string)
#define weechat_string_input_for_buffer(__string) \