annotate libpurple/protocols/msn/directconn.c @ 30088:e432507151d1

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