mirror of
https://github.com/irssi/irssi.git
synced 2024-11-03 04:27:19 -05:00
Merge pull request #152 from sebth/master
Try to split long lines on spaces
This commit is contained in:
commit
9abdeb8611
2
NEWS
2
NEWS
@ -1,5 +1,7 @@
|
|||||||
v0.8.18-head 2014-XX-YY The Irssi team <staff@irssi.org>
|
v0.8.18-head 2014-XX-YY The Irssi team <staff@irssi.org>
|
||||||
+ Disable SSLv3 due to the POODLE vulnerability.
|
+ Disable SSLv3 due to the POODLE vulnerability.
|
||||||
|
+ Try to split long lines on spaces to avoid words being splitted. Adds
|
||||||
|
a new option: 'split_line_on_space' which defaults to on.
|
||||||
|
|
||||||
v0.8.17 2014-10-11 The Irssi team <staff@irssi.org>
|
v0.8.17 2014-10-11 The Irssi team <staff@irssi.org>
|
||||||
+ Document that SSL connections aren't properly handled during /UPGRADE. See Github PR #39.
|
+ Document that SSL connections aren't properly handled during /UPGRADE. See Github PR #39.
|
||||||
|
@ -967,19 +967,30 @@ char *ascii_strdown(char *str)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
char **strsplit_len(const char *str, int len)
|
char **strsplit_len(const char *str, int len, gboolean onspace)
|
||||||
{
|
{
|
||||||
char **ret;
|
char **ret = g_new(char *, 1);
|
||||||
size_t total_len = strlen(str);
|
int n;
|
||||||
int n = total_len / len;
|
int offset;
|
||||||
|
|
||||||
|
for (n = 0; *str != '\0'; n++, str += MIN(len - offset, strlen(str))) {
|
||||||
|
offset = 0;
|
||||||
|
if (onspace) {
|
||||||
|
/*
|
||||||
|
* Try to find a space to split on and leave
|
||||||
|
* the space on the previous line.
|
||||||
|
*/
|
||||||
int i;
|
int i;
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
if (total_len % len)
|
if (str[len-1-i] == ' ') {
|
||||||
n++;
|
offset = i;
|
||||||
|
break;
|
||||||
ret = g_new(char *, n + 1);
|
}
|
||||||
for (i = 0; i < n; i++, str += len)
|
}
|
||||||
ret[i] = g_strndup(str, len);
|
}
|
||||||
|
ret[n] = g_strndup(str, len - offset);
|
||||||
|
ret = g_renew(char *, ret, n + 2);
|
||||||
|
}
|
||||||
ret[n] = NULL;
|
ret[n] = NULL;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -116,6 +116,6 @@ uoff_t str_to_uofft(const char *str);
|
|||||||
int find_substr(const char *list, const char *item);
|
int find_substr(const char *list, const char *item);
|
||||||
|
|
||||||
/* split `str' into `len' sized substrings */
|
/* split `str' into `len' sized substrings */
|
||||||
char **strsplit_len(const char *str, int len);
|
char **strsplit_len(const char *str, int len, gboolean onspace);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -183,7 +183,7 @@ char *recode_out(const SERVER_REC *server, const char *str, const char *target)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char **recode_split(const SERVER_REC *server, const char *str,
|
char **recode_split(const SERVER_REC *server, const char *str,
|
||||||
const char *target, int len)
|
const char *target, int len, gboolean onspace)
|
||||||
{
|
{
|
||||||
GIConv cd = (GIConv)-1;
|
GIConv cd = (GIConv)-1;
|
||||||
const char *from = translit_charset;
|
const char *from = translit_charset;
|
||||||
@ -219,7 +219,7 @@ char **recode_split(const SERVER_REC *server, const char *str,
|
|||||||
cd = g_iconv_open(to, from);
|
cd = g_iconv_open(to, from);
|
||||||
if (cd == (GIConv)-1) {
|
if (cd == (GIConv)-1) {
|
||||||
/* Fall back to splitting by byte. */
|
/* Fall back to splitting by byte. */
|
||||||
ret = strsplit_len(str, len);
|
ret = strsplit_len(str, len, onspace);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,11 +235,25 @@ char **recode_split(const SERVER_REC *server, const char *str,
|
|||||||
*/
|
*/
|
||||||
ret[n] = NULL;
|
ret[n] = NULL;
|
||||||
g_strfreev(ret);
|
g_strfreev(ret);
|
||||||
ret = strsplit_len(str, len);
|
ret = strsplit_len(str, len, onspace);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Outbuf overflowed, split the input string. */
|
/* Outbuf overflowed, split the input string. */
|
||||||
|
if (onspace) {
|
||||||
|
/*
|
||||||
|
* Try to find a space to split on and leave
|
||||||
|
* the space on the previous line.
|
||||||
|
*/
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < inbuf - previnbuf; i++) {
|
||||||
|
if (previnbuf[inbuf-previnbuf-1-i] == ' ') {
|
||||||
|
inbuf -= i;
|
||||||
|
inbytesleft += i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
ret[n++] = g_strndup(previnbuf, inbuf - previnbuf);
|
ret[n++] = g_strndup(previnbuf, inbuf - previnbuf);
|
||||||
ret = g_renew(char *, ret, n + 1);
|
ret = g_renew(char *, ret, n + 1);
|
||||||
previnbuf = inbuf;
|
previnbuf = inbuf;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
char *recode_in (const SERVER_REC *server, const char *str, const char *target);
|
char *recode_in (const SERVER_REC *server, const char *str, const char *target);
|
||||||
char *recode_out (const SERVER_REC *server, const char *str, const char *target);
|
char *recode_out (const SERVER_REC *server, const char *str, const char *target);
|
||||||
char **recode_split(const SERVER_REC *server, const char *str,
|
char **recode_split(const SERVER_REC *server, const char *str,
|
||||||
const char *target, int len);
|
const char *target, int len, gboolean onspace);
|
||||||
gboolean is_valid_charset(const char *charset);
|
gboolean is_valid_charset(const char *charset);
|
||||||
gboolean is_utf8(void);
|
gboolean is_utf8(void);
|
||||||
void recode_update_charset(void);
|
void recode_update_charset(void);
|
||||||
|
@ -85,6 +85,7 @@ static char **split_line(const SERVER_REC *server, const char *line,
|
|||||||
{
|
{
|
||||||
const char *start = settings_get_str("split_line_start");
|
const char *start = settings_get_str("split_line_start");
|
||||||
const char *end = settings_get_str("split_line_end");
|
const char *end = settings_get_str("split_line_end");
|
||||||
|
gboolean onspace = settings_get_bool("split_line_on_space");
|
||||||
char *recoded_start = recode_out(server, start, target);
|
char *recoded_start = recode_out(server, start, target);
|
||||||
char *recoded_end = recode_out(server, end, target);
|
char *recoded_end = recode_out(server, end, target);
|
||||||
char **lines;
|
char **lines;
|
||||||
@ -103,7 +104,7 @@ static char **split_line(const SERVER_REC *server, const char *line,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
lines = recode_split(server, line, target, len);
|
lines = recode_split(server, line, target, len, onspace);
|
||||||
for (i = 0; lines[i] != NULL; i++) {
|
for (i = 0; lines[i] != NULL; i++) {
|
||||||
if (i != 0 && *start != '\0') {
|
if (i != 0 && *start != '\0') {
|
||||||
/* Not the first line. */
|
/* Not the first line. */
|
||||||
@ -972,6 +973,7 @@ void irc_servers_init(void)
|
|||||||
settings_add_str("misc", "usermode", DEFAULT_USER_MODE);
|
settings_add_str("misc", "usermode", DEFAULT_USER_MODE);
|
||||||
settings_add_str("misc", "split_line_start", "");
|
settings_add_str("misc", "split_line_start", "");
|
||||||
settings_add_str("misc", "split_line_end", "");
|
settings_add_str("misc", "split_line_end", "");
|
||||||
|
settings_add_bool("misc", "split_line_on_space", TRUE);
|
||||||
settings_add_time("flood", "cmd_queue_speed", DEFAULT_CMD_QUEUE_SPEED);
|
settings_add_time("flood", "cmd_queue_speed", DEFAULT_CMD_QUEUE_SPEED);
|
||||||
settings_add_int("flood", "cmds_max_at_once", DEFAULT_CMDS_MAX_AT_ONCE);
|
settings_add_int("flood", "cmds_max_at_once", DEFAULT_CMDS_MAX_AT_ONCE);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user