annotate libpurple/protocols/msn/directconn.c @ 30952:b4285ea42b6e

msn_message_destroy() calls msn_message_unref() if refcount>0. This is always the case. So change all code to call msn_message_unref() directly and change msn_message_destroy to be a private function. This should be more clear.
author Mark Doliner <mark@kingant.net>
date Mon, 22 Nov 2010 07:40:23 +0000
parents 2de522fa534a
children 2f2c45abb3af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * @file directconn.c MSN direct connection functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
4 * purple
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
6 * 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
7 * 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
8 * source distribution.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * 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
11 * 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
12 * 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
13 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * 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
16 * 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
17 * 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
18 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 * 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
21 * along with this program; if not, write to the Free Software
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 18431
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 */
30742
a99b6dcdb60d Remove unnecesary includes from msn.h.
masca@cpw.pidgin.im
parents: 30088
diff changeset
24
30758
230caecf5435 Include internal.h on each c file to avoid windows breakage as recommended by Daniel.
masca@cpw.pidgin.im
parents: 30742
diff changeset
25 #include "internal.h"
30742
a99b6dcdb60d Remove unnecesary includes from msn.h.
masca@cpw.pidgin.im
parents: 30088
diff changeset
26 #include "cipher.h"
a99b6dcdb60d Remove unnecesary includes from msn.h.
masca@cpw.pidgin.im
parents: 30088
diff changeset
27 #include "debug.h"
a99b6dcdb60d Remove unnecesary includes from msn.h.
masca@cpw.pidgin.im
parents: 30088
diff changeset
28
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 #include "msn.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #include "directconn.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include "slp.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 #include "slpmsg.h"
30762
e03f912141dd Start moving p2p specific code to its own module.
masca@cpw.pidgin.im
parents: 30758
diff changeset
34 #include "p2p.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35
30053
56871d6c06fc I've seen packet sizes larger than our current maximum. Hopefully 8KiB is
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30052
diff changeset
36 #define DC_MAX_BODY_SIZE 8*1024
30762
e03f912141dd Start moving p2p specific code to its own module.
masca@cpw.pidgin.im
parents: 30758
diff changeset
37 #define DC_MAX_PACKET_SIZE (P2P_PACKET_HEADER_SIZE + DC_MAX_BODY_SIZE)
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
38
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
39 static void
30041
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
40 msn_dc_calculate_nonce_hash(MsnDirectConnNonceType type,
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
41 const guchar nonce[16], gchar nonce_hash[37])
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 {
30019
bc720282a62d Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30018
diff changeset
43 guchar digest[20];
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44
30041
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
45 if (type == DC_NONCE_SHA1) {
30039
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
46 PurpleCipher *cipher = purple_ciphers_find_cipher("sha1");
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
47 PurpleCipherContext *context = purple_cipher_context_new(cipher, NULL);
30041
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
48 purple_cipher_context_append(context, nonce, sizeof(nonce));
30039
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
49 purple_cipher_context_digest(context, sizeof(digest), digest, NULL);
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
50 purple_cipher_context_destroy(context);
30041
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
51 } else if (type == DC_NONCE_PLAIN) {
30039
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
52 memcpy(digest, nonce, 16);
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
53 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54
30041
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
55 g_sprintf(nonce_hash,
30123
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
56 "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
57
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
58 digest[3],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
59 digest[2],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
60 digest[1],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
61 digest[0],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
62
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
63 digest[5],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
64 digest[4],
30120
ef7303c25751 For some reason, this line creates the following warning:
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30101
diff changeset
65
30123
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
66 digest[7],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
67 digest[6],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
68
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
69 digest[8],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
70 digest[9],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
71
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
72 digest[10],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
73 digest[11],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
74 digest[12],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
75 digest[13],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
76 digest[14],
f7e1d5d397b6 It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30120
diff changeset
77 digest[15]
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
78 );
30041
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
79 }
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
80
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
81 static void
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
82 msn_dc_generate_nonce(MsnDirectConn *dc)
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
83 {
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
84 guint32 *nonce;
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
85 int i;
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
86
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
87 nonce = (guint32 *)&dc->nonce;
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
88 for (i = 0; i < 4; i++)
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
89 nonce[i] = rand();
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
90
3affd3508612 Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30039
diff changeset
91 msn_dc_calculate_nonce_hash(dc->nonce_type, dc->nonce, dc->nonce_hash);
30037
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
92
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
93 if (purple_debug_is_verbose())
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
94 purple_debug_info("msn", "DC %p generated nonce %s\n", dc, dc->nonce_hash);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
95 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96
30022
ca7dec8303cb This DC stuff is a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30021
diff changeset
97 static MsnDirectConnPacket *
30044
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
98 msn_dc_new_packet(guint32 length)
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
99 {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
100 MsnDirectConnPacket *p;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
102 p = g_new0(MsnDirectConnPacket, 1);
30045
63684aa5d6ab The length of a DC packet does not include itself.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30044
diff changeset
103 p->length = length;
30044
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
104 p->data = g_malloc(length);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
106 return p;
15373
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
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
109 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
110 msn_dc_destroy_packet(MsnDirectConnPacket *p)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
111 {
30023
ecd237d3f578 Minor cleanups.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30022
diff changeset
112 g_free(p->data);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
113
30805
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
114 #if 0
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
115 if (p->msg)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
116 msn_message_unref(p->msg);
30805
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
117 #endif
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
118 if (p->part)
30847
74c4aa38adfc Add support to ref/unref SlpMessageParts.
masca@cpw.pidgin.im
parents: 30830
diff changeset
119 msn_slpmsgpart_unref(p->part);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
121 g_free(p);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
122 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
124 MsnDirectConn *
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
125 msn_dc_new(MsnSlpCall *slpcall)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
126 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
127 MsnDirectConn *dc;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
128
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
129 g_return_val_if_fail(slpcall != NULL, NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
130
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
131 dc = g_new0(MsnDirectConn, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132
30024
db0f95b6a2cf Fix typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30023
diff changeset
133 if (purple_debug_is_verbose())
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
134 purple_debug_info("msn", "msn_dc_new %p\n", dc);
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
135
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
136 dc->slplink = slpcall->slplink;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
137 dc->slpcall = slpcall;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
138
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
139 if (dc->slplink->dc != NULL)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
140 purple_debug_warning("msn", "msn_dc_new: slplink already has an allocated DC!\n");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
141
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
142 dc->slplink->dc = dc;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
144 dc->msg_body = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
145 dc->prev_ack = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
146 dc->listen_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
147 dc->connect_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
148 dc->listenfd = -1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
149 dc->listenfd_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
150 dc->connect_timeout_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
151 dc->fd = -1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
152 dc->recv_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
153 dc->send_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
154 dc->state = DC_STATE_CLOSED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
155 dc->in_buffer = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
156 dc->out_queue = g_queue_new();
30044
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
157 dc->msg_pos = -1;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
158 dc->send_connection_info_msg_cb = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
159 dc->ext_ip = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
160 dc->timeout_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
161 dc->progress = FALSE;
30080
3dac28d77320 C comments only.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30079
diff changeset
162 /*dc->num_calls = 1;*/
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163
30039
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
164 /* TODO: Probably should set this based on buddy caps */
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
165 dc->nonce_type = DC_NONCE_PLAIN;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
166 msn_dc_generate_nonce(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
167
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
168 return dc;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
169 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
171 void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
172 msn_dc_destroy(MsnDirectConn *dc)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
173 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
174 MsnSlpLink *slplink;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
175
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
176 if (purple_debug_is_verbose())
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
177 purple_debug_info("msn", "msn_dc_destroy %p\n", dc);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
178
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
179 g_return_if_fail(dc != NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
181 if (dc->slpcall != NULL)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
182 dc->slpcall->wait_for_socket = FALSE;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
183
30088
e432507151d1 NULL-ify some reverse links so that there's no double-free on exit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30080
diff changeset
184 slplink = dc->slplink;
e432507151d1 NULL-ify some reverse links so that there's no double-free on exit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30080
diff changeset
185 if (slplink) {
e432507151d1 NULL-ify some reverse links so that there's no double-free on exit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30080
diff changeset
186 slplink->dc = NULL;
e432507151d1 NULL-ify some reverse links so that there's no double-free on exit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30080
diff changeset
187 if (slplink->swboard == NULL)
30830
e935d15725c3 Hide msn_slplink_destroy and use the unref version everywhere.
masca@cpw.pidgin.im
parents: 30805
diff changeset
188 msn_slplink_unref(slplink);
30088
e432507151d1 NULL-ify some reverse links so that there's no double-free on exit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30080
diff changeset
189 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190
30031
6d1894d0170e NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30024
diff changeset
191 g_free(dc->msg_body);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
192
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
193 if (dc->prev_ack) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
194 msn_slpmsg_destroy(dc->prev_ack);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
197 if (dc->listen_data != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
198 purple_network_listen_cancel(dc->listen_data);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
199 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
200
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
201 if (dc->connect_data != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
202 purple_proxy_connect_cancel(dc->connect_data);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
203 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
204
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
205 if (dc->listenfd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
206 purple_network_remove_port_mapping(dc->listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
207 close(dc->listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
208 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
209
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
210 if (dc->listenfd_handle != 0) {
30064
60ea80b5af53 This is not a timeout, but an input handler.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30063
diff changeset
211 purple_input_remove(dc->listenfd_handle);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
212 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
213
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
214 if (dc->connect_timeout_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
215 purple_timeout_remove(dc->connect_timeout_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
216 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
217
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
218 if (dc->fd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
219 close(dc->fd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
220 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
221
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
222 if (dc->send_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
223 purple_input_remove(dc->send_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
224 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
225
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
226 if (dc->recv_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
227 purple_input_remove(dc->recv_handle);
15373
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
30031
6d1894d0170e NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30024
diff changeset
230 g_free(dc->in_buffer);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
231
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
232 if (dc->out_queue != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
233 while (!g_queue_is_empty(dc->out_queue))
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
234 msn_dc_destroy_packet( g_queue_pop_head(dc->out_queue) );
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
236 g_queue_free(dc->out_queue);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238
30031
6d1894d0170e NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30024
diff changeset
239 g_free(dc->ext_ip);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
241 if (dc->timeout_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
242 purple_timeout_remove(dc->timeout_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
243 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
244
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
245 g_free(dc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
248 /*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
249 void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
250 msn_dc_ref(MsnDirectConn *dc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251 {
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
252 g_return_if_fail(dc != NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
254 dc->num_calls++;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257 void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
258 msn_dc_unref(MsnDirectConn *dc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 {
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
260 g_return_if_fail(dc != NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
262
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
263 if (dc->num_calls > 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
264 dc->num_calls--;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
265 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 }
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
267 */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
270 msn_dc_send_invite(MsnDirectConn *dc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
272 MsnSlpCall *slpcall;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
273 MsnSlpMessage *msg;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
274 gchar *header;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
275
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
276 if (purple_debug_is_verbose())
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
277 purple_debug_info("msn", "msn_dc_send_invite %p\n", dc);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
278
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
279 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
280
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
281 slpcall = dc->slpcall;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
282 g_return_if_fail(slpcall != NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
284 header = g_strdup_printf(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
285 "INVITE MSNMSGR:%s MSNSLP/1.0",
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
286 slpcall->slplink->remote_user
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
287 );
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
288
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
289 msg = msn_slpmsg_sip_new(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
290 slpcall,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
291 0,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
292 header,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
293 slpcall->branch,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
294 "application/x-msnmsgr-transrespbody",
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
295 dc->msg_body
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
296 );
30033
a613180bfeab Set some information for debugging.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30032
diff changeset
297 msg->info = "DC INVITE";
a613180bfeab Set some information for debugging.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30032
diff changeset
298 msg->text_body = TRUE;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
299 g_free(header);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
300 g_free(dc->msg_body);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
301 dc->msg_body = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
303 msn_slplink_queue_slpmsg(slpcall->slplink, msg);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
304 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
305
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
306 void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
307 msn_dc_send_ok(MsnDirectConn *dc)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
308 {
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
309 if (purple_debug_is_verbose())
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
310 purple_debug_info("msn", "msn_dc_send_ok %p\n", dc);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
311
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
312 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
313
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
314 msn_slp_send_ok(dc->slpcall, dc->slpcall->branch,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
315 "application/x-msnmsgr-transrespbody", dc->msg_body);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
316 g_free(dc->msg_body);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
317 dc->msg_body = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
318
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
319 msn_slplink_send_slpmsg(dc->slpcall->slplink, dc->prev_ack);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
320 msn_slpmsg_destroy(dc->prev_ack);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
321 dc->prev_ack = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
322 msn_slplink_send_queued_slpmsgs(dc->slpcall->slplink);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324
30047
6936ffd13cb9 Make msn_dc_fallback_to_p2p non-static, and remove some old code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30045
diff changeset
325 void
30101
7f564cf26ea3 I think it's more accurate to say that a DC is a P2P transfer, so if that
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30088
diff changeset
326 msn_dc_fallback_to_sb(MsnDirectConn *dc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327 {
30067
ccae796bdbad Ref the slplink before destroying the DC, or we might lose our slpcall.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30066
diff changeset
328 MsnSlpLink *slplink;
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
329 MsnSlpCall *slpcall;
30070
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
330 GQueue *queue = NULL;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
331
30101
7f564cf26ea3 I think it's more accurate to say that a DC is a P2P transfer, so if that
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30088
diff changeset
332 purple_debug_info("msn", "msn_dc_fallback_to_sb %p\n", dc);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
333
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
334 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
335
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
336 slpcall = dc->slpcall;
30067
ccae796bdbad Ref the slplink before destroying the DC, or we might lose our slpcall.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30066
diff changeset
337 slplink = msn_slplink_ref(dc->slplink);
30070
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
338 if (slpcall && !g_queue_is_empty(dc->out_queue)) {
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
339 queue = dc->out_queue;
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
340 dc->out_queue = NULL;
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
341 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
342
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
343 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
344
30070
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
345 if (slpcall) {
30066
28f774432954 Use msn_dc_fallback_to_p2p where possible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30064
diff changeset
346 msn_slpcall_session_init(slpcall);
30070
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
347 if (queue) {
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
348 while (!g_queue_is_empty(queue)) {
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
349 MsnDirectConnPacket *p = g_queue_pop_head(queue);
30805
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
350 msn_slplink_send_msgpart(slplink, (MsnSlpMessage*)p->part->ack_data);
30070
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
351 msn_dc_destroy_packet(p);
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
352 }
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
353 g_queue_free(queue);
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
354 }
0b88a1b54475 If there's stuff stuck in the DC queue, then try to send it over the SB if
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30067
diff changeset
355 }
30067
ccae796bdbad Ref the slplink before destroying the DC, or we might lose our slpcall.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30066
diff changeset
356 msn_slplink_unref(slplink);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
357 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
358
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
359 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
360 msn_dc_send_cb(gpointer data, gint fd, PurpleInputCondition cond)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
361 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
362 MsnDirectConn *dc = data;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
363 MsnDirectConnPacket *p;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
364 int bytes_to_send;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
365 int bytes_sent;
19843
60bc06498746 Committing khc's msnp14 changes from Trac Ticket #148. --rlaager
Ka-Hing Cheung <khc@hxbc.us>
parents: 15822
diff changeset
366
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
367 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
368 g_return_if_fail(fd != -1);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
369
30031
6d1894d0170e NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30024
diff changeset
370 if (g_queue_is_empty(dc->out_queue)) {
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
371 if (dc->send_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
372 purple_input_remove(dc->send_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
373 dc->send_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
374 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375 return;
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
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
378 p = g_queue_peek_head(dc->out_queue);
30044
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
379
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
380 if (dc->msg_pos < 0) {
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
381 /* First we send the length of the packet */
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
382 guint32 len = GUINT32_TO_LE(p->length);
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
383 bytes_sent = send(fd, &len, 4, 0);
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
384 if (bytes_sent < 0) {
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
385 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
386 return;
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
387
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
388 purple_debug_warning("msn", "msn_dc_send_cb: send error\n");
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
389 msn_dc_destroy(dc);
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
390 return;
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
391 }
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
392 dc->msg_pos = 0;
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
393 }
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
394
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
395 bytes_to_send = p->length - dc->msg_pos;
30050
99f81d97cbe6 I'm pretty sure we need to actually use dc->msg_pos for something, instead
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30049
diff changeset
396 bytes_sent = send(fd, p->data + dc->msg_pos, bytes_to_send, 0);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
397 if (bytes_sent < 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
398 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
399 return;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
400
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
401 purple_debug_warning("msn", "msn_dc_send_cb: send error\n");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
402 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
403 return;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
406 dc->progress = TRUE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
408 dc->msg_pos += bytes_sent;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
409 if (dc->msg_pos == p->length) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
410 if (p->sent_cb != NULL)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
411 p->sent_cb(p);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
413 g_queue_pop_head(dc->out_queue);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
414 msn_dc_destroy_packet(p);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
415
30044
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
416 dc->msg_pos = -1;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420 static void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
421 msn_dc_enqueue_packet(MsnDirectConn *dc, MsnDirectConnPacket *p)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
422 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
423 gboolean was_empty;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
424
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
425 was_empty = g_queue_is_empty(dc->out_queue);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
426 g_queue_push_tail(dc->out_queue, p);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
428 if (was_empty && dc->send_handle == 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
429 dc->send_handle = purple_input_add(dc->fd, PURPLE_INPUT_WRITE, msn_dc_send_cb, dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
430 msn_dc_send_cb(dc, dc->fd, PURPLE_INPUT_WRITE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433
20578
7c30d5aa5e01 Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20514
diff changeset
434 static void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
435 msn_dc_send_foo(MsnDirectConn *dc)
20578
7c30d5aa5e01 Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20514
diff changeset
436 {
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
437 MsnDirectConnPacket *p;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
438
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
439 if (purple_debug_is_verbose())
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
440 purple_debug_info("msn", "msn_dc_send_foo %p\n", dc);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
441
30044
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
442 p = msn_dc_new_packet(4);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
443
30044
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
444 memcpy(p->data, "foo\0", 4);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
445
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
446 msn_dc_enqueue_packet(dc, p);
20578
7c30d5aa5e01 Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20514
diff changeset
447 }
7c30d5aa5e01 Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20514
diff changeset
448
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
449 static void
30048
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
450 msn_dc_send_handshake_with_nonce(MsnDirectConn *dc, MsnDirectConnPacket *p)
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
451 {
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
452 const gchar *h;
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
453
30775
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
454 h = (gchar*) msn_p2p_header_to_wire(&dc->header);
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
455
30762
e03f912141dd Start moving p2p specific code to its own module.
masca@cpw.pidgin.im
parents: 30758
diff changeset
456 memcpy(p->data, h, P2P_PACKET_HEADER_SIZE);
30048
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
457
30767
e5e712cf9f7e Drop Binary from the struct name.
masca@cpw.pidgin.im
parents: 30765
diff changeset
458 memcpy(p->data + offsetof(MsnP2PHeader, ack_id), dc->nonce, 16);
30048
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
459
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
460 msn_dc_enqueue_packet(dc, p);
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
461 }
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
462
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
463 static void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
464 msn_dc_send_handshake(MsnDirectConn *dc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
466 MsnDirectConnPacket *p;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
467
30762
e03f912141dd Start moving p2p specific code to its own module.
masca@cpw.pidgin.im
parents: 30758
diff changeset
468 p = msn_dc_new_packet(P2P_PACKET_HEADER_SIZE);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
469
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
470 dc->header.session_id = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
471 dc->header.id = dc->slpcall->slplink->slp_seq_id++;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
472 dc->header.offset = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
473 dc->header.total_size = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
474 dc->header.length = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
475 dc->header.flags = 0x100;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
476
30048
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
477 msn_dc_send_handshake_with_nonce(dc, p);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
478 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
480 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
481 msn_dc_send_handshake_reply(MsnDirectConn *dc)
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
482 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
483 MsnDirectConnPacket *p;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
484
30762
e03f912141dd Start moving p2p specific code to its own module.
masca@cpw.pidgin.im
parents: 30758
diff changeset
485 p = msn_dc_new_packet(P2P_PACKET_HEADER_SIZE);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
486
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
487 dc->header.id = dc->slpcall->slplink->slp_seq_id++;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
488 dc->header.length = 0;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489
30048
b491612862dc Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30047
diff changeset
490 msn_dc_send_handshake_with_nonce(dc, p);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
491 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
492
30037
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
493 static gboolean
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
494 msn_dc_verify_handshake(MsnDirectConn *dc, guint32 packet_length)
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
495 {
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
496 guchar nonce[16];
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
497 gchar nonce_hash[37];
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
498
30762
e03f912141dd Start moving p2p specific code to its own module.
masca@cpw.pidgin.im
parents: 30758
diff changeset
499 if (packet_length != P2P_PACKET_HEADER_SIZE)
30037
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
500 return FALSE;
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
501
30767
e5e712cf9f7e Drop Binary from the struct name.
masca@cpw.pidgin.im
parents: 30765
diff changeset
502 memcpy(nonce, dc->in_buffer + 4 + offsetof(MsnP2PHeader, ack_id), 16);
30037
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
503
30049
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
504 if (dc->nonce_type == DC_NONCE_PLAIN) {
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
505 if (memcmp(dc->nonce, nonce, 16) == 0) {
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
506 purple_debug_info("msn",
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
507 "Nonce from buddy request and nonce from DC attempt match, "
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
508 "allowing direct connection\n");
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
509 return TRUE;
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
510 } else {
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
511 purple_debug_warning("msn",
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
512 "Nonce from buddy request and nonce from DC attempt "
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
513 "don't match, ignoring direct connection\n");
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
514 return FALSE;
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
515 }
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
516
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
517 } else if (dc->nonce_type == DC_NONCE_SHA1) {
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
518 msn_dc_calculate_nonce_hash(dc->nonce_type, nonce, nonce_hash);
30037
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
519
30049
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
520 if (g_str_equal(dc->remote_nonce, nonce_hash)) {
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
521 purple_debug_info("msn",
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
522 "Received nonce %s from buddy request "
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
523 "and calculated nonce %s from DC attempt. "
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
524 "Nonces match, allowing direct connection\n",
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
525 dc->remote_nonce, nonce_hash);
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
526 return TRUE;
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
527 } else {
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
528 purple_debug_warning("msn",
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
529 "Received nonce %s from buddy request "
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
530 "and calculated nonce %s from DC attempt. "
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
531 "Nonces don't match, ignoring direct connection\n",
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
532 dc->remote_nonce, nonce_hash);
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
533 return FALSE;
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
534 }
b0a7b31dcc5d I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30048
diff changeset
535 } else
30043
97942038af05 Obviously, if this comparison fails, I should be returning FALSE.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30042
diff changeset
536 return FALSE;
30037
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
537 }
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
538
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
539 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
540 msn_dc_send_packet_cb(MsnDirectConnPacket *p)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
541 {
30805
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
542 if (p->part != NULL && p->part->ack_cb != NULL)
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
543 p->part->ack_cb(p->part, p->part->ack_data);
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
544 }
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
545
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
546 #if 0
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
547 static void
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
548 msn_dc_send_packet_cb(MsnDirectConnPacket *p)
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
549 {
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
550 if (p->msg != NULL && p->msg->ack_cb != NULL)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
551 p->msg->ack_cb(p->msg, p->msg->ack_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
552 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554 void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
555 msn_dc_enqueue_msg(MsnDirectConn *dc, MsnMessage *msg)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
556 {
30044
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
557 MsnDirectConnPacket *p;
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
558 guint32 length;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
559
30762
e03f912141dd Start moving p2p specific code to its own module.
masca@cpw.pidgin.im
parents: 30758
diff changeset
560 length = msg->body_len + P2P_PACKET_HEADER_SIZE;
30044
87854e2529a0 It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30043
diff changeset
561 p = msn_dc_new_packet(length);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
562
30784
320c0852b5cc Drop slp header and footer from MsnMessage in favor of MsnSlpMessage->header and footer.
masca@cpw.pidgin.im
parents: 30779
diff changeset
563 memcpy(p->data, msg->slpmsg->header, P2P_PACKET_HEADER_SIZE);
30762
e03f912141dd Start moving p2p specific code to its own module.
masca@cpw.pidgin.im
parents: 30758
diff changeset
564 memcpy(p->data + P2P_PACKET_HEADER_SIZE, msg->body, msg->body_len);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
565
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
566 p->sent_cb = msn_dc_send_packet_cb;
30023
ecd237d3f578 Minor cleanups.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30022
diff changeset
567 p->msg = msn_message_ref(msg);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
568
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
569 msn_dc_enqueue_packet(dc, p);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
570 }
30805
dfada77da5cb Reomove MsnMessage reference from DirectConn.
masca@cpw.pidgin.im
parents: 30804
diff changeset
571 #endif
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
572
30797
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
573 void
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
574 msn_dc_enqueue_part(MsnDirectConn *dc, MsnSlpMessagePart *part)
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
575 {
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
576 MsnDirectConnPacket *p;
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
577 guint32 length;
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
578
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
579 length = part->size + P2P_PACKET_HEADER_SIZE;
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
580 p = msn_dc_new_packet(length);
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
581
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
582 memcpy(p->data, part->header, P2P_PACKET_HEADER_SIZE);
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
583 memcpy(p->data + P2P_PACKET_HEADER_SIZE, part->buffer, part->size);
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
584
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
585 p->sent_cb = msn_dc_send_packet_cb;
30804
0678ad30aa65 This bit must be migrated too.
masca@cpw.pidgin.im
parents: 30797
diff changeset
586 p->part = part;
30797
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
587
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
588 msn_dc_enqueue_packet(dc, p);
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
589 }
efe9b0338606 Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
masca@cpw.pidgin.im
parents: 30784
diff changeset
590
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
591 static int
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
592 msn_dc_process_packet(MsnDirectConn *dc, guint32 packet_length)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
593 {
30858
2d00d29a45fd Process SlpMessageParts, a sequence of parts will generate a SlpMessage.
masca@cpw.pidgin.im
parents: 30853
diff changeset
594 MsnSlpMessagePart *part;
2d00d29a45fd Process SlpMessageParts, a sequence of parts will generate a SlpMessage.
masca@cpw.pidgin.im
parents: 30853
diff changeset
595
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
596 g_return_val_if_fail(dc != NULL, DC_PROCESS_ERROR);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
597
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
598 switch (dc->state) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
599 case DC_STATE_CLOSED:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
600 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
601
30023
ecd237d3f578 Minor cleanups.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30022
diff changeset
602 case DC_STATE_FOO:
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
603 /* FOO message is always 4 bytes long */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
604 if (packet_length != 4 || memcmp(dc->in_buffer, "\4\0\0\0foo", 8) != 0)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
605 return DC_PROCESS_FALLBACK;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
606
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
607 dc->state = DC_STATE_HANDSHAKE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
608 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
609
30023
ecd237d3f578 Minor cleanups.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30022
diff changeset
610 case DC_STATE_HANDSHAKE:
30037
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
611 if (!msn_dc_verify_handshake(dc, packet_length))
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
612 return DC_PROCESS_FALLBACK;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
613
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
614 msn_dc_send_handshake_reply(dc);
30015
bcb5e6c2e5a3 Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30014
diff changeset
615 dc->state = DC_STATE_ESTABLISHED;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
616
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
617 msn_slpcall_session_init(dc->slpcall);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
618 dc->slpcall = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
619 break;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
620
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
621 case DC_STATE_HANDSHAKE_REPLY:
30037
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
622 if (!msn_dc_verify_handshake(dc, packet_length))
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
623 return DC_PROCESS_FALLBACK;
4e532eedcab4 Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30033
diff changeset
624
30015
bcb5e6c2e5a3 Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30014
diff changeset
625 dc->state = DC_STATE_ESTABLISHED;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
626
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
627 msn_slpcall_session_init(dc->slpcall);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
628 dc->slpcall = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
629 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
630
30015
bcb5e6c2e5a3 Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30014
diff changeset
631 case DC_STATE_ESTABLISHED:
30858
2d00d29a45fd Process SlpMessageParts, a sequence of parts will generate a SlpMessage.
masca@cpw.pidgin.im
parents: 30853
diff changeset
632
30932
dec85cefc758 Don't attempt to process zero-length DC messages. We should probably
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30860
diff changeset
633 if (dc->header.length) {
dec85cefc758 Don't attempt to process zero-length DC messages. We should probably
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30860
diff changeset
634 part = msn_slpmsgpart_new_from_data(dc->in_buffer + 4, dc->header.length);
dec85cefc758 Don't attempt to process zero-length DC messages. We should probably
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30860
diff changeset
635 msn_slplink_process_msg(dc->slplink, part);
30935
2de522fa534a Fix a lot more leaks, some old, some new.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30932
diff changeset
636 msn_slpmsgpart_destroy(part);
30932
dec85cefc758 Don't attempt to process zero-length DC messages. We should probably
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30860
diff changeset
637 }
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
638
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
639 /*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
640 if (dc->num_calls == 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
641 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
642
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
643 return DC_PROCESS_CLOSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
644 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
645 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
646 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
647 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
648
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
649 return DC_PROCESS_OK;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
652 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
653 msn_dc_recv_cb(gpointer data, gint fd, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
655 MsnDirectConn *dc;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
656 int free_buf_space;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
657 int bytes_received;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
658 guint32 packet_length;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
659
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
660 g_return_if_fail(data != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
661 g_return_if_fail(fd != -1);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
662
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
663 dc = data;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
664 free_buf_space = dc->in_size - dc->in_pos;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
665
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
666 bytes_received = recv(fd, dc->in_buffer + dc->in_pos, free_buf_space, 0);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
667 if (bytes_received < 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
668 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
669 return;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
670
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
671 purple_debug_warning("msn", "msn_dc_recv_cb: recv error\n");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
672
30015
bcb5e6c2e5a3 Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30014
diff changeset
673 if(dc->state != DC_STATE_ESTABLISHED)
30101
7f564cf26ea3 I think it's more accurate to say that a DC is a P2P transfer, so if that
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30088
diff changeset
674 msn_dc_fallback_to_sb(dc);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
675 else
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
676 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
677 return;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
678
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
679 } else if (bytes_received == 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
680 /* EOF. Remote side closed connection. */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
681 purple_debug_info("msn", "msn_dc_recv_cb: recv EOF\n");
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
682
30015
bcb5e6c2e5a3 Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30014
diff changeset
683 if(dc->state != DC_STATE_ESTABLISHED)
30101
7f564cf26ea3 I think it's more accurate to say that a DC is a P2P transfer, so if that
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30088
diff changeset
684 msn_dc_fallback_to_sb(dc);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
685 else
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
686 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
687 return;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
688 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
689
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
690 dc->progress = TRUE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
691
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
692 dc->in_pos += bytes_received;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
693
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
694 /* Wait for packet length */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
695 while (dc->in_pos >= 4) {
30053
56871d6c06fc I've seen packet sizes larger than our current maximum. Hopefully 8KiB is
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30052
diff changeset
696 packet_length = GUINT32_FROM_LE(*((guint32*)dc->in_buffer));
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
697
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
698 if (packet_length > DC_MAX_PACKET_SIZE) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
699 /* Oversized packet */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
700 purple_debug_warning("msn", "msn_dc_recv_cb: oversized packet received\n");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
701 return;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
702 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
703
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
704 /* Wait for the whole packet to arrive */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
705 if (dc->in_pos < 4 + packet_length)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
706 return;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
707
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
708 if (dc->state != DC_STATE_FOO) {
30775
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
709 MsnP2PHeader *context;
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
710 MsnP2PHeader *h;
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
711
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
712 /* Skip packet size */
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
713 context = (MsnP2PHeader *)(dc->in_buffer + 4);
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
714
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
715 h = msn_p2p_header_from_wire(context);
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
716 memcpy(&dc->header, h, P2P_PACKET_HEADER_SIZE);
dbe448a9bfa1 Use p2p functions in directconn too.
masca@cpw.pidgin.im
parents: 30767
diff changeset
717 g_free(h);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
718 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
719
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
720 switch (msn_dc_process_packet(dc, packet_length)) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
721 case DC_PROCESS_CLOSE:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
722 return;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
723
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
724 case DC_PROCESS_FALLBACK:
30101
7f564cf26ea3 I think it's more accurate to say that a DC is a P2P transfer, so if that
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30088
diff changeset
725 purple_debug_warning("msn", "msn_dc_recv_cb: packet processing error, fall back to SB\n");
7f564cf26ea3 I think it's more accurate to say that a DC is a P2P transfer, so if that
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30088
diff changeset
726 msn_dc_fallback_to_sb(dc);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
727 return;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
728
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
729 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
730
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
731 if (dc->in_pos > packet_length + 4) {
30054
531fe008410e Valgrind pointed out that dest and src may overlap, so we need to use
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30053
diff changeset
732 g_memmove(dc->in_buffer, dc->in_buffer + 4 + packet_length, dc->in_pos - packet_length - 4);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
733 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
734
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
735 dc->in_pos -= packet_length + 4;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
736 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
737 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
738
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
739 static gboolean
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
740 msn_dc_timeout(gpointer data)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
741 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
742 MsnDirectConn *dc = data;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
743
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
744 g_return_val_if_fail(dc != NULL, FALSE);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
745
30062
783d736704b8 If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30059
diff changeset
746 if (dc->progress) {
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
747 dc->progress = FALSE;
30062
783d736704b8 If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30059
diff changeset
748 return TRUE;
783d736704b8 If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30059
diff changeset
749 } else {
783d736704b8 If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30059
diff changeset
750 dc->timeout_handle = 0;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
751 msn_dc_destroy(dc);
30062
783d736704b8 If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30059
diff changeset
752 return FALSE;
783d736704b8 If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30059
diff changeset
753 }
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
754 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
755
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
756 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
757 msn_dc_init(MsnDirectConn *dc)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
758 {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
759 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
760
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
761 dc->in_size = DC_MAX_PACKET_SIZE + 4;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
762 dc->in_pos = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
763 dc->in_buffer = g_malloc(dc->in_size);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
764
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
765 dc->recv_handle = purple_input_add(dc->fd, PURPLE_INPUT_READ, msn_dc_recv_cb, dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
766 dc->send_handle = purple_input_add(dc->fd, PURPLE_INPUT_WRITE, msn_dc_send_cb, dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
767
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
768 dc->timeout_handle = purple_timeout_add_seconds(DC_TIMEOUT, msn_dc_timeout, dc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
769 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
770
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
771 void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
772 msn_dc_connected_to_peer_cb(gpointer data, gint fd, const gchar *error_msg)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
773 {
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
774 MsnDirectConn *dc = data;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
775
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
776 if (purple_debug_is_verbose())
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
777 purple_debug_info("msn", "msn_dc_connected_to_peer_cb %p\n", dc);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
778
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
779 g_return_if_fail(dc != NULL);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
780
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
781 dc->connect_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
782 purple_timeout_remove(dc->connect_timeout_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
783 dc->connect_timeout_handle = 0;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
784
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
785 dc->fd = fd;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
786 if (dc->fd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
787 msn_dc_init(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
788 msn_dc_send_foo(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
789 msn_dc_send_handshake(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
790 dc->state = DC_STATE_HANDSHAKE_REPLY;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
791 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
792 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
793
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
794 /*
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
795 * This callback will be called when we're the server
30079
1aa1e1e1876d Make it more explicit that incoming and outgoing timeouts are different.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30070
diff changeset
796 * and nobody has connected us in DC_INCOMING_TIMEOUT seconds
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
797 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
798 static gboolean
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
799 msn_dc_incoming_connection_timeout_cb(gpointer data) {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
800 MsnDirectConn *dc = data;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
801
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
802 if (purple_debug_is_verbose())
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
803 purple_debug_info("msn", "msn_dc_incoming_connection_timeout_cb %p\n", dc);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
804
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
805 g_return_val_if_fail(dc != NULL, FALSE);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
806
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
807 if (dc->listen_data != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
808 purple_network_listen_cancel(dc->listen_data);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
809 dc->listen_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
810 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
811
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
812 if (dc->listenfd_handle != 0) {
30064
60ea80b5af53 This is not a timeout, but an input handler.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30063
diff changeset
813 purple_input_remove(dc->listenfd_handle);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
814 dc->listenfd_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
815 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
816
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
817 if (dc->listenfd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
818 purple_network_remove_port_mapping(dc->listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
819 close(dc->listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
820 dc->listenfd = -1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
821 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
822
30056
f0de96a35877 This should probably work a bit better. At least, we want to get rid of any
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30054
diff changeset
823 dc->connect_timeout_handle = 0;
30101
7f564cf26ea3 I think it's more accurate to say that a DC is a P2P transfer, so if that
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30088
diff changeset
824 msn_dc_fallback_to_sb(dc);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
825
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
826 return FALSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
827 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
828
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
829 /*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
830 * This callback will be called when we're unable to connect to
30079
1aa1e1e1876d Make it more explicit that incoming and outgoing timeouts are different.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30070
diff changeset
831 * the remote host in DC_OUTGOING_TIMEOUT seconds.
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
832 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
833 gboolean
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
834 msn_dc_outgoing_connection_timeout_cb(gpointer data)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
835 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
836 MsnDirectConn *dc = data;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
837
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
838 purple_debug_info("msn", "msn_dc_outgoing_connection_timeout_cb %p\n", dc);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
839
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
840 g_return_val_if_fail(dc != NULL, FALSE);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
841
30059
a6642358155b We can't both remove a timeout and return FALSE in its callback.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30056
diff changeset
842 dc->connect_timeout_handle = 0;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
843
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
844 if (dc->connect_data != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
845 purple_proxy_connect_cancel(dc->connect_data);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
846 dc->connect_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
847 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
848
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
849 if (dc->ext_ip && dc->ext_port) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
850 /* Try external IP/port if available. */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
851 dc->connect_data = purple_proxy_connect(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
852 NULL,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
853 dc->slpcall->slplink->session->account,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
854 dc->ext_ip,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
855 dc->ext_port,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
856 msn_dc_connected_to_peer_cb,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
857 dc
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
858 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
859
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
860 g_free(dc->ext_ip);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
861 dc->ext_ip = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
862
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
863 if (dc->connect_data) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
864 dc->connect_timeout_handle = purple_timeout_add_seconds(
30079
1aa1e1e1876d Make it more explicit that incoming and outgoing timeouts are different.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30070
diff changeset
865 DC_OUTGOING_TIMEOUT,
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
866 msn_dc_outgoing_connection_timeout_cb,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
867 dc
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
868 );
30063
0662e5baada0 Fallback to P2P if connecting to external IP didn't work immediately.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30062
diff changeset
869 } else {
0662e5baada0 Fallback to P2P if connecting to external IP didn't work immediately.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30062
diff changeset
870 /*
0662e5baada0 Fallback to P2P if connecting to external IP didn't work immediately.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30062
diff changeset
871 * Connection failed
30101
7f564cf26ea3 I think it's more accurate to say that a DC is a P2P transfer, so if that
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30088
diff changeset
872 * Fall back to SB transfer
30063
0662e5baada0 Fallback to P2P if connecting to external IP didn't work immediately.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30062
diff changeset
873 */
0662e5baada0 Fallback to P2P if connecting to external IP didn't work immediately.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30062
diff changeset
874 msn_dc_outgoing_connection_timeout_cb(dc);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
875 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
876
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
877 } else {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
878 /*
30059
a6642358155b We can't both remove a timeout and return FALSE in its callback.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30056
diff changeset
879 * Both internal and external connection attempts failed.
30101
7f564cf26ea3 I think it's more accurate to say that a DC is a P2P transfer, so if that
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30088
diff changeset
880 * Fall back to SB transfer.
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
881 */
30101
7f564cf26ea3 I think it's more accurate to say that a DC is a P2P transfer, so if that
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30088
diff changeset
882 msn_dc_fallback_to_sb(dc);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
883 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
884
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
885 return FALSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
886 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
887
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
888 /*
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
889 * This callback will be called when we're the server
30079
1aa1e1e1876d Make it more explicit that incoming and outgoing timeouts are different.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30070
diff changeset
890 * and somebody has connected to us in DC_INCOMING_TIMEOUT seconds.
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
891 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
892 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
893 msn_dc_incoming_connection_cb(gpointer data, gint listenfd, PurpleInputCondition cond)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
894 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
895 MsnDirectConn *dc = data;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
896
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
897 if (purple_debug_is_verbose())
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
898 purple_debug_info("msn", "msn_dc_incoming_connection_cb %p\n", dc);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
899
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
900 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
901
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
902 if (dc->connect_timeout_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
903 purple_timeout_remove(dc->connect_timeout_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
904 dc->connect_timeout_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
905 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
906
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
907 if (dc->listenfd_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
908 purple_input_remove(dc->listenfd_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
909 dc->listenfd_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
910 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
911
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
912 dc->fd = accept(listenfd, NULL, 0);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
913
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
914 purple_network_remove_port_mapping(dc->listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
915 close(dc->listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
916 dc->listenfd = -1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
917
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
918 if (dc->fd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
919 msn_dc_init(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
920 dc->state = DC_STATE_FOO;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
921 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
922 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
923
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
924 void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
925 msn_dc_listen_socket_created_cb(int listenfd, gpointer data)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
926 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
927 MsnDirectConn *dc = data;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
928
30021
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
929 if (purple_debug_is_verbose())
24579d001831 This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30020
diff changeset
930 purple_debug_info("msn", "msn_dc_listen_socket_created_cb %p\n", dc);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
931
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
932 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
933
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
934 dc->listen_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
935
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
936 if (listenfd != -1) {
30031
6d1894d0170e NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30024
diff changeset
937 const char *ext_ip;
6d1894d0170e NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30024
diff changeset
938 const char *int_ip;
6d1894d0170e NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30024
diff changeset
939 int port;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
940
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
941 ext_ip = purple_network_get_my_ip(listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
942 int_ip = purple_network_get_local_system_ip(listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
943 port = purple_network_get_port_from_fd(listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
944
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
945 dc->listenfd = listenfd;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
946 dc->listenfd_handle = purple_input_add(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
947 listenfd,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
948 PURPLE_INPUT_READ,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
949 msn_dc_incoming_connection_cb,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
950 dc
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
951 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
952 dc->connect_timeout_handle = purple_timeout_add_seconds(
30079
1aa1e1e1876d Make it more explicit that incoming and outgoing timeouts are different.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30070
diff changeset
953 DC_INCOMING_TIMEOUT,
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
954 msn_dc_incoming_connection_timeout_cb,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
955 dc
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
956 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
957
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
958 if (strcmp(int_ip, ext_ip) != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
959 dc->msg_body = g_strdup_printf(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
960 "Bridge: TCPv1\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
961 "Listening: true\r\n"
30039
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
962 "%sNonce: {%s}\r\n"
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
963 "IPv4External-Addrs: %s\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
964 "IPv4External-Port: %d\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
965 "IPv4Internal-Addrs: %s\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
966 "IPv4Internal-Port: %d\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
967 "\r\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
968
30039
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
969 dc->nonce_type != DC_NONCE_PLAIN ? "Hashed-" : "",
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
970 dc->nonce_hash,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
971 ext_ip,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
972 port,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
973 int_ip,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
974 port
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
975 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
976
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
977 } else {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
978 dc->msg_body = g_strdup_printf(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
979 "Bridge: TCPv1\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
980 "Listening: true\r\n"
30039
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
981 "%sNonce: {%s}\r\n"
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
982 "IPv4External-Addrs: %s\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
983 "IPv4External-Port: %d\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
984 "\r\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
985
30039
a97d60c15e25 Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30037
diff changeset
986 dc->nonce_type != DC_NONCE_PLAIN ? "Hashed-" : "",
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
987 dc->nonce_hash,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
988 ext_ip,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
989 port
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
990 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
991 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
992
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
993 if (dc->slpcall->wait_for_socket) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
994 if (dc->send_connection_info_msg_cb != NULL)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
995 dc->send_connection_info_msg_cb(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
996
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
997 dc->slpcall->wait_for_socket = FALSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
998 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
999 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1000 }
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1001