gaim/gaim

Fix some bugs that appear workink with x86 archs.
oldstatus
2005-08-31, Juanjo Molinero Horno
3881d580385d
Parents 925e2e354927
Children dc4cd7da3669
Fix some bugs that appear workink with x86 archs.
--- a/src/protocols/bonjour/Makefile Wed Aug 31 15:18:36 2005 -0400
+++ b/src/protocols/bonjour/Makefile Wed Aug 31 17:10:41 2005 -0400
@@ -231,9 +231,9 @@
PACKAGE_TARNAME = gaim
PACKAGE_VERSION = 1.5.1cvs
PATH_SEPARATOR = :
-PERL = perl
-PERL_CFLAGS = -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/perl/5.8/CORE
-PERL_LIBS = -Wl,-E -L/usr/local/lib /usr/lib/perl/5.8/auto/DynaLoader/DynaLoader.a -L/usr/lib/perl/5.8/CORE -lperl -ldl -lm -lpthread -lcrypt
+PERL =
+PERL_CFLAGS =
+PERL_LIBS =
PERL_MM_PARAMS =
PKG_CONFIG = /usr/bin/pkg-config
PLUGINS_FALSE = #
@@ -288,8 +288,8 @@
USE_NLS = yes
USE_NSS_FALSE = #
USE_NSS_TRUE =
-USE_PERL_FALSE = #
-USE_PERL_TRUE =
+USE_PERL_FALSE =
+USE_PERL_TRUE = #
USE_TCL_FALSE =
USE_TCL_TRUE = #
USE_TK_FALSE =
@@ -329,7 +329,7 @@
enable_dot = yes
enable_doxygen = yes
exec_prefix = ${prefix}
-gaimpath = /usr/local/bin/gaim
+gaimpath =
host = powerpc-unknown-linux-gnu
host_alias =
host_cpu = powerpc
@@ -344,7 +344,7 @@
mandir = ${prefix}/man
mkdir_p = mkdir -p --
oldincludedir = /usr/include
-perlpath = /usr/bin/perl
+perlpath =
prefix = /usr/local
program_transform_name = s,x,x,
sbindir = ${exec_prefix}/sbin
--- a/src/protocols/bonjour/bonjour.c Wed Aug 31 15:18:36 2005 -0400
+++ b/src/protocols/bonjour/bonjour.c Wed Aug 31 17:10:41 2005 -0400
@@ -61,17 +61,18 @@
// Connect to the mDNS daemon looking for buddies in the LAN
bd->dns_sd_data = bonjour_dns_sd_new();
bd->dns_sd_data->name = (sw_string)gaim_account_get_username(account);
- bd->dns_sd_data->txtvers = "1";
- bd->dns_sd_data->version = "1";
+ bd->dns_sd_data->txtvers = g_strdup("1");
+ bd->dns_sd_data->version = g_strdup("1");
bd->dns_sd_data->first = gaim_account_get_string(account, "first", "Juanjo");
bd->dns_sd_data->last = gaim_account_get_string(account, "last", "");
bd->dns_sd_data->port_p2pj = gaim_account_get_int(account, "port", BONJOUR_DEFAULT_PORT_INT);
- bd->dns_sd_data->phsh = "";
- bd->dns_sd_data->status = "avail"; //<-- Check the real status if different from avail
+ bd->dns_sd_data->phsh = g_strdup("");
+ bd->dns_sd_data->status = g_strdup("avail"); //<-- Check the real status if different from avail
bd->dns_sd_data->email = gaim_account_get_string(account, "email", "");
- bd->dns_sd_data->vc = "";
- bd->dns_sd_data->jid = "";
- bd->dns_sd_data->AIM = "";
+ bd->dns_sd_data->vc = g_strdup("");
+ bd->dns_sd_data->jid = g_strdup("");
+ bd->dns_sd_data->AIM = g_strdup("");
+ bd->dns_sd_data->msg = g_strdup(gc->away);
bd->dns_sd_data->account = account;
bonjour_dns_sd_start(bd->dns_sd_data);
@@ -91,10 +92,6 @@
GSList* l;
BonjourData* bd = (BonjourData*)connection->proto_data;
- // Stop waiting for conversations
- bonjour_jabber_stop(bd->jabber_data);
- g_free(bd->jabber_data);
-
// Stop looking for buddies in the LAN
if (connection != NULL) {
bonjour_dns_sd_stop(bd->dns_sd_data);
@@ -103,6 +100,10 @@
}
}
+ // Stop waiting for conversations
+ bonjour_jabber_stop(bd->jabber_data);
+ g_free(bd->jabber_data);
+
// Remove all the bonjour buddies
if(connection != NULL){
buddies = gaim_find_buddies(connection->account, connection->account->username);
@@ -136,14 +137,14 @@
void bonjour_set_status(GaimConnection* connection, const char* state, const char* message)
{
char* status_dns_sd = NULL;
- char *stripped = NULL;
+ char* stripped = NULL;
if(message) {
stripped = g_strdup(message);
- } else if(!state || strcmp(state, GAIM_AWAY_CUSTOM)) { // Sacado del plugin de jabber
+ } else {
stripped = g_strdup("");
}
-gaim_debug_warning("bonjour", "Set status: %s - %s\n", state, stripped);
+
if(connection->away){
g_free(connection->away);
}
@@ -155,6 +156,8 @@
status_dns_sd = g_strdup("away");
} else if (g_ascii_strcasecmp(state, _("Do Not Disturb")) == 0) {
status_dns_sd = g_strdup("dnd");
+ } else if (g_ascii_strcasecmp(state, _("Custom")) == 0) {
+ status_dns_sd = g_strdup("away");
}
if (status_dns_sd != NULL) {
--- a/src/protocols/bonjour/dns_sd.c Wed Aug 31 15:18:36 2005 -0400
+++ b/src/protocols/bonjour/dns_sd.c Wed Aug 31 17:10:41 2005 -0400
@@ -93,7 +93,6 @@
sw_int8 value[SW_TEXT_RECORD_MAX_LEN];
sw_uint32 value_length;
-gaim_debug_info("bonjour", "_resolve_reply\n");
sw_discovery_cancel(discovery, oid);
// Get the ip as a string
@@ -215,79 +214,51 @@
return SW_OKAY;
}
-dns_sd_packet* _dns_sd_packet_new()
-{
- return g_new(dns_sd_packet, 1);
-}
-
-void _dns_sd_send_packet(dns_sd_packet* packet, sw_discovery* session)
+int _dns_sd_publish(BonjourDnsSd* data, PublishType type)
{
sw_text_record dns_data;
- sw_discovery_publish_id session_id;
-gaim_debug_warning("bonjour", "dns_sd send packet --> Fill data for the service\n");
+ sw_result publish_result;
+
// Fill the data for the service
if(sw_text_record_init(&dns_data) != SW_OKAY){
gaim_debug_error("bonjour", "Unable to initialize the data for the mDNS.");
- return;
+ return -1;
}
-
- sw_text_record_add_key_and_string_value(dns_data, "txtvers", packet->txtvers);
- sw_text_record_add_key_and_string_value(dns_data, "version", packet->version);
- sw_text_record_add_key_and_string_value(dns_data, "1st", packet->first);
- sw_text_record_add_key_and_string_value(dns_data, "last", packet->last);
- // sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", itoa(packet->port_p2pj));
+
+ sw_text_record_add_key_and_string_value(dns_data, "txtvers", data->txtvers);
+ sw_text_record_add_key_and_string_value(dns_data, "version", data->version);
+ sw_text_record_add_key_and_string_value(dns_data, "1st", data->first);
+ sw_text_record_add_key_and_string_value(dns_data, "last", data->last);
+ // sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", itoa(data->port_p2pj));
sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", BONJOUR_DEFAULT_PORT);
- sw_text_record_add_key_and_string_value(dns_data, "phsh", packet->phsh);
- sw_text_record_add_key_and_string_value(dns_data, "status", packet->status);
- sw_text_record_add_key_and_string_value(dns_data, "msg", packet->message);
- sw_text_record_add_key_and_string_value(dns_data, "email", packet->email);
- sw_text_record_add_key_and_string_value(dns_data, "vc", packet->vc);
- sw_text_record_add_key_and_string_value(dns_data, "jid", packet->jid);
- sw_text_record_add_key_and_string_value(dns_data, "AIM", packet->AIM);
+ sw_text_record_add_key_and_string_value(dns_data, "phsh", data->phsh);
+ sw_text_record_add_key_and_string_value(dns_data, "status", data->status);
+ sw_text_record_add_key_and_string_value(dns_data, "msg", data->msg);
+ sw_text_record_add_key_and_string_value(dns_data, "email", data->email);
+ sw_text_record_add_key_and_string_value(dns_data, "vc", data->vc);
+ sw_text_record_add_key_and_string_value(dns_data, "jid", data->jid);
+ sw_text_record_add_key_and_string_value(dns_data, "AIM", data->AIM);
// Publish the service
- if(sw_discovery_publish(*session, 0, packet->name, ICHAT_SERVICE, NULL,
- NULL, packet->port_p2pj, sw_text_record_bytes(dns_data), sw_text_record_len(dns_data),
- _publish_reply, NULL, &session_id) != SW_OKAY){
+ switch (type) {
+ case PUBLISH_START:
+ publish_result = sw_discovery_publish(*(data->session), 0, data->name, ICHAT_SERVICE, NULL,
+ NULL, data->port_p2pj, sw_text_record_bytes(dns_data), sw_text_record_len(dns_data),
+ _publish_reply, NULL, &(data->session_id));
+ break;
+ case PUBLISH_UPDATE:
+ publish_result = sw_discovery_publish_update(*(data->session),data->session_id,
+ sw_text_record_bytes(dns_data), sw_text_record_len(dns_data));
+ break;
+ }
+ if(publish_result != SW_OKAY){
gaim_debug_error("bonjour", "Unable to publish or change the status of the _presence._tcp service.");
- return;
+ return -1;
}
-
+
// Free the memory used by temp data
sw_text_record_fina(dns_data);
-}
-void _dns_sd_packet_free(dns_sd_packet* packet)
-{
- g_free(packet);
-}
-
-int _dns_sd_register(BonjourDnsSd* data)
-{
- dns_sd_packet* packet;
-
- // Create a new dns-sd packet
- packet = _dns_sd_packet_new();
- packet->name = data->name;
- packet->txtvers = data->txtvers;
- packet->version = data->version;
- packet->first = data->first;
- packet->last = data->last;
- packet->port_p2pj = data->port_p2pj;
- packet->phsh = data->phsh;
- packet->status = data->status;
- packet->message = "";
- packet->email = data->email;
- packet->vc = data->vc;
- packet->jid = data->jid;
- packet->AIM = data->AIM;
-
- // Send the dns-sd packet
- _dns_sd_send_packet(packet, data->session);
-
- // Free the dns-sd packet
- _dns_sd_packet_free(packet);
-
return 0;
}
@@ -301,7 +272,7 @@
{
sw_discovery_oid session_id;
BonjourDnsSd* dns_sd_data = (BonjourDnsSd*)data;
-gaim_debug_error("bonjour", "Wait for connections\n");
+
// Advise the daemon that we are waiting for connections
if(sw_discovery_browse(*(dns_sd_data->session), 0, ICHAT_SERVICE, NULL, _browser_reply,
dns_sd_data->account, &session_id) != SW_OKAY){
@@ -340,31 +311,16 @@
/**
* Send a new dns-sd packet updating our status.
*/
-void bonjour_dns_sd_send_status(BonjourDnsSd* data, char* status_dns_sd, const char* status_message)
+void bonjour_dns_sd_send_status(BonjourDnsSd* data, char* status, const char* status_message)
{
- dns_sd_packet* packet;
-
- // Create a new dns-sd packet
- packet = _dns_sd_packet_new();
- packet->name = data->name;
- packet->txtvers = data->txtvers;
- packet->version = data->version;
- packet->first = data->first;
- packet->last = data->last;
- packet->port_p2pj = data->port_p2pj;
- packet->phsh = data->phsh;
- packet->status = status_dns_sd;
- packet->message = g_strdup(status_message);
- packet->email = data->email;
- packet->vc = data->vc;
- packet->jid = data->jid;
- packet->AIM = data->AIM;
-
- // Send the dns-sd packet
- _dns_sd_send_packet(packet, data->session);
-
- // Free the dns-sd packet
- _dns_sd_packet_free(packet);
+ if (data->status) g_free(data->status);
+ if (data->msg) g_free(data->msg);
+
+ data->status = g_strdup(status);
+ data->msg = g_strdup(status_message);
+
+ // Update our text record with the new status
+ _dns_sd_publish(data, PUBLISH_UPDATE); // <--We must control the errors
}
/**
@@ -380,20 +336,13 @@
// Initilizations of the dns-sd data and session
data->session = malloc(sizeof(sw_discovery));
if(sw_discovery_init(data->session) != SW_OKAY){
- gaim_debug_error("bonjour", "Unable to initialize a mDNS session.");
- return;
+ gaim_debug_error("bonjour", "Unable to initialize a mDNS session.");
+ return;
}
- // Register our bonjour IM client at the mDNS daemon
- _dns_sd_register(data);
+ // Publish our bonjour IM client at the mDNS daemon
+ _dns_sd_publish(data, PUBLISH_START); // <--We must control the errors
- // Wait for new bonjour IM client connections, we should start a new thread
- /*
- if (!g_thread_supported ()){
- g_thread_init (NULL);
- }
- g_thread_create(_dns_sd_wait_for_connections, data, FALSE, NULL);
- */
// Advise the daemon that we are waiting for connections
if(sw_discovery_browse(*(data->session), 0, ICHAT_SERVICE, NULL, _browser_reply,
@@ -401,11 +350,8 @@
gaim_debug_error("bonjour", "Unable to get service.");
return;
}
-
- // Yields control of the cpu to the daemon
- //sw_discovery_run(*(dns_sd_data->session));
- // Get the socket that communicates with the mDNS daemon and binf it to a
+ // Get the socket that communicates with the mDNS daemon and bind it to a
// callback that will handle the dns_sd packets
dns_sd_socket = sw_discovery_socket(*(data->session));
io_channel = g_io_channel_unix_new(dns_sd_socket);
@@ -417,7 +363,7 @@
*/
int bonjour_dns_sd_stop(BonjourDnsSd* data)
{
- sw_discovery_stop_run(*(data->session));
+ sw_discovery_cancel(*(data->session), data->session_id);
return 0;
}
--- a/src/protocols/bonjour/dns_sd.h Wed Aug 31 15:18:36 2005 -0400
+++ b/src/protocols/bonjour/dns_sd.h Wed Aug 31 17:10:41 2005 -0400
@@ -30,6 +30,7 @@
*/
typedef struct _bonjour_dns_sd{
sw_discovery* session;
+ sw_discovery_oid session_id;
GaimAccount* account;
gchar* name;
gchar* txtvers;
@@ -43,9 +44,15 @@
gchar* vc;
gchar* jid;
gchar* AIM;
+ gchar* msg;
GHashTable* buddies;
}BonjourDnsSd;
+typedef enum _PublishType{
+ PUBLISH_START,
+ PUBLISH_UPDATE
+}PublishType;
+
/**
* Allocate space for the dns-sd data.
*/
@@ -59,7 +66,7 @@
/**
* Send a new dns-sd packet updating our status.
*/
-void bonjour_dns_sd_send_status(BonjourDnsSd* data, char* status_dns_sd, const char* status_message);
+void bonjour_dns_sd_send_status(BonjourDnsSd* data, char* status, const char* status_message);
/**
* Advertise our presence within the dns-sd daemon and start browsing for other
--- a/src/protocols/bonjour/jabber.c Wed Aug 31 15:18:36 2005 -0400
+++ b/src/protocols/bonjour/jabber.c Wed Aug 31 17:10:41 2005 -0400
@@ -45,19 +45,23 @@
gint _connect_to_buddy(GaimBuddy* gb)
{
gint socket_fd;
+ gint retorno = 0;
struct sockaddr_in buddy_address;
// Create a socket and make it non-blocking
- socket_fd = socket(AF_INET, SOCK_STREAM, 0);
- fcntl(socket_fd, F_SETFL, O_NONBLOCK);
+ socket_fd = socket(PF_INET, SOCK_STREAM, 0);
- buddy_address.sin_family = AF_INET;
+ buddy_address.sin_family = PF_INET;
buddy_address.sin_port = htons(((BonjourBuddy*)(gb->proto_data))->port_p2pj);
inet_aton(((BonjourBuddy*)(gb->proto_data))->ip, &(buddy_address.sin_addr));
memset(&(buddy_address.sin_zero), '\0', 8);
- connect(socket_fd, (struct sockaddr*)&buddy_address, sizeof(struct sockaddr));
-
+ retorno = connect(socket_fd, (struct sockaddr*)&buddy_address, sizeof(struct sockaddr));
+ if (retorno == -1) {
+ perror("connect");
+ }
+ fcntl(socket_fd, F_SETFL, O_NONBLOCK);
+
return socket_fd;
}
@@ -113,6 +117,8 @@
} else {
result = g_string_new("1");
}
+
+ return g_string_free(result, FALSE);
}
void _jabber_parse_and_write_message_to_ui(char* message, GaimConnection* connection, GaimBuddy* gb)
{
@@ -140,7 +146,6 @@
}
body_node = xmlnode_get_child(message_node, "body");
- gaim_debug_info("bonjour", "body node --> %s\n", xmlnode_to_str(body_node, NULL));
if (body_node != NULL) {
body = xmlnode_get_data(body_node);
} else {
@@ -148,7 +153,6 @@
}
html_node = xmlnode_get_child(message_node, "html");
- gaim_debug_info("bonjour", "html node --> %s\n", xmlnode_to_str(html_node, NULL));
if (html_node != NULL) {
isHTML = TRUE;
html_body_node = xmlnode_get_child(html_node, "body");
@@ -198,7 +202,6 @@
if (ichat_balloon_color == NULL) ichat_balloon_color = "#FFFFFF";
body = g_strconcat("<font face='", font_face, "' size='", font_size, "' color='", ichat_text_color,
"' back='", ichat_balloon_color, "'>", html_body, "</font>", NULL);
- gaim_debug_info("bonjour", "message sent to the UI --> %s\n", body);
}
// Send the message to the UI
@@ -215,10 +218,14 @@
GaimBuddy* gb = (GaimBuddy*)value;
BonjourBuddy* bb = (BonjourBuddy*)gb->proto_data;
- if (g_strcasecmp(bb->ip, (char*)address) == 0) {
- return TRUE;
+ if (bb != NULL) {
+ if (g_strcasecmp(bb->ip, (char*)address) == 0) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
} else {
- return FALSE;
+ return FALSE;
}
}
@@ -231,24 +238,26 @@
// Read chunks of 512 bytes till the end of the data
while ((parcial_message_length = recv(socket, parcial_data, 512, 0)) > 0) {
- if (parcial_message_length != -1) {
g_string_append_len(data, parcial_data, parcial_message_length);
total_message_length += parcial_message_length;
- } else { // If there is some problem on the transmission we return -1
- g_string_free(data, TRUE);
+ }
+
+ if (parcial_message_length == -1) {
+ perror("recv");
+ if (total_message_length == 0) {
return -1;
}
}
-
+
*message = data->str;
g_string_free(data, FALSE);
-
+if (total_message_length != 0) gaim_debug_info("bonjour", "Receive: -%s- %d bytes\n", *message, total_message_length);
return total_message_length;
}
gint _send_data(gint socket, char* message)
{
- gint message_len = strlen(message) + 1;
+ gint message_len = strlen(message);
gint parcial_sent = 0;
gchar* parcial_message = message;
@@ -261,7 +270,7 @@
}
}
- return strlen(message) + 1;
+ return strlen(message);
}
void _client_socket_handler(gpointer data, gint socket, GaimInputCondition condition)
@@ -279,8 +288,6 @@
// Read the data from the socket
if ((message_length = _read_data(socket, &message)) == -1) {
// There have been an error reading from the socket
- error_message = strerror(errno);
- gaim_debug_error("bonjour", "eohhh:%s\n", error_message);
return;
} else if (message_length == 0) { // The other end has closed the socket
closed_conversation = TRUE;
@@ -293,7 +300,7 @@
}
}
- // Check if the start of the doctype has been receiced, if not check that the current
+ // Check if the start of the doctype has been received, if not check that the current
// data is the doctype
if (!(bb->conversation->start_step_one)) {
if (g_str_has_prefix(message, DOCTYPE_DECLARATION)){
@@ -309,7 +316,7 @@
// If we haven't done it yet, we have to sent the start of the stream to the other buddy
if (!(bb->conversation->stream_started)) {
- if (send(bb->conversation->socket, CONVERSATION_START, strlen(CONVERSATION_START) + 1, 0) == -1) {
+ if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1) {
gaim_debug_error("bonjour", "Unable to start a conversation with %s\n", bb->name);
}
}
@@ -320,21 +327,22 @@
// Check that this is not the end of the conversation
if (g_str_has_prefix(message, STREAM_END) || (closed_conversation == TRUE)) {
// Close the socket, clear the watcher and free memory
- close(bb->conversation->socket);
- gaim_input_remove(bb->conversation->watcher_id);
- g_free(bb->conversation->buddy_name);
- g_free(bb->conversation);
- bb->conversation = NULL;
+ if (bb->conversation != NULL) {
+ close(bb->conversation->socket);
+ gaim_input_remove(bb->conversation->watcher_id);
+ g_free(bb->conversation->buddy_name);
+ g_free(bb->conversation);
+ bb->conversation = NULL;
+ }
// Inform the user that the conversation has been closed
conversation = gaim_find_conversation_with_account(gb->name, account);
closed_conv_message = g_strconcat(gb->name, " has closed the conversation.", NULL);
gaim_conversation_write(conversation, NULL, closed_conv_message, GAIM_MESSAGE_SYSTEM, time(NULL));
- return;
+ } else {
+ // Parse the message to get the data and send to the ui
+ _jabber_parse_and_write_message_to_ui(message, account->gc, gb);
}
-
- // Parse the message to get the data and send to the ui
- _jabber_parse_and_write_message_to_ui(message, account->gc, gb);
}
void _server_socket_handler(gpointer data, int server_socket, GaimInputCondition condition)
@@ -346,12 +354,12 @@
BonjourBuddy* bb = NULL;
char* address_text = NULL;
GaimBuddyList* bl = gaim_get_blist();
-
+
//Check that it is a read condition
if (condition != GAIM_INPUT_READ) {
return;
}
-
+
if ((client_socket = accept(server_socket, (struct sockaddr *)&their_addr, &sin_size)) == -1) {
return;
}
@@ -377,6 +385,12 @@
bb->conversation->buddy_name = g_strdup(gb->name);
bb->conversation->message_id = 1;
+ if (bb->conversation->stream_started == FALSE) {
+ // Start the stream
+ send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0);
+ bb->conversation->stream_started = TRUE;
+ }
+
// Open a watcher for the client socket
bb->conversation->watcher_id = gaim_input_add(client_socket, GAIM_INPUT_READ,
_client_socket_handler, gb);
@@ -391,8 +405,9 @@
int yes = 1;
char* error_message = NULL;
+
// Open a listening socket for incoming conversations
- if ((data->socket = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+ if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
gaim_debug_error("bonjour", "Cannot get socket\n");
error_message = strerror(errno);
gaim_debug_error("bonjour", "%s\n", error_message);
@@ -401,20 +416,19 @@
}
// Make the socket reusable
- if (setsockopt(data->socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
+ if (setsockopt(data->socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0) {
gaim_debug_error("bonjour", "Cannot make socket reusable\n");
error_message = strerror(errno);
gaim_debug_error("bonjour", "%s\n", error_message);
gaim_connection_error(data->account->gc, "Error setting socket options");
return -1;
}
+
+ memset(&my_addr, 0, sizeof(struct sockaddr_in));
+ my_addr.sin_family = PF_INET;
+ my_addr.sin_port = htons(data->port);
- my_addr.sin_family = AF_INET;
- my_addr.sin_port = data->port;
- my_addr.sin_addr.s_addr = INADDR_ANY;
- memset(&(my_addr.sin_zero), '\0', 8);
-
- if (bind(data->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == -1) {
+ if (bind(data->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) {
gaim_debug_error("bonjour", "Cannot bind socket\n");
error_message = strerror(errno);
gaim_debug_error("bonjour", "%s\n", error_message);
@@ -422,7 +436,7 @@
return -1;
}
- if (listen(data->socket, 10) == -1) {
+ if (listen(data->socket, 10) != 0) {
gaim_debug_error("bonjour", "Cannot listen to socket\n");
error_message = strerror(errno);
gaim_debug_error("bonjour", "%s\n", error_message);
@@ -430,8 +444,12 @@
return -1;
}
- gaim_debug_info("bonjour", "Listening on port %d with socket %d\n", data->port, data->socket);
-
+ //data->socket = gaim_network_listen(data->port);
+
+ //if (data->socket == -1) {
+ // gaim_debug_error("bonjour", "No se ha podido crear el socket\n");
+ //}
+
// Open a watcher in the socket we have just opened
data->watcher_id = gaim_input_add(data->socket, GAIM_INPUT_READ, _server_socket_handler, data);
@@ -498,8 +516,9 @@
// Check if the stream for the conversation has been started
if (bb->conversation->stream_started == FALSE) {
// Start the stream
- if (send(bb->conversation->socket, CONVERSATION_START, strlen(CONVERSATION_START) + 1, 0) == -1) {
+ if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1) {
gaim_debug_error("bonjour", "Unable to start a conversation\n");
+ perror("send");
conv_message = g_strdup("Unable to send the message, the conversation couldn't be started.");
conversation = gaim_find_conversation_with_account(bb->name, data->account);
gaim_conversation_write(conversation, NULL, conv_message, GAIM_MESSAGE_SYSTEM, time(NULL));
@@ -517,13 +536,12 @@
}
// Send the message
- if (_send_data(bb->conversation->socket, message) == -1) { // This only works with small amounts of data
+ if (_send_data(bb->conversation->socket, message) == -1) {
gaim_debug_error("bonjour", "Unable to send the message\n");
conv_message = g_strdup("Unable to send the message.");
conversation = gaim_find_conversation_with_account(bb->name, data->account);
gaim_conversation_write(conversation, NULL, conv_message, GAIM_MESSAGE_SYSTEM, time(NULL));
}
- gaim_debug_info("bonjour", "Sent message to %s -->\n%s\n", to, message);
}
void bonjour_jabber_close_conversation(BonjourJabber* data, GaimBuddy* gb)
@@ -532,7 +550,7 @@
if (bb->conversation != NULL) {
// Send the end of the stream to the other end of the conversation
- send(bb->conversation->socket, STREAM_END, strlen(STREAM_END) + 1, 0);
+ send(bb->conversation->socket, STREAM_END, strlen(STREAM_END), 0);
// Close the socket and remove the watcher
close(bb->conversation->socket);
@@ -541,6 +559,7 @@
// Free all the data related to the conversation
g_free(bb->conversation->buddy_name);
g_free(bb->conversation);
+ bb->conversation = NULL;
}
}
@@ -562,7 +581,7 @@
gb = (GaimBuddy*)l->data;
bb = (BonjourBuddy*)gb->proto_data;
if (bb->conversation != NULL) {
- send(bb->conversation->socket, STREAM_END, strlen(STREAM_END) + 1, 0);
+ send(bb->conversation->socket, STREAM_END, strlen(STREAM_END), 0);
close(bb->conversation->socket);
gaim_input_remove(bb->conversation->watcher_id);
}
--- a/src/protocols/bonjour/jabber.h Wed Aug 31 15:18:36 2005 -0400
+++ b/src/protocols/bonjour/jabber.h Wed Aug 31 17:10:41 2005 -0400
@@ -29,10 +29,10 @@
#include "account.h"
#define DOCTYPE_DECLARATION "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
-#define STREAM_START "<stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" >"
-#define CONVERSATION_START "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" >\n"
+#define STREAM_START "<stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\">"
+#define CONVERSATION_START "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\">"
#define STREAM_END "</stream:stream>"
-
+#define DOCTYPE "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" >"
typedef struct _bonjour_jabber{
gint port;
gint socket;