mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 23:36:37 +02:00
Charsets are now checked when set by /charset command
This commit is contained in:
+36
-11
@@ -1837,11 +1837,32 @@ weechat_cmd_charset_display (t_gui_buffer *buffer)
|
||||
|
||||
/*
|
||||
* weechat_cmd_charset_set: set a charset for server or channel
|
||||
* from_internal == 1 if charset is used to encode data,
|
||||
* 0 if charset is used to decode data
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_cmd_charset_set (t_gui_buffer *buffer, char **string, char *charset)
|
||||
int
|
||||
weechat_cmd_charset_set (t_gui_buffer *buffer, char **string, char *charset,
|
||||
int from_internal)
|
||||
{
|
||||
int iconv_ok;
|
||||
|
||||
if (charset)
|
||||
{
|
||||
if (from_internal)
|
||||
iconv_ok = weechat_iconv_check (NULL, charset);
|
||||
else
|
||||
iconv_ok = weechat_iconv_check (charset, NULL);
|
||||
|
||||
if (!iconv_ok)
|
||||
{
|
||||
irc_display_prefix (NULL, NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s charset \"%s\" is not available\n"),
|
||||
WEECHAT_ERROR, charset);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (BUFFER_IS_SERVER(buffer))
|
||||
{
|
||||
if (charset)
|
||||
@@ -1859,6 +1880,7 @@ weechat_cmd_charset_set (t_gui_buffer *buffer, char **string, char *charset)
|
||||
config_option_list_remove (string, CHANNEL(buffer)->name);
|
||||
weechat_cmd_charset_display (buffer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1870,6 +1892,7 @@ weechat_cmd_charset (t_irc_server *server, t_irc_channel *channel,
|
||||
int argc, char **argv)
|
||||
{
|
||||
t_gui_buffer *buffer;
|
||||
int rc;
|
||||
|
||||
irc_find_context (server, channel, NULL, &buffer);
|
||||
|
||||
@@ -1878,17 +1901,17 @@ weechat_cmd_charset (t_irc_server *server, t_irc_channel *channel,
|
||||
else
|
||||
{
|
||||
if (ascii_strcasecmp (argv[0], "decode_iso") == 0)
|
||||
weechat_cmd_charset_set (buffer,
|
||||
&(SERVER(buffer)->charset_decode_iso),
|
||||
(argc > 1) ? argv[1] : NULL);
|
||||
rc = weechat_cmd_charset_set (buffer,
|
||||
&(SERVER(buffer)->charset_decode_iso),
|
||||
(argc > 1) ? argv[1] : NULL, 0);
|
||||
else if (ascii_strcasecmp (argv[0], "decode_utf") == 0)
|
||||
weechat_cmd_charset_set (buffer,
|
||||
&(SERVER(buffer)->charset_decode_utf),
|
||||
(argc > 1) ? argv[1] : NULL);
|
||||
rc = weechat_cmd_charset_set (buffer,
|
||||
&(SERVER(buffer)->charset_decode_utf),
|
||||
(argc > 1) ? argv[1] : NULL, 0);
|
||||
else if (ascii_strcasecmp (argv[0], "encode") == 0)
|
||||
weechat_cmd_charset_set (buffer,
|
||||
&(SERVER(buffer)->charset_encode),
|
||||
(argc > 1) ? argv[1] : NULL);
|
||||
rc = weechat_cmd_charset_set (buffer,
|
||||
&(SERVER(buffer)->charset_encode),
|
||||
(argc > 1) ? argv[1] : NULL, 1);
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, NULL, PREFIX_ERROR);
|
||||
@@ -1897,6 +1920,8 @@ weechat_cmd_charset (t_irc_server *server, t_irc_channel *channel,
|
||||
WEECHAT_ERROR, "charset");
|
||||
return -1;
|
||||
}
|
||||
if (rc < 0)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -274,6 +274,35 @@ weechat_iconv (char *from_code, char *to_code, char *string)
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_iconv_check: check a charset
|
||||
* if a charset is NULL, internal charset is used
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_iconv_check (char *from_code, char *to_code)
|
||||
{
|
||||
#ifdef HAVE_ICONV
|
||||
iconv_t cd;
|
||||
|
||||
if (!from_code || !from_code[0])
|
||||
from_code = (cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset;
|
||||
|
||||
if (!to_code || !to_code[0])
|
||||
to_code = (cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset;
|
||||
|
||||
cd = iconv_open (to_code, from_code);
|
||||
if (cd == (iconv_t)(-1))
|
||||
return 0;
|
||||
iconv_close (cd);
|
||||
return 1;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_strreplace: replace a string by new one in a string
|
||||
* note: returned value has to be free() after use
|
||||
|
||||
@@ -110,6 +110,7 @@ extern int ascii_strcasecmp (char *, char *);
|
||||
extern int ascii_strncasecmp (char *, char *, int);
|
||||
extern char *ascii_strcasestr (char *, char *);
|
||||
extern char *weechat_iconv (char *, char *, char *);
|
||||
extern int weechat_iconv_check (char *, char *);
|
||||
extern char *weechat_strreplace (char *, char *, char *);
|
||||
extern void weechat_dump (int);
|
||||
extern long get_timeval_diff (struct timeval *, struct timeval *);
|
||||
|
||||
Reference in New Issue
Block a user