Skip to content

Commit

Permalink
Fallback to UTF-8 encoding for sending IRC lines, as that's a no-op f…
Browse files Browse the repository at this point in the history
…rom Tcl.
  • Loading branch information
thommey committed Apr 21, 2016
1 parent 34a7b15 commit 886845d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions eggdrop.conf
Expand Up @@ -61,6 +61,7 @@ set offset "5"
# that are not representable in the target encoding.
# You can append //IGNORE to the encoding to ignore characters,
# that are not representable in the target encoding.
# If this fails, everything is sent from Tcl as-is (UTF-8).
#set out-encoding "utf-8"

# If you're using virtual hosting (your machine has more than 1 IP), you
Expand Down
8 changes: 7 additions & 1 deletion src/tcl.c
Expand Up @@ -169,18 +169,24 @@ static size_t convert_encoding(iconv_t conversion, char *src, size_t len, char *
size_t convert_out_encoding(char *msg, size_t len, char *buf, size_t bufsize)
{
static int initialized;
static iconv_t enc_utf8_utf8 = (iconv_t)(-1);
size_t i;

if (!initialized) {
initialized = 1;
reopen_encoding(&enc_utf8_out, out_encoding, "utf-8");
reopen_encoding(&enc_utf8_utf8, "utf-8", "utf-8");
}

i = convert_encoding(enc_utf8_out, msg, len, buf, bufsize);
if (i != -1)
return i;

/* Output encoding conversion failed, fallback to strcpy. */
i = convert_encoding(enc_utf8_utf8, msg, len, buf, bufsize);
if (i != -1)
return i;

/* Output encoding conversion failed, very unlikely, fallback to strcpy. */
size_t tocopy = min(len, bufsize);
strncpy(msg, buf, tocopy);
return bufsize - tocopy;
Expand Down

0 comments on commit 886845d

Please sign in to comment.