Mon, 10 Feb 2014 16:22:00 +0530
Merged default branch
|
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" |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34557
diff
changeset
|
26 | #include "ciphers/sha1hash.h" |
|
30945
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) { |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34557
diff
changeset
|
47 | PurpleHash *hash = purple_sha1_hash_new(); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34557
diff
changeset
|
48 | purple_hash_append(hash, nonce, nonce_len); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34557
diff
changeset
|
49 | purple_hash_digest(hash, digest, sizeof(digest)); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34557
diff
changeset
|
50 | g_object_unref(hash); |
|
30094
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
51 | } 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
|
52 | memcpy(digest, nonce, nonce_len); |
|
31803
3f10f8ceca66
msn: Avoid reading uninit memory.
Paul Aurich <darkrain42@pidgin.im>
parents:
31790
diff
changeset
|
53 | } else { |
|
3f10f8ceca66
msn: Avoid reading uninit memory.
Paul Aurich <darkrain42@pidgin.im>
parents:
31790
diff
changeset
|
54 | nonce_hash[0] = '\0'; |
|
3f10f8ceca66
msn: Avoid reading uninit memory.
Paul Aurich <darkrain42@pidgin.im>
parents:
31790
diff
changeset
|
55 | 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
|
56 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
57 | |
|
30094
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
58 | 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
|
59 | "%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
|
60 | |
|
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 | 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
|
62 | 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
|
63 | 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
|
64 | 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
|
65 | |
|
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 | 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
|
67 | digest[4], |
|
30373
015cf7cacf23
For some reason, this line creates the following warning:
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30349
diff
changeset
|
68 | |
|
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
|
69 | 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
|
70 | 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
|
71 | |
|
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 | 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
|
73 | 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
|
74 | |
|
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 | 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
|
76 | 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
|
77 | 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
|
78 | 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
|
79 | 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
|
80 | digest[15] |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
81 | ); |
|
30094
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
82 | } |
|
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 | static void |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
85 | msn_dc_generate_nonce(MsnDirectConn *dc) |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
86 | { |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
87 | guint32 *nonce; |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
88 | int i; |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
89 | |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
90 | nonce = (guint32 *)&dc->nonce; |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
91 | for (i = 0; i < 4; i++) |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
92 | nonce[i] = rand(); |
|
dba1e7ecf923
Remove some duplicate code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30092
diff
changeset
|
93 | |
|
33785
502a383ea856
msn: Fix hash calculation for SHA1 nonce hashes
Daniel Atallah <datallah@pidgin.im>
parents:
31803
diff
changeset
|
94 | 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
|
95 | |
|
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 | 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
|
97 | 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
|
98 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
99 | |
|
30075
381b22b5bd49
This DC stuff is a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30074
diff
changeset
|
100 | 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
|
101 | 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
|
102 | { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
103 | MsnDirectConnPacket *p; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
104 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
105 | 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
|
106 | 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
|
107 | p->data = g_malloc(length); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
108 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
109 | return p; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
110 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
111 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
112 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
113 | 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
|
114 | { |
|
30076
2b751385616f
Minor cleanups.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30075
diff
changeset
|
115 | g_free(p->data); |
| 30067 | 116 | |
|
31007
336b38bb5876
Reomove MsnMessage reference from DirectConn.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31006
diff
changeset
|
117 | if (p->part) |
|
31049
22a86713164e
Add support to ref/unref SlpMessageParts.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31032
diff
changeset
|
118 | msn_slpmsgpart_unref(p->part); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
119 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
120 | g_free(p); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
121 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
122 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
123 | MsnDirectConn * |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
124 | 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
|
125 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
126 | MsnDirectConn *dc; |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
127 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
128 | g_return_val_if_fail(slpcall != NULL, NULL); |
| 30067 | 129 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
130 | dc = g_new0(MsnDirectConn, 1); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
131 | |
| 30077 | 132 | 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
|
133 | 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
|
134 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
135 | 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
|
136 | dc->slpcall = slpcall; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
137 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
138 | 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
|
139 | 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
|
140 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
141 | dc->slplink->dc = dc; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
142 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
143 | 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
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | dc->listenfd = -1; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
148 | 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
|
149 | 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
|
150 | dc->fd = -1; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
151 | 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
|
152 | 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
|
153 | 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
|
154 | 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
|
155 | 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
|
156 | 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
|
157 | 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
|
158 | 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
|
159 | 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
|
160 | dc->progress = FALSE; |
|
30328
fe6e047b9f85
C comments only.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30327
diff
changeset
|
161 | /*dc->num_calls = 1;*/ |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
162 | |
|
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
|
163 | /* 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
|
164 | 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
|
165 | 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
|
166 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
167 | return dc; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
168 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
169 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
170 | void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
171 | 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
|
172 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
173 | MsnSlpLink *slplink; |
| 30067 | 174 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
175 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
176 | purple_debug_info("msn", "msn_dc_destroy %p\n", dc); |
| 30067 | 177 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
178 | g_return_if_fail(dc != NULL); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
179 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
180 | 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
|
181 | dc->slpcall->wait_for_socket = FALSE; |
| 30067 | 182 | |
|
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
|
183 | 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
|
184 | 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
|
185 | 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
|
186 | 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
|
187 | 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
|
188 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
189 | |
|
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
|
190 | g_free(dc->msg_body); |
| 30067 | 191 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
192 | 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
|
193 | msn_slpmsg_destroy(dc->prev_ack); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
194 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
195 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
196 | 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
|
197 | 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
|
198 | } |
| 30067 | 199 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
200 | 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
|
201 | 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
|
202 | } |
| 30067 | 203 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
204 | 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
|
205 | 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
|
206 | close(dc->listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
207 | } |
| 30067 | 208 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
209 | 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
|
210 | 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
|
211 | } |
| 30067 | 212 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
213 | 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
|
214 | 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
|
215 | } |
| 30067 | 216 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
217 | 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
|
218 | close(dc->fd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
219 | } |
| 30067 | 220 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
221 | 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
|
222 | 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
|
223 | } |
| 30067 | 224 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
225 | 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
|
226 | purple_input_remove(dc->recv_handle); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
227 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
228 | |
|
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
|
229 | g_free(dc->in_buffer); |
| 30067 | 230 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
231 | 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
|
232 | 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
|
233 | 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
|
234 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
235 | g_queue_free(dc->out_queue); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
236 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
237 | |
|
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
|
238 | g_free(dc->ext_ip); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
239 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
240 | 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
|
241 | 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
|
242 | } |
|
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 | g_free(dc); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
245 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
246 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
247 | /* |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
248 | void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
249 | msn_dc_ref(MsnDirectConn *dc) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
250 | { |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
251 | g_return_if_fail(dc != NULL); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
252 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
253 | dc->num_calls++; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
254 | } |
|
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 | void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
257 | msn_dc_unref(MsnDirectConn *dc) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
258 | { |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
259 | g_return_if_fail(dc != NULL); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
260 | |
| 30067 | 261 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
262 | 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
|
263 | dc->num_calls--; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
264 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
265 | } |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
266 | */ |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
267 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
268 | void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
269 | msn_dc_send_invite(MsnDirectConn *dc) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
270 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
271 | MsnSlpCall *slpcall; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
272 | MsnSlpMessage *msg; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
273 | gchar *header; |
| 30067 | 274 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
275 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
276 | 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
|
277 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
278 | 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
|
279 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
280 | slpcall = dc->slpcall; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
281 | g_return_if_fail(slpcall != NULL); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
282 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
283 | 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
|
284 | "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
|
285 | 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
|
286 | ); |
| 30067 | 287 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
288 | 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
|
289 | slpcall, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
290 | 0, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
291 | header, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
292 | slpcall->branch, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
293 | "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
|
294 | dc->msg_body |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
295 | ); |
|
30086
32109706f5ec
Set some information for debugging.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30085
diff
changeset
|
296 | msg->info = "DC INVITE"; |
|
32109706f5ec
Set some information for debugging.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30085
diff
changeset
|
297 | 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
|
298 | g_free(header); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
299 | 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
|
300 | dc->msg_body = NULL; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
301 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
302 | 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
|
303 | } |
|
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 | void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
306 | 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
|
307 | { |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
308 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
309 | purple_debug_info("msn", "msn_dc_send_ok %p\n", dc); |
| 30067 | 310 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
311 | g_return_if_fail(dc != NULL); |
| 30067 | 312 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
313 | 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
|
314 | "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
|
315 | 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
|
316 | 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
|
317 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
318 | 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
|
319 | 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
|
320 | 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
|
321 | msn_slplink_send_queued_slpmsgs(dc->slpcall->slplink); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
322 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
323 | |
|
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
|
324 | 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
|
325 | msn_dc_fallback_to_sb(MsnDirectConn *dc) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
326 | { |
|
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
|
327 | MsnSlpLink *slplink; |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
328 | 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
|
329 | GQueue *queue = NULL; |
| 30067 | 330 | |
|
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
|
331 | purple_debug_info("msn", "msn_dc_fallback_to_sb %p\n", dc); |
| 30067 | 332 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
333 | 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
|
334 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
335 | 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
|
336 | 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
|
337 | 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
|
338 | 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
|
339 | 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
|
340 | } |
| 30067 | 341 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
342 | 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
|
343 | |
|
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
|
344 | if (slpcall) { |
|
30314
72174fad31d8
Use msn_dc_fallback_to_p2p where possible.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30256
diff
changeset
|
345 | 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
|
346 | 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
|
347 | 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
|
348 | 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
|
349 | 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
|
350 | 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
|
351 | } |
|
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 | 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
|
353 | } |
|
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 | } |
|
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
|
355 | 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
|
356 | } |
|
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 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
359 | 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
|
360 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
361 | MsnDirectConn *dc = data; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
362 | MsnDirectConnPacket *p; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
363 | int bytes_to_send; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
364 | 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
|
365 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
366 | 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
|
367 | g_return_if_fail(fd != -1); |
| 30067 | 368 | |
|
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
|
369 | 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
|
370 | 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
|
371 | 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
|
372 | 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
|
373 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
374 | return; |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
375 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
376 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
377 | 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
|
378 | |
|
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 | 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
|
380 | /* 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
|
381 | 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
|
382 | 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
|
383 | 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
|
384 | 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
|
385 | 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
|
386 | |
|
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 | 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
|
388 | 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
|
389 | 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
|
390 | } |
|
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 | 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
|
392 | } |
|
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 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
394 | 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
|
395 | 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
|
396 | 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
|
397 | 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
|
398 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
399 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
400 | 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
|
401 | 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
|
402 | return; |
|
10899
87d9aec5b72d
[gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10589
diff
changeset
|
403 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
404 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
405 | dc->progress = TRUE; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
406 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
407 | dc->msg_pos += bytes_sent; |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
408 | if ((guint32)dc->msg_pos == p->length) { |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
409 | 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
|
410 | p->sent_cb(p); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
411 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
412 | 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
|
413 | msn_dc_destroy_packet(p); |
| 30067 | 414 | |
|
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
|
415 | dc->msg_pos = -1; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
416 | } |
|
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 | static void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
420 | msn_dc_enqueue_packet(MsnDirectConn *dc, MsnDirectConnPacket *p) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
421 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
422 | gboolean was_empty; |
| 30067 | 423 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
424 | 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
|
425 | g_queue_push_tail(dc->out_queue, p); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
426 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
427 | 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
|
428 | 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
|
429 | msn_dc_send_cb(dc, dc->fd, PURPLE_INPUT_WRITE); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
430 | } |
|
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 | |
|
20646
69768ff2194a
Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
433 | static void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
434 | 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
|
435 | { |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
436 | MsnDirectConnPacket *p; |
| 30067 | 437 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
438 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
439 | purple_debug_info("msn", "msn_dc_send_foo %p\n", dc); |
| 30067 | 440 | |
|
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
|
441 | 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
|
442 | |
|
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
|
443 | 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
|
444 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
445 | 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
|
446 | } |
|
69768ff2194a
Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <datallah@pidgin.im>
parents:
20597
diff
changeset
|
447 | |
|
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
|
448 | #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
|
449 | 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
|
450 | 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
|
451 | 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
|
452 | 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
|
453 | 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
|
454 | 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
|
455 | } 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
|
456 | #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
|
457 | #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
|
458 | #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
|
459 | |
|
a0bfbebab591
Try and reduce some code duplication.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30100
diff
changeset
|
460 | static void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
461 | msn_dc_send_handshake(MsnDirectConn *dc) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
462 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
463 | 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
|
464 | gchar *h; |
| 30067 | 465 | |
|
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
|
466 | 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
|
467 | 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
|
468 | |
|
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 | 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
|
470 | |
|
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 | msn_push32le(h, dc->slpcall->slplink->slp_seq_id++); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
472 | |
|
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
|
473 | /* 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
|
474 | 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
|
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_push32le(h, 0); |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
477 | |
|
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
|
478 | /* 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
|
479 | 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
|
480 | |
|
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
|
481 | /* 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
|
482 | memcpy(h, dc->nonce, 16); |
| 30067 | 483 | |
|
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
|
484 | 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
|
485 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
486 | |
|
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
|
487 | 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
|
488 | 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
|
489 | { |
|
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 | 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
|
491 | 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
|
492 | |
|
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
|
493 | 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
|
494 | 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
|
495 | |
|
33785
502a383ea856
msn: Fix hash calculation for SHA1 nonce hashes
Daniel Atallah <datallah@pidgin.im>
parents:
31803
diff
changeset
|
496 | 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
|
497 | |
|
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
|
498 | 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
|
499 | 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
|
500 | 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
|
501 | "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
|
502 | "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
|
503 | 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
|
504 | } 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
|
505 | 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
|
506 | "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
|
507 | "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
|
508 | 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
|
509 | } |
|
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 | } 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
|
512 | 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
|
513 | |
|
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
|
514 | 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
|
515 | 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
|
516 | "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
|
517 | "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
|
518 | "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
|
519 | 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
|
520 | 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
|
521 | } 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
|
522 | 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
|
523 | "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
|
524 | "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
|
525 | "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
|
526 | 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
|
527 | 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
|
528 | } |
|
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 | } else |
|
30096
6b0dfc4e1e83
Obviously, if this comparison fails, I should be returning FALSE.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30095
diff
changeset
|
530 | 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
|
531 | } |
|
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 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
533 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
534 | 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
|
535 | { |
|
31007
336b38bb5876
Reomove MsnMessage reference from DirectConn.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31006
diff
changeset
|
536 | 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
|
537 | 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
|
538 | } |
|
336b38bb5876
Reomove MsnMessage reference from DirectConn.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31006
diff
changeset
|
539 | |
|
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
|
540 | 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
|
541 | 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
|
542 | { |
|
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 | 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
|
544 | 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
|
545 | |
|
31334
c892163971f2
Use the serializing function for SlpMsgParts on a direct connection.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31303
diff
changeset
|
546 | 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
|
547 | 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
|
548 | 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
|
549 | |
|
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 | 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
|
551 | 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
|
552 | |
|
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 | 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
|
554 | } |
|
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 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
556 | static int |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
557 | msn_dc_process_packet(MsnDirectConn *dc, guint32 packet_length) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
558 | { |
|
31060
67d11dfa6338
Process SlpMessageParts, a sequence of parts will generate a SlpMessage.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31055
diff
changeset
|
559 | MsnSlpMessagePart *part; |
|
67d11dfa6338
Process SlpMessageParts, a sequence of parts will generate a SlpMessage.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31055
diff
changeset
|
560 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
561 | 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
|
562 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
563 | switch (dc->state) { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
564 | 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
|
565 | break; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
566 | |
|
30076
2b751385616f
Minor cleanups.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30075
diff
changeset
|
567 | 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
|
568 | /* 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
|
569 | 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
|
570 | 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
|
571 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
572 | 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
|
573 | break; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
574 | |
|
30076
2b751385616f
Minor cleanups.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30075
diff
changeset
|
575 | 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
|
576 | 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
|
577 | 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
|
578 | |
|
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
|
579 | 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
|
580 | dc->state = DC_STATE_ESTABLISHED; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
581 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
582 | 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
|
583 | dc->slpcall = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
584 | break; |
| 30067 | 585 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
586 | 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
|
587 | 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
|
588 | 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
|
589 | |
|
30068
ade8dd1a1339
Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30067
diff
changeset
|
590 | dc->state = DC_STATE_ESTABLISHED; |
| 30067 | 591 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
592 | 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
|
593 | dc->slpcall = NULL; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
594 | break; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
595 | |
|
30068
ade8dd1a1339
Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30067
diff
changeset
|
596 | 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
|
597 | 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
|
598 | 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
|
599 | 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
|
600 | 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
|
601 | if (part) { |
|
26fc2e71129a
Ignore short packets related to p2pv2.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31247
diff
changeset
|
602 | 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
|
603 | msn_slpmsgpart_unref(part); |
|
26fc2e71129a
Ignore short packets related to p2pv2.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31247
diff
changeset
|
604 | } |
|
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
|
605 | } |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
606 | |
|
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 | 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
|
609 | 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
|
610 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
611 | 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
|
612 | } |
|
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 | break; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
615 | } |
|
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 | return DC_PROCESS_OK; |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
618 | } |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
619 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
620 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
621 | msn_dc_recv_cb(gpointer data, gint fd, PurpleInputCondition cond) |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
622 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
623 | MsnDirectConn *dc; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
624 | int free_buf_space; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
625 | int bytes_received; |
|
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
626 | guint32 packet_length; |
| 30067 | 627 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
628 | 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
|
629 | 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
|
630 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
631 | dc = data; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
632 | free_buf_space = dc->in_size - dc->in_pos; |
| 30067 | 633 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
634 | 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
|
635 | 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
|
636 | 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
|
637 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
638 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
639 | 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
|
640 | |
|
30068
ade8dd1a1339
Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30067
diff
changeset
|
641 | 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
|
642 | 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
|
643 | else |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
644 | 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
|
645 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
646 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
647 | } 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
|
648 | /* 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
|
649 | purple_debug_info("msn", "msn_dc_recv_cb: recv EOF\n"); |
| 30067 | 650 | |
|
30068
ade8dd1a1339
Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30067
diff
changeset
|
651 | 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
|
652 | 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
|
653 | else |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
654 | 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
|
655 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
656 | } |
| 30067 | 657 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
658 | dc->progress = TRUE; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
659 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
660 | 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
|
661 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
662 | /* 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
|
663 | 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
|
664 | packet_length = GUINT32_FROM_LE(*((guint32*)dc->in_buffer)); |
| 30067 | 665 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
666 | 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
|
667 | /* Oversized packet */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
668 | 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
|
669 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
670 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
671 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
672 | /* Wait for the whole packet to arrive */ |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
673 | if ((guint32)dc->in_pos < 4 + packet_length) |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
674 | return; |
| 30067 | 675 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
676 | 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
|
677 | 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
|
678 | return; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
679 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
680 | 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
|
681 | 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
|
682 | 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
|
683 | return; |
| 30067 | 684 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
685 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
686 | |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
687 | if ((guint32)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
|
688 | 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
|
689 | } |
|
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 | 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
|
692 | } |
|
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 | static gboolean |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
696 | 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
|
697 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
698 | MsnDirectConn *dc = data; |
| 30067 | 699 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
700 | 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
|
701 | |
|
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
|
702 | 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
|
703 | 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
|
704 | 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
|
705 | } 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
|
706 | 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
|
707 | 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
|
708 | 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
|
709 | } |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
710 | } |
|
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 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
713 | 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
|
714 | { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
715 | g_return_if_fail(dc != NULL); |
| 30067 | 716 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
717 | 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
|
718 | 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
|
719 | 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
|
720 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
721 | 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
|
722 | 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
|
723 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
724 | 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
|
725 | } |
|
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 | void |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
728 | 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
|
729 | { |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
730 | MsnDirectConn *dc = data; |
| 30067 | 731 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
732 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
733 | 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
|
734 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
735 | 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
|
736 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
737 | 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
|
738 | 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
|
739 | dc->connect_timeout_handle = 0; |
| 30067 | 740 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
741 | dc->fd = fd; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
742 | 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
|
743 | 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
|
744 | 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
|
745 | 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
|
746 | 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
|
747 | } |
|
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 | |
| 30067 | 750 | /* |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
751 | * 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
|
752 | * 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
|
753 | */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
754 | static gboolean |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
755 | msn_dc_incoming_connection_timeout_cb(gpointer data) { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
756 | MsnDirectConn *dc = data; |
| 30067 | 757 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
758 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
759 | purple_debug_info("msn", "msn_dc_incoming_connection_timeout_cb %p\n", dc); |
| 30067 | 760 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
761 | 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
|
762 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
763 | 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
|
764 | 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
|
765 | 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
|
766 | } |
|
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 | 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
|
769 | 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
|
770 | 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
|
771 | } |
|
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 | 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
|
774 | 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
|
775 | close(dc->listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
776 | dc->listenfd = -1; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
777 | } |
|
14174
1615a99529dc
[gaim-migrate @ 16746]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
778 | |
|
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
|
779 | 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
|
780 | 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
|
781 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
782 | return FALSE; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
783 | } |
|
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 | * 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
|
787 | * 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
|
788 | */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
789 | gboolean |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
790 | 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
|
791 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
792 | MsnDirectConn *dc = data; |
| 30067 | 793 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
794 | 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
|
795 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
796 | g_return_val_if_fail(dc != NULL, FALSE); |
| 30067 | 797 | |
|
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
|
798 | 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
|
799 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
800 | 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
|
801 | 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
|
802 | 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
|
803 | } |
|
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 | 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
|
806 | /* 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
|
807 | 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
|
808 | NULL, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
809 | 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
|
810 | dc->ext_ip, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
811 | dc->ext_port, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
812 | 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
|
813 | dc |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
814 | ); |
|
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 | 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
|
817 | 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
|
818 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
819 | 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
|
820 | 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
|
821 | 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
|
822 | 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
|
823 | dc |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
824 | ); |
|
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
|
825 | } 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
|
826 | /* |
|
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 | * 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
|
828 | * 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
|
829 | */ |
|
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 | 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
|
831 | } |
|
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 | } else { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
834 | /* |
|
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
|
835 | * 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
|
836 | * 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
|
837 | */ |
|
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
|
838 | 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
|
839 | } |
|
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 | return FALSE; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
842 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
843 | |
| 30067 | 844 | /* |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
845 | * 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
|
846 | * 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
|
847 | */ |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
848 | static void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
849 | 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
|
850 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
851 | MsnDirectConn *dc = data; |
| 30067 | 852 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
853 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
854 | 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
|
855 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
856 | g_return_if_fail(dc != NULL); |
| 30067 | 857 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
858 | 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
|
859 | 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
|
860 | 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
|
861 | } |
|
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 | 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
|
864 | 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
|
865 | 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
|
866 | } |
| 30067 | 867 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
868 | 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
|
869 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
870 | 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
|
871 | close(dc->listenfd); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
872 | dc->listenfd = -1; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
873 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
874 | 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
|
875 | 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
|
876 | 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
|
877 | } |
|
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 | void |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
881 | 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
|
882 | { |
|
30069
e10a97223cf8
Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30068
diff
changeset
|
883 | 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
|
884 | |
|
30074
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
885 | if (purple_debug_is_verbose()) |
|
f8a8097f6191
This DC stuff seems a bit verbose.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30073
diff
changeset
|
886 | purple_debug_info("msn", "msn_dc_listen_socket_created_cb %p\n", dc); |
| 30067 | 887 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
888 | g_return_if_fail(dc != NULL); |
| 30067 | 889 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
890 | 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
|
891 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
892 | 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
|
893 | 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
|
894 | 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
|
895 | int port; |
|
14174
1615a99529dc
[gaim-migrate @ 16746]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
896 | |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
897 | 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
|
898 | 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
|
899 | 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
|
900 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
901 | dc->listenfd = listenfd; |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
902 | 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
|
903 | listenfd, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
904 | PURPLE_INPUT_READ, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
905 | 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
|
906 | dc |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
907 | ); |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
908 | 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
|
909 | 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
|
910 | 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
|
911 | dc |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
912 | ); |
|
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 | 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
|
915 | 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
|
916 | "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
|
917 | "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
|
918 | "%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
|
919 | "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
|
920 | "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
|
921 | "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
|
922 | "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
|
923 | "\r\n", |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
924 | |
|
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
|
925 | 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
|
926 | dc->nonce_hash, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
927 | ext_ip, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
928 | port, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
929 | int_ip, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
930 | port |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
931 | ); |
|
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 | } else { |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
934 | 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
|
935 | "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
|
936 | "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
|
937 | "%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
|
938 | "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
|
939 | "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
|
940 | "\r\n", |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
941 | |
|
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
|
942 | 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
|
943 | dc->nonce_hash, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
944 | ext_ip, |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
945 | port |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
946 | ); |
|
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 | 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
|
950 | 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
|
951 | 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
|
952 | |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
953 | 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
|
954 | } |
|
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
955 | } |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
diff
changeset
|
956 | } |
|
30066
25742b976ce2
Initial support for direct connections. Preliminary patch from ticket #247
Gábor Szuromi <kukkerman@gmail.com>
parents:
28170
diff
changeset
|
957 |