Mercurial > pidgin
comparison src/list.c @ 2825:8cd878c14090
[gaim-migrate @ 2838]
come on baby let's take a chance
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sat, 01 Dec 2001 21:38:29 +0000 |
parents | 37d80035e77f |
children | 4697411bd90c |
comparison
equal
deleted
inserted
replaced
2824:2c39e70dd07c | 2825:8cd878c14090 |
---|---|
479 dlist = dlist->next; | 479 dlist = dlist->next; |
480 } | 480 } |
481 } | 481 } |
482 | 482 |
483 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ | 483 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ |
484 static void translate_lst(FILE *src_fp, char *dest) | 484 static GString *translate_lst(FILE *src_fp) |
485 { | 485 { |
486 char line[BUF_LEN], *line2; | 486 char line[BUF_LEN], *line2; |
487 char *name; | 487 char *name; |
488 int i; | 488 int i; |
489 | 489 |
490 sprintf(dest, "m 1\n"); | 490 GString *dest = g_string_new("m 1\n"); |
491 | 491 |
492 while (fgets(line, BUF_LEN, src_fp)) { | 492 while (fgets(line, BUF_LEN, src_fp)) { |
493 line2 = g_strchug(line); | 493 line2 = g_strchug(line); |
494 if (strstr(line2, "group") == line2) { | 494 if (strstr(line2, "group") == line2) { |
495 name = strpbrk(line2, " \t\n\r\f") + 1; | 495 name = strpbrk(line2, " \t\n\r\f") + 1; |
496 strcat(dest, "g "); | 496 dest = g_string_append(dest, "g "); |
497 for (i = 0; i < strcspn(name, "\n\r"); i++) | 497 for (i = 0; i < strcspn(name, "\n\r"); i++) |
498 if (name[i] != '\"') | 498 if (name[i] != '\"') |
499 strncat(dest, &name[i], 1); | 499 dest = g_string_append_c(dest, name[i]); |
500 strcat(dest, "\n"); | 500 dest = g_string_append_c(dest, '\n'); |
501 } | 501 } |
502 if (strstr(line2, "buddy") == line2) { | 502 if (strstr(line2, "buddy") == line2) { |
503 name = strpbrk(line2, " \t\n\r\f") + 1; | 503 name = strpbrk(line2, " \t\n\r\f") + 1; |
504 strcat(dest, "b "); | 504 dest = g_string_append(dest, "b "); |
505 for (i = 0; i < strcspn(name, "\n\r"); i++) | 505 for (i = 0; i < strcspn(name, "\n\r"); i++) |
506 if (name[i] != '\"') | 506 if (name[i] != '\"') |
507 strncat(dest, &name[i], 1); | 507 dest = g_string_append_c(dest, name[i]); |
508 strcat(dest, "\n"); | 508 dest = g_string_append_c(dest, '\n'); |
509 } | 509 } |
510 } | 510 } |
511 | 511 |
512 return; | 512 return dest; |
513 } | 513 } |
514 | 514 |
515 | 515 |
516 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ | 516 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ |
517 static void translate_blt(FILE *src_fp, char *dest) | 517 static GString *translate_blt(FILE *src_fp) |
518 { | 518 { |
519 int i; | 519 int i; |
520 char line[BUF_LEN]; | 520 char line[BUF_LEN]; |
521 char *buddy; | 521 char *buddy; |
522 | 522 |
523 sprintf(dest, "m 1\n"); | 523 GString *dest = g_string_new("m 1\n"); |
524 | 524 |
525 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | 525 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); |
526 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | 526 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); |
527 | 527 |
528 while (1) { | 528 while (1) { |
531 break; | 531 break; |
532 | 532 |
533 if (strchr(line, '{') != NULL) { | 533 if (strchr(line, '{') != NULL) { |
534 /* Syntax starting with "<group> {" */ | 534 /* Syntax starting with "<group> {" */ |
535 | 535 |
536 strcat(dest, "g "); | 536 dest = g_string_append(dest, "g "); |
537 buddy = g_strchug(strtok(line, "{")); | 537 buddy = g_strchug(strtok(line, "{")); |
538 for (i = 0; i < strlen(buddy); i++) { | 538 for (i = 0; i < strlen(buddy); i++) |
539 if (buddy[i] != '\"') { | 539 if (buddy[i] != '\"') |
540 strncat(dest, &buddy[i], 1); | 540 dest = g_string_append_c(dest, buddy[i]); |
541 } | 541 dest = g_string_append_c(dest, '\n'); |
542 } | |
543 strcat(dest, "\n"); | |
544 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { | 542 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { |
545 gboolean pounce = FALSE; | 543 gboolean pounce = FALSE; |
544 char *e; | |
546 g_strchomp(line); | 545 g_strchomp(line); |
547 buddy = g_strchug(line); | 546 buddy = g_strchug(line); |
548 debug_printf("\nbuddy: \"%s\"\n\n", buddy); | 547 debug_printf("\nbuddy: \"%s\"\n\n", buddy); |
549 strcat(dest, "b "); | 548 dest = g_string_append(dest, "b "); |
550 if (strchr(buddy, '{') != NULL) { | 549 if (strchr(buddy, '{') != NULL) { |
551 /* buddy pounce, etc */ | 550 /* buddy pounce, etc */ |
552 char *pos = strchr(buddy, '{') - 1; | 551 char *pos = strchr(buddy, '{') - 1; |
553 *pos = 0; | 552 *pos = 0; |
554 pounce = TRUE; | 553 pounce = TRUE; |
555 } | 554 } |
556 if (strchr(buddy, '\"') != NULL) { | 555 if ((e = strchr(buddy, '\"')) != NULL) { |
556 *e = '\0'; | |
557 buddy++; | 557 buddy++; |
558 strncat(dest, buddy, strchr(buddy, '\"') - buddy); | 558 } |
559 } else | 559 dest = g_string_append(dest, buddy); |
560 strcat(dest, buddy); | 560 dest = g_string_append_c(dest, '\n'); |
561 strcat(dest, "\n"); | |
562 if (pounce) | 561 if (pounce) |
563 do | 562 do |
564 fgets(line, BUF_LEN, src_fp); | 563 fgets(line, BUF_LEN, src_fp); |
565 while (!strchr(line, '}')); | 564 while (!strchr(line, '}')); |
566 } | 565 } |
567 } else { | 566 } else { |
568 | 567 |
569 /* Syntax "group buddy buddy ..." */ | 568 /* Syntax "group buddy buddy ..." */ |
570 buddy = g_strchug(strtok(line, " \n")); | 569 buddy = g_strchug(strtok(line, " \n")); |
571 strcat(dest, "g "); | 570 dest = g_string_append(dest, "g "); |
572 if (strchr(buddy, '\"') != NULL) { | 571 if (strchr(buddy, '\"') != NULL) { |
573 strcat(dest, &buddy[1]); | 572 dest = g_string_append(dest, &buddy[1]); |
574 strcat(dest, " "); | 573 dest = g_string_append_c(dest, ' '); |
575 buddy = g_strchug(strtok(NULL, " \n")); | 574 buddy = g_strchug(strtok(NULL, " \n")); |
576 while (strchr(buddy, '\"') == NULL) { | 575 while (strchr(buddy, '\"') == NULL) { |
577 strcat(dest, buddy); | 576 dest = g_string_append(dest, buddy); |
578 strcat(dest, " "); | 577 dest = g_string_append_c(dest, ' '); |
579 buddy = g_strchug(strtok(NULL, " \n")); | 578 buddy = g_strchug(strtok(NULL, " \n")); |
580 } | 579 } |
581 strncat(dest, buddy, strlen(buddy) - 1); | 580 buddy[strlen(buddy) - 1] = '\0'; |
581 dest = g_string_append(dest, buddy); | |
582 } else { | 582 } else { |
583 strcat(dest, buddy); | 583 dest = g_string_append(dest, buddy); |
584 } | 584 } |
585 strcat(dest, "\n"); | 585 dest = g_string_append_c(dest, '\n'); |
586 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { | 586 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { |
587 strcat(dest, "b "); | 587 dest = g_string_append(dest, "b "); |
588 if (strchr(buddy, '\"') != NULL) { | 588 if (strchr(buddy, '\"') != NULL) { |
589 strcat(dest, &buddy[1]); | 589 dest = g_string_append(dest, &buddy[1]); |
590 strcat(dest, " "); | 590 dest = g_string_append_c(dest, ' '); |
591 buddy = g_strchug(strtok(NULL, " \n")); | 591 buddy = g_strchug(strtok(NULL, " \n")); |
592 while (strchr(buddy, '\"') == NULL) { | 592 while (strchr(buddy, '\"') == NULL) { |
593 strcat(dest, buddy); | 593 dest = g_string_append(dest, buddy); |
594 strcat(dest, " "); | 594 dest = g_string_append_c(dest, ' '); |
595 buddy = g_strchug(strtok(NULL, " \n")); | 595 buddy = g_strchug(strtok(NULL, " \n")); |
596 } | 596 } |
597 strncat(dest, buddy, strlen(buddy) - 1); | 597 buddy[strlen(buddy) - 1] = '\0'; |
598 dest = g_string_append(dest, buddy); | |
598 } else { | 599 } else { |
599 strcat(dest, buddy); | 600 dest = g_string_append(dest, buddy); |
600 } | 601 } |
601 strcat(dest, "\n"); | 602 dest = g_string_append_c(dest, '\n'); |
602 } | 603 } |
603 } | 604 } |
604 } | 605 } |
605 | 606 |
606 return; | 607 return dest; |
608 } | |
609 | |
610 static GString *translate_gnomeicu(FILE *src_fp) | |
611 { | |
612 char line[BUF_LEN]; | |
613 GString *dest = g_string_new("m 1\ng Buddies\n"); | |
614 | |
615 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); | |
616 | |
617 while (fgets(line, BUF_LEN, src_fp)) { | |
618 char *eq; | |
619 g_strchomp(line); | |
620 if (line[0] == '\n' || line[0] == '[') | |
621 break; | |
622 eq = strchr(line, '='); | |
623 if (!eq) | |
624 break; | |
625 *eq = ':'; | |
626 eq = strchr(eq, ','); | |
627 if (eq) | |
628 *eq = '\0'; | |
629 dest = g_string_append(dest, "b "); | |
630 dest = g_string_append(dest, line); | |
631 dest = g_string_append_c(dest, '\n'); | |
632 } | |
633 | |
634 return dest; | |
607 } | 635 } |
608 | 636 |
609 static gchar *get_screenname_filename(const char *name) | 637 static gchar *get_screenname_filename(const char *name) |
610 { | 638 { |
611 gchar **split; | 639 gchar **split; |
656 return ret; | 684 return ret; |
657 } | 685 } |
658 | 686 |
659 void do_import(struct gaim_connection *gc, char *filename) | 687 void do_import(struct gaim_connection *gc, char *filename) |
660 { | 688 { |
661 char *buf = g_malloc(BUF_LONG * 2); | 689 GString *buf = NULL; |
662 char *buf2; | 690 char first[64]; |
663 char *first = g_malloc(64); | |
664 char *file; | |
665 char path[PATHSIZE]; | 691 char path[PATHSIZE]; |
666 char *g_screenname; | |
667 int len; | 692 int len; |
668 FILE *f; | 693 FILE *f; |
694 struct stat st; | |
669 | 695 |
670 if (filename) { | 696 if (filename) { |
671 g_snprintf(path, sizeof(path), "%s", filename); | 697 g_snprintf(path, sizeof(path), "%s", filename); |
672 } else { | 698 } else { |
673 g_screenname = get_screenname_filename(gc->username); | 699 char *g_screenname = get_screenname_filename(gc->username); |
674 | 700 char *file = gaim_user_dir(); |
675 file = gaim_user_dir(); | 701 |
676 if (file != (char *)NULL) { | 702 if (file != (char *)NULL) { |
677 sprintf(path, "%s/%s.%d.blist", file, g_screenname, gc->protocol); | 703 sprintf(path, "%s/%s.%d.blist", file, g_screenname, gc->protocol); |
678 g_free(file); | 704 g_free(file); |
679 g_free(g_screenname); | 705 g_free(g_screenname); |
680 } else { | 706 } else { |
681 g_free(g_screenname); | 707 g_free(g_screenname); |
682 g_free(buf); | |
683 g_free(first); | |
684 return; | 708 return; |
685 } | 709 } |
710 } | |
711 | |
712 if (stat(path, &st)) { | |
713 debug_printf("Unable to stat %s.\n", path); | |
714 return; | |
686 } | 715 } |
687 | 716 |
688 if (!(f = fopen(path, "r"))) { | 717 if (!(f = fopen(path, "r"))) { |
689 debug_printf("Unable to open %s.\n", path); | 718 debug_printf("Unable to open %s.\n", path); |
690 g_free(buf); | |
691 g_free(first); | |
692 return; | 719 return; |
693 } | 720 } |
694 | 721 |
695 fgets(first, 64, f); | 722 fgets(first, 64, f); |
696 | 723 |
697 /* AIM 4 buddy list */ | 724 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) |
725 fgets(first, 64, f); | |
726 | |
698 if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | 727 if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { |
728 /* AIM 4 buddy list */ | |
699 debug_printf("aim 4\n"); | 729 debug_printf("aim 4\n"); |
700 rewind(f); | 730 rewind(f); |
701 translate_blt(f, buf); | 731 buf = translate_blt(f); |
702 debug_printf("%s\n", buf); | 732 } else if (strstr(first, "group") != NULL) { |
703 buf2 = buf; | |
704 buf = g_malloc(8193); | |
705 g_snprintf(buf, 8192, "toc_set_config {%s}\n", buf2); | |
706 g_free(buf2); | |
707 /* AIM 3 buddy list */ | 733 /* AIM 3 buddy list */ |
708 } else if (strstr(first, "group") != NULL) { | |
709 debug_printf("aim 3\n"); | 734 debug_printf("aim 3\n"); |
710 rewind(f); | 735 rewind(f); |
711 translate_lst(f, buf); | 736 buf = translate_lst(f); |
712 debug_printf("%s\n", buf); | 737 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { |
713 buf2 = buf; | 738 /* GnomeICU (hopefully) */ |
714 buf = g_malloc(8193); | 739 debug_printf("gnomeicu\n"); |
715 g_snprintf(buf, 8192, "toc_set_config {%s}\n", buf2); | 740 rewind(f); |
716 g_free(buf2); | 741 buf = translate_gnomeicu(f); |
742 } else if (first[0] == 'm') { | |
717 /* Gaim buddy list - no translation */ | 743 /* Gaim buddy list - no translation */ |
718 } else if (first[0] == 'm') { | 744 char buf2[BUF_LONG * 2]; |
745 buf = g_string_new(""); | |
719 rewind(f); | 746 rewind(f); |
720 len = fread(buf, 1, BUF_LONG * 2, f); | 747 while (1) { |
721 buf[len] = '\0'; | 748 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); |
722 buf2 = buf; | 749 if (len <= 0) |
723 buf = g_malloc(8193); | 750 break; |
724 g_snprintf(buf, 8192, "toc_set_config {%s}\n", buf2); | 751 buf2[len] = '\0'; |
725 g_free(buf2); | 752 buf = g_string_append(buf, buf2); |
726 /* Something else */ | 753 if (len != BUF_LONG * 2 - 1) |
727 } else { | 754 break; |
728 g_free(buf); | 755 } |
729 g_free(first); | 756 } |
730 fclose(f); | |
731 return; | |
732 } | |
733 | |
734 parse_toc_buddy_list(gc, buf); | |
735 | 757 |
736 fclose(f); | 758 fclose(f); |
737 | 759 |
738 g_free(buf); | 760 if (buf) { |
739 g_free(first); | 761 buf = g_string_prepend(buf, "toc_set_config {"); |
762 buf = g_string_append(buf, "}\n"); | |
763 parse_toc_buddy_list(gc, buf->str); | |
764 g_string_free(buf, TRUE); | |
765 } | |
740 } | 766 } |
741 | 767 |
742 void do_export(struct gaim_connection *g) | 768 void do_export(struct gaim_connection *g) |
743 { | 769 { |
744 FILE *dir; | 770 FILE *dir; |