comparison src/protocols/gg/gg.c @ 5563:9eb5b13fd412

[gaim-migrate @ 5965] Just a taste of what's coming. Standard "This won't compile" thing. Plugin authors, you're going to hate me, but that's okay, because I have friends too! It's really late. My brain resembles that of fish swimming in jello pudding with neon lights flying around chanting musicals. I'm not on drugs. I'm just that tired. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 30 May 2003 09:38:29 +0000
parents ad445074d239
children 7805a9a2c6ba
comparison
equal deleted inserted replaced
5562:3c8d34574601 5563:9eb5b13fd412
1 /* 1 /*
2 * gaim - Gadu-Gadu Protocol Plugin 2 * gaim - Gadu-Gadu Protocol Plugin
3 * $Id: gg.c 5818 2003-05-18 19:59:02Z chipx86 $ 3 * $Id: gg.c 5965 2003-05-30 09:38:29Z chipx86 $
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
90 struct gg_session *sess; 90 struct gg_session *sess;
91 int own_status; 91 int own_status;
92 }; 92 };
93 93
94 struct agg_http { 94 struct agg_http {
95 struct gaim_connection *gc; 95 GaimConnection *gc;
96 gchar *request; 96 gchar *request;
97 gchar *form; 97 gchar *form;
98 gchar *host; 98 gchar *host;
99 int inpa; 99 int inpa;
100 int type; 100 int type;
117 static gint args_compare(gconstpointer a, gconstpointer b) 117 static gint args_compare(gconstpointer a, gconstpointer b)
118 { 118 {
119 return g_ascii_strcasecmp((const gchar *)a,(const gchar *)b); 119 return g_ascii_strcasecmp((const gchar *)a,(const gchar *)b);
120 } 120 }
121 121
122 static gboolean allowed_uin(struct gaim_connection *gc, char *uin) 122 static gboolean allowed_uin(GaimConnection *gc, char *uin)
123 { 123 {
124 switch (gc->account->permdeny) { 124 GaimAccount *account = gaim_connection_get_account(gc);
125
126 switch (account->perm_deny) {
125 case 1: 127 case 1:
126 /* permit all, deny none */ 128 /* permit all, deny none */
127 return TRUE; 129 return TRUE;
128 break; 130 break;
129 case 2: 131 case 2:
146 return TRUE; 148 return TRUE;
147 break; 149 break;
148 } 150 }
149 } 151 }
150 152
151 static char *handle_errcode(struct gaim_connection *gc, int errcode) 153 static char *handle_errcode(GaimConnection *gc, int errcode)
152 { 154 {
153 static char msg[AGG_BUF_LEN]; 155 static char msg[AGG_BUF_LEN];
154 156
155 switch (errcode) { 157 switch (errcode) {
156 case GG_FAILURE_RESOLVING: 158 case GG_FAILURE_RESOLVING:
179 hide_login_progress(gc, msg); 181 hide_login_progress(gc, msg);
180 182
181 return msg; 183 return msg;
182 } 184 }
183 185
184 static void agg_set_away(struct gaim_connection *gc, char *state, char *msg) 186 static void agg_set_away(GaimConnection *gc, char *state, char *msg)
185 { 187 {
186 struct agg_data *gd = (struct agg_data *)gc->proto_data; 188 struct agg_data *gd = (struct agg_data *)gc->proto_data;
187 int status = gd->own_status; 189 int status = gd->own_status;
188 190
189 if (gc->away) { 191 if (gc->away) {
248 case GG_STATUS_NOT_AVAIL: 250 case GG_STATUS_NOT_AVAIL:
249 return AGG_STATUS_NOT_AVAIL; 251 return AGG_STATUS_NOT_AVAIL;
250 } 252 }
251 } 253 }
252 254
253 static GList *agg_away_states(struct gaim_connection *gc) 255 static GList *agg_away_states(GaimConnection *gc)
254 { 256 {
255 GList *m = NULL; 257 GList *m = NULL;
256 258
257 m = g_list_append(m, AGG_STATUS_AVAIL); 259 m = g_list_append(m, AGG_STATUS_AVAIL);
258 m = g_list_append(m, AGG_STATUS_BUSY); 260 m = g_list_append(m, AGG_STATUS_BUSY);
263 m = g_list_append(m, AGG_STATUS_NOT_AVAIL); 265 m = g_list_append(m, AGG_STATUS_NOT_AVAIL);
264 return m; 266 return m;
265 } 267 }
266 268
267 /* Enhance these functions, more options and such stuff */ 269 /* Enhance these functions, more options and such stuff */
268 static GList *agg_buddy_menu(struct gaim_connection *gc, const char *who) 270 static GList *agg_buddy_menu(GaimConnection *gc, const char *who)
269 { 271 {
270 GList *m = NULL; 272 GList *m = NULL;
271 struct proto_buddy_menu *pbm; 273 struct proto_buddy_menu *pbm;
272 struct buddy *b = gaim_find_buddy(gc->account, who); 274 struct buddy *b = gaim_find_buddy(gc->account, who);
273 static char buf[AGG_BUF_LEN]; 275 static char buf[AGG_BUF_LEN];
286 return m; 288 return m;
287 } 289 }
288 290
289 static void main_callback(gpointer data, gint source, GaimInputCondition cond) 291 static void main_callback(gpointer data, gint source, GaimInputCondition cond)
290 { 292 {
291 struct gaim_connection *gc = data; 293 GaimConnection *gc = data;
292 struct agg_data *gd = gc->proto_data; 294 struct agg_data *gd = gc->proto_data;
293 struct gg_event *e; 295 struct gg_event *e;
294 296
295 debug_printf("main_callback enter: begin\n"); 297 debug_printf("main_callback enter: begin\n");
296 298
401 gg_free_event(e); 403 gg_free_event(e);
402 } 404 }
403 405
404 void login_callback(gpointer data, gint source, GaimInputCondition cond) 406 void login_callback(gpointer data, gint source, GaimInputCondition cond)
405 { 407 {
406 struct gaim_connection *gc = data; 408 GaimConnection *gc = data;
407 struct agg_data *gd = gc->proto_data; 409 struct agg_data *gd = gc->proto_data;
408 struct gg_event *e; 410 struct gg_event *e;
409 411
410 debug_printf("GG login_callback...\n"); 412 debug_printf("GG login_callback...\n");
411 if (!g_slist_find(connections, gc)) { 413 if (!g_slist_find(connections, gc)) {
493 if (gc->inpa) 495 if (gc->inpa)
494 gaim_input_remove(gc->inpa); 496 gaim_input_remove(gc->inpa);
495 gc->inpa = gaim_input_add(gd->sess->fd, GAIM_INPUT_READ, main_callback, gc); 497 gc->inpa = gaim_input_add(gd->sess->fd, GAIM_INPUT_READ, main_callback, gc);
496 498
497 /* Our signon is complete */ 499 /* Our signon is complete */
498 account_online(gc); 500 gaim_connection_set_state(gc, GAIM_CONNECTED);
499 serv_finish_login(gc); 501 serv_finish_login(gc);
500 502
501 break; 503 break;
502 case GG_EVENT_CONN_FAILED: 504 case GG_EVENT_CONN_FAILED:
503 gaim_input_remove(gc->inpa); 505 gaim_input_remove(gc->inpa);
511 } 513 }
512 debug_printf("Returning from login_callback\n"); 514 debug_printf("Returning from login_callback\n");
513 gg_free_event(e); 515 gg_free_event(e);
514 } 516 }
515 517
516 static void agg_keepalive(struct gaim_connection *gc) 518 static void agg_keepalive(GaimConnection *gc)
517 { 519 {
518 struct agg_data *gd = (struct agg_data *)gc->proto_data; 520 struct agg_data *gd = (struct agg_data *)gc->proto_data;
519 if (gg_ping(gd->sess) < 0) { 521 if (gg_ping(gd->sess) < 0) {
520 hide_login_progress(gc, _("Unable to ping server")); 522 hide_login_progress(gc, _("Unable to ping server"));
521 signoff(gc); 523 signoff(gc);
522 return; 524 return;
523 } 525 }
524 } 526 }
525 527
526 static void agg_login(struct gaim_account *account) 528 static void agg_login(GaimAccount *account)
527 { 529 {
528 struct gaim_connection *gc = new_gaim_conn(account); 530 GaimConnection *gc = gaim_account_get_connection(account);
529 struct agg_data *gd = gc->proto_data = g_new0(struct agg_data, 1); 531 struct agg_data *gd = gc->proto_data = g_new0(struct agg_data, 1);
530 char buf[80]; 532 char buf[80];
531 533
534 #if 0
532 gc->checkbox = _("Send as message"); 535 gc->checkbox = _("Send as message");
536 #endif
533 537
534 gd->sess = g_new0(struct gg_session, 1); 538 gd->sess = g_new0(struct gg_session, 1);
535 539
536 if (account->proto_opt[USEROPT_NICK][0]) 540 gaim_connection_set_display_name(account, gaim_account_get_string("nick"));
537 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s",
538 account->proto_opt[USEROPT_NICK]);
539 541
540 set_login_progress(gc, 1, _("Looking up GG server")); 542 set_login_progress(gc, 1, _("Looking up GG server"));
541 543
542 if (invalid_uin(account->username)) { 544 if (invalid_uin(account->username)) {
543 hide_login_progress(gc, _("Invalid Gadu-Gadu UIN specified")); 545 hide_login_progress(gc, _("Invalid Gadu-Gadu UIN specified"));
569 signoff(gc); 571 signoff(gc);
570 return; 572 return;
571 } 573 }
572 } 574 }
573 575
574 static void agg_close(struct gaim_connection *gc) 576 static void agg_close(GaimConnection *gc)
575 { 577 {
576 struct agg_data *gd = (struct agg_data *)gc->proto_data; 578 struct agg_data *gd = (struct agg_data *)gc->proto_data;
577 if (gc->inpa) 579 if (gc->inpa)
578 gaim_input_remove(gc->inpa); 580 gaim_input_remove(gc->inpa);
579 gg_logoff(gd->sess); 581 gg_logoff(gd->sess);
580 gd->own_status = GG_STATUS_NOT_AVAIL; 582 gd->own_status = GG_STATUS_NOT_AVAIL;
581 gg_free_session(gd->sess); 583 gg_free_session(gd->sess);
582 g_free(gc->proto_data); 584 g_free(gc->proto_data);
583 } 585 }
584 586
585 static int agg_send_im(struct gaim_connection *gc, const char *who, const char *msg, int len, int flags) 587 static int agg_send_im(GaimConnection *gc, const char *who, const char *msg, int len, int flags)
586 { 588 {
587 struct agg_data *gd = (struct agg_data *)gc->proto_data; 589 struct agg_data *gd = (struct agg_data *)gc->proto_data;
588 gchar *imsg; 590 gchar *imsg;
589 591
590 if (invalid_uin(who)) { 592 if (invalid_uin(who)) {
603 g_free(imsg); 605 g_free(imsg);
604 } 606 }
605 return 1; 607 return 1;
606 } 608 }
607 609
608 static void agg_add_buddy(struct gaim_connection *gc, const char *who) 610 static void agg_add_buddy(GaimConnection *gc, const char *who)
609 { 611 {
610 struct agg_data *gd = (struct agg_data *)gc->proto_data; 612 struct agg_data *gd = (struct agg_data *)gc->proto_data;
611 if (invalid_uin(who)) 613 if (invalid_uin(who))
612 return; 614 return;
613 gg_add_notify(gd->sess, strtol(who, (char **)NULL, 10)); 615 gg_add_notify(gd->sess, strtol(who, (char **)NULL, 10));
614 } 616 }
615 617
616 static void agg_rem_buddy(struct gaim_connection *gc, char *who, char *group) 618 static void agg_rem_buddy(GaimConnection *gc, char *who, char *group)
617 { 619 {
618 struct agg_data *gd = (struct agg_data *)gc->proto_data; 620 struct agg_data *gd = (struct agg_data *)gc->proto_data;
619 if (invalid_uin(who)) 621 if (invalid_uin(who))
620 return; 622 return;
621 gg_remove_notify(gd->sess, strtol(who, (char **)NULL, 10)); 623 gg_remove_notify(gd->sess, strtol(who, (char **)NULL, 10));
622 } 624 }
623 625
624 static void agg_add_buddies(struct gaim_connection *gc, GList *whos) 626 static void agg_add_buddies(GaimConnection *gc, GList *whos)
625 { 627 {
626 struct agg_data *gd = (struct agg_data *)gc->proto_data; 628 struct agg_data *gd = (struct agg_data *)gc->proto_data;
627 uin_t *userlist = NULL; 629 uin_t *userlist = NULL;
628 int userlist_size = 0; 630 int userlist_size = 0;
629 631
641 gg_notify(gd->sess, userlist, userlist_size); 643 gg_notify(gd->sess, userlist, userlist_size);
642 g_free(userlist); 644 g_free(userlist);
643 } 645 }
644 } 646 }
645 647
646 static void search_results(struct gaim_connection *gc, gchar *webdata) 648 static void search_results(GaimConnection *gc, gchar *webdata)
647 { 649 {
648 gchar **webdata_tbl; 650 gchar **webdata_tbl;
649 gchar *buf; 651 gchar *buf;
650 char *ptr; 652 char *ptr;
651 int i, j; 653 int i, j;
748 g_show_info_text(gc, NULL, 2, buf, NULL); 750 g_show_info_text(gc, NULL, 2, buf, NULL);
749 751
750 g_free(buf); 752 g_free(buf);
751 } 753 }
752 754
753 static void import_buddies_server_results(struct gaim_connection *gc, gchar *webdata) 755 static void import_buddies_server_results(GaimConnection *gc, gchar *webdata)
754 { 756 {
755 gchar *ptr; 757 gchar *ptr;
756 gchar **users_tbl; 758 gchar **users_tbl;
757 int i; 759 int i;
758 if (strstr(webdata, "no_data:")) { 760 if (strstr(webdata, "no_data:")) {
820 g_strfreev(data_tbl); 822 g_strfreev(data_tbl);
821 } 823 }
822 g_strfreev(users_tbl); 824 g_strfreev(users_tbl);
823 } 825 }
824 826
825 static void export_buddies_server_results(struct gaim_connection *gc, gchar *webdata) 827 static void export_buddies_server_results(GaimConnection *gc, gchar *webdata)
826 { 828 {
827 if (strstr(webdata, "put_success:")) { 829 if (strstr(webdata, "put_success:")) {
828 gaim_notify_info(gc, NULL, 830 gaim_notify_info(gc, NULL,
829 _("Buddy List successfully transferred to " 831 _("Buddy List successfully transferred to "
830 "Gadu-Gadu server"), NULL); 832 "Gadu-Gadu server"), NULL);
835 gaim_notify_error(gc, NULL, 837 gaim_notify_error(gc, NULL,
836 _("Couldn't transfer Buddy List to Gadu-Gadu server"), 838 _("Couldn't transfer Buddy List to Gadu-Gadu server"),
837 NULL); 839 NULL);
838 } 840 }
839 841
840 static void delete_buddies_server_results(struct gaim_connection *gc, gchar *webdata) 842 static void delete_buddies_server_results(GaimConnection *gc, gchar *webdata)
841 { 843 {
842 if (strstr(webdata, "put_success:")) { 844 if (strstr(webdata, "put_success:")) {
843 gaim_notify_info(gc, NULL, 845 gaim_notify_info(gc, NULL,
844 _("Buddy List successfully deleted from " 846 _("Buddy List successfully deleted from "
845 "Gadu-Gadu server"), NULL); 847 "Gadu-Gadu server"), NULL);
850 gaim_notify_error(gc, NULL, 852 gaim_notify_error(gc, NULL,
851 _("Couldn't delete Buddy List from Gadu-Gadu server"), 853 _("Couldn't delete Buddy List from Gadu-Gadu server"),
852 NULL); 854 NULL);
853 } 855 }
854 856
855 static void password_change_server_results(struct gaim_connection *gc, gchar *webdata) 857 static void password_change_server_results(GaimConnection *gc, gchar *webdata)
856 { 858 {
857 if (strstr(webdata, "reg_success:")) { 859 if (strstr(webdata, "reg_success:")) {
858 gaim_notify_info(gc, NULL, 860 gaim_notify_info(gc, NULL,
859 _("Password changed successfully"), NULL); 861 _("Password changed successfully"), NULL);
860 return; 862 return;
866 } 868 }
867 869
868 static void http_results(gpointer data, gint source, GaimInputCondition cond) 870 static void http_results(gpointer data, gint source, GaimInputCondition cond)
869 { 871 {
870 struct agg_http *hdata = data; 872 struct agg_http *hdata = data;
871 struct gaim_connection *gc = hdata->gc; 873 GaimConnection *gc = hdata->gc;
872 char *webdata; 874 char *webdata;
873 int len; 875 int len;
874 char read_data; 876 char read_data;
875 877
876 debug_printf("http_results: begin\n"); 878 debug_printf("http_results: begin\n");
935 } 937 }
936 938
937 static void http_req_callback(gpointer data, gint source, GaimInputCondition cond) 939 static void http_req_callback(gpointer data, gint source, GaimInputCondition cond)
938 { 940 {
939 struct agg_http *hdata = data; 941 struct agg_http *hdata = data;
940 struct gaim_connection *gc = hdata->gc; 942 GaimConnection *gc = hdata->gc;
941 gchar *request = hdata->request; 943 gchar *request = hdata->request;
942 gchar *buf; 944 gchar *buf;
943 945
944 debug_printf("http_req_callback: begin\n"); 946 debug_printf("http_req_callback: begin\n");
945 947
984 g_free(buf); 986 g_free(buf);
985 987
986 hdata->inpa = gaim_input_add(source, GAIM_INPUT_READ, http_results, hdata); 988 hdata->inpa = gaim_input_add(source, GAIM_INPUT_READ, http_results, hdata);
987 } 989 }
988 990
989 static void import_buddies_server(struct gaim_connection *gc) 991 static void import_buddies_server(GaimConnection *gc)
990 { 992 {
991 struct agg_http *hi = g_new0(struct agg_http, 1); 993 struct agg_http *hi = g_new0(struct agg_http, 1);
992 gchar *u = gg_urlencode(gc->username); 994 gchar *u = gg_urlencode(gc->username);
993 gchar *p = gg_urlencode(gc->password); 995 gchar *p = gg_urlencode(gc->password);
994 996
1010 g_free(hi); 1012 g_free(hi);
1011 return; 1013 return;
1012 } 1014 }
1013 } 1015 }
1014 1016
1015 static void export_buddies_server(struct gaim_connection *gc) 1017 static void export_buddies_server(GaimConnection *gc)
1016 { 1018 {
1017 struct agg_http *he = g_new0(struct agg_http, 1); 1019 struct agg_http *he = g_new0(struct agg_http, 1);
1018 gchar *ptr; 1020 gchar *ptr;
1019 gchar *u = gg_urlencode(gc->username); 1021 gchar *u = gg_urlencode(gc->username);
1020 gchar *p = gg_urlencode(gc->password); 1022 gchar *p = gg_urlencode(gc->password);
1080 g_free(he); 1082 g_free(he);
1081 return; 1083 return;
1082 } 1084 }
1083 } 1085 }
1084 1086
1085 static void delete_buddies_server(struct gaim_connection *gc) 1087 static void delete_buddies_server(GaimConnection *gc)
1086 { 1088 {
1087 struct agg_http *he = g_new0(struct agg_http, 1); 1089 struct agg_http *he = g_new0(struct agg_http, 1);
1088 gchar *u = gg_urlencode(gc->username); 1090 gchar *u = gg_urlencode(gc->username);
1089 gchar *p = gg_urlencode(gc->password); 1091 gchar *p = gg_urlencode(gc->password);
1090 1092
1103 g_free(he); 1105 g_free(he);
1104 return; 1106 return;
1105 } 1107 }
1106 } 1108 }
1107 1109
1108 static void agg_dir_search(struct gaim_connection *gc, const char *first, const char *middle, 1110 static void agg_dir_search(GaimConnection *gc, const char *first, const char *middle,
1109 const char *last, const char *maiden, const char *city, const char *state, 1111 const char *last, const char *maiden, const char *city, const char *state,
1110 const char *country, const char *email) 1112 const char *country, const char *email)
1111 { 1113 {
1112 struct agg_http *srch = g_new0(struct agg_http, 1); 1114 struct agg_http *srch = g_new0(struct agg_http, 1);
1113 srch->gc = gc; 1115 srch->gc = gc;
1153 g_free(srch); 1155 g_free(srch);
1154 return; 1156 return;
1155 } 1157 }
1156 } 1158 }
1157 1159
1158 static void agg_change_passwd(struct gaim_connection *gc, const char *old, const char *new) 1160 static void agg_change_passwd(GaimConnection *gc, const char *old, const char *new)
1159 { 1161 {
1160 struct agg_http *hpass = g_new0(struct agg_http, 1); 1162 struct agg_http *hpass = g_new0(struct agg_http, 1);
1161 gchar *u = gg_urlencode(gc->username); 1163 gchar *u = gg_urlencode(gc->username);
1162 gchar *p = gg_urlencode(gc->password); 1164 gchar *p = gg_urlencode(gc->password);
1163 gchar *enew = gg_urlencode(new); 1165 gchar *enew = gg_urlencode(new);
1188 g_free(hpass); 1190 g_free(hpass);
1189 return; 1191 return;
1190 } 1192 }
1191 } 1193 }
1192 1194
1193 static GList *agg_actions(struct gaim_connection *gc) 1195 static GList *agg_actions(GaimConnection *gc)
1194 { 1196 {
1195 GList *m = NULL; 1197 GList *m = NULL;
1196 struct proto_actions_menu *pam; 1198 struct proto_actions_menu *pam;
1197 1199
1198 pam = g_new0(struct proto_actions_menu, 1); 1200 pam = g_new0(struct proto_actions_menu, 1);
1230 m = g_list_append(m, pam); 1232 m = g_list_append(m, pam);
1231 1233
1232 return m; 1234 return m;
1233 } 1235 }
1234 1236
1235 static void agg_get_info(struct gaim_connection *gc, const char *who) 1237 static void agg_get_info(GaimConnection *gc, const char *who)
1236 { 1238 {
1237 struct agg_http *srch = g_new0(struct agg_http, 1); 1239 struct agg_http *srch = g_new0(struct agg_http, 1);
1238 srch->gc = gc; 1240 srch->gc = gc;
1239 srch->type = AGG_HTTP_SEARCH; 1241 srch->type = AGG_HTTP_SEARCH;
1240 srch->form = AGG_PUBDIR_SEARCH_FORM; 1242 srch->form = AGG_PUBDIR_SEARCH_FORM;
1265 g_free(srch); 1267 g_free(srch);
1266 return; 1268 return;
1267 } 1269 }
1268 } 1270 }
1269 1271
1270 static const char *agg_list_icon(struct gaim_account *a, struct buddy *b) 1272 static const char *agg_list_icon(GaimAccount *a, struct buddy *b)
1271 { 1273 {
1272 return "gadu-gadu"; 1274 return "gadu-gadu";
1273 } 1275 }
1274 1276
1275 static void agg_list_emblems(struct buddy *b, char **se, char **sw, char **nw, char **ne) 1277 static void agg_list_emblems(struct buddy *b, char **se, char **sw, char **nw, char **ne)
1289 *se = "invisiible"; 1291 *se = "invisiible";
1290 } 1292 }
1291 } 1293 }
1292 1294
1293 1295
1294 static void agg_set_permit_deny_dummy(struct gaim_connection *gc) 1296 static void agg_set_permit_deny_dummy(GaimConnection *gc)
1295 { 1297 {
1296 /* It's implemented on client side because GG server doesn't support this */ 1298 /* It's implemented on client side because GG server doesn't support this */
1297 } 1299 }
1298 1300
1299 static void agg_permit_deny_dummy(struct gaim_connection *gc, const char *who) 1301 static void agg_permit_deny_dummy(GaimConnection *gc, const char *who)
1300 { 1302 {
1301 /* It's implemented on client side because GG server doesn't support this */ 1303 /* It's implemented on client side because GG server doesn't support this */
1302 } 1304 }
1303 1305
1304 static GaimPlugin *my_protocol = NULL; 1306 static GaimPlugin *my_protocol = NULL;