Mercurial > pidgin.yaz
comparison libpurple/protocols/yahoo/util.c @ 25467:be098f796b32
yaz patch has been applied.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Wed, 25 Apr 2007 07:57:26 +0000 |
parents | 8e61e7be988b |
children | 411b5a604a17 |
comparison
equal
deleted
inserted
replaced
25466:46a28577399d | 25467:be098f796b32 |
---|---|
27 #include "debug.h" | 27 #include "debug.h" |
28 #include "internal.h" | 28 #include "internal.h" |
29 #include "prpl.h" | 29 #include "prpl.h" |
30 | 30 |
31 #include "yahoo.h" | 31 #include "yahoo.h" |
32 #include "util.h" | |
32 | 33 |
33 #include <string.h> | 34 #include <string.h> |
34 | 35 |
35 /** | 36 /** |
36 * Encode some text to send to the yahoo server. | 37 * Encode some text to send to the yahoo server. |
45 * @return The g_malloced string in the appropriate encoding. | 46 * @return The g_malloced string in the appropriate encoding. |
46 */ | 47 */ |
47 char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8) | 48 char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8) |
48 { | 49 { |
49 struct yahoo_data *yd = gc->proto_data; | 50 struct yahoo_data *yd = gc->proto_data; |
50 char *ret; | 51 char *ret, *strtmp; |
52 int newlen; | |
51 const char *to_codeset; | 53 const char *to_codeset; |
52 | 54 |
53 if (yd->jp && utf8 && *utf8) | 55 if (yd->jp && utf8 && *utf8) |
54 *utf8 = FALSE; | 56 *utf8 = FALSE; |
55 | 57 |
59 if (yd->jp) | 61 if (yd->jp) |
60 to_codeset = "SHIFT_JIS"; | 62 to_codeset = "SHIFT_JIS"; |
61 else | 63 else |
62 to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1"); | 64 to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1"); |
63 | 65 |
64 ret = g_convert_with_fallback(str, strlen(str), to_codeset, "UTF-8", "?", NULL, NULL, NULL); | 66 strtmp = sanitize_utf((char *)str, strlen((char *)str), &newlen); |
67 | |
68 ret = g_convert_with_fallback(strtmp, strlen(strtmp), to_codeset, "UTF-8", "?", NULL, NULL, NULL); | |
69 | |
70 g_free(strtmp); | |
71 | |
65 if (ret) | 72 if (ret) |
66 return ret; | 73 return ret; |
67 else | 74 else |
68 return g_strdup(""); | 75 return g_strdup(""); |
69 } | 76 } |
77 * @return The decoded, utf-8 string, which must be g_free()'d. | 84 * @return The decoded, utf-8 string, which must be g_free()'d. |
78 */ | 85 */ |
79 char *yahoo_string_decode(PurpleConnection *gc, const char *str, gboolean utf8) | 86 char *yahoo_string_decode(PurpleConnection *gc, const char *str, gboolean utf8) |
80 { | 87 { |
81 struct yahoo_data *yd = gc->proto_data; | 88 struct yahoo_data *yd = gc->proto_data; |
82 char *ret; | 89 char *ret, *tmp; |
83 const char *from_codeset; | 90 char *from_codeset; |
91 int newlen; | |
84 | 92 |
85 if (utf8) { | 93 if (utf8) { |
86 if (g_utf8_validate(str, -1, NULL)) | 94 if (g_utf8_validate(str, -1, NULL)) |
87 return g_strdup(str); | 95 return g_strdup(str); |
88 } | 96 } |
90 if (yd->jp) | 98 if (yd->jp) |
91 from_codeset = "SHIFT_JIS"; | 99 from_codeset = "SHIFT_JIS"; |
92 else | 100 else |
93 from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1"); | 101 from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1"); |
94 | 102 |
95 ret = g_convert_with_fallback(str, strlen(str), "UTF-8", from_codeset, NULL, NULL, NULL, NULL); | 103 /* yaz: it's a kind of voodoo to avoid malconversion of "~". */ |
96 | 104 tmp = g_convert(str, strlen(str), "EUC-JP", from_codeset, NULL, NULL, NULL); |
97 if (ret) | 105 if(tmp) { |
106 ret = g_convert(tmp, strlen(tmp), "UTF-8", "EUC-JP", NULL, NULL, NULL); | |
107 g_free(tmp); | |
108 } else { | |
109 ret = g_convert_with_fallback(str, strlen(str), "UTF-8", from_codeset, NULL, NULL, NULL, NULL); | |
110 } | |
111 | |
112 if (ret){ | |
113 tmp = ret; | |
114 ret = botch_utf(ret, strlen(ret), &newlen); | |
115 g_free(tmp); | |
98 return ret; | 116 return ret; |
117 } | |
99 else | 118 else |
100 return g_strdup(""); | 119 return g_strdup(""); |
101 } | 120 } |
102 | 121 |
103 /* | 122 /* |