| 355 */ |
366 */ |
| 356 if (closed_conversation || purple_str_has_prefix(message, STREAM_END)) { |
367 if (closed_conversation || purple_str_has_prefix(message, STREAM_END)) { |
| 357 char *closed_conv_message; |
368 char *closed_conv_message; |
| 358 |
369 |
| 359 /* Close the socket, clear the watcher and free memory */ |
370 /* Close the socket, clear the watcher and free memory */ |
| 360 if (bb->conversation != NULL) { |
371 if (bb->conversation != NULL) |
| 361 close(bb->conversation->socket); |
372 bonjour_jabber_close_conversation(pb); |
| 362 purple_input_remove(bb->conversation->watcher_id); |
|
| 363 g_free(bb->conversation->buddy_name); |
|
| 364 g_free(bb->conversation); |
|
| 365 bb->conversation = NULL; |
|
| 366 } |
|
| 367 |
373 |
| 368 /* Inform the user that the conversation has been closed */ |
374 /* Inform the user that the conversation has been closed */ |
| 369 conversation = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pb->name, account); |
375 conversation = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pb->name, account); |
| 370 closed_conv_message = g_strdup_printf(_("%s has closed the conversation."), pb->name); |
376 closed_conv_message = g_strdup_printf(_("%s has closed the conversation."), pb->name); |
| 371 purple_conversation_write(conversation, NULL, closed_conv_message, PURPLE_MESSAGE_SYSTEM, time(NULL)); |
377 purple_conversation_write(conversation, NULL, closed_conv_message, PURPLE_MESSAGE_SYSTEM, time(NULL)); |
| 420 bb = pb->proto_data; |
426 bb = pb->proto_data; |
| 421 |
427 |
| 422 /* Check if the conversation has been previously started */ |
428 /* Check if the conversation has been previously started */ |
| 423 if (bb->conversation == NULL) |
429 if (bb->conversation == NULL) |
| 424 { |
430 { |
| 425 bb->conversation = g_new(BonjourJabberConversation, 1); |
431 bb->conversation = bonjour_jabber_conv_new(pb->name); |
| 426 bb->conversation->socket = client_socket; |
432 bb->conversation->socket = client_socket; |
| 427 bb->conversation->stream_started = FALSE; |
|
| 428 bb->conversation->buddy_name = g_strdup(pb->name); |
|
| 429 |
433 |
| 430 if (bb->conversation->stream_started == FALSE) { |
434 if (bb->conversation->stream_started == FALSE) { |
| 431 char *stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account), |
435 char *stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account), |
| 432 purple_buddy_get_name(pb)); |
436 purple_buddy_get_name(pb)); |
| 433 /* Start the stream */ |
437 /* Start the stream */ |
| 539 { |
543 { |
| 540 int socket = _connect_to_buddy(pb); |
544 int socket = _connect_to_buddy(pb); |
| 541 if (socket < 0) |
545 if (socket < 0) |
| 542 return -10001; |
546 return -10001; |
| 543 |
547 |
| 544 bb->conversation = g_new(BonjourJabberConversation, 1); |
548 bb->conversation = bonjour_jabber_conv_new(pb->name); |
| 545 bb->conversation->socket = socket; |
549 bb->conversation->socket = socket; |
| 546 bb->conversation->stream_started = FALSE; |
|
| 547 bb->conversation->buddy_name = g_strdup(pb->name); |
|
| 548 bb->conversation->watcher_id = purple_input_add(bb->conversation->socket, |
550 bb->conversation->watcher_id = purple_input_add(bb->conversation->socket, |
| 549 PURPLE_INPUT_READ, _client_socket_handler, pb); |
551 PURPLE_INPUT_READ, _client_socket_handler, pb); |
| 550 } |
552 } |
| 551 |
553 |
| 552 message_node = xmlnode_new("message"); |
554 message_node = xmlnode_new("message"); |
| 591 purple_debug_warning("bonjour", "send error: %s\n", strerror(errno)); |
593 purple_debug_warning("bonjour", "send error: %s\n", strerror(errno)); |
| 592 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, data->account); |
594 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, data->account); |
| 593 purple_conversation_write(conv, NULL, |
595 purple_conversation_write(conv, NULL, |
| 594 _("Unable to send the message, the conversation couldn't be started."), |
596 _("Unable to send the message, the conversation couldn't be started."), |
| 595 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
597 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
| 596 close(bb->conversation->socket); |
598 |
| 597 purple_input_remove(bb->conversation->watcher_id); |
599 bonjour_jabber_close_conversation(pb); |
| 598 |
600 |
| 599 /* Free all the data related to the conversation */ |
|
| 600 g_free(bb->conversation->buddy_name); |
|
| 601 g_free(bb->conversation); |
|
| 602 bb->conversation = NULL; |
|
| 603 g_free(message); |
601 g_free(message); |
| 604 g_free(stream_start); |
602 g_free(stream_start); |
| 605 return 0; |
603 return 0; |
| 606 } |
604 } |
| 607 |
605 |