changeset 4051:a5c49e9c6a53

[gaim-migrate @ 4261] (18:27:24) Paco-Paco: The new gaim prpl semantics dictate that gaim<=>prpl communication is always done in UTF-8. This patch brings gadu-gadu up-to-date with respect to this practice. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 08 Dec 2002 23:29:45 +0000
parents 9438d2e96cb1
children fe0cf4c9115d
files src/protocols/gg/Makefile.am src/protocols/gg/gg.c src/protocols/gg/iconv_string.c src/protocols/gg/iconv_string.h
diffstat 4 files changed, 9 insertions(+), 247 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/gg/Makefile.am	Fri Dec 06 18:42:52 2002 +0000
+++ b/src/protocols/gg/Makefile.am	Sun Dec 08 23:29:45 2002 +0000
@@ -14,8 +14,6 @@
 libgg_a_SOURCES = libgg.c \
 		  libgg.h \
 		  common.c \
-		  iconv_string.c \
-		  iconv_string.h \
 		  gg.c
 
 libgg_a_CFLAGS = $(AM_CFLAGS)
@@ -29,8 +27,6 @@
 libgg_la_SOURCES = libgg.c \
 		   libgg.h \
 		   common.c \
-		   iconv_string.c \
-		   iconv_string.h \
 		   gg.c
 
 endif
--- a/src/protocols/gg/gg.c	Fri Dec 06 18:42:52 2002 +0000
+++ b/src/protocols/gg/gg.c	Sun Dec 08 23:29:45 2002 +0000
@@ -1,6 +1,6 @@
 /*
  * gaim - Gadu-Gadu Protocol Plugin
- * $Id: gg.c 3850 2002-10-16 19:57:03Z hermanator $
+ * $Id: gg.c 4261 2002-12-08 23:29:45Z lschiere $
  *
  * Copyright (C) 2001 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
  * 
@@ -42,13 +42,6 @@
 #include <time.h>
 #include <sys/stat.h>
 #include <ctype.h>
-#ifdef HAVE_LANGINFO_CODESET
-#include <langinfo.h>
-#endif
-#ifdef HAVE_ICONV
-#include <iconv.h>
-#include "iconv_string.h"
-#endif
 /* Library from EKG (Eksperymentalny Klient Gadu-Gadu) */
 #include "libgg.h"
 #include "multi.h"
@@ -115,12 +108,7 @@
 
 static gchar *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst)
 {
-#ifdef HAVE_ICONV
-	gchar *result = NULL;
-	if (iconv_string(encdst, encsrc, locstr, locstr + strlen(locstr) + 1, &result, NULL) >= 0)
-		return result;
-#endif
-	return g_strdup(locstr);
+	return (g_convert (locstr, strlen (locstr), encdst, encsrc, NULL, NULL, NULL));
 }
 
 static gboolean invalid_uin(const char *uin)
@@ -168,20 +156,6 @@
 	}
 }
 
-static const gchar *find_local_charset(void)
-{
-	const gchar *gg_localenc = g_getenv("GG_CHARSET");
-
-	if (gg_localenc == NULL) {
-#ifdef HAVE_LANGINFO_CODESET
-		gg_localenc = nl_langinfo(CODESET);
-#else
-		gg_localenc = "US-ASCII";
-#endif
-	}
-	return gg_localenc;
-}
-
 static char *handle_errcode(struct gaim_connection *gc, int errcode)
 {
 	static char msg[AGG_BUF_LEN];
@@ -362,7 +336,7 @@
 			g_snprintf(user, sizeof(user), "%lu", e->event.msg.sender);
 			if (!allowed_uin(gc, user))
 				break;
-			imsg = charset_convert(e->event.msg.message, "CP1250", find_local_charset());
+			imsg = charset_convert(e->event.msg.message, "CP1250", "UTF-8");
 			strip_linefeed(imsg);
 			/* e->event.msg.time - we don't know what this time is for */
 			serv_got_im(gc, user, imsg, 0, time(NULL), -1);
@@ -630,7 +604,7 @@
 	}
 
 	if (strlen(msg) > 0) {
-		imsg = charset_convert(msg, find_local_charset(), "CP1250");
+		imsg = charset_convert(msg, "UTF-8", "CP1250");
 		if (gg_send_message(gd->sess, (flags & IM_FLAG_CHECKBOX)
 				    ? GG_CLASS_MSG : GG_CLASS_CHAT,
 				    strtol(who, (char **)NULL, 10), imsg) < 0)
@@ -709,7 +683,7 @@
 		if (i % 8 == 0)
 			j = 0;
 
-		p = charset_convert(g_strstrip(webdata_tbl[i]), "CP1250", find_local_charset());
+		p = charset_convert(g_strstrip(webdata_tbl[i]), "CP1250", "UTF-8");
 
 		oldibuf = ibuf;
 
@@ -1114,9 +1088,9 @@
 		srch->request = g_strdup_printf("Mode=1&Email=%s", eemail);
 		g_free(eemail);
 	} else {
-		gchar *new_first = charset_convert(first, find_local_charset(), "CP1250");
-		gchar *new_last = charset_convert(last, find_local_charset(), "CP1250");
-		gchar *new_city = charset_convert(city, find_local_charset(), "CP1250");
+		gchar *new_first = charset_convert(first, "UTF-8", "CP1250");
+		gchar *new_last = charset_convert(last, "UTF-8", "CP1250");
+		gchar *new_city = charset_convert(city, "UTF-8", "CP1250");
 
 		gchar *enew_first = gg_urlencode(new_first);
 		gchar *enew_last = gg_urlencode(new_last);
@@ -1220,7 +1194,7 @@
 
 	/* If it's invalid uin then maybe it's nickname? */
 	if (invalid_uin(who)) {
-		gchar *new_who = charset_convert(who, find_local_charset(), "CP1250");
+		gchar *new_who = charset_convert(who, "UTF-8", "CP1250");
 		gchar *enew_who = gg_urlencode(new_who);
 		
 		g_free(new_who);
--- a/src/protocols/gg/iconv_string.c	Fri Dec 06 18:42:52 2002 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,161 +0,0 @@
-/* Copyright (C) 1999-2001 Bruno Haible.
-   This file is not part of the GNU LIBICONV Library.
-   This file is put into the public domain.  */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_ICONV
-#include "iconv_string.h"
-#include <iconv.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define tmpbufsize 4096
-
-int iconv_string (const char* tocode, const char* fromcode,
-                  const char* start, const char* end,
-                  char** resultp, size_t* lengthp)
-{
-  iconv_t cd = iconv_open(tocode,fromcode);
-  size_t length;
-  char* result;
-  if (cd == (iconv_t)(-1)) {
-    if (errno != EINVAL)
-      return -1;
-    /* Unsupported fromcode or tocode. Check whether the caller requested
-       autodetection. */
-    if (!strcmp(fromcode,"autodetect_utf8")) {
-      int ret;
-      /* Try UTF-8 first. There are very few ISO-8859-1 inputs that would
-         be valid UTF-8, but many UTF-8 inputs are valid ISO-8859-1. */
-      ret = iconv_string(tocode,"UTF-8",start,end,resultp,lengthp);
-      if (!(ret < 0 && errno == EILSEQ))
-        return ret;
-      ret = iconv_string(tocode,"ISO-8859-1",start,end,resultp,lengthp);
-      return ret;
-    }
-    if (!strcmp(fromcode,"autodetect_jp")) {
-      int ret;
-      /* Try 7-bit encoding first. If the input contains bytes >= 0x80,
-         it will fail. */
-      ret = iconv_string(tocode,"ISO-2022-JP-2",start,end,resultp,lengthp);
-      if (!(ret < 0 && errno == EILSEQ))
-        return ret;
-      /* Try EUC-JP next. Short SHIFT_JIS inputs may come out wrong. This
-         is unavoidable. People will condemn SHIFT_JIS.
-         If we tried SHIFT_JIS first, then some short EUC-JP inputs would
-         come out wrong, and people would condemn EUC-JP and Unix, which
-         would not be good. */
-      ret = iconv_string(tocode,"EUC-JP",start,end,resultp,lengthp);
-      if (!(ret < 0 && errno == EILSEQ))
-        return ret;
-      /* Finally try SHIFT_JIS. */
-      ret = iconv_string(tocode,"SHIFT_JIS",start,end,resultp,lengthp);
-      return ret;
-    }
-    if (!strcmp(fromcode,"autodetect_kr")) {
-      int ret;
-      /* Try 7-bit encoding first. If the input contains bytes >= 0x80,
-         it will fail. */
-      ret = iconv_string(tocode,"ISO-2022-KR",start,end,resultp,lengthp);
-      if (!(ret < 0 && errno == EILSEQ))
-        return ret;
-      /* Finally try EUC-KR. */
-      ret = iconv_string(tocode,"EUC-KR",start,end,resultp,lengthp);
-      return ret;
-    }
-    errno = EINVAL;
-    return -1;
-  }
-  /* Determine the length we need. */
-  {
-    size_t count = 0;
-    char tmpbuf[tmpbufsize];
-    char* inptr = (char *)start;
-    size_t insize = end-start;
-    while (insize > 0) {
-      char* outptr = tmpbuf;
-      size_t outsize = tmpbufsize;
-      size_t res = iconv(cd,&inptr,&insize,&outptr,&outsize);
-      if (res == (size_t)(-1)) {
-        if (errno == EINVAL)
-          break;
-        else {
-          int saved_errno = errno;
-          iconv_close(cd);
-          errno = saved_errno;
-          return -1;
-        }
-      }
-      count += outptr-tmpbuf;
-    }
-    {
-      char* outptr = tmpbuf;
-      size_t outsize = tmpbufsize;
-      size_t res = iconv(cd,NULL,NULL,&outptr,&outsize);
-      if (res == (size_t)(-1)) {
-        int saved_errno = errno;
-        iconv_close(cd);
-        errno = saved_errno;
-        return -1;
-      }
-      count += outptr-tmpbuf;
-    }
-    length = count;
-  }
-  if (lengthp != NULL)
-    *lengthp = length;
-  if (resultp == NULL) {
-    iconv_close(cd);
-    return 0;
-  }
-  result = (*resultp == NULL ? malloc(length) : realloc(*resultp,length));
-  *resultp = result;
-  if (length == 0) {
-    iconv_close(cd);
-    return 0;
-  }
-  if (result == NULL) {
-    iconv_close(cd);
-    errno = ENOMEM;
-    return -1;
-  }
-  iconv(cd,NULL,NULL,NULL,NULL); /* return to the initial state */
-  /* Do the conversion for real. */
-  {
-    char* inptr = (char *)start;
-    size_t insize = end-start;
-    char* outptr = result;
-    size_t outsize = length;
-    while (insize > 0) {
-      size_t res = iconv(cd,&inptr,&insize,&outptr,&outsize);
-      if (res == (size_t)(-1)) {
-        if (errno == EINVAL)
-          break;
-        else {
-          int saved_errno = errno;
-          iconv_close(cd);
-          errno = saved_errno;
-          return -1;
-        }
-      }
-    }
-    {
-      size_t res = iconv(cd,NULL,NULL,&outptr,&outsize);
-      if (res == (size_t)(-1)) {
-        int saved_errno = errno;
-        iconv_close(cd);
-        errno = saved_errno;
-        return -1;
-      }
-    }
-    if (outsize != 0) abort();
-  }
-  iconv_close(cd);
-  return 0;
-}
-
-#endif
--- a/src/protocols/gg/iconv_string.h	Fri Dec 06 18:42:52 2002 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/* Copyright (C) 1999-2001 Bruno Haible.
-   This file is not part of the GNU LIBICONV Library.
-   This file is put into the public domain.  */
-
-/*
- * This C function converts an entire string from one encoding to another,
- * using iconv. Easier to use than iconv() itself, and supports autodetect
- * encodings on input.
- *
- *   int iconv_string (const char* tocode, const char* fromcode,
- *                     const char* start, const char* end,
- *                     char** resultp, size_t* lengthp)
- *
- * Converts a memory region given in encoding FROMCODE to a new memory
- * region in encoding TOCODE. FROMCODE and TOCODE are as for iconv_open(3),
- * except that FROMCODE may be one of the values
- *    "autodetect_utf8"          supports ISO-8859-1 and UTF-8
- *    "autodetect_jp"            supports EUC-JP, ISO-2022-JP-2 and SHIFT_JIS
- *    "autodetect_kr"            supports EUC-KR and ISO-2022-KR
- * The input is in the memory region between start (inclusive) and end
- * (exclusive). If resultp is not NULL, the output string is stored in
- * *resultp; malloc/realloc is used to allocate the result.
- *
- * This function does not treat zero characters specially.
- *
- * Return value: 0 if successful, otherwise -1 and errno set. Particular
- * errno values: EILSEQ and ENOMEM.
- *
- * Example:
- *   const char* s = ...;
- *   char* result = NULL;
- *   if (iconv_string("UCS-4-INTERNAL", "autodetect_utf8",
- *                    s, s+strlen(s)+1, &result, NULL) < 0)
- *     perror("iconv_string");
- *
- */
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern int iconv_string (const char* tocode, const char* fromcode, const char* start, const char* end, char** resultp, size_t* lengthp);
-
-#ifdef __cplusplus
-}
-#endif