comparison libpurple/protocols/yahoo/util.c @ 27767:76ff0ad87964

propagate from branch 'im.pidgin.pidgin' (head 9de3934cd71a8b08f0f6da39df8f0102d36fbd2b) to branch 'im.pidgin.pidgin.yaz' (head d439d42fe8d0ee4a40486b4de12acb4116bc2e58)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 25 Feb 2008 05:45:57 +0000
parents e9cf897bd873
children c9b4fdb3fdb1
comparison
equal deleted inserted replaced
22325:9d02eb04f406 27767:76ff0ad87964
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 * Returns cookies formatted as a null terminated string for the given connection. 36 * Returns cookies formatted as a null terminated string for the given connection.
36 * Must g_free return value. 37 * Must g_free return value.
109 * @return The g_malloced string in the appropriate encoding. 110 * @return The g_malloced string in the appropriate encoding.
110 */ 111 */
111 char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8) 112 char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8)
112 { 113 {
113 struct yahoo_data *yd = gc->proto_data; 114 struct yahoo_data *yd = gc->proto_data;
114 char *ret; 115 char *ret, *strtmp;
116 int newlen;
115 const char *to_codeset; 117 const char *to_codeset;
116 118
117 if (yd->jp && utf8 && *utf8) 119 if (yd->jp && utf8 && *utf8)
118 *utf8 = FALSE; 120 *utf8 = FALSE;
119 121
123 if (yd->jp) 125 if (yd->jp)
124 to_codeset = "SHIFT_JIS"; 126 to_codeset = "SHIFT_JIS";
125 else 127 else
126 to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1"); 128 to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1");
127 129
128 ret = g_convert_with_fallback(str, -1, to_codeset, "UTF-8", "?", NULL, NULL, NULL); 130 // strtmp = sanitize_utf((char *)str, strlen((char *)str), &newlen);
131 strtmp = g_strdup(str);
132
133 ret = g_convert_with_fallback(strtmp, strlen(strtmp), to_codeset, "UTF-8", "?", NULL, NULL, NULL);
134
135 g_free(strtmp);
136
129 if (ret) 137 if (ret)
130 return ret; 138 return ret;
131 else 139 else
132 return g_strdup(""); 140 return g_strdup("");
133 } 141 }
141 * @return The decoded, utf-8 string, which must be g_free()'d. 149 * @return The decoded, utf-8 string, which must be g_free()'d.
142 */ 150 */
143 char *yahoo_string_decode(PurpleConnection *gc, const char *str, gboolean utf8) 151 char *yahoo_string_decode(PurpleConnection *gc, const char *str, gboolean utf8)
144 { 152 {
145 struct yahoo_data *yd = gc->proto_data; 153 struct yahoo_data *yd = gc->proto_data;
146 char *ret; 154 char *ret, *tmp;
147 const char *from_codeset; 155 char *from_codeset;
156 int newlen;
148 157
149 if (utf8) { 158 if (utf8) {
150 if (g_utf8_validate(str, -1, NULL)) 159 if (g_utf8_validate(str, -1, NULL))
151 return g_strdup(str); 160 return g_strdup(str);
152 } 161 }
154 if (yd->jp) 163 if (yd->jp)
155 from_codeset = "SHIFT_JIS"; 164 from_codeset = "SHIFT_JIS";
156 else 165 else
157 from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1"); 166 from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1");
158 167
159 ret = g_convert_with_fallback(str, -1, "UTF-8", from_codeset, NULL, NULL, NULL, NULL); 168 /* yaz: it's a kind of voodoo to avoid malconversion of "~". */
160 169 tmp = g_convert(str, strlen(str), "EUC-JP", from_codeset, NULL, NULL, NULL);
161 if (ret) 170 if(tmp) {
171 ret = g_convert(tmp, strlen(tmp), "UTF-8", "EUC-JP", NULL, NULL, NULL);
172 g_free(tmp);
173 } else {
174 ret = g_convert_with_fallback(str, strlen(str), "UTF-8", from_codeset, NULL, NULL, NULL, NULL);
175 }
176
177 if (ret){
178 tmp = ret;
179 // ret = botch_utf(tmp, strlen(tmp), &newlen);
180 ret = g_strdup(tmp);
181 g_free(tmp);
162 return ret; 182 return ret;
183 }
163 else 184 else
164 return g_strdup(""); 185 return g_strdup("");
165 } 186 }
166 187
167 char *yahoo_convert_to_numeric(const char *str) 188 char *yahoo_convert_to_numeric(const char *str)