Mercurial > pidgin
annotate libpurple/protocols/bonjour/jabber.c @ 18728:3db31505e42f
Use pseudo-nonblocking stuff to update the feeds.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Tue, 31 Jul 2007 04:33:53 +0000 |
parents | b981d3c39d0b |
children | 316be7e715c6 |
rev | line source |
---|---|
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1 /* |
15822 | 2 * purple - Bonjour Protocol Plugin |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3 * |
15822 | 4 * Purple is the legal property of its developers, whose names are too numerous |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
6 * source distribution. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
7 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
8 * This program is free software; you can redistribute it and/or modify |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
11 * (at your option) any later version. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
12 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
16 * GNU General Public License for more details. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
17 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
21 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
22 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
23 #include <sys/socket.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
24 #include <netinet/in.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
25 #include <arpa/inet.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
26 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
27 #include "libc_interface.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
28 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
29 #include <sys/types.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
30 #include <glib.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
31 #include <unistd.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
32 #include <fcntl.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
33 |
18276
1faa319ab4c3
More compile fixes from rekkanoryo for G_GNUC_NULL_TERMINATED issues
Stu Tomlinson <stu@nosnilmot.com>
parents:
17599
diff
changeset
|
34 #include "internal.h" |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
35 #include "network.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
36 #include "eventloop.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
37 #include "connection.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
38 #include "blist.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
39 #include "xmlnode.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
40 #include "debug.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
41 #include "notify.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
42 #include "util.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
43 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
44 #include "jabber.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
45 #include "bonjour.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
46 #include "buddy.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
47 |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
48 #define STREAM_END "</stream:stream>" |
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
49 /* TODO: specify version='1.0' and send stream features */ |
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
50 #define DOCTYPE "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" \ |
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
51 "<stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" from=\"%s\" to=\"%s\">" |
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
52 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
53 #if 0 /* this isn't used anywhere... */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
54 static const char * |
15822 | 55 _font_size_purple_to_ichat(int size) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
56 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
57 switch (size) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
58 case 1: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
59 return "8"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
60 case 2: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
61 return "10"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
62 case 3: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
63 return "12"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
64 case 4: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
65 return "14"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
66 case 5: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
67 return "17"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
68 case 6: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
69 return "21"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
70 case 7: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
71 return "24"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
72 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
73 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
74 return "12"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
75 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
76 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
77 |
17555
b13850d13391
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17554
diff
changeset
|
78 static BonjourJabberConversation * |
17556
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
79 bonjour_jabber_conv_new() { |
17555
b13850d13391
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17554
diff
changeset
|
80 |
b13850d13391
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17554
diff
changeset
|
81 BonjourJabberConversation *bconv = g_new0(BonjourJabberConversation, 1); |
b13850d13391
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17554
diff
changeset
|
82 bconv->socket = -1; |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
83 bconv->tx_buf = purple_circ_buffer_new(512); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
84 bconv->tx_handler = -1; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
85 bconv->rx_handler = -1; |
17555
b13850d13391
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17554
diff
changeset
|
86 |
b13850d13391
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17554
diff
changeset
|
87 return bconv; |
b13850d13391
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17554
diff
changeset
|
88 } |
b13850d13391
Consolidate BonjourJabberConversation creation and deletion.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17554
diff
changeset
|
89 |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
90 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
91 static const char * |
15822 | 92 _font_size_ichat_to_purple(int size) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
93 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
94 if (size > 24) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
95 return "7"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
96 } else if (size >= 21) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
97 return "6"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
98 } else if (size >= 17) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
99 return "5"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
100 } else if (size >= 14) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
101 return "4"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
102 } else if (size >= 12) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
103 return "3"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
104 } else if (size >= 10) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
105 return "2"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
106 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
107 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
108 return "1"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
109 } |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
110 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
111 static void |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
112 _jabber_parse_and_write_message_to_ui(xmlnode *message_node, PurpleConnection *connection, PurpleBuddy *pb) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
113 { |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
114 xmlnode *body_node, *html_node, *events_node; |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
115 char *body, *html_body = NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
116 const char *ichat_balloon_color = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
117 const char *ichat_text_color = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
118 const char *font_face = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
119 const char *font_size = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
120 const char *font_color = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
121 gboolean composing_event = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
122 |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
123 body_node = xmlnode_get_child(message_node, "body"); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
124 if (body_node == NULL) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
125 return; |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
126 body = xmlnode_get_data(body_node); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
127 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
128 html_node = xmlnode_get_child(message_node, "html"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
129 if (html_node != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
130 { |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
131 xmlnode *html_body_node; |
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
132 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
133 html_body_node = xmlnode_get_child(html_node, "body"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
134 if (html_body_node != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
135 { |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
136 xmlnode *html_body_font_node; |
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
137 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
138 ichat_balloon_color = xmlnode_get_attrib(html_body_node, "ichatballooncolor"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
139 ichat_text_color = xmlnode_get_attrib(html_body_node, "ichattextcolor"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
140 html_body_font_node = xmlnode_get_child(html_body_node, "font"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
141 if (html_body_font_node != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
142 { /* Types of messages sent by iChat */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
143 font_face = xmlnode_get_attrib(html_body_font_node, "face"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
144 /* The absolute iChat font sizes should be converted to 1..7 range */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
145 font_size = xmlnode_get_attrib(html_body_font_node, "ABSZ"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
146 if (font_size != NULL) |
15822 | 147 font_size = _font_size_ichat_to_purple(atoi(font_size)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
148 font_color = xmlnode_get_attrib(html_body_font_node, "color"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
149 html_body = xmlnode_get_data(html_body_font_node); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
150 if (html_body == NULL) |
15822 | 151 /* This is the kind of formated messages that Purple creates */ |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
152 html_body = xmlnode_to_str(html_body_font_node, NULL); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
153 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
154 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
155 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
156 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
157 events_node = xmlnode_get_child_with_namespace(message_node, "x", "jabber:x:event"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
158 if (events_node != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
159 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
160 if (xmlnode_get_child(events_node, "composing") != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
161 composing_event = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
162 if (xmlnode_get_child(events_node, "id") != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
163 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
164 /* The user is just typing */ |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
165 /* TODO: Deal with typing notification */ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
166 g_free(body); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
167 g_free(html_body); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
168 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
169 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
170 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
171 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
172 /* Compose the message */ |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
173 if (html_body != NULL) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
174 { |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
175 g_free(body); |
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
176 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
177 if (font_face == NULL) font_face = "Helvetica"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
178 if (font_size == NULL) font_size = "3"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
179 if (ichat_text_color == NULL) ichat_text_color = "#000000"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
180 if (ichat_balloon_color == NULL) ichat_balloon_color = "#FFFFFF"; |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
181 body = g_strdup_printf("<font face='%s' size='%s' color='%s' back='%s'>%s</font>", |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
182 font_face, font_size, ichat_text_color, ichat_balloon_color, |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
183 html_body); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
184 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
185 |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
186 /* TODO: Should we do something with "composing_event" here? */ |
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
187 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
188 /* Send the message to the UI */ |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
189 serv_got_im(connection, pb->name, body, 0, time(NULL)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
190 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
191 g_free(body); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
192 g_free(html_body); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
193 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
194 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
195 struct _check_buddy_by_address_t { |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
196 const char *address; |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
197 PurpleBuddy **pb; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
198 BonjourJabber *bj; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
199 }; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
200 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
201 static void |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
202 _check_buddy_by_address(gpointer key, gpointer value, gpointer data) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
203 { |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
204 PurpleBuddy *pb = value; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
205 BonjourBuddy *bb; |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
206 struct _check_buddy_by_address_t *cbba = data; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
207 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
208 /* |
15822 | 209 * If the current PurpleBuddy's data is not null and the PurpleBuddy's account |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
210 * is the same as the account requesting the check then continue to determine |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
211 * whether the buddies IP matches the target IP. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
212 */ |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
213 if (cbba->bj->account == pb->account) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
214 { |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
215 bb = pb->proto_data; |
17082
7ade887fd3f6
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
216 if ((bb != NULL) && (g_ascii_strcasecmp(bb->ip, cbba->address) == 0)) |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
217 *(cbba->pb) = pb; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
218 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
219 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
220 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
221 static gint |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
222 _read_data(gint socket, char **message) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
223 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
224 GString *data = g_string_new(""); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
225 char partial_data[512]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
226 gint total_message_length = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
227 gint partial_message_length = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
228 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
229 /* Read chunks of 512 bytes till the end of the data */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
230 while ((partial_message_length = recv(socket, partial_data, 512, 0)) > 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
231 { |
17500
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
232 g_string_append_len(data, partial_data, partial_message_length); |
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
233 total_message_length += partial_message_length; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
234 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
235 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
236 if (partial_message_length == -1) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
237 { |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
238 if (errno != EAGAIN) |
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
239 purple_debug_warning("bonjour", "receive error: %s\n", strerror(errno)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
240 if (total_message_length == 0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
241 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
242 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
243 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
244 |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
245 *message = g_string_free(data, FALSE); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
246 if (total_message_length != 0) |
15822 | 247 purple_debug_info("bonjour", "Receive: -%s- %d bytes\n", *message, total_message_length); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
248 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
249 return total_message_length; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
250 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
251 |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
252 static void |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
253 _send_data_write_cb(gpointer data, gint source, PurpleInputCondition cond) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
254 { |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
255 PurpleBuddy *pb = data; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
256 BonjourBuddy *bb = pb->proto_data; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
257 BonjourJabberConversation *bconv = bb->conversation; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
258 int ret, writelen; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
259 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
260 /* TODO: Make sure that the stream has been established before sending */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
261 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
262 writelen = purple_circ_buffer_get_max_read(bconv->tx_buf); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
263 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
264 if (writelen == 0) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
265 purple_input_remove(bconv->tx_handler); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
266 bconv->tx_handler = -1; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
267 return; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
268 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
269 |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
270 ret = send(bconv->socket, bconv->tx_buf->outptr, writelen, 0); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
271 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
272 if (ret < 0 && errno == EAGAIN) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
273 return; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
274 else if (ret <= 0) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
275 PurpleConversation *conv; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
276 const char *error = strerror(errno); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
277 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
278 purple_debug_error("bonjour", "Error sending message to buddy %s error: %s\n", |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
279 purple_buddy_get_name(pb), error ? error : "(null)"); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
280 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
281 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, pb->account); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
282 if (conv != NULL) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
283 purple_conversation_write(conv, NULL, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
284 _("Unable to send message."), |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
285 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
286 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
287 bonjour_jabber_close_conversation(bb->conversation); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
288 bb->conversation = NULL; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
289 return; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
290 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
291 |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
292 purple_circ_buffer_mark_read(bconv->tx_buf, ret); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
293 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
294 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
295 static gint |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
296 _send_data(PurpleBuddy *pb, char *message) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
297 { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
298 gint ret; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
299 int len = strlen(message); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
300 BonjourBuddy *bb = pb->proto_data; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
301 BonjourJabberConversation *bconv = bb->conversation; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
302 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
303 /* If we're not ready to actually send, append it to the buffer */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
304 if (bconv->tx_handler != -1 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
305 || bconv->connect_data != NULL |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
306 || !bconv->stream_started |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
307 || purple_circ_buffer_get_max_read(bconv->tx_buf) > 0) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
308 ret = -1; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
309 errno = EAGAIN; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
310 } else { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
311 ret = send(bconv->socket, message, len, 0); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
312 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
313 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
314 if (ret == -1 && errno == EAGAIN) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
315 ret = 0; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
316 else if (ret <= 0) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
317 PurpleConversation *conv; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
318 const char *error = strerror(errno); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
319 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
320 purple_debug_error("bonjour", "Error sending message to buddy %s error: %s\n", |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
321 purple_buddy_get_name(pb), error ? error : "(null)"); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
322 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
323 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, pb->account); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
324 if (conv != NULL) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
325 purple_conversation_write(conv, NULL, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
326 _("Unable to send message."), |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
327 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
328 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
329 bonjour_jabber_close_conversation(bb->conversation); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
330 bb->conversation = NULL; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
331 return -1; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
332 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
333 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
334 if (ret < len) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
335 if (bconv->tx_handler == -1) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
336 bconv->tx_handler = purple_input_add(bconv->socket, PURPLE_INPUT_WRITE, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
337 _send_data_write_cb, pb); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
338 purple_circ_buffer_append(bconv->tx_buf, message + ret, len - ret); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
339 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
340 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
341 return ret; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
342 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
343 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
344 static void |
15822 | 345 _client_socket_handler(gpointer data, gint socket, PurpleInputCondition condition) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
346 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
347 char *message = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
348 gint message_length; |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
349 PurpleBuddy *pb = data; |
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
350 PurpleAccount *account = pb->account; |
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
351 BonjourBuddy *bb = pb->proto_data; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
352 gboolean closed_conversation = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
353 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
354 /* Read the data from the socket */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
355 if ((message_length = _read_data(socket, &message)) == -1) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
356 /* There have been an error reading from the socket */ |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
357 if (errno != EAGAIN) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
358 bonjour_jabber_close_conversation(bb->conversation); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
359 bb->conversation = NULL; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
360 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
361 /* I guess we really don't need to notify the user. |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
362 * If they try to send another message it'll reconnect */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
363 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
364 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
365 } else if (message_length == 0) { /* The other end has closed the socket */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
366 closed_conversation = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
367 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
368 message[message_length] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
369 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
370 while (g_ascii_iscntrl(message[message_length - 1])) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
371 message[message_length - 1] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
372 message_length--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
373 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
374 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
375 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
376 /* |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
377 * Check that this is not the end of the conversation. This is |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
378 * using a magic string, but xmlnode won't play nice when just |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
379 * parsing an end tag |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
380 */ |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
381 if (closed_conversation || purple_str_has_prefix(message, STREAM_END)) { |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
382 PurpleConversation *conv; |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
383 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
384 /* Close the socket, clear the watcher and free memory */ |
17556
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
385 bonjour_jabber_close_conversation(bb->conversation); |
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
386 bb->conversation = NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
387 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
388 /* Inform the user that the conversation has been closed */ |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
389 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pb->name, account); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
390 if (conv != NULL) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
391 char *tmp = g_strdup_printf(_("%s has closed the conversation."), pb->name); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
392 purple_conversation_write(conv, NULL, tmp, PURPLE_MESSAGE_SYSTEM, time(NULL)); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
393 g_free(tmp); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
394 } |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
395 } else { |
18651
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
396 xmlnode *message_node; |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
397 |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
398 /* Parse the message into an XMLnode for analysis */ |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
399 message_node = xmlnode_from_str(message, strlen(message)); |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
400 |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
401 if (message_node != NULL) { |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
402 /* Parse the message to get the data and send to the ui */ |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
403 _jabber_parse_and_write_message_to_ui(message_node, account->gc, pb); |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
404 xmlnode_free(message_node); |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
405 } else { |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
406 /* TODO: Deal with receiving only a partial message */ |
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
407 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
408 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
409 |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
410 g_free(message); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
411 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
412 |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
413 struct _stream_start_data { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
414 char *msg; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
415 PurpleInputFunction tx_handler_cb; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
416 }; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
417 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
418 static void |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
419 _start_stream(gpointer data, gint source, PurpleInputCondition condition) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
420 { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
421 PurpleBuddy *pb = data; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
422 BonjourBuddy *bb = pb->proto_data; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
423 struct _stream_start_data *ss = bb->conversation->stream_data; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
424 int len, ret; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
425 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
426 len = strlen(ss->msg); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
427 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
428 /* Start Stream */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
429 ret = send(source, ss->msg, len, 0); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
430 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
431 if (ret == -1 && errno == EAGAIN) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
432 return; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
433 else if (ret <= 0) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
434 const char *err = strerror(errno); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
435 PurpleConversation *conv; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
436 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
437 purple_debug_error("bonjour", "Error starting stream with buddy %s at %s:%d error: %s\n", |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
438 purple_buddy_get_name(pb), bb->ip ? bb->ip : "(null)", bb->port_p2pj, err ? err : "(null)"); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
439 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
440 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, pb->account); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
441 if (conv != NULL) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
442 purple_conversation_write(conv, NULL, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
443 _("Unable to send the message, the conversation couldn't be started."), |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
444 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
445 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
446 bonjour_jabber_close_conversation(bb->conversation); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
447 bb->conversation = NULL; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
448 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
449 return; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
450 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
451 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
452 /* This is EXTREMELY unlikely to happen */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
453 if (ret < len) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
454 char *tmp = g_strdup(ss->msg + ret); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
455 g_free(ss->msg); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
456 ss->msg = tmp; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
457 return; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
458 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
459 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
460 /* Stream started; process the send buffer if there is one*/ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
461 purple_input_remove(bb->conversation->tx_handler); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
462 bb->conversation->tx_handler= -1; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
463 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
464 bb->conversation->stream_started = TRUE; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
465 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
466 g_free(ss->msg); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
467 g_free(ss); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
468 bb->conversation->stream_data = NULL; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
469 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
470 if (ss->tx_handler_cb) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
471 bb->conversation->tx_handler = purple_input_add(source, PURPLE_INPUT_WRITE, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
472 ss->tx_handler_cb, pb); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
473 /* We can probably write the data now. */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
474 (ss->tx_handler_cb)(pb, source, PURPLE_INPUT_WRITE); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
475 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
476 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
477 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
478 static void |
15822 | 479 _server_socket_handler(gpointer data, int server_socket, PurpleInputCondition condition) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
480 { |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
481 PurpleBuddy *pb = NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
482 struct sockaddr_in their_addr; /* connector's address information */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
483 socklen_t sin_size = sizeof(struct sockaddr); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
484 int client_socket; |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
485 BonjourBuddy *bb; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
486 char *address_text = NULL; |
15822 | 487 PurpleBuddyList *bl = purple_get_blist(); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
488 struct _check_buddy_by_address_t *cbba; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
489 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
490 /* Check that it is a read condition */ |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
491 if (condition != PURPLE_INPUT_READ) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
492 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
493 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
494 if ((client_socket = accept(server_socket, (struct sockaddr *)&their_addr, &sin_size)) == -1) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
495 return; |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
496 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
497 fcntl(client_socket, F_SETFL, O_NONBLOCK); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
498 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
499 /* Look for the buddy that has opened the conversation and fill information */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
500 address_text = inet_ntoa(their_addr.sin_addr); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
501 cbba = g_new0(struct _check_buddy_by_address_t, 1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
502 cbba->address = address_text; |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
503 cbba->pb = &pb; |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
504 cbba->bj = data; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
505 g_hash_table_foreach(bl->buddies, _check_buddy_by_address, cbba); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
506 g_free(cbba); |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
507 if (pb == NULL) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
508 { |
15822 | 509 purple_debug_info("bonjour", "We don't like invisible buddies, this is not a superheros comic\n"); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
510 close(client_socket); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
511 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
512 } |
17554
a1d05bc43d95
Send 'to' and 'from' attributes in the stream start message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17553
diff
changeset
|
513 bb = pb->proto_data; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
514 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
515 /* Check if the conversation has been previously started */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
516 if (bb->conversation == NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
517 { |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
518 int ret, len; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
519 char *stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account), |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
520 purple_buddy_get_name(pb)); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
521 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
522 len = strlen(stream_start); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
523 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
524 /* Start the stream */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
525 ret = send(client_socket, stream_start, len, 0); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
526 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
527 if (ret == -1 && errno == EAGAIN) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
528 ret = 0; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
529 else if (ret <= 0) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
530 const char *err = strerror(errno); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
531 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
532 purple_debug_error("bonjour", "Error starting stream with buddy %s at %s:%d error: %s\n", |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
533 purple_buddy_get_name(pb), bb->ip ? bb->ip : "(null)", bb->port_p2pj, err ? err : "(null)"); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
534 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
535 close(client_socket); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
536 g_free(stream_start); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
537 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
538 return; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
539 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
540 |
17556
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
541 bb->conversation = bonjour_jabber_conv_new(); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
542 bb->conversation->socket = client_socket; |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
543 bb->conversation->rx_handler = purple_input_add(client_socket, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
544 PURPLE_INPUT_READ, _client_socket_handler, pb); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
545 |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
546 /* This is unlikely to happen */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
547 if (ret < len) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
548 struct _stream_start_data *ss = g_new(struct _stream_start_data, 1); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
549 ss->msg = g_strdup(stream_start + ret); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
550 ss->tx_handler_cb = NULL; /* We have nothing to write yet */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
551 bb->conversation->stream_data = ss; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
552 /* Finish sending the stream start */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
553 bb->conversation->tx_handler = purple_input_add(client_socket, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
554 PURPLE_INPUT_WRITE, _start_stream, pb); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
555 } else { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
556 bb->conversation->stream_started = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
557 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
558 |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
559 g_free(stream_start); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
560 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
561 close(client_socket); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
562 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
563 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
564 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
565 gint |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
566 bonjour_jabber_start(BonjourJabber *data) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
567 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
568 struct sockaddr_in my_addr; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
569 int yes = 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
570 int i; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
571 gboolean bind_successful; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
572 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
573 /* Open a listening socket for incoming conversations */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
574 if ((data->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
575 { |
15822 | 576 purple_debug_error("bonjour", "Cannot open socket: %s\n", strerror(errno)); |
577 purple_connection_error(data->account->gc, _("Cannot open socket")); | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
578 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
579 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
580 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
581 /* Make the socket reusable */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
582 if (setsockopt(data->socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
583 { |
15822 | 584 purple_debug_error("bonjour", "Error setting socket options: %s\n", strerror(errno)); |
585 purple_connection_error(data->account->gc, _("Error setting socket options")); | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
586 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
587 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
588 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
589 memset(&my_addr, 0, sizeof(struct sockaddr_in)); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
590 my_addr.sin_family = PF_INET; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
591 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
592 /* Attempt to find a free port */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
593 bind_successful = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
594 for (i = 0; i < 10; i++) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
595 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
596 my_addr.sin_port = htons(data->port); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
597 if (bind(data->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
598 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
599 bind_successful = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
600 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
601 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
602 data->port++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
603 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
604 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
605 /* On no! We tried 10 ports and could not bind to ANY of them */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
606 if (!bind_successful) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
607 { |
15822 | 608 purple_debug_error("bonjour", "Cannot bind socket: %s\n", strerror(errno)); |
609 purple_connection_error(data->account->gc, _("Could not bind socket to port")); | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
610 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
611 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
612 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
613 /* Attempt to listen on the bound socket */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
614 if (listen(data->socket, 10) != 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
615 { |
15822 | 616 purple_debug_error("bonjour", "Cannot listen on socket: %s\n", strerror(errno)); |
617 purple_connection_error(data->account->gc, _("Could not listen on socket")); | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
618 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
619 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
620 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
621 #if 0 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
622 /* TODO: Why isn't this being used? */ |
15822 | 623 data->socket = purple_network_listen(data->port, SOCK_STREAM); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
624 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
625 if (data->socket == -1) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
626 { |
15822 | 627 purple_debug_error("bonjour", "No se ha podido crear el socket\n"); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
628 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
629 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
630 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
631 /* Open a watcher in the socket we have just opened */ |
15822 | 632 data->watcher_id = purple_input_add(data->socket, PURPLE_INPUT_READ, _server_socket_handler, data); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
633 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
634 return data->port; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
635 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
636 |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
637 static void |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
638 _connected_to_buddy(gpointer data, gint source, const gchar *error) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
639 { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
640 PurpleBuddy *pb = data; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
641 BonjourBuddy *bb = pb->proto_data; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
642 int len, ret; |
18651
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
643 char *stream_start; |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
644 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
645 bb->conversation->connect_data = NULL; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
646 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
647 if (source < 0) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
648 PurpleConversation *conv; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
649 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
650 purple_debug_error("bonjour", "Error connecting to buddy %s at %s:%d error: %s\n", |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
651 purple_buddy_get_name(pb), bb->ip ? bb->ip : "(null)", bb->port_p2pj, error ? error : "(null)"); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
652 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
653 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, pb->account); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
654 if (conv != NULL) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
655 purple_conversation_write(conv, NULL, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
656 _("Unable to send the message, the conversation couldn't be started."), |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
657 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
658 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
659 bonjour_jabber_close_conversation(bb->conversation); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
660 bb->conversation = NULL; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
661 return; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
662 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
663 |
18651
b981d3c39d0b
Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
Daniel Atallah <daniel.atallah@gmail.com>
parents:
18276
diff
changeset
|
664 stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account), purple_buddy_get_name(pb)); |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
665 len = strlen(stream_start); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
666 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
667 /* Start the stream and send queued messages */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
668 ret = send(source, stream_start, len, 0); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
669 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
670 if (ret == -1 && errno == EAGAIN) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
671 ret = 0; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
672 else if (ret <= 0) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
673 const char *err = strerror(errno); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
674 PurpleConversation *conv; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
675 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
676 purple_debug_error("bonjour", "Error starting stream with buddy %s at %s:%d error: %s\n", |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
677 purple_buddy_get_name(pb), bb->ip ? bb->ip : "(null)", bb->port_p2pj, err ? err : "(null)"); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
678 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
679 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, bb->name, pb->account); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
680 if (conv != NULL) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
681 purple_conversation_write(conv, NULL, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
682 _("Unable to send the message, the conversation couldn't be started."), |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
683 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
684 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
685 close(source); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
686 bonjour_jabber_close_conversation(bb->conversation); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
687 bb->conversation = NULL; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
688 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
689 g_free(stream_start); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
690 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
691 return; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
692 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
693 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
694 bb->conversation->socket = source; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
695 bb->conversation->rx_handler = purple_input_add(source, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
696 PURPLE_INPUT_READ, _client_socket_handler, pb); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
697 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
698 /* This is unlikely to happen */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
699 if (ret < len) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
700 struct _stream_start_data *ss = g_new(struct _stream_start_data, 1); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
701 ss->msg = g_strdup(stream_start + ret); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
702 ss->tx_handler_cb = _send_data_write_cb; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
703 bb->conversation->stream_data = ss; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
704 /* Finish sending the stream start */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
705 bb->conversation->tx_handler = purple_input_add(source, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
706 PURPLE_INPUT_WRITE, _start_stream, pb); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
707 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
708 /* Process the send buffer */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
709 else { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
710 bb->conversation->stream_started = TRUE; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
711 /* Watch for when we can write the buffered messages */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
712 bb->conversation->tx_handler = purple_input_add(source, PURPLE_INPUT_WRITE, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
713 _send_data_write_cb, pb); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
714 /* We can probably write the data now. */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
715 _send_data_write_cb(pb, source, PURPLE_INPUT_WRITE); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
716 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
717 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
718 g_free(stream_start); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
719 } |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
720 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
721 int |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
722 bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
723 { |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
724 xmlnode *message_node, *node, *node2; |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
725 gchar *message; |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
726 PurpleBuddy *pb; |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
727 BonjourBuddy *bb; |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
728 int ret; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
729 |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
730 pb = purple_find_buddy(data->account, to); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
731 if (pb == NULL) { |
17500
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
732 purple_debug_info("bonjour", "Can't send a message to an offline buddy (%s).\n", to); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
733 /* You can not send a message to an offline buddy */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
734 return -10000; |
17500
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
735 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
736 |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
737 bb = pb->proto_data; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
738 |
17500
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
739 /* Check if there is a previously open conversation */ |
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
740 if (bb->conversation == NULL) |
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
741 { |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
742 PurpleProxyConnectData *connect_data; |
17599
bce4211c4980
More robust hack to force Bonjour to use no proxy when directly connecting to buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17558
diff
changeset
|
743 PurpleProxyInfo *proxy_info; |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
744 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
745 /* Make sure that the account always has a proxy of "none". |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
746 * This is kind of dirty, but proxy_connect_none() isn't exposed. */ |
17599
bce4211c4980
More robust hack to force Bonjour to use no proxy when directly connecting to buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17558
diff
changeset
|
747 proxy_info = purple_account_get_proxy_info(data->account); |
bce4211c4980
More robust hack to force Bonjour to use no proxy when directly connecting to buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17558
diff
changeset
|
748 if (proxy_info == NULL) { |
bce4211c4980
More robust hack to force Bonjour to use no proxy when directly connecting to buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17558
diff
changeset
|
749 proxy_info = purple_proxy_info_new(); |
bce4211c4980
More robust hack to force Bonjour to use no proxy when directly connecting to buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17558
diff
changeset
|
750 purple_account_set_proxy_info(data->account, proxy_info); |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
751 } |
17599
bce4211c4980
More robust hack to force Bonjour to use no proxy when directly connecting to buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17558
diff
changeset
|
752 purple_proxy_info_set_type(proxy_info, PURPLE_PROXY_NONE); |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
753 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
754 connect_data = |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
755 purple_proxy_connect(data->account->gc, data->account, bb->ip, |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
756 bb->port_p2pj, _connected_to_buddy, pb); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
757 |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
758 if (connect_data == NULL) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
759 purple_debug_error("bonjour", "Unable to connect to buddy (%s).\n", to); |
17500
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
760 return -10001; |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
761 } |
17500
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
762 |
17556
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
763 bb->conversation = bonjour_jabber_conv_new(); |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
764 bb->conversation->connect_data = connect_data; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
765 /* We don't want _send_data() to register the tx_handler; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
766 * that neeeds to wait until we're actually connected. */ |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
767 bb->conversation->tx_handler = 0; |
17500
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
768 } |
bca2780f7669
Improve error handling while connecting to a bonjour buddy.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17495
diff
changeset
|
769 |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
770 message_node = xmlnode_new("message"); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
771 xmlnode_set_attrib(message_node, "to", bb->name); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
772 xmlnode_set_attrib(message_node, "from", purple_account_get_username(data->account)); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
773 xmlnode_set_attrib(message_node, "type", "chat"); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
774 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
775 /* Enclose the message from the UI within a "font" node */ |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
776 node = xmlnode_new_child(message_node, "body"); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
777 message = purple_markup_strip_html(body); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
778 xmlnode_insert_data(node, message, strlen(message)); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
779 g_free(message); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
780 |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
781 node = xmlnode_new_child(message_node, "html"); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
782 xmlnode_set_namespace(node, "http://www.w3.org/1999/xhtml"); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
783 |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
784 node = xmlnode_new_child(node, "body"); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
785 message = g_strdup_printf("<font>%s</font>", body); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
786 node2 = xmlnode_from_str(message, strlen(message)); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
787 g_free(message); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
788 xmlnode_insert_child(node, node2); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
789 |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
790 node = xmlnode_new_child(message_node, "x"); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
791 xmlnode_set_namespace(node, "jabber:x:event"); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
792 xmlnode_insert_child(node, xmlnode_new("composing")); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
793 |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
794 message = xmlnode_to_str(message_node, NULL); |
15811 | 795 xmlnode_free(message_node); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
796 |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
797 ret = _send_data(pb, message) >= 0; |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
798 |
15811 | 799 g_free(message); |
800 | |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
801 return ret; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
802 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
803 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
804 void |
17556
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
805 bonjour_jabber_close_conversation(BonjourJabberConversation *bconv) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
806 { |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
807 if (bconv != NULL) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
808 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
809 /* Close the socket and remove the watcher */ |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
810 if (bconv->socket >= 0) { |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
811 /* Send the end of the stream to the other end of the conversation */ |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
812 if (bconv->stream_started) |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
813 send(bconv->socket, STREAM_END, strlen(STREAM_END), 0); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
814 /* TODO: We're really supposed to wait for "</stream:stream>" before closing the socket */ |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
815 close(bconv->socket); |
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
816 } |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
817 if (bconv->rx_handler != -1) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
818 purple_input_remove(bconv->rx_handler); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
819 if (bconv->tx_handler > 0) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
820 purple_input_remove(bconv->tx_handler); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
821 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
822 /* Free all the data related to the conversation */ |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
823 purple_circ_buffer_destroy(bconv->tx_buf); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
824 if (bconv->connect_data != NULL) |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
825 purple_proxy_connect_cancel(bconv->connect_data); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
826 if (bconv->stream_data != NULL) { |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
827 struct _stream_start_data *ss = bconv->stream_data; |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
828 g_free(ss->msg); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
829 g_free(ss); |
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
830 } |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
831 g_free(bconv); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
832 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
833 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
834 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
835 void |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
836 bonjour_jabber_stop(BonjourJabber *data) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
837 { |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
838 /* Close the server socket and remove the watcher */ |
17541
a62a695ccfb5
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17500
diff
changeset
|
839 if (data->socket >= 0) |
a62a695ccfb5
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17500
diff
changeset
|
840 close(data->socket); |
a62a695ccfb5
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17500
diff
changeset
|
841 if (data->watcher_id > 0) |
a62a695ccfb5
Improve Bonjour error handling when there are errors "connecting".
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17500
diff
changeset
|
842 purple_input_remove(data->watcher_id); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
843 |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
844 /* Close all the conversation sockets and remove all the watchers after sending end streams */ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
845 if (data->account->gc != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
846 { |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
847 GSList *buddies, *l; |
17542
496d007a8912
Some more Bonjour cleanup and leak fixing.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17541
diff
changeset
|
848 |
17553
61005dea822b
Cleanup, fix a leak and prevent the inbound xml from being parsed twice for every message.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17542
diff
changeset
|
849 buddies = purple_find_buddies(data->account, purple_account_get_username(data->account)); |
17556
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
850 for (l = buddies; l; l = l->next) { |
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
851 BonjourBuddy *bb = ((PurpleBuddy*) l->data)->proto_data; |
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
852 bonjour_jabber_close_conversation(bb->conversation); |
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
853 bb->conversation = NULL; |
612dc5149964
Close conversation connections when logging out of the Bonjour account. This also fixes leakage.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17555
diff
changeset
|
854 } |
17558
6e4e2d234c3a
Update Bonjour to do nonblocking I/O correctly.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
17556
diff
changeset
|
855 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
856 g_slist_free(buddies); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
857 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
858 } |