Mercurial > pidgin
comparison src/util.c @ 7824:1663c076a744
[gaim-migrate @ 8476]
Changes from revo/shx. They're still all #if 0'ed out and what not.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 10 Dec 2003 06:34:11 +0000 |
parents | 8e60ddc28a22 |
children | 13334c29799b |
comparison
equal
deleted
inserted
replaced
7823:35cd3ef34fb0 | 7824:1663c076a744 |
---|---|
354 g_free(orig); | 354 g_free(orig); |
355 | 355 |
356 return tmp; | 356 return tmp; |
357 | 357 |
358 #if 0 | 358 #if 0 |
359 /* This is revo/shx's version, and it caused coredumps for me */ | 359 /* The shx version! */ |
360 char *cur, *mark; | 360 const char *cur, *mark; |
361 char *unencoded_start, *unencoded_end; | 361 const char *unencoded, *encoded; |
362 char *charset, *encoding, *word, *decoded; | |
363 char *n, *new; | 362 char *n, *new; |
364 | 363 |
365 n = new = g_malloc(strlen(str)); | 364 n = new = g_malloc(strlen(str)); |
366 charset = word = NULL; | |
367 | 365 |
368 gaim_debug(GAIM_DEBUG_ERROR, "XXX", "new is %d\n", new); | 366 gaim_debug(GAIM_DEBUG_ERROR, "XXX", "new is %d\n", new); |
369 /* Here we will be looking for encoded words and if they seem to be | 367 |
370 * valid then decode them */ | 368 /* |
371 | 369 * Here we will be looking for encoded words and if they seem to be |
372 for (unencoded_start = cur = str; | 370 * valid then decode them. |
373 (unencoded_end = cur = strstr(cur, "=?")); | 371 * They are of this form: =?charset?encoding?text?= |
374 unencoded_start = cur) { | 372 */ |
375 | 373 for ( unencoded = cur = str; |
376 int len; | 374 (encoded = cur = strstr(cur, "=?")); |
377 char *token; | 375 unencoded = cur) { |
378 GQueue *tokens = g_queue_new(); | 376 |
379 | 377 gboolean found_word = FALSE; |
380 for (cur += 2, mark = cur; *cur; cur++) { | 378 int i, num, len, dec_len; |
379 char *decoded, *converted; | |
380 char *tokens[3]; | |
381 | |
382 /* Let's look for tokens, they are between ?'s */ | |
383 for (cur += 2, mark = cur, num = 0; *cur; cur++) { | |
381 if (*cur == '?') { | 384 if (*cur == '?') { |
382 token = g_strndup(mark, cur - mark); | 385 if (num > 2) |
383 g_queue_push_head(tokens, token); | 386 /* No more than 3 tokens. */ |
387 break; | |
388 | |
389 tokens[num++] = g_strndup(mark, cur - mark); | |
384 | 390 |
385 mark = (cur + 1); | 391 mark = (cur + 1); |
386 | 392 |
387 if (mark[0] == '=' && mark[1] == '\0') | 393 if (mark[0] == '=' && mark[1] == '\0') { |
394 found_word = TRUE; | |
388 break; | 395 break; |
389 } else { | 396 } |
390 if ((tokens->length == 2) && (*cur == ' ')) | 397 } |
391 break; | 398 #if 0 |
392 else if ((tokens->length < 2) && (strchr("()<>@,;:/[]", *cur))) | 399 /* I think this is rarely going to happen, if at all */ |
393 break; | 400 else if ((num < 2) && (strchr("()<>@,;:/[]", *cur))) |
394 else if (tokens->length > 2) | 401 /* There can't be these characters in the first two tokens. */ |
395 break; | 402 break; |
396 } | 403 else if ((num == 2) && (*cur == ' ')) |
404 /* There can't be spaces in the third token. */ | |
405 break; | |
406 #endif | |
397 } | 407 } |
398 | 408 |
399 cur += 2; | 409 cur += 2; |
400 gaim_debug(GAIM_DEBUG_ERROR, "XXX", "new is %d, this is probably different than above, that's bad\n", new); | 410 gaim_debug(GAIM_DEBUG_ERROR, "XXX", "new is %d, this is probably different than above, that's bad\n", new); |
401 | 411 if (found_word) { |
402 if ((tokens->length == 3) && (*mark == '=')) { | 412 /* We found an encoded word. */ |
403 len = unencoded_end - unencoded_start; | 413 /* =?charset?encoding?text?= */ |
404 n = strncpy(n, unencoded_start, len) + len; | 414 len = encoded - unencoded; |
405 | 415 n = strncpy(n, unencoded, len) + len; |
406 charset = g_queue_pop_tail(tokens); | 416 |
407 encoding = g_queue_pop_tail(tokens); | 417 if (g_ascii_strcasecmp(tokens[1], "Q") == 0) |
408 word = g_queue_pop_tail(tokens); | 418 gaim_quotedp_decode(tokens[2], &decoded, &dec_len); |
409 | 419 else if (g_ascii_strcasecmp(tokens[1], "B") == 0) |
410 if ((decoded = gaim_mime_decode_word(charset, encoding, word))) { | 420 gaim_base64_decode(tokens[2], &decoded, &dec_len); |
411 len = strlen(decoded); | 421 else |
412 n = strncpy(n, decoded, len) + len; | 422 decoded = NULL; |
423 | |
424 if (decoded) { | |
425 converted = g_convert(decoded, dec_len, OUT_CHARSET, tokens[0], | |
426 NULL, &len, NULL); | |
413 g_free(decoded); | 427 g_free(decoded); |
414 } | 428 |
415 | 429 n = strncpy(n, converted, len) + len; |
416 g_free(charset); | 430 g_free(converted); |
417 g_free(encoding); | 431 } |
418 g_free(word); | |
419 } else { | 432 } else { |
420 len = cur - unencoded_start; | 433 /* Some unencoded text. */ |
421 n = strncpy(n, unencoded_start, len) + len; | 434 len = cur - unencoded; |
422 | 435 n = strncpy(n, unencoded, len) + len; |
423 while ((token = g_queue_pop_tail(tokens))) | 436 } |
424 g_free(token); | 437 |
425 } | 438 for (i = 0; i < num; i++) |
426 | 439 g_free(tokens[i]); |
427 g_queue_free(tokens); | |
428 } | 440 } |
429 | 441 |
430 *n = '\0'; | 442 *n = '\0'; |
431 | 443 |
432 if (*unencoded_start) | 444 /* There is unencoded text at the end. */ |
433 n = strcpy(n, unencoded_start); | 445 if (*unencoded) |
446 n = strcpy(n, unencoded); | |
434 | 447 |
435 return new; | 448 return new; |
436 #endif | 449 #endif |
437 } | 450 } |
438 | 451 |