Fri, 08 Jun 2007 06:28:31 +0000
Consolidate BonjourJabberConversation creation and deletion.
| 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 * |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
112 | bonjour_jabber_conv_new(const char *name) { |
|
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->buddy_name = g_strdup(name); |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
117 | bconv->watcher_id = -1; |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
118 | |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
119 | return bconv; |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
120 | } |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
121 | |
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
122 | static const char * |
| 15884 | 123 | _font_size_ichat_to_purple(int size) |
| 11477 | 124 | { |
| 125 | if (size > 24) { | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
126 | return "7"; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
127 | } else if (size >= 21) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
128 | return "6"; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
129 | } else if (size >= 17) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
130 | return "5"; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
131 | } else if (size >= 14) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
132 | return "4"; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
133 | } else if (size >= 12) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
134 | return "3"; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
135 | } else if (size >= 10) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
136 | return "2"; |
| 11477 | 137 | } |
| 138 | ||
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
139 | return "1"; |
| 11477 | 140 | } |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
141 | |
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
142 | 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
|
143 | _jabber_parse_and_write_message_to_ui(xmlnode *message_node, PurpleConnection *connection, PurpleBuddy *gb) |
| 11477 | 144 | { |
|
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
|
145 | 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
|
146 | char *body, *html_body = NULL; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
147 | const char *ichat_balloon_color = NULL; |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
148 | const char *ichat_text_color = NULL; |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
149 | const char *font_face = NULL; |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
150 | const char *font_size = NULL; |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
151 | const char *font_color = NULL; |
| 11477 | 152 | gboolean composing_event = FALSE; |
| 153 | ||
|
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
|
154 | 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
|
155 | if (body_node == NULL) |
| 11477 | 156 | return; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
157 | body = xmlnode_get_data(body_node); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
158 | |
| 11477 | 159 | html_node = xmlnode_get_child(message_node, "html"); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
160 | if (html_node != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
161 | { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
162 | xmlnode *html_body_node; |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
163 | |
| 11477 | 164 | html_body_node = xmlnode_get_child(html_node, "body"); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
165 | if (html_body_node != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
166 | { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
167 | xmlnode *html_body_font_node; |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
168 | |
| 11477 | 169 | ichat_balloon_color = xmlnode_get_attrib(html_body_node, "ichatballooncolor"); |
| 170 | ichat_text_color = xmlnode_get_attrib(html_body_node, "ichattextcolor"); | |
| 171 | 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
|
172 | if (html_body_font_node != NULL) |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
173 | { /* Types of messages sent by iChat */ |
| 11477 | 174 | font_face = xmlnode_get_attrib(html_body_font_node, "face"); |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
175 | /* The absolute iChat font sizes should be converted to 1..7 range */ |
| 11477 | 176 | font_size = xmlnode_get_attrib(html_body_font_node, "ABSZ"); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
177 | if (font_size != NULL) |
| 15884 | 178 | font_size = _font_size_ichat_to_purple(atoi(font_size)); |
| 11477 | 179 | font_color = xmlnode_get_attrib(html_body_font_node, "color"); |
| 180 | html_body = xmlnode_get_data(html_body_font_node); | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
181 | if (html_body == NULL) |
| 15884 | 182 | /* 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
|
183 | html_body = xmlnode_to_str(html_body_font_node, NULL); |
| 11477 | 184 | } |
| 185 | } | |
| 186 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
187 | |
| 11477 | 188 | 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
|
189 | if (events_node != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
190 | { |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
191 | if (xmlnode_get_child(events_node, "composing") != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
192 | { |
| 11477 | 193 | composing_event = TRUE; |
| 194 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
195 | if (xmlnode_get_child(events_node, "id") != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
196 | { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
197 | /* The user is just typing */ |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
198 | /* TODO: Deal with typing notification */ |
| 11477 | 199 | g_free(body); |
| 200 | g_free(html_body); | |
| 201 | return; | |
| 202 | } | |
| 203 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
204 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
205 | /* Compose the message */ |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
206 | if (html_body != NULL) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
207 | { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
208 | g_free(body); |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
209 | |
| 11477 | 210 | if (font_face == NULL) font_face = "Helvetica"; |
| 211 | if (font_size == NULL) font_size = "3"; | |
| 212 | if (ichat_text_color == NULL) ichat_text_color = "#000000"; | |
| 213 | 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
|
214 | 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
|
215 | 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
|
216 | html_body); |
| 11477 | 217 | } |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
218 | |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
219 | /* 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
|
220 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
221 | /* Send the message to the UI */ |
| 11477 | 222 | serv_got_im(connection, gb->name, body, 0, time(NULL)); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
223 | |
| 11477 | 224 | g_free(body); |
| 225 | g_free(html_body); | |
| 226 | } | |
| 227 | ||
| 12708 | 228 | struct _check_buddy_by_address_t { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
229 | const char *address; |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
230 | PurpleBuddy **pb; |
| 13962 | 231 | BonjourJabber *bj; |
| 12708 | 232 | }; |
| 233 | ||
| 234 | static void | |
| 235 | _check_buddy_by_address(gpointer key, gpointer value, gpointer data) | |
| 11477 | 236 | { |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
237 | PurpleBuddy *pb = value; |
| 13962 | 238 | BonjourBuddy *bb; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
239 | struct _check_buddy_by_address_t *cbba = data; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
240 | |
| 13962 | 241 | /* |
| 15884 | 242 | * If the current PurpleBuddy's data is not null and the PurpleBuddy's account |
| 13962 | 243 | * is the same as the account requesting the check then continue to determine |
| 244 | * whether the buddies IP matches the target IP. | |
| 245 | */ | |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
246 | if (cbba->bj->account == pb->account) |
| 13962 | 247 | { |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
248 | bb = pb->proto_data; |
|
17155
143ff2796376
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
249 | 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
|
250 | *(cbba->pb) = pb; |
| 11477 | 251 | } |
| 252 | } | |
| 253 | ||
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
254 | static gint |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
255 | _read_data(gint socket, char **message) |
| 11477 | 256 | { |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
257 | GString *data = g_string_new(""); |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
258 | char partial_data[512]; |
| 11477 | 259 | gint total_message_length = 0; |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
260 | gint partial_message_length = 0; |
| 11477 | 261 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
262 | /* 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
|
263 | 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
|
264 | { |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
265 | 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
|
266 | total_message_length += partial_message_length; |
| 11477 | 267 | } |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
268 | |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
269 | if (partial_message_length == -1) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
270 | { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
271 | if (errno != EAGAIN) |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
272 | purple_debug_warning("bonjour", "receive error: %s\n", strerror(errno)); |
| 11477 | 273 | if (total_message_length == 0) { |
| 274 | return -1; | |
| 275 | } | |
| 276 | } | |
| 277 | ||
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
278 | *message = g_string_free(data, FALSE); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
279 | if (total_message_length != 0) |
| 15884 | 280 | 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
|
281 | |
| 11477 | 282 | return total_message_length; |
| 283 | } | |
| 284 | ||
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
285 | static gint |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
286 | _send_data(gint socket, char *message) |
| 11477 | 287 | { |
| 288 | gint message_len = strlen(message); | |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
289 | gint partial_sent = 0; |
|
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
290 | gchar *partial_message = message; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
291 | |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
292 | 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
|
293 | { |
|
13006
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
294 | if (partial_sent != -1) { |
|
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
295 | partial_message += partial_sent; |
|
2e2ca7e0c716
[gaim-migrate @ 15359]
Daniel Atallah <datallah@pidgin.im>
parents:
12733
diff
changeset
|
296 | message_len -= partial_sent; |
| 11477 | 297 | } else { |
| 298 | return -1; | |
| 299 | } | |
| 300 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
301 | |
| 11477 | 302 | return strlen(message); |
| 303 | } | |
| 304 | ||
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
305 | static void |
| 15884 | 306 | _client_socket_handler(gpointer data, gint socket, PurpleInputCondition condition) |
| 11477 | 307 | { |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
308 | char *message = NULL; |
| 11477 | 309 | gint message_length; |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
310 | PurpleBuddy *pb = data; |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
311 | PurpleAccount *account = pb->account; |
| 15884 | 312 | PurpleConversation *conversation; |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
313 | BonjourBuddy *bb = pb->proto_data; |
| 11477 | 314 | gboolean closed_conversation = FALSE; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
315 | xmlnode *message_node; |
| 11477 | 316 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
317 | /* Read the data from the socket */ |
| 11477 | 318 | if ((message_length = _read_data(socket, &message)) == -1) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
319 | /* 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
|
320 | /* TODO: Shouldn't we handle the error if it isn't EAGAIN? */ |
| 11477 | 321 | return; |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
322 | } else if (message_length == 0) { /* The other end has closed the socket */ |
| 11477 | 323 | closed_conversation = TRUE; |
| 324 | } else { | |
| 325 | message[message_length] = '\0'; | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
326 | |
| 11477 | 327 | while (g_ascii_iscntrl(message[message_length - 1])) { |
| 328 | message[message_length - 1] = '\0'; | |
| 329 | message_length--; | |
| 330 | } | |
| 331 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
332 | |
| 13964 | 333 | /* Parse the message into an XMLnode for analysis */ |
| 334 | message_node = xmlnode_from_str(message, strlen(message)); | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
335 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
336 | /* 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
|
337 | /* data is the start of the stream */ |
| 13964 | 338 | if (!(bb->conversation->stream_started)) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
339 | { |
| 13964 | 340 | /* Check if this is the start of the stream */ |
| 341 | if ((message_node != NULL) && | |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
342 | 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
|
343 | (xmlnode_get_attrib(message_node,"xmlns:stream") != NULL)) |
| 13964 | 344 | { |
| 345 | bb->conversation->stream_started = TRUE; | |
| 346 | } | |
| 347 | else | |
| 348 | { | |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
349 | 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
|
350 | 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
|
351 | |
| 13964 | 352 | /* 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
|
353 | if (send(bb->conversation->socket, stream_start, strlen(stream_start), 0) == -1) |
| 15884 | 354 | purple_debug_error("bonjour", "Unable to start a conversation with %s\n", bb->name); |
| 13964 | 355 | else |
| 356 | 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
|
357 | |
|
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
358 | g_free(stream_start); |
| 11477 | 359 | } |
| 360 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
361 | |
| 13964 | 362 | /* |
| 363 | * Check that this is not the end of the conversation. This is | |
| 364 | * using a magic string, but xmlnode won't play nice when just | |
| 365 | * parsing an end tag | |
| 366 | */ | |
|
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
|
367 | 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
|
368 | char *closed_conv_message; |
|
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
369 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
370 | /* Close the socket, clear the watcher and free memory */ |
|
17662
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
371 | if (bb->conversation != NULL) |
|
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
372 | bonjour_jabber_close_conversation(pb); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
373 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
374 | /* 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
|
375 | 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
|
376 | closed_conv_message = g_strdup_printf(_("%s has closed the conversation."), pb->name); |
| 15884 | 377 | 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
|
378 | 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
|
379 | } else if (message_node != NULL) { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
380 | /* 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
|
381 | _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
|
382 | } 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
|
383 | /* TODO: Deal with receiving only a partial message */ |
| 11477 | 384 | } |
| 13964 | 385 | |
|
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
|
386 | g_free(message); |
|
13972
50b7226d8519
[gaim-migrate @ 16408]
Mark Doliner <markdoliner@pidgin.im>
parents:
13971
diff
changeset
|
387 | if (message_node != NULL) |
|
50b7226d8519
[gaim-migrate @ 16408]
Mark Doliner <markdoliner@pidgin.im>
parents:
13971
diff
changeset
|
388 | xmlnode_free(message_node); |
| 11477 | 389 | } |
| 390 | ||
|
12443
ad94864144f8
[gaim-migrate @ 14750]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11830
diff
changeset
|
391 | static void |
| 15884 | 392 | _server_socket_handler(gpointer data, int server_socket, PurpleInputCondition condition) |
| 11477 | 393 | { |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
394 | PurpleBuddy *pb = NULL; |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
395 | struct sockaddr_in their_addr; /* connector's address information */ |
|
11515
09651c1daa98
[gaim-migrate @ 13760]
Mark Doliner <markdoliner@pidgin.im>
parents:
11498
diff
changeset
|
396 | socklen_t sin_size = sizeof(struct sockaddr); |
| 11477 | 397 | int client_socket; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
398 | BonjourBuddy *bb; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
399 | char *address_text = NULL; |
| 15884 | 400 | PurpleBuddyList *bl = purple_get_blist(); |
|
12733
0c1de18b51ed
[gaim-migrate @ 15077]
Mark Doliner <markdoliner@pidgin.im>
parents:
12730
diff
changeset
|
401 | struct _check_buddy_by_address_t *cbba; |
| 11477 | 402 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
403 | /* 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
|
404 | if (condition != PURPLE_INPUT_READ) |
| 11477 | 405 | return; |
| 406 | ||
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
407 | if ((client_socket = accept(server_socket, (struct sockaddr *)&their_addr, &sin_size)) == -1) |
| 11477 | 408 | return; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
409 | |
| 11477 | 410 | fcntl(client_socket, F_SETFL, O_NONBLOCK); |
| 411 | ||
| 13962 | 412 | /* Look for the buddy that has opened the conversation and fill information */ |
| 11477 | 413 | address_text = inet_ntoa(their_addr.sin_addr); |
|
12733
0c1de18b51ed
[gaim-migrate @ 15077]
Mark Doliner <markdoliner@pidgin.im>
parents:
12730
diff
changeset
|
414 | cbba = g_new0(struct _check_buddy_by_address_t, 1); |
| 12708 | 415 | 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
|
416 | cbba->pb = &pb; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
417 | cbba->bj = data; |
|
13250
3857dfd699c5
[gaim-migrate @ 15615]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
13006
diff
changeset
|
418 | g_hash_table_foreach(bl->buddies, _check_buddy_by_address, cbba); |
| 12708 | 419 | g_free(cbba); |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
420 | if (pb == NULL) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
421 | { |
| 15884 | 422 | purple_debug_info("bonjour", "We don't like invisible buddies, this is not a superheros comic\n"); |
| 11477 | 423 | close(client_socket); |
| 424 | return; | |
| 425 | } | |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
426 | bb = pb->proto_data; |
| 11477 | 427 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
428 | /* Check if the conversation has been previously started */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
429 | if (bb->conversation == NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
430 | { |
|
17662
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
431 | bb->conversation = bonjour_jabber_conv_new(pb->name); |
| 11477 | 432 | bb->conversation->socket = client_socket; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
433 | |
| 11477 | 434 | 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
|
435 | 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
|
436 | purple_buddy_get_name(pb)); |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
437 | /* Start the stream */ |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
438 | send(bb->conversation->socket, stream_start, strlen(stream_start), 0); |
| 11477 | 439 | 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
|
440 | g_free(stream_start); |
| 11477 | 441 | } |
| 442 | ||
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
443 | /* Open a watcher for the client socket */ |
| 15884 | 444 | 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
|
445 | _client_socket_handler, pb); |
| 11477 | 446 | } else { |
| 447 | close(client_socket); | |
| 448 | } | |
| 449 | } | |
| 450 | ||
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
451 | gint |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
452 | bonjour_jabber_start(BonjourJabber *data) |
| 11477 | 453 | { |
| 454 | struct sockaddr_in my_addr; | |
| 455 | int yes = 1; | |
| 13971 | 456 | int i; |
| 457 | gboolean bind_successful; | |
| 11477 | 458 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
459 | /* Open a listening socket for incoming conversations */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
460 | if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
461 | { |
| 15884 | 462 | purple_debug_error("bonjour", "Cannot open socket: %s\n", strerror(errno)); |
| 463 | purple_connection_error(data->account->gc, _("Cannot open socket")); | |
| 11477 | 464 | return -1; |
| 465 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
466 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
467 | /* Make the socket reusable */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
468 | 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
|
469 | { |
| 15884 | 470 | purple_debug_error("bonjour", "Error setting socket options: %s\n", strerror(errno)); |
| 471 | purple_connection_error(data->account->gc, _("Error setting socket options")); | |
| 11477 | 472 | return -1; |
| 473 | } | |
| 474 | ||
| 475 | memset(&my_addr, 0, sizeof(struct sockaddr_in)); | |
| 476 | my_addr.sin_family = PF_INET; | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
477 | |
| 13971 | 478 | /* Attempt to find a free port */ |
| 479 | bind_successful = FALSE; | |
| 480 | for (i = 0; i < 10; i++) | |
| 481 | { | |
| 482 | my_addr.sin_port = htons(data->port); | |
| 483 | if (bind(data->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == 0) | |
| 484 | { | |
| 485 | bind_successful = TRUE; | |
| 486 | break; | |
| 487 | } | |
| 488 | data->port++; | |
| 489 | } | |
| 490 | ||
| 491 | /* On no! We tried 10 ports and could not bind to ANY of them */ | |
| 492 | if (!bind_successful) | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
493 | { |
| 15884 | 494 | purple_debug_error("bonjour", "Cannot bind socket: %s\n", strerror(errno)); |
| 495 | purple_connection_error(data->account->gc, _("Could not bind socket to port")); | |
| 11477 | 496 | return -1; |
| 497 | } | |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
498 | |
| 13971 | 499 | /* Attempt to listen on the bound socket */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
500 | if (listen(data->socket, 10) != 0) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
501 | { |
| 15884 | 502 | purple_debug_error("bonjour", "Cannot listen on socket: %s\n", strerror(errno)); |
| 503 | purple_connection_error(data->account->gc, _("Could not listen on socket")); | |
| 11477 | 504 | return -1; |
| 505 | } | |
| 506 | ||
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
507 | #if 0 |
|
12730
f64fdbc34677
[gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents:
12708
diff
changeset
|
508 | /* TODO: Why isn't this being used? */ |
| 15884 | 509 | data->socket = purple_network_listen(data->port, SOCK_STREAM); |
| 11477 | 510 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
511 | if (data->socket == -1) |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
512 | { |
| 15884 | 513 | 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
|
514 | } |
|
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
515 | #endif |
| 11477 | 516 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
517 | /* Open a watcher in the socket we have just opened */ |
| 15884 | 518 | 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
|
519 | |
| 13971 | 520 | return data->port; |
| 11477 | 521 | } |
| 522 | ||
|
11693
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
523 | int |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
524 | bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body) |
| 11477 | 525 | { |
|
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
|
526 | 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
|
527 | 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
|
528 | 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
|
529 | 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
|
530 | int ret; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
531 | |
|
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
|
532 | 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
|
533 | if (pb == NULL) { |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
534 | 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
|
535 | /* You can not send a message to an offline buddy */ |
|
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
536 | return -10000; |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
537 | } |
|
11693
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
538 | |
|
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
|
539 | bb = pb->proto_data; |
|
11693
1a42a66ca0f8
[gaim-migrate @ 13979]
Mark Doliner <markdoliner@pidgin.im>
parents:
11688
diff
changeset
|
540 | |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
541 | /* 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
|
542 | if (bb->conversation == NULL) |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
543 | { |
|
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
|
544 | 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
|
545 | if (socket < 0) |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
546 | return -10001; |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
547 | |
|
17662
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
548 | bb->conversation = bonjour_jabber_conv_new(pb->name); |
|
17607
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
549 | bb->conversation->socket = socket; |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
550 | 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
|
551 | 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
|
552 | } |
|
4d7a1c0f169b
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <datallah@pidgin.im>
parents:
17596
diff
changeset
|
553 | |
|
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
|
554 | 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
|
555 | 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
|
556 | 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
|
557 | 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
|
558 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
559 | /* 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
|
560 | 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
|
561 | 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
|
562 | 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
|
563 | g_free(message); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
564 | |
|
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
|
565 | 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
|
566 | xmlnode_set_namespace(node, "http://www.w3.org/1999/xhtml"); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
567 | |
|
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
|
568 | 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
|
569 | 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
|
570 | 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
|
571 | 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
|
572 | xmlnode_insert_child(node, node2); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
573 | |
|
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
|
574 | 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
|
575 | 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
|
576 | xmlnode_insert_child(node, xmlnode_new("composing")); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
577 | |
|
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
|
578 | |
|
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
|
579 | message = xmlnode_to_str(message_node, NULL); |
|
15873
78d3aa0fb61e
plug some memory leaks
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15435
diff
changeset
|
580 | xmlnode_free(message_node); |
| 11477 | 581 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
582 | /* Check if the stream for the conversation has been started */ |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
583 | if (bb->conversation->stream_started == FALSE) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
584 | { |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
585 | 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
|
586 | purple_buddy_get_name(pb)); |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
587 | /* Start the stream */ |
|
17661
96c6a21c4139
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <datallah@pidgin.im>
parents:
17660
diff
changeset
|
588 | 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
|
589 | { |
|
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
|
590 | 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
|
591 | |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
592 | 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
|
593 | 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
|
594 | 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
|
595 | purple_conversation_write(conv, NULL, |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
596 | _("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
|
597 | PURPLE_MESSAGE_SYSTEM, time(NULL)); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
598 | |
|
17662
233ff0515d7b
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <datallah@pidgin.im>
parents:
17661
diff
changeset
|
599 | bonjour_jabber_close_conversation(pb); |
|
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 |
|
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
|
621 | bonjour_jabber_close_conversation(PurpleBuddy *pb) |
| 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 | BonjourBuddy *bb = pb->proto_data; |
|
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
|
624 | BonjourJabberConversation *bconv = bb->conversation; |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
625 | |
|
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 != NULL) |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
627 | { |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
628 | /* 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
|
629 | 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
|
630 | /* 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
|
631 | 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
|
632 | 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
|
633 | /* 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
|
634 | 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
|
635 | } |
|
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 | purple_input_remove(bconv->watcher_id); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
637 | |
|
11826
10ebbc41f163
[gaim-migrate @ 14117]
Richard Laager <rlaager@pidgin.im>
parents:
11823
diff
changeset
|
638 | /* 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
|
639 | g_free(bconv->buddy_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
|
640 | g_free(bconv); |
| 11477 | 641 | bb->conversation = NULL; |
| 642 | } | |
| 643 | } | |
| 644 | ||
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
645 | void |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
646 | bonjour_jabber_stop(BonjourJabber *data) |
| 11477 | 647 | { |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
648 | /* 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
|
649 | if (data->socket >= 0) |
|
b27a15168d33
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <datallah@pidgin.im>
parents:
17607
diff
changeset
|
650 | close(data->socket); |
|
b27a15168d33
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <datallah@pidgin.im>
parents:
17607
diff
changeset
|
651 | if (data->watcher_id > 0) |
|
b27a15168d33
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <datallah@pidgin.im>
parents:
17607
diff
changeset
|
652 | purple_input_remove(data->watcher_id); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
653 | |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
654 | /* 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
|
655 | if (data->account->gc != NULL) |
|
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
656 | { |
|
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
|
657 | GSList *buddies, *l; |
|
17633
b76241c02857
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <datallah@pidgin.im>
parents:
17632
diff
changeset
|
658 | |
|
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
|
659 | buddies = purple_find_buddies(data->account, purple_account_get_username(data->account)); |
|
11539
fbabe3f89777
[gaim-migrate @ 13794]
Mark Doliner <markdoliner@pidgin.im>
parents:
11515
diff
changeset
|
660 | for (l = buddies; l; l = l->next) |
|
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
|
661 | bonjour_jabber_close_conversation(l->data); |
| 11477 | 662 | g_slist_free(buddies); |
| 663 | } | |
| 664 | } |