annotate src/protocols/oscar/oft.c @ 13616:ee7f92a706ac

[gaim-migrate @ 16002] Patch from Bj??rn Voigt on gaim-i18n to translate the search instructions that come from the Jabber server. He's provided the string for users.jabber.org, the most common case. This technique is a bit of a hack, but it seems like the best option we've got at the moment. I said I'd commit this as long as nobody objected. Also, there's a fix here in case xmlnode_get_data(instnode) returns NULL. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Mon, 10 Apr 2006 23:37:32 +0000
parents 6c34fbb75bbd
children 931320242432
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 * Gaim's oscar protocol plugin
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 * This file is the legal property of its developers.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 * Please see the AUTHORS file distributed alongside this file.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 * Lesser General Public License for more details.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22 * I feel like this is a good place to explain OFT, so I'm going to
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23 * do just that. Each OFT packet has a header type. I guess this
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
24 * is pretty similar to the subtype of a SNAC packet. The type
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
25 * basically tells the other client the meaning of the OFT packet.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
26 * There are two distinct types of file transfer, which I usually
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
27 * call "sendfile" and "getfile." Sendfile is when you send a file
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
28 * to another AIM user. Getfile is when you share a group of files,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
29 * and other users request that you send them the files.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
30 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 * A typical sendfile file transfer goes like this:
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
32 * 1) Sender sends a channel 2 ICBM telling the other user that
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33 * we want to send them a file. At the same time, we open a
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
34 * listener socket (this should be done before sending the
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35 * ICBM) on some port, and wait for them to connect to us.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
36 * The ICBM we sent should contain our IP address and the port
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
37 * number that we're listening on.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
38 * 2) The receiver connects to the sender on the given IP address
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
39 * and port. After the connection is established, the receiver
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
40 * sends an ICBM signifying that we are ready and waiting.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
41 * 3) The sender sends an OFT PROMPT message over the OFT
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42 * connection.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
43 * 4) The receiver of the file sends back an exact copy of this
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44 * OFT packet, except the cookie is filled in with the cookie
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
45 * from the ICBM. I think this might be an attempt to verify
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
46 * that the user that is connected is actually the guy that
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
47 * we sent the ICBM to. Oh, I've been calling this the ACK.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
48 * 5) The sender starts sending raw data across the connection
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
49 * until the entire file has been sent.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
50 * 6) The receiver knows the file is finished because the sender
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
51 * sent the file size in an earlier OFT packet. So then the
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
52 * receiver sends the DONE thingy (after filling in the
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
53 * "received" checksum and size) and closes the connection.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
54 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56 #include "oscar.h"
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57 #include "peer.h"
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60 * Calculate oft checksum of buffer
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62 * Prevcheck should be 0xFFFF0000 when starting a checksum of a file. The
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63 * checksum is kind of a rolling checksum thing, so each time you get bytes
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64 * of a file you just call this puppy and it updates the checksum. You can
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
65 * calculate the checksum of an entire file by calling this in a while or a
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 * for loop, or something.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68 * Thanks to Graham Booker for providing this improved checksum routine,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
69 * which is simpler and should be more accurate than Josh Myer's original
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
70 * code. -- wtm
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
71 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
72 * This algorithm works every time I have tried it. The other fails
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
73 * sometimes. So, AOL who thought this up? It has got to be the weirdest
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
74 * checksum I have ever seen.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
75 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
76 * @param buffer Buffer of data to checksum. Man I'd like to buff her...
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
77 * @param bufsize Size of buffer.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
78 * @param prevchecksum Previous checksum.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 static guint32
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
81 peer_oft_checksum_chunk(const guint8 *buffer, int bufferlen, guint32 prevchecksum)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
82 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
83 guint32 checksum, oldchecksum;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
84 int i;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
85 unsigned short val;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
87 checksum = (prevchecksum >> 16) & 0xffff;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
88 for (i = 0; i < bufferlen; i++)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
90 oldchecksum = checksum;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91 if (i & 1)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
92 val = buffer[i];
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93 else
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94 val = buffer[i] << 8;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95 checksum -= val;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 * The following appears to be necessary.... It happens
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
98 * every once in a while and the checksum doesn't fail.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100 if (checksum > oldchecksum)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101 checksum--;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
103 checksum = ((checksum & 0x0000ffff) + (checksum >> 16));
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
104 checksum = ((checksum & 0x0000ffff) + (checksum >> 16));
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 return checksum << 16;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 static guint32
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109 peer_oft_checksum_file(char *filename)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 FILE *fd;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112 guint32 checksum = 0xffff0000;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
114 if ((fd = fopen(filename, "rb")))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
115 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116 int bytes;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
117 guint8 buffer[1024];
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
118
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
119 while ((bytes = fread(buffer, 1, 1024, fd)) != 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
120 checksum = peer_oft_checksum_chunk(buffer, bytes, checksum);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121 fclose(fd);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
123
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
124 return checksum;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
125 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
126
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
127 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
128 * Free any OFT related data.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
129 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
130 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
131 peer_oft_close(PeerConnection *conn)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
132 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
133 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
134 * If canceled by local user, and we're receiving a file, and
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
135 * we're not connected/ready then send an ICBM cancel message.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
136 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
137 if ((gaim_xfer_get_status(conn->xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL) &&
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
138 !conn->ready)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
139 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
140 aim_im_sendch2_cancel(conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
141 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
142
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
143 if (conn->sending_data_timer != 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
144 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
145 gaim_timeout_remove(conn->sending_data_timer);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
146 conn->sending_data_timer = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
147 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
148 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
149
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
150 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
151 * Write the given OftFrame to a ByteStream and send it out
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
152 * on the established PeerConnection.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
153 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
154 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
155 peer_oft_send(PeerConnection *conn, OftFrame *frame)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
156 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
157 size_t length;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
158 ByteStream bs;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
159
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
160 length = 192 + MAX(64, frame->name_length + 1);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
161 byte_stream_init(&bs, malloc(length), length);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
162 byte_stream_putraw(&bs, conn->magic, 4);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
163 byte_stream_put16(&bs, length);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
164 byte_stream_put16(&bs, frame->type);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
165 byte_stream_putraw(&bs, frame->cookie, 8);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
166 byte_stream_put16(&bs, frame->encrypt);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
167 byte_stream_put16(&bs, frame->compress);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
168 byte_stream_put16(&bs, frame->totfiles);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
169 byte_stream_put16(&bs, frame->filesleft);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
170 byte_stream_put16(&bs, frame->totparts);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
171 byte_stream_put16(&bs, frame->partsleft);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
172 byte_stream_put32(&bs, frame->totsize);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
173 byte_stream_put32(&bs, frame->size);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
174 byte_stream_put32(&bs, frame->modtime);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
175 byte_stream_put32(&bs, frame->checksum);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
176 byte_stream_put32(&bs, frame->rfrcsum);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
177 byte_stream_put32(&bs, frame->rfsize);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
178 byte_stream_put32(&bs, frame->cretime);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
179 byte_stream_put32(&bs, frame->rfcsum);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
180 byte_stream_put32(&bs, frame->nrecvd);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
181 byte_stream_put32(&bs, frame->recvcsum);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
182 byte_stream_putraw(&bs, frame->idstring, 32);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
183 byte_stream_put8(&bs, frame->flags);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
184 byte_stream_put8(&bs, frame->lnameoffset);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
185 byte_stream_put8(&bs, frame->lsizeoffset);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
186 byte_stream_putraw(&bs, frame->dummy, 69);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
187 byte_stream_putraw(&bs, frame->macfileinfo, 16);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
188 byte_stream_put16(&bs, frame->nencode);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
189 byte_stream_put16(&bs, frame->nlanguage);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
190 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
191 * The name can be more than 64 characters, but if it is less than
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
192 * 64 characters it is padded with NULLs.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
193 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
194 byte_stream_putraw(&bs, frame->name, MAX(64, frame->name_length + 1));
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
195
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
196 peer_connection_send(conn, &bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
197
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
198 free(bs.data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
199 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
200
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
201 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
202 peer_oft_send_prompt(PeerConnection *conn)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
203 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
204 conn->xferdata.type = PEER_TYPE_PROMPT;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
205 peer_oft_send(conn, &conn->xferdata);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
206 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
207
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
208 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
209 peer_oft_send_ack(PeerConnection *conn)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
210 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
211 conn->xferdata.type = PEER_TYPE_ACK;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
212
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
213 /* Fill in the cookie */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
214 memcpy(conn->xferdata.cookie, conn->cookie, 8);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
215
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
216 peer_oft_send(conn, &conn->xferdata);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
217 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
218
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
219 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
220 peer_oft_send_done(PeerConnection *conn)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
221 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
222 conn->xferdata.type = PEER_TYPE_DONE;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
223 conn->xferdata.filesleft = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
224 conn->xferdata.partsleft = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
225 conn->xferdata.nrecvd = gaim_xfer_get_bytes_sent(conn->xfer);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
226 peer_oft_send(conn, &conn->xferdata);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
227 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
228
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
229 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
230 * This function exists so that we don't remove the outgoing
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
231 * data watcher while we're still sending data. In most cases
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
232 * any data we're sending will be instantly wisked away to a TCP
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
233 * buffer maintained by our operating system... but we want to
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
234 * make sure the core doesn't start sending file data while
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
235 * we're still sending OFT frame data. That would be bad.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
236 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
237 static gboolean
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
238 start_transfer_when_done_sending_data(gpointer data)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
239 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
240 PeerConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
241
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
242 conn = data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
243
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
244 if (gaim_circ_buffer_get_max_read(conn->buffer_outgoing) == 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
245 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
246 conn->sending_data_timer = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
247 conn->xfer->fd = conn->fd;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
248 conn->fd = -1;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
249 gaim_xfer_start(conn->xfer, conn->xfer->fd, NULL, 0);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
250 return FALSE;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
251 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
252
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
253 return TRUE;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
254 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
255
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
256 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
257 * This function is similar to the above function, except instead
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
258 * of starting the xfer it will destroy the connection. This is
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
259 * used when you want to send one final message across the peer
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
260 * connection, and then close everything.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
261 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
262 static gboolean
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
263 destroy_connection_when_done_sending_data(gpointer data)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
264 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
265 PeerConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
266
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
267 conn = data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
268
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
269 if (gaim_circ_buffer_get_max_read(conn->buffer_outgoing) == 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
270 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
271 conn->sending_data_timer = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
272 peer_connection_destroy(conn, conn->disconnect_reason);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
273 return FALSE;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
274 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
275
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
276 return TRUE;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
277 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
278
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
279 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
280 * This is called when a buddy sends us some file info. This happens when they
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
281 * are sending a file to you, and you have just established a connection to them.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
282 * You should send them the exact same info except use the real cookie. We also
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
283 * get like totally ready to like, receive the file, kay?
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
284 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
285 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
286 peer_oft_recv_frame_prompt(PeerConnection *conn, OftFrame *frame)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
287 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
288 /* Record the file information and send an ack */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
289 memcpy(&conn->xferdata, frame, sizeof(OftFrame));
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
290 peer_oft_send_ack(conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
291
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
292 /* Remove our watchers and use the file transfer watchers in the core */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
293 gaim_input_remove(conn->watcher_incoming);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
294 conn->watcher_incoming = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
295 conn->sending_data_timer = gaim_timeout_add(100,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
296 start_transfer_when_done_sending_data, conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
297 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
298
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
299 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
300 * We are sending a file to someone else. They have just acknowledged our
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
301 * prompt, so we want to start sending data like there's no tomorrow.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
302 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
303 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
304 peer_oft_recv_frame_ack(PeerConnection *conn, OftFrame *frame)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
305 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
306 if (memcmp(conn->cookie, frame->cookie, 8))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
307 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
308 gaim_debug_info("oscar", "Received an incorrect cookie. "
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
309 "Closing connection.\n");
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13607
diff changeset
310 peer_connection_destroy(conn, OSCAR_DISCONNECT_INVALID_DATA);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
311 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
312 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
313
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
314 /* Remove our watchers and use the file transfer watchers in the core */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
315 gaim_input_remove(conn->watcher_incoming);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
316 conn->watcher_incoming = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
317 conn->sending_data_timer = gaim_timeout_add(100,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
318 start_transfer_when_done_sending_data, conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
319 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
320
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
321 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
322 * We just sent a file to someone. They said they got it and everything,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
323 * so we can close our direct connection and what not.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
324 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
325 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
326 peer_oft_recv_frame_done(PeerConnection *conn, OftFrame *frame)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
327 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
328 if (frame->nrecvd == frame->size)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
329 gaim_xfer_set_completed(conn->xfer, TRUE);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
330
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
331 gaim_input_remove(conn->watcher_incoming);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
332 conn->watcher_incoming = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
333 conn->xfer->fd = conn->fd;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
334 conn->fd = -1;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
335 gaim_xfer_end(conn->xfer);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
336 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
337
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
338 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
339 * Handle an incoming OftFrame. If there is a payload associated
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
340 * with this frame, then we remove the old watcher and add the
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
341 * OFT watcher to read in the payload.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
342 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
343 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
344 peer_oft_recv_frame(PeerConnection *conn, ByteStream *bs)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
345 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
346 OftFrame frame;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
347
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
348 frame.type = byte_stream_get16(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
349 byte_stream_getrawbuf(bs, frame.cookie, 8);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
350 frame.encrypt = byte_stream_get16(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
351 frame.compress = byte_stream_get16(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
352 frame.totfiles = byte_stream_get16(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
353 frame.filesleft = byte_stream_get16(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
354 frame.totparts = byte_stream_get16(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
355 frame.partsleft = byte_stream_get16(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
356 frame.totsize = byte_stream_get32(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
357 frame.size = byte_stream_get32(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
358 frame.modtime = byte_stream_get32(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
359 frame.checksum = byte_stream_get32(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
360 frame.rfrcsum = byte_stream_get32(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
361 frame.rfsize = byte_stream_get32(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
362 frame.cretime = byte_stream_get32(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
363 frame.rfcsum = byte_stream_get32(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
364 frame.nrecvd = byte_stream_get32(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
365 frame.recvcsum = byte_stream_get32(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
366 byte_stream_getrawbuf(bs, frame.idstring, 32);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
367 frame.flags = byte_stream_get8(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
368 frame.lnameoffset = byte_stream_get8(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
369 frame.lsizeoffset = byte_stream_get8(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
370 byte_stream_getrawbuf(bs, frame.dummy, 69);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
371 byte_stream_getrawbuf(bs, frame.macfileinfo, 16);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
372 frame.nencode = byte_stream_get16(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
373 frame.nlanguage = byte_stream_get16(bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
374 frame.name_length = bs->len - 186;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
375 frame.name = byte_stream_getraw(bs, frame.name_length);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
376
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
377 gaim_debug_info("oscar", "Incoming OFT frame from %s with "
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
378 "type=0x%04x\n", conn->sn, frame.type);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
379
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
380 /* TODOFT: peer_oft_dirconvert_fromstupid(frame->name); */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
381
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
382 if (frame.type == PEER_TYPE_PROMPT)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
383 peer_oft_recv_frame_prompt(conn, &frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
384 else if (frame.type == PEER_TYPE_ACK)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
385 peer_oft_recv_frame_ack(conn, &frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
386 else if (frame.type == PEER_TYPE_DONE)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
387 peer_oft_recv_frame_done(conn, &frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
388
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
389 free(frame.name);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
390 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
391
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
392 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
393 /* Begin GaimXfer callbacks for use when receiving a file */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
394 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
395
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
396 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
397 peer_oft_recvcb_init(GaimXfer *xfer)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
398 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
399 PeerConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
400
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
401 conn = xfer->data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
402 conn->flags |= PEER_CONNECTION_FLAG_APPROVED;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
403 peer_connection_trynext(conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
404 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
405
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
406 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
407 peer_oft_recvcb_end(GaimXfer *xfer)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
408 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
409 PeerConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
410
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
411 conn = xfer->data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
412
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
413 /* Tell the other person that we've received everything */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
414 conn->fd = conn->xfer->fd;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
415 conn->xfer->fd = -1;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
416 peer_oft_send_done(conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
417
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13607
diff changeset
418 conn->disconnect_reason = OSCAR_DISCONNECT_DONE;
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
419 conn->sending_data_timer = gaim_timeout_add(100,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
420 destroy_connection_when_done_sending_data, conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
421 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
422
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
423 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
424 peer_oft_recvcb_ack_recv(GaimXfer *xfer, const guchar *buffer, size_t size)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
425 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
426 PeerConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
427
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
428 /* Update our rolling checksum. Like Walmart, yo. */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
429 conn = xfer->data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
430 conn->xferdata.recvcsum = peer_oft_checksum_chunk(buffer,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
431 size, conn->xferdata.recvcsum);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
432 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
433
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
434 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
435 /* End GaimXfer callbacks for use when receiving a file */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
436 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
437
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
438 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
439 /* Begin GaimXfer callbacks for use when sending a file */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
440 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
441
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
442 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
443 peer_oft_sendcb_init(GaimXfer *xfer)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
444 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
445 PeerConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
446
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
447 conn = xfer->data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
448 conn->flags |= PEER_CONNECTION_FLAG_APPROVED;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
449
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
450 /* Keep track of file transfer info */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
451 conn->xferdata.totfiles = 1;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
452 conn->xferdata.filesleft = 1;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
453 conn->xferdata.totparts = 1;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
454 conn->xferdata.partsleft = 1;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
455 conn->xferdata.totsize = gaim_xfer_get_size(xfer);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
456 conn->xferdata.size = gaim_xfer_get_size(xfer);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
457 conn->xferdata.checksum = 0xffff0000;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
458 conn->xferdata.rfrcsum = 0xffff0000;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
459 conn->xferdata.rfcsum = 0xffff0000;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
460 conn->xferdata.recvcsum = 0xffff0000;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
461 strncpy((gchar *)conn->xferdata.idstring, "OFT_Windows ICBMFT V1.1 32", 31);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
462 conn->xferdata.modtime = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
463 conn->xferdata.cretime = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
464 xfer->filename = g_path_get_basename(xfer->local_filename);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
465 conn->xferdata.name = (guchar *)g_strdup(xfer->filename);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
466 conn->xferdata.name_length = strlen(xfer->filename);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
467
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
468 /* Calculating the checksum can take a very long time for large files */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
469 gaim_debug_info("oscar","calculating file checksum\n");
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
470 conn->xferdata.checksum = peer_oft_checksum_file(xfer->local_filename);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
471 gaim_debug_info("oscar","checksum calculated\n");
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
472
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
473 /* Start the connection process */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
474 peer_connection_trynext(conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
475 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
476
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
477 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
478 * AIM file transfers aren't really meant to be thought
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
479 * of as a transferring just a single file. The rendezvous
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
480 * establishes a connection between two computers, and then
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
481 * those computers can use the same connection for transferring
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
482 * multiple files. So we don't want the Gaim core up and closing
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
483 * the socket all willy-nilly. We want to do that in the oscar
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
484 * prpl, whenever one side or the other says they're finished
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
485 * using the connection. There might be a better way to intercept
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
486 * the socket from the core...
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
487 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
488 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
489 peer_oft_sendcb_ack(GaimXfer *xfer, const guchar *buffer, size_t size)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
490 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
491 PeerConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
492
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
493 conn = xfer->data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
494
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
495 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
496 * If we're done sending, intercept the socket from the core ft code
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
497 * and wait for the other guy to send the "done" OFT packet.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
498 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
499 if (gaim_xfer_get_bytes_remaining(xfer) <= 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
500 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
501 gaim_input_remove(xfer->watcher);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
502 conn->fd = xfer->fd;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
503 xfer->fd = -1;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
504 conn->watcher_incoming = gaim_input_add(conn->fd,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
505 GAIM_INPUT_READ, peer_connection_recv_cb, conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
506 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
507 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
508
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
509 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
510 /* End GaimXfer callbacks for use when sending a file */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
511 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
512
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
513 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
514 /* Begin GaimXfer callbacks for use when sending and receiving */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
515 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
516
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
517 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
518 peer_oft_cb_generic_cancel(GaimXfer *xfer)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
519 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
520 PeerConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
521
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
522 conn = xfer->data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
523
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
524 if (conn == NULL)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
525 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
526
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13607
diff changeset
527 peer_connection_destroy(conn, OSCAR_DISCONNECT_LOCAL_CLOSED);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
528 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
529
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
530 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
531 /* End GaimXfer callbacks for use when sending and receiving */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
532 /*******************************************************************/
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
533
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
534 #if 0
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
535 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
536 * This little area in oscar.c is the nexus of file transfer code,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
537 * so I wrote a little explanation of what happens. I am such a
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
538 * ninja.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
539 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
540 * The series of events for a file send is:
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
541 * -Create xfer and call gaim_xfer_request (this happens in oscar_ask_sendfile)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
542 * -User chooses a file and oscar_xfer_init is called. It establishes a
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
543 * listening socket, then asks the remote user to connect to us (and
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
544 * gives them the file name, port, IP, etc.)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
545 * -They connect to us and we send them an PEER_TYPE_PROMPT (this happens
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
546 * in peer_oft_recv_frame_established)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
547 * -They send us an PEER_TYPE_ACK and then we start sending data
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
548 * -When we finish, they send us an PEER_TYPE_DONE and they close the
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
549 * connection.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
550 * -We get drunk because file transfer kicks ass.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
551 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
552 * The series of events for a file receive is:
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
553 * -Create xfer and call gaim_xfer request (this happens in incomingim_chan2)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
554 * -Gaim user selects file to name and location to save file to and
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
555 * oscar_xfer_init is called
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
556 * -It connects to the remote user using the IP they gave us earlier
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
557 * -After connecting, they send us an PEER_TYPE_PROMPT. In reply, we send
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
558 * them an PEER_TYPE_ACK.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
559 * -They begin to send us lots of raw data.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
560 * -When they finish sending data we send an PEER_TYPE_DONE and then close
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
561 * the connection.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
562 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
563 * Update August 2005:
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
564 * The series of events for transfers has been seriously complicated by the addition
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
565 * of transfer redirects and proxied connections. I could throw a whole lot of words
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
566 * at trying to explain things here, but it probably wouldn't do much good. To get
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
567 * a better idea of what happens, take a look at the diagrams and documentation
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
568 * from my Summer of Code project. -- Jonathan Clark
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
569 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
570
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
571 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
572 * Convert the directory separator from / (0x2f) to ^A (0x01)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
573 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
574 * @param name The filename to convert.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
575 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
576 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
577 peer_oft_dirconvert_tostupid(char *name)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
578 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
579 while (name[0]) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
580 if (name[0] == 0x01)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
581 name[0] = G_DIR_SEPARATOR;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
582 name++;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
583 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
584 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
585
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
586 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
587 * Convert the directory separator from ^A (0x01) to / (0x2f)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
588 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
589 * @param name The filename to convert.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
590 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
591 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
592 peer_oft_dirconvert_fromstupid(char *name)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
593 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
594 while (name[0]) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
595 if (name[0] == G_DIR_SEPARATOR)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
596 name[0] = 0x01;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
597 name++;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
598 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
599 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
600 #endif