1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-12-25 04:43:33 +00:00

- Original program can't send/receive non-ASCII chars correctly

in MSN/Yahoo. This patch can fix that.  Also note that original
  config file has problem in writing default charset setting to
  file.
- Bump PORTREVISION

PR:		57734
Submitted by:	maintainer
This commit is contained in:
Kirill Ponomarev 2003-10-08 19:03:09 +00:00
parent 9043fdd66a
commit 54540550d7
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=90658
10 changed files with 62 additions and 440 deletions

View File

@ -8,7 +8,7 @@
PORTNAME= centericq
PORTVERSION= 4.9.7
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= net
MASTER_SITES= http://konst.org.ua/download/
@ -67,7 +67,7 @@ post-patch:
${MV} -f ${file} ${file}.orig ; \
${GREP} -v "_G_config.h" ${file}.orig > ${file})
.endfor
.if !defined(NOPORTDOCS)
post-install:
@${MKDIR} ${DOCSDIR}

View File

@ -0,0 +1,11 @@
--- src/icqconf.cc.orig Wed Oct 1 08:27:45 2003
+++ src/icqconf.cc Wed Oct 8 17:28:21 2003
@@ -270,7 +270,7 @@
if(getantispam()) f << "antispam" << endl;
if(getmailcheck()) f << "mailcheck" << endl;
if(getaskaway()) f << "askaway" << endl;
- f << "defcharset" << getdefcharset() << endl;
+ f << "defcharset\t" << getdefcharset() << endl;
param = "";
for(protocolname pname = icq; pname != protocolname_size; (int) pname += 1)

View File

@ -1,29 +1,20 @@
--- src/hooks/msnhook.cc.orig Tue Sep 30 19:38:43 2003
+++ src/hooks/msnhook.cc Tue Oct 7 10:20:29 2003
@@ -33,6 +33,7 @@
#include "accountmanager.h"
#include "eventmanager.h"
#include "imlogger.h"
+#include "utf8conv.h"
#include "connwrap.h"
#include "msn_bittybits.h"
@@ -248,7 +249,8 @@
+++ src/hooks/msnhook.cc Wed Oct 8 17:44:13 2003
@@ -248,7 +248,7 @@
}
icqcontact *c = clist.get(ev.getcontact());
- text = siconv(text, conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset(), "utf8");
+// text = siconv(text, conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset(), "utf8");
+ text = StrToUtf8(text);
+ text = siconv(text, conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset(), "utf-8");
if(c)
if(c->getstatus() != offline || !c->inlist()) {
@@ -378,11 +380,11 @@
@@ -378,11 +378,11 @@
void msnhook::checkfriendly(icqcontact *c, const string friendlynick, bool forcefetch) {
string oldnick = c->getnick();
- string newnick = unmime(friendlynick);
+ string newnick = Utf8ToStr(unmime(friendlynick));
+ string newnick = siconv(unmime(friendlynick), "utf-8", conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset());
c->setnick(newnick);
@ -32,153 +23,12 @@
c->setdispnick(newnick);
face.relaxedupdate();
}
@@ -602,7 +604,8 @@
@@ -602,7 +602,7 @@
mhook.checkinlist(ic);
- string text = siconv(msg->body, "utf8", conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset());
+// string text = siconv(msg->body, "utf8", conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset());
+ string text = Utf8ToStr(msg->body);
+ string text = siconv(msg->body, "utf-8", conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset());
em.store(immessage(ic, imevent::incoming, text));
}
@@ -779,5 +782,139 @@
log(string("[OUT] ") + buf);
}
}
+
+#if HAVE_ICONV_H
+int safe_iconv( iconv_t handle, const char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft)
+{
+ int ret;
+ while (*inbytesleft) {
+ ret = iconv( handle, inbuf, inbytesleft,
+ outbuf, outbytesleft);
+ if (!*inbytesleft || !*outbytesleft)
+ return ret;
+ /*got invalid seq - so replace it with '?' */
+ **outbuf = '?'; (*outbuf)++; (*outbytesleft)--;
+ (*inbuf)++; (*inbytesleft)--;
+ }
+ return ret;
+}
+
+const char* guess_current_locale_charset()
+{
+ char *lang, *ch;
+ /* Return previously learned charset */
+ if (loc_charset[0])
+ return loc_charset;
+
+ lang = getenv("LANG");
+ if (!lang) {
+ strcpy( loc_charset, DEFAULT_CHARSET );
+ return loc_charset;
+ };
+ ch = strrchr( lang, '.' );
+ if (!ch)
+ strcpy( loc_charset, DEFAULT_CHARSET );
+ else {
+ iconv_t pt;
+ ch++;
+ strncpy( loc_charset, ch, sizeof(loc_charset) );
+ /* try to open iconv handle using guessed charset */
+ if ( (pt = iconv_open( loc_charset, loc_charset )) == (iconv_t)(-1) )
+ {
+ strcpy( loc_charset, DEFAULT_CHARSET );
+ } else {
+ iconv_close(pt);
+ };
+
+ }
+
+ return loc_charset;
+}
+
+char *StrToUtf8( const char *inbuf )
+{
+ size_t length = strlen( inbuf );
+ size_t outmaxlength = UTF8_BUF_LENGTH;
+ char *outbuf = utf8_buf;
+ char *outbuf_save = outbuf;
+ int ret;
+
+ iconv_t handle = iconv_open( "utf-8", guess_current_locale_charset() );
+ if(((int) handle) != -1) {
+ ret = safe_iconv( handle, (const char **) &inbuf, &length, &outbuf, &outmaxlength );
+
+ *outbuf = '\0';
+ iconv_close( handle );
+ return outbuf_save;
+ } else {
+ return (char *)inbuf;
+ };
+}
+
+std::string StrToUtf8( const std::string &instr )
+{
+ size_t length = instr.length();
+ size_t outmaxlength = UTF8_BUF_LENGTH;
+ const char *inbuf = instr.c_str();
+ char *outbuf = utf8_buf;
+ char *outbuf_save = outbuf;
+ int ret;
+
+ iconv_t handle = iconv_open( "utf-8", guess_current_locale_charset() );
+ if(((int) handle) != -1) {
+ ret = safe_iconv( handle, (const char **) &inbuf, &length, &outbuf, &outmaxlength );
+
+ *outbuf = '\0';
+ iconv_close( handle );
+
+ std::string return_me = outbuf_save;
+ return return_me;
+ } else {
+ return instr;
+ };
+}
+
+char *Utf8ToStr( const char *inbuf )
+{
+ size_t length = strlen( inbuf );
+ size_t outmaxlength = UTF8_BUF_LENGTH / 4;
+ char *outbuf = utf8_buf;
+ char *outbuf_save = outbuf;
+ int ret;
+
+ iconv_t handle = iconv_open( guess_current_locale_charset(), "utf-8" );
+ if(((int) handle) != -1) {
+ ret = safe_iconv( handle, (const char **) &inbuf, &length, &outbuf, &outmaxlength );
+ *outbuf = '\0';
+ iconv_close( handle );
+ return outbuf_save;
+ } else {
+ return (char *)inbuf;
+ };
+}
+
+std::string Utf8ToStr( const std::string &instr )
+{
+ size_t length = instr.length();
+ const char *inbuf = instr.c_str();
+ size_t outmaxlength = UTF8_BUF_LENGTH / 4;
+ char *outbuf = utf8_buf;
+ char *outbuf_save = outbuf;
+ int ret;
+
+ iconv_t handle = iconv_open( guess_current_locale_charset(), "utf-8" );
+
+ if(((int) handle) != -1) {
+ ret = safe_iconv( handle, (const char **) &inbuf, &length, &outbuf, &outmaxlength );
+ *outbuf = '\0';
+ iconv_close( handle );
+ std::string return_me = outbuf_save;
+ return return_me;
+ } else {
+ return instr;
+ };
+}
+#endif /* HAVE_ICONV_H */
#endif

View File

@ -1,61 +0,0 @@
--- src/hooks/utf8conv.h Thu Jan 1 08:00:00 1970
+++ src/hooks/utf8conv.h Tue Nov 26 16:10:40 2002
@@ -0,0 +1,58 @@
+/*-------------------------------------------------------*/
+/* utf8conv.h ( Utf8 Converter ) */
+/*-------------------------------------------------------*/
+/* target : Converting Utf8 from/to string/char */
+/* modifier : clsung@dragon2.net */
+/* create : unknown */
+/* update : 02/11/26 */
+/*-------------------------------------------------------*/
+#ifndef _UTF8CONV_
+#define _UTF8CONV_
+
+#ifndef HAVE_ICONV_H
+#define HAVE_ICONV_H
+#endif
+
+#ifdef HAVE_ICONV_H
+#include <iconv.h>
+#endif
+#include <string>
+#define DEFAULT_CHARSET "ISO-8859-1"
+#define UTF8_BUF_LENGTH 2048
+/* charset name cache buffer */
+static char loc_charset[32];
+static char utf8_buf[UTF8_BUF_LENGTH]; // max 401 length or per message
+/*
+** Name: safe_iconv
+** Purpose: 'Fault-tolerant' version if iconv. Replaces invalid seq with '?'
+** Input: see iconv manpage
+*/
+int safe_iconv( iconv_t handle, const char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft);
+
+/*
+** Name: guess_current_locale_charset
+** Purpose: Try to guess default charset for the current locale
+** Output: charset name
+** FIXME: is there more right method for guessing charset
+ than scanning $LANG ?
+*/
+const char* guess_current_locale_charset();
+
+/*
+** Name: Str2Utf8
+** Purpose: convert a string in UTF-8 format
+** Input: inbuf - the string to convert
+** Output: a new string in UTF-8 format
+*/
+char *StrToUtf8( const char *inbuf );
+std::string StrToUtf8( const std::string &instr );
+/*
+** Name: Utf8ToStr
+** Purpose: revert UTF-8 string conversion
+** Input: inbuf - the string to decode
+** Output: a new decoded string
+*/
+char *Utf8ToStr( const char *inbuf );
+std::string Utf8ToStr( const std::string &instr );
+#endif

View File

@ -0,0 +1,11 @@
--- src/hooks/yahoohook.cc.orig Fri Oct 3 03:55:06 2003
+++ src/hooks/yahoohook.cc Wed Oct 8 17:29:21 2003
@@ -556,7 +556,7 @@
string yahoohook::decode(const string &text, bool utf) {
if(utf)
- return siconv(text, "utf8",
+ return siconv(text, "utf-8",
conf.getrussian(proto) ? "koi8-u" : conf.getdefcharset());
return rushtmlconv("wk", text);

View File

@ -8,7 +8,7 @@
PORTNAME= centericq
PORTVERSION= 4.9.7
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= net
MASTER_SITES= http://konst.org.ua/download/
@ -67,7 +67,7 @@ post-patch:
${MV} -f ${file} ${file}.orig ; \
${GREP} -v "_G_config.h" ${file}.orig > ${file})
.endfor
.if !defined(NOPORTDOCS)
post-install:
@${MKDIR} ${DOCSDIR}

View File

@ -0,0 +1,11 @@
--- src/icqconf.cc.orig Wed Oct 1 08:27:45 2003
+++ src/icqconf.cc Wed Oct 8 17:28:21 2003
@@ -270,7 +270,7 @@
if(getantispam()) f << "antispam" << endl;
if(getmailcheck()) f << "mailcheck" << endl;
if(getaskaway()) f << "askaway" << endl;
- f << "defcharset" << getdefcharset() << endl;
+ f << "defcharset\t" << getdefcharset() << endl;
param = "";
for(protocolname pname = icq; pname != protocolname_size; (int) pname += 1)

View File

@ -1,29 +1,20 @@
--- src/hooks/msnhook.cc.orig Tue Sep 30 19:38:43 2003
+++ src/hooks/msnhook.cc Tue Oct 7 10:20:29 2003
@@ -33,6 +33,7 @@
#include "accountmanager.h"
#include "eventmanager.h"
#include "imlogger.h"
+#include "utf8conv.h"
#include "connwrap.h"
#include "msn_bittybits.h"
@@ -248,7 +249,8 @@
+++ src/hooks/msnhook.cc Wed Oct 8 17:44:13 2003
@@ -248,7 +248,7 @@
}
icqcontact *c = clist.get(ev.getcontact());
- text = siconv(text, conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset(), "utf8");
+// text = siconv(text, conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset(), "utf8");
+ text = StrToUtf8(text);
+ text = siconv(text, conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset(), "utf-8");
if(c)
if(c->getstatus() != offline || !c->inlist()) {
@@ -378,11 +380,11 @@
@@ -378,11 +378,11 @@
void msnhook::checkfriendly(icqcontact *c, const string friendlynick, bool forcefetch) {
string oldnick = c->getnick();
- string newnick = unmime(friendlynick);
+ string newnick = Utf8ToStr(unmime(friendlynick));
+ string newnick = siconv(unmime(friendlynick), "utf-8", conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset());
c->setnick(newnick);
@ -32,153 +23,12 @@
c->setdispnick(newnick);
face.relaxedupdate();
}
@@ -602,7 +604,8 @@
@@ -602,7 +602,7 @@
mhook.checkinlist(ic);
- string text = siconv(msg->body, "utf8", conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset());
+// string text = siconv(msg->body, "utf8", conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset());
+ string text = Utf8ToStr(msg->body);
+ string text = siconv(msg->body, "utf-8", conf.getrussian(msn) ? "koi8-u" : conf.getdefcharset());
em.store(immessage(ic, imevent::incoming, text));
}
@@ -779,5 +782,139 @@
log(string("[OUT] ") + buf);
}
}
+
+#if HAVE_ICONV_H
+int safe_iconv( iconv_t handle, const char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft)
+{
+ int ret;
+ while (*inbytesleft) {
+ ret = iconv( handle, inbuf, inbytesleft,
+ outbuf, outbytesleft);
+ if (!*inbytesleft || !*outbytesleft)
+ return ret;
+ /*got invalid seq - so replace it with '?' */
+ **outbuf = '?'; (*outbuf)++; (*outbytesleft)--;
+ (*inbuf)++; (*inbytesleft)--;
+ }
+ return ret;
+}
+
+const char* guess_current_locale_charset()
+{
+ char *lang, *ch;
+ /* Return previously learned charset */
+ if (loc_charset[0])
+ return loc_charset;
+
+ lang = getenv("LANG");
+ if (!lang) {
+ strcpy( loc_charset, DEFAULT_CHARSET );
+ return loc_charset;
+ };
+ ch = strrchr( lang, '.' );
+ if (!ch)
+ strcpy( loc_charset, DEFAULT_CHARSET );
+ else {
+ iconv_t pt;
+ ch++;
+ strncpy( loc_charset, ch, sizeof(loc_charset) );
+ /* try to open iconv handle using guessed charset */
+ if ( (pt = iconv_open( loc_charset, loc_charset )) == (iconv_t)(-1) )
+ {
+ strcpy( loc_charset, DEFAULT_CHARSET );
+ } else {
+ iconv_close(pt);
+ };
+
+ }
+
+ return loc_charset;
+}
+
+char *StrToUtf8( const char *inbuf )
+{
+ size_t length = strlen( inbuf );
+ size_t outmaxlength = UTF8_BUF_LENGTH;
+ char *outbuf = utf8_buf;
+ char *outbuf_save = outbuf;
+ int ret;
+
+ iconv_t handle = iconv_open( "utf-8", guess_current_locale_charset() );
+ if(((int) handle) != -1) {
+ ret = safe_iconv( handle, (const char **) &inbuf, &length, &outbuf, &outmaxlength );
+
+ *outbuf = '\0';
+ iconv_close( handle );
+ return outbuf_save;
+ } else {
+ return (char *)inbuf;
+ };
+}
+
+std::string StrToUtf8( const std::string &instr )
+{
+ size_t length = instr.length();
+ size_t outmaxlength = UTF8_BUF_LENGTH;
+ const char *inbuf = instr.c_str();
+ char *outbuf = utf8_buf;
+ char *outbuf_save = outbuf;
+ int ret;
+
+ iconv_t handle = iconv_open( "utf-8", guess_current_locale_charset() );
+ if(((int) handle) != -1) {
+ ret = safe_iconv( handle, (const char **) &inbuf, &length, &outbuf, &outmaxlength );
+
+ *outbuf = '\0';
+ iconv_close( handle );
+
+ std::string return_me = outbuf_save;
+ return return_me;
+ } else {
+ return instr;
+ };
+}
+
+char *Utf8ToStr( const char *inbuf )
+{
+ size_t length = strlen( inbuf );
+ size_t outmaxlength = UTF8_BUF_LENGTH / 4;
+ char *outbuf = utf8_buf;
+ char *outbuf_save = outbuf;
+ int ret;
+
+ iconv_t handle = iconv_open( guess_current_locale_charset(), "utf-8" );
+ if(((int) handle) != -1) {
+ ret = safe_iconv( handle, (const char **) &inbuf, &length, &outbuf, &outmaxlength );
+ *outbuf = '\0';
+ iconv_close( handle );
+ return outbuf_save;
+ } else {
+ return (char *)inbuf;
+ };
+}
+
+std::string Utf8ToStr( const std::string &instr )
+{
+ size_t length = instr.length();
+ const char *inbuf = instr.c_str();
+ size_t outmaxlength = UTF8_BUF_LENGTH / 4;
+ char *outbuf = utf8_buf;
+ char *outbuf_save = outbuf;
+ int ret;
+
+ iconv_t handle = iconv_open( guess_current_locale_charset(), "utf-8" );
+
+ if(((int) handle) != -1) {
+ ret = safe_iconv( handle, (const char **) &inbuf, &length, &outbuf, &outmaxlength );
+ *outbuf = '\0';
+ iconv_close( handle );
+ std::string return_me = outbuf_save;
+ return return_me;
+ } else {
+ return instr;
+ };
+}
+#endif /* HAVE_ICONV_H */
#endif

View File

@ -1,61 +0,0 @@
--- src/hooks/utf8conv.h Thu Jan 1 08:00:00 1970
+++ src/hooks/utf8conv.h Tue Nov 26 16:10:40 2002
@@ -0,0 +1,58 @@
+/*-------------------------------------------------------*/
+/* utf8conv.h ( Utf8 Converter ) */
+/*-------------------------------------------------------*/
+/* target : Converting Utf8 from/to string/char */
+/* modifier : clsung@dragon2.net */
+/* create : unknown */
+/* update : 02/11/26 */
+/*-------------------------------------------------------*/
+#ifndef _UTF8CONV_
+#define _UTF8CONV_
+
+#ifndef HAVE_ICONV_H
+#define HAVE_ICONV_H
+#endif
+
+#ifdef HAVE_ICONV_H
+#include <iconv.h>
+#endif
+#include <string>
+#define DEFAULT_CHARSET "ISO-8859-1"
+#define UTF8_BUF_LENGTH 2048
+/* charset name cache buffer */
+static char loc_charset[32];
+static char utf8_buf[UTF8_BUF_LENGTH]; // max 401 length or per message
+/*
+** Name: safe_iconv
+** Purpose: 'Fault-tolerant' version if iconv. Replaces invalid seq with '?'
+** Input: see iconv manpage
+*/
+int safe_iconv( iconv_t handle, const char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft);
+
+/*
+** Name: guess_current_locale_charset
+** Purpose: Try to guess default charset for the current locale
+** Output: charset name
+** FIXME: is there more right method for guessing charset
+ than scanning $LANG ?
+*/
+const char* guess_current_locale_charset();
+
+/*
+** Name: Str2Utf8
+** Purpose: convert a string in UTF-8 format
+** Input: inbuf - the string to convert
+** Output: a new string in UTF-8 format
+*/
+char *StrToUtf8( const char *inbuf );
+std::string StrToUtf8( const std::string &instr );
+/*
+** Name: Utf8ToStr
+** Purpose: revert UTF-8 string conversion
+** Input: inbuf - the string to decode
+** Output: a new decoded string
+*/
+char *Utf8ToStr( const char *inbuf );
+std::string Utf8ToStr( const std::string &instr );
+#endif

View File

@ -0,0 +1,11 @@
--- src/hooks/yahoohook.cc.orig Fri Oct 3 03:55:06 2003
+++ src/hooks/yahoohook.cc Wed Oct 8 17:29:21 2003
@@ -556,7 +556,7 @@
string yahoohook::decode(const string &text, bool utf) {
if(utf)
- return siconv(text, "utf8",
+ return siconv(text, "utf-8",
conf.getrussian(proto) ? "koi8-u" : conf.getdefcharset());
return rushtmlconv("wk", text);