Mercurial > pidgin
comparison src/list.c @ 4404:16f7f9451814
[gaim-migrate @ 4673]
This should fixing importing blists with mad crazy wild i18n characters.
It's from Paco-Paco. No peeps have had problems with it, and it has
helped a dude or dudet or two. Totally.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 23 Jan 2003 18:54:01 +0000 |
parents | d0cef2cc9660 |
children | 94bf204f837e |
comparison
equal
deleted
inserted
replaced
4403:5a7fda352a8d | 4404:16f7f9451814 |
---|---|
39 #include "win32dep.h" | 39 #include "win32dep.h" |
40 #endif | 40 #endif |
41 | 41 |
42 #define PATHSIZE 1024 | 42 #define PATHSIZE 1024 |
43 | 43 |
44 /* This guy does its best to convert a string to UTF-8 from an unknown | |
45 * encoding by checking the locale and trying some sane defaults ... | |
46 * if everything fails it returns NULL. */ | |
47 static char *whatever_to_utf8(const char *str); | |
48 | |
44 void remove_buddy(struct buddy *rem_b) | 49 void remove_buddy(struct buddy *rem_b) |
45 { | 50 { |
46 if(rem_b->user->gc) { | 51 if(rem_b->user->gc) { |
47 struct group *rem_g = find_group_by_buddy(rem_b); | 52 struct group *rem_g = find_group_by_buddy(rem_b); |
48 | 53 |
255 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | 260 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); |
256 do { | 261 do { |
257 if (c == NULL) | 262 if (c == NULL) |
258 break; | 263 break; |
259 if (*c == 'g') { | 264 if (*c == 'g') { |
260 strncpy(current, c + 2, sizeof(current)); | 265 char *utf8 = NULL; |
266 utf8 = whatever_to_utf8(c + 2); | |
267 if (utf8 == NULL) { | |
268 g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
269 } else { | |
270 g_strlcpy(current, utf8, sizeof(current)); | |
271 g_free(utf8); | |
272 } | |
261 if (!find_group(current)) { | 273 if (!find_group(current)) { |
262 add_group(current); | 274 add_group(current); |
263 } | 275 } |
264 } else if (*c == 'b' && !find_buddy(user, c + 2)) { | 276 } else if (*c == 'b') { /*&& !find_buddy(user, c + 2)) {*/ |
265 char nm[80], sw[BUDDY_ALIAS_MAXLEN], *tmp = c + 2; | 277 char nm[80], sw[BUDDY_ALIAS_MAXLEN], *tmp = c + 2, *a, *utf8 = NULL; |
266 int i = 0; | 278 |
267 while (*tmp != ':' && *tmp && i < sizeof(nm) - 1) | 279 if ((a = strchr(c + 2, ':')) != NULL) { |
268 nm[i++] = *tmp++; | 280 *a++ = '\0'; /* nul the : */ |
269 | 281 } |
270 while (*tmp != ':' && *tmp) | 282 |
271 tmp++; | 283 g_strlcpy(nm, c + 2, sizeof(nm)); |
272 | 284 if (a) { |
273 if (*tmp == ':') | 285 utf8 = whatever_to_utf8(a); |
274 *tmp++ = '\0'; | 286 if (utf8 == NULL) { |
275 | 287 debug_printf ("Failed to convert alias for '%s' to UTF-8\n", nm); |
276 nm[i] = '\0'; | 288 } |
277 i = 0; | 289 } |
278 while (*tmp && i < sizeof(sw) - 1) | 290 if (utf8 == NULL) { |
279 sw[i++] = *tmp++; | 291 sw[0] = '\0'; |
280 sw[i] = '\0'; | 292 } else { |
293 /* This can leave a partial sequence at the end, | |
294 * but who cares? */ | |
295 g_strlcpy(sw, utf8, sizeof(sw)); | |
296 g_free(utf8); | |
297 } | |
298 | |
281 if (!find_buddy(user, nm)) { | 299 if (!find_buddy(user, nm)) { |
282 add_buddy(user, current, nm, sw); | 300 add_buddy(user, current, nm, sw); |
283 bud = g_list_append(bud, c + 2); | 301 bud = g_list_append(bud, nm); |
284 } | 302 } |
285 } else if (*c == 'p') { | 303 } else if (*c == 'p') { |
286 gaim_privacy_permit_add(user, c + 2); | 304 gaim_privacy_permit_add(user, c + 2); |
287 } else if (*c == 'd') { | 305 } else if (*c == 'd') { |
288 gaim_privacy_deny_add(user, c + 2); | 306 gaim_privacy_deny_add(user, c + 2); |
1162 char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | 1180 char *gaim_buddy_get_setting(struct buddy *b, const char *key) { |
1163 if(!b) | 1181 if(!b) |
1164 return NULL; | 1182 return NULL; |
1165 return g_strdup(g_hash_table_lookup(b->settings, key)); | 1183 return g_strdup(g_hash_table_lookup(b->settings, key)); |
1166 } | 1184 } |
1185 | |
1186 static char *whatever_to_utf8(const char *str) | |
1187 { | |
1188 int converted; | |
1189 char *utf8; | |
1190 | |
1191 if (g_utf8_validate(str, -1, NULL)) { | |
1192 return g_strdup(str); | |
1193 } | |
1194 | |
1195 utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL); | |
1196 if (utf8 && converted == strlen (str)) { | |
1197 return(utf8); | |
1198 } else if (utf8) { | |
1199 g_free(utf8); | |
1200 } | |
1201 | |
1202 utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL); | |
1203 if (utf8 && converted == strlen (str)) { | |
1204 return(utf8); | |
1205 } else if (utf8) { | |
1206 g_free(utf8); | |
1207 } | |
1208 | |
1209 return(NULL); | |
1210 } |