| 226 static void |
226 static void |
| 227 _check_buddy_by_address(gpointer key, gpointer value, gpointer data) |
227 _check_buddy_by_address(gpointer key, gpointer value, gpointer data) |
| 228 { |
228 { |
| 229 GaimBuddy *gb = (GaimBuddy*)value; |
229 GaimBuddy *gb = (GaimBuddy*)value; |
| 230 BonjourBuddy *bb = (BonjourBuddy*)gb->proto_data; |
230 BonjourBuddy *bb = (BonjourBuddy*)gb->proto_data; |
| 231 struct _check_buddy_by_address_t *d = (struct _check_buddy_by_address_t *)data; |
231 struct _check_buddy_by_address_t *d = (struct _check_buddy_by_address_t *)data; |
| 232 |
232 |
| 233 if (bb != NULL) { |
233 if (bb != NULL) { |
| 234 if (g_strcasecmp(bb->ip, (char*)d->address) == 0) |
234 if (g_strcasecmp(bb->ip, (char*)d->address) == 0) |
| 235 *(d->gb) = gb; |
235 *(d->gb) = gb; |
| 236 } |
236 } |
| 237 } |
237 } |
| 238 |
238 |
| 239 static gint |
239 static gint |
| 240 _read_data(gint socket, char **message) |
240 _read_data(gint socket, char **message) |
| 241 { |
241 { |
| 242 GString *data = g_string_new(""); |
242 GString *data = g_string_new(""); |
| 243 char parcial_data[512]; |
243 char partial_data[512]; |
| 244 gint total_message_length = 0; |
244 gint total_message_length = 0; |
| 245 gint parcial_message_length = 0; |
245 gint partial_message_length = 0; |
| 246 |
246 |
| 247 /* Read chunks of 512 bytes till the end of the data */ |
247 /* Read chunks of 512 bytes till the end of the data */ |
| 248 while ((parcial_message_length = recv(socket, parcial_data, 512, 0)) > 0) |
248 while ((partial_message_length = recv(socket, partial_data, 512, 0)) > 0) |
| 249 { |
249 { |
| 250 g_string_append_len(data, parcial_data, parcial_message_length); |
250 g_string_append_len(data, partial_data, partial_message_length); |
| 251 total_message_length += parcial_message_length; |
251 total_message_length += partial_message_length; |
| 252 } |
252 } |
| 253 |
253 |
| 254 if (parcial_message_length == -1) |
254 if (partial_message_length == -1) |
| 255 { |
255 { |
| 256 gaim_debug_warning("bonjour", "receive error: %s\n", strerror(errno)); |
256 gaim_debug_warning("bonjour", "receive error: %s\n", strerror(errno)); |
| 257 if (total_message_length == 0) { |
257 if (total_message_length == 0) { |
| 258 return -1; |
258 return -1; |
| 259 } |
259 } |
| 269 |
269 |
| 270 static gint |
270 static gint |
| 271 _send_data(gint socket, char *message) |
271 _send_data(gint socket, char *message) |
| 272 { |
272 { |
| 273 gint message_len = strlen(message); |
273 gint message_len = strlen(message); |
| 274 gint parcial_sent = 0; |
274 gint partial_sent = 0; |
| 275 gchar *parcial_message = message; |
275 gchar *partial_message = message; |
| 276 |
276 |
| 277 while ((parcial_sent = send(socket, parcial_message, message_len, 0)) < message_len) |
277 while ((partial_sent = send(socket, partial_message, message_len, 0)) < message_len) |
| 278 { |
278 { |
| 279 if (parcial_sent != -1) { |
279 if (partial_sent != -1) { |
| 280 parcial_message += parcial_sent; |
280 partial_message += partial_sent; |
| 281 message_len -= parcial_sent; |
281 message_len -= partial_sent; |
| 282 } else { |
282 } else { |
| 283 return -1; |
283 return -1; |
| 284 } |
284 } |
| 285 } |
285 } |
| 286 |
286 |
| 545 |
545 |
| 546 /* Check if there is a previously open conversation */ |
546 /* Check if there is a previously open conversation */ |
| 547 if (bb->conversation == NULL) |
547 if (bb->conversation == NULL) |
| 548 { |
548 { |
| 549 bb->conversation = g_new(BonjourJabberConversation, 1); |
549 bb->conversation = g_new(BonjourJabberConversation, 1); |
| 550 bb->conversation->socket = _connect_to_buddy(gb);; |
550 bb->conversation->socket = _connect_to_buddy(gb); |
| 551 bb->conversation->start_step_one = FALSE; |
551 bb->conversation->start_step_one = FALSE; |
| 552 bb->conversation->start_step_two = FALSE; |
552 bb->conversation->start_step_two = FALSE; |
| 553 bb->conversation->stream_started = FALSE; |
553 bb->conversation->stream_started = FALSE; |
| 554 bb->conversation->buddy_name = g_strdup(gb->name); |
554 bb->conversation->buddy_name = g_strdup(gb->name); |
| 555 bb->conversation->watcher_id = gaim_input_add(bb->conversation->socket, |
555 bb->conversation->watcher_id = gaim_input_add(bb->conversation->socket, |