Changes in protocols/purple/purple.c [2dd23da:5ebff60]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/purple/purple.c
r2dd23da r5ebff60 23 23 24 24 #include "bitlbee.h" 25 #include "bpurple.h"26 25 #include "help.h" 27 26 … … 40 39 static char *set_eval_display_name(set_t *set, char *value); 41 40 42 void purple_request_input_callback(guint id, struct im_connection *ic,43 const char *message, const char *who);44 45 /* purple_request_input specific stuff */46 typedef void (*ri_callback_t)(gpointer, const gchar *);47 48 struct request_input_data {49 ri_callback_t data_callback;50 void *user_data;51 struct im_connection *ic;52 char *buddy;53 guint id;54 };55 56 41 struct im_connection *purple_ic_by_pa(PurpleAccount *pa) 57 42 { 58 43 GSList *i; 59 struct purple_data *pd;60 44 61 45 for (i = purple_connections; i; i = i->next) { 62 pd = ((struct im_connection *) i->data)->proto_data; 63 if (pd->account == pa) { 46 if (((struct im_connection *) i->data)->proto_data == pa) { 64 47 return i->data; 65 48 } … … 307 290 { 308 291 struct im_connection *ic = imcb_new(acc); 309 struct purple_data *pd;292 PurpleAccount *pa; 310 293 311 294 if ((local_bee != NULL && local_bee != acc->bee) || … … 323 306 purple_connections = g_slist_prepend(purple_connections, ic); 324 307 325 ic->proto_data = pd = g_new0(struct purple_data, 1); 326 pd->account = purple_account_new(acc->user, (char *) acc->prpl->data); 327 pd->input_requests = g_hash_table_new_full(g_direct_hash, g_direct_equal, 328 NULL, g_free); 329 pd->next_request_id = 0; 330 purple_account_set_password(pd->account, acc->pass); 331 purple_sync_settings(acc, pd->account); 332 333 purple_account_set_enabled(pd->account, "BitlBee", TRUE); 308 ic->proto_data = pa = purple_account_new(acc->user, (char *) acc->prpl->data); 309 purple_account_set_password(pa, acc->pass); 310 purple_sync_settings(acc, pa); 311 312 purple_account_set_enabled(pa, "BitlBee", TRUE); 334 313 } 335 314 336 315 static void purple_logout(struct im_connection *ic) 337 316 { 338 struct purple_data *pd = ic->proto_data; 339 340 if (!pd) { 341 return; 342 } 343 344 purple_account_set_enabled(pd->account, "BitlBee", FALSE); 317 PurpleAccount *pa = ic->proto_data; 318 319 purple_account_set_enabled(pa, "BitlBee", FALSE); 345 320 purple_connections = g_slist_remove(purple_connections, ic); 346 purple_accounts_remove(pd->account); 347 g_hash_table_destroy(pd->input_requests); 348 g_free(pd); 321 purple_accounts_remove(pa); 349 322 } 350 323 … … 352 325 { 353 326 PurpleConversation *conv; 354 struct purple_data *pd = ic->proto_data;355 356 if (!strncmp(who, PURPLE_REQUEST_HANDLE, sizeof(PURPLE_REQUEST_HANDLE) - 1)) {357 guint request_id = atoi(who + sizeof(PURPLE_REQUEST_HANDLE));358 purple_request_input_callback(request_id, ic, message, who);359 return 1;360 }361 327 362 328 if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, 363 who, pd->account)) == NULL) {329 who, ic->proto_data)) == NULL) { 364 330 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, 365 pd->account, who);331 ic->proto_data, who); 366 332 } 367 333 … … 373 339 static GList *purple_away_states(struct im_connection *ic) 374 340 { 375 struct purple_data *pd= ic->proto_data;341 PurpleAccount *pa = ic->proto_data; 376 342 GList *st, *ret = NULL; 377 343 378 for (st = purple_account_get_status_types(p d->account); st; st = st->next) {344 for (st = purple_account_get_status_types(pa); st; st = st->next) { 379 345 PurpleStatusPrimitive prim = purple_status_type_get_primitive(st->data); 380 346 if (prim != PURPLE_STATUS_AVAILABLE && prim != PURPLE_STATUS_OFFLINE) { … … 388 354 static void purple_set_away(struct im_connection *ic, char *state_txt, char *message) 389 355 { 390 struct purple_data *pd= ic->proto_data;391 GList *status_types = purple_account_get_status_types(p d->account), *st;356 PurpleAccount *pa = ic->proto_data; 357 GList *status_types = purple_account_get_status_types(pa), *st; 392 358 PurpleStatusType *pst = NULL; 393 359 GList *args = NULL; … … 412 378 } 413 379 414 purple_account_set_status_list(pd->account, 415 st ? purple_status_type_get_id(pst) : "away", 380 purple_account_set_status_list(pa, st ? purple_status_type_get_id(pst) : "away", 416 381 TRUE, args); 417 382 … … 482 447 PurpleBuddy *pb; 483 448 PurpleGroup *pg = NULL; 484 struct purple_data *pd = ic->proto_data;485 449 486 450 if (group && !(pg = purple_find_group(group))) { … … 489 453 } 490 454 491 pb = purple_buddy_new( pd->account, who, NULL);455 pb = purple_buddy_new((PurpleAccount *) ic->proto_data, who, NULL); 492 456 purple_blist_add_buddy(pb, NULL, pg, NULL); 493 purple_account_add_buddy( pd->account, pb);494 495 purple_gg_buddylist_export( pd->account->gc);457 purple_account_add_buddy((PurpleAccount *) ic->proto_data, pb); 458 459 purple_gg_buddylist_export(((PurpleAccount *) ic->proto_data)->gc); 496 460 } 497 461 … … 499 463 { 500 464 PurpleBuddy *pb; 501 struct purple_data *pd = ic->proto_data; 502 503 pb = purple_find_buddy(pd->account, who); 465 466 pb = purple_find_buddy((PurpleAccount *) ic->proto_data, who); 504 467 if (pb != NULL) { 505 468 PurpleGroup *group; 506 469 507 470 group = purple_buddy_get_group(pb); 508 purple_account_remove_buddy( pd->account, pb, group);471 purple_account_remove_buddy((PurpleAccount *) ic->proto_data, pb, group); 509 472 510 473 purple_blist_remove_buddy(pb); 511 474 } 512 475 513 purple_gg_buddylist_export( pd->account->gc);476 purple_gg_buddylist_export(((PurpleAccount *) ic->proto_data)->gc); 514 477 } 515 478 516 479 static void purple_add_permit(struct im_connection *ic, char *who) 517 480 { 518 struct purple_data *pd= ic->proto_data;519 520 purple_privacy_permit_add(p d->account, who, FALSE);481 PurpleAccount *pa = ic->proto_data; 482 483 purple_privacy_permit_add(pa, who, FALSE); 521 484 } 522 485 523 486 static void purple_add_deny(struct im_connection *ic, char *who) 524 487 { 525 struct purple_data *pd= ic->proto_data;526 527 purple_privacy_deny_add(p d->account, who, FALSE);488 PurpleAccount *pa = ic->proto_data; 489 490 purple_privacy_deny_add(pa, who, FALSE); 528 491 } 529 492 530 493 static void purple_rem_permit(struct im_connection *ic, char *who) 531 494 { 532 struct purple_data *pd= ic->proto_data;533 534 purple_privacy_permit_remove(p d->account, who, FALSE);495 PurpleAccount *pa = ic->proto_data; 496 497 purple_privacy_permit_remove(pa, who, FALSE); 535 498 } 536 499 537 500 static void purple_rem_deny(struct im_connection *ic, char *who) 538 501 { 539 struct purple_data *pd= ic->proto_data;540 541 purple_privacy_deny_remove(p d->account, who, FALSE);502 PurpleAccount *pa = ic->proto_data; 503 504 purple_privacy_deny_remove(pa, who, FALSE); 542 505 } 543 506 544 507 static void purple_get_info(struct im_connection *ic, char *who) 545 508 { 546 struct purple_data *pd = ic->proto_data; 547 548 serv_get_info(purple_account_get_connection(pd->account), who); 509 serv_get_info(purple_account_get_connection(ic->proto_data), who); 549 510 } 550 511 … … 556 517 { 557 518 PurpleTypingState state = PURPLE_NOT_TYPING; 558 struct purple_data *pd= ic->proto_data;519 PurpleAccount *pa = ic->proto_data; 559 520 560 521 if (flags & OPT_TYPING) { … … 564 525 } 565 526 566 serv_send_typing(purple_account_get_connection(p d->account), who, state);527 serv_send_typing(purple_account_get_connection(pa), who, state); 567 528 568 529 return 1; … … 598 559 /* There went my nice afternoon. :-( */ 599 560 600 struct purple_data *pd= ic->proto_data;601 PurplePlugin *prpl = purple_plugins_find_with_id(p d->account->protocol_id);561 PurpleAccount *pa = ic->proto_data; 562 PurplePlugin *prpl = purple_plugins_find_with_id(pa->protocol_id); 602 563 PurplePluginProtocolInfo *pi = prpl->info->extra_info; 603 PurpleBuddy *pb = purple_find_buddy( pd->account, who);564 PurpleBuddy *pb = purple_find_buddy((PurpleAccount *) ic->proto_data, who); 604 565 PurpleMenuAction *mi; 605 566 GList *menu; … … 636 597 PurpleConversation *pc = gc->data; 637 598 PurpleConvChat *pcc = PURPLE_CONV_CHAT(pc); 638 struct purple_data *pd = gc->ic->proto_data; 639 640 serv_chat_invite(purple_account_get_connection(pd->account), 599 600 serv_chat_invite(purple_account_get_connection(gc->ic->proto_data), 641 601 purple_conv_chat_get_id(pcc), 642 602 message && *message ? message : "Please join my chat", … … 663 623 set_t **sets) 664 624 { 665 struct purple_data *pd= ic->proto_data;666 PurplePlugin *prpl = purple_plugins_find_with_id(p d->account->protocol_id);625 PurpleAccount *pa = ic->proto_data; 626 PurplePlugin *prpl = purple_plugins_find_with_id(pa->protocol_id); 667 627 PurplePluginProtocolInfo *pi = prpl->info->extra_info; 668 628 GHashTable *chat_hash; … … 671 631 672 632 if (!pi->chat_info || !pi->chat_info_defaults || 673 !(info = pi->chat_info(purple_account_get_connection(p d->account)))) {633 !(info = pi->chat_info(purple_account_get_connection(pa)))) { 674 634 imcb_error(ic, "Joining chatrooms not supported by this protocol"); 675 635 return NULL; 676 636 } 677 637 678 if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, 679 room, pd->account))) { 638 if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, room, pa))) { 680 639 purple_conversation_destroy(conv); 681 640 } 682 641 683 chat_hash = pi->chat_info_defaults( 684 purple_account_get_connection(pd->account), room 685 ); 642 chat_hash = pi->chat_info_defaults(purple_account_get_connection(pa), room); 686 643 687 644 for (l = info; l; l = l->next) { … … 697 654 } 698 655 699 serv_join_chat(purple_account_get_connection(p d->account), chat_hash);656 serv_join_chat(purple_account_get_connection(pa), chat_hash); 700 657 701 658 return NULL; … … 1024 981 pqad->yes(pqad->user_data, pqad->yes_i); 1025 982 } 983 g_free(pqad); 1026 984 } 1027 985 … … 1033 991 pqad->no(pqad->user_data, pqad->no_i); 1034 992 } 1035 } 1036 1037 /* q->free() callback from query_del()*/ 1038 static void prplcb_request_action_free(void *data) 1039 { 1040 struct prplcb_request_action_data *pqad = data; 1041 1042 pqad->bee_data = NULL; 1043 purple_request_close(PURPLE_REQUEST_ACTION, pqad); 993 g_free(pqad); 1044 994 } 1045 995 … … 1076 1026 q = g_strdup_printf("Request: %s\n\n%s\n\n%s", title, primary, secondary); 1077 1027 pqad->bee_data = query_add(local_bee->ui_data, purple_ic_by_pa(account), q, 1078 prplcb_request_action_yes, prplcb_request_action_no, 1079 prplcb_request_action_free, pqad); 1028 prplcb_request_action_yes, prplcb_request_action_no, g_free, pqad); 1080 1029 1081 1030 g_free(q); … … 1084 1033 } 1085 1034 1086 /* So it turns out some requests have no account context at all, because 1087 * libpurple hates us. This means that query_del_by_conn() won't remove those 1088 * on logout, and will segfault if the user replies. That's why this exists. 1089 */ 1090 static void prplcb_close_request(PurpleRequestType type, void *data) 1091 { 1092 struct prplcb_request_action_data *pqad; 1093 struct request_input_data *ri; 1094 struct purple_data *pd; 1095 1096 if (!data) { 1097 return; 1098 } 1099 1100 switch (type) { 1101 case PURPLE_REQUEST_ACTION: 1102 pqad = data; 1103 /* if this is null, it's because query_del was run already */ 1104 if (pqad->bee_data) { 1105 query_del(local_bee->ui_data, pqad->bee_data); 1106 } 1107 g_free(pqad); 1108 break; 1109 case PURPLE_REQUEST_INPUT: 1110 ri = data; 1111 pd = ri->ic->proto_data; 1112 imcb_remove_buddy(ri->ic, ri->buddy, NULL); 1113 g_free(ri->buddy); 1114 g_hash_table_remove(pd->input_requests, GUINT_TO_POINTER(ri->id)); 1115 break; 1116 default: 1117 g_free(data); 1118 break; 1119 } 1120 1121 } 1122 1123 void* prplcb_request_input(const char *title, const char *primary, 1124 const char *secondary, const char *default_value, gboolean multiline, 1125 gboolean masked, gchar *hint, const char *ok_text, GCallback ok_cb, 1126 const char *cancel_text, GCallback cancel_cb, PurpleAccount *account, 1127 const char *who, PurpleConversation *conv, void *user_data) 1128 { 1129 struct im_connection *ic = purple_ic_by_pa(account); 1130 struct purple_data *pd = ic->proto_data; 1131 struct request_input_data *ri = g_new0(struct request_input_data, 1); 1132 guint id = pd->next_request_id++; 1133 1134 ri->id = id; 1135 ri->ic = ic; 1136 ri->buddy = g_strdup_printf("%s_%u", PURPLE_REQUEST_HANDLE, id); 1137 ri->data_callback = (ri_callback_t) ok_cb; 1138 ri->user_data = user_data; 1139 g_hash_table_insert(pd->input_requests, GUINT_TO_POINTER(id), ri); 1140 1141 imcb_add_buddy(ic, ri->buddy, NULL); 1142 imcb_buddy_msg(ic, ri->buddy, secondary, 0, 0); 1143 1144 return ri; 1145 } 1146 1147 void purple_request_input_callback(guint id, struct im_connection *ic, 1148 const char *message, const char *who) 1149 { 1150 struct purple_data *pd = ic->proto_data; 1151 struct request_input_data *ri; 1152 1153 if (!(ri = g_hash_table_lookup(pd->input_requests, GUINT_TO_POINTER(id)))) { 1154 return; 1155 } 1156 1157 ri->data_callback(ri->user_data, message); 1158 1159 purple_request_close(PURPLE_REQUEST_INPUT, ri); 1160 } 1161 1035 /* 1036 static void prplcb_request_test() 1037 { 1038 fprintf( stderr, "bla\n" ); 1039 } 1040 */ 1162 1041 1163 1042 static PurpleRequestUiOps bee_request_uiops = 1164 1043 { 1165 prplcb_request_input,1044 NULL, 1166 1045 NULL, 1167 1046 prplcb_request_action, 1168 1047 NULL, 1169 1048 NULL, 1170 prplcb_close_request,1049 NULL, 1171 1050 NULL, 1172 1051 };
Note: See TracChangeset
for help on using the changeset viewer.