annotate src/protocols/bonjour/jabber.c @ 11693:b91a84e7cbcb

[gaim-migrate @ 13979] Don't crash on bonjour when IMing a non-existant user. Also better error reporting, I think. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 18 Oct 2005 04:16:44 +0000
parents 1fd2a974379f
children 27ed05facc71
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 /*
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 * gaim - Bonjour Protocol Plugin
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 *
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6 * source distribution.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
7 *
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 * (at your option) any later version.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12 *
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16 * GNU General Public License for more details.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 *
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 */
11688
1fd2a974379f [gaim-migrate @ 13974]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11539
diff changeset
22 #ifndef _WIN32
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23 #include <sys/socket.h>
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
24 #include <netinet/in.h>
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
25 #include <arpa/inet.h>
11688
1fd2a974379f [gaim-migrate @ 13974]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11539
diff changeset
26 #else
1fd2a974379f [gaim-migrate @ 13974]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11539
diff changeset
27 #include "libc_interface.h"
1fd2a974379f [gaim-migrate @ 13974]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11539
diff changeset
28 #endif
1fd2a974379f [gaim-migrate @ 13974]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11539
diff changeset
29 #include <sys/types.h>
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
30 #include <glib.h>
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 #include <glib/gprintf.h>
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
32 #include <unistd.h>
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33 #include <fcntl.h>
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
34
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35 #include "network.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
36 #include "eventloop.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
37 #include "connection.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
38 #include "blist.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
39 #include "xmlnode.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
40 #include "debug.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
41 #include "notify.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42 #include "util.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
43
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44 #include "jabber.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
45 #include "bonjour.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
46 #include "buddy.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
47
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
48 gint
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
49 _connect_to_buddy(GaimBuddy *gb)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
50 {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
51 gint socket_fd;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
52 gint retorno = 0;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
53 struct sockaddr_in buddy_address;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
54
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55 // Create a socket and make it non-blocking
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56 socket_fd = socket(PF_INET, SOCK_STREAM, 0);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
57
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58 buddy_address.sin_family = PF_INET;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 buddy_address.sin_port = htons(((BonjourBuddy*)(gb->proto_data))->port_p2pj);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60 inet_aton(((BonjourBuddy*)(gb->proto_data))->ip, &(buddy_address.sin_addr));
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61 memset(&(buddy_address.sin_zero), '\0', 8);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
62
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63 retorno = connect(socket_fd, (struct sockaddr*)&buddy_address, sizeof(struct sockaddr));
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64 if (retorno == -1) {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
65 perror("connect");
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 fcntl(socket_fd, F_SETFL, O_NONBLOCK);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
69 return socket_fd;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
70 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
71
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
72 char *
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
73 _font_size_gaim_to_ichat(int size)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
74 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
75 GString *result = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
76
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
77 switch(size) {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
78 case 1 :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79 result = g_string_new("8");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
81 case 2 :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
82 result = g_string_new("10");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
83 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
84 case 3 :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
85 result = g_string_new("12");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
87 case 4 :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
88 result = g_string_new("14");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
90 case 5 :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91 result = g_string_new("17");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
92 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93 case 6 :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94 result = g_string_new("21");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 case 7 :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 result = g_string_new("24");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
98 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 default:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100 result = g_string_new("12");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
102
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
103 return g_string_free(result, FALSE);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
104 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
106 char *
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
107 _font_size_ichat_to_gaim(int size)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
109 GString *result = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
110
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 if (size > 24) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112 result = g_string_new("7");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
113 } else if (size >= 21) {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
114 result = g_string_new("6");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
115 } else if (size >= 17) {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116 result = g_string_new("5");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
117 } else if (size >= 14) {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
118 result = g_string_new("4");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
119 } else if (size >= 12) {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
120 result = g_string_new("3");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
121 } else if (size >= 10) {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122 result = g_string_new("2");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
123 } else {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
124 result = g_string_new("1");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
125 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
126
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
127 return g_string_free(result, FALSE);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
128 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
129 void
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
130 _jabber_parse_and_write_message_to_ui(char *message, GaimConnection *connection, GaimBuddy *gb)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
131 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
132 xmlnode *body_node = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
133 char *body = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
134 xmlnode *html_node = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
135 gboolean isHTML = FALSE;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
136 xmlnode *html_body_node = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
137 const char *ichat_balloon_color = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
138 const char *ichat_text_color = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
139 xmlnode *html_body_font_node = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
140 const char *font_face = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
141 const char *font_size = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
142 const char *font_color = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
143 char *html_body = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
144 xmlnode *events_node = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
145 gboolean composing_event = FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
146 gint garbage = -1;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
147 xmlnode *message_node = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
148
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
149 // Parsing of the message
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
150 message_node = xmlnode_from_str(message, strlen(message));
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
151 if (message_node == NULL) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
152 return;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
153 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
154
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
155 body_node = xmlnode_get_child(message_node, "body");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
156 if (body_node != NULL) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
157 body = xmlnode_get_data(body_node);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
158 } else {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
159 return;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
160 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
161
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
162 html_node = xmlnode_get_child(message_node, "html");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
163 if (html_node != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
164 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
165 isHTML = TRUE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
166 html_body_node = xmlnode_get_child(html_node, "body");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
167 if (html_body_node != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
168 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
169 ichat_balloon_color = xmlnode_get_attrib(html_body_node, "ichatballooncolor");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
170 ichat_text_color = xmlnode_get_attrib(html_body_node, "ichattextcolor");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
171 html_body_font_node = xmlnode_get_child(html_body_node, "font");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
172 if (html_body_font_node != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
173 { // Types of messages sent by iChat
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
174 font_face = xmlnode_get_attrib(html_body_font_node, "face");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
175 // The absolute iChat font sizes should be converted to 1..7 range
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
176 font_size = xmlnode_get_attrib(html_body_font_node, "ABSZ");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
177 if (font_size != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
178 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
179 font_size = _font_size_ichat_to_gaim(atoi(font_size)); //<-- This call will probably leak memory
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
180 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
181 font_color = xmlnode_get_attrib(html_body_font_node, "color");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
182 html_body = xmlnode_get_data(html_body_font_node);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
183 if (html_body == NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
184 {
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
185 // This is the kind of formated messages that Gaim creates
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
186 html_body = xmlnode_to_str(html_body_font_node, &garbage);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
187 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
188 } else {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
189 isHTML = FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
190 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
191 } else {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
192 isHTML = FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
193 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
194
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
195 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
196
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
197 events_node = xmlnode_get_child_with_namespace(message_node, "x", "jabber:x:event");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
198 if (events_node != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
199 {
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
200 if (xmlnode_get_child(events_node, "composing") != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
201 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
202 composing_event = TRUE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
203 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
204 if (xmlnode_get_child(events_node, "id") != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
205 {
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
206 // The user is just typing
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
207 xmlnode_free(message_node);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
208 g_free(body);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
209 g_free(html_body);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
210 return;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
211 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
212 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
213
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
214 // Compose the message
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
215 if (isHTML)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
216 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
217 if (font_face == NULL) font_face = "Helvetica";
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
218 if (font_size == NULL) font_size = "3";
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
219 if (ichat_text_color == NULL) ichat_text_color = "#000000";
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
220 if (ichat_balloon_color == NULL) ichat_balloon_color = "#FFFFFF";
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
221 body = g_strconcat("<font face='", font_face, "' size='", font_size, "' color='", ichat_text_color,
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
222 "' back='", ichat_balloon_color, "'>", html_body, "</font>", NULL);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
223 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
224
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
225 // Send the message to the UI
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
226 serv_got_im(connection, gb->name, body, 0, time(NULL));
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
227
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
228 // Free all the strings and nodes (the attributes are freed with their nodes)
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
229 xmlnode_free(message_node);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
230 g_free(body);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
231 g_free(html_body);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
232 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
233
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
234 gboolean
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
235 _check_buddy_by_address(gpointer key, gpointer value, gpointer address)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
236 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
237 GaimBuddy *gb = (GaimBuddy*)value;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
238 BonjourBuddy *bb = (BonjourBuddy*)gb->proto_data;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
239
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
240 if (bb != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
241 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
242 if (g_strcasecmp(bb->ip, (char*)address) == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
243 return TRUE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
244 } else {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
245 return FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
246 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
247 } else {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
248 return FALSE;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
249 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
250 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
251
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
252 gint
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
253 _read_data(gint socket, char **message)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
254 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
255 GString *data = g_string_new("");
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
256 char parcial_data[512];
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
257 gint total_message_length = 0;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
258 gint parcial_message_length = 0;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
259
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
260 // Read chunks of 512 bytes till the end of the data
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
261 while ((parcial_message_length = recv(socket, parcial_data, 512, 0)) > 0)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
262 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
263 g_string_append_len(data, parcial_data, parcial_message_length);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
264 total_message_length += parcial_message_length;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
265 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
266
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
267 if (parcial_message_length == -1)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
268 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
269 perror("recv");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
270 if (total_message_length == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
271 return -1;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
272 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
273 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
274
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
275 *message = data->str;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
276 g_string_free(data, FALSE);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
277 if (total_message_length != 0)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
278 gaim_debug_info("bonjour", "Receive: -%s- %d bytes\n", *message, total_message_length);
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
279
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
280 return total_message_length;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
281 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
282
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
283 gint
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
284 _send_data(gint socket, char *message)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
285 {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
286 gint message_len = strlen(message);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
287 gint parcial_sent = 0;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
288 gchar *parcial_message = message;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
289
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
290 while ((parcial_sent = send(socket, parcial_message, message_len, 0)) < message_len)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
291 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
292 if (parcial_sent != -1) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
293 parcial_message += parcial_sent;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
294 message_len -= parcial_sent;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
295 } else {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
296 return -1;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
297 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
298 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
299
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
300 return strlen(message);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
301 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
302
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
303 void
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
304 _client_socket_handler(gpointer data, gint socket, GaimInputCondition condition)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
305 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
306 char *message = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
307 gint message_length;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
308 GaimBuddy *gb = (GaimBuddy*)data;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
309 GaimAccount *account = gb->account;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
310 GaimConversation *conversation;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
311 char *closed_conv_message;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
312 BonjourBuddy *bb = (BonjourBuddy*)gb->proto_data;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
313 gboolean closed_conversation = FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
314
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
315 // Read the data from the socket
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
316 if ((message_length = _read_data(socket, &message)) == -1) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
317 // There have been an error reading from the socket
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
318 return;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
319 } else if (message_length == 0) { // The other end has closed the socket
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
320 closed_conversation = TRUE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
321 } else {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
322 message[message_length] = '\0';
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
323
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
324 while (g_ascii_iscntrl(message[message_length - 1])) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
325 message[message_length - 1] = '\0';
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
326 message_length--;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
327 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
328 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
329
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
330 // Check if the start of the doctype has been received, if not check that the current
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
331 // data is the doctype
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
332 if (!(bb->conversation->start_step_one))
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
333 {
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
334 if (g_str_has_prefix(message, DOCTYPE_DECLARATION))
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
335 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
336 bb->conversation->start_step_one = TRUE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
337 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
338 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
339
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
340 // Check if the start of the stream has been received, if not check that the current
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
341 // data is the start of the stream
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
342 if (!(bb->conversation->start_step_two))
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
343 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
344 if (g_str_has_suffix(message, STREAM_START)) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
345 bb->conversation->start_step_two = TRUE;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
346
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
347 // If we haven't done it yet, we have to sent the start of the stream to the other buddy
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
348 if (!(bb->conversation->stream_started)) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
349 if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
350 gaim_debug_error("bonjour", "Unable to start a conversation with %s\n", bb->name);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
351 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
352 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
353 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
354 return;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
355 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
356
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
357 // Check that this is not the end of the conversation
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
358 if (g_str_has_prefix(message, STREAM_END) || (closed_conversation == TRUE)) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
359 // Close the socket, clear the watcher and free memory
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
360 if (bb->conversation != NULL) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
361 close(bb->conversation->socket);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
362 gaim_input_remove(bb->conversation->watcher_id);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
363 g_free(bb->conversation->buddy_name);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
364 g_free(bb->conversation);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
365 bb->conversation = NULL;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
366 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
367
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
368 // Inform the user that the conversation has been closed
11498
ea52fefd3602 [gaim-migrate @ 13743]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
369 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, gb->name, account);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
370 closed_conv_message = g_strconcat(gb->name, " has closed the conversation.", NULL);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
371 gaim_conversation_write(conversation, NULL, closed_conv_message, GAIM_MESSAGE_SYSTEM, time(NULL));
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
372 } else {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
373 // Parse the message to get the data and send to the ui
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
374 _jabber_parse_and_write_message_to_ui(message, account->gc, gb);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
375 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
376 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
377
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
378 void
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
379 _server_socket_handler(gpointer data, int server_socket, GaimInputCondition condition)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
380 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
381 GaimBuddy *gb = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
382 struct sockaddr_in their_addr; // connector's address information
11515
f8a447af7494 [gaim-migrate @ 13760]
Mark Doliner <mark@kingant.net>
parents: 11498
diff changeset
383 socklen_t sin_size = sizeof(struct sockaddr);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
384 int client_socket;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
385 BonjourBuddy *bb = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
386 char *address_text = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
387 GaimBuddyList *bl = gaim_get_blist();
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
388
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
389 //Check that it is a read condition
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
390 if (condition != GAIM_INPUT_READ) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
391 return;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
392 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
393
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
394 if ((client_socket = accept(server_socket, (struct sockaddr *)&their_addr, &sin_size)) == -1)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
395 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
396 return;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
397 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
398 fcntl(client_socket, F_SETFL, O_NONBLOCK);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
399
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
400 // Look for the buddy that has open the conversation and fill information
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
401 address_text = inet_ntoa(their_addr.sin_addr);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
402 gb = (GaimBuddy*)g_hash_table_find(bl->buddies, _check_buddy_by_address, address_text);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
403 if (gb == NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
404 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
405 gaim_debug_info("bonjour", "We don't like invisible buddies, this is not a superheros comic\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
406 close(client_socket);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
407 return;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
408 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
409 bb = (BonjourBuddy*)gb->proto_data;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
410
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
411 // Check if the conversation has been previously started
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
412 if (bb->conversation == NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
413 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
414 bb->conversation = g_new(BonjourJabberConversation, 1);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
415 bb->conversation->socket = client_socket;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
416 bb->conversation->start_step_one = FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
417 bb->conversation->start_step_two = FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
418 bb->conversation->stream_started = FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
419 bb->conversation->buddy_name = g_strdup(gb->name);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
420 bb->conversation->message_id = 1;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
421
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
422 if (bb->conversation->stream_started == FALSE) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
423 // Start the stream
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
424 send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
425 bb->conversation->stream_started = TRUE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
426 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
427
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
428 // Open a watcher for the client socket
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
429 bb->conversation->watcher_id = gaim_input_add(client_socket, GAIM_INPUT_READ,
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
430 _client_socket_handler, gb);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
431 } else {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
432 close(client_socket);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
433 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
434 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
435
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
436 gint
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
437 bonjour_jabber_start(BonjourJabber *data)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
438 {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
439 struct sockaddr_in my_addr;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
440 int yes = 1;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
441 char *error_message = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
442
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
443 // Open a listening socket for incoming conversations
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
444 if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
445 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
446 gaim_debug_error("bonjour", "Cannot get socket\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
447 error_message = strerror(errno);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
448 gaim_debug_error("bonjour", "%s\n", error_message);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
449 gaim_connection_error(data->account->gc, "Cannot open socket");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
450 return -1;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
451 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
452
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
453 // Make the socket reusable
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
454 if (setsockopt(data->socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
455 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
456 gaim_debug_error("bonjour", "Cannot make socket reusable\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
457 error_message = strerror(errno);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
458 gaim_debug_error("bonjour", "%s\n", error_message);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
459 gaim_connection_error(data->account->gc, "Error setting socket options");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
460 return -1;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
461 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
462
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
463 memset(&my_addr, 0, sizeof(struct sockaddr_in));
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
464 my_addr.sin_family = PF_INET;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
465 my_addr.sin_port = htons(data->port);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
466
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
467 if (bind(data->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
468 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
469 gaim_debug_error("bonjour", "Cannot bind socket\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
470 error_message = strerror(errno);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
471 gaim_debug_error("bonjour", "%s\n", error_message);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
472 gaim_connection_error(data->account->gc, "Cannot bind socket to port");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
473 return -1;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
474 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
475
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
476 if (listen(data->socket, 10) != 0)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
477 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
478 gaim_debug_error("bonjour", "Cannot listen to socket\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
479 error_message = strerror(errno);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
480 gaim_debug_error("bonjour", "%s\n", error_message);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
481 gaim_connection_error(data->account->gc, "Cannot listen to socket");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
482 return -1;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
483 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
484
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
485 //data->socket = gaim_network_listen(data->port);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
486
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
487 //if (data->socket == -1)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
488 //{
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
489 // gaim_debug_error("bonjour", "No se ha podido crear el socket\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
490 //}
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
491
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
492 // Open a watcher in the socket we have just opened
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
493 data->watcher_id = gaim_input_add(data->socket, GAIM_INPUT_READ, _server_socket_handler, data);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
494
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
495 return 0;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
496 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
497
11693
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
498 int
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
499 bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
500 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
501 xmlnode *message_node = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
502 gchar *message = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
503 gint message_length = -1;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
504 xmlnode *message_body_node = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
505 xmlnode *message_html_node = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
506 xmlnode *message_html_body_node = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
507 xmlnode *message_html_body_font_node = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
508 xmlnode *message_x_node = NULL;
11693
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
509 GaimBuddy *gb = NULL;
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
510 BonjourBuddy *bb = NULL;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
511 char *conv_message = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
512 GaimConversation *conversation = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
513 char *message_from_ui = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
514 char *stripped_message = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
515
11693
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
516 gb = gaim_find_buddy(data->account, to);
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
517 if (gb == NULL)
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
518 /* You can not send a message to an offline buddy */
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
519 return -10000;
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
520
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
521 bb = (BonjourBuddy *)gb->proto_data;
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
522
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
523 // Enclose the message from the UI within a "font" node
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
524 message_body_node = xmlnode_new("body");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
525 stripped_message = gaim_markup_strip_html(body);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
526 xmlnode_insert_data(message_body_node, stripped_message, strlen(stripped_message));
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
527
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
528 message_from_ui = g_strconcat("<font>", body, "</font>", NULL);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
529 message_html_body_font_node = xmlnode_from_str(message_from_ui, strlen(message_from_ui));
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
530
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
531 message_html_body_node = xmlnode_new("body");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
532 xmlnode_insert_child(message_html_body_node, message_html_body_font_node);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
533
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
534 message_html_node = xmlnode_new("html");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
535 xmlnode_set_attrib(message_html_node, "xmlns", "http://www.w3.org/1999/xhtml");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
536 xmlnode_insert_child(message_html_node, message_html_body_node);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
537
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
538 message_x_node = xmlnode_new("x");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
539 xmlnode_set_attrib(message_x_node, "xmlns", "jabber:x:event");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
540 xmlnode_insert_child(message_x_node, xmlnode_new("composing"));
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
541
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
542 message_node = xmlnode_new("message");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
543 xmlnode_set_attrib(message_node, "to", ((BonjourBuddy*)(gb->proto_data))->name);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
544 xmlnode_set_attrib(message_node, "type", "chat");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
545 xmlnode_insert_child(message_node, message_body_node);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
546 xmlnode_insert_child(message_node, message_html_node);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
547 xmlnode_insert_child(message_node, message_x_node);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
548
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
549 message = xmlnode_to_str(message_node, &message_length);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
550
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
551 // Check if there is a previously open conversation
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
552 if (bb->conversation == NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
553 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
554 bb->conversation = g_new(BonjourJabberConversation, 1);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
555 bb->conversation->socket = _connect_to_buddy(gb);;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
556 bb->conversation->start_step_one = FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
557 bb->conversation->start_step_two = FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
558 bb->conversation->stream_started = FALSE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
559 bb->conversation->buddy_name = g_strdup(gb->name);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
560 bb->conversation->watcher_id = gaim_input_add(bb->conversation->socket,
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
561 GAIM_INPUT_READ, _client_socket_handler, gb);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
562 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
563
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
564 // Check if the stream for the conversation has been started
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
565 if (bb->conversation->stream_started == FALSE)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
566 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
567 // Start the stream
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
568 if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
569 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
570 gaim_debug_error("bonjour", "Unable to start a conversation\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
571 perror("send");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
572 conv_message = g_strdup("Unable to send the message, the conversation couldn't be started.");
11498
ea52fefd3602 [gaim-migrate @ 13743]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
573 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, bb->name, data->account);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
574 gaim_conversation_write(conversation, NULL, conv_message, GAIM_MESSAGE_SYSTEM, time(NULL));
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
575 close(bb->conversation->socket);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
576 gaim_input_remove(bb->conversation->watcher_id);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
577
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
578 // Free all the data related to the conversation
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
579 g_free(bb->conversation->buddy_name);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
580 g_free(bb->conversation);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
581 bb->conversation = NULL;
11693
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
582 return 0;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
583 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
584
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
585 bb->conversation->stream_started = TRUE;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
586 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
587
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
588 // Send the message
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
589 if (_send_data(bb->conversation->socket, message) == -1)
11693
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
590 return -10000;
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
591
b91a84e7cbcb [gaim-migrate @ 13979]
Mark Doliner <mark@kingant.net>
parents: 11688
diff changeset
592 return 1;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
593 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
594
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
595 void
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
596 bonjour_jabber_close_conversation(BonjourJabber *data, GaimBuddy *gb)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
597 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
598 BonjourBuddy *bb = (BonjourBuddy*)gb->proto_data;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
599
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
600 if (bb->conversation != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
601 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
602 // Send the end of the stream to the other end of the conversation
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
603 send(bb->conversation->socket, STREAM_END, strlen(STREAM_END), 0);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
604
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
605 // Close the socket and remove the watcher
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
606 close(bb->conversation->socket);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
607 gaim_input_remove(bb->conversation->watcher_id);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
608
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
609 // Free all the data related to the conversation
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
610 g_free(bb->conversation->buddy_name);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
611 g_free(bb->conversation);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
612 bb->conversation = NULL;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
613 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
614 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
615
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
616 void
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
617 bonjour_jabber_stop(BonjourJabber *data)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
618 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
619 GaimBuddy *gb = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
620 BonjourBuddy *bb = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
621 GSList *buddies;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
622 GSList *l;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
623
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
624 // Close the server socket and remove all the watcher
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
625 close(data->socket);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
626 gaim_input_remove(data->watcher_id);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
627
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
628 // Close all the sockets and remove all the watchers after sending end streams
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
629 if (data->account->gc != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
630 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
631 buddies = gaim_find_buddies(data->account, data->account->username);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
632 for (l = buddies; l; l = l->next)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
633 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
634 gb = (GaimBuddy*)l->data;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
635 bb = (BonjourBuddy*)gb->proto_data;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
636 if (bb->conversation != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
637 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
638 send(bb->conversation->socket, STREAM_END, strlen(STREAM_END), 0);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
639 close(bb->conversation->socket);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
640 gaim_input_remove(bb->conversation->watcher_id);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
641 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
642 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
643 g_slist_free(buddies);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
644 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
645 }