annotate libpurple/protocols/msn/directconn.c @ 30020:264c76d29ab0

I don't like accessing memory by magic-constant.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Thu, 18 Mar 2010 04:30:27 +0000
parents bc720282a62d
children 24579d001831
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)
264c76d29ab0 I don't like accessing memory by magic-constant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30019
diff changeset
46 #define DC_MAX_BODY_SIZE 1352
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
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
50 msn_dc_generate_nonce(MsnDirectConn *dc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
52 PurpleCipher *cipher = NULL;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
53 PurpleCipherContext *context = NULL;
30019
bc720282a62d Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30018
diff changeset
54 guint32 *nonce;
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
55 int i;
30019
bc720282a62d Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30018
diff changeset
56 guchar digest[20];
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
58 cipher = purple_ciphers_find_cipher("sha1");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
59 g_return_if_fail(cipher != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
60
30019
bc720282a62d Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30018
diff changeset
61 nonce = (guint32 *)&dc->nonce;
bc720282a62d Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30018
diff changeset
62 for (i = 0; i < 4; i++)
bc720282a62d Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30018
diff changeset
63 nonce[i] = rand();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
65 context = purple_cipher_context_new(cipher, NULL);
30019
bc720282a62d Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30018
diff changeset
66 purple_cipher_context_append(context, dc->nonce, sizeof(dc->nonce));
bc720282a62d Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30018
diff changeset
67 purple_cipher_context_digest(context, sizeof(digest), digest, NULL);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
68 purple_cipher_context_destroy(context);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69
30019
bc720282a62d Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30018
diff changeset
70 g_sprintf(dc->nonce_hash,
bc720282a62d Clean up msn_dc_generate_nonce. It just looked weird.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30018
diff changeset
71 "%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
72 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
73 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
74 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
75 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
76 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
77 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
78 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
79 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
81 static MsnDirectConnPacket*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
82 msn_dc_new_packet()
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
83 {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
84 MsnDirectConnPacket *p;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
86 p = g_new0(MsnDirectConnPacket, 1);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
87 p->data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
88 p->sent_cb = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
89 p->msg = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
91 return p;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
94 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
95 msn_dc_destroy_packet(MsnDirectConnPacket *p)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
96 {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
97 if (p->data)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
98 g_free(p->data);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
99
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
100 if (p->msg)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
101 msn_message_unref(p->msg);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
103 g_free(p);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
104 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
106 MsnDirectConn*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
107 msn_dc_new(MsnSlpCall *slpcall)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
108 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
109 MsnDirectConn *dc;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
110
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
111 purple_debug_info("msn", "msn_dc_new\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
113 g_return_val_if_fail(slpcall != NULL, NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
114
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
115 dc = g_new0(MsnDirectConn, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
117 dc->slplink = slpcall->slplink;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
118 dc->slpcall = slpcall;
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 if (dc->slplink->dc != NULL)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
121 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
122
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
123 dc->slplink->dc = dc;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
125 dc->msg_body = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
126 dc->prev_ack = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
127 dc->listen_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
128 dc->connect_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
129 dc->listenfd = -1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
130 dc->listenfd_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
131 dc->connect_timeout_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
132 dc->fd = -1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
133 dc->recv_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
134 dc->send_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
135 dc->state = DC_STATE_CLOSED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
136 dc->in_buffer = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
137 dc->out_queue = g_queue_new();
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
138 dc->msg_pos = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
139 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
140 dc->ext_ip = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
141 dc->timeout_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
142 dc->progress = FALSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
143 //dc->num_calls = 1;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
145 msn_dc_generate_nonce(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
146
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
147 return dc;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
148 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
150 void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
151 msn_dc_destroy(MsnDirectConn *dc)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
152 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
153 MsnSlpLink *slplink;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
154
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
155 purple_debug_info("msn", "msn_dc_destroy\n");
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
156
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
157 g_return_if_fail(dc != NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
159 slplink = dc->slplink;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
161 if (dc->slpcall != NULL)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
162 dc->slpcall->wait_for_socket = FALSE;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
163
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
164 slplink->dc = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
165
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
166 if (slplink->swboard == NULL)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
167 msn_slplink_destroy(slplink);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
169 if (dc->msg_body != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
170 g_free(dc->msg_body);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
171 dc->msg_body = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
172 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
173
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
174 if (dc->prev_ack) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
175 msn_slpmsg_destroy(dc->prev_ack);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
176 dc->prev_ack = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
179 if (dc->listen_data != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
180 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
181 dc->listen_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
182 }
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->connect_data != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
185 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
186 dc->connect_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
187 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
188
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
189 if (dc->listenfd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
190 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
191 close(dc->listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
192 dc->listenfd = -1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
193 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
194
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
195 if (dc->listenfd_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
196 purple_timeout_remove(dc->listenfd_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
197 dc->listenfd_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
198 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
199
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
200 if (dc->connect_timeout_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
201 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
202 dc->connect_timeout_handle = 0;
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->fd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
206 close(dc->fd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
207 dc->fd = -1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
208 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
209
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
210 if (dc->send_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
211 purple_input_remove(dc->send_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
212 dc->send_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
213 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
214
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
215 if (dc->recv_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
216 purple_input_remove(dc->recv_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
217 dc->recv_handle = 0;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
220 if (dc->in_buffer != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
221 g_free(dc->in_buffer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
222 dc->in_buffer = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
223 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
224
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
225 if (dc->out_queue != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
226 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
227 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
228
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
229 g_queue_free(dc->out_queue);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 }
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->ext_ip != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
233 g_free(dc->ext_ip);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
234 dc->ext_ip = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
235 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
237 if (dc->timeout_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
238 purple_timeout_remove(dc->timeout_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
239 dc->timeout_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
240 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
241
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
242 g_free(dc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 }
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 /*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
246 void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
247 msn_dc_ref(MsnDirectConn *dc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248 {
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
249 g_return_if_fail(dc != NULL);
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 dc->num_calls++;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
255 msn_dc_unref(MsnDirectConn *dc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 {
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
257 g_return_if_fail(dc != NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
259
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
260 if (dc->num_calls > 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
261 dc->num_calls--;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
262 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263 }
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
264 */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
267 msn_dc_send_invite(MsnDirectConn *dc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
269 MsnSlpCall *slpcall;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
270 MsnSlpMessage *msg;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
271 gchar *header;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
272
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
273 purple_debug_info("msn", "msn_dc_send_invite\n");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
274
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
275 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
276
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
277 slpcall = dc->slpcall;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
278 g_return_if_fail(slpcall != NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
280 header = g_strdup_printf(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
281 "INVITE MSNMSGR:%s MSNSLP/1.0",
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
282 slpcall->slplink->remote_user
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
283 );
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
284
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
285 msg = msn_slpmsg_sip_new(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
286 slpcall,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
287 0,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
288 header,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
289 slpcall->branch,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
290 "application/x-msnmsgr-transrespbody",
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
291 dc->msg_body
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
292 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
293 g_free(header);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
294 g_free(dc->msg_body);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
295 dc->msg_body = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
297 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
298 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
299
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
300 void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
301 msn_dc_send_ok(MsnDirectConn *dc)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
302 {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
303 purple_debug_info("msn", "msn_dc_send_ok\n");
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 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
306
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
307 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
308 "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
309 g_free(dc->msg_body);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
310 dc->msg_body = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
311
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
312 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
313 msn_slpmsg_destroy(dc->prev_ack);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
314 dc->prev_ack = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
315 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
316 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318 static void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
319 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
320 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
321 MsnSlpCall *slpcall;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
322 PurpleXfer *xfer;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
323
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
324 purple_debug_info("msn", "msn_dc_try_fallback_to_p2p\n");
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
325
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
326 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
327
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
328 slpcall = dc->slpcall;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
329 g_return_if_fail(slpcall != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
330
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
331 xfer = slpcall->xfer;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
332 g_return_if_fail(xfer != NULL);
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
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
336 msn_slpcall_session_init(slpcall);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
337
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
338 /*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
339 switch (purple_xfer_get_status(xfer)) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
340 case PURPLE_XFER_STATUS_NOT_STARTED:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
341 case PURPLE_XFER_STATUS_ACCEPTED:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
342 msn_slpcall_session_init(slpcall);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
343 break;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
345 case PURPLE_XFER_STATUS_STARTED:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
346 slpcall->session_init_cb = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
347 slpcall->end_cb = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
348 slpcall->progress_cb = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
349 slpcall->cb = NULL;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
350
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
351 if (fail_local)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
352 purple_xfer_cancel_local(xfer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
353 else
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
354 purple_xfer_cancel_remote(xfer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
355 break;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
357 default:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
358 slpcall->session_init_cb = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
359 slpcall->end_cb = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
360 slpcall->progress_cb = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
361 slpcall->cb = NULL;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
362
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
363 if (fail_local)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
364 purple_xfer_cancel_local(xfer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
365 else
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
366 purple_xfer_cancel_remote(xfer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
367
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
368 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
369 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
370 */
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
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
373 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
374 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
375 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
376 MsnSlpHeader *h;
30020
264c76d29ab0 I don't like accessing memory by magic-constant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30019
diff changeset
377 MsnDcContext *context;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
378
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
379 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
380
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
381 h = &dc->header;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
382 /* 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
383 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
384
30020
264c76d29ab0 I don't like accessing memory by magic-constant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30019
diff changeset
385 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
386 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
387 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
388 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
389 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
390 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
391 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
392 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
393 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
394 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
395
30018
e0c368986e1f OK, so maybe this one does need to be static.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30017
diff changeset
396 static const gchar *
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
397 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
398 MsnSlpHeader *h;
264c76d29ab0 I don't like accessing memory by magic-constant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30019
diff changeset
399 static MsnDcContext bin_header;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
400
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
401 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
402
30020
264c76d29ab0 I don't like accessing memory by magic-constant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30019
diff changeset
403 h = &dc->header;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
404
30020
264c76d29ab0 I don't like accessing memory by magic-constant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30019
diff changeset
405 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
406 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
407 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
408 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
409 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
410 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
411 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
412 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
413 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
414
30020
264c76d29ab0 I don't like accessing memory by magic-constant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30019
diff changeset
415 return (const gchar *)&bin_header;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
416 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
418 /*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
419 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
420 msn_dc_send_bye(MsnDirectConn *dc)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
421 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
422 MsnSlpLink *slplink;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
423 PurpleAccount *account;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
424 char *body;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
425 int body_len;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
426
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
427 purple_debug_info("msn", "msn_dc_send_bye\n");
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
428
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
429 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
430 g_return_if_fail(dc->slpcall != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
431
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
432 slplink = dc->slpcall->slplink;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
433 account = slplink->session->account;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
434
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
435 dc->header.session_id = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
436 dc->header.id = dc->slpcall->slplink->slp_seq_id++;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
437 dc->header.offset = 0;
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
438
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
439 body = g_strdup_printf(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
440 "BYE MSNMSGR:%s MSNSLP/1.0\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
441 "To: <msnmsgr:%s>\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
442 "From: <msnmsgr:%s>\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
443 "Via: MSNSLP/1.0/TLP ;branch={%s}\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
444 "CSeq: 0\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
445 "Call-ID: {%s}\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
446 "Max-Forwards: 0\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
447 "Content-Type: application/x-msnmsgr-sessionclosebody\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
448 "Content-Length: 3\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
449 "\r\n\r\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
451 slplink->remote_user,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
452 slplink->remote_user,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
453 purple_account_get_username(account),
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
454 dc->slpcall->branch,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
455 dc->slpcall->id
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
456 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
457 body_len = strlen(body) + 1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
458 memcpy(dc->buffer, body, body_len);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
459 g_free(body);
19843
60bc06498746 Committing khc's msnp14 changes from Trac Ticket #148. --rlaager
Ka-Hing Cheung <khc@hxbc.us>
parents: 15822
diff changeset
460
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
461 dc->header.total_size = body_len;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
462 dc->header.length = body_len;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
463 dc->header.flags = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
464 dc->header.ack_sub_id = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
465 dc->header.ack_size = 0;
19843
60bc06498746 Committing khc's msnp14 changes from Trac Ticket #148. --rlaager
Ka-Hing Cheung <khc@hxbc.us>
parents: 15822
diff changeset
466
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
467 msn_dc_send_packet(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
468 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
470 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
471 msn_dc_send_ack(MsnDirectConn *dc)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
472 {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
473 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
474
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
475 dc->header.session_id = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
476 dc->header.ack_sub_id = dc->header.ack_id;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
477 dc->header.ack_id = dc->header.id;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
478 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
479 dc->header.offset = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
480 dc->header.length = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
481 dc->header.flags = 0x02;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
482 dc->header.ack_size = dc->header.total_size;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
483
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
484 msn_dc_send_packet(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
485 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
486
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
487 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
488 msn_dc_send_data_ack(MsnDirectConn *dc)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
489 {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
490 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
491
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
492 dc->header.session_id = dc->slpcall->session_id;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
493 dc->header.ack_sub_id = dc->header.ack_id;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
494 dc->header.ack_id = dc->header.id;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
495 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
496 dc->header.offset = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
497 dc->header.length = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
498 dc->header.flags = 0x02;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
499 dc->header.ack_size = dc->header.total_size;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
500
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
501 msn_dc_send_packet(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
502 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
504 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
505 msn_dc_xfer_send_cancel(PurpleXfer *xfer)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
506 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
507 MsnSlpCall *slpcall;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
508 MsnDirectConn *dc;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
509
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
510 purple_debug_info("msn", "msn_dc_xfer_send_cancel\n");
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
511
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
512 g_return_if_fail(xfer != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
513
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
514 slpcall = xfer->data;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
515 g_return_if_fail(slpcall != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
516
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
517 dc = slpcall->dc;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
518 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
519
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
520 switch (dc->state) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
521 case DC_STATE_TRANSFER:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
522 msn_dc_send_bye(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
523 dc->state = DC_STATE_CANCELLED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
524 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
525
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
526 default:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
527 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
528 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
529 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
530 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
532 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
533 msn_dc_xfer_recv_cancel(PurpleXfer *xfer)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
534 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
535 MsnSlpCall *slpcall;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
536 MsnDirectConn *dc;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
537
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
538 purple_debug_info("msn", "msn_dc_xfer_recv_cancel\n");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
539
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
540 g_return_if_fail(xfer != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
541
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
542 slpcall = xfer->data;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
543 g_return_if_fail(slpcall != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
544
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
545 dc = slpcall->dc;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
546 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
547
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
548 switch (dc->state) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
549 case DC_STATE_TRANSFER:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
550 msn_dc_send_bye(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
551 dc->state = DC_STATE_CANCELLED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
552 break;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
554 default:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
555 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
556 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
557 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
558 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
559 */
19843
60bc06498746 Committing khc's msnp14 changes from Trac Ticket #148. --rlaager
Ka-Hing Cheung <khc@hxbc.us>
parents: 15822
diff changeset
560
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
561 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
562 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
563 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
564 MsnDirectConn *dc = data;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
565 MsnDirectConnPacket *p;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
566 int bytes_to_send;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
567 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
568
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
569 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
570 g_return_if_fail(fd != -1);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
571
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
572 if(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
573 if (dc->send_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
574 purple_input_remove(dc->send_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
575 dc->send_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
576 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
579
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
580 p = g_queue_peek_head(dc->out_queue);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
581 bytes_to_send = p->length - dc->msg_pos;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
582
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
583 bytes_sent = send(fd, p->data, bytes_to_send, 0);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
584 if (bytes_sent < 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
585 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
586 return;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
587
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
588 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
589 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
590 return;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
593 dc->progress = TRUE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
594
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
595 dc->msg_pos += bytes_sent;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
596 if (dc->msg_pos == p->length) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
597 if (p->sent_cb != NULL)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
598 p->sent_cb(p);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
600 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
601 msn_dc_destroy_packet(p);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
602
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
603 dc->msg_pos = 0;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
606
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
607 static void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
608 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
609 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
610 gboolean was_empty;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
611
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
612 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
613 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
614
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
615 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
616 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
617 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
618 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620
20578
7c30d5aa5e01 Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20514
diff changeset
621 static void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
622 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
623 {
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
624 MsnDirectConnPacket *p;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
625
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
626 purple_debug_info("msn", "msn_dc_send_foo\n");
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
627
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
628 g_return_if_fail(dc != NULL);
20578
7c30d5aa5e01 Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20514
diff changeset
629
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
630 p = msn_dc_new_packet();
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
631
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
632 p->length = 8;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
633 p->data = (guchar*)g_strdup("\4\0\0\0foo");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
634 p->sent_cb = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
635
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
636 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
637 }
7c30d5aa5e01 Fix incorrect purple_proxy_connect() callback and comment out an unused function.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20514
diff changeset
638
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
639 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
640 msn_dc_send_handshake(MsnDirectConn *dc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
641 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
642 MsnDirectConnPacket *p;
30018
e0c368986e1f OK, so maybe this one does need to be static.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30017
diff changeset
643 const gchar *h;
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
644 guint32 l;
30013
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 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
647
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
648 p = msn_dc_new_packet();
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
649
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
650 p->length = 4 + DC_PACKET_HEADER_SIZE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
651 p->data = g_malloc(p->length);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
653 l = DC_PACKET_HEADER_SIZE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
654 l = GUINT32_TO_LE(l);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
655 memcpy(p->data, &l, 4);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
656
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
657 dc->header.session_id = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
658 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
659 dc->header.offset = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
660 dc->header.total_size = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
661 dc->header.length = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
662 dc->header.flags = 0x100;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
663
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
664 h = msn_dc_serialize_binary_header(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
665 memcpy(p->data + 4, h, DC_PACKET_HEADER_SIZE);
30020
264c76d29ab0 I don't like accessing memory by magic-constant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30019
diff changeset
666 memcpy(p->data + 4 + offsetof(MsnDcContext, ack_id), dc->nonce, 16);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
667
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
668 msn_dc_enqueue_packet(dc, p);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
669 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
671 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
672 msn_dc_send_handshake_reply(MsnDirectConn *dc)
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
673 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
674 MsnDirectConnPacket *p;
30018
e0c368986e1f OK, so maybe this one does need to be static.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30017
diff changeset
675 const gchar *h;
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
676 guint32 l;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
677
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
678 g_return_if_fail(dc != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
679
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
680 p = msn_dc_new_packet();
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
681
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
682 p->length = 4 + DC_PACKET_HEADER_SIZE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
683 p->data = g_malloc(p->length);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
684
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
685 l = DC_PACKET_HEADER_SIZE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
686 l = GUINT32_TO_LE(l);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
687 memcpy(p->data, &l, 4);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
688
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
689 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
690 dc->header.length = 0;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
691
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
692 h = msn_dc_serialize_binary_header(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
693 memcpy(p->data + 4, h, DC_PACKET_HEADER_SIZE);
30020
264c76d29ab0 I don't like accessing memory by magic-constant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30019
diff changeset
694 memcpy(p->data + 4 + offsetof(MsnDcContext, ack_id), dc->nonce, 16);
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
695
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
696 msn_dc_enqueue_packet(dc, p);
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
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
699 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
700 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
701 {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
702 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
703 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
704 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
705
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
706 void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
707 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
708 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
709 MsnDirectConnPacket *p = msn_dc_new_packet();
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
710 guint32 length = msg->body_len + DC_PACKET_HEADER_SIZE;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
711
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
712 p->length = 4 + length;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
713 p->data = g_malloc(p->length);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
714
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
715 length = GUINT32_TO_LE(length);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
716 memcpy(p->data, &length, 4);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
717 memcpy(p->data + 4, &msg->msnslp_header, DC_PACKET_HEADER_SIZE);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
718 memcpy(p->data + 4 + DC_PACKET_HEADER_SIZE, msg->body, msg->body_len);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
719
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
720 p->sent_cb = msn_dc_send_packet_cb;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
721 p->msg = msg;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
722 msn_message_ref(msg);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
723
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
724 msn_dc_enqueue_packet(dc, p);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
725 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
726
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
727 static int
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
728 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
729 {
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
730 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
731
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
732 switch (dc->state) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
733 case DC_STATE_CLOSED:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
734 break;
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 case DC_STATE_FOO: {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
737 /* 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
738 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
739 return DC_PROCESS_FALLBACK;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
740
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
741 dc->state = DC_STATE_HANDSHAKE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
742 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
743 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
744
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
745 case DC_STATE_HANDSHAKE: {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
746 if (packet_length != DC_PACKET_HEADER_SIZE)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
747 return DC_PROCESS_FALLBACK;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
748
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
749 /* TODO: Check! */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
750 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
751 dc->state = DC_STATE_ESTABLISHED;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
752
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
753 msn_slpcall_session_init(dc->slpcall);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
754 dc->slpcall = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
755 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
756 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
757
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
758 case DC_STATE_HANDSHAKE_REPLY:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
759 /* TODO: Check! */
30015
bcb5e6c2e5a3 Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30014
diff changeset
760 dc->state = DC_STATE_ESTABLISHED;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
761
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
762 msn_slpcall_session_init(dc->slpcall);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
763 dc->slpcall = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
764 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
765
30015
bcb5e6c2e5a3 Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30014
diff changeset
766 case DC_STATE_ESTABLISHED:
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
767 msn_slplink_process_msg(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
768 dc->slplink,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
769 &dc->header,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
770 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
771 dc->header.length
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
772 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
773
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
774 /*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
775 if (dc->num_calls == 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
776 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
777
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
778 return DC_PROCESS_CLOSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
779 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
780 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
781 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
782 #if 0
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
783 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
784 guint64 file_size;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
785 int bytes_written;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
786 PurpleXfer *xfer;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
787 MsnSlpHeader *h = &dc->header;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
788
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
789 if (packet_length < DC_PACKET_HEADER_SIZE)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
790 return DC_TRANSFER_FALLBACK;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
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 * TODO: MSN Messenger 7.0 sends BYE with flags 0x0000000 so we'll get rid of
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
794 * 0x1000000 bit but file data is always sent with flags 0x1000030 in both
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
795 * MSN Messenger and Live.*/
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
796 switch (h->flags) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
797 case 0x0000000:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
798 case 0x1000000:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
799 msn_dc_send_ack(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
800 if (strncmp(dc->buffer, "BYE", 3) == 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
801 /* Remote side cancelled the transfer. */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
802 purple_xfer_cancel_remote(dc->slpcall->xfer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
803 return DC_TRANSFER_CANCELLED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
804 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
805 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
806
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
807 case 0x1000030:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
808 /* File data */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
809 xfer = dc->slpcall->xfer;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
810 file_size = purple_xfer_get_size(xfer);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
811
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
812 /* Packet sanity checks */
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
813 if ( h->session_id != dc->slpcall->session_id ||
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
814 h->offset >= file_size ||
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
815 h->total_size != file_size ||
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
816 h->length != packet_length - DC_PACKET_HEADER_SIZE ||
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
817 h->offset + h->length > file_size) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
818
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
819 purple_debug_warning("msn", "msn_dc_recv_process_packet_cb: packet range check error!\n");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
820 purple_xfer_cancel_local(dc->slpcall->xfer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
821 return DC_TRANSFER_CANCELLED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
822 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
823
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
824 bytes_written = fwrite(dc->buffer, 1, h->length, xfer->dest_fp);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
825 if (bytes_written != h->length) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
826 purple_debug_warning("msn", "msn_dc_recv_process_packet_cb: cannot write whole packet to file!\n");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
827 purple_xfer_cancel_local(dc->slpcall->xfer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
828 return DC_TRANSFER_CANCELLED;
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 xfer->bytes_sent = (h->offset + h->length);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
832 xfer->bytes_remaining = h->total_size - xfer->bytes_sent;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
833
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
834 purple_xfer_update_progress(xfer);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
835
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
836 if (xfer->bytes_remaining == 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
837 /* ACK only the last data packet */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
838 msn_dc_send_data_ack(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
839 purple_xfer_set_completed(xfer, TRUE);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
840 dc->state = DC_STATE_BYE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
841 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
842 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
843 default:
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
844 /*
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
845 * TODO: Packet with unknown flags. Should we ACK these?
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
846 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
847 msn_dc_send_ack(dc);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
848
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
849 purple_debug_warning(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
850 "msn",
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
851 "msn_dc_recv_process_packet_cb: received packet with unknown flags: 0x%08x\n",
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
852 dc->header.flags
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
853 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
854 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
855 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
856 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
857
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
858 case DC_STATE_BYE:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
859 /* TODO: Check! */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
860 switch (dc->header.flags) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
861 case 0x0000000:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
862 case 0x1000000:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
863 msn_dc_send_ack(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
864 if (strncmp(dc->buffer, "BYE", 3) == 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
865 dc->state = DC_STATE_COMPLETED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
866 return DC_TRANSFER_COMPLETED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
867 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
868 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
869
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
870 default:
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
871 /*
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
872 * TODO: Packet with unknown flags. Should we ACK these?
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
873 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
874 msn_dc_send_ack(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
875 purple_debug_warning(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
876 "msn",
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
877 "msn_dc_recv_process_packet_cb: received packet with unknown flags: 0x%08x\n",
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
878 dc->header.flags
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
879 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
880 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
881 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
882 #endif
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
883 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
884
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
885 return DC_PROCESS_OK;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
886 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
887
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
888 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
889 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
890 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
891 MsnDirectConn *dc;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
892 int free_buf_space;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
893 int bytes_received;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
894 guint32 packet_length;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
895
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
896 g_return_if_fail(data != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
897 g_return_if_fail(fd != -1);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
898
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
899 dc = data;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
900 free_buf_space = dc->in_size - dc->in_pos;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
901
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
902 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
903 if (bytes_received < 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
904 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
905 return;
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 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
908
30015
bcb5e6c2e5a3 Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30014
diff changeset
909 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
910 msn_dc_fallback_to_p2p(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
911 else
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
912 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
913 return;
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 } else if (bytes_received == 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
916 /* EOF. Remote side closed connection. */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
917 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
918
30015
bcb5e6c2e5a3 Re-indent directconn.h, and fix a typo.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30014
diff changeset
919 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
920 msn_dc_fallback_to_p2p(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
921 else
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
922 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
923 return;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
924 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
925
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
926 dc->progress = TRUE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
927
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
928 dc->in_pos += bytes_received;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
929
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
930 /* Wait for packet length */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
931 while (dc->in_pos >= 4) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
932 packet_length = *((guint32*)dc->in_buffer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
933 packet_length = GUINT32_FROM_LE(packet_length);
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 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
936 /* Oversized packet */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
937 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
938 return;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
939 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
940
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
941 /* 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
942 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
943 return;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
944
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
945 if (dc->state != DC_STATE_FOO) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
946 msn_dc_parse_binary_header(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
947 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
948
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
949 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
950 case DC_PROCESS_CLOSE:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
951 return;
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 case DC_PROCESS_FALLBACK:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
954 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
955 msn_dc_fallback_to_p2p(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
956 return;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
957
30013
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
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
960 if (dc->in_pos > packet_length + 4) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
961 memcpy(dc->in_buffer, dc->in_buffer + 4 + packet_length, dc->in_pos - packet_length - 4);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
962 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
963
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
964 dc->in_pos -= packet_length + 4;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
965 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
966 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
967
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
968 #if 0
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
969 static gboolean
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
970 msn_dc_send_next_packet(MsnDirectConn *dc)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
971 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
972 MsnSlpMessage *msg;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
973
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
974 if(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
975 return TRUE;
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 msg = g_queue_peek_head(dc->out_queue);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
978 msn_slplink_send_msgpart(dc->slplink, msg);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
979
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
980
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
981
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
982 PurpleXfer *xfer;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
983 int bytes_read;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
984
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
985 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
986 g_return_val_if_fail(dc->slpcall != NULL, FALSE);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
987
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
988 xfer = dc->slpcall->xfer;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
989
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
990 bytes_read = fread(dc->buffer, 1, DC_MAX_BODY_SIZE, xfer->dest_fp);
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 if (bytes_read > 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
993 dc->header.session_id = dc->slpcall->session_id;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
994 /* Only increment seq. ID before sending BYE */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
995 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
996 dc->header.offset = xfer->bytes_sent;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
997 dc->header.total_size = xfer->size;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
998 dc->header.length = bytes_read;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
999 dc->header.flags = 0x1000030;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1000 dc->header.ack_id = rand() % G_MAXUINT32;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1001 dc->header.ack_sub_id = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1002 dc->header.ack_size = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1003
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1004 msn_dc_send_packet(dc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1005
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1006 xfer->bytes_sent += bytes_read;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1007 xfer->bytes_remaining -= bytes_read;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1008 purple_xfer_update_progress(xfer);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1009
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1010 if (xfer->bytes_remaining == 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1011 purple_xfer_set_completed(xfer, TRUE);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1012
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1013 /* Increment seq. ID for the next BYE message */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1014 dc->slpcall->slplink->slp_seq_id++;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1015 dc->state = DC_STATE_DATA_ACK;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1016 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1017
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1018 } else {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1019 /* File read error */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1020 purple_xfer_cancel_local(xfer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1021 return FALSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1022 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1023
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1024 return TRUE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1025 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1026
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1027 static int
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1028 msn_dc_send_process_packet_cb(MsnDirectConn *dc, guint32 packet_length)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1029 {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1030 g_return_val_if_fail(dc != NULL, DC_TRANSFER_CANCELLED);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1031
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1032 switch (dc->state) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1033 case DC_STATE_FOO: {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1034 if (packet_length != 4)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1035 return DC_TRANSFER_FALLBACK;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1036
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1037 if (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
1038 return DC_TRANSFER_FALLBACK;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1039
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1040 dc->state = DC_STATE_HANDSHAKE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1041 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1042 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1043
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1044 case DC_STATE_HANDSHAKE: {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1045 if (packet_length != DC_PACKET_HEADER_SIZE)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1046 return DC_TRANSFER_FALLBACK;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1047
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1048 /* TODO: Check! */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1049 msn_dc_send_handshake_reply(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1050 dc->state = DC_STATE_TRANSFER;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1051
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1052 purple_xfer_set_request_denied_fnc(dc->slpcall->xfer, msn_dc_xfer_send_cancel);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1053 purple_xfer_set_cancel_send_fnc(dc->slpcall->xfer, msn_dc_xfer_send_cancel);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1054 purple_xfer_set_end_fnc(dc->slpcall->xfer, msn_dc_xfer_end);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1055 purple_xfer_start(dc->slpcall->xfer, -1, NULL, 0);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1056 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1057 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1058
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1059 case DC_STATE_HANDSHAKE_REPLY:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1060 /* TODO: Check! */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1061 dc->state = DC_STATE_TRANSFER;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1062 break;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1063
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1064 case DC_STATE_TRANSFER: {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1065 switch (dc->header.flags) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1066 case 0x0000000:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1067 case 0x1000000:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1068 msn_dc_send_ack(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1069 if (strncmp(dc->buffer, "BYE", 3) == 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1070 /* Remote side cancelled the transfer. */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1071 purple_xfer_cancel_remote(dc->slpcall->xfer);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1072 return DC_TRANSFER_CANCELLED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1073 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1074 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1075 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1076 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1077 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1078
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1079 case DC_STATE_DATA_ACK: {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1080 /* TODO: Check! */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1081 msn_dc_send_bye(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1082 dc->state = DC_STATE_BYE_ACK;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1083 break;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1084 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1085
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1086 case DC_STATE_BYE_ACK:
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1087 /* TODO: Check! */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1088 dc->state = DC_STATE_COMPLETED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1089 return DC_TRANSFER_COMPLETED;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1090 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1091
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1092 return DC_TRANSFER_OK;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1093 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1094 #endif
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1095
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1096 static gboolean
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1097 msn_dc_timeout(gpointer data)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1098 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
1099 MsnDirectConn *dc = data;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1100
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1101 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
1102
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1103 if (dc->progress)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1104 dc->progress = FALSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1105 else
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1106 msn_dc_destroy(dc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1107
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1108 return TRUE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1109 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1110
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1111 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1112 msn_dc_init(MsnDirectConn *dc)
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1113 {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1114 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1115
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1116 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
1117 dc->in_pos = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1118 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
1119
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1120 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
1121 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
1122
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1123 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
1124 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1125
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1126 void
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1127 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
1128 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
1129 MsnDirectConn *dc;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1130
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1131 purple_debug_info("msn", "msn_dc_connected_to_peer_cb\n");
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1132
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1133 g_return_if_fail(data != NULL);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1134
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1135 dc = data;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1136
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1137 dc->connect_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1138 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
1139 dc->connect_timeout_handle = 0;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1140
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1141 dc->fd = fd;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1142 if (dc->fd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1143 msn_dc_init(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1144 msn_dc_send_foo(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1145 msn_dc_send_handshake(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1146 dc->state = DC_STATE_HANDSHAKE_REPLY;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1147 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1148 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1149
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1150 /*
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1151 * This callback will be called when we're the server
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1152 * and nobody has connected us in DC_CONNECT_TIMEOUT seconds
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1153 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1154 static gboolean
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1155 msn_dc_incoming_connection_timeout_cb(gpointer data) {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
1156 MsnDirectConn *dc = data;
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
1157 MsnSlpCall *slpcall = dc->slpcall;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1158
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1159 purple_debug_info("msn", "msn_dc_incoming_connection_timeout_cb\n");
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1160
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1161 dc = data;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1162 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
1163
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1164 slpcall = dc->slpcall;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1165 g_return_val_if_fail(slpcall != NULL, FALSE);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1166
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1167 if (dc->listen_data != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1168 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
1169 dc->listen_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1170 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1171
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1172 if (dc->listenfd_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1173 purple_timeout_remove(dc->listenfd_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1174 dc->listenfd_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1175 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1176
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1177 if (dc->listenfd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1178 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
1179 close(dc->listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1180 dc->listenfd = -1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1181 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1182
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1183 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1184 /* Start p2p file transfer */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1185 msn_slpcall_session_init(slpcall);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1186
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1187 return FALSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1188 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1189
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1190 /*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1191 * This callback will be called when we're unable to connect to
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1192 * the remote host in DC_CONNECT_TIMEOUT seconds.
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1193 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1194 gboolean
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1195 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
1196 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
1197 MsnDirectConn *dc = data;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1198
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1199 purple_debug_info("msn", "msn_dc_outgoing_connection_timeout_cb\n");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1200
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1201 g_return_val_if_fail(dc != NULL, FALSE);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1202
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1203 if (dc->connect_timeout_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1204 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
1205 dc->connect_timeout_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1206 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1207
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1208 if (dc->connect_data != NULL) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1209 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
1210 dc->connect_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1211 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1212
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1213 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
1214 /* Try external IP/port if available. */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1215 dc->connect_data = purple_proxy_connect(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1216 NULL,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1217 dc->slpcall->slplink->session->account,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1218 dc->ext_ip,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1219 dc->ext_port,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1220 msn_dc_connected_to_peer_cb,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1221 dc
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1222 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1223
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1224 g_free(dc->ext_ip);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1225 dc->ext_ip = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1226
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1227 if (dc->connect_data) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1228 dc->connect_timeout_handle = purple_timeout_add_seconds(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1229 DC_CONNECT_TIMEOUT,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1230 msn_dc_outgoing_connection_timeout_cb,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1231 dc
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1232 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1233 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1234
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1235 } else {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1236 /*
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1237 * Both internal and external connection attempts are failed.
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1238 * Fall back to p2p transfer.
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1239 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1240 MsnSlpCall *slpcall = dc->slpcall;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1241
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1242 msn_dc_destroy(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1243 /* Start p2p file transfer */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1244 msn_slpcall_session_init(slpcall);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1245 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1246
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1247 return FALSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1248 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1249
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1250 /*
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1251 * This callback will be called when we're the server
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1252 * and somebody has connected to us in DC_CONNECT_TIMEOUT seconds.
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1253 */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1254 static void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1255 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
1256 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
1257 MsnDirectConn *dc = data;
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1258
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1259 purple_debug_info("msn", "msn_dc_incoming_connection_cb\n");
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1260
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1261 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1262
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1263 if (dc->connect_timeout_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1264 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
1265 dc->connect_timeout_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1266 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1267
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1268 if (dc->listenfd_handle != 0) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1269 purple_input_remove(dc->listenfd_handle);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1270 dc->listenfd_handle = 0;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1271 }
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1272
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1273 dc->fd = accept(listenfd, NULL, 0);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1274
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1275 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
1276 close(dc->listenfd);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1277 dc->listenfd = -1;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1278
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1279 if (dc->fd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1280 msn_dc_init(dc);
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1281 dc->state = DC_STATE_FOO;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1282 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1283 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1284
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1285 void
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1286 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
1287 {
30016
0ea33256f462 Tabs-to-spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30015
diff changeset
1288 MsnDirectConn *dc = data;
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1289
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1290 purple_debug_info("msn", "msn_dc_listen_socket_created_cb\n");
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1291
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1292 g_return_if_fail(dc != NULL);
30014
b1cda3f8fdc9 De-spacify.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30013
diff changeset
1293
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1294 dc->listen_data = NULL;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1295
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1296 if (listenfd != -1) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1297 const char *ext_ip;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1298 const char *int_ip;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1299 int port;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1300
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1301 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
1302 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
1303 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
1304
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1305 dc->listenfd = listenfd;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1306 dc->listenfd_handle = purple_input_add(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1307 listenfd,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1308 PURPLE_INPUT_READ,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1309 msn_dc_incoming_connection_cb,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1310 dc
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1311 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1312 dc->connect_timeout_handle = purple_timeout_add_seconds(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1313 DC_CONNECT_TIMEOUT * 2, /* Internal + external connection attempts */
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1314 msn_dc_incoming_connection_timeout_cb,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1315 dc
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1316 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1317
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1318 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
1319 dc->msg_body = g_strdup_printf(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1320 "Bridge: TCPv1\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1321 "Listening: true\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1322 "Hashed-Nonce: {%s}\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1323 "IPv4External-Addrs: %s\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1324 "IPv4External-Port: %d\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1325 "IPv4Internal-Addrs: %s\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1326 "IPv4Internal-Port: %d\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1327 "\r\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1328
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1329 dc->nonce_hash,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1330 ext_ip,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1331 port,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1332 int_ip,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1333 port
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1334 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1335
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1336 } else {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1337 dc->msg_body = g_strdup_printf(
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1338 "Bridge: TCPv1\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1339 "Listening: true\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1340 "Hashed-Nonce: {%s}\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1341 "IPv4External-Addrs: %s\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1342 "IPv4External-Port: %d\r\n"
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1343 "\r\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1344
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1345 dc->nonce_hash,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1346 ext_ip,
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1347 port
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1348 );
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1349 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1350
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1351 if (dc->slpcall->wait_for_socket) {
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1352 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
1353 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
1354
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1355 dc->slpcall->wait_for_socket = FALSE;
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1356 }
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1357 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1358 }
30013
119bd7b072eb Initial support for direct connections. Preliminary patch from ticket #247
kukkerman@gmail.com
parents: 27893
diff changeset
1359