Fri, 08 Jun 2007 15:28:00 +0000
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
| 11477 | 1 | /* |
| 15884 | 2 | * purple - Bonjour Protocol Plugin |
| 11477 | 3 | * |
| 15884 | 4 | * Purple is the legal property of its developers, whose names are too numerous |
| 11477 | 5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 6 | * source distribution. | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | */ | |
|
11688
d5a7c35ddc80
[gaim-migrate @ 13974]
Daniel Atallah <datallah@pidgin.im>
parents:
11539
diff
changeset
|
22 | #ifndef _WIN32 |
| 11477 | 23 | #include <sys/socket.h> |
| 24 | #include <netinet/in.h> | |
| 25 | #include <arpa/inet.h> | |
|
11688
d5a7c35ddc80
[gaim-migrate @ 13974]
Daniel Atallah <datallah@pidgin.im>
parents:
11539
diff
changeset
|
26 | #else |
|
d5a7c35ddc80
[gaim-migrate @ 13974]
Daniel Atallah <datallah@pidgin.im>
parents:
11539
diff
changeset
|
27 | #include "libc_interface.h" |
|
d5a7c35ddc80
[gaim-migrate @ 13974]
Daniel Atallah <datallah@pidgin.im>
parents:
11539
diff
changeset
|
28 | #endif |
|
d5a7c35ddc80
[gaim-migrate @ 13974]
Daniel Atallah <datallah@pidgin.im>
parents:
11539
diff
changeset
|
29 | #include <sys/types.h> |
| 11477 | 30 | #include <glib.h> |
| 31 | #include <unistd.h> | |
| 32 | #include <fcntl.h> | |
| 33 | ||
| 34 | #include "network.h" | |
| 35 | #include "eventloop.h" | |
| 36 | #include "connection.h" | |
| 37 | #include "blist.h" | |
| 38 | #include "xmlnode.h" | |
| 39 | #include "debug.h" | |
| 40 | #include "notify.h" | |
| 41 | #include "util.h" | |
| 42 | ||
| 43 | #include "jabber.h" | |
| 44 | #include "bonjour.h" | |
| 45 | #include "buddy.h" | |
| 46 | ||
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
47 | #define STREAM_END "</stream:stream>" |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
48 | /* TODO: specify version='1.0' and send stream features */ |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
49 | #define DOCTYPE "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" \ |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
50 | "<stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" from=\"%s\" to=\"%s\">" |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
51 | |
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
52 | static gint |
| 15884 | 53 | _connect_to_buddy(PurpleBuddy *gb) |
| 11477 | 54 | { |
| 55 | gint socket_fd; | |
| 56 | struct sockaddr_in buddy_address; | |
|
17596
45f6190fe54a
This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <datallah@pidgin.im>
parents:
17155
diff
changeset
|
57 | BonjourBuddy *bb = gb->proto_data; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
58 | |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
59 | purple_debug_info("bonjour", "Connecting to buddy %s at %s:%d.\n", |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
60 | purple_buddy_get_name(gb), bb->ip ? bb->ip : "(null)", bb->port_p2pj); |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
61 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
62 | /* Create a socket and make it non-blocking */ |
| 11477 | 63 | socket_fd = socket(PF_INET, SOCK_STREAM, 0); |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
64 | if (socket_fd < 0) { |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
65 | purple_debug_warning("bonjour", "Error opening socket: %s\n", strerror(errno)); |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
66 | return -1; |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
67 | } |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
68 | |
| 11477 | 69 | buddy_address.sin_family = PF_INET; |
|
17596
45f6190fe54a
This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <datallah@pidgin.im>
parents:
17155
diff
changeset
|
70 | buddy_address.sin_port = htons(bb->port_p2pj); |
|
45f6190fe54a
This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <datallah@pidgin.im>
parents:
17155
diff
changeset
|
71 | inet_aton(bb->ip, &(buddy_address.sin_addr)); |
| 11477 | 72 | memset(&(buddy_address.sin_zero), '\0', 8); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
73 | |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
74 | /* TODO: make this nonblocking before connecting */ |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
75 | if (connect(socket_fd, (struct sockaddr*)&buddy_address, sizeof(struct sockaddr)) == 0) |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
76 | fcntl(socket_fd, F_SETFL, O_NONBLOCK); |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
77 | else { |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
78 | purple_debug_warning("bonjour", "Error connecting to buddy %s at %s:%d error: %s\n", purple_buddy_get_name(gb), bb->ip ? bb->ip : "(null)", bb->port_p2pj, strerror(errno)); |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
79 | close(socket_fd); |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
80 | socket_fd = -1; |
| 11477 | 81 | } |
| 82 | ||
| 83 | return socket_fd; | |
| 84 | } | |
| 85 | ||
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
86 | #if 0 /* this isn't used anywhere... */ |
|
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
87 | static const char * |
| 15884 | 88 | _font_size_purple_to_ichat(int size) |
| 11477 | 89 | { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
90 | switch (size) { |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
91 | case 1: |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
92 | return "8"; |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
93 | case 2: |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
94 | return "10"; |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
95 | case 3: |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
96 | return "12"; |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
97 | case 4: |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
98 | return "14"; |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
99 | case 5: |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
100 | return "17"; |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
101 | case 6: |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
102 | return "21"; |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
103 | case 7: |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
104 | return "24"; |
| 11477 | 105 | } |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
106 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
107 | return "12"; |
| 11477 | 108 | } |
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
109 | #endif |
| 11477 | 110 | |
|
17662
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
111 | static BonjourJabberConversation * |
|
17663
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
112 | bonjour_jabber_conv_new() { |
|
17662
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
113 | |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
114 | BonjourJabberConversation *bconv = g_new0(BonjourJabberConversation, 1); |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
115 | bconv->socket = -1; |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
116 | bconv->watcher_id = -1; |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
117 | |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
118 | return bconv; |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
119 | } |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
120 | |
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
121 | static const char * |
| 15884 | 122 | _font_size_ichat_to_purple(int size) |
| 11477 | 123 | { |
| 124 | if (size > 24) { | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
125 | return "7"; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
126 | } else if (size >= 21) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
127 | return "6"; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
128 | } else if (size >= 17) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
129 | return "5"; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
130 | } else if (size >= 14) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
131 | return "4"; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
132 | } else if (size >= 12) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
133 | return "3"; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
134 | } else if (size >= 10) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
135 | return "2"; |
| 11477 | 136 | } |
| 137 | ||
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
138 | return "1"; |
| 11477 | 139 | } |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
140 | |
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
141 | static void |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
142 | _jabber_parse_and_write_message_to_ui(xmlnode *message_node, PurpleConnection *connection, PurpleBuddy *gb) |
| 11477 | 143 | { |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
144 | xmlnode *body_node, *html_node, *events_node; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
145 | char *body, *html_body = NULL; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
146 | const char *ichat_balloon_color = NULL; |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
147 | const char *ichat_text_color = NULL; |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
148 | const char *font_face = NULL; |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
149 | const char *font_size = NULL; |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
150 | const char *font_color = NULL; |
| 11477 | 151 | gboolean composing_event = FALSE; |
| 152 | ||
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
153 | body_node = xmlnode_get_child(message_node, "body"); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
154 | if (body_node == NULL) |
| 11477 | 155 | return; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
156 | body = xmlnode_get_data(body_node); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
157 | |
| 11477 | 158 | html_node = xmlnode_get_child(message_node, "html"); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
159 | if (html_node != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
160 | { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
161 | xmlnode *html_body_node; |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
162 | |
| 11477 | 163 | html_body_node = xmlnode_get_child(html_node, "body"); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
164 | if (html_body_node != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
165 | { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
166 | xmlnode *html_body_font_node; |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
167 | |
| 11477 | 168 | ichat_balloon_color = xmlnode_get_attrib(html_body_node, "ichatballooncolor"); |
| 169 | ichat_text_color = xmlnode_get_attrib(html_body_node, "ichattextcolor"); | |
| 170 | html_body_font_node = xmlnode_get_child(html_body_node, "font"); | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
171 | if (html_body_font_node != NULL) |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
172 | { /* Types of messages sent by iChat */ |
| 11477 | 173 | font_face = xmlnode_get_attrib(html_body_font_node, "face"); |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
174 | /* The absolute iChat font sizes should be converted to 1..7 range */ |
| 11477 | 175 | font_size = xmlnode_get_attrib(html_body_font_node, "ABSZ"); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
176 | if (font_size != NULL) |
| 15884 | 177 | font_size = _font_size_ichat_to_purple(atoi(font_size)); |
| 11477 | 178 | font_color = xmlnode_get_attrib(html_body_font_node, "color"); |
| 179 | html_body = xmlnode_get_data(html_body_font_node); | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
180 | if (html_body == NULL) |
| 15884 | 181 | /* This is the kind of formated messages that Purple creates */ |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
182 | html_body = xmlnode_to_str(html_body_font_node, NULL); |
| 11477 | 183 | } |
| 184 | } | |
| 185 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
186 | |
| 11477 | 187 | events_node = xmlnode_get_child_with_namespace(message_node, "x", "jabber:x:event"); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
188 | if (events_node != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
189 | { |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
190 | if (xmlnode_get_child(events_node, "composing") != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
191 | { |
| 11477 | 192 | composing_event = TRUE; |
| 193 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
194 | if (xmlnode_get_child(events_node, "id") != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
195 | { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
196 | /* The user is just typing */ |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
197 | /* TODO: Deal with typing notification */ |
| 11477 | 198 | g_free(body); |
| 199 | g_free(html_body); | |
| 200 | return; | |
| 201 | } | |
| 202 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
203 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
204 | /* Compose the message */ |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
205 | if (html_body != NULL) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
206 | { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
207 | g_free(body); |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
208 | |
| 11477 | 209 | if (font_face == NULL) font_face = "Helvetica"; |
| 210 | if (font_size == NULL) font_size = "3"; | |
| 211 | if (ichat_text_color == NULL) ichat_text_color = "#000000"; | |
| 212 | if (ichat_balloon_color == NULL) ichat_balloon_color = "#FFFFFF"; | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
213 | body = g_strdup_printf("<font face='%s' size='%s' color='%s' back='%s'>%s</font>", |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
214 | font_face, font_size, ichat_text_color, ichat_balloon_color, |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
215 | html_body); |
| 11477 | 216 | } |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
217 | |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
218 | /* TODO: Should we do something with "composing_event" here? */ |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
219 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
220 | /* Send the message to the UI */ |
| 11477 | 221 | serv_got_im(connection, gb->name, body, 0, time(NULL)); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
222 | |
| 11477 | 223 | g_free(body); |
| 224 | g_free(html_body); | |
| 225 | } | |
| 226 | ||
| 12708 | 227 | struct _check_buddy_by_address_t { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
228 | const char *address; |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
229 | PurpleBuddy **pb; |
| 13962 | 230 | BonjourJabber *bj; |
| 12708 | 231 | }; |
| 232 | ||
| 233 | static void | |
| 234 | _check_buddy_by_address(gpointer key, gpointer value, gpointer data) | |
| 11477 | 235 | { |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
236 | PurpleBuddy *pb = value; |
| 13962 | 237 | BonjourBuddy *bb; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
238 | struct _check_buddy_by_address_t *cbba = data; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
239 | |
| 13962 | 240 | /* |
| 15884 | 241 | * If the current PurpleBuddy's data is not null and the PurpleBuddy's account |
| 13962 | 242 | * is the same as the account requesting the check then continue to determine |
| 243 | * whether the buddies IP matches the target IP. | |
| 244 | */ | |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
245 | if (cbba->bj->account == pb->account) |
| 13962 | 246 | { |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
247 | bb = pb->proto_data; |
|
17155
143ff2796376
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
248 | if ((bb != NULL) && (g_ascii_strcasecmp(bb->ip, cbba->address) == 0)) |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
249 | *(cbba->pb) = pb; |
| 11477 | 250 | } |
| 251 | } | |
| 252 | ||
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
253 | static gint |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
254 | _read_data(gint socket, char **message) |
| 11477 | 255 | { |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
256 | GString *data = g_string_new(""); |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
257 | char partial_data[512]; |
| 11477 | 258 | gint total_message_length = 0; |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
259 | gint partial_message_length = 0; |
| 11477 | 260 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
261 | /* Read chunks of 512 bytes till the end of the data */ |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
262 | while ((partial_message_length = recv(socket, partial_data, 512, 0)) > 0) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
263 | { |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
264 | g_string_append_len(data, partial_data, partial_message_length); |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
265 | total_message_length += partial_message_length; |
| 11477 | 266 | } |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
267 | |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
268 | if (partial_message_length == -1) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
269 | { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
270 | if (errno != EAGAIN) |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
271 | purple_debug_warning("bonjour", "receive error: %s\n", strerror(errno)); |
| 11477 | 272 | if (total_message_length == 0) { |
| 273 | return -1; | |
| 274 | } | |
| 275 | } | |
| 276 | ||
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
277 | *message = g_string_free(data, FALSE); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
278 | if (total_message_length != 0) |
| 15884 | 279 | purple_debug_info("bonjour", "Receive: -%s- %d bytes\n", *message, total_message_length); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
280 | |
| 11477 | 281 | return total_message_length; |
| 282 | } | |
| 283 | ||
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
284 | static gint |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
285 | _send_data(gint socket, char *message) |
| 11477 | 286 | { |
| 287 | gint message_len = strlen(message); | |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
288 | gint partial_sent = 0; |
|
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
289 | gchar *partial_message = message; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
290 | |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
291 | while ((partial_sent = send(socket, partial_message, message_len, 0)) < message_len) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
292 | { |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
293 | if (partial_sent != -1) { |
|
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
294 | partial_message += partial_sent; |
|
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
295 | message_len -= partial_sent; |
| 11477 | 296 | } else { |
| 297 | return -1; | |
| 298 | } | |
| 299 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
300 | |
| 11477 | 301 | return strlen(message); |
| 302 | } | |
| 303 | ||
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
304 | static void |
| 15884 | 305 | _client_socket_handler(gpointer data, gint socket, PurpleInputCondition condition) |
| 11477 | 306 | { |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
307 | char *message = NULL; |
| 11477 | 308 | gint message_length; |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
309 | PurpleBuddy *pb = data; |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
310 | PurpleAccount *account = pb->account; |
| 15884 | 311 | PurpleConversation *conversation; |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
312 | BonjourBuddy *bb = pb->proto_data; |
| 11477 | 313 | gboolean closed_conversation = FALSE; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
314 | xmlnode *message_node; |
| 11477 | 315 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
316 | /* Read the data from the socket */ |
| 11477 | 317 | if ((message_length = _read_data(socket, &message)) == -1) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
318 | /* There have been an error reading from the socket */ |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
319 | /* TODO: Shouldn't we handle the error if it isn't EAGAIN? */ |
| 11477 | 320 | return; |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
321 | } else if (message_length == 0) { /* The other end has closed the socket */ |
| 11477 | 322 | closed_conversation = TRUE; |
| 323 | } else { | |
| 324 | message[message_length] = '\0'; | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
325 | |
| 11477 | 326 | while (g_ascii_iscntrl(message[message_length - 1])) { |
| 327 | message[message_length - 1] = '\0'; | |
| 328 | message_length--; | |
| 329 | } | |
| 330 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
331 | |
| 13964 | 332 | /* Parse the message into an XMLnode for analysis */ |
| 333 | message_node = xmlnode_from_str(message, strlen(message)); | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
334 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
335 | /* Check if the start of the stream has been received, if not check that the current */ |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
336 | /* data is the start of the stream */ |
| 13964 | 337 | if (!(bb->conversation->stream_started)) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
338 | { |
| 13964 | 339 | /* Check if this is the start of the stream */ |
| 340 | if ((message_node != NULL) && | |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
341 | g_ascii_strcasecmp(xmlnode_get_attrib(message_node, "xmlns"), "jabber:client") && |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
342 | (xmlnode_get_attrib(message_node,"xmlns:stream") != NULL)) |
| 13964 | 343 | { |
| 344 | bb->conversation->stream_started = TRUE; | |
| 345 | } | |
| 346 | else | |
| 347 | { | |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
348 | char *stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account), |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
349 | purple_buddy_get_name(pb)); |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
350 | |
| 13964 | 351 | /* TODO: This needs to be nonblocking! */ |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
352 | if (send(bb->conversation->socket, stream_start, strlen(stream_start), 0) == -1) |
| 15884 | 353 | purple_debug_error("bonjour", "Unable to start a conversation with %s\n", bb->name); |
| 13964 | 354 | else |
| 355 | bb->conversation->stream_started = TRUE; | |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
356 | |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
357 | g_free(stream_start); |
| 11477 | 358 | } |
| 359 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
360 | |
| 13964 | 361 | /* |
| 362 | * Check that this is not the end of the conversation. This is | |
| 363 | * using a magic string, but xmlnode won't play nice when just | |
| 364 | * parsing an end tag | |
| 365 | */ | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
366 | if (closed_conversation || purple_str_has_prefix(message, STREAM_END)) { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
367 | char *closed_conv_message; |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
368 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
369 | /* Close the socket, clear the watcher and free memory */ |
|
17663
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
370 | bonjour_jabber_close_conversation(bb->conversation); |
|
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
371 | bb->conversation = NULL; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
372 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
373 | /* Inform the user that the conversation has been closed */ |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
374 | conversation = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pb->name, account); |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
375 | closed_conv_message = g_strdup_printf(_("%s has closed the conversation."), pb->name); |
| 15884 | 376 | purple_conversation_write(conversation, NULL, closed_conv_message, PURPLE_MESSAGE_SYSTEM, time(NULL)); |
|
13267
aaf66137870b
[gaim-migrate @ 15632]
Mark Doliner <markdoliner@pidgin.im>
parents:
13250
diff
changeset
|
377 | g_free(closed_conv_message); |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
378 | } else if (message_node != NULL) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
379 | /* Parse the message to get the data and send to the ui */ |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
380 | _jabber_parse_and_write_message_to_ui(message_node, account->gc, pb); |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
381 | } else { |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
382 | /* TODO: Deal with receiving only a partial message */ |
| 11477 | 383 | } |
| 13964 | 384 | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
385 | g_free(message); |
|
13972
50b7226d8519
[gaim-migrate @ 16408]
Mark Doliner <markdoliner@pidgin.im>
parents:
13971
diff
changeset
|
386 | if (message_node != NULL) |
|
50b7226d8519
[gaim-migrate @ 16408]
Mark Doliner <markdoliner@pidgin.im>
parents:
13971
diff
changeset
|
387 | xmlnode_free(message_node); |
| 11477 | 388 | } |
| 389 | ||
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
390 | static void |
| 15884 | 391 | _server_socket_handler(gpointer data, int server_socket, PurpleInputCondition condition) |
| 11477 | 392 | { |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
393 | PurpleBuddy *pb = NULL; |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
394 | struct sockaddr_in their_addr; /* connector's address information */ |
|
11515
09651c1daa98
[gaim-migrate @ 13760]
Mark Doliner <markdoliner@pidgin.im>
parents:
11498
diff
changeset
|
395 | socklen_t sin_size = sizeof(struct sockaddr); |
| 11477 | 396 | int client_socket; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
397 | BonjourBuddy *bb; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
398 | char *address_text = NULL; |
| 15884 | 399 | PurpleBuddyList *bl = purple_get_blist(); |
|
12733
0c1de18b51ed
[gaim-migrate @ 15077]
Mark Doliner <markdoliner@pidgin.im>
parents:
12730
diff
changeset
|
400 | struct _check_buddy_by_address_t *cbba; |
| 11477 | 401 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
402 | /* Check that it is a read condition */ |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
403 | if (condition != PURPLE_INPUT_READ) |
| 11477 | 404 | return; |
| 405 | ||
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
406 | if ((client_socket = accept(server_socket, (struct sockaddr *)&their_addr, &sin_size)) == -1) |
| 11477 | 407 | return; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
408 | |
| 11477 | 409 | fcntl(client_socket, F_SETFL, O_NONBLOCK); |
| 410 | ||
| 13962 | 411 | /* Look for the buddy that has opened the conversation and fill information */ |
| 11477 | 412 | address_text = inet_ntoa(their_addr.sin_addr); |
|
12733
0c1de18b51ed
[gaim-migrate @ 15077]
Mark Doliner <markdoliner@pidgin.im>
parents:
12730
diff
changeset
|
413 | cbba = g_new0(struct _check_buddy_by_address_t, 1); |
| 12708 | 414 | cbba->address = address_text; |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
415 | cbba->pb = &pb; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
416 | cbba->bj = data; |
|
13250
3857dfd699c5
[gaim-migrate @ 15615]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
13006
diff
changeset
|
417 | g_hash_table_foreach(bl->buddies, _check_buddy_by_address, cbba); |
| 12708 | 418 | g_free(cbba); |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
419 | if (pb == NULL) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
420 | { |
| 15884 | 421 | purple_debug_info("bonjour", "We don't like invisible buddies, this is not a superheros comic\n"); |
| 11477 | 422 | close(client_socket); |
| 423 | return; | |
| 424 | } | |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
425 | bb = pb->proto_data; |
| 11477 | 426 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
427 | /* Check if the conversation has been previously started */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
428 | if (bb->conversation == NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
429 | { |
|
17663
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
430 | bb->conversation = bonjour_jabber_conv_new(); |
| 11477 | 431 | bb->conversation->socket = client_socket; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
432 | |
| 11477 | 433 | if (bb->conversation->stream_started == FALSE) { |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
434 | char *stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account), |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
435 | purple_buddy_get_name(pb)); |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
436 | /* Start the stream */ |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
437 | send(bb->conversation->socket, stream_start, strlen(stream_start), 0); |
| 11477 | 438 | bb->conversation->stream_started = TRUE; |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
439 | g_free(stream_start); |
| 11477 | 440 | } |
| 441 | ||
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
442 | /* Open a watcher for the client socket */ |
| 15884 | 443 | bb->conversation->watcher_id = purple_input_add(client_socket, PURPLE_INPUT_READ, |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
444 | _client_socket_handler, pb); |
| 11477 | 445 | } else { |
| 446 | close(client_socket); | |
| 447 | } | |
| 448 | } | |
| 449 | ||
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
450 | gint |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
451 | bonjour_jabber_start(BonjourJabber *data) |
| 11477 | 452 | { |
| 453 | struct sockaddr_in my_addr; | |
| 454 | int yes = 1; | |
| 13971 | 455 | int i; |
| 456 | gboolean bind_successful; | |
| 11477 | 457 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
458 | /* Open a listening socket for incoming conversations */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
459 | if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
460 | { |
| 15884 | 461 | purple_debug_error("bonjour", "Cannot open socket: %s\n", strerror(errno)); |
| 462 | purple_connection_error(data->account->gc, _("Cannot open socket")); | |
| 11477 | 463 | return -1; |
| 464 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
465 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
466 | /* Make the socket reusable */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
467 | if (setsockopt(data->socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
468 | { |
| 15884 | 469 | purple_debug_error("bonjour", "Error setting socket options: %s\n", strerror(errno)); |
| 470 | purple_connection_error(data->account->gc, _("Error setting socket options")); | |
| 11477 | 471 | return -1; |
| 472 | } | |
| 473 | ||
| 474 | memset(&my_addr, 0, sizeof(struct sockaddr_in)); | |
| 475 | my_addr.sin_family = PF_INET; | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
476 | |
| 13971 | 477 | /* Attempt to find a free port */ |
| 478 | bind_successful = FALSE; | |
| 479 | for (i = 0; i < 10; i++) | |
| 480 | { | |
| 481 | my_addr.sin_port = htons(data->port); | |
| 482 | if (bind(data->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == 0) | |
| 483 | { | |
| 484 | bind_successful = TRUE; | |
| 485 | break; | |
| 486 | } | |
| 487 | data->port++; | |
| 488 | } | |
| 489 | ||
| 490 | /* On no! We tried 10 ports and could not bind to ANY of them */ | |
| 491 | if (!bind_successful) | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
492 | { |
| 15884 | 493 | purple_debug_error("bonjour", "Cannot bind socket: %s\n", strerror(errno)); |
| 494 | purple_connection_error(data->account->gc, _("Could not bind socket to port")); | |
| 11477 | 495 | return -1; |
| 496 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
497 | |
| 13971 | 498 | /* Attempt to listen on the bound socket */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
499 | if (listen(data->socket, 10) != 0) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
500 | { |
| 15884 | 501 | purple_debug_error("bonjour", "Cannot listen on socket: %s\n", strerror(errno)); |
| 502 | purple_connection_error(data->account->gc, _("Could not listen on socket")); | |
| 11477 | 503 | return -1; |
| 504 | } | |
| 505 | ||
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
506 | #if 0 |
|
12730
f64fdbc34677
[gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents:
12708
diff
changeset
|
507 | /* TODO: Why isn't this being used? */ |
| 15884 | 508 | data->socket = purple_network_listen(data->port, SOCK_STREAM); |
| 11477 | 509 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
510 | if (data->socket == -1) |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
511 | { |
| 15884 | 512 | purple_debug_error("bonjour", "No se ha podido crear el socket\n"); |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
513 | } |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
514 | #endif |
| 11477 | 515 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
516 | /* Open a watcher in the socket we have just opened */ |
| 15884 | 517 | data->watcher_id = purple_input_add(data->socket, PURPLE_INPUT_READ, _server_socket_handler, data); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
518 | |
| 13971 | 519 | return data->port; |
| 11477 | 520 | } |
| 521 | ||
|
11693
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
522 | int |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
523 | bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body) |
| 11477 | 524 | { |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
525 | xmlnode *message_node, *node, *node2; |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
526 | gchar *message; |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
527 | PurpleBuddy *pb; |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
528 | BonjourBuddy *bb; |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
529 | int ret; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
530 | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
531 | pb = purple_find_buddy(data->account, to); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
532 | if (pb == NULL) { |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
533 | purple_debug_info("bonjour", "Can't send a message to an offline buddy (%s).\n", to); |
|
11693
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
534 | /* You can not send a message to an offline buddy */ |
|
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
535 | return -10000; |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
536 | } |
|
11693
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
537 | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
538 | bb = pb->proto_data; |
|
11693
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
539 | |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
540 | /* Check if there is a previously open conversation */ |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
541 | if (bb->conversation == NULL) |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
542 | { |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
543 | int socket = _connect_to_buddy(pb); |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
544 | if (socket < 0) |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
545 | return -10001; |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
546 | |
|
17663
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
547 | bb->conversation = bonjour_jabber_conv_new(); |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
548 | bb->conversation->socket = socket; |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
549 | bb->conversation->watcher_id = purple_input_add(bb->conversation->socket, |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
550 | PURPLE_INPUT_READ, _client_socket_handler, pb); |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
551 | } |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
552 | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
553 | message_node = xmlnode_new("message"); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
554 | xmlnode_set_attrib(message_node, "to", bb->name); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
555 | xmlnode_set_attrib(message_node, "from", purple_account_get_username(data->account)); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
556 | xmlnode_set_attrib(message_node, "type", "chat"); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
557 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
558 | /* Enclose the message from the UI within a "font" node */ |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
559 | node = xmlnode_new_child(message_node, "body"); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
560 | message = purple_markup_strip_html(body); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
561 | xmlnode_insert_data(node, message, strlen(message)); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
562 | g_free(message); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
563 | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
564 | node = xmlnode_new_child(message_node, "html"); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
565 | xmlnode_set_namespace(node, "http://www.w3.org/1999/xhtml"); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
566 | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
567 | node = xmlnode_new_child(node, "body"); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
568 | message = g_strdup_printf("<font>%s</font>", body); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
569 | node2 = xmlnode_from_str(message, strlen(message)); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
570 | g_free(message); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
571 | xmlnode_insert_child(node, node2); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
572 | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
573 | node = xmlnode_new_child(message_node, "x"); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
574 | xmlnode_set_namespace(node, "jabber:x:event"); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
575 | xmlnode_insert_child(node, xmlnode_new("composing")); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
576 | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
577 | |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
578 | message = xmlnode_to_str(message_node, NULL); |
|
15873
78d3aa0fb61e
plug some memory leaks
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15435
diff
changeset
|
579 | xmlnode_free(message_node); |
| 11477 | 580 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
581 | /* Check if the stream for the conversation has been started */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
582 | if (bb->conversation->stream_started == FALSE) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
583 | { |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
584 | char *stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account), |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
585 | purple_buddy_get_name(pb)); |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
586 | /* Start the stream */ |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
587 | if (send(bb->conversation->socket, stream_start, strlen(stream_start), 0) == -1) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
588 | { |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
589 | PurpleConversation *conv; |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
590 | |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
591 | purple_debug_error("bonjour", "Unable to start a conversation\n"); |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
592 | purple_debug_warning("bonjour", "send error: %s\n", strerror(errno)); |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
593 | conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, data->account); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
594 | purple_conversation_write(conv, NULL, |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
595 | _("Unable to send the message, the conversation couldn't be started."), |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
596 | PURPLE_MESSAGE_SYSTEM, time(NULL)); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
597 | |
|
17663
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
598 | bonjour_jabber_close_conversation(bb->conversation); |
|
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
599 | bb->conversation = NULL; |
|
17662
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
600 | |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
601 | g_free(message); |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
602 | g_free(stream_start); |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
603 | return 0; |
| 11477 | 604 | } |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
605 | |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
606 | g_free(stream_start); |
| 11477 | 607 | bb->conversation->stream_started = TRUE; |
| 608 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
609 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
610 | /* Send the message */ |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
611 | ret = (_send_data(bb->conversation->socket, message) == -1); |
|
15873
78d3aa0fb61e
plug some memory leaks
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15435
diff
changeset
|
612 | g_free(message); |
|
78d3aa0fb61e
plug some memory leaks
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15435
diff
changeset
|
613 | |
|
78d3aa0fb61e
plug some memory leaks
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15435
diff
changeset
|
614 | if (ret == -1) |
|
11693
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
615 | return -10000; |
|
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
616 | |
|
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
617 | return 1; |
| 11477 | 618 | } |
| 619 | ||
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
620 | void |
|
17663
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
621 | bonjour_jabber_close_conversation(BonjourJabberConversation *bconv) |
| 11477 | 622 | { |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
623 | if (bconv != NULL) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
624 | { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
625 | /* Close the socket and remove the watcher */ |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
626 | if (bconv->socket >= 0) { |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
627 | /* Send the end of the stream to the other end of the conversation */ |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
628 | if (bconv->stream_started) |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
629 | send(bconv->socket, STREAM_END, strlen(STREAM_END), 0); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
630 | /* TODO: We're really supposed to wait for "</stream:stream>" before closing the socket */ |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
631 | close(bconv->socket); |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
632 | } |
|
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
633 | purple_input_remove(bconv->watcher_id); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
634 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
635 | /* Free all the data related to the conversation */ |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
636 | g_free(bconv); |
| 11477 | 637 | } |
| 638 | } | |
| 639 | ||
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
640 | void |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
641 | bonjour_jabber_stop(BonjourJabber *data) |
| 11477 | 642 | { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
643 | /* Close the server socket and remove the watcher */ |
|
17632
b27a15168d33
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <datallah@pidgin.im>
parents:
17607
diff
changeset
|
644 | if (data->socket >= 0) |
|
b27a15168d33
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <datallah@pidgin.im>
parents:
17607
diff
changeset
|
645 | close(data->socket); |
|
b27a15168d33
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <datallah@pidgin.im>
parents:
17607
diff
changeset
|
646 | if (data->watcher_id > 0) |
|
b27a15168d33
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <datallah@pidgin.im>
parents:
17607
diff
changeset
|
647 | purple_input_remove(data->watcher_id); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
648 | |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
649 | /* Close all the conversation sockets and remove all the watchers after sending end streams */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
650 | if (data->account->gc != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
651 | { |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
652 | GSList *buddies, *l; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
653 | |
|
17660
23c712d0a795
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <datallah@pidgin.im>
parents:
17633
diff
changeset
|
654 | buddies = purple_find_buddies(data->account, purple_account_get_username(data->account)); |
|
17663
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
655 | for (l = buddies; l; l = l->next) { |
|
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
656 | BonjourBuddy *bb = ((PurpleBuddy*) l->data)->proto_data; |
|
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
657 | bonjour_jabber_close_conversation(bb->conversation); |
|
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
658 | bb->conversation = NULL; |
|
fd736a4d91a9
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <datallah@pidgin.im>
parents:
17662
diff
changeset
|
659 | } |
| 11477 | 660 | g_slist_free(buddies); |
| 661 | } | |
| 662 | } |