Mercurial > pidgin
comparison src/protocols/bonjour/jabber.c @ 13909:8264f52a1142
[gaim-migrate @ 16406]
More of sf patch #1490646, from Jonty Wareing & Jono Cole
"The screen name + hostname of the sending user is sent
in the outgoing jabber message, fixing a sporadic
problem with iChat.
The port in use has been fixed to the one described in
the Bonjour specification and can no longer be changed
in the prpl preferences - modifiying this just stops
the client from being able to start a chat.
The option for a buddy icon has been removed for now as
no code actually uses it yet - we plan to change this
in the future.
This update also introduces automatic local port retry
for up to ten attempts if the port is in
use (e.g. if multiple instances of gaim are running)."
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 03 Jul 2006 00:37:41 +0000 |
parents | 425e0f861e88 |
children | 6c907830a45f |
comparison
equal
deleted
inserted
replaced
13908:cab785a7c766 | 13909:8264f52a1142 |
---|---|
448 gint | 448 gint |
449 bonjour_jabber_start(BonjourJabber *data) | 449 bonjour_jabber_start(BonjourJabber *data) |
450 { | 450 { |
451 struct sockaddr_in my_addr; | 451 struct sockaddr_in my_addr; |
452 int yes = 1; | 452 int yes = 1; |
453 int i; | |
454 gboolean bind_successful; | |
453 | 455 |
454 /* Open a listening socket for incoming conversations */ | 456 /* Open a listening socket for incoming conversations */ |
455 if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) | 457 if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) |
456 { | 458 { |
457 gaim_debug_error("bonjour", "Cannot open socket: %s\n", strerror(errno)); | 459 gaim_debug_error("bonjour", "Cannot open socket: %s\n", strerror(errno)); |
467 return -1; | 469 return -1; |
468 } | 470 } |
469 | 471 |
470 memset(&my_addr, 0, sizeof(struct sockaddr_in)); | 472 memset(&my_addr, 0, sizeof(struct sockaddr_in)); |
471 my_addr.sin_family = PF_INET; | 473 my_addr.sin_family = PF_INET; |
472 my_addr.sin_port = htons(data->port); | 474 |
473 | 475 /* Attempt to find a free port */ |
474 if (bind(data->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) | 476 bind_successful = FALSE; |
477 for (i = 0; i < 10; i++) | |
478 { | |
479 my_addr.sin_port = htons(data->port); | |
480 if (bind(data->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == 0) | |
481 { | |
482 bind_successful = TRUE; | |
483 break; | |
484 } | |
485 data->port++; | |
486 } | |
487 | |
488 /* On no! We tried 10 ports and could not bind to ANY of them */ | |
489 if (!bind_successful) | |
475 { | 490 { |
476 gaim_debug_error("bonjour", "Cannot bind socket: %s\n", strerror(errno)); | 491 gaim_debug_error("bonjour", "Cannot bind socket: %s\n", strerror(errno)); |
477 gaim_connection_error(data->account->gc, _("Cannot bind socket to port")); | 492 gaim_connection_error(data->account->gc, _("Could not bind socket to port")); |
478 return -1; | 493 return -1; |
479 } | 494 } |
480 | 495 |
496 /* Attempt to listen on the bound socket */ | |
481 if (listen(data->socket, 10) != 0) | 497 if (listen(data->socket, 10) != 0) |
482 { | 498 { |
483 gaim_debug_error("bonjour", "Cannot listen on socket: %s\n", strerror(errno)); | 499 gaim_debug_error("bonjour", "Cannot listen on socket: %s\n", strerror(errno)); |
484 gaim_connection_error(data->account->gc, _("Cannot listen on socket")); | 500 gaim_connection_error(data->account->gc, _("Could not listen on socket")); |
485 return -1; | 501 return -1; |
486 } | 502 } |
487 | 503 |
488 #if 0 | 504 #if 0 |
489 /* TODO: Why isn't this being used? */ | 505 /* TODO: Why isn't this being used? */ |
496 #endif | 512 #endif |
497 | 513 |
498 /* Open a watcher in the socket we have just opened */ | 514 /* Open a watcher in the socket we have just opened */ |
499 data->watcher_id = gaim_input_add(data->socket, GAIM_INPUT_READ, _server_socket_handler, data); | 515 data->watcher_id = gaim_input_add(data->socket, GAIM_INPUT_READ, _server_socket_handler, data); |
500 | 516 |
501 return 0; | 517 return data->port; |
502 } | 518 } |
503 | 519 |
504 int | 520 int |
505 bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body) | 521 bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body) |
506 { | 522 { |
545 xmlnode_set_attrib(message_x_node, "xmlns", "jabber:x:event"); | 561 xmlnode_set_attrib(message_x_node, "xmlns", "jabber:x:event"); |
546 xmlnode_insert_child(message_x_node, xmlnode_new("composing")); | 562 xmlnode_insert_child(message_x_node, xmlnode_new("composing")); |
547 | 563 |
548 message_node = xmlnode_new("message"); | 564 message_node = xmlnode_new("message"); |
549 xmlnode_set_attrib(message_node, "to", ((BonjourBuddy*)(gb->proto_data))->name); | 565 xmlnode_set_attrib(message_node, "to", ((BonjourBuddy*)(gb->proto_data))->name); |
566 xmlnode_set_attrib(message_node, "from", data->account->username); | |
550 xmlnode_set_attrib(message_node, "type", "chat"); | 567 xmlnode_set_attrib(message_node, "type", "chat"); |
551 xmlnode_insert_child(message_node, message_body_node); | 568 xmlnode_insert_child(message_node, message_body_node); |
552 xmlnode_insert_child(message_node, message_html_node); | 569 xmlnode_insert_child(message_node, message_html_node); |
553 xmlnode_insert_child(message_node, message_x_node); | 570 xmlnode_insert_child(message_node, message_x_node); |
554 | 571 |