comparison src/protocols/irc/parse.c @ 10258:357d4fa1bfbe

[gaim-migrate @ 11400] This is the IRC fallback encoding patch and gaim_utf8_salvage function that just hit oldstatus. If CVS didn't suck, I wouldn't have to generate two commits for this. :-P committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Wed, 24 Nov 2004 06:39:47 +0000
parents cbdce0acbbe6
children dabcadc17ca0
comparison
equal deleted inserted replaced
10257:b98f856e2e5e 10258:357d4fa1bfbe
24 24
25 #include "accountopt.h" 25 #include "accountopt.h"
26 #include "conversation.h" 26 #include "conversation.h"
27 #include "notify.h" 27 #include "notify.h"
28 #include "debug.h" 28 #include "debug.h"
29 #include "util.h"
29 #include "cmds.h" 30 #include "cmds.h"
30 #include "irc.h" 31 #include "irc.h"
31 32
32 #include <stdio.h> 33 #include <stdio.h>
33 #include <stdlib.h> 34 #include <stdlib.h>
199 200
200 static char *irc_send_convert(struct irc_conn *irc, const char *string) 201 static char *irc_send_convert(struct irc_conn *irc, const char *string)
201 { 202 {
202 char *utf8; 203 char *utf8;
203 GError *err = NULL; 204 GError *err = NULL;
204 const gchar *charset; 205 gchar **encodings;
205 206 const gchar *enclist;
206 charset = gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); 207
207 if (!strcasecmp("UTF-8", charset)) 208 enclist = gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET);
209 encodings = g_strsplit(enclist, ",", 2);
210
211 if (encodings[0] == NULL || !strcasecmp("UTF-8", encodings[0]))
208 return g_strdup(string); 212 return g_strdup(string);
209 213
210 utf8 = g_convert(string, strlen(string), charset, "UTF-8", NULL, NULL, &err); 214 utf8 = g_convert(string, strlen(string), encodings[0], "UTF-8", NULL, NULL, &err);
211 if (err) { 215 if (err) {
212 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Send conversion error: %s\n", err->message); 216 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Send conversion error: %s\n", err->message);
213 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Sending as UTF-8 instead of %s\n", charset); 217 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Sending as UTF-8 instead of %s\n", encodings[0]);
214 utf8 = g_strdup(string); 218 utf8 = g_strdup(string);
215 g_error_free(err); 219 g_error_free(err);
216 } 220 }
217 221 g_strfreev(encodings);
222
218 return utf8; 223 return utf8;
219 } 224 }
220 225
221 static char *irc_recv_convert(struct irc_conn *irc, const char *string) 226 static char *irc_recv_convert(struct irc_conn *irc, const char *string)
222 { 227 {
223 char *utf8 = NULL; 228 char *utf8 = NULL;
224 GError *err = NULL; 229 const gchar *charset, *enclist;
225 const gchar *charset; 230 gchar **encodings;
226 231 int i;
227 charset = gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET); 232
228 233 enclist = gaim_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET);
229 if (!strcasecmp("UTF-8", charset)) { 234 encodings = g_strsplit(enclist, ",", -1);
230 if (g_utf8_validate(string, strlen(string), NULL)) 235
231 utf8 = g_strdup(string); 236 if (encodings[0] == NULL)
232 } else { 237 return gaim_utf8_salvage(string);
233 utf8 = g_convert(string, strlen(string), "UTF-8", charset, NULL, NULL, &err); 238
234 } 239 for (i = 0; encodings[i] != NULL; i++) {
235 240 charset = encodings[i];
236 if (err) { 241 while (*charset == ' ')
237 gaim_debug(GAIM_DEBUG_ERROR, "irc", "recv conversion error: %s\n", err->message); 242 charset++;
238 g_error_free(err); 243
239 } 244 if (!strcasecmp("UTF-8", charset)) {
240 245 if (g_utf8_validate(string, strlen(string), NULL))
241 if (utf8 == NULL) 246 utf8 = g_strdup(string);
242 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); 247 } else {
243 248 utf8 = g_convert(string, strlen(string), "UTF-8", charset, NULL, NULL, NULL);
244 return utf8; 249 }
250
251 if (utf8) {
252 g_strfreev(encodings);
253 return utf8;
254 }
255 }
256
257 return gaim_utf8_salvage(string);
245 } 258 }
246 259
247 /* XXX tag closings are not necessarily correctly nested here! If we 260 /* XXX tag closings are not necessarily correctly nested here! If we
248 * get a ^O or reach the end of the string and there are open 261 * get a ^O or reach the end of the string and there are open
249 * tags, they are closed in a fixed order ... this means, for 262 * tags, they are closed in a fixed order ... this means, for