comparison src/protocols/gg/gg.c @ 2806:1ffac7cf4e94

[gaim-migrate @ 2819] thanks Arkadiusz Miskiewicz: Here is patch that adds ,,delete userlist from server'', updates protocol.txt and makes small cleanup with freeing webdata + with function names (all agg_ names are reserved for struct prpl functions ;) committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 27 Nov 2001 22:54:32 +0000
parents 9123abd0db92
children d8e67ff8022f
comparison
equal deleted inserted replaced
2805:9b3c7d2a6e9a 2806:1ffac7cf4e94
1 /* 1 /*
2 * gaim - Gadu-Gadu Protocol Plugin 2 * gaim - Gadu-Gadu Protocol Plugin
3 * $Id: gg.c 2805 2001-11-26 21:22:56Z warmenhoven $ 3 * $Id: gg.c 2819 2001-11-27 22:54:32Z 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
77 77
78 #define AGG_HTTP_NONE 0 78 #define AGG_HTTP_NONE 0
79 #define AGG_HTTP_SEARCH 1 79 #define AGG_HTTP_SEARCH 1
80 #define AGG_HTTP_USERLIST_IMPORT 2 80 #define AGG_HTTP_USERLIST_IMPORT 2
81 #define AGG_HTTP_USERLIST_EXPORT 3 81 #define AGG_HTTP_USERLIST_EXPORT 3
82 #define AGG_HTTP_USERLIST_DELETE 4
82 83
83 #define UC_NORMAL 2 84 #define UC_NORMAL 2
84 85
85 struct agg_data { 86 struct agg_data {
86 struct gg_session *sess; 87 struct gg_session *sess;
576 gd->sess->uin = (uin_t) strtol(user->username, (char **)NULL, 10); 577 gd->sess->uin = (uin_t) strtol(user->username, (char **)NULL, 10);
577 gd->sess->password = g_strdup(user->password); 578 gd->sess->password = g_strdup(user->password);
578 gd->sess->state = GG_STATE_CONNECTING_HTTP; 579 gd->sess->state = GG_STATE_CONNECTING_HTTP;
579 gd->sess->check = GG_CHECK_WRITE; 580 gd->sess->check = GG_CHECK_WRITE;
580 gd->sess->async = 1; 581 gd->sess->async = 1;
581 gd->sess->recv_left = 0;
582 gd->sess->fd = proxy_connect(GG_APPMSG_HOST, GG_APPMSG_PORT, login_callback, gc); 582 gd->sess->fd = proxy_connect(GG_APPMSG_HOST, GG_APPMSG_PORT, login_callback, gc);
583 583
584 if (gd->sess->fd < 0) { 584 if (gd->sess->fd < 0) {
585 g_snprintf(buf, sizeof(buf), _("Connect to %s failed"), GG_APPMSG_HOST); 585 g_snprintf(buf, sizeof(buf), _("Connect to %s failed"), GG_APPMSG_HOST);
586 hide_login_progress(gc, buf); 586 hide_login_progress(gc, buf);
665 char *ptr; 665 char *ptr;
666 int i, j; 666 int i, j;
667 667
668 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) {
669 debug_printf("search_callback: pubdir result [%s]\n", webdata); 669 debug_printf("search_callback: pubdir result [%s]\n", webdata);
670 g_free(webdata);
671 do_error_dialog(_("Couldn't get search results"), _("Gadu-Gadu Error")); 670 do_error_dialog(_("Couldn't get search results"), _("Gadu-Gadu Error"));
672 return; 671 return;
673 } 672 }
674 ptr++; 673 ptr++;
675 674
676 buf = g_strconcat("<B>", _("Gadu-Gadu Search Engine"), "</B><BR>\n", NULL); 675 buf = g_strconcat("<B>", _("Gadu-Gadu Search Engine"), "</B><BR>\n", NULL);
677 676
678 webdata_tbl = g_strsplit(ptr, "\n", AGG_PUBDIR_MAX_ENTRIES); 677 webdata_tbl = g_strsplit(ptr, "\n", AGG_PUBDIR_MAX_ENTRIES);
679
680 g_free(webdata);
681 678
682 j = 0; 679 j = 0;
683 680
684 /* Parse array */ 681 /* Parse array */
685 for (i = 0; webdata_tbl[i] != NULL; i++) { 682 for (i = 0; webdata_tbl[i] != NULL; i++) {
766 g_show_info_text(gc, NULL, 2, buf, NULL); 763 g_show_info_text(gc, NULL, 2, buf, NULL);
767 764
768 g_free(buf); 765 g_free(buf);
769 } 766 }
770 767
771 static void agg_import_buddies_results(struct gaim_connection *gc, gchar *webdata) 768 static void import_buddies_server_results(struct gaim_connection *gc, gchar *webdata)
772 { 769 {
773 gchar *ptr; 770 gchar *ptr;
774 gchar **users_tbl; 771 gchar **users_tbl;
775 int i; 772 int i;
776 if (strstr(webdata, "no_data:")) { 773 if (strstr(webdata, "no_data:")) {
777 g_free(webdata);
778 do_error_dialog(_("There is no Buddy List stored on server. Sorry!"), 774 do_error_dialog(_("There is no Buddy List stored on server. Sorry!"),
779 _("Gadu-Gadu Error")); 775 _("Gadu-Gadu Error"));
780 return; 776 return;
781 } 777 }
782 778
783 if ((ptr = strstr(webdata, "get_results:")) == NULL || (ptr = strchr(ptr, ':')) == NULL) { 779 if ((ptr = strstr(webdata, "get_results:")) == NULL || (ptr = strchr(ptr, ':')) == NULL) {
784 debug_printf("agg_import_buddies_list: import buddies result [%s]\n", webdata); 780 debug_printf("import_buddies_server_results: import buddies result [%s]\n", webdata);
785 g_free(webdata);
786 do_error_dialog(_("Couldn't Import Buddies List from Server"), _("Gadu-Gadu Error")); 781 do_error_dialog(_("Couldn't Import Buddies List from Server"), _("Gadu-Gadu Error"));
787 return; 782 return;
788 } 783 }
789 ptr++; 784 ptr++;
790 785
791 users_tbl = g_strsplit(ptr, "\n", AGG_PUBDIR_MAX_ENTRIES); 786 users_tbl = g_strsplit(ptr, "\n", AGG_PUBDIR_MAX_ENTRIES);
792 g_free(webdata);
793 787
794 /* Parse array of Buddies List */ 788 /* Parse array of Buddies List */
795 for (i = 0; users_tbl[i] != NULL; i++) { 789 for (i = 0; users_tbl[i] != NULL; i++) {
796 gchar **data_tbl; 790 gchar **data_tbl;
797 gchar *name, *show; 791 gchar *name, *show;
804 798
805 if (invalid_uin(name)) { 799 if (invalid_uin(name)) {
806 continue; 800 continue;
807 } 801 }
808 802
809 debug_printf("uin: %s\n", name); 803 debug_printf("import_buddies_server_results: uin: %s\n", name);
810 if (!find_buddy(gc, name)) { 804 if (!find_buddy(gc, name)) {
811 /* Default group if none specified on server */ 805 /* Default group if none specified on server */
812 gchar *group = g_strdup("Gadu-Gadu"); 806 gchar *group = g_strdup("Gadu-Gadu");
813 if (strlen(data_tbl[5])) { 807 if (strlen(data_tbl[5])) {
814 gchar **group_tbl = g_strsplit(data_tbl[5], ",", 2); 808 gchar **group_tbl = g_strsplit(data_tbl[5], ",", 2);
826 g_strfreev(data_tbl); 820 g_strfreev(data_tbl);
827 } 821 }
828 g_strfreev(users_tbl); 822 g_strfreev(users_tbl);
829 } 823 }
830 824
831 static void agg_export_buddies_results(struct gaim_connection *gc, gchar *webdata) 825 static void export_buddies_server_results(struct gaim_connection *gc, gchar *webdata)
832 { 826 {
833 if (strstr(webdata, "put_success:")) { 827 if (strstr(webdata, "put_success:")) {
834 g_free(webdata);
835 do_error_dialog(_("Buddies List sucessfully transfered into Server"), 828 do_error_dialog(_("Buddies List sucessfully transfered into Server"),
836 _("Gadu-Gadu Information")); 829 _("Gadu-Gadu Information"));
837 return; 830 return;
838 } 831 }
839 832
840 debug_printf("agg_export_buddies_results: webdata [%s]\n", webdata); 833 debug_printf("export_buddies_server_results: webdata [%s]\n", webdata);
841 g_free(webdata);
842 do_error_dialog(_("Couldn't transfer Buddies List into Server"), _("Gadu-Gadu Error")); 834 do_error_dialog(_("Couldn't transfer Buddies List into Server"), _("Gadu-Gadu Error"));
835 }
836
837 static void delete_buddies_server_results(struct gaim_connection *gc, gchar *webdata)
838 {
839 if (strstr(webdata, "put_success:")) {
840 do_error_dialog(_("Buddies List sucessfully deleted from Server"),
841 _("Gadu-Gadu Information"));
842 return;
843 }
844
845 debug_printf("delete_buddies_server_results: webdata [%s]\n", webdata);
846 do_error_dialog(_("Couldn't delete Buddies List from Server"), _("Gadu-Gadu Error"));
843 } 847 }
844 848
845 static void http_results(gpointer data, gint source, GaimInputCondition cond) 849 static void http_results(gpointer data, gint source, GaimInputCondition cond)
846 { 850 {
847 struct agg_http *hdata = data; 851 struct agg_http *hdata = data;
888 switch (hdata->type) { 892 switch (hdata->type) {
889 case AGG_HTTP_SEARCH: 893 case AGG_HTTP_SEARCH:
890 search_results(gc, webdata); 894 search_results(gc, webdata);
891 break; 895 break;
892 case AGG_HTTP_USERLIST_IMPORT: 896 case AGG_HTTP_USERLIST_IMPORT:
893 agg_import_buddies_results(gc, webdata); 897 import_buddies_server_results(gc, webdata);
894 break; 898 break;
895 case AGG_HTTP_USERLIST_EXPORT: 899 case AGG_HTTP_USERLIST_EXPORT:
896 agg_export_buddies_results(gc, webdata); 900 export_buddies_server_results(gc, webdata);
901 break;
902 case AGG_HTTP_USERLIST_DELETE:
903 delete_buddies_server_results(gc, webdata);
897 break; 904 break;
898 case AGG_HTTP_NONE: 905 case AGG_HTTP_NONE:
899 default: 906 default:
900 debug_printf("http_results: unsupported type %d\n", hdata->type); 907 debug_printf("http_results: unsupported type %d\n", hdata->type);
901 break; 908 break;
902 } 909 }
903 910
911 g_free(webdata);
904 g_free(hdata); 912 g_free(hdata);
905 } 913 }
906 914
907 static void http_req_callback(gpointer data, gint source, GaimInputCondition cond) 915 static void http_req_callback(gpointer data, gint source, GaimInputCondition cond)
908 { 916 {
954 g_free(buf); 962 g_free(buf);
955 963
956 hdata->inpa = gaim_input_add(source, GAIM_INPUT_READ, http_results, hdata); 964 hdata->inpa = gaim_input_add(source, GAIM_INPUT_READ, http_results, hdata);
957 } 965 }
958 966
959 static void agg_import_buddies(struct gaim_connection *gc) 967 static void import_buddies_server(struct gaim_connection *gc)
960 { 968 {
961 struct agg_http *hi = g_new0(struct agg_http, 1); 969 struct agg_http *hi = g_new0(struct agg_http, 1);
962 static char msg[AGG_BUF_LEN]; 970 static char msg[AGG_BUF_LEN];
963 971
964 hi->gc = gc; 972 hi->gc = gc;
975 g_free(hi); 983 g_free(hi);
976 return; 984 return;
977 } 985 }
978 } 986 }
979 987
980 static void agg_export_buddies(struct gaim_connection *gc) 988 static void export_buddies_server(struct gaim_connection *gc)
981 { 989 {
982 struct agg_http *he = g_new0(struct agg_http, 1); 990 struct agg_http *he = g_new0(struct agg_http, 1);
983 static char msg[AGG_BUF_LEN]; 991 static char msg[AGG_BUF_LEN];
984 gchar *ptr; 992 gchar *ptr;
985 GSList *gr = gc->groups; 993 GSList *gr = gc->groups;
1021 g_free(he); 1029 g_free(he);
1022 return; 1030 return;
1023 } 1031 }
1024 } 1032 }
1025 1033
1034 static void delete_buddies_server(struct gaim_connection *gc)
1035 {
1036 struct agg_http *he = g_new0(struct agg_http, 1);
1037 static char msg[AGG_BUF_LEN];
1038
1039 he->gc = gc;
1040 he->type = AGG_HTTP_USERLIST_DELETE;
1041 he->form = AGG_PUBDIR_USERLIST_EXPORT_FORM;
1042 he->host = GG_PUBDIR_HOST;
1043 he->request = g_strdup_printf("FmNum=%s&Pass=%s&Delete=1", gc->username, gc->password);
1044
1045 if (proxy_connect(GG_PUBDIR_HOST, GG_PUBDIR_PORT, http_req_callback, he) < 0) {
1046 g_snprintf(msg, sizeof(msg), _("Deletion of Buddies List from Server failed (%s)"),
1047 GG_PUBDIR_HOST);
1048 do_error_dialog(msg, _("Gadu-Gadu Error"));
1049 g_free(he->request);
1050 g_free(he);
1051 return;
1052 }
1053 }
1054
1026 static void agg_dir_search(struct gaim_connection *gc, char *first, char *middle, 1055 static void agg_dir_search(struct gaim_connection *gc, char *first, char *middle,
1027 char *last, char *maiden, char *city, char *state, char *country, char *email) 1056 char *last, char *maiden, char *city, char *state, char *country, char *email)
1028 { 1057 {
1029 struct agg_http *srch = g_new0(struct agg_http, 1); 1058 struct agg_http *srch = g_new0(struct agg_http, 1);
1030 static char msg[AGG_BUF_LEN]; 1059 static char msg[AGG_BUF_LEN];
1064 static void agg_do_action(struct gaim_connection *gc, char *action) 1093 static void agg_do_action(struct gaim_connection *gc, char *action)
1065 { 1094 {
1066 if (!strcmp(action, _("Directory Search"))) { 1095 if (!strcmp(action, _("Directory Search"))) {
1067 show_find_info(gc); 1096 show_find_info(gc);
1068 } else if (!strcmp(action, _("Import Buddies List from Server"))) { 1097 } else if (!strcmp(action, _("Import Buddies List from Server"))) {
1069 agg_import_buddies(gc); 1098 import_buddies_server(gc);
1070 } else if (!strcmp(action, _("Export Buddies List to Server"))) { 1099 } else if (!strcmp(action, _("Export Buddies List to Server"))) {
1071 agg_export_buddies(gc); 1100 export_buddies_server(gc);
1101 } else if (!strcmp(action, _("Delete Buddies List from Server"))) {
1102 delete_buddies_server(gc);
1072 } 1103 }
1073 } 1104 }
1074 1105
1075 static GList *agg_actions() 1106 static GList *agg_actions()
1076 { 1107 {
1077 GList *m = NULL; 1108 GList *m = NULL;
1078 1109
1079 m = g_list_append(m, _("Directory Search")); 1110 m = g_list_append(m, _("Directory Search"));
1080 m = g_list_append(m, _("Import Buddies List from Server")); 1111 m = g_list_append(m, _("Import Buddies List from Server"));
1081 m = g_list_append(m, _("Export Buddies List to Server")); 1112 m = g_list_append(m, _("Export Buddies List to Server"));
1113 m = g_list_append(m, _("Delete Buddies List from Server"));
1082 1114
1083 return m; 1115 return m;
1084 } 1116 }
1085 1117
1086 static void agg_get_info(struct gaim_connection *gc, char *who) 1118 static void agg_get_info(struct gaim_connection *gc, char *who)