| 352 bb->conversation = NULL; |
352 bb->conversation = NULL; |
| 353 } |
353 } |
| 354 |
354 |
| 355 /* Inform the user that the conversation has been closed */ |
355 /* Inform the user that the conversation has been closed */ |
| 356 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, gb->name, account); |
356 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, gb->name, account); |
| 357 closed_conv_message = g_strconcat(gb->name, " has closed the conversation.", NULL); |
357 closed_conv_message = g_strdup_printf(_("%s has closed the conversation."), gb->name); |
| 358 gaim_conversation_write(conversation, NULL, closed_conv_message, GAIM_MESSAGE_SYSTEM, time(NULL)); |
358 gaim_conversation_write(conversation, NULL, closed_conv_message, GAIM_MESSAGE_SYSTEM, time(NULL)); |
| |
359 g_free(closed_conv_message); |
| 359 } else { |
360 } else { |
| 360 /* Parse the message to get the data and send to the ui */ |
361 /* Parse the message to get the data and send to the ui */ |
| 361 _jabber_parse_and_write_message_to_ui(message, account->gc, gb); |
362 _jabber_parse_and_write_message_to_ui(message, account->gc, gb); |
| 362 } |
363 } |
| 363 } |
364 } |
| 428 gint |
429 gint |
| 429 bonjour_jabber_start(BonjourJabber *data) |
430 bonjour_jabber_start(BonjourJabber *data) |
| 430 { |
431 { |
| 431 struct sockaddr_in my_addr; |
432 struct sockaddr_in my_addr; |
| 432 int yes = 1; |
433 int yes = 1; |
| 433 char *error_message = NULL; |
|
| 434 |
434 |
| 435 /* Open a listening socket for incoming conversations */ |
435 /* Open a listening socket for incoming conversations */ |
| 436 if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) |
436 if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) |
| 437 { |
437 { |
| 438 gaim_debug_error("bonjour", "Cannot get socket\n"); |
438 gaim_debug_error("bonjour", "Cannot open socket: %s\n", strerror(errno)); |
| 439 error_message = strerror(errno); |
439 gaim_connection_error(data->account->gc, _("Cannot open socket")); |
| 440 gaim_debug_error("bonjour", "%s\n", error_message); |
|
| 441 gaim_connection_error(data->account->gc, "Cannot open socket"); |
|
| 442 return -1; |
440 return -1; |
| 443 } |
441 } |
| 444 |
442 |
| 445 /* Make the socket reusable */ |
443 /* Make the socket reusable */ |
| 446 if (setsockopt(data->socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0) |
444 if (setsockopt(data->socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0) |
| 447 { |
445 { |
| 448 gaim_debug_error("bonjour", "Cannot make socket reusable\n"); |
446 gaim_debug_error("bonjour", "Error setting socket options: %s\n", strerror(errno)); |
| 449 error_message = strerror(errno); |
447 gaim_connection_error(data->account->gc, _("Error setting socket options")); |
| 450 gaim_debug_error("bonjour", "%s\n", error_message); |
|
| 451 gaim_connection_error(data->account->gc, "Error setting socket options"); |
|
| 452 return -1; |
448 return -1; |
| 453 } |
449 } |
| 454 |
450 |
| 455 memset(&my_addr, 0, sizeof(struct sockaddr_in)); |
451 memset(&my_addr, 0, sizeof(struct sockaddr_in)); |
| 456 my_addr.sin_family = PF_INET; |
452 my_addr.sin_family = PF_INET; |
| 457 my_addr.sin_port = htons(data->port); |
453 my_addr.sin_port = htons(data->port); |
| 458 |
454 |
| 459 if (bind(data->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) |
455 if (bind(data->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) |
| 460 { |
456 { |
| 461 gaim_debug_error("bonjour", "Cannot bind socket\n"); |
457 gaim_debug_error("bonjour", "Cannot bind socket: %s\n", strerror(errno)); |
| 462 error_message = strerror(errno); |
458 gaim_connection_error(data->account->gc, _("Cannot bind socket to port")); |
| 463 gaim_debug_error("bonjour", "%s\n", error_message); |
|
| 464 gaim_connection_error(data->account->gc, "Cannot bind socket to port"); |
|
| 465 return -1; |
459 return -1; |
| 466 } |
460 } |
| 467 |
461 |
| 468 if (listen(data->socket, 10) != 0) |
462 if (listen(data->socket, 10) != 0) |
| 469 { |
463 { |
| 470 gaim_debug_error("bonjour", "Cannot listen to socket\n"); |
464 gaim_debug_error("bonjour", "Cannot listen on socket: %s\n", strerror(errno)); |
| 471 error_message = strerror(errno); |
465 gaim_connection_error(data->account->gc, _("Cannot listen on socket")); |
| 472 gaim_debug_error("bonjour", "%s\n", error_message); |
|
| 473 gaim_connection_error(data->account->gc, "Cannot listen to socket"); |
|
| 474 return -1; |
466 return -1; |
| 475 } |
467 } |
| 476 |
468 |
| 477 #if 0 |
469 #if 0 |
| 478 /* TODO: Why isn't this being used? */ |
470 /* TODO: Why isn't this being used? */ |
| 562 /* Start the stream */ |
554 /* Start the stream */ |
| 563 if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1) |
555 if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1) |
| 564 { |
556 { |
| 565 gaim_debug_error("bonjour", "Unable to start a conversation\n"); |
557 gaim_debug_error("bonjour", "Unable to start a conversation\n"); |
| 566 gaim_debug_warning("bonjour", "send error: %s\n", strerror(errno)); |
558 gaim_debug_warning("bonjour", "send error: %s\n", strerror(errno)); |
| 567 conv_message = g_strdup("Unable to send the message, the conversation couldn't be started."); |
559 conv_message = g_strdup(_("Unable to send the message, the conversation couldn't be started.")); |
| 568 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, bb->name, data->account); |
560 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, bb->name, data->account); |
| 569 gaim_conversation_write(conversation, NULL, conv_message, GAIM_MESSAGE_SYSTEM, time(NULL)); |
561 gaim_conversation_write(conversation, NULL, conv_message, GAIM_MESSAGE_SYSTEM, time(NULL)); |
| 570 close(bb->conversation->socket); |
562 close(bb->conversation->socket); |
| 571 gaim_input_remove(bb->conversation->watcher_id); |
563 gaim_input_remove(bb->conversation->watcher_id); |
| 572 |
564 |