Sun, 24 Feb 2013 16:45:13 -0500
msn: Fix hash calculation for SHA1 nonce hashes
* I think the effect of this being broken is that the direct connect handshake
would never succeed if the other party was using sha1 hashes (I don't know if
that actually ever happens).
* CID 731945
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
1 | /** |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
2 | * @file directconn.c MSN direct connection functions |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
3 | * |
| 15884 | 4 | * purple |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
5 | * |
| 15884 | 6 | * Purple is the legal property of its developers, whose names are too numerous |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 | * source distribution. |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
9 | * |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
10 | * This program is free software; you can redistribute it and/or modify |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
11 | * it under the terms of the GNU General Public License as published by |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
12 | * the Free Software Foundation; either version 2 of the License, or |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
13 | * (at your option) any later version. |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
14 | * |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
15 | * This program is distributed in the hope that it will be useful, |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
18 | * GNU General Public License for more details. |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
19 | * |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
20 | * You should have received a copy of the GNU General Public License |
|
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
21 | * along with this program; if not, write to the Free Software |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18610
diff
changeset
|
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
9198
e8eb6d5eb9eb
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
23 | */ |
|
30945
b875cf477e19
Remove unnecesary includes from msn.h.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30336
diff
changeset
|
24 | |
|
30961
885064b16c54
Include internal.h on each c file to avoid windows breakage as recommended by Daniel.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30945
diff
changeset
|
25 | #include "internal.h" |
|
30945
b875cf477e19
Remove unnecesary includes from msn.h.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30336
diff
changeset
|
26 | #include "cipher.h" |
|
b875cf477e19
Remove unnecesary includes from msn.h.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30336
diff
changeset
|
27 | #include "debug.h" |
|
b875cf477e19
Remove unnecesary includes from msn.h.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30336
diff
changeset
|
28 | |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
29 | #include "msn.h" |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
30 | #include "msnutils.h" |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
31 | #include "directconn.h" |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
32 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
33 | #include "slp.h" |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
34 | #include "slpmsg.h" |
|
30966
c9d0661c74ed
Start moving p2p specific code to its own module.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30961
diff
changeset
|
35 | #include "p2p.h" |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
36 | |
|
30106
142f2a062877
I've seen packet sizes larger than our current maximum. Hopefully 8KiB is
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30105
diff
changeset
|
37 | #define DC_MAX_BODY_SIZE 8*1024 |
|
30966
c9d0661c74ed
Start moving p2p specific code to its own module.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30961
diff
changeset
|
38 | #define DC_MAX_PACKET_SIZE (P2P_PACKET_HEADER_SIZE + DC_MAX_BODY_SIZE) |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
39 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
40 | static void |
|
30094
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
41 | msn_dc_calculate_nonce_hash(MsnDirectConnNonceType type, |
|
33785
502a383ea856
msn: Fix hash calculation for SHA1 nonce hashes
Daniel Atallah <datallah@pidgin.im>
parents:
31803
diff
changeset
|
42 | const guchar *nonce, gsize nonce_len, gchar nonce_hash[37]) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
43 | { |
|
30072
0564e70bd919
Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30071
diff
changeset
|
44 | guchar digest[20]; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
45 | |
|
30094
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
46 | if (type == DC_NONCE_SHA1) { |
|
30092
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
47 | PurpleCipher *cipher = purple_ciphers_find_cipher("sha1"); |
|
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
48 | PurpleCipherContext *context = purple_cipher_context_new(cipher, NULL); |
|
33785
502a383ea856
msn: Fix hash calculation for SHA1 nonce hashes
Daniel Atallah <datallah@pidgin.im>
parents:
31803
diff
changeset
|
49 | purple_cipher_context_append(context, nonce, nonce_len); |
|
30092
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
50 | purple_cipher_context_digest(context, sizeof(digest), digest, NULL); |
|
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
51 | purple_cipher_context_destroy(context); |
|
30094
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
52 | } else if (type == DC_NONCE_PLAIN) { |
|
33785
502a383ea856
msn: Fix hash calculation for SHA1 nonce hashes
Daniel Atallah <datallah@pidgin.im>
parents:
31803
diff
changeset
|
53 | memcpy(digest, nonce, nonce_len); |
|
31803
3f10f8ceca66
msn: Avoid reading uninit memory.
Paul Aurich <darkrain42@pidgin.im>
parents:
31790
diff
changeset
|
54 | } else { |
|
3f10f8ceca66
msn: Avoid reading uninit memory.
Paul Aurich <darkrain42@pidgin.im>
parents:
31790
diff
changeset
|
55 | nonce_hash[0] = '\0'; |
|
3f10f8ceca66
msn: Avoid reading uninit memory.
Paul Aurich <darkrain42@pidgin.im>
parents:
31790
diff
changeset
|
56 | g_return_if_reached(); |
|
30092
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
57 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
58 | |
|
30094
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
59 | g_sprintf(nonce_hash, |
|
30376
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
60 | "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
61 | |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
62 | digest[3], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
63 | digest[2], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
64 | digest[1], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
65 | digest[0], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
66 | |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
67 | digest[5], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
68 | digest[4], |
|
30373
015cf7cacf23
For some reason, this line creates the following warning:
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30349
diff
changeset
|
69 | |
|
30376
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
70 | digest[7], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
71 | digest[6], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
72 | |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
73 | digest[8], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
74 | digest[9], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
75 | |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
76 | digest[10], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
77 | digest[11], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
78 | digest[12], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
79 | digest[13], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
80 | digest[14], |
|
50d2c4e03154
It's probably best just to be explicit about the ordering here.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30373
diff
changeset
|
81 | digest[15] |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
82 | ); |
|
30094
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
83 | } |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
84 | |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
85 | static void |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
86 | msn_dc_generate_nonce(MsnDirectConn *dc) |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
87 | { |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
88 | guint32 *nonce; |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
89 | int i; |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
90 | |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
91 | nonce = (guint32 *)&dc->nonce; |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
92 | for (i = 0; i < 4; i++) |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
93 | nonce[i] = rand(); |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
94 | |
|
33785
502a383ea856
msn: Fix hash calculation for SHA1 nonce hashes
Daniel Atallah <datallah@pidgin.im>
parents:
31803
diff
changeset
|
95 | msn_dc_calculate_nonce_hash(dc->nonce_type, dc->nonce, sizeof(dc->nonce), dc->nonce_hash); |
|
30090
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
96 | |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
97 | if (purple_debug_is_verbose()) |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
98 | purple_debug_info("msn", "DC %p generated nonce %s\n", dc, dc->nonce_hash); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
99 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
100 | |
|
30075
381b22b5bd49
This DC stuff is a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30074
diff
changeset
|
101 | static MsnDirectConnPacket * |
|
30097
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
102 | msn_dc_new_packet(guint32 length) |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
103 | { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
104 | MsnDirectConnPacket *p; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
105 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
106 | p = g_new0(MsnDirectConnPacket, 1); |
|
30098
b18dd95fe141
The length of a DC packet does not include itself.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30097
diff
changeset
|
107 | p->length = length; |
|
30097
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
108 | p->data = g_malloc(length); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
109 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
110 | return p; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
111 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
112 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
113 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
114 | msn_dc_destroy_packet(MsnDirectConnPacket *p) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
115 | { |
|
30076
2b751385616f
Minor cleanups.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30075
diff
changeset
|
116 | g_free(p->data); |
| 30067 | 117 | |
|
31007
336b38bb5876
Reomove MsnMessage reference from DirectConn.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31006
diff
changeset
|
118 | if (p->part) |
|
31049
22a86713164e
Add support to ref/unref SlpMessageParts.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31032
diff
changeset
|
119 | msn_slpmsgpart_unref(p->part); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
120 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
121 | g_free(p); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
122 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
123 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
124 | MsnDirectConn * |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
125 | msn_dc_new(MsnSlpCall *slpcall) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
126 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
127 | MsnDirectConn *dc; |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
128 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
129 | g_return_val_if_fail(slpcall != NULL, NULL); |
| 30067 | 130 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
131 | dc = g_new0(MsnDirectConn, 1); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
132 | |
| 30077 | 133 | if (purple_debug_is_verbose()) |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
134 | purple_debug_info("msn", "msn_dc_new %p\n", dc); |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
135 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
136 | dc->slplink = slpcall->slplink; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
137 | dc->slpcall = slpcall; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
138 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
139 | if (dc->slplink->dc != NULL) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
140 | purple_debug_warning("msn", "msn_dc_new: slplink already has an allocated DC!\n"); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
141 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
142 | dc->slplink->dc = dc; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
143 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
144 | dc->msg_body = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
145 | dc->prev_ack = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
146 | dc->listen_data = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
147 | dc->connect_data = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
148 | dc->listenfd = -1; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
149 | dc->listenfd_handle = 0; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
150 | dc->connect_timeout_handle = 0; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
151 | dc->fd = -1; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
152 | dc->recv_handle = 0; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
153 | dc->send_handle = 0; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
154 | dc->state = DC_STATE_CLOSED; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
155 | dc->in_buffer = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
156 | dc->out_queue = g_queue_new(); |
|
30097
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
157 | dc->msg_pos = -1; |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
158 | dc->send_connection_info_msg_cb = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
159 | dc->ext_ip = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
160 | dc->timeout_handle = 0; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
161 | dc->progress = FALSE; |
|
30328
fe6e047b9f85
C comments only.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30327
diff
changeset
|
162 | /*dc->num_calls = 1;*/ |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
163 | |
|
30092
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
164 | /* TODO: Probably should set this based on buddy caps */ |
|
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
165 | dc->nonce_type = DC_NONCE_PLAIN; |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
166 | msn_dc_generate_nonce(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
167 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
168 | return dc; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
169 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
170 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
171 | void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
172 | msn_dc_destroy(MsnDirectConn *dc) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
173 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
174 | MsnSlpLink *slplink; |
| 30067 | 175 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
176 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
177 | purple_debug_info("msn", "msn_dc_destroy %p\n", dc); |
| 30067 | 178 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
179 | g_return_if_fail(dc != NULL); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
180 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
181 | if (dc->slpcall != NULL) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
182 | dc->slpcall->wait_for_socket = FALSE; |
| 30067 | 183 | |
|
30336
cec8b3660981
NULL-ify some reverse links so that there's no double-free on exit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30328
diff
changeset
|
184 | slplink = dc->slplink; |
|
cec8b3660981
NULL-ify some reverse links so that there's no double-free on exit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30328
diff
changeset
|
185 | if (slplink) { |
|
cec8b3660981
NULL-ify some reverse links so that there's no double-free on exit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30328
diff
changeset
|
186 | slplink->dc = NULL; |
|
cec8b3660981
NULL-ify some reverse links so that there's no double-free on exit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30328
diff
changeset
|
187 | if (slplink->swboard == NULL) |
|
31032
b25150599f00
Hide msn_slplink_destroy and use the unref version everywhere.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31007
diff
changeset
|
188 | msn_slplink_unref(slplink); |
|
30336
cec8b3660981
NULL-ify some reverse links so that there's no double-free on exit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30328
diff
changeset
|
189 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
190 | |
|
30084
57ef011cbce0
NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30077
diff
changeset
|
191 | g_free(dc->msg_body); |
| 30067 | 192 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
193 | if (dc->prev_ack) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
194 | msn_slpmsg_destroy(dc->prev_ack); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
195 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
196 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
197 | if (dc->listen_data != NULL) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
198 | purple_network_listen_cancel(dc->listen_data); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
199 | } |
| 30067 | 200 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
201 | if (dc->connect_data != NULL) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
202 | purple_proxy_connect_cancel(dc->connect_data); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
203 | } |
| 30067 | 204 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
205 | if (dc->listenfd != -1) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
206 | purple_network_remove_port_mapping(dc->listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
207 | close(dc->listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
208 | } |
| 30067 | 209 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
210 | if (dc->listenfd_handle != 0) { |
|
30256
669f8bc11d33
This is not a timeout, but an input handler.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30255
diff
changeset
|
211 | purple_input_remove(dc->listenfd_handle); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
212 | } |
| 30067 | 213 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
214 | if (dc->connect_timeout_handle != 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
215 | purple_timeout_remove(dc->connect_timeout_handle); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
216 | } |
| 30067 | 217 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
218 | if (dc->fd != -1) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
219 | close(dc->fd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
220 | } |
| 30067 | 221 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
222 | if (dc->send_handle != 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
223 | purple_input_remove(dc->send_handle); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
224 | } |
| 30067 | 225 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
226 | if (dc->recv_handle != 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
227 | purple_input_remove(dc->recv_handle); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
228 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
229 | |
|
30084
57ef011cbce0
NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30077
diff
changeset
|
230 | g_free(dc->in_buffer); |
| 30067 | 231 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
232 | if (dc->out_queue != NULL) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
233 | while (!g_queue_is_empty(dc->out_queue)) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
234 | msn_dc_destroy_packet( g_queue_pop_head(dc->out_queue) ); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
235 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
236 | g_queue_free(dc->out_queue); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
237 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
238 | |
|
30084
57ef011cbce0
NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30077
diff
changeset
|
239 | g_free(dc->ext_ip); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
240 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
241 | if (dc->timeout_handle != 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
242 | purple_timeout_remove(dc->timeout_handle); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
243 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
244 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
245 | g_free(dc); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
246 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
247 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
248 | /* |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
249 | void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
250 | msn_dc_ref(MsnDirectConn *dc) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
251 | { |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
252 | g_return_if_fail(dc != NULL); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
253 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
254 | dc->num_calls++; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
255 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
256 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
257 | void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
258 | msn_dc_unref(MsnDirectConn *dc) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
259 | { |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
260 | g_return_if_fail(dc != NULL); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
261 | |
| 30067 | 262 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
263 | if (dc->num_calls > 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
264 | dc->num_calls--; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
265 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
266 | } |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
267 | */ |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
268 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
269 | void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
270 | msn_dc_send_invite(MsnDirectConn *dc) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
271 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
272 | MsnSlpCall *slpcall; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
273 | MsnSlpMessage *msg; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
274 | gchar *header; |
| 30067 | 275 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
276 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
277 | purple_debug_info("msn", "msn_dc_send_invite %p\n", dc); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
278 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
279 | g_return_if_fail(dc != NULL); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
280 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
281 | slpcall = dc->slpcall; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
282 | g_return_if_fail(slpcall != NULL); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
283 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
284 | header = g_strdup_printf( |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
285 | "INVITE MSNMSGR:%s MSNSLP/1.0", |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
286 | slpcall->slplink->remote_user |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
287 | ); |
| 30067 | 288 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
289 | msg = msn_slpmsg_sip_new( |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
290 | slpcall, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
291 | 0, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
292 | header, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
293 | slpcall->branch, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
294 | "application/x-msnmsgr-transrespbody", |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
295 | dc->msg_body |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
296 | ); |
|
30086
32109706f5ec
Set some information for debugging.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30085
diff
changeset
|
297 | msg->info = "DC INVITE"; |
|
32109706f5ec
Set some information for debugging.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30085
diff
changeset
|
298 | msg->text_body = TRUE; |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
299 | g_free(header); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
300 | g_free(dc->msg_body); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
301 | dc->msg_body = NULL; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
302 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
303 | msn_slplink_queue_slpmsg(slpcall->slplink, msg); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
304 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
305 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
306 | void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
307 | msn_dc_send_ok(MsnDirectConn *dc) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
308 | { |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
309 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
310 | purple_debug_info("msn", "msn_dc_send_ok %p\n", dc); |
| 30067 | 311 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
312 | g_return_if_fail(dc != NULL); |
| 30067 | 313 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
314 | msn_slp_send_ok(dc->slpcall, dc->slpcall->branch, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
315 | "application/x-msnmsgr-transrespbody", dc->msg_body); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
316 | g_free(dc->msg_body); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
317 | dc->msg_body = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
318 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
319 | msn_slplink_send_slpmsg(dc->slpcall->slplink, dc->prev_ack); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
320 | msn_slpmsg_destroy(dc->prev_ack); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
321 | dc->prev_ack = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
322 | msn_slplink_send_queued_slpmsgs(dc->slpcall->slplink); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
323 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
324 | |
|
30100
3382aeef1a88
Make msn_dc_fallback_to_p2p non-static, and remove some old code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30098
diff
changeset
|
325 | void |
|
30349
26be44d0f764
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:
30336
diff
changeset
|
326 | msn_dc_fallback_to_sb(MsnDirectConn *dc) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
327 | { |
|
30315
04efebd0545a
Ref the slplink before destroying the DC, or we might lose our slpcall.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30314
diff
changeset
|
328 | MsnSlpLink *slplink; |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
329 | MsnSlpCall *slpcall; |
|
30318
16ea090fa7ea
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:
30315
diff
changeset
|
330 | GQueue *queue = NULL; |
| 30067 | 331 | |
|
30349
26be44d0f764
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:
30336
diff
changeset
|
332 | purple_debug_info("msn", "msn_dc_fallback_to_sb %p\n", dc); |
| 30067 | 333 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
334 | g_return_if_fail(dc != NULL); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
335 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
336 | slpcall = dc->slpcall; |
|
30315
04efebd0545a
Ref the slplink before destroying the DC, or we might lose our slpcall.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30314
diff
changeset
|
337 | slplink = msn_slplink_ref(dc->slplink); |
|
30318
16ea090fa7ea
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:
30315
diff
changeset
|
338 | if (slpcall && !g_queue_is_empty(dc->out_queue)) { |
|
16ea090fa7ea
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:
30315
diff
changeset
|
339 | queue = dc->out_queue; |
|
16ea090fa7ea
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:
30315
diff
changeset
|
340 | dc->out_queue = NULL; |
|
16ea090fa7ea
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:
30315
diff
changeset
|
341 | } |
| 30067 | 342 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
343 | msn_dc_destroy(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
344 | |
|
30318
16ea090fa7ea
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:
30315
diff
changeset
|
345 | if (slpcall) { |
|
30314
72174fad31d8
Use msn_dc_fallback_to_p2p where possible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30256
diff
changeset
|
346 | msn_slpcall_session_init(slpcall); |
|
30318
16ea090fa7ea
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:
30315
diff
changeset
|
347 | if (queue) { |
|
16ea090fa7ea
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:
30315
diff
changeset
|
348 | while (!g_queue_is_empty(queue)) { |
|
16ea090fa7ea
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:
30315
diff
changeset
|
349 | MsnDirectConnPacket *p = g_queue_pop_head(queue); |
|
31007
336b38bb5876
Reomove MsnMessage reference from DirectConn.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31006
diff
changeset
|
350 | msn_slplink_send_msgpart(slplink, (MsnSlpMessage*)p->part->ack_data); |
|
30318
16ea090fa7ea
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:
30315
diff
changeset
|
351 | msn_dc_destroy_packet(p); |
|
16ea090fa7ea
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:
30315
diff
changeset
|
352 | } |
|
16ea090fa7ea
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:
30315
diff
changeset
|
353 | g_queue_free(queue); |
|
16ea090fa7ea
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:
30315
diff
changeset
|
354 | } |
|
16ea090fa7ea
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:
30315
diff
changeset
|
355 | } |
|
30315
04efebd0545a
Ref the slplink before destroying the DC, or we might lose our slpcall.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30314
diff
changeset
|
356 | msn_slplink_unref(slplink); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
357 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
358 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
359 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
360 | msn_dc_send_cb(gpointer data, gint fd, PurpleInputCondition cond) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
361 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
362 | MsnDirectConn *dc = data; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
363 | MsnDirectConnPacket *p; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
364 | int bytes_to_send; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
365 | int bytes_sent; |
|
20473
91e1b3a49d10
msn.tgz from SF Patch #1621854 from Ka-Hing Cheung
Ka-Hing Cheung <khc@pidgin.im>
parents:
20472
diff
changeset
|
366 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
367 | g_return_if_fail(dc != NULL); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
368 | g_return_if_fail(fd != -1); |
| 30067 | 369 | |
|
30084
57ef011cbce0
NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30077
diff
changeset
|
370 | if (g_queue_is_empty(dc->out_queue)) { |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
371 | if (dc->send_handle != 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
372 | purple_input_remove(dc->send_handle); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
373 | dc->send_handle = 0; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
374 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
375 | return; |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
376 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
377 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
378 | p = g_queue_peek_head(dc->out_queue); |
|
30097
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
379 | |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
380 | if (dc->msg_pos < 0) { |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
381 | /* First we send the length of the packet */ |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
382 | guint32 len = GUINT32_TO_LE(p->length); |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
383 | bytes_sent = send(fd, &len, 4, 0); |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
384 | if (bytes_sent < 0) { |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
385 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
386 | return; |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
387 | |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
388 | purple_debug_warning("msn", "msn_dc_send_cb: send error\n"); |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
389 | msn_dc_destroy(dc); |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
390 | return; |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
391 | } |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
392 | dc->msg_pos = 0; |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
393 | } |
|
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
394 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
395 | bytes_to_send = p->length - dc->msg_pos; |
|
30103
123a1c4a914b
I'm pretty sure we need to actually use dc->msg_pos for something, instead
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30102
diff
changeset
|
396 | bytes_sent = send(fd, p->data + dc->msg_pos, bytes_to_send, 0); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
397 | if (bytes_sent < 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
398 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
399 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
400 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
401 | purple_debug_warning("msn", "msn_dc_send_cb: send error\n"); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
402 | msn_dc_destroy(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
403 | return; |
|
10899
87d9aec5b72d
[gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10589
diff
changeset
|
404 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
405 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
406 | dc->progress = TRUE; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
407 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
408 | dc->msg_pos += bytes_sent; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
409 | if (dc->msg_pos == p->length) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
410 | if (p->sent_cb != NULL) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
411 | p->sent_cb(p); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
412 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
413 | g_queue_pop_head(dc->out_queue); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
414 | msn_dc_destroy_packet(p); |
| 30067 | 415 | |
|
30097
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
416 | dc->msg_pos = -1; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
417 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
418 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
419 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
420 | static void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
421 | msn_dc_enqueue_packet(MsnDirectConn *dc, MsnDirectConnPacket *p) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
422 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
423 | gboolean was_empty; |
| 30067 | 424 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
425 | was_empty = g_queue_is_empty(dc->out_queue); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
426 | g_queue_push_tail(dc->out_queue, p); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
427 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
428 | if (was_empty && dc->send_handle == 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
429 | dc->send_handle = purple_input_add(dc->fd, PURPLE_INPUT_WRITE, msn_dc_send_cb, dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
430 | msn_dc_send_cb(dc, dc->fd, PURPLE_INPUT_WRITE); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
431 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
432 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
433 | |
|
20646
69768ff2194a
Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
434 | static void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
435 | msn_dc_send_foo(MsnDirectConn *dc) |
|
20646
69768ff2194a
Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
436 | { |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
437 | MsnDirectConnPacket *p; |
| 30067 | 438 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
439 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
440 | purple_debug_info("msn", "msn_dc_send_foo %p\n", dc); |
| 30067 | 441 | |
|
30097
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
442 | p = msn_dc_new_packet(4); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
443 | |
|
30097
581f70ecbc24
It seems like every DC packet requires a length, so why make every little
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30096
diff
changeset
|
444 | memcpy(p->data, "foo\0", 4); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
445 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
446 | msn_dc_enqueue_packet(dc, p); |
|
20646
69768ff2194a
Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
447 | } |
|
69768ff2194a
Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
448 | |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
449 | #if 0 /* We don't actually need this */ |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
450 | typedef struct { |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
451 | guint32 null; |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
452 | guint32 id; |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
453 | guint32 null[5]; |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
454 | guint32 flags; |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
455 | guint8 nonce[16]; |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
456 | } MsnDirectConnNoncePacket; |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
457 | #endif |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
458 | #define DC_NONCE_PACKET_SIZE (8 * 4 + 16) |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
459 | #define DC_NONCE_PACKET_NONCE (8 * 4) |
|
30101
a0bfbebab591
Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30100
diff
changeset
|
460 | |
|
a0bfbebab591
Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30100
diff
changeset
|
461 | static void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
462 | msn_dc_send_handshake(MsnDirectConn *dc) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
463 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
464 | MsnDirectConnPacket *p; |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
465 | gchar *h; |
| 30067 | 466 | |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
467 | p = msn_dc_new_packet(DC_NONCE_PACKET_SIZE); |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
468 | h = (gchar *)p->data; |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
469 | |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
470 | msn_push32le(h, 0); /* NUL */ |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
471 | |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
472 | msn_push32le(h, dc->slpcall->slplink->slp_seq_id++); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
473 | |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
474 | /* More NUL stuff */ |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
475 | msn_push64le(h, 0); |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
476 | msn_push64le(h, 0); |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
477 | msn_push32le(h, 0); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
478 | |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
479 | /* Flags */ |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
480 | msn_push32le(h, P2P_DC_HANDSHAKE); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
481 | |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
482 | /* The real Nonce, yay! */ |
|
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
483 | memcpy(h, dc->nonce, 16); |
| 30067 | 484 | |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
485 | msn_dc_enqueue_packet(dc, p); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
486 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
487 | |
|
30090
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
488 | static gboolean |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
489 | msn_dc_verify_handshake(MsnDirectConn *dc, guint32 packet_length) |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
490 | { |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
491 | guchar nonce[16]; |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
492 | gchar nonce_hash[37]; |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
493 | |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
494 | if (packet_length != DC_NONCE_PACKET_SIZE) |
|
30090
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
495 | return FALSE; |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
496 | |
|
33785
502a383ea856
msn: Fix hash calculation for SHA1 nonce hashes
Daniel Atallah <datallah@pidgin.im>
parents:
31803
diff
changeset
|
497 | memcpy(nonce, dc->in_buffer + 4 + DC_NONCE_PACKET_NONCE, sizeof(nonce)); |
|
30090
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
498 | |
|
30102
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
499 | if (dc->nonce_type == DC_NONCE_PLAIN) { |
|
33785
502a383ea856
msn: Fix hash calculation for SHA1 nonce hashes
Daniel Atallah <datallah@pidgin.im>
parents:
31803
diff
changeset
|
500 | if (memcmp(dc->nonce, nonce, sizeof(nonce)) == 0) { |
|
30102
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
501 | purple_debug_info("msn", |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
502 | "Nonce from buddy request and nonce from DC attempt match, " |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
503 | "allowing direct connection\n"); |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
504 | return TRUE; |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
505 | } else { |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
506 | purple_debug_warning("msn", |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
507 | "Nonce from buddy request and nonce from DC attempt " |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
508 | "don't match, ignoring direct connection\n"); |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
509 | return FALSE; |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
510 | } |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
511 | |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
512 | } else if (dc->nonce_type == DC_NONCE_SHA1) { |
|
33785
502a383ea856
msn: Fix hash calculation for SHA1 nonce hashes
Daniel Atallah <datallah@pidgin.im>
parents:
31803
diff
changeset
|
513 | msn_dc_calculate_nonce_hash(dc->nonce_type, nonce, sizeof(nonce), nonce_hash); |
|
30090
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
514 | |
|
30102
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
515 | if (g_str_equal(dc->remote_nonce, nonce_hash)) { |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
516 | purple_debug_info("msn", |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
517 | "Received nonce %s from buddy request " |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
518 | "and calculated nonce %s from DC attempt. " |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
519 | "Nonces match, allowing direct connection\n", |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
520 | dc->remote_nonce, nonce_hash); |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
521 | return TRUE; |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
522 | } else { |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
523 | purple_debug_warning("msn", |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
524 | "Received nonce %s from buddy request " |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
525 | "and calculated nonce %s from DC attempt. " |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
526 | "Nonces don't match, ignoring direct connection\n", |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
527 | dc->remote_nonce, nonce_hash); |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
528 | return FALSE; |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
529 | } |
|
7375eaf7c469
I think this finally works with both aMSN and the official client, for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30101
diff
changeset
|
530 | } else |
|
30096
6b0dfc4e1e83
Obviously, if this comparison fails, I should be returning FALSE.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30095
diff
changeset
|
531 | return FALSE; |
|
30090
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
532 | } |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
533 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
534 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
535 | msn_dc_send_packet_cb(MsnDirectConnPacket *p) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
536 | { |
|
31007
336b38bb5876
Reomove MsnMessage reference from DirectConn.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31006
diff
changeset
|
537 | if (p->part != NULL && p->part->ack_cb != NULL) |
|
336b38bb5876
Reomove MsnMessage reference from DirectConn.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31006
diff
changeset
|
538 | p->part->ack_cb(p->part, p->part->ack_data); |
|
336b38bb5876
Reomove MsnMessage reference from DirectConn.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31006
diff
changeset
|
539 | } |
|
336b38bb5876
Reomove MsnMessage reference from DirectConn.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31006
diff
changeset
|
540 | |
|
30999
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
541 | void |
|
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
542 | msn_dc_enqueue_part(MsnDirectConn *dc, MsnSlpMessagePart *part) |
|
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
543 | { |
|
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
544 | MsnDirectConnPacket *p; |
|
31334
c892163971f2
Use the serializing function for SlpMsgParts on a direct connection.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31303
diff
changeset
|
545 | size_t length; |
|
30999
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
546 | |
|
31334
c892163971f2
Use the serializing function for SlpMsgParts on a direct connection.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31303
diff
changeset
|
547 | p = msn_dc_new_packet(0); |
|
c892163971f2
Use the serializing function for SlpMsgParts on a direct connection.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31303
diff
changeset
|
548 | p->data = (guchar *)msn_slpmsgpart_serialize(part, &length); |
|
c892163971f2
Use the serializing function for SlpMsgParts on a direct connection.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31303
diff
changeset
|
549 | p->length = length - P2P_PACKET_FOOTER_SIZE; /* DC doesn't need footer? */ |
|
30999
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
550 | |
|
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
551 | p->sent_cb = msn_dc_send_packet_cb; |
|
31241
cc8a2c660694
Correct the ref counts on the SlpMsgParts. When it's removed from the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31240
diff
changeset
|
552 | p->part = msn_slpmsgpart_ref(part); |
|
30999
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
553 | |
|
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
554 | msn_dc_enqueue_packet(dc, p); |
|
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
555 | } |
|
274aa4f2422d
Add a function that enqueue a Part instead of a Message since directconn does not sends messages.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30986
diff
changeset
|
556 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
557 | static int |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
558 | msn_dc_process_packet(MsnDirectConn *dc, guint32 packet_length) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
559 | { |
|
31060
67d11dfa6338
Process SlpMessageParts, a sequence of parts will generate a SlpMessage.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31055
diff
changeset
|
560 | MsnSlpMessagePart *part; |
|
67d11dfa6338
Process SlpMessageParts, a sequence of parts will generate a SlpMessage.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31055
diff
changeset
|
561 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
562 | g_return_val_if_fail(dc != NULL, DC_PROCESS_ERROR); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
563 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
564 | switch (dc->state) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
565 | case DC_STATE_CLOSED: |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
566 | break; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
567 | |
|
30076
2b751385616f
Minor cleanups.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30075
diff
changeset
|
568 | case DC_STATE_FOO: |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
569 | /* FOO message is always 4 bytes long */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
570 | if (packet_length != 4 || memcmp(dc->in_buffer, "\4\0\0\0foo", 8) != 0) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
571 | return DC_PROCESS_FALLBACK; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
572 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
573 | dc->state = DC_STATE_HANDSHAKE; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
574 | break; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
575 | |
|
30076
2b751385616f
Minor cleanups.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30075
diff
changeset
|
576 | case DC_STATE_HANDSHAKE: |
|
30090
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
577 | if (!msn_dc_verify_handshake(dc, packet_length)) |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
578 | return DC_PROCESS_FALLBACK; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
579 | |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
580 | msn_dc_send_handshake(dc); |
|
30068
ade8dd1a1339
Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30067
diff
changeset
|
581 | dc->state = DC_STATE_ESTABLISHED; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
582 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
583 | msn_slpcall_session_init(dc->slpcall); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
584 | dc->slpcall = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
585 | break; |
| 30067 | 586 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
587 | case DC_STATE_HANDSHAKE_REPLY: |
|
30090
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
588 | if (!msn_dc_verify_handshake(dc, packet_length)) |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
589 | return DC_PROCESS_FALLBACK; |
|
a97b8c06eeae
Save remote nonce, and verify we get the same data when initiating the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30086
diff
changeset
|
590 | |
|
30068
ade8dd1a1339
Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30067
diff
changeset
|
591 | dc->state = DC_STATE_ESTABLISHED; |
| 30067 | 592 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
593 | msn_slpcall_session_init(dc->slpcall); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
594 | dc->slpcall = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
595 | break; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
596 | |
|
30068
ade8dd1a1339
Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30067
diff
changeset
|
597 | case DC_STATE_ESTABLISHED: |
|
31296
1f460ae727e1
A direct connection really has no need of the whole P2P packet header,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
598 | if (packet_length) { |
|
31781
e847bafa5e00
Get the P2P version based on the user. Still hard-coded as v1 though.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31334
diff
changeset
|
599 | MsnP2PVersion p2p; |
|
31790
fd6e676248f8
Getting the P2P version is probably the slplink's job, since it has
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31781
diff
changeset
|
600 | p2p = msn_slplink_get_p2p_version(dc->slplink); |
|
31781
e847bafa5e00
Get the P2P version based on the user. Still hard-coded as v1 though.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31334
diff
changeset
|
601 | part = msn_slpmsgpart_new_from_data(p2p, dc->in_buffer + 4, packet_length); |
|
31267
26fc2e71129a
Ignore short packets related to p2pv2.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31247
diff
changeset
|
602 | if (part) { |
|
26fc2e71129a
Ignore short packets related to p2pv2.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31247
diff
changeset
|
603 | msn_slplink_process_msg(dc->slplink, part); |
|
26fc2e71129a
Ignore short packets related to p2pv2.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31247
diff
changeset
|
604 | msn_slpmsgpart_unref(part); |
|
26fc2e71129a
Ignore short packets related to p2pv2.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31247
diff
changeset
|
605 | } |
|
31133
9383e6398f7d
Don't attempt to process zero-length DC messages. We should probably
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31062
diff
changeset
|
606 | } |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
607 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
608 | /* |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
609 | if (dc->num_calls == 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
610 | msn_dc_destroy(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
611 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
612 | return DC_PROCESS_CLOSE; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
613 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
614 | */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
615 | break; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
616 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
617 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
618 | return DC_PROCESS_OK; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
619 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
620 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
621 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
622 | msn_dc_recv_cb(gpointer data, gint fd, PurpleInputCondition cond) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
623 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
624 | MsnDirectConn *dc; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
625 | int free_buf_space; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
626 | int bytes_received; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
627 | guint32 packet_length; |
| 30067 | 628 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
629 | g_return_if_fail(data != NULL); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
630 | g_return_if_fail(fd != -1); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
631 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
632 | dc = data; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
633 | free_buf_space = dc->in_size - dc->in_pos; |
| 30067 | 634 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
635 | bytes_received = recv(fd, dc->in_buffer + dc->in_pos, free_buf_space, 0); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
636 | if (bytes_received < 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
637 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
638 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
639 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
640 | purple_debug_warning("msn", "msn_dc_recv_cb: recv error\n"); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
641 | |
|
30068
ade8dd1a1339
Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30067
diff
changeset
|
642 | if(dc->state != DC_STATE_ESTABLISHED) |
|
30349
26be44d0f764
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:
30336
diff
changeset
|
643 | msn_dc_fallback_to_sb(dc); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
644 | else |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
645 | msn_dc_destroy(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
646 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
647 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
648 | } else if (bytes_received == 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
649 | /* EOF. Remote side closed connection. */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
650 | purple_debug_info("msn", "msn_dc_recv_cb: recv EOF\n"); |
| 30067 | 651 | |
|
30068
ade8dd1a1339
Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30067
diff
changeset
|
652 | if(dc->state != DC_STATE_ESTABLISHED) |
|
30349
26be44d0f764
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:
30336
diff
changeset
|
653 | msn_dc_fallback_to_sb(dc); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
654 | else |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
655 | msn_dc_destroy(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
656 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
657 | } |
| 30067 | 658 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
659 | dc->progress = TRUE; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
660 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
661 | dc->in_pos += bytes_received; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
662 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
663 | /* Wait for packet length */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
664 | while (dc->in_pos >= 4) { |
|
30106
142f2a062877
I've seen packet sizes larger than our current maximum. Hopefully 8KiB is
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30105
diff
changeset
|
665 | packet_length = GUINT32_FROM_LE(*((guint32*)dc->in_buffer)); |
| 30067 | 666 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
667 | if (packet_length > DC_MAX_PACKET_SIZE) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
668 | /* Oversized packet */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
669 | purple_debug_warning("msn", "msn_dc_recv_cb: oversized packet received\n"); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
670 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
671 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
672 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
673 | /* Wait for the whole packet to arrive */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
674 | if (dc->in_pos < 4 + packet_length) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
675 | return; |
| 30067 | 676 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
677 | switch (msn_dc_process_packet(dc, packet_length)) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
678 | case DC_PROCESS_CLOSE: |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
679 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
680 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
681 | case DC_PROCESS_FALLBACK: |
|
30349
26be44d0f764
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:
30336
diff
changeset
|
682 | purple_debug_warning("msn", "msn_dc_recv_cb: packet processing error, fall back to SB\n"); |
|
26be44d0f764
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:
30336
diff
changeset
|
683 | msn_dc_fallback_to_sb(dc); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
684 | return; |
| 30067 | 685 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
686 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
687 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
688 | if (dc->in_pos > packet_length + 4) { |
|
30107
8f91902bcc39
Valgrind pointed out that dest and src may overlap, so we need to use
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30106
diff
changeset
|
689 | g_memmove(dc->in_buffer, dc->in_buffer + 4 + packet_length, dc->in_pos - packet_length - 4); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
690 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
691 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
692 | dc->in_pos -= packet_length + 4; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
693 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
694 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
695 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
696 | static gboolean |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
697 | msn_dc_timeout(gpointer data) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
698 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
699 | MsnDirectConn *dc = data; |
| 30067 | 700 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
701 | g_return_val_if_fail(dc != NULL, FALSE); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
702 | |
|
30254
7c1f0dc0d410
If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30186
diff
changeset
|
703 | if (dc->progress) { |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
704 | dc->progress = FALSE; |
|
30254
7c1f0dc0d410
If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30186
diff
changeset
|
705 | return TRUE; |
|
7c1f0dc0d410
If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30186
diff
changeset
|
706 | } else { |
|
7c1f0dc0d410
If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30186
diff
changeset
|
707 | dc->timeout_handle = 0; |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
708 | msn_dc_destroy(dc); |
|
30254
7c1f0dc0d410
If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30186
diff
changeset
|
709 | return FALSE; |
|
7c1f0dc0d410
If removing a timeout and return FALSE in its handler isn't good, then
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30186
diff
changeset
|
710 | } |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
711 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
712 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
713 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
714 | msn_dc_init(MsnDirectConn *dc) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
715 | { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
716 | g_return_if_fail(dc != NULL); |
| 30067 | 717 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
718 | dc->in_size = DC_MAX_PACKET_SIZE + 4; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
719 | dc->in_pos = 0; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
720 | dc->in_buffer = g_malloc(dc->in_size); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
721 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
722 | dc->recv_handle = purple_input_add(dc->fd, PURPLE_INPUT_READ, msn_dc_recv_cb, dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
723 | dc->send_handle = purple_input_add(dc->fd, PURPLE_INPUT_WRITE, msn_dc_send_cb, dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
724 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
725 | dc->timeout_handle = purple_timeout_add_seconds(DC_TIMEOUT, msn_dc_timeout, dc); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
726 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
727 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
728 | void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
729 | msn_dc_connected_to_peer_cb(gpointer data, gint fd, const gchar *error_msg) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
730 | { |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
731 | MsnDirectConn *dc = data; |
| 30067 | 732 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
733 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
734 | purple_debug_info("msn", "msn_dc_connected_to_peer_cb %p\n", dc); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
735 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
736 | g_return_if_fail(dc != NULL); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
737 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
738 | dc->connect_data = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
739 | purple_timeout_remove(dc->connect_timeout_handle); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
740 | dc->connect_timeout_handle = 0; |
| 30067 | 741 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
742 | dc->fd = fd; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
743 | if (dc->fd != -1) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
744 | msn_dc_init(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
745 | msn_dc_send_foo(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
746 | msn_dc_send_handshake(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
747 | dc->state = DC_STATE_HANDSHAKE_REPLY; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
748 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
749 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
750 | |
| 30067 | 751 | /* |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
752 | * This callback will be called when we're the server |
|
30327
d3d120d3f9e8
Make it more explicit that incoming and outgoing timeouts are different.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30318
diff
changeset
|
753 | * and nobody has connected us in DC_INCOMING_TIMEOUT seconds |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
754 | */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
755 | static gboolean |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
756 | msn_dc_incoming_connection_timeout_cb(gpointer data) { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
757 | MsnDirectConn *dc = data; |
| 30067 | 758 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
759 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
760 | purple_debug_info("msn", "msn_dc_incoming_connection_timeout_cb %p\n", dc); |
| 30067 | 761 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
762 | g_return_val_if_fail(dc != NULL, FALSE); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
763 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
764 | if (dc->listen_data != NULL) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
765 | purple_network_listen_cancel(dc->listen_data); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
766 | dc->listen_data = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
767 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
768 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
769 | if (dc->listenfd_handle != 0) { |
|
30256
669f8bc11d33
This is not a timeout, but an input handler.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30255
diff
changeset
|
770 | purple_input_remove(dc->listenfd_handle); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
771 | dc->listenfd_handle = 0; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
772 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
773 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
774 | if (dc->listenfd != -1) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
775 | purple_network_remove_port_mapping(dc->listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
776 | close(dc->listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
777 | dc->listenfd = -1; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
778 | } |
|
14174
1615a99529dc
[gaim-migrate @ 16746]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
779 | |
|
30109
356116df6885
This should probably work a bit better. At least, we want to get rid of any
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30107
diff
changeset
|
780 | dc->connect_timeout_handle = 0; |
|
30349
26be44d0f764
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:
30336
diff
changeset
|
781 | msn_dc_fallback_to_sb(dc); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
782 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
783 | return FALSE; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
784 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
785 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
786 | /* |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
787 | * This callback will be called when we're unable to connect to |
|
30327
d3d120d3f9e8
Make it more explicit that incoming and outgoing timeouts are different.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30318
diff
changeset
|
788 | * the remote host in DC_OUTGOING_TIMEOUT seconds. |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
789 | */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
790 | gboolean |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
791 | msn_dc_outgoing_connection_timeout_cb(gpointer data) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
792 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
793 | MsnDirectConn *dc = data; |
| 30067 | 794 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
795 | purple_debug_info("msn", "msn_dc_outgoing_connection_timeout_cb %p\n", dc); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
796 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
797 | g_return_val_if_fail(dc != NULL, FALSE); |
| 30067 | 798 | |
|
30186
3122a381a2c6
We can't both remove a timeout and return FALSE in its callback.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30109
diff
changeset
|
799 | dc->connect_timeout_handle = 0; |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
800 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
801 | if (dc->connect_data != NULL) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
802 | purple_proxy_connect_cancel(dc->connect_data); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
803 | dc->connect_data = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
804 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
805 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
806 | if (dc->ext_ip && dc->ext_port) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
807 | /* Try external IP/port if available. */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
808 | dc->connect_data = purple_proxy_connect( |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
809 | NULL, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
810 | dc->slpcall->slplink->session->account, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
811 | dc->ext_ip, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
812 | dc->ext_port, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
813 | msn_dc_connected_to_peer_cb, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
814 | dc |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
815 | ); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
816 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
817 | g_free(dc->ext_ip); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
818 | dc->ext_ip = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
819 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
820 | if (dc->connect_data) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
821 | dc->connect_timeout_handle = purple_timeout_add_seconds( |
|
30327
d3d120d3f9e8
Make it more explicit that incoming and outgoing timeouts are different.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30318
diff
changeset
|
822 | DC_OUTGOING_TIMEOUT, |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
823 | msn_dc_outgoing_connection_timeout_cb, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
824 | dc |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
825 | ); |
|
30255
47794eb7b979
Fallback to P2P if connecting to external IP didn't work immediately.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30254
diff
changeset
|
826 | } else { |
|
47794eb7b979
Fallback to P2P if connecting to external IP didn't work immediately.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30254
diff
changeset
|
827 | /* |
|
47794eb7b979
Fallback to P2P if connecting to external IP didn't work immediately.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30254
diff
changeset
|
828 | * Connection failed |
|
30349
26be44d0f764
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:
30336
diff
changeset
|
829 | * Fall back to SB transfer |
|
30255
47794eb7b979
Fallback to P2P if connecting to external IP didn't work immediately.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30254
diff
changeset
|
830 | */ |
|
47794eb7b979
Fallback to P2P if connecting to external IP didn't work immediately.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30254
diff
changeset
|
831 | msn_dc_outgoing_connection_timeout_cb(dc); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
832 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
833 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
834 | } else { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
835 | /* |
|
30186
3122a381a2c6
We can't both remove a timeout and return FALSE in its callback.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30109
diff
changeset
|
836 | * Both internal and external connection attempts failed. |
|
30349
26be44d0f764
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:
30336
diff
changeset
|
837 | * Fall back to SB transfer. |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
838 | */ |
|
30349
26be44d0f764
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:
30336
diff
changeset
|
839 | msn_dc_fallback_to_sb(dc); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
840 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
841 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
842 | return FALSE; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
843 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
844 | |
| 30067 | 845 | /* |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
846 | * This callback will be called when we're the server |
|
30327
d3d120d3f9e8
Make it more explicit that incoming and outgoing timeouts are different.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30318
diff
changeset
|
847 | * and somebody has connected to us in DC_INCOMING_TIMEOUT seconds. |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
848 | */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
849 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
850 | msn_dc_incoming_connection_cb(gpointer data, gint listenfd, PurpleInputCondition cond) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
851 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
852 | MsnDirectConn *dc = data; |
| 30067 | 853 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
854 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
855 | purple_debug_info("msn", "msn_dc_incoming_connection_cb %p\n", dc); |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
856 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
857 | g_return_if_fail(dc != NULL); |
| 30067 | 858 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
859 | if (dc->connect_timeout_handle != 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
860 | purple_timeout_remove(dc->connect_timeout_handle); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
861 | dc->connect_timeout_handle = 0; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
862 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
863 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
864 | if (dc->listenfd_handle != 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
865 | purple_input_remove(dc->listenfd_handle); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
866 | dc->listenfd_handle = 0; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
867 | } |
| 30067 | 868 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
869 | dc->fd = accept(listenfd, NULL, 0); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
870 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
871 | purple_network_remove_port_mapping(dc->listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
872 | close(dc->listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
873 | dc->listenfd = -1; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
874 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
875 | if (dc->fd != -1) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
876 | msn_dc_init(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
877 | dc->state = DC_STATE_FOO; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
878 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
879 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
880 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
881 | void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
882 | msn_dc_listen_socket_created_cb(int listenfd, gpointer data) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
883 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
884 | MsnDirectConn *dc = data; |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
885 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
886 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
887 | purple_debug_info("msn", "msn_dc_listen_socket_created_cb %p\n", dc); |
| 30067 | 888 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
889 | g_return_if_fail(dc != NULL); |
| 30067 | 890 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
891 | dc->listen_data = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
892 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
893 | if (listenfd != -1) { |
|
30084
57ef011cbce0
NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30077
diff
changeset
|
894 | const char *ext_ip; |
|
57ef011cbce0
NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30077
diff
changeset
|
895 | const char *int_ip; |
|
57ef011cbce0
NULL-ing this stuff after free is nice in theory, but totally pointless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30077
diff
changeset
|
896 | int port; |
|
14174
1615a99529dc
[gaim-migrate @ 16746]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
897 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
898 | ext_ip = purple_network_get_my_ip(listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
899 | int_ip = purple_network_get_local_system_ip(listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
900 | port = purple_network_get_port_from_fd(listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
901 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
902 | dc->listenfd = listenfd; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
903 | dc->listenfd_handle = purple_input_add( |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
904 | listenfd, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
905 | PURPLE_INPUT_READ, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
906 | msn_dc_incoming_connection_cb, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
907 | dc |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
908 | ); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
909 | dc->connect_timeout_handle = purple_timeout_add_seconds( |
|
30327
d3d120d3f9e8
Make it more explicit that incoming and outgoing timeouts are different.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30318
diff
changeset
|
910 | DC_INCOMING_TIMEOUT, |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
911 | msn_dc_incoming_connection_timeout_cb, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
912 | dc |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
913 | ); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
914 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
915 | if (strcmp(int_ip, ext_ip) != 0) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
916 | dc->msg_body = g_strdup_printf( |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
917 | "Bridge: TCPv1\r\n" |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
918 | "Listening: true\r\n" |
|
30092
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
919 | "%sNonce: {%s}\r\n" |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
920 | "IPv4External-Addrs: %s\r\n" |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
921 | "IPv4External-Port: %d\r\n" |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
922 | "IPv4Internal-Addrs: %s\r\n" |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
923 | "IPv4Internal-Port: %d\r\n" |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
924 | "\r\n", |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
925 | |
|
30092
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
926 | dc->nonce_type != DC_NONCE_PLAIN ? "Hashed-" : "", |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
927 | dc->nonce_hash, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
928 | ext_ip, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
929 | port, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
930 | int_ip, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
931 | port |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
932 | ); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
933 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
934 | } else { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
935 | dc->msg_body = g_strdup_printf( |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
936 | "Bridge: TCPv1\r\n" |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
937 | "Listening: true\r\n" |
|
30092
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
938 | "%sNonce: {%s}\r\n" |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
939 | "IPv4External-Addrs: %s\r\n" |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
940 | "IPv4External-Port: %d\r\n" |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
941 | "\r\n", |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
942 | |
|
30092
ad8776ef2844
Support old-style Nonce, which should let us use direct connections to
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30090
diff
changeset
|
943 | dc->nonce_type != DC_NONCE_PLAIN ? "Hashed-" : "", |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
944 | dc->nonce_hash, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
945 | ext_ip, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
946 | port |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
947 | ); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
948 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
949 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
950 | if (dc->slpcall->wait_for_socket) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
951 | if (dc->send_connection_info_msg_cb != NULL) |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
952 | dc->send_connection_info_msg_cb(dc); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
953 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
954 | dc->slpcall->wait_for_socket = FALSE; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
955 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
956 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
957 | } |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
958 |