comparison libpurple/protocols/bonjour/jabber.c @ 17556:612dc5149964

Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 08 Jun 2007 15:28:00 +0000
parents b13850d13391
children 6e4e2d234c3a
comparison
equal deleted inserted replaced
17555:b13850d13391 17556:612dc5149964
107 return "12"; 107 return "12";
108 } 108 }
109 #endif 109 #endif
110 110
111 static BonjourJabberConversation * 111 static BonjourJabberConversation *
112 bonjour_jabber_conv_new(const char *name) { 112 bonjour_jabber_conv_new() {
113 113
114 BonjourJabberConversation *bconv = g_new0(BonjourJabberConversation, 1); 114 BonjourJabberConversation *bconv = g_new0(BonjourJabberConversation, 1);
115 bconv->socket = -1; 115 bconv->socket = -1;
116 bconv->buddy_name = g_strdup(name);
117 bconv->watcher_id = -1; 116 bconv->watcher_id = -1;
118 117
119 return bconv; 118 return bconv;
120 } 119 }
121 120
366 */ 365 */
367 if (closed_conversation || purple_str_has_prefix(message, STREAM_END)) { 366 if (closed_conversation || purple_str_has_prefix(message, STREAM_END)) {
368 char *closed_conv_message; 367 char *closed_conv_message;
369 368
370 /* Close the socket, clear the watcher and free memory */ 369 /* Close the socket, clear the watcher and free memory */
371 if (bb->conversation != NULL) 370 bonjour_jabber_close_conversation(bb->conversation);
372 bonjour_jabber_close_conversation(pb); 371 bb->conversation = NULL;
373 372
374 /* Inform the user that the conversation has been closed */ 373 /* Inform the user that the conversation has been closed */
375 conversation = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pb->name, account); 374 conversation = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pb->name, account);
376 closed_conv_message = g_strdup_printf(_("%s has closed the conversation."), pb->name); 375 closed_conv_message = g_strdup_printf(_("%s has closed the conversation."), pb->name);
377 purple_conversation_write(conversation, NULL, closed_conv_message, PURPLE_MESSAGE_SYSTEM, time(NULL)); 376 purple_conversation_write(conversation, NULL, closed_conv_message, PURPLE_MESSAGE_SYSTEM, time(NULL));
426 bb = pb->proto_data; 425 bb = pb->proto_data;
427 426
428 /* Check if the conversation has been previously started */ 427 /* Check if the conversation has been previously started */
429 if (bb->conversation == NULL) 428 if (bb->conversation == NULL)
430 { 429 {
431 bb->conversation = bonjour_jabber_conv_new(pb->name); 430 bb->conversation = bonjour_jabber_conv_new();
432 bb->conversation->socket = client_socket; 431 bb->conversation->socket = client_socket;
433 432
434 if (bb->conversation->stream_started == FALSE) { 433 if (bb->conversation->stream_started == FALSE) {
435 char *stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account), 434 char *stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account),
436 purple_buddy_get_name(pb)); 435 purple_buddy_get_name(pb));
543 { 542 {
544 int socket = _connect_to_buddy(pb); 543 int socket = _connect_to_buddy(pb);
545 if (socket < 0) 544 if (socket < 0)
546 return -10001; 545 return -10001;
547 546
548 bb->conversation = bonjour_jabber_conv_new(pb->name); 547 bb->conversation = bonjour_jabber_conv_new();
549 bb->conversation->socket = socket; 548 bb->conversation->socket = socket;
550 bb->conversation->watcher_id = purple_input_add(bb->conversation->socket, 549 bb->conversation->watcher_id = purple_input_add(bb->conversation->socket,
551 PURPLE_INPUT_READ, _client_socket_handler, pb); 550 PURPLE_INPUT_READ, _client_socket_handler, pb);
552 } 551 }
553 552
594 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, data->account); 593 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, data->account);
595 purple_conversation_write(conv, NULL, 594 purple_conversation_write(conv, NULL,
596 _("Unable to send the message, the conversation couldn't be started."), 595 _("Unable to send the message, the conversation couldn't be started."),
597 PURPLE_MESSAGE_SYSTEM, time(NULL)); 596 PURPLE_MESSAGE_SYSTEM, time(NULL));
598 597
599 bonjour_jabber_close_conversation(pb); 598 bonjour_jabber_close_conversation(bb->conversation);
599 bb->conversation = NULL;
600 600
601 g_free(message); 601 g_free(message);
602 g_free(stream_start); 602 g_free(stream_start);
603 return 0; 603 return 0;
604 } 604 }
616 616
617 return 1; 617 return 1;
618 } 618 }
619 619
620 void 620 void
621 bonjour_jabber_close_conversation(PurpleBuddy *pb) 621 bonjour_jabber_close_conversation(BonjourJabberConversation *bconv)
622 { 622 {
623 BonjourBuddy *bb = pb->proto_data;
624 BonjourJabberConversation *bconv = bb->conversation;
625
626 if (bconv != NULL) 623 if (bconv != NULL)
627 { 624 {
628 /* Close the socket and remove the watcher */ 625 /* Close the socket and remove the watcher */
629 if (bconv->socket >= 0) { 626 if (bconv->socket >= 0) {
630 /* Send the end of the stream to the other end of the conversation */ 627 /* Send the end of the stream to the other end of the conversation */
634 close(bconv->socket); 631 close(bconv->socket);
635 } 632 }
636 purple_input_remove(bconv->watcher_id); 633 purple_input_remove(bconv->watcher_id);
637 634
638 /* Free all the data related to the conversation */ 635 /* Free all the data related to the conversation */
639 g_free(bconv->buddy_name);
640 g_free(bconv); 636 g_free(bconv);
641 bb->conversation = NULL;
642 } 637 }
643 } 638 }
644 639
645 void 640 void
646 bonjour_jabber_stop(BonjourJabber *data) 641 bonjour_jabber_stop(BonjourJabber *data)
655 if (data->account->gc != NULL) 650 if (data->account->gc != NULL)
656 { 651 {
657 GSList *buddies, *l; 652 GSList *buddies, *l;
658 653
659 buddies = purple_find_buddies(data->account, purple_account_get_username(data->account)); 654 buddies = purple_find_buddies(data->account, purple_account_get_username(data->account));
660 for (l = buddies; l; l = l->next) 655 for (l = buddies; l; l = l->next) {
661 bonjour_jabber_close_conversation(l->data); 656 BonjourBuddy *bb = ((PurpleBuddy*) l->data)->proto_data;
657 bonjour_jabber_close_conversation(bb->conversation);
658 bb->conversation = NULL;
659 }
662 g_slist_free(buddies); 660 g_slist_free(buddies);
663 } 661 }
664 } 662 }