Mercurial > pidgin.yaz
comparison src/protocols/bonjour/jabber.c @ 11826:e05778d4f12d
[gaim-migrate @ 14117]
Comment changes, plus I reworked _font_size_gaim_to_ichat and _font_size_ichat_to_gaim so they didn't suck as bad.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Wed, 26 Oct 2005 00:28:26 +0000 |
parents | 27ed05facc71 |
children | 9cd233ea2799 |
comparison
equal
deleted
inserted
replaced
11825:9e14f1850369 | 11826:e05778d4f12d |
---|---|
50 { | 50 { |
51 gint socket_fd; | 51 gint socket_fd; |
52 gint retorno = 0; | 52 gint retorno = 0; |
53 struct sockaddr_in buddy_address; | 53 struct sockaddr_in buddy_address; |
54 | 54 |
55 // Create a socket and make it non-blocking | 55 /* Create a socket and make it non-blocking */ |
56 socket_fd = socket(PF_INET, SOCK_STREAM, 0); | 56 socket_fd = socket(PF_INET, SOCK_STREAM, 0); |
57 | 57 |
58 buddy_address.sin_family = PF_INET; | 58 buddy_address.sin_family = PF_INET; |
59 buddy_address.sin_port = htons(((BonjourBuddy*)(gb->proto_data))->port_p2pj); | 59 buddy_address.sin_port = htons(((BonjourBuddy*)(gb->proto_data))->port_p2pj); |
60 inet_aton(((BonjourBuddy*)(gb->proto_data))->ip, &(buddy_address.sin_addr)); | 60 inet_aton(((BonjourBuddy*)(gb->proto_data))->ip, &(buddy_address.sin_addr)); |
67 fcntl(socket_fd, F_SETFL, O_NONBLOCK); | 67 fcntl(socket_fd, F_SETFL, O_NONBLOCK); |
68 | 68 |
69 return socket_fd; | 69 return socket_fd; |
70 } | 70 } |
71 | 71 |
72 char * | 72 const char * |
73 _font_size_gaim_to_ichat(int size) | 73 _font_size_gaim_to_ichat(int size) |
74 { | 74 { |
75 GString *result = NULL; | 75 switch (size) { |
76 | 76 case 1: |
77 switch(size) { | 77 return "8"; |
78 case 1 : | 78 case 2: |
79 result = g_string_new("8"); | 79 return "10"; |
80 break; | 80 case 3: |
81 case 2 : | 81 return "12"; |
82 result = g_string_new("10"); | 82 case 4: |
83 break; | 83 return "14"; |
84 case 3 : | 84 case 5: |
85 result = g_string_new("12"); | 85 return "17"; |
86 break; | 86 case 6: |
87 case 4 : | 87 return "21"; |
88 result = g_string_new("14"); | 88 case 7: |
89 break; | 89 return "24"; |
90 case 5 : | 90 } |
91 result = g_string_new("17"); | 91 |
92 break; | 92 return "12"; |
93 case 6 : | 93 } |
94 result = g_string_new("21"); | 94 |
95 break; | 95 const char * |
96 case 7 : | |
97 result = g_string_new("24"); | |
98 break; | |
99 default: | |
100 result = g_string_new("12"); | |
101 } | |
102 | |
103 return g_string_free(result, FALSE); | |
104 } | |
105 | |
106 char * | |
107 _font_size_ichat_to_gaim(int size) | 96 _font_size_ichat_to_gaim(int size) |
108 { | 97 { |
109 GString *result = NULL; | |
110 | |
111 if (size > 24) { | 98 if (size > 24) { |
112 result = g_string_new("7"); | 99 return "7"; |
113 } else if (size >= 21) { | 100 } else if (size >= 21) { |
114 result = g_string_new("6"); | 101 return "6"; |
115 } else if (size >= 17) { | 102 } else if (size >= 17) { |
116 result = g_string_new("5"); | 103 return "5"; |
117 } else if (size >= 14) { | 104 } else if (size >= 14) { |
118 result = g_string_new("4"); | 105 return "4"; |
119 } else if (size >= 12) { | 106 } else if (size >= 12) { |
120 result = g_string_new("3"); | 107 return "3"; |
121 } else if (size >= 10) { | 108 } else if (size >= 10) { |
122 result = g_string_new("2"); | 109 return "2"; |
123 } else { | 110 } |
124 result = g_string_new("1"); | 111 |
125 } | 112 return "1"; |
126 | |
127 return g_string_free(result, FALSE); | |
128 } | 113 } |
129 void | 114 void |
130 _jabber_parse_and_write_message_to_ui(char *message, GaimConnection *connection, GaimBuddy *gb) | 115 _jabber_parse_and_write_message_to_ui(char *message, GaimConnection *connection, GaimBuddy *gb) |
131 { | 116 { |
132 xmlnode *body_node = NULL; | 117 xmlnode *body_node = NULL; |
144 xmlnode *events_node = NULL; | 129 xmlnode *events_node = NULL; |
145 gboolean composing_event = FALSE; | 130 gboolean composing_event = FALSE; |
146 gint garbage = -1; | 131 gint garbage = -1; |
147 xmlnode *message_node = NULL; | 132 xmlnode *message_node = NULL; |
148 | 133 |
149 // Parsing of the message | 134 /* Parsing of the message */ |
150 message_node = xmlnode_from_str(message, strlen(message)); | 135 message_node = xmlnode_from_str(message, strlen(message)); |
151 if (message_node == NULL) { | 136 if (message_node == NULL) { |
152 return; | 137 return; |
153 } | 138 } |
154 | 139 |
168 { | 153 { |
169 ichat_balloon_color = xmlnode_get_attrib(html_body_node, "ichatballooncolor"); | 154 ichat_balloon_color = xmlnode_get_attrib(html_body_node, "ichatballooncolor"); |
170 ichat_text_color = xmlnode_get_attrib(html_body_node, "ichattextcolor"); | 155 ichat_text_color = xmlnode_get_attrib(html_body_node, "ichattextcolor"); |
171 html_body_font_node = xmlnode_get_child(html_body_node, "font"); | 156 html_body_font_node = xmlnode_get_child(html_body_node, "font"); |
172 if (html_body_font_node != NULL) | 157 if (html_body_font_node != NULL) |
173 { // Types of messages sent by iChat | 158 { /* Types of messages sent by iChat */ |
174 font_face = xmlnode_get_attrib(html_body_font_node, "face"); | 159 font_face = xmlnode_get_attrib(html_body_font_node, "face"); |
175 // The absolute iChat font sizes should be converted to 1..7 range | 160 /* The absolute iChat font sizes should be converted to 1..7 range */ |
176 font_size = xmlnode_get_attrib(html_body_font_node, "ABSZ"); | 161 font_size = xmlnode_get_attrib(html_body_font_node, "ABSZ"); |
177 if (font_size != NULL) | 162 if (font_size != NULL) |
178 { | 163 { |
179 font_size = _font_size_ichat_to_gaim(atoi(font_size)); //<-- This call will probably leak memory | 164 font_size = _font_size_ichat_to_gaim(atoi(font_size)); |
180 } | 165 } |
181 font_color = xmlnode_get_attrib(html_body_font_node, "color"); | 166 font_color = xmlnode_get_attrib(html_body_font_node, "color"); |
182 html_body = xmlnode_get_data(html_body_font_node); | 167 html_body = xmlnode_get_data(html_body_font_node); |
183 if (html_body == NULL) | 168 if (html_body == NULL) |
184 { | 169 { |
185 // This is the kind of formated messages that Gaim creates | 170 /* This is the kind of formated messages that Gaim creates */ |
186 html_body = xmlnode_to_str(html_body_font_node, &garbage); | 171 html_body = xmlnode_to_str(html_body_font_node, &garbage); |
187 } | 172 } |
188 } else { | 173 } else { |
189 isHTML = FALSE; | 174 isHTML = FALSE; |
190 } | 175 } |
201 { | 186 { |
202 composing_event = TRUE; | 187 composing_event = TRUE; |
203 } | 188 } |
204 if (xmlnode_get_child(events_node, "id") != NULL) | 189 if (xmlnode_get_child(events_node, "id") != NULL) |
205 { | 190 { |
206 // The user is just typing | 191 /* The user is just typing */ |
207 xmlnode_free(message_node); | 192 xmlnode_free(message_node); |
208 g_free(body); | 193 g_free(body); |
209 g_free(html_body); | 194 g_free(html_body); |
210 return; | 195 return; |
211 } | 196 } |
212 } | 197 } |
213 | 198 |
214 // Compose the message | 199 /* Compose the message */ |
215 if (isHTML) | 200 if (isHTML) |
216 { | 201 { |
217 if (font_face == NULL) font_face = "Helvetica"; | 202 if (font_face == NULL) font_face = "Helvetica"; |
218 if (font_size == NULL) font_size = "3"; | 203 if (font_size == NULL) font_size = "3"; |
219 if (ichat_text_color == NULL) ichat_text_color = "#000000"; | 204 if (ichat_text_color == NULL) ichat_text_color = "#000000"; |
220 if (ichat_balloon_color == NULL) ichat_balloon_color = "#FFFFFF"; | 205 if (ichat_balloon_color == NULL) ichat_balloon_color = "#FFFFFF"; |
221 body = g_strconcat("<font face='", font_face, "' size='", font_size, "' color='", ichat_text_color, | 206 body = g_strconcat("<font face='", font_face, "' size='", font_size, "' color='", ichat_text_color, |
222 "' back='", ichat_balloon_color, "'>", html_body, "</font>", NULL); | 207 "' back='", ichat_balloon_color, "'>", html_body, "</font>", NULL); |
223 } | 208 } |
224 | 209 g_free(font_size); |
225 // Send the message to the UI | 210 |
211 /* Send the message to the UI */ | |
226 serv_got_im(connection, gb->name, body, 0, time(NULL)); | 212 serv_got_im(connection, gb->name, body, 0, time(NULL)); |
227 | 213 |
228 // Free all the strings and nodes (the attributes are freed with their nodes) | 214 /* Free all the strings and nodes (the attributes are freed with their nodes) */ |
229 xmlnode_free(message_node); | 215 xmlnode_free(message_node); |
230 g_free(body); | 216 g_free(body); |
231 g_free(html_body); | 217 g_free(html_body); |
232 } | 218 } |
233 | 219 |
255 GString *data = g_string_new(""); | 241 GString *data = g_string_new(""); |
256 char parcial_data[512]; | 242 char parcial_data[512]; |
257 gint total_message_length = 0; | 243 gint total_message_length = 0; |
258 gint parcial_message_length = 0; | 244 gint parcial_message_length = 0; |
259 | 245 |
260 // Read chunks of 512 bytes till the end of the data | 246 /* Read chunks of 512 bytes till the end of the data */ |
261 while ((parcial_message_length = recv(socket, parcial_data, 512, 0)) > 0) | 247 while ((parcial_message_length = recv(socket, parcial_data, 512, 0)) > 0) |
262 { | 248 { |
263 g_string_append_len(data, parcial_data, parcial_message_length); | 249 g_string_append_len(data, parcial_data, parcial_message_length); |
264 total_message_length += parcial_message_length; | 250 total_message_length += parcial_message_length; |
265 } | 251 } |
310 GaimConversation *conversation; | 296 GaimConversation *conversation; |
311 char *closed_conv_message; | 297 char *closed_conv_message; |
312 BonjourBuddy *bb = (BonjourBuddy*)gb->proto_data; | 298 BonjourBuddy *bb = (BonjourBuddy*)gb->proto_data; |
313 gboolean closed_conversation = FALSE; | 299 gboolean closed_conversation = FALSE; |
314 | 300 |
315 // Read the data from the socket | 301 /* Read the data from the socket */ |
316 if ((message_length = _read_data(socket, &message)) == -1) { | 302 if ((message_length = _read_data(socket, &message)) == -1) { |
317 // There have been an error reading from the socket | 303 /* There have been an error reading from the socket */ |
318 return; | 304 return; |
319 } else if (message_length == 0) { // The other end has closed the socket | 305 } else if (message_length == 0) { /* The other end has closed the socket */ |
320 closed_conversation = TRUE; | 306 closed_conversation = TRUE; |
321 } else { | 307 } else { |
322 message[message_length] = '\0'; | 308 message[message_length] = '\0'; |
323 | 309 |
324 while (g_ascii_iscntrl(message[message_length - 1])) { | 310 while (g_ascii_iscntrl(message[message_length - 1])) { |
325 message[message_length - 1] = '\0'; | 311 message[message_length - 1] = '\0'; |
326 message_length--; | 312 message_length--; |
327 } | 313 } |
328 } | 314 } |
329 | 315 |
330 // Check if the start of the doctype has been received, if not check that the current | 316 /* Check if the start of the doctype has been received, if not check that the current */ |
331 // data is the doctype | 317 /* data is the doctype */ |
332 if (!(bb->conversation->start_step_one)) | 318 if (!(bb->conversation->start_step_one)) |
333 { | 319 { |
334 if (g_str_has_prefix(message, DOCTYPE_DECLARATION)) | 320 if (g_str_has_prefix(message, DOCTYPE_DECLARATION)) |
335 { | 321 { |
336 bb->conversation->start_step_one = TRUE; | 322 bb->conversation->start_step_one = TRUE; |
337 } | 323 } |
338 } | 324 } |
339 | 325 |
340 // Check if the start of the stream has been received, if not check that the current | 326 /* Check if the start of the stream has been received, if not check that the current */ |
341 // data is the start of the stream | 327 /* data is the start of the stream */ |
342 if (!(bb->conversation->start_step_two)) | 328 if (!(bb->conversation->start_step_two)) |
343 { | 329 { |
344 if (g_str_has_suffix(message, STREAM_START)) { | 330 if (g_str_has_suffix(message, STREAM_START)) { |
345 bb->conversation->start_step_two = TRUE; | 331 bb->conversation->start_step_two = TRUE; |
346 | 332 |
347 // If we haven't done it yet, we have to sent the start of the stream to the other buddy | 333 /* If we haven't done it yet, we have to sent the start of the stream to the other buddy */ |
348 if (!(bb->conversation->stream_started)) { | 334 if (!(bb->conversation->stream_started)) { |
349 if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1) { | 335 if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1) { |
350 gaim_debug_error("bonjour", "Unable to start a conversation with %s\n", bb->name); | 336 gaim_debug_error("bonjour", "Unable to start a conversation with %s\n", bb->name); |
351 } | 337 } |
352 } | 338 } |
353 } | 339 } |
354 return; | 340 return; |
355 } | 341 } |
356 | 342 |
357 // Check that this is not the end of the conversation | 343 /* Check that this is not the end of the conversation */ |
358 if (g_str_has_prefix(message, STREAM_END) || (closed_conversation == TRUE)) { | 344 if (g_str_has_prefix(message, STREAM_END) || (closed_conversation == TRUE)) { |
359 // Close the socket, clear the watcher and free memory | 345 /* Close the socket, clear the watcher and free memory */ |
360 if (bb->conversation != NULL) { | 346 if (bb->conversation != NULL) { |
361 close(bb->conversation->socket); | 347 close(bb->conversation->socket); |
362 gaim_input_remove(bb->conversation->watcher_id); | 348 gaim_input_remove(bb->conversation->watcher_id); |
363 g_free(bb->conversation->buddy_name); | 349 g_free(bb->conversation->buddy_name); |
364 g_free(bb->conversation); | 350 g_free(bb->conversation); |
365 bb->conversation = NULL; | 351 bb->conversation = NULL; |
366 } | 352 } |
367 | 353 |
368 // Inform the user that the conversation has been closed | 354 /* Inform the user that the conversation has been closed */ |
369 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, gb->name, account); | 355 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, gb->name, account); |
370 closed_conv_message = g_strconcat(gb->name, " has closed the conversation.", NULL); | 356 closed_conv_message = g_strconcat(gb->name, " has closed the conversation.", NULL); |
371 gaim_conversation_write(conversation, NULL, closed_conv_message, GAIM_MESSAGE_SYSTEM, time(NULL)); | 357 gaim_conversation_write(conversation, NULL, closed_conv_message, GAIM_MESSAGE_SYSTEM, time(NULL)); |
372 } else { | 358 } else { |
373 // Parse the message to get the data and send to the ui | 359 /* Parse the message to get the data and send to the ui */ |
374 _jabber_parse_and_write_message_to_ui(message, account->gc, gb); | 360 _jabber_parse_and_write_message_to_ui(message, account->gc, gb); |
375 } | 361 } |
376 } | 362 } |
377 | 363 |
378 void | 364 void |
379 _server_socket_handler(gpointer data, int server_socket, GaimInputCondition condition) | 365 _server_socket_handler(gpointer data, int server_socket, GaimInputCondition condition) |
380 { | 366 { |
381 GaimBuddy *gb = NULL; | 367 GaimBuddy *gb = NULL; |
382 struct sockaddr_in their_addr; // connector's address information | 368 struct sockaddr_in their_addr; /* connector's address information */ |
383 socklen_t sin_size = sizeof(struct sockaddr); | 369 socklen_t sin_size = sizeof(struct sockaddr); |
384 int client_socket; | 370 int client_socket; |
385 BonjourBuddy *bb = NULL; | 371 BonjourBuddy *bb = NULL; |
386 char *address_text = NULL; | 372 char *address_text = NULL; |
387 GaimBuddyList *bl = gaim_get_blist(); | 373 GaimBuddyList *bl = gaim_get_blist(); |
388 | 374 |
389 //Check that it is a read condition | 375 /* Check that it is a read condition */ |
390 if (condition != GAIM_INPUT_READ) { | 376 if (condition != GAIM_INPUT_READ) { |
391 return; | 377 return; |
392 } | 378 } |
393 | 379 |
394 if ((client_socket = accept(server_socket, (struct sockaddr *)&their_addr, &sin_size)) == -1) | 380 if ((client_socket = accept(server_socket, (struct sockaddr *)&their_addr, &sin_size)) == -1) |
395 { | 381 { |
396 return; | 382 return; |
397 } | 383 } |
398 fcntl(client_socket, F_SETFL, O_NONBLOCK); | 384 fcntl(client_socket, F_SETFL, O_NONBLOCK); |
399 | 385 |
400 // Look for the buddy that has open the conversation and fill information | 386 /* Look for the buddy that has open the conversation and fill information */ |
401 address_text = inet_ntoa(their_addr.sin_addr); | 387 address_text = inet_ntoa(their_addr.sin_addr); |
402 gb = (GaimBuddy*)g_hash_table_find(bl->buddies, _check_buddy_by_address, address_text); | 388 gb = (GaimBuddy*)g_hash_table_find(bl->buddies, _check_buddy_by_address, address_text); |
403 if (gb == NULL) | 389 if (gb == NULL) |
404 { | 390 { |
405 gaim_debug_info("bonjour", "We don't like invisible buddies, this is not a superheros comic\n"); | 391 gaim_debug_info("bonjour", "We don't like invisible buddies, this is not a superheros comic\n"); |
406 close(client_socket); | 392 close(client_socket); |
407 return; | 393 return; |
408 } | 394 } |
409 bb = (BonjourBuddy*)gb->proto_data; | 395 bb = (BonjourBuddy*)gb->proto_data; |
410 | 396 |
411 // Check if the conversation has been previously started | 397 /* Check if the conversation has been previously started */ |
412 if (bb->conversation == NULL) | 398 if (bb->conversation == NULL) |
413 { | 399 { |
414 bb->conversation = g_new(BonjourJabberConversation, 1); | 400 bb->conversation = g_new(BonjourJabberConversation, 1); |
415 bb->conversation->socket = client_socket; | 401 bb->conversation->socket = client_socket; |
416 bb->conversation->start_step_one = FALSE; | 402 bb->conversation->start_step_one = FALSE; |
418 bb->conversation->stream_started = FALSE; | 404 bb->conversation->stream_started = FALSE; |
419 bb->conversation->buddy_name = g_strdup(gb->name); | 405 bb->conversation->buddy_name = g_strdup(gb->name); |
420 bb->conversation->message_id = 1; | 406 bb->conversation->message_id = 1; |
421 | 407 |
422 if (bb->conversation->stream_started == FALSE) { | 408 if (bb->conversation->stream_started == FALSE) { |
423 // Start the stream | 409 /* Start the stream */ |
424 send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0); | 410 send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0); |
425 bb->conversation->stream_started = TRUE; | 411 bb->conversation->stream_started = TRUE; |
426 } | 412 } |
427 | 413 |
428 // Open a watcher for the client socket | 414 /* Open a watcher for the client socket */ |
429 bb->conversation->watcher_id = gaim_input_add(client_socket, GAIM_INPUT_READ, | 415 bb->conversation->watcher_id = gaim_input_add(client_socket, GAIM_INPUT_READ, |
430 _client_socket_handler, gb); | 416 _client_socket_handler, gb); |
431 } else { | 417 } else { |
432 close(client_socket); | 418 close(client_socket); |
433 } | 419 } |
438 { | 424 { |
439 struct sockaddr_in my_addr; | 425 struct sockaddr_in my_addr; |
440 int yes = 1; | 426 int yes = 1; |
441 char *error_message = NULL; | 427 char *error_message = NULL; |
442 | 428 |
443 // Open a listening socket for incoming conversations | 429 /* Open a listening socket for incoming conversations */ |
444 if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) | 430 if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) |
445 { | 431 { |
446 gaim_debug_error("bonjour", "Cannot get socket\n"); | 432 gaim_debug_error("bonjour", "Cannot get socket\n"); |
447 error_message = strerror(errno); | 433 error_message = strerror(errno); |
448 gaim_debug_error("bonjour", "%s\n", error_message); | 434 gaim_debug_error("bonjour", "%s\n", error_message); |
449 gaim_connection_error(data->account->gc, "Cannot open socket"); | 435 gaim_connection_error(data->account->gc, "Cannot open socket"); |
450 return -1; | 436 return -1; |
451 } | 437 } |
452 | 438 |
453 // Make the socket reusable | 439 /* Make the socket reusable */ |
454 if (setsockopt(data->socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0) | 440 if (setsockopt(data->socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0) |
455 { | 441 { |
456 gaim_debug_error("bonjour", "Cannot make socket reusable\n"); | 442 gaim_debug_error("bonjour", "Cannot make socket reusable\n"); |
457 error_message = strerror(errno); | 443 error_message = strerror(errno); |
458 gaim_debug_error("bonjour", "%s\n", error_message); | 444 gaim_debug_error("bonjour", "%s\n", error_message); |
480 gaim_debug_error("bonjour", "%s\n", error_message); | 466 gaim_debug_error("bonjour", "%s\n", error_message); |
481 gaim_connection_error(data->account->gc, "Cannot listen to socket"); | 467 gaim_connection_error(data->account->gc, "Cannot listen to socket"); |
482 return -1; | 468 return -1; |
483 } | 469 } |
484 | 470 |
485 //data->socket = gaim_network_listen(data->port); | 471 #if 0 |
486 | 472 data->socket = gaim_network_listen(data->port); |
487 //if (data->socket == -1) | 473 |
488 //{ | 474 if (data->socket == -1) |
489 // gaim_debug_error("bonjour", "No se ha podido crear el socket\n"); | 475 { |
490 //} | 476 gaim_debug_error("bonjour", "No se ha podido crear el socket\n"); |
491 | 477 } |
492 // Open a watcher in the socket we have just opened | 478 #endif |
479 | |
480 /* Open a watcher in the socket we have just opened */ | |
493 data->watcher_id = gaim_input_add(data->socket, GAIM_INPUT_READ, _server_socket_handler, data); | 481 data->watcher_id = gaim_input_add(data->socket, GAIM_INPUT_READ, _server_socket_handler, data); |
494 | 482 |
495 return 0; | 483 return 0; |
496 } | 484 } |
497 | 485 |
518 /* You can not send a message to an offline buddy */ | 506 /* You can not send a message to an offline buddy */ |
519 return -10000; | 507 return -10000; |
520 | 508 |
521 bb = (BonjourBuddy *)gb->proto_data; | 509 bb = (BonjourBuddy *)gb->proto_data; |
522 | 510 |
523 // Enclose the message from the UI within a "font" node | 511 /* Enclose the message from the UI within a "font" node */ |
524 message_body_node = xmlnode_new("body"); | 512 message_body_node = xmlnode_new("body"); |
525 stripped_message = gaim_markup_strip_html(body); | 513 stripped_message = gaim_markup_strip_html(body); |
526 xmlnode_insert_data(message_body_node, stripped_message, strlen(stripped_message)); | 514 xmlnode_insert_data(message_body_node, stripped_message, strlen(stripped_message)); |
527 | 515 |
528 message_from_ui = g_strconcat("<font>", body, "</font>", NULL); | 516 message_from_ui = g_strconcat("<font>", body, "</font>", NULL); |
546 xmlnode_insert_child(message_node, message_html_node); | 534 xmlnode_insert_child(message_node, message_html_node); |
547 xmlnode_insert_child(message_node, message_x_node); | 535 xmlnode_insert_child(message_node, message_x_node); |
548 | 536 |
549 message = xmlnode_to_str(message_node, &message_length); | 537 message = xmlnode_to_str(message_node, &message_length); |
550 | 538 |
551 // Check if there is a previously open conversation | 539 /* Check if there is a previously open conversation */ |
552 if (bb->conversation == NULL) | 540 if (bb->conversation == NULL) |
553 { | 541 { |
554 bb->conversation = g_new(BonjourJabberConversation, 1); | 542 bb->conversation = g_new(BonjourJabberConversation, 1); |
555 bb->conversation->socket = _connect_to_buddy(gb);; | 543 bb->conversation->socket = _connect_to_buddy(gb);; |
556 bb->conversation->start_step_one = FALSE; | 544 bb->conversation->start_step_one = FALSE; |
559 bb->conversation->buddy_name = g_strdup(gb->name); | 547 bb->conversation->buddy_name = g_strdup(gb->name); |
560 bb->conversation->watcher_id = gaim_input_add(bb->conversation->socket, | 548 bb->conversation->watcher_id = gaim_input_add(bb->conversation->socket, |
561 GAIM_INPUT_READ, _client_socket_handler, gb); | 549 GAIM_INPUT_READ, _client_socket_handler, gb); |
562 } | 550 } |
563 | 551 |
564 // Check if the stream for the conversation has been started | 552 /* Check if the stream for the conversation has been started */ |
565 if (bb->conversation->stream_started == FALSE) | 553 if (bb->conversation->stream_started == FALSE) |
566 { | 554 { |
567 // Start the stream | 555 /* Start the stream */ |
568 if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1) | 556 if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1) |
569 { | 557 { |
570 gaim_debug_error("bonjour", "Unable to start a conversation\n"); | 558 gaim_debug_error("bonjour", "Unable to start a conversation\n"); |
571 gaim_debug_warning("bonjour", "send error: %s\n", strerror(errno)); | 559 gaim_debug_warning("bonjour", "send error: %s\n", strerror(errno)); |
572 conv_message = g_strdup("Unable to send the message, the conversation couldn't be started."); | 560 conv_message = g_strdup("Unable to send the message, the conversation couldn't be started."); |
573 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, bb->name, data->account); | 561 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, bb->name, data->account); |
574 gaim_conversation_write(conversation, NULL, conv_message, GAIM_MESSAGE_SYSTEM, time(NULL)); | 562 gaim_conversation_write(conversation, NULL, conv_message, GAIM_MESSAGE_SYSTEM, time(NULL)); |
575 close(bb->conversation->socket); | 563 close(bb->conversation->socket); |
576 gaim_input_remove(bb->conversation->watcher_id); | 564 gaim_input_remove(bb->conversation->watcher_id); |
577 | 565 |
578 // Free all the data related to the conversation | 566 /* Free all the data related to the conversation */ |
579 g_free(bb->conversation->buddy_name); | 567 g_free(bb->conversation->buddy_name); |
580 g_free(bb->conversation); | 568 g_free(bb->conversation); |
581 bb->conversation = NULL; | 569 bb->conversation = NULL; |
582 return 0; | 570 return 0; |
583 } | 571 } |
584 | 572 |
585 bb->conversation->stream_started = TRUE; | 573 bb->conversation->stream_started = TRUE; |
586 } | 574 } |
587 | 575 |
588 // Send the message | 576 /* Send the message */ |
589 if (_send_data(bb->conversation->socket, message) == -1) | 577 if (_send_data(bb->conversation->socket, message) == -1) |
590 return -10000; | 578 return -10000; |
591 | 579 |
592 return 1; | 580 return 1; |
593 } | 581 } |
597 { | 585 { |
598 BonjourBuddy *bb = (BonjourBuddy*)gb->proto_data; | 586 BonjourBuddy *bb = (BonjourBuddy*)gb->proto_data; |
599 | 587 |
600 if (bb->conversation != NULL) | 588 if (bb->conversation != NULL) |
601 { | 589 { |
602 // Send the end of the stream to the other end of the conversation | 590 /* Send the end of the stream to the other end of the conversation */ |
603 send(bb->conversation->socket, STREAM_END, strlen(STREAM_END), 0); | 591 send(bb->conversation->socket, STREAM_END, strlen(STREAM_END), 0); |
604 | 592 |
605 // Close the socket and remove the watcher | 593 /* Close the socket and remove the watcher */ |
606 close(bb->conversation->socket); | 594 close(bb->conversation->socket); |
607 gaim_input_remove(bb->conversation->watcher_id); | 595 gaim_input_remove(bb->conversation->watcher_id); |
608 | 596 |
609 // Free all the data related to the conversation | 597 /* Free all the data related to the conversation */ |
610 g_free(bb->conversation->buddy_name); | 598 g_free(bb->conversation->buddy_name); |
611 g_free(bb->conversation); | 599 g_free(bb->conversation); |
612 bb->conversation = NULL; | 600 bb->conversation = NULL; |
613 } | 601 } |
614 } | 602 } |
619 GaimBuddy *gb = NULL; | 607 GaimBuddy *gb = NULL; |
620 BonjourBuddy *bb = NULL; | 608 BonjourBuddy *bb = NULL; |
621 GSList *buddies; | 609 GSList *buddies; |
622 GSList *l; | 610 GSList *l; |
623 | 611 |
624 // Close the server socket and remove all the watcher | 612 /* Close the server socket and remove all the watcher */ |
625 close(data->socket); | 613 close(data->socket); |
626 gaim_input_remove(data->watcher_id); | 614 gaim_input_remove(data->watcher_id); |
627 | 615 |
628 // Close all the sockets and remove all the watchers after sending end streams | 616 /* Close all the sockets and remove all the watchers after sending end streams */ |
629 if (data->account->gc != NULL) | 617 if (data->account->gc != NULL) |
630 { | 618 { |
631 buddies = gaim_find_buddies(data->account, data->account->username); | 619 buddies = gaim_find_buddies(data->account, data->account->username); |
632 for (l = buddies; l; l = l->next) | 620 for (l = buddies; l; l = l->next) |
633 { | 621 { |