comparison src/protocols/gg/gg.c @ 2792:9123abd0db92

[gaim-migrate @ 2805] Arkadiusz Miskiewicz's updates to Gadu-Gadu committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 26 Nov 2001 21:22:56 +0000
parents 8f6365332a05
children 1ffac7cf4e94
comparison
equal deleted inserted replaced
2791:8f6365332a05 2792:9123abd0db92
1 /* 1 /*
2 * gaim - Gadu-Gadu Protocol Plugin 2 * gaim - Gadu-Gadu Protocol Plugin
3 * $Id: gg.c 2804 2001-11-26 20:39:54Z warmenhoven $ 3 * $Id: gg.c 2805 2001-11-26 21:22:56Z warmenhoven $
4 * 4 *
5 * Copyright (C) 2001, Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL> 5 * Copyright (C) 2001 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 10 * (at your option) any later version.
60 60
61 #define AGG_BUF_LEN 1024 61 #define AGG_BUF_LEN 1024
62 62
63 #define AGG_GENDER_NONE -1 63 #define AGG_GENDER_NONE -1
64 64
65 #define AGG_PUBDIR_FORM "/appsvc/fmpubquery2.asp" 65 #define AGG_PUBDIR_USERLIST_EXPORT_FORM "/appsvc/fmcontactsput.asp"
66 #define AGG_PUBDIR_USERLIST_IMPORT_FORM "/appsvc/fmcontactsget.asp"
67 #define AGG_PUBDIR_SEARCH_FORM "/appsvc/fmpubquery2.asp"
66 #define AGG_PUBDIR_MAX_ENTRIES 200 68 #define AGG_PUBDIR_MAX_ENTRIES 200
67 69
68 #define AGG_STATUS_AVAIL _("Available") 70 #define AGG_STATUS_AVAIL _("Available")
69 #define AGG_STATUS_AVAIL_FRIENDS _("Available for friends only") 71 #define AGG_STATUS_AVAIL_FRIENDS _("Available for friends only")
70 #define AGG_STATUS_BUSY _("Away") 72 #define AGG_STATUS_BUSY _("Away")
71 #define AGG_STATUS_BUSY_FRIENDS _("Away for friends only") 73 #define AGG_STATUS_BUSY_FRIENDS _("Away for friends only")
72 #define AGG_STATUS_INVISIBLE _("Invisible") 74 #define AGG_STATUS_INVISIBLE _("Invisible")
73 #define AGG_STATUS_INVISIBLE_FRIENDS _("Invisible for friends only") 75 #define AGG_STATUS_INVISIBLE_FRIENDS _("Invisible for friends only")
74 #define AGG_STATUS_NOT_AVAIL _("Unavailable") 76 #define AGG_STATUS_NOT_AVAIL _("Unavailable")
75 77
78 #define AGG_HTTP_NONE 0
79 #define AGG_HTTP_SEARCH 1
80 #define AGG_HTTP_USERLIST_IMPORT 2
81 #define AGG_HTTP_USERLIST_EXPORT 3
82
76 #define UC_NORMAL 2 83 #define UC_NORMAL 2
77 84
78 struct agg_data { 85 struct agg_data {
79 struct gg_session *sess; 86 struct gg_session *sess;
80 }; 87 };
81 88
82 struct agg_search { 89 struct agg_http {
83 struct gaim_connection *gc; 90 struct gaim_connection *gc;
84 gchar *search_data; 91 gchar *request;
92 gchar *form;
93 gchar *host;
85 int inpa; 94 int inpa;
95 int type;
86 }; 96 };
87 97
88 static char *agg_name() 98 static char *agg_name()
89 { 99 {
90 return "Gadu-Gadu"; 100 return "Gadu-Gadu";
92 102
93 static gchar *charset_convert(const gchar *locstr, char *encsrc, char *encdst) 103 static gchar *charset_convert(const gchar *locstr, char *encsrc, char *encdst)
94 { 104 {
95 #ifdef HAVE_ICONV 105 #ifdef HAVE_ICONV
96 gchar *result = NULL; 106 gchar *result = NULL;
97 if (iconv_string(encdst, encsrc, locstr, locstr+strlen(locstr)+1, &result, NULL) >= 0) 107 if (iconv_string(encdst, encsrc, locstr, locstr + strlen(locstr) + 1, &result, NULL) >= 0)
98 return result; 108 return result;
99 #endif 109 #endif
100 return g_strdup(locstr); 110 return g_strdup(locstr);
101 } 111 }
102 112
200 for (i = 0; i < strlen(data); i++) { 210 for (i = 0; i < strlen(data); i++) {
201 /* locale insensitive, doesn't reflect RFC (1738 section 2.2, 1866 section 8.2.1) */ 211 /* locale insensitive, doesn't reflect RFC (1738 section 2.2, 1866 section 8.2.1) */
202 if ((data[i] >= 'a' && data[i] <= 'z') 212 if ((data[i] >= 'a' && data[i] <= 'z')
203 || (data[i] >= 'A' && data[i] <= 'Z') 213 || (data[i] >= 'A' && data[i] <= 'Z')
204 || (data[i] >= '0' && data[i] <= '9') 214 || (data[i] >= '0' && data[i] <= '9')
205 || data[i] == '=' || data[i] == '&' 215 || data[i] == '=' || data[i] == '&') {
206 || data[i] == '\n' || data[i] == '\r' || data[i] == '\t' || data[i] == '\014') {
207 p = g_realloc(p, j + 1); 216 p = g_realloc(p, j + 1);
208 p[j] = data[i]; 217 p[j] = data[i];
209 j++; 218 j++;
210 } else { 219 } else {
211 p = g_realloc(p, j + 4); /* remember, sprintf appends a '\0' */ 220 p = g_realloc(p, j + 4); /* remember, sprintf appends a '\0' */
369 case GG_EVENT_MSG: 378 case GG_EVENT_MSG:
370 { 379 {
371 gchar *imsg; 380 gchar *imsg;
372 gchar user[20]; 381 gchar user[20];
373 382
374 g_snprintf(user, sizeof(user), "%u", e->event.msg.sender); 383 g_snprintf(user, sizeof(user), "%lu", e->event.msg.sender);
375 if (!allowed_uin(gc, user)) 384 if (!allowed_uin(gc, user))
376 break; 385 break;
377 imsg = charset_convert(e->event.msg.message, "CP1250", find_local_charset()); 386 imsg = charset_convert(e->event.msg.message, "CP1250", find_local_charset());
387 /* e->event.msg.time - we don't know what this time is for */
378 serv_got_im(gc, user, imsg, 0, time((time_t) NULL)); 388 serv_got_im(gc, user, imsg, 0, time((time_t) NULL));
379 g_free(imsg); 389 g_free(imsg);
380 } 390 }
381 break; 391 break;
382 case GG_EVENT_NOTIFY: 392 case GG_EVENT_NOTIFY:
399 default: 409 default:
400 status = UC_NORMAL; 410 status = UC_NORMAL;
401 break; 411 break;
402 } 412 }
403 413
404 g_snprintf(user, sizeof(user), "%u", n->uin); 414 g_snprintf(user, sizeof(user), "%lu", n->uin);
405 serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0, 415 serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0,
406 status, 0); 416 status, 0);
407 n++; 417 n++;
408 } 418 }
409 } 419 }
426 default: 436 default:
427 status = UC_NORMAL; 437 status = UC_NORMAL;
428 break; 438 break;
429 } 439 }
430 440
431 g_snprintf(user, sizeof(user), "%u", e->event.status.uin); 441 g_snprintf(user, sizeof(user), "%lu", e->event.status.uin);
432 serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0, status, 442 serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0, status,
433 0); 443 0);
434 } 444 }
435 break; 445 break;
436 case GG_EVENT_ACK: 446 case GG_EVENT_ACK:
646 gg_notify(gd->sess, userlist, userlist_size); 656 gg_notify(gd->sess, userlist, userlist_size);
647 g_free(userlist); 657 g_free(userlist);
648 } 658 }
649 } 659 }
650 660
651 static void search_results(gpointer data, gint source, GaimInputCondition cond) 661 static void search_results(struct gaim_connection *gc, gchar *webdata)
652 { 662 {
653 struct agg_search *srch = data; 663 gchar **webdata_tbl;
654 struct gaim_connection *gc = srch->gc;
655 gchar *buf; 664 gchar *buf;
656 char *ptr; 665 char *ptr;
657 char *webdata;
658 int len;
659 char read_data;
660 gchar **webdata_tbl;
661 int i, j; 666 int i, j;
662
663 if (!g_slist_find(connections, gc)) {
664 debug_printf("search_callback: g_slist_find error\n");
665 gaim_input_remove(srch->inpa);
666 g_free(srch);
667 close(source);
668 return;
669 }
670
671 webdata = NULL;
672 len = 0;
673
674 while (read(source, &read_data, 1) > 0 || errno == EWOULDBLOCK) {
675 if (errno == EWOULDBLOCK) {
676 errno = 0;
677 continue;
678 }
679
680 if (!read_data)
681 continue;
682
683 len++;
684 webdata = g_realloc(webdata, len);
685 webdata[len - 1] = read_data;
686 }
687
688 webdata = g_realloc(webdata, len + 1);
689 webdata[len] = 0;
690
691 gaim_input_remove(srch->inpa);
692 g_free(srch);
693 close(source);
694 667
695 if ((ptr = strstr(webdata, "query_results:")) == NULL || (ptr = strchr(ptr, '\n')) == NULL) { 668 if ((ptr = strstr(webdata, "query_results:")) == NULL || (ptr = strchr(ptr, '\n')) == NULL) {
696 debug_printf("search_callback: pubdir result [%s]\n", webdata); 669 debug_printf("search_callback: pubdir result [%s]\n", webdata);
697 g_free(webdata); 670 g_free(webdata);
698 do_error_dialog(_("Couldn't get search results"), _("Gadu-Gadu Error")); 671 do_error_dialog(_("Couldn't get search results"), _("Gadu-Gadu Error"));
793 g_show_info_text(gc, NULL, 2, buf, NULL); 766 g_show_info_text(gc, NULL, 2, buf, NULL);
794 767
795 g_free(buf); 768 g_free(buf);
796 } 769 }
797 770
798 static void search_callback(gpointer data, gint source, GaimInputCondition cond) 771 static void agg_import_buddies_results(struct gaim_connection *gc, gchar *webdata)
799 { 772 {
800 struct agg_search *srch = data; 773 gchar *ptr;
801 struct gaim_connection *gc = srch->gc; 774 gchar **users_tbl;
802 gchar *search_data = srch->search_data; 775 int i;
776 if (strstr(webdata, "no_data:")) {
777 g_free(webdata);
778 do_error_dialog(_("There is no Buddy List stored on server. Sorry!"),
779 _("Gadu-Gadu Error"));
780 return;
781 }
782
783 if ((ptr = strstr(webdata, "get_results:")) == NULL || (ptr = strchr(ptr, ':')) == NULL) {
784 debug_printf("agg_import_buddies_list: import buddies result [%s]\n", webdata);
785 g_free(webdata);
786 do_error_dialog(_("Couldn't Import Buddies List from Server"), _("Gadu-Gadu Error"));
787 return;
788 }
789 ptr++;
790
791 users_tbl = g_strsplit(ptr, "\n", AGG_PUBDIR_MAX_ENTRIES);
792 g_free(webdata);
793
794 /* Parse array of Buddies List */
795 for (i = 0; users_tbl[i] != NULL; i++) {
796 gchar **data_tbl;
797 gchar *name, *show;
798
799 g_strdelimit(users_tbl[i], "\r\t\n\015", ' ');
800 data_tbl = g_strsplit(users_tbl[i], ";", 8);
801
802 show = data_tbl[3];
803 name = data_tbl[6];
804
805 if (invalid_uin(name)) {
806 continue;
807 }
808
809 debug_printf("uin: %s\n", name);
810 if (!find_buddy(gc, name)) {
811 /* Default group if none specified on server */
812 gchar *group = g_strdup("Gadu-Gadu");
813 if (strlen(data_tbl[5])) {
814 gchar **group_tbl = g_strsplit(data_tbl[5], ",", 2);
815 if (strlen(group_tbl[0])) {
816 g_free(group);
817 group = g_strdup(group_tbl[0]);
818 }
819 g_strfreev(group_tbl);
820 }
821 /* Add Buddy to our userlist */
822 add_buddy(gc, group, name, strlen(show) ? show : name);
823 do_export(gc);
824 g_free(group);
825 }
826 g_strfreev(data_tbl);
827 }
828 g_strfreev(users_tbl);
829 }
830
831 static void agg_export_buddies_results(struct gaim_connection *gc, gchar *webdata)
832 {
833 if (strstr(webdata, "put_success:")) {
834 g_free(webdata);
835 do_error_dialog(_("Buddies List sucessfully transfered into Server"),
836 _("Gadu-Gadu Information"));
837 return;
838 }
839
840 debug_printf("agg_export_buddies_results: webdata [%s]\n", webdata);
841 g_free(webdata);
842 do_error_dialog(_("Couldn't transfer Buddies List into Server"), _("Gadu-Gadu Error"));
843 }
844
845 static void http_results(gpointer data, gint source, GaimInputCondition cond)
846 {
847 struct agg_http *hdata = data;
848 struct gaim_connection *gc = hdata->gc;
849 char *webdata;
850 int len;
851 char read_data;
852
853 debug_printf("http_results: begin\n");
854
855 if (!g_slist_find(connections, gc)) {
856 debug_printf("search_callback: g_slist_find error\n");
857 gaim_input_remove(hdata->inpa);
858 g_free(hdata);
859 close(source);
860 return;
861 }
862
863 webdata = NULL;
864 len = 0;
865
866 while (read(source, &read_data, 1) > 0 || errno == EWOULDBLOCK) {
867 if (errno == EWOULDBLOCK) {
868 errno = 0;
869 continue;
870 }
871
872 if (!read_data)
873 continue;
874
875 len++;
876 webdata = g_realloc(webdata, len);
877 webdata[len - 1] = read_data;
878 }
879
880 webdata = g_realloc(webdata, len + 1);
881 webdata[len] = 0;
882
883 gaim_input_remove(hdata->inpa);
884 close(source);
885
886 debug_printf("http_results: type %d, webdata [%s]\n", hdata->type, webdata);
887
888 switch (hdata->type) {
889 case AGG_HTTP_SEARCH:
890 search_results(gc, webdata);
891 break;
892 case AGG_HTTP_USERLIST_IMPORT:
893 agg_import_buddies_results(gc, webdata);
894 break;
895 case AGG_HTTP_USERLIST_EXPORT:
896 agg_export_buddies_results(gc, webdata);
897 break;
898 case AGG_HTTP_NONE:
899 default:
900 debug_printf("http_results: unsupported type %d\n", hdata->type);
901 break;
902 }
903
904 g_free(hdata);
905 }
906
907 static void http_req_callback(gpointer data, gint source, GaimInputCondition cond)
908 {
909 struct agg_http *hdata = data;
910 struct gaim_connection *gc = hdata->gc;
911 gchar *request = hdata->request;
803 gchar *buf; 912 gchar *buf;
804 char *ptr; 913 char *ptr;
805 914
806 debug_printf("search_callback enter: begin\n"); 915 debug_printf("http_req_callback: begin\n");
807 916
808 if (!g_slist_find(connections, gc)) { 917 if (!g_slist_find(connections, gc)) {
809 debug_printf("search_callback: g_slist_find error\n"); 918 debug_printf("http_req_callback: g_slist_find error\n");
810 g_free(search_data); 919 g_free(request);
811 g_free(srch); 920 g_free(hdata);
812 close(source); 921 close(source);
813 return; 922 return;
814 } 923 }
815 924
816 if (source == -1) { 925 if (source == -1) {
817 g_free(search_data); 926 g_free(request);
818 g_free(srch); 927 g_free(hdata);
819 return; 928 return;
820 } 929 }
821 930
822 ptr = encode_postdata(search_data); 931 ptr = encode_postdata(request);
823 g_free(search_data); 932 g_free(request);
824 933
825 debug_printf("search_callback: pubdir request [%s]\n", ptr); 934 debug_printf("http_req_callback: http request [%s]\n", ptr);
826 935
827 buf = g_strdup_printf("POST " AGG_PUBDIR_FORM " HTTP/1.0\r\n" 936 buf = g_strdup_printf("POST %s HTTP/1.0\r\n"
828 "Host: " GG_PUBDIR_HOST "\r\n" 937 "Host: %s\r\n"
829 "Content-Type: application/x-www-form-urlencoded\r\n" 938 "Content-Type: application/x-www-form-urlencoded\r\n"
830 "User-Agent: Mozilla/4.7 [en] (Win98; I)\r\n" 939 "User-Agent: " GG_HTTP_USERAGENT "\r\n"
831 "Content-Length: %d\r\n" 940 "Content-Length: %d\r\n"
832 "Pragma: no-cache\r\n" "\r\n" "%s\r\n", strlen(ptr), ptr); 941 "Pragma: no-cache\r\n" "\r\n" "%s\r\n",
942 hdata->form, hdata->host, strlen(ptr), ptr);
833 943
834 g_free(ptr); 944 g_free(ptr);
835 945
836 if (write(source, buf, strlen(buf)) < strlen(buf)) { 946 if (write(source, buf, strlen(buf)) < strlen(buf)) {
837 g_free(buf); 947 g_free(buf);
838 g_free(srch); 948 g_free(hdata);
839 close(source); 949 close(source);
840 do_error_dialog(_("Couldn't send search request"), _("Gadu-Gadu Error")); 950 do_error_dialog(_("Couldn't send http request"), _("Gadu-Gadu Error"));
841 return; 951 return;
842 } 952 }
843 953
844 g_free(buf); 954 g_free(buf);
845 955
846 srch->inpa = gaim_input_add(source, GAIM_INPUT_READ, search_results, srch); 956 hdata->inpa = gaim_input_add(source, GAIM_INPUT_READ, http_results, hdata);
957 }
958
959 static void agg_import_buddies(struct gaim_connection *gc)
960 {
961 struct agg_http *hi = g_new0(struct agg_http, 1);
962 static char msg[AGG_BUF_LEN];
963
964 hi->gc = gc;
965 hi->type = AGG_HTTP_USERLIST_IMPORT;
966 hi->form = AGG_PUBDIR_USERLIST_IMPORT_FORM;
967 hi->host = GG_PUBDIR_HOST;
968 hi->request = g_strdup_printf("FmNum=%s&Pass=%s", gc->username, gc->password);
969
970 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, hi) < 0) {
971 g_snprintf(msg, sizeof(msg), _("Buddies List import from Server failed (%s)"),
972 GG_PUBDIR_HOST);
973 do_error_dialog(msg, _("Gadu-Gadu Error"));
974 g_free(hi->request);
975 g_free(hi);
976 return;
977 }
978 }
979
980 static void agg_export_buddies(struct gaim_connection *gc)
981 {
982 struct agg_http *he = g_new0(struct agg_http, 1);
983 static char msg[AGG_BUF_LEN];
984 gchar *ptr;
985 GSList *gr = gc->groups;
986
987 he->gc = gc;
988 he->type = AGG_HTTP_USERLIST_EXPORT;
989 he->form = AGG_PUBDIR_USERLIST_EXPORT_FORM;
990 he->host = GG_PUBDIR_HOST;
991 he->request = g_strdup_printf("FmNum=%s&Pass=%s&Contacts=", gc->username, gc->password);
992
993 while (gr) {
994 struct group *g = gr->data;
995 GSList *m = g->members;
996 while (m) {
997 struct buddy *b = m->data;
998 gchar *newdata;
999 /* GG Number */
1000 gchar *name = b->name;
1001 /* GG Pseudo */
1002 gchar *show = strlen(b->show) ? b->show : b->name;
1003
1004 ptr = he->request;
1005 newdata = g_strdup_printf("%s;%s;%s;%s;%s;%s;%s\r\n",
1006 show, show, show, show, "", g->name, name);
1007 he->request = g_strconcat(ptr, newdata, NULL);
1008 g_free(newdata);
1009 g_free(ptr);
1010
1011 m = g_slist_next(m);
1012 }
1013 gr = g_slist_next(gr);
1014 }
1015
1016 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, he) < 0) {
1017 g_snprintf(msg, sizeof(msg), _("Buddies List export to Server failed (%s)"),
1018 GG_PUBDIR_HOST);
1019 do_error_dialog(msg, _("Gadu-Gadu Error"));
1020 g_free(he->request);
1021 g_free(he);
1022 return;
1023 }
847 } 1024 }
848 1025
849 static void agg_dir_search(struct gaim_connection *gc, char *first, char *middle, 1026 static void agg_dir_search(struct gaim_connection *gc, char *first, char *middle,
850 char *last, char *maiden, char *city, char *state, char *country, char *email) 1027 char *last, char *maiden, char *city, char *state, char *country, char *email)
851 { 1028 {
852 struct agg_search *srch = g_new0(struct agg_search, 1); 1029 struct agg_http *srch = g_new0(struct agg_http, 1);
853 static char msg[AGG_BUF_LEN]; 1030 static char msg[AGG_BUF_LEN];
854 1031
855 srch->gc = gc; 1032 srch->gc = gc;
1033 srch->type = AGG_HTTP_SEARCH;
1034 srch->form = AGG_PUBDIR_SEARCH_FORM;
1035 srch->host = GG_PUBDIR_HOST;
856 1036
857 if (email && strlen(email)) { 1037 if (email && strlen(email)) {
858 srch->search_data = g_strdup_printf("Mode=1&Email=%s", email); 1038 srch->request = g_strdup_printf("Mode=1&Email=%s", email);
859 } else { 1039 } else {
860 gchar *new_first = charset_convert(first, find_local_charset(), "CP1250"); 1040 gchar *new_first = charset_convert(first, find_local_charset(), "CP1250");
861 gchar *new_last = charset_convert(last, find_local_charset(), "CP1250"); 1041 gchar *new_last = charset_convert(last, find_local_charset(), "CP1250");
862 gchar *new_city = charset_convert(city, find_local_charset(), "CP1250"); 1042 gchar *new_city = charset_convert(city, find_local_charset(), "CP1250");
863 1043
864 /* For active only add &ActiveOnly= */ 1044 /* For active only add &ActiveOnly= */
865 srch->search_data = g_strdup_printf("Mode=0&FirstName=%s&LastName=%s&Gender=%d" 1045 srch->request = g_strdup_printf("Mode=0&FirstName=%s&LastName=%s&Gender=%d"
866 "&NickName=%s&City=%s&MinBirth=%d&MaxBirth=%d", 1046 "&NickName=%s&City=%s&MinBirth=%d&MaxBirth=%d",
867 new_first, new_last, AGG_GENDER_NONE, 1047 new_first, new_last, AGG_GENDER_NONE,
868 "", new_city, 0, 0); 1048 "", new_city, 0, 0);
869 1049
870 g_free(new_first); 1050 g_free(new_first);
871 g_free(new_last); 1051 g_free(new_last);
872 g_free(new_city); 1052 g_free(new_city);
873 } 1053 }
874 1054
875 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, search_callback, srch) < 0) { 1055 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, srch) < 0) {
876 g_snprintf(msg, sizeof(msg), _("Connect to search service failed (%s)"), GG_PUBDIR_HOST); 1056 g_snprintf(msg, sizeof(msg), _("Connect to search service failed (%s)"), GG_PUBDIR_HOST);
877 do_error_dialog(msg, _("Gadu-Gadu Error")); 1057 do_error_dialog(msg, _("Gadu-Gadu Error"));
878 g_free(srch->search_data); 1058 g_free(srch->request);
879 g_free(srch); 1059 g_free(srch);
880 return; 1060 return;
881 } 1061 }
882 } 1062 }
883 1063
884 static void agg_do_action(struct gaim_connection *gc, char *action) 1064 static void agg_do_action(struct gaim_connection *gc, char *action)
885 { 1065 {
886 if (!strcmp(action, _("Directory Search"))) { 1066 if (!strcmp(action, _("Directory Search"))) {
887 show_find_info(gc); 1067 show_find_info(gc);
1068 } else if (!strcmp(action, _("Import Buddies List from Server"))) {
1069 agg_import_buddies(gc);
1070 } else if (!strcmp(action, _("Export Buddies List to Server"))) {
1071 agg_export_buddies(gc);
888 } 1072 }
889 } 1073 }
890 1074
891 static GList *agg_actions() 1075 static GList *agg_actions()
892 { 1076 {
893 GList *m = NULL; 1077 GList *m = NULL;
894 1078
895 m = g_list_append(m, _("Directory Search")); 1079 m = g_list_append(m, _("Directory Search"));
1080 m = g_list_append(m, _("Import Buddies List from Server"));
1081 m = g_list_append(m, _("Export Buddies List to Server"));
896 1082
897 return m; 1083 return m;
898 } 1084 }
899 1085
900 static void agg_get_info(struct gaim_connection *gc, char *who) 1086 static void agg_get_info(struct gaim_connection *gc, char *who)
901 { 1087 {
902 struct agg_search *srch = g_new0(struct agg_search, 1); 1088 struct agg_http *srch = g_new0(struct agg_http, 1);
903 static char msg[AGG_BUF_LEN]; 1089 static char msg[AGG_BUF_LEN];
904 1090
905 srch->gc = gc; 1091 srch->gc = gc;
1092 srch->type = AGG_HTTP_SEARCH;
1093 srch->form = AGG_PUBDIR_SEARCH_FORM;
1094 srch->host = GG_PUBDIR_HOST;
906 1095
907 /* If it's invalid uin then maybe it's nickname? */ 1096 /* If it's invalid uin then maybe it's nickname? */
908 if (invalid_uin(who)) { 1097 if (invalid_uin(who)) {
909 gchar *new_who = charset_convert(who, find_local_charset(), "CP1250"); 1098 gchar *new_who = charset_convert(who, find_local_charset(), "CP1250");
910 1099
911 srch->search_data = g_strdup_printf("Mode=0&FirstName=%s&LastName=%s&Gender=%d" 1100 srch->request = g_strdup_printf("Mode=0&FirstName=%s&LastName=%s&Gender=%d"
912 "&NickName=%s&City=%s&MinBirth=%d&MaxBirth=%d", 1101 "&NickName=%s&City=%s&MinBirth=%d&MaxBirth=%d",
913 "", "", AGG_GENDER_NONE, new_who, "", 0, 0); 1102 "", "", AGG_GENDER_NONE, new_who, "", 0, 0);
914 1103
915 g_free(new_who); 1104 g_free(new_who);
916 } else 1105 } else
917 srch->search_data = g_strdup_printf("Mode=3&UserId=%s", who); 1106 srch->request = g_strdup_printf("Mode=3&UserId=%s", who);
918 1107
919 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, search_callback, srch) < 0) { 1108 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, srch) < 0) {
920 g_snprintf(msg, sizeof(msg), _("Connect to search service failed (%s)"), GG_PUBDIR_HOST); 1109 g_snprintf(msg, sizeof(msg), _("Connect to search service failed (%s)"), GG_PUBDIR_HOST);
921 do_error_dialog(msg, _("Gadu-Gadu Error")); 1110 do_error_dialog(msg, _("Gadu-Gadu Error"));
922 g_free(srch->search_data); 1111 g_free(srch->request);
923 g_free(srch); 1112 g_free(srch);
924 return; 1113 return;
925 } 1114 }
926 } 1115 }
927 1116