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