mirror of
https://github.com/weechat/weechat.git
synced 2026-06-27 21:36:37 +02:00
api: add functions string_base_{encode,decode}, remove functions string_{encode,decode}_base64
This commit is contained in:
+12
-11
@@ -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;
|
||||
|
||||
@@ -94,6 +94,45 @@ plugin_api_ngettext (const char *single, const char *plural, int count)
|
||||
return NG_(single, plural, 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.
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
@@ -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, \
|
||||
|
||||
Reference in New Issue
Block a user