annotate src/protocols/oscar/ft.c @ 12756:6ef1cdc26b40

[gaim-migrate @ 15103] Cleanup to STUN code. Fixed endianness. Fixed to work where sizeof(short) != 2 or sizeof(int) != 4. Close the socket when we're done with it. Instead of using a bunch of static variables, pass data around the various callbacks. Don't invoke the specified StunCallback before the initial function has returned. Deal with requerying if the STUN server has changed since last query, or the last query was unsuccessful and 5 minutes have elapsed. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sat, 07 Jan 2006 22:10:18 +0000
parents 2cf6d4cf2cb0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /*
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
2 * Oscar File transfer (OFT) and Oscar Direct Connect (ODC).
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
3 * (ODC is also referred to as DirectIM and IM Image.)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
4 *
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
5 * There are a few static helper functions at the top, then
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
6 * ODC stuff, then ft stuff.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
7 *
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
8 * I feel like this is a good place to explain OFT, so I'm going to
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
9 * do just that. Each OFT packet has a header type. I guess this
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
10 * is pretty similar to the subtype of a SNAC packet. The type
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
11 * basically tells the other client the meaning of the OFT packet.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
12 * There are two distinct types of file transfer, which I usually
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
13 * call "sendfile" and "getfile." Sendfile is when you send a file
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
14 * to another AIM user. Getfile is when you share a group of files,
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
15 * and other users request that you send them the files.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
16 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
17 * A typical sendfile file transfer goes like this:
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
18 * 1) Sender sends a channel 2 ICBM telling the other user that
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
19 * we want to send them a file. At the same time, we open a
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
20 * listener socket (this should be done before sending the
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
21 * ICBM) on some port, and wait for them to connect to us.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
22 * The ICBM we sent should contain our IP address and the port
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
23 * number that we're listening on.
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
24 * 2) The receiver connects to the sender on the given IP address
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
25 * and port. After the connection is established, the receiver
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
26 * sends an ICBM signifying that we are ready and waiting.
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
27 * 3) The sender sends an OFT PROMPT message over the OFT
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
28 * connection.
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
29 * 4) The receiver of the file sends back an exact copy of this
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
30 * OFT packet, except the cookie is filled in with the cookie
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
31 * from the ICBM. I think this might be an attempt to verify
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
32 * that the user that is connected is actually the guy that
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
33 * we sent the ICBM to. Oh, I've been calling this the ACK.
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
34 * 5) The sender starts sending raw data across the connection
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
35 * until the entire file has been sent.
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
36 * 6) The receiver knows the file is finished because the sender
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
37 * sent the file size in an earlier OFT packet. So then the
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
38 * receiver sends the DONE thingy (after filling in the
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
39 * "received" checksum and size) and closes the connection.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 #define FAIM_INTERNAL
5415
2141e33513ef [gaim-migrate @ 5791]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
43 #ifdef HAVE_CONFIG_H
2141e33513ef [gaim-migrate @ 5791]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
44 #include <config.h>
2141e33513ef [gaim-migrate @ 5791]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
45 #endif
2141e33513ef [gaim-migrate @ 5791]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
46
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 #include <aim.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 #ifndef _WIN32
5927
04dc7fe68889 [gaim-migrate @ 6367]
Mark Doliner <mark@kingant.net>
parents: 5415
diff changeset
50 #include <stdio.h>
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 #include <netdb.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 #include <sys/socket.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 #include <netinet/in.h>
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
54 #include <sys/utsname.h> /* for aim_odc_initiate */
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
55 #include <arpa/inet.h> /* for inet_ntoa */
8080
4720864c365d [gaim-migrate @ 8779]
Ethan Blanton <elb@pidgin.im>
parents: 8078
diff changeset
56 #include <limits.h> /* for UINT_MAX */
3960
7ba5f2e13ee8 [gaim-migrate @ 4142]
Mark Doliner <mark@kingant.net>
parents: 3953
diff changeset
57 #define G_DIR_SEPARATOR '/'
3646
bfd8df165f32 [gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
58 #endif
bfd8df165f32 [gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
59
bfd8df165f32 [gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
60 #ifdef _WIN32
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
61 #include "win32dep.h"
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
62 #endif
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63
9430
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
64 /*
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
65 * I really want to switch all our networking code to using IPv6 only,
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
66 * but that really isn't a good idea at all. Evan S. of Adium says
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
67 * OS X sets all connections as "AF_INET6/PF_INET6," even if there is
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
68 * nothing inherently IPv6 about them. And I feel like Linux kernel
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
69 * 2.6.5 is doing the same thing. So we REALLY should accept
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
70 * connections if they're showing up as IPv6. Old OSes (Solaris?)
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
71 * that might not have full IPv6 support yet will fail if we try
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
72 * to use PF_INET6 but it isn't defined. --Mark Doliner
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
73 */
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
74 #ifndef PF_INET6
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
75 #define PF_INET6 PF_INET
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
76 #endif
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
77
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
78 struct aim_odc_intdata {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
79 fu8_t cookie[8];
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
80 char sn[MAXSNLEN+1];
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
81 char ip[22];
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
82 };
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
83
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
84 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
85 * Convert the directory separator from / (0x2f) to ^A (0x01)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
86 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
87 * @param name The filename to convert.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
88 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
89 static void aim_oft_dirconvert_tostupid(char *name)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
90 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
91 while (name[0]) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
92 if (name[0] == 0x01)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
93 name[0] = G_DIR_SEPARATOR;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
94 name++;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
95 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
96 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
97
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
98 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
99 * Convert the directory separator from ^A (0x01) to / (0x2f)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
100 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
101 * @param name The filename to convert.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
102 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
103 static void aim_oft_dirconvert_fromstupid(char *name)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
104 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
105 while (name[0]) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
106 if (name[0] == G_DIR_SEPARATOR)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
107 name[0] = 0x01;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
108 name++;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
109 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
110 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
111
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
112 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
113 * Calculate oft checksum of buffer
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
114 *
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
115 * Prevcheck should be 0xFFFF0000 when starting a checksum of a file. The
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
116 * checksum is kind of a rolling checksum thing, so each time you get bytes
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
117 * of a file you just call this puppy and it updates the checksum. You can
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
118 * calculate the checksum of an entire file by calling this in a while or a
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
119 * for loop, or something.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
120 *
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
121 * Thanks to Graham Booker for providing this improved checksum routine,
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
122 * which is simpler and should be more accurate than Josh Myer's original
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
123 * code. -- wtm
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
124 *
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
125 * This algorithm works every time I have tried it. The other fails
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
126 * sometimes. So, AOL who thought this up? It has got to be the weirdest
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
127 * checksum I have ever seen.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
128 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
129 * @param buffer Buffer of data to checksum. Man I'd like to buff her...
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
130 * @param bufsize Size of buffer.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
131 * @param prevcheck Previous checksum.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
132 */
4763
c050edba7b83 [gaim-migrate @ 5081]
Mark Doliner <mark@kingant.net>
parents: 4650
diff changeset
133 faim_export fu32_t aim_oft_checksum_chunk(const fu8_t *buffer, int bufferlen, fu32_t prevcheck)
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
134 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
135 fu32_t check = (prevcheck >> 16) & 0xffff, oldcheck;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
136 int i;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
137 unsigned short val;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
138
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
139 for (i=0; i<bufferlen; i++) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
140 oldcheck = check;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
141 if (i&1)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
142 val = buffer[i];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
143 else
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
144 val = buffer[i] << 8;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
145 check -= val;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
146 /*
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
147 * The following appears to be necessary.... It happens
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
148 * every once in a while and the checksum doesn't fail.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
149 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
150 if (check > oldcheck)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
151 check--;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
152 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
153 check = ((check & 0x0000ffff) + (check >> 16));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
154 check = ((check & 0x0000ffff) + (check >> 16));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
155 return check << 16;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
156 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
157
4650
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
158 faim_export fu32_t aim_oft_checksum_file(char *filename) {
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
159 FILE *fd;
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
160 fu32_t checksum = 0xffff0000;
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
161
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
162 if ((fd = fopen(filename, "rb"))) {
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
163 int bytes;
4763
c050edba7b83 [gaim-migrate @ 5081]
Mark Doliner <mark@kingant.net>
parents: 4650
diff changeset
164 fu8_t buffer[1024];
4650
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
165
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
166 while ((bytes = fread(buffer, 1, 1024, fd)))
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
167 checksum = aim_oft_checksum_chunk(buffer, bytes, checksum);
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
168 fclose(fd);
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
169 }
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
170
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
171 return checksum;
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
172 }
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
173
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
175 * After establishing a listening socket, this is called to accept a connection. It
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
176 * clones the conn used by the listener, and passes both of these to a signal handler.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
177 * The signal handler should close the listener conn and keep track of the new conn,
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
178 * since this is what is used for file transfers and what not.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
179 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
180 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
181 * @param cur The conn the incoming connection is on.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
182 * @return Return 0 if no errors, otherwise return the error number.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
184 faim_export int aim_handlerendconnect(aim_session_t *sess, aim_conn_t *cur)
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
185 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
186 int acceptfd = 0;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
187 struct sockaddr addr;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
188 socklen_t addrlen = sizeof(addr);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
189 int ret = 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
190 aim_conn_t *newconn;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
191 char ip[20];
8880
ec3e041dc3bd [gaim-migrate @ 9649]
Mark Doliner <mark@kingant.net>
parents: 8735
diff changeset
192 unsigned short port;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
194 if ((acceptfd = accept(cur->fd, &addr, &addrlen)) == -1)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
195 return 0; /* not an error */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196
9430
30a812571a6b [gaim-migrate @ 10250]
Mark Doliner <mark@kingant.net>
parents: 9070
diff changeset
197 if ((addr.sa_family != PF_INET) && (addr.sa_family != PF_INET6)) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
198 close(acceptfd);
10271
361c9170d8af [gaim-migrate @ 11420]
Mark Doliner <mark@kingant.net>
parents: 10267
diff changeset
199 aim_conn_close(cur);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
200 return -1;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
201 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
202
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
203 strncpy(ip, inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr), sizeof(ip));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
204 port = ntohs(((struct sockaddr_in *)&addr)->sin_port);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
206 if (!(newconn = aim_cloneconn(sess, cur))) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
207 close(acceptfd);
10271
361c9170d8af [gaim-migrate @ 11420]
Mark Doliner <mark@kingant.net>
parents: 10267
diff changeset
208 aim_conn_close(cur);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
209 return -ENOMEM;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
210 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
212 newconn->type = AIM_CONN_TYPE_RENDEZVOUS;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
213 newconn->fd = acceptfd;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
215 if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
216 aim_rxcallback_t userfunc;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
217 struct aim_odc_intdata *priv;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
219 priv = (struct aim_odc_intdata *)(newconn->internal = cur->internal);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
220 cur->internal = NULL;
8446
d9cf0c2f4339 [gaim-migrate @ 9176]
Mark Doliner <mark@kingant.net>
parents: 8426
diff changeset
221 snprintf(priv->ip, sizeof(priv->ip), "%s:%hu", ip, port);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
223 if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIM_ESTABLISHED)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
224 ret = userfunc(sess, NULL, newconn, cur);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
225
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
226 } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
227 } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
228 aim_rxcallback_t userfunc;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
229
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
230 if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_ESTABLISHED)))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
231 ret = userfunc(sess, NULL, newconn, cur);
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
232
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
233 } else {
11253
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11214
diff changeset
234 gaim_debug_warning("oscar", "Got a connection on a listener that's not rendezvous. Closing connection.\n");
10271
361c9170d8af [gaim-migrate @ 11420]
Mark Doliner <mark@kingant.net>
parents: 10267
diff changeset
235 aim_conn_close(newconn);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
236 ret = -1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
237 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
239 return ret;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
241
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
243 * Send client-to-client typing notification over an established direct connection.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
245 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
246 * @param conn The already-connected ODC connection.
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
247 * @param typing If 0x0002, sends a "typing" message, 0x0001 sends "typed," and
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
248 * 0x0000 sends "stopped."
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
249 * @return Return 0 if no errors, otherwise return the error number.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
250 */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
251 faim_export int aim_odc_send_typing(aim_session_t *sess, aim_conn_t *conn, int typing)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
252 {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
253 struct aim_odc_intdata *intdata = (struct aim_odc_intdata *)conn->internal;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
254 aim_frame_t *fr;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
255 aim_bstream_t *hdrbs;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
256 fu8_t *hdr;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
257 int hdrlen = 0x44;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
259 if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS))
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
260 return -EINVAL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
261
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
262 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0001, 0)))
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
263 return -ENOMEM;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
264 memcpy(fr->hdr.rend.magic, "ODC2", 4);
8934
535449a13b07 [gaim-migrate @ 9704]
Mark Doliner <mark@kingant.net>
parents: 8880
diff changeset
265 fr->hdr.rend.hdrlen = hdrlen + 8;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
266
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
267 if (!(hdr = calloc(1, hdrlen))) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
268 aim_frame_destroy(fr);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
269 return -ENOMEM;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
270 }
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
271
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
272 hdrbs = &(fr->data);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
273 aim_bstream_init(hdrbs, hdr, hdrlen);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
274
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
275 aimbs_put16(hdrbs, 0x0006);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
276 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
277 aimbs_putraw(hdrbs, intdata->cookie, 8);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
278 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
279 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
280 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
281 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
282 aimbs_put32(hdrbs, 0x00000000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
283 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
284 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
285 aimbs_put16(hdrbs, 0x0000);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
286
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
287 if (typing == 0x0002)
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
288 aimbs_put16(hdrbs, 0x0002 | 0x0008);
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
289 else if (typing == 0x0001)
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
290 aimbs_put16(hdrbs, 0x0002 | 0x0004);
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
291 else
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
292 aimbs_put16(hdrbs, 0x0002);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
293
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
294 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
295 aimbs_put16(hdrbs, 0x0000);
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10560
diff changeset
296 aimbs_putstr(hdrbs, sess->sn);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
297
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
298 aim_bstream_setpos(hdrbs, 52); /* bleeehh */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
299
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
300 aimbs_put8(hdrbs, 0x00);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
301 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
302 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
303 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
304 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
305 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
306 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
307 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
308 aimbs_put8(hdrbs, 0x00);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
309
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
310 /* end of hdr */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
312 aim_tx_enqueue(sess, fr);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
313
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
314 return 0;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
315 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
317 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
318 * Send client-to-client IM over an established direct connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
319 * Call this just like you would aim_send_im, to send a directim.
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
320 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
321 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
322 * @param conn The already-connected ODC connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
323 * @param msg Null-terminated string to send.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
324 * @param len The length of the message to send, including binary data.
9826
6f2a90c36ee2 [gaim-migrate @ 10697]
Mark Doliner <mark@kingant.net>
parents: 9430
diff changeset
325 * @param encoding See the AIM_CHARSET_* defines in aim.h
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
326 * @param isawaymsg 0 if this is not an auto-response, 1 if it is.
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
327 * @return Return 0 if no errors, otherwise return the error number.
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
328 */
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
329 faim_export int aim_odc_send_im(aim_session_t *sess, aim_conn_t *conn, const char *msg, int len, int encoding, int isawaymsg)
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
330 {
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
331 aim_frame_t *fr;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
332 aim_bstream_t *hdrbs;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
333 struct aim_odc_intdata *intdata = (struct aim_odc_intdata *)conn->internal;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
334 int hdrlen = 0x44;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
335 fu8_t *hdr;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
336
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
337 if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !msg)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
338 return -EINVAL;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
339
4875
26837f462a66 [gaim-migrate @ 5205]
Mark Doliner <mark@kingant.net>
parents: 4870
diff changeset
340 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, 0)))
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
341 return -ENOMEM;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
342
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
343 memcpy(fr->hdr.rend.magic, "ODC2", 4);
8934
535449a13b07 [gaim-migrate @ 9704]
Mark Doliner <mark@kingant.net>
parents: 8880
diff changeset
344 fr->hdr.rend.hdrlen = hdrlen + 8;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
345
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
346 if (!(hdr = calloc(1, hdrlen + len))) {
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
347 aim_frame_destroy(fr);
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
348 return -ENOMEM;
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
349 }
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
350
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
351 hdrbs = &(fr->data);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
352 aim_bstream_init(hdrbs, hdr, hdrlen + len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
353
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
354 aimbs_put16(hdrbs, 0x0006);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
355 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
356 aimbs_putraw(hdrbs, intdata->cookie, 8);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
357 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
358 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
359 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
360 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
361 aimbs_put32(hdrbs, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
362 aimbs_put16(hdrbs, encoding);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
363 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
364 aimbs_put16(hdrbs, 0x0000);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
365
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
366 /* flags - used for typing notification and to mark if this is an away message */
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
367 aimbs_put16(hdrbs, 0x0000 | isawaymsg);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
368
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
369 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
370 aimbs_put16(hdrbs, 0x0000);
10990
8d74ae785a46 [gaim-migrate @ 12828]
Mark Doliner <mark@kingant.net>
parents: 10560
diff changeset
371 aimbs_putstr(hdrbs, sess->sn);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
372
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
373 aim_bstream_setpos(hdrbs, 52); /* bleeehh */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
374
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
375 aimbs_put8(hdrbs, 0x00);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
376 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
377 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
378 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
379 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
380 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
381 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
382 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
383 aimbs_put8(hdrbs, 0x00);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
384
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
385 /* end of hdr2 */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
386
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
387 #if 0 /* XXX - this is how you send buddy icon info... */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
388 aimbs_put16(hdrbs, 0x0008);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
389 aimbs_put16(hdrbs, 0x000c);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
390 aimbs_put16(hdrbs, 0x0000);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
391 aimbs_put16(hdrbs, 0x1466);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
392 aimbs_put16(hdrbs, 0x0001);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
393 aimbs_put16(hdrbs, 0x2e0f);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
394 aimbs_put16(hdrbs, 0x393e);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
395 aimbs_put16(hdrbs, 0xcac8);
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
396 #endif
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 11126
diff changeset
397 aimbs_putraw(hdrbs, (guchar *)msg, len);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
398
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
399 aim_tx_enqueue(sess, fr);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
400
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
401 return 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
402 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
403
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
404 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
405 * Get the screen name of the peer of a direct connection.
8983
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
406 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
407 * @param conn The ODC connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
408 * @return The screen name of the dude, or NULL if there was an anomaly.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
409 */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
410 faim_export const char *aim_odc_getsn(aim_conn_t *conn)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
411 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
412 struct aim_odc_intdata *intdata;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
413
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
414 if (!conn || !conn->internal)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
415 return NULL;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
416
8983
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
417 if ((conn->type != AIM_CONN_TYPE_RENDEZVOUS) ||
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
418 (conn->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM))
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
419 return NULL;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
420
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
421 intdata = (struct aim_odc_intdata *)conn->internal;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
422
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
423 return intdata->sn;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
424 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
425
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
426 /**
8983
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
427 * Get the cookie of a direct connection.
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
428 *
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
429 * @param conn The ODC connection.
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
430 * @return The cookie, an 8 byte unterminated string, or NULL if there was an anomaly.
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
431 */
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 11126
diff changeset
432 faim_export const guchar *aim_odc_getcookie(aim_conn_t *conn)
8983
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
433 {
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
434 struct aim_odc_intdata *intdata;
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
435
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
436 if (!conn || !conn->internal)
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
437 return NULL;
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
438
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
439 intdata = (struct aim_odc_intdata *)conn->internal;
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
440
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
441 return intdata->cookie;
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
442 }
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
443
460d02fe03df [gaim-migrate @ 9758]
Tim Ringenbach <marv@pidgin.im>
parents: 8982
diff changeset
444 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
445 * Find the conn of a direct connection with the given buddy.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
446 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
447 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
448 * @param sn The screen name of the buddy whose direct connection you want to find.
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
449 * @return The conn for the direct connection with the given buddy, or NULL if no
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
450 * connection was found.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
451 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
452 faim_export aim_conn_t *aim_odc_getconn(aim_session_t *sess, const char *sn)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
453 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
454 aim_conn_t *cur;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
455 struct aim_odc_intdata *intdata;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
456
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
457 if (!sess || !sn || !strlen(sn))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
458 return NULL;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
459
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
460 for (cur = sess->connlist; cur; cur = cur->next) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
461 if ((cur->type == AIM_CONN_TYPE_RENDEZVOUS) && (cur->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM)) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
462 intdata = cur->internal;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
463 if (!aim_sncmp(intdata->sn, sn))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
464 return cur;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
465 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
466 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
467
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
468 return NULL;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
469 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
470
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
471 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
472 * For those times when we want to open up the direct connection channel ourselves.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
473 *
8982
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
474 * You'll want to set up some kind of watcher on this socket.
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
475 * When the state changes, call aim_handlerendconnection with
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
476 * the connection returned by this. aim_handlerendconnection
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
477 * will accept the pending connection and stop listening.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
478 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
479 * @param sess The session
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
480 * @param sn The screen name to connect to.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
481 * @return The new connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
482 */
8982
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
483 faim_export aim_conn_t *aim_odc_initiate(aim_session_t *sess, const char *sn, int listenfd,
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
484 const fu8_t *localip, fu16_t port, const fu8_t *mycookie)
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
485 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
486 aim_conn_t *newconn;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
487 aim_msgcookie_t *cookie;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
488 struct aim_odc_intdata *priv;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
489 fu8_t ck[8];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
490
8982
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
491 if (!localip)
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
492 return NULL;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
493
8982
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
494 if (mycookie) {
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
495 memcpy(ck, mycookie, 8);
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
496 aim_im_sendch2_odcrequest(sess, ck, TRUE, sn, localip, port);
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
497 } else
a4fd6666bb83 [gaim-migrate @ 9757]
Tim Ringenbach <marv@pidgin.im>
parents: 8934
diff changeset
498 aim_im_sendch2_odcrequest(sess, ck, FALSE, sn, localip, port);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
499
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
500 cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
501 memcpy(cookie->cookie, ck, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
502 cookie->type = AIM_COOKIETYPE_OFTIM;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
503
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
504 /* this one is for the cookie */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
505 priv = (struct aim_odc_intdata *)calloc(1, sizeof(struct aim_odc_intdata));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
506
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
507 memcpy(priv->cookie, ck, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
508 strncpy(priv->sn, sn, sizeof(priv->sn));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
509 cookie->data = priv;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
510 aim_cachecookie(sess, cookie);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
511
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
512 /* XXX - switch to aim_cloneconn()? */
11162
ccb38cf22483 [gaim-migrate @ 13263]
Mark Doliner <mark@kingant.net>
parents: 11159
diff changeset
513 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER))) {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
514 close(listenfd);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
515 return NULL;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
516 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
517
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
518 /* this one is for the conn */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
519 priv = (struct aim_odc_intdata *)calloc(1, sizeof(struct aim_odc_intdata));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
520
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
521 memcpy(priv->cookie, ck, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
522 strncpy(priv->sn, sn, sizeof(priv->sn));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
523
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
524 newconn->fd = listenfd;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
525 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
526 newconn->internal = priv;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
527 newconn->lastactivity = time(NULL);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
528
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
529 return newconn;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
530 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
531
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
532 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
533 * Connect directly to the given buddy for directim.
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
534 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
535 * This is a wrapper for aim_newconn.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
536 *
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
537 * If addr is NULL, the socket is not created, but the connection is
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
538 * allocated and setup to connect.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
539 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
540 * @param sess The Godly session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
541 * @param sn The screen name we're connecting to. I hope it's a girl...
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
542 * @param addr Address to connect to.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
543 * @return The new connection.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
544 */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
545 faim_export aim_conn_t *aim_odc_connect(aim_session_t *sess, const char *sn, const char *addr, const fu8_t *cookie)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
546 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
547 aim_conn_t *newconn;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
548 struct aim_odc_intdata *intdata;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
549
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
550 if (!sess || !sn)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
551 return NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
552
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
553 if (!(intdata = calloc(1, sizeof(struct aim_odc_intdata))))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
554 return NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
555 memcpy(intdata->cookie, cookie, 8);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
556 strncpy(intdata->sn, sn, sizeof(intdata->sn));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
557 if (addr)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
558 strncpy(intdata->ip, addr, sizeof(intdata->ip));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
559
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
560 /* XXX - verify that non-blocking connects actually work */
11162
ccb38cf22483 [gaim-migrate @ 13263]
Mark Doliner <mark@kingant.net>
parents: 11159
diff changeset
561 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS))) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
562 free(intdata);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
563 return NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
564 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
565
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
566 newconn->internal = intdata;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
567 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
568
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
569 return newconn;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
570 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
571
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
572 /**
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
573 * Sometimes you just don't know with these kinds of people.
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
574 *
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
575 * @param sess The session.
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
576 * @param conn The ODC connection of the incoming data.
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
577 * @param frr The frame allocated for the incoming data.
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
578 * @param bs It stands for "bologna sandwich."
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
579 * @return Return 0 if no errors, otherwise return the error number.
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
580 */
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
581 static int handlehdr_odc(aim_session_t *sess, aim_conn_t *conn, aim_frame_t *frr, aim_bstream_t *bs)
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
582 {
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
583 aim_frame_t fr;
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
584 int ret = 0;
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
585 aim_rxcallback_t userfunc;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
586 fu32_t payloadlength;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
587 fu16_t flags, encoding;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
588 char *snptr = NULL;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
589
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
590 fr.conn = conn;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
591
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
592 /* AAA - ugly */
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
593 aim_bstream_setpos(bs, 20);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
594 payloadlength = aimbs_get32(bs);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
595
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
596 aim_bstream_setpos(bs, 24);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
597 encoding = aimbs_get16(bs);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
598
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
599 aim_bstream_setpos(bs, 30);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
600 flags = aimbs_get16(bs);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
601
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
602 aim_bstream_setpos(bs, 36);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
603 /* XXX - create an aimbs_getnullstr function? */
4913
6c02ee2b471d [gaim-migrate @ 5247]
Mark Doliner <mark@kingant.net>
parents: 4895
diff changeset
604 snptr = aimbs_getstr(bs, 32); /* Next 32 bytes contain the sn, padded with null chars */
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
605
11253
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11214
diff changeset
606 gaim_debug_misc("oscar", "faim: OFT frame: handlehdr_odc: %04x / %04x / %s\n", payloadlength, flags, snptr);
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
607
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
608 if (flags & 0x0008) {
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
609 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)))
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
610 ret = userfunc(sess, &fr, snptr, 2);
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
611 } else if (flags & 0x0004) {
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
612 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)))
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
613 ret = userfunc(sess, &fr, snptr, 1);
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
614 } else {
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
615 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)))
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
616 ret = userfunc(sess, &fr, snptr, 0);
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
617 }
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
618
8000
3ca778499f19 [gaim-migrate @ 8677]
Sean Egan <seanegan@gmail.com>
parents: 7997
diff changeset
619 if ((payloadlength != 0) && (payloadlength != UINT_MAX)) {
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
620 char *msg;
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
621 int recvd = 0;
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
622 int i, isawaymsg;
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
623
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
624 isawaymsg = flags & 0x0001;
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
625
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
626 if (!(msg = calloc(1, payloadlength+1))) {
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
627 free(snptr);
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
628 return -ENOMEM;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
629 }
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
630
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
631 while (payloadlength - recvd) {
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
632 if (payloadlength - recvd >= 1024)
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
633 i = aim_recv(conn->fd, &msg[recvd], 1024);
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
634 else
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
635 i = aim_recv(conn->fd, &msg[recvd], payloadlength - recvd);
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
636 if (i <= 0) {
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
637 free(msg);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
638 free(snptr);
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
639 return -1;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
640 }
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
641 recvd = recvd + i;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
642 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_IMAGETRANSFER)))
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
643 ret = userfunc(sess, &fr, snptr, (double)recvd / payloadlength);
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
644 }
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
645
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
646 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)))
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
647 ret = userfunc(sess, &fr, snptr, msg, payloadlength, encoding, isawaymsg);
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
648
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
649 free(msg);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
650 }
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
651
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
652 free(snptr);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
653
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
654 return ret;
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
655 }
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
656
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
657 faim_export struct aim_oft_info *aim_oft_createinfo(aim_session_t *sess, const fu8_t *cookie, const char *sn, const char *ip, fu16_t port, fu32_t size, fu32_t modtime, char *filename, int send_or_recv, int method, int stage)
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
658 {
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
659 struct aim_oft_info *new;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
660
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
661 if (!sess)
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
662 return NULL;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
663
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
664 if (!(new = (struct aim_oft_info *)calloc(1, sizeof(struct aim_oft_info))))
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
665 return NULL;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
666
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
667 new->sess = sess;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
668 if (cookie)
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
669 memcpy(new->cookie, cookie, 8);
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
670 else
11401
69b0378c79e0 [gaim-migrate @ 13636]
Mark Doliner <mark@kingant.net>
parents: 11399
diff changeset
671 aim_icbm_makecookie(new->cookie);
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
672 if (ip)
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
673 new->clientip = strdup(ip);
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
674 else
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
675 new->clientip = NULL;
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
676 if (sn)
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
677 new->sn = strdup(sn);
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
678 else
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
679 new->sn = NULL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
680 new->method = method;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
681 new->send_or_recv = send_or_recv;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
682 new->stage = stage;
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
683 new->port = port;
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
684 new->xfer_reffed = FALSE;
11214
751de30689ef [gaim-migrate @ 13346]
Jonathan Clark <ardentlygnarly>
parents: 11162
diff changeset
685 new->success = FALSE;
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
686 new->fh.totfiles = 1;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
687 new->fh.filesleft = 1;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
688 new->fh.totparts = 1;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
689 new->fh.partsleft = 1;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
690 new->fh.totsize = size;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
691 new->fh.size = size;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
692 new->fh.modtime = modtime;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
693 new->fh.checksum = 0xffff0000;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
694 new->fh.rfrcsum = 0xffff0000;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
695 new->fh.rfcsum = 0xffff0000;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
696 new->fh.recvcsum = 0xffff0000;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
697 strncpy(new->fh.idstring, "OFT_Windows ICBMFT V1.1 32", 31);
8446
d9cf0c2f4339 [gaim-migrate @ 9176]
Mark Doliner <mark@kingant.net>
parents: 8426
diff changeset
698 if (filename) {
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
699 strncpy(new->fh.name, filename, 63);
8446
d9cf0c2f4339 [gaim-migrate @ 9176]
Mark Doliner <mark@kingant.net>
parents: 8426
diff changeset
700 new->fh.name[63] = '\0';
d9cf0c2f4339 [gaim-migrate @ 9176]
Mark Doliner <mark@kingant.net>
parents: 8426
diff changeset
701 }
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
702
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
703 new->next = sess->oft_info;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
704 sess->oft_info = new;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
705
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
706 return new;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
707 }
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
708
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
709 faim_export struct aim_rv_proxy_info *aim_rv_proxy_createinfo(aim_session_t *sess, const fu8_t *cookie,
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
710 fu16_t port)
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
711 {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
712 struct aim_rv_proxy_info *proxy_info;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
713
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
714 if (!(proxy_info = (struct aim_rv_proxy_info*)calloc(1, sizeof(struct aim_rv_proxy_info))))
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
715 return NULL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
716
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
717 proxy_info->sess = sess;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
718 proxy_info->port = port;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
719 proxy_info->packet_ver = AIM_RV_PROXY_PACKETVER_DFLT;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
720 proxy_info->unknownA = AIM_RV_PROXY_UNKNOWNA_DFLT;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
721
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
722 if (cookie)
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
723 memcpy(proxy_info->cookie, cookie, 8);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
724
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
725 return proxy_info;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
726 }
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
727
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
728 /**
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
729 * Remove the given oft_info struct from the oft_info linked list, and
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
730 * then free its memory.
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
731 *
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
732 * @param sess The session.
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
733 * @param oft_info The aim_oft_info struct that we're destroying.
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
734 * @return Return 0 if no errors, otherwise return the error number.
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
735 */
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
736 faim_export int aim_oft_destroyinfo(struct aim_oft_info *oft_info)
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
737 {
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
738 aim_session_t *sess;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
739
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
740 if (!oft_info || !(sess = oft_info->sess))
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
741 return -EINVAL;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
742
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
743 if (sess->oft_info && (sess->oft_info == oft_info)) {
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
744 sess->oft_info = sess->oft_info->next;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
745 } else {
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
746 struct aim_oft_info *cur;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
747 for (cur=sess->oft_info; (cur->next && (cur->next!=oft_info)); cur=cur->next);
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
748 if (cur->next)
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
749 cur->next = cur->next->next;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
750 }
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
751
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
752 free(oft_info->sn);
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
753 free(oft_info->proxyip);
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
754 free(oft_info->clientip);
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
755 free(oft_info->verifiedip);
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
756 free(oft_info);
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
757
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
758 return 0;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
759 }
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
760
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
761 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
762 * Creates a listener socket so the other dude can connect to us.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
763 *
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
764 * You'll want to set up some kind of watcher on this socket.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
765 * When the state changes, call aim_handlerendconnection with
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
766 * the connection returned by this. aim_handlerendconnection
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
767 * will accept the pending connection and stop listening.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
768 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
769 * @param sess The session.
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
770 * @param oft_info File transfer information associated with this
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
771 * connection.
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
772 * @return Return 0 if no errors, otherwise return the error number.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
773 */
8240
609a62b8e748 [gaim-migrate @ 8963]
Mark Doliner <mark@kingant.net>
parents: 8080
diff changeset
774 faim_export int aim_sendfile_listen(aim_session_t *sess, struct aim_oft_info *oft_info, int listenfd)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
775 {
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
776 if (!oft_info)
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
777 return -EINVAL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
778
11162
ccb38cf22483 [gaim-migrate @ 13263]
Mark Doliner <mark@kingant.net>
parents: 11159
diff changeset
779 if (!(oft_info->conn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER))) {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
780 close(listenfd);
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
781 return -ENOMEM;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
782 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
783
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
784 oft_info->conn->fd = listenfd;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
785 oft_info->conn->subtype = AIM_CONN_SUBTYPE_OFT_SENDFILE;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
786 oft_info->conn->lastactivity = time(NULL);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
787
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
788 return 0;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
789 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
790
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
791 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
792 * Extract an &aim_fileheader_t from the given buffer.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
793 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
794 * @param bs The should be from an incoming rendezvous packet.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
795 * @return A pointer to new struct on success, or NULL on error.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
796 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
797 static struct aim_fileheader_t *aim_oft_getheader(aim_bstream_t *bs)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
798 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
799 struct aim_fileheader_t *fh;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
800
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
801 if (!(fh = calloc(1, sizeof(struct aim_fileheader_t))))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
802 return NULL;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
803
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
804 /* The bstream should be positioned after the hdrtype. */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
805 aimbs_getrawbuf(bs, fh->bcookie, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
806 fh->encrypt = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
807 fh->compress = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
808 fh->totfiles = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
809 fh->filesleft = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
810 fh->totparts = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
811 fh->partsleft = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
812 fh->totsize = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
813 fh->size = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
814 fh->modtime = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
815 fh->checksum = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
816 fh->rfrcsum = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
817 fh->rfsize = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
818 fh->cretime = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
819 fh->rfcsum = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
820 fh->nrecvd = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
821 fh->recvcsum = aimbs_get32(bs);
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 11126
diff changeset
822 aimbs_getrawbuf(bs, (guchar *)fh->idstring, 32);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
823 fh->flags = aimbs_get8(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
824 fh->lnameoffset = aimbs_get8(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
825 fh->lsizeoffset = aimbs_get8(bs);
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
826 aimbs_getrawbuf(bs, (guchar *)fh->dummy, 69);
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
827 aimbs_getrawbuf(bs, (guchar *)fh->macfileinfo, 16);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
828 fh->nencode = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
829 fh->nlanguage = aimbs_get16(bs);
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 11126
diff changeset
830 aimbs_getrawbuf(bs, (guchar *)fh->name, 64); /* XXX - filenames longer than 64B */
8446
d9cf0c2f4339 [gaim-migrate @ 9176]
Mark Doliner <mark@kingant.net>
parents: 8426
diff changeset
831 fh->name[63] = '\0';
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
832
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
833 return fh;
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
834 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
835
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
836 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
837 * Fills a buffer with network-order fh data
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
838 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
839 * @param bs A bstream to fill -- automatically initialized
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
840 * @param fh A struct aim_fileheader_t to get data from.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
841 * @return Return non-zero on error.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
842 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
843 static int aim_oft_buildheader(aim_bstream_t *bs, struct aim_fileheader_t *fh)
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
844 {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
845 fu8_t *hdr;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
846
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
847 if (!bs || !fh)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
848 return -EINVAL;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
849
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
850 if (!(hdr = (unsigned char *)calloc(1, 0x100 - 8)))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
851 return -ENOMEM;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
852
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
853 aim_bstream_init(bs, hdr, 0x100 - 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
854 aimbs_putraw(bs, fh->bcookie, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
855 aimbs_put16(bs, fh->encrypt);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
856 aimbs_put16(bs, fh->compress);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
857 aimbs_put16(bs, fh->totfiles);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
858 aimbs_put16(bs, fh->filesleft);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
859 aimbs_put16(bs, fh->totparts);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
860 aimbs_put16(bs, fh->partsleft);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
861 aimbs_put32(bs, fh->totsize);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
862 aimbs_put32(bs, fh->size);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
863 aimbs_put32(bs, fh->modtime);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
864 aimbs_put32(bs, fh->checksum);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
865 aimbs_put32(bs, fh->rfrcsum);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
866 aimbs_put32(bs, fh->rfsize);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
867 aimbs_put32(bs, fh->cretime);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
868 aimbs_put32(bs, fh->rfcsum);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
869 aimbs_put32(bs, fh->nrecvd);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
870 aimbs_put32(bs, fh->recvcsum);
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
871 aimbs_putraw(bs, (guchar *)fh->idstring, 32);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
872 aimbs_put8(bs, fh->flags);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
873 aimbs_put8(bs, fh->lnameoffset);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
874 aimbs_put8(bs, fh->lsizeoffset);
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
875 aimbs_putraw(bs, (guchar *)fh->dummy, 69);
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
876 aimbs_putraw(bs, (guchar *)fh->macfileinfo, 16);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
877 aimbs_put16(bs, fh->nencode);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
878 aimbs_put16(bs, fh->nlanguage);
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
879 aimbs_putraw(bs, (guchar *)fh->name, 64); /* XXX - filenames longer than 64B */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
880
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
881 return 0;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
882 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
883
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
884 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
885 * Create an OFT packet based on the given information, and send it on its merry way.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
886 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
887 * @param sess The session.
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
888 * @param type The subtype of the OFT packet we're sending.
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
889 * @param oft_info The aim_oft_info struct with the connection and OFT
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
890 * info we're sending.
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
891 * @return Return 0 if no errors, otherwise return the error number.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
892 */
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
893 faim_export int aim_oft_sendheader(aim_session_t *sess, fu16_t type, struct aim_oft_info *oft_info)
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
894 {
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
895 aim_frame_t *fr;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
896
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
897 if (!sess || !oft_info || !oft_info->conn || (oft_info->conn->type != AIM_CONN_TYPE_RENDEZVOUS))
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
898 return -EINVAL;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
899
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
900 #if 0
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
901 /*
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
902 * If you are receiving a file, the cookie should be null, if you are sending a
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
903 * file, the cookie should be the same as the one used in the ICBM negotiation
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
904 * SNACs.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
905 */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
906 fh->lnameoffset = 0x1a;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
907 fh->lsizeoffset = 0x10;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
908
9826
6f2a90c36ee2 [gaim-migrate @ 10697]
Mark Doliner <mark@kingant.net>
parents: 9430
diff changeset
909 /* These should be the same as charset and charsubset in ICBMs */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
910 fh->nencode = 0x0000;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
911 fh->nlanguage = 0x0000;
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
912 #endif
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
913
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
914 aim_oft_dirconvert_tostupid(oft_info->fh.name);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
915
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
916 if (!(fr = aim_tx_new(sess, oft_info->conn, AIM_FRAMETYPE_OFT, type, 0)))
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
917 return -ENOMEM;
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
918
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
919 if (aim_oft_buildheader(&fr->data, &oft_info->fh) == -1) {
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
920 aim_frame_destroy(fr);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
921 return -ENOMEM;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
922 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
923
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
924 memcpy(fr->hdr.rend.magic, "OFT2", 4);
8426
aa755705bcf5 [gaim-migrate @ 9156]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
925 fr->hdr.rend.hdrlen = aim_bstream_curpos(&fr->data) + 8;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
926
5146
ac9ca88d4b25 [gaim-migrate @ 5510]
Mark Doliner <mark@kingant.net>
parents: 4913
diff changeset
927 aim_tx_enqueue(sess, fr);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
928
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
929 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
930 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
931
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
932 /**
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
933 * Create a rendezvous "init recv" packet and send it on its merry way.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
934 * This is the first packet sent to the proxy server by the second client
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
935 * involved in this rendezvous proxy session.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
936 *
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
937 * @param sess The session.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
938 * @param proxy_info Changable pieces of data for this packet
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
939 * @return Return 0 if no errors, otherwise return the error number.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
940 */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
941 faim_export int aim_rv_proxy_init_recv(struct aim_rv_proxy_info *proxy_info)
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
942 {
11820
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
943 #if 0
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
944 aim_tlvlist_t *tlvlist_sendfile;
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
945 #endif
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
946 aim_bstream_t bs;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
947 fu8_t *bs_raw;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
948 fu16_t packet_len;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
949 fu8_t sn_len;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
950 int err;
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
951
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
952 err = 0;
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
953
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
954 if (!proxy_info)
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
955 return -EINVAL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
956
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
957 sn_len = strlen(proxy_info->sess->sn);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
958 packet_len = 2 + 2 /* packet_len, packet_ver */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
959 + 2 + 4 /* cmd_type, unknownA */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
960 + 2 /* flags */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
961 + 1 + sn_len /* Length/value pair for screenname */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
962 + 8 /* ICBM Cookie */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
963 + 2 /* port */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
964 + 2 + 2 + 16; /* TLV for Filesend capability block */
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
965
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
966 if (!(bs_raw = malloc(packet_len)))
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
967 return -ENOMEM;
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
968
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
969 aim_bstream_init(&bs, bs_raw, packet_len);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
970 aimbs_put16(&bs, packet_len - 2); /* Length includes only packets after length marker */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
971 aimbs_put16(&bs, proxy_info->packet_ver);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
972 aimbs_put16(&bs, AIM_RV_PROXY_INIT_RECV);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
973 aimbs_put32(&bs, proxy_info->unknownA);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
974 aimbs_put16(&bs, proxy_info->flags);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
975 aimbs_put8(&bs, sn_len);
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
976 aimbs_putraw(&bs, (const guchar *)proxy_info->sess->sn, sn_len);
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
977 aimbs_put16(&bs, proxy_info->port);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
978 aimbs_putraw(&bs, proxy_info->cookie, 8);
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
979
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
980 aimbs_put16(&bs, 0x0001); /* Type */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
981 aimbs_put16(&bs, 16); /* Length */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
982 aimbs_putcaps(&bs, AIM_CAPS_SENDFILE); /* Value */
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
983
11820
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
984
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
985 #if 0
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
986 /* TODO: Use built-in TLV */
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
987 aim_tlvlist_add_caps(&tlvlist_sendfile, 0x0001, AIM_CAPS_SENDFILE);
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
988 aim_tlvlist_write(&bs, &tlvlist_sendfile);
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
989 #endif
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
990
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
991 aim_bstream_rewind(&bs);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
992 if (aim_bstream_send(&bs, proxy_info->conn, packet_len) != packet_len)
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
993 err = errno;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
994 proxy_info->conn->lastactivity = time(NULL);
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
995
11820
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
996 #if 0
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
997 aim_tlvlist_free(tlvlist_sendfile);
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
998 #endif
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
999 free(bs_raw);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1000
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1001 return err;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1002 }
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1003
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1004
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1005 /**
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1006 * Create a rendezvous "init send" packet and send it on its merry way.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1007 * This is the first packet sent to the proxy server by the client
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1008 * first indicating that this will be a proxied connection
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1009 *
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1010 * @param sess The session.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1011 * @param proxy_info Changable pieces of data for this packet
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1012 * @return Return 0 if no errors, otherwise return the error number.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1013 */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1014 faim_export int aim_rv_proxy_init_send(struct aim_rv_proxy_info *proxy_info)
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1015 {
11820
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1016 #if 0
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1017 aim_tlvlist_t *tlvlist_sendfile;
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1018 #endif
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1019 aim_bstream_t bs;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1020 fu8_t *bs_raw;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1021 fu16_t packet_len;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1022 fu8_t sn_len;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1023 int err;
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1024
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1025 err = 0;
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1026
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1027 if (!proxy_info)
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1028 return -EINVAL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1029
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1030 sn_len = strlen(proxy_info->sess->sn);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1031 packet_len = 2 + 2 /* packet_len, packet_ver */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1032 + 2 + 4 /* cmd_type, unknownA */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1033 + 2 /* flags */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1034 + 1 + sn_len /* Length/value pair for screenname */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1035 + 8 /* ICBM Cookie */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1036 + 2 + 2 + 16; /* TLV for Filesend capability block */
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1037
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1038 if (!(bs_raw = malloc(packet_len)))
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1039 return -ENOMEM;
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1040
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1041 aim_bstream_init(&bs, bs_raw, packet_len);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1042 aimbs_put16(&bs, packet_len - 2); /* Length includes only packets after length marker */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1043 aimbs_put16(&bs, proxy_info->packet_ver);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1044 aimbs_put16(&bs, AIM_RV_PROXY_INIT_SEND);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1045 aimbs_put32(&bs, proxy_info->unknownA);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1046 aimbs_put16(&bs, proxy_info->flags);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1047 aimbs_put8(&bs, sn_len);
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1048 aimbs_putraw(&bs, (const guchar *)proxy_info->sess->sn, sn_len);
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1049 aimbs_putraw(&bs, proxy_info->cookie, 8);
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1050
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1051 aimbs_put16(&bs, 0x0001); /* Type */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1052 aimbs_put16(&bs, 16); /* Length */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1053 aimbs_putcaps(&bs, AIM_CAPS_SENDFILE); /* Value */
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1054
11820
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1055 /* TODO: Use built-in TLV */
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1056 #if 0
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1057 aim_tlvlist_add_caps(&tlvlist_sendfile, 0x0001, AIM_CAPS_SENDFILE);
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1058 aim_tlvlist_write(&bs, &tlvlist_sendfile);
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1059 #endif
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1060
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1061 aim_bstream_rewind(&bs);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1062 if (aim_bstream_send(&bs, proxy_info->conn, packet_len) != packet_len)
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1063 err = errno;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1064 proxy_info->conn->lastactivity = time(NULL);
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1065
11820
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1066 #if 0
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1067 aim_tlvlist_free(tlvlist_sendfile);
2cf6d4cf2cb0 [gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents: 11401
diff changeset
1068 #endif
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1069 free(bs_raw);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1070
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1071 return err;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1072 }
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1073
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1074 /**
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1075 * Handle incoming data on a rendezvous connection. This is analogous to the
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1076 * consumesnac function in rxhandlers.c, and I really think this should probably
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1077 * be in rxhandlers.c as well, but I haven't finished cleaning everything up yet.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1078 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1079 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1080 * @param fr The frame allocated for the incoming data.
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1081 * @return Return 0 if the packet was handled correctly, otherwise return the
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1082 * error number.
3771
765769211688 [gaim-migrate @ 3910]
Rob Flynn <gaim@robflynn.com>
parents: 3752
diff changeset
1083 */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
1084 faim_internal int aim_rxdispatch_rendezvous(aim_session_t *sess, aim_frame_t *fr)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1085 {
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
1086 aim_conn_t *conn = fr->conn;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1087 int ret = 1;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1088
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1089 if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1090 if (fr->hdr.rend.type == 0x0001)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1091 ret = handlehdr_odc(sess, conn, fr, &fr->data);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1092 else
11253
7d31d61e6438 [gaim-migrate @ 13422]
Mark Doliner <mark@kingant.net>
parents: 11214
diff changeset
1093 gaim_debug_info("oscar", "ODC directim frame unknown, type is %04x\n", fr->hdr.rend.type);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1094
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
1095 } else {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1096 aim_rxcallback_t userfunc;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1097 struct aim_fileheader_t *header = aim_oft_getheader(&fr->data);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1098 aim_oft_dirconvert_fromstupid(header->name); /* XXX - This should be client-side */
3771
765769211688 [gaim-migrate @ 3910]
Rob Flynn <gaim@robflynn.com>
parents: 3752
diff changeset
1099
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1100 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, fr->hdr.rend.type)))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1101 ret = userfunc(sess, fr, conn, header->bcookie, header);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1102
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1103 free(header);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
1104 }
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
1105
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
1106 if (ret == -1)
10271
361c9170d8af [gaim-migrate @ 11420]
Mark Doliner <mark@kingant.net>
parents: 10267
diff changeset
1107 aim_conn_close(conn);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1108
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
1109 return ret;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
1110 }
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1111
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1112 /**
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1113 * Handle incoming data on a rendezvous proxy connection. This is similar to
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1114 * aim_rxdispatch_rendezvous above and should probably be kept with that function.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1115 *
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1116 * @param sess The session.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1117 * @param fr The frame allocated for the incoming data.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1118 * @return Return 0 if the packet was handled correctly, otherwise return the
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1119 * error number.
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1120 */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1121 faim_internal struct aim_rv_proxy_info *aim_rv_proxy_read(aim_session_t *sess, aim_conn_t *conn)
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1122 {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1123 aim_bstream_t bs_hdr;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1124 fu8_t hdr_buf[AIM_RV_PROXY_HDR_LEN];
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1125 aim_bstream_t bs_body; /* The body (everything but the header) of the packet */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1126 fu8_t *body_buf = NULL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1127 fu8_t body_len;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1128
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1129 char str_ip[30] = {""};
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1130 fu8_t ip_temp[4];
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1131
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1132 fu16_t len;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1133 struct aim_rv_proxy_info *proxy_info;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1134
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1135 if(!(proxy_info = malloc(sizeof(struct aim_rv_proxy_info))))
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1136 return NULL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1137
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1138 aim_bstream_init(&bs_hdr, hdr_buf, AIM_RV_PROXY_HDR_LEN);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1139 if (aim_bstream_recv(&bs_hdr, conn->fd, AIM_RV_PROXY_HDR_LEN) == AIM_RV_PROXY_HDR_LEN) {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1140 aim_bstream_rewind(&bs_hdr);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1141 len = aimbs_get16(&bs_hdr);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1142 proxy_info->packet_ver = aimbs_get16(&bs_hdr);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1143 proxy_info->cmd_type = aimbs_get16(&bs_hdr);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1144 proxy_info->unknownA = aimbs_get32(&bs_hdr);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1145 proxy_info->flags = aimbs_get16(&bs_hdr);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1146 if(proxy_info->cmd_type == AIM_RV_PROXY_READY) {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1147 /* Do a little victory dance
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1148 * A ready packet contains no additional information */
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1149 } else if(proxy_info->cmd_type == AIM_RV_PROXY_ERROR) {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1150 if(len == AIM_RV_PROXY_ERROR_LEN - 2) {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1151 body_len = AIM_RV_PROXY_ERROR_LEN - AIM_RV_PROXY_HDR_LEN;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1152 body_buf = malloc(body_len);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1153 aim_bstream_init(&bs_body, body_buf, body_len);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1154 if (aim_bstream_recv(&bs_body, conn->fd, body_len) == body_len) {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1155 aim_bstream_rewind(&bs_body);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1156 proxy_info->err_code = aimbs_get16(&bs_body);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1157 } else {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1158 gaim_debug_warning("oscar","error reading rv proxy error packet\n");
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1159 aim_conn_close(conn);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1160 free(proxy_info);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1161 proxy_info = NULL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1162 }
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1163 } else {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1164 gaim_debug_warning("oscar","invalid length for proxy error packet\n");
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1165 free(proxy_info);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1166 proxy_info = NULL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1167 }
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1168 } else if(proxy_info->cmd_type == AIM_RV_PROXY_ACK) {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1169 if(len == AIM_RV_PROXY_ACK_LEN - 2) {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1170 body_len = AIM_RV_PROXY_ACK_LEN - AIM_RV_PROXY_HDR_LEN;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1171 body_buf = malloc(body_len);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1172 aim_bstream_init(&bs_body, body_buf, body_len);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1173 if (aim_bstream_recv(&bs_body, conn->fd, body_len) == body_len) {
11399
48244c196228 [gaim-migrate @ 13634]
Mark Doliner <mark@kingant.net>
parents: 11369
diff changeset
1174 int i;
11369
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1175 aim_bstream_rewind(&bs_body);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1176 proxy_info->port = aimbs_get16(&bs_body);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1177 for(i=0; i<4; i++)
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1178 ip_temp[i] = aimbs_get8(&bs_body);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1179 snprintf(str_ip, sizeof(str_ip), "%hhu.%hhu.%hhu.%hhu",
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1180 ip_temp[0], ip_temp[1],
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1181 ip_temp[2], ip_temp[3]);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1182 proxy_info->ip = strdup(str_ip);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1183 } else {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1184 gaim_debug_warning("oscar","error reading rv proxy error packet\n");
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1185 aim_conn_close(conn);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1186 free(proxy_info);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1187 proxy_info = NULL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1188 }
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1189 } else {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1190 gaim_debug_warning("oscar","invalid length for proxy error packet\n");
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1191 free(proxy_info);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1192 proxy_info = NULL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1193 }
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1194 } else {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1195 gaim_debug_warning("oscar","unknown type for aim rendezvous proxy packet\n");
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1196 }
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1197 } else {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1198 gaim_debug_warning("oscar","error reading header of rv proxy packet\n");
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1199 aim_conn_close(conn);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1200 free(proxy_info);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1201 proxy_info = NULL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1202 }
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1203 if(body_buf) {
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1204 free(body_buf);
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1205 body_buf = NULL;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1206 }
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1207 return proxy_info;
ab0fa7cd61cc [gaim-migrate @ 13593]
Jonathan Clark <ardentlygnarly>
parents: 11253
diff changeset
1208 }