diff options
author | Alexey Shchepin <alexey@process-one.net> | 2005-12-14 01:32:48 +0000 |
---|---|---|
committer | Alexey Shchepin <alexey@process-one.net> | 2005-12-14 01:32:48 +0000 |
commit | 5f2de53f01b3a27c8c4817266f17e21e6992214f (patch) | |
tree | a0d8cb4e61151aec39708fcab7fd5dfa804eaad3 | |
parent | * src/win32/ejabberd.nsi: Updated (thanks to Maxim Ryazanov) (diff) |
* src/mod_irc/iconv_erl.c: Bugfix (thanks to Tomas Janousek)
SVN Revision: 470
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/mod_irc/iconv_erl.c | 28 |
2 files changed, 22 insertions, 10 deletions
@@ -1,3 +1,7 @@ +2005-12-14 Alexey Shchepin <alexey@sevcom.net> + + * src/mod_irc/iconv_erl.c: Bugfix (thanks to Tomas Janousek) + 2005-12-13 Alexey Shchepin <alexey@sevcom.net> * src/win32/ejabberd.nsi: Updated (thanks to Maxim Ryazanov) diff --git a/src/mod_irc/iconv_erl.c b/src/mod_irc/iconv_erl.c index 85b898bb3..3698ee977 100644 --- a/src/mod_irc/iconv_erl.c +++ b/src/mod_irc/iconv_erl.c @@ -55,27 +55,35 @@ static int iconv_erl_control(ErlDrvData drv_data, ei_get_type(buf, &index, &i, &size); stmp = string = malloc(size + 1); ei_decode_string(buf, &index, string); - + cd = iconv_open(to, from); - if(cd == (iconv_t) -1) - { + if (cd == (iconv_t) -1) { cd = iconv_open("ascii", "ascii"); - if(cd == (iconv_t) -1) - { - cd = iconv_open("ascii", "ascii"); - } + if (cd == (iconv_t) -1) { + *rbuf = (char*)(b = driver_alloc_binary(size)); + memcpy(b->orig_bytes, string, size); + + free(from); + free(to); + free(string); + + return size; + } } outleft = avail = 4*size; inleft = size; rtmp = rstring = malloc(avail); - iconv(cd, &stmp, &inleft, &rtmp, &outleft); + while (inleft > 0) { + if (iconv(cd, &stmp, &inleft, &rtmp, &outleft) == (size_t) -1) { + stmp++; + inleft--; + } + } size = rtmp - rstring; - //printf("size=%d, res=%s\r\n", size, rstring); - *rbuf = (char*)(b = driver_alloc_binary(size)); memcpy(b->orig_bytes, rstring, size); |