diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-network.c | 2 | ||||
-rw-r--r-- | src/core/wee-secure-config.c | 4 | ||||
-rw-r--r-- | src/core/wee-secure.c | 6 | ||||
-rw-r--r-- | src/core/wee-string.c | 12 | ||||
-rw-r--r-- | src/core/wee-string.h | 12 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-window.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-sasl.c | 23 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 39 | ||||
-rw-r--r-- | src/plugins/plugin-api.h | 4 | ||||
-rw-r--r-- | src/plugins/plugin.c | 4 | ||||
-rw-r--r-- | src/plugins/relay/relay-websocket.c | 4 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 16 |
12 files changed, 87 insertions, 41 deletions
diff --git a/src/core/wee-network.c b/src/core/wee-network.c index dcb8e174d..8fd45d690 100644 --- a/src/core/wee-network.c +++ b/src/core/wee-network.c @@ -267,7 +267,7 @@ network_pass_httpproxy (struct t_proxy *proxy, int sock, const char *address, snprintf (authbuf, sizeof (authbuf), "%s:%s", username, password); free (username); free (password); - if (string_encode_base64 (authbuf, strlen (authbuf), authbuf_base64) < 0) + if (string_base64_encode (authbuf, strlen (authbuf), authbuf_base64) < 0) return 0; length = snprintf (buffer, sizeof (buffer), "CONNECT %s:%d HTTP/1.0\r\nProxy-Authorization: " diff --git a/src/core/wee-secure-config.c b/src/core/wee-secure-config.c index 5e1332019..4ee1f1112 100644 --- a/src/core/wee-secure-config.c +++ b/src/core/wee-secure-config.c @@ -274,7 +274,7 @@ secure_config_data_read_cb (const void *pointer, void *data, if (!buffer) return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - length_buffer = string_decode_base16 (value, buffer); + length_buffer = string_base16_decode (value, buffer); while (1) { decrypted = NULL; @@ -370,7 +370,7 @@ secure_config_data_write_map_cb (void *data, buffer_base16 = malloc ((length_buffer * 2) + 1); if (buffer_base16) { - if (string_encode_base16 (buffer, length_buffer, + if (string_base16_encode (buffer, length_buffer, buffer_base16) >= 0) { config_file_write_line (config_file, key, diff --git a/src/core/wee-secure.c b/src/core/wee-secure.c index b9abe62c9..84680bec8 100644 --- a/src/core/wee-secure.c +++ b/src/core/wee-secure.c @@ -466,7 +466,7 @@ secure_decrypt_data_not_decrypted (const char *passphrase) buffer = malloc (strlen (value) + 1); if (buffer) { - length_buffer = string_decode_base16 (value, buffer); + length_buffer = string_base16_decode (value, buffer); decrypted = NULL; length_decrypted = 0; rc = secure_decrypt_data ( @@ -595,7 +595,7 @@ secure_totp_generate (const char *secret_base32, time_t totp_time, int digits) if (!secret) goto error; - length_secret = string_decode_base32 (secret_base32, secret); + length_secret = string_base32_decode (secret_base32, secret); if (length_secret < 0) goto error; @@ -654,7 +654,7 @@ secure_totp_validate (const char *secret_base32, time_t totp_time, int window, if (!secret) goto error; - length_secret = string_decode_base32 (secret_base32, secret); + length_secret = string_base32_decode (secret_base32, secret); if (length_secret < 0) goto error; diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 32afd060e..016f93f04 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -2707,7 +2707,7 @@ string_format_size (unsigned long long size) */ int -string_encode_base16 (const char *from, int length, char *to) +string_base16_encode (const char *from, int length, char *to) { int i, count; const char *hexa = "0123456789ABCDEF"; @@ -2734,7 +2734,7 @@ string_encode_base16 (const char *from, int length, char *to) */ int -string_decode_base16 (const char *from, char *to) +string_base16_decode (const char *from, char *to) { int length, i, pos, count; unsigned char value; @@ -2803,7 +2803,7 @@ string_decode_base16 (const char *from, char *to) */ int -string_encode_base32 (const char *from, int length, char *to) +string_base32_encode (const char *from, int length, char *to) { unsigned char base32_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; int count, value, next, bits_left, pad, index; @@ -2880,7 +2880,7 @@ string_encode_base32 (const char *from, int length, char *to) */ int -string_decode_base32 (const char *from, char *to) +string_base32_decode (const char *from, char *to) { const char *ptr_from; int value, bits_left, count; @@ -2956,7 +2956,7 @@ string_convbase64_8x3_to_6x4 (const char *from, char *to) */ int -string_encode_base64 (const char *from, int length, char *to) +string_base64_encode (const char *from, int length, char *to) { const char *ptr_from; char rest[3]; @@ -3027,7 +3027,7 @@ string_convbase64_6x4_to_8x3 (const unsigned char *from, unsigned char *to) */ int -string_decode_base64 (const char *from, char *to) +string_base64_decode (const char *from, char *to) { const char *ptr_from; int length, to_length, i; diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 4709f73d7..6d059f8fa 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -105,12 +105,12 @@ extern char *string_iconv_from_internal (const char *charset, const char *string); extern int string_fprintf (FILE *file, const char *data, ...); extern char *string_format_size (unsigned long long size); -extern int string_encode_base16 (const char *from, int length, char *to); -extern int string_decode_base16 (const char *from, char *to); -extern int string_encode_base32 (const char *from, int length, char *to); -extern int string_decode_base32 (const char *from, char *to); -extern int string_encode_base64 (const char *from, int length, char *to); -extern int string_decode_base64 (const char *from, char *to); +extern int string_base16_encode (const char *from, int length, char *to); +extern int string_base16_decode (const char *from, char *to); +extern int string_base32_encode (const char *from, int length, char *to); +extern int string_base32_decode (const char *from, char *to); +extern int string_base64_encode (const char *from, int length, char *to); +extern int string_base64_decode (const char *from, char *to); extern char *string_hex_dump (const char *data, int data_size, int bytes_per_line, const char *prefix, const char *suffix); diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index e9ff4aae3..a177e2f95 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -2509,7 +2509,7 @@ gui_window_send_clipboard (const char *storage_unit, const char *text) text_base64 = malloc ((length * 4) + 1); if (text_base64) { - if (string_encode_base64 (text, length, text_base64) >= 0) + if (string_base64_encode (text, length, text_base64) >= 0) { fprintf (stderr, "\033]52;%s;%s\a", (storage_unit) ? storage_unit : "", diff --git a/src/plugins/irc/irc-sasl.c b/src/plugins/irc/irc-sasl.c index 63d9bf6e5..718e59e90 100644 --- a/src/plugins/irc/irc-sasl.c +++ b/src/plugins/irc/irc-sasl.c @@ -73,8 +73,8 @@ irc_sasl_mechanism_plain (const char *sasl_username, const char *sasl_password) answer_base64 = malloc (length * 4); if (answer_base64) { - if (weechat_string_encode_base64 (string, length - 1, - answer_base64) < 0) + if (weechat_string_base_encode (64, string, length - 1, + answer_base64) < 0) { free (answer_base64); answer_base64 = NULL; @@ -180,7 +180,7 @@ irc_sasl_mechanism_ecdsa_nist256p_challenge (struct t_irc_server *server, data = malloc (strlen (data_base64) + 1); if (!data) return NULL; - length_data = weechat_string_decode_base64 (data_base64, data); + length_data = weechat_string_base_decode (64, data_base64, data); /* read file with private key */ str_privkey = irc_sasl_get_key_content (server, sasl_key); @@ -226,8 +226,8 @@ irc_sasl_mechanism_ecdsa_nist256p_challenge (struct t_irc_server *server, pubkey_base64 = malloc ((x.size + 1 + 1) * 4); if (pubkey_base64) { - if (weechat_string_encode_base64 (pubkey, x.size + 1, - pubkey_base64) >= 0) + if (weechat_string_base_encode (64, pubkey, x.size + 1, + pubkey_base64) >= 0) { weechat_printf ( server->buffer, @@ -299,7 +299,8 @@ irc_sasl_mechanism_ecdsa_nist256p_challenge (struct t_irc_server *server, answer_base64 = malloc ((length + 1) * 4); if (answer_base64) { - if (weechat_string_encode_base64 (string, length, answer_base64) < 0) + if (weechat_string_base_encode (64, string, length, + answer_base64) < 0) { free (answer_base64); answer_base64 = NULL; @@ -364,7 +365,7 @@ irc_sasl_dh (const char *data_base64, data = malloc (strlen (data_base64) + 1); if (!data) goto dhend; - length_data = weechat_string_decode_base64 (data_base64, data); + length_data = weechat_string_base_decode (64, data_base64, data); ptr_data = (unsigned char *)data; /* extract prime number */ @@ -520,8 +521,8 @@ irc_sasl_mechanism_dh_blowfish (const char *data_base64, answer_base64 = malloc ((length_answer + 1) * 4); if (answer_base64) { - if (weechat_string_encode_base64 (answer, length_answer, - answer_base64) < 0) + if (weechat_string_base_encode (64, answer, length_answer, + answer_base64) < 0) { free (answer_base64); answer_base64 = NULL; @@ -649,8 +650,8 @@ irc_sasl_mechanism_dh_aes (const char *data_base64, answer_base64 = malloc ((length_answer + 1) * 4); if (answer_base64) { - if (weechat_string_encode_base64 (answer, length_answer, - answer_base64) < 0) + if (weechat_string_base_encode (64, answer, length_answer, + answer_base64) < 0) { free (answer_base64); answer_base64 = NULL; diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 2ac0a8eeb..646fb9f9a 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -95,6 +95,45 @@ plugin_api_ngettext (const char *single, const char *plural, int count) } /* + * Encodes a string in base 16, 32, or 64. + */ + +int +plugin_api_string_base_encode (int base, const char *from, int length, + char *to) +{ + switch (base) + { + case 16: + return string_base16_encode (from, length, to); + case 32: + return string_base32_encode (from, length, to); + case 64: + return string_base64_encode (from, length, to); + } + return -1; +} + +/* + * Decodes a string encoded in base 16, 32, or 64. + */ + +int +plugin_api_string_base_decode (int base, const char *from, char *to) +{ + switch (base) + { + case 16: + return string_base16_decode (from, to); + case 32: + return string_base32_decode (from, to); + case 64: + return string_base64_decode (from, to); + } + return -1; +} + +/* * Frees an option. */ diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h index c754fe243..29764096e 100644 --- a/src/plugins/plugin-api.h +++ b/src/plugins/plugin-api.h @@ -28,6 +28,10 @@ extern void plugin_api_charset_set (struct t_weechat_plugin *plugin, extern const char *plugin_api_gettext (const char *string); extern const char *plugin_api_ngettext (const char *single, const char *plural, int count); +extern int plugin_api_string_base_encode (int base, const char *from, + int length, char *to); +extern int plugin_api_string_base_decode (int base, const char *from, + char *to); /* config */ extern void plugin_api_config_file_option_free (struct t_config_option *option); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 84e2e3a2c..d57b4d331 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -636,8 +636,8 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv) new_plugin->string_free_split_command = &string_free_split_command; new_plugin->string_format_size = &string_format_size; new_plugin->string_remove_color = &gui_color_decode; - new_plugin->string_encode_base64 = &string_encode_base64; - new_plugin->string_decode_base64 = &string_decode_base64; + 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_is_command_char = &string_is_command_char; new_plugin->string_input_for_buffer = &string_input_for_buffer; diff --git a/src/plugins/relay/relay-websocket.c b/src/plugins/relay/relay-websocket.c index 60c4f4526..c0398061e 100644 --- a/src/plugins/relay/relay-websocket.c +++ b/src/plugins/relay/relay-websocket.c @@ -214,8 +214,8 @@ relay_websocket_build_handshake (struct t_relay_client *client) length = gcry_md_get_algo_dlen (GCRY_MD_SHA1); gcry_md_write (hd, key, strlen (key)); result = gcry_md_read (hd, GCRY_MD_SHA1); - if (weechat_string_encode_base64 ((char *)result, length, - sec_websocket_accept) < 0) + if (weechat_string_base_encode (64, (char *)result, length, + sec_websocket_accept) < 0) { sec_websocket_accept[0] = '\0'; } diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 94aa54598..a05082b9a 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -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 "20181102-01" +#define WEECHAT_PLUGIN_API_VERSION "20181104-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -323,8 +323,9 @@ struct t_weechat_plugin void (*string_free_split_command) (char **split_command); char *(*string_format_size) (unsigned long long size); char *(*string_remove_color) (const char *string, const char *replacement); - int (*string_encode_base64) (const char *from, int length, char *to); - int (*string_decode_base64) (const char *from, char *to); + int (*string_base_encode) (int base, const char *from, int length, + char *to); + int (*string_base_decode) (int base, const char *from, char *to); char *(*string_hex_dump) (const char *data, int data_size, int bytes_per_line, const char *prefix, const char *suffix); @@ -1224,10 +1225,11 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); (weechat_plugin->string_format_size)(__size) #define weechat_string_remove_color(__string, __replacement) \ (weechat_plugin->string_remove_color)(__string, __replacement) -#define weechat_string_encode_base64(__from, __length, __to) \ - (weechat_plugin->string_encode_base64)(__from, __length, __to) -#define weechat_string_decode_base64(__from, __to) \ - (weechat_plugin->string_decode_base64)(__from, __to) +#define weechat_string_base_encode(__base, __from, __length, __to) \ + (weechat_plugin->string_base_encode)(__base, __from, __length, \ + __to) +#define weechat_string_base_decode(__base, __from, __to) \ + (weechat_plugin->string_base_decode)(__base, __from, __to) #define weechat_string_hex_dump(__data, __data_size, __bytes_per_line, \ __prefix, __suffix) \ (weechat_plugin->string_hex_dump)(__data, __data_size, \ |