annotate src/protocols/oscar/ft.c @ 5136:381da05cb5ed

[gaim-migrate @ 5500] this started out as simply adding an option to right-click on a jabber buddy and re-request authorization. Then I ended up chasing the disgusting mess of const vs non-const parameters all over gaim. The end result is that you can now right-click on jabber buddies and re-request auth like you can for ICQ. Also, a lot more things are const that should be, I fixed a bug or two, and I cleaned up one of my least favorite functions in gaim (linkify_text). It is now decidedly less evil. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 15 Apr 2003 04:18:00 +0000
parents 6c02ee2b471d
children ac9ca88d4b25
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 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
5 * There are a few static helper functions at the top, then
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 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
8 * I feel like this is a good place to explain OFT, so I'm going to
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
9 * do just that. Each OFT packet has a header type. I guess this
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
10 * is pretty similar to the subtype of a SNAC packet. The type
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
11 * basically tells the other client the meaning of the OFT packet.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
12 * There are two distinct types of file transfer, which I usually
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
13 * call "sendfile" and "getfile." Sendfile is when you send a file
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
14 * to another AIM user. Getfile is when you share a group of files,
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:
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
18 * 1) Sender sends a channel 2 ICBM telling the other user that
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
19 * we want to send them a file. At the same time, we open a
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
20 * listener socket (this should be done before sending the
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
21 * ICBM) on some port, and wait for them to connect to us.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
22 * The ICBM we sent should contain our IP address and the port
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
23 * number that we're listening on.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
24 * 2) The receiver connects to the sender on the given IP address
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
25 * and port. After the connection is established, the receiver
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
26 * sends another ICBM signifying that we are ready and waiting.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
27 * 3) The sender sends an OFT PROMPT message over the OFT
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
28 * connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
29 * 4) The receiver of the file sends back an exact copy of this
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
30 * OFT packet, except the cookie is filled in with the cookie
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
31 * from the ICBM. I think this might be an attempt to verify
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
32 * that the user that is connected is actually the guy that
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.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
34 * 5) The sender starts sending raw data across the connection
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
35 * until the entire file has been sent.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
36 * 6) The receiver knows the file is finished because the sender
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
37 * sent the file size in an earlier OFT packet. So then the
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
38 * receiver sends the DONE thingy and closes the connection.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 */
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 #define FAIM_INTERNAL
2931
10a2d4d5bcf2 [gaim-migrate @ 2944]
Adam Fritzler <mid@auk.cx>
parents: 2919
diff changeset
42
2711
b7455c506979 [gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2675
diff changeset
43 #ifdef HAVE_CONFIG_H
b7455c506979 [gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2675
diff changeset
44 #include <config.h>
b7455c506979 [gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2675
diff changeset
45 #endif
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 #include <aim.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 #ifndef _WIN32
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 #include <netdb.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 #include <sys/socket.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 #include <netinet/in.h>
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
52 #include <sys/utsname.h> /* for aim_odc_initiate */
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
53 #include <arpa/inet.h> /* for inet_ntoa */
3960
7ba5f2e13ee8 [gaim-migrate @ 4142]
Mark Doliner <mark@kingant.net>
parents: 3953
diff changeset
54 #define G_DIR_SEPARATOR '/'
3646
bfd8df165f32 [gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
55 #endif
bfd8df165f32 [gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
56
bfd8df165f32 [gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
57 #ifdef _WIN32
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
58 #include "win32dep.h"
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
59 #endif
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
61 struct aim_odc_intdata {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
62 fu8_t cookie[8];
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
63 char sn[MAXSNLEN+1];
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
64 char ip[22];
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
65 };
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
66
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
67 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
68 * Convert the directory separator from / (0x2f) to ^A (0x01)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
69 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
70 * @param name The filename to convert.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
71 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
72 static void aim_oft_dirconvert_tostupid(char *name)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
73 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
74 while (name[0]) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
75 if (name[0] == 0x01)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
76 name[0] = G_DIR_SEPARATOR;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
77 name++;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
78 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
79 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
80
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
81 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
82 * Convert the directory separator from ^A (0x01) to / (0x2f)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
83 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
84 * @param name The filename to convert.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
85 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
86 static void aim_oft_dirconvert_fromstupid(char *name)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
87 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
88 while (name[0]) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
89 if (name[0] == G_DIR_SEPARATOR)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
90 name[0] = 0x01;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
91 name++;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
92 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
93 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
94
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 * Calculate oft checksum of buffer
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 * Prevcheck should be 0xFFFF0000 when starting a checksum of a file. The
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
99 * checksum is kind of a rolling checksum thing, so each time you get bytes
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
100 * of a file you just call this puppy and it updates the checksum. You can
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
101 * calculate the checksum of an entire file by calling this in a while or a
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
102 * for loop, or something.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
103 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
104 * Thanks to Graham Booker for providing this improved checksum routine,
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
105 * which is simpler and should be more accurate than Josh Myer's original
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
106 * code. -- wtm
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
107 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
108 * This algorithim works every time I have tried it. The other fails
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
109 * sometimes. So, AOL who thought this up? It has got to be the weirdest
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
110 * checksum I have ever seen.
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 * @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
113 * @param bufsize Size of buffer.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
114 * @param prevcheck Previous checksum.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
115 */
4763
c050edba7b83 [gaim-migrate @ 5081]
Mark Doliner <mark@kingant.net>
parents: 4650
diff changeset
116 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
117 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
118 fu32_t check = (prevcheck >> 16) & 0xffff, oldcheck;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
119 int i;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
120 unsigned short val;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
121
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
122 for (i=0; i<bufferlen; i++) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
123 oldcheck = check;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
124 if (i&1)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
125 val = buffer[i];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
126 else
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
127 val = buffer[i] << 8;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
128 check -= val;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
129 /*
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
130 * The following appears to be necessary.... It happens
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
131 * every once in a while and the checksum doesn't fail.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
132 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
133 if (check > oldcheck)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
134 check--;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
135 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
136 check = ((check & 0x0000ffff) + (check >> 16));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
137 check = ((check & 0x0000ffff) + (check >> 16));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
138 return check << 16;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
139 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
140
4650
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
141 faim_export fu32_t aim_oft_checksum_file(char *filename) {
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
142 FILE *fd;
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
143 fu32_t checksum = 0xffff0000;
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
144
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
145 if ((fd = fopen(filename, "rb"))) {
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
146 int bytes;
4763
c050edba7b83 [gaim-migrate @ 5081]
Mark Doliner <mark@kingant.net>
parents: 4650
diff changeset
147 fu8_t buffer[1024];
4650
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
148
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
149 while ((bytes = fread(buffer, 1, 1024, fd)))
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
150 checksum = aim_oft_checksum_chunk(buffer, bytes, checksum);
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
151 fclose(fd);
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
152 }
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
153
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
154 return checksum;
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
155 }
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4646
diff changeset
156
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
158 * Create a listening socket on a given port.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
159 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
160 * XXX - Give the client author the responsibility of setting up a
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
161 * listener, then we no longer have a libfaim problem with broken
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
162 * solaris *innocent smile* -- jbm
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
164 * @param portnum The port number to bind to.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
165 * @return The file descriptor of the listening socket.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
166 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
167 static int listenestablish(fu16_t portnum)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
168 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
169 #if HAVE_GETADDRINFO
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
170 int listenfd;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
171 const int on = 1;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
172 struct addrinfo hints, *res, *ressave;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
173 char serv[5];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
174
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
175 snprintf(serv, sizeof(serv), "%d", portnum);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
176 memset(&hints, 0, sizeof(struct addrinfo));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
177 hints.ai_flags = AI_PASSIVE;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
178 hints.ai_family = AF_UNSPEC;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
179 hints.ai_socktype = SOCK_STREAM;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
180 if (getaddrinfo(NULL /* any IP */, serv, &hints, &res) != 0) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
181 perror("getaddrinfo");
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
182 return -1;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
183 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
184 ressave = res;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
185 do {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
186 listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
187 if (listenfd < 0)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
188 continue;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
189 setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
190 if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
191 break; /* success */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
192 close(listenfd);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
193 } while ( (res = res->ai_next) );
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
194
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
195 if (!res)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
196 return -1;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
197
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
198 freeaddrinfo(ressave);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
199 #else
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
200 int listenfd;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
201 const int on = 1;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
202 struct sockaddr_in sockin;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
203
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
204 if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
205 perror("socket");
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
206 return -1;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
207 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
208
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
209 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) != 0) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
210 perror("setsockopt");
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
211 close(listenfd);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
212 return -1;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
213 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
214
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
215 memset(&sockin, 0, sizeof(struct sockaddr_in));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
216 sockin.sin_family = AF_INET;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
217 sockin.sin_port = htons(portnum);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
218
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
219 if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
220 perror("bind");
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
221 close(listenfd);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
222 return -1;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
223 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
224 #endif
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
225
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
226 if (listen(listenfd, 4) != 0) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
227 perror("listen");
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
228 close(listenfd);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
229 return -1;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
230 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
231 fcntl(listenfd, F_SETFL, O_NONBLOCK);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
232
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
233 return listenfd;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
234 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
235
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
236 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
237 * 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
238 * 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
239 * 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
240 * 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
241 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
242 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
243 * @param cur The conn the incoming connection is on.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
244 * @return Return 0 if no errors, otherwise return the error number.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245 */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
246 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
247 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
248 int acceptfd = 0;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
249 struct sockaddr addr;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
250 socklen_t addrlen = sizeof(addr);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
251 int ret = 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
252 aim_conn_t *newconn;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
253 char ip[20];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
254 int port;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
255
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
256 if ((acceptfd = accept(cur->fd, &addr, &addrlen)) == -1)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
257 return 0; /* not an error */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
259 if (addr.sa_family != AF_INET) { /* just in case IPv6 really is happening */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
260 close(acceptfd);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
261 aim_conn_close(cur);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
262 return -1;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
263 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
264
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
265 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
266 port = ntohs(((struct sockaddr_in *)&addr)->sin_port);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
267
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
268 if (!(newconn = aim_cloneconn(sess, cur))) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
269 close(acceptfd);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
270 aim_conn_close(cur);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
271 return -ENOMEM;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
272 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
273
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
274 newconn->type = AIM_CONN_TYPE_RENDEZVOUS;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
275 newconn->fd = acceptfd;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
276
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
277 if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
278 aim_rxcallback_t userfunc;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
279 struct aim_odc_intdata *priv;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
280
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
281 priv = (struct aim_odc_intdata *)(newconn->internal = cur->internal);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
282 cur->internal = NULL;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
283 snprintf(priv->ip, sizeof(priv->ip), "%s:%u", ip, port);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
284
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
285 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
286 ret = userfunc(sess, NULL, newconn, cur);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
287
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
288 } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
289 } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
290 aim_rxcallback_t userfunc;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
291
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
292 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
293 ret = userfunc(sess, NULL, newconn, cur);
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
294
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
295 } else {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
296 faimdprintf(sess, 1,"Got a connection on a listener that's not rendezvous. Closing connection.\n");
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
297 aim_conn_close(newconn);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
298 ret = -1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
299 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
300
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
301 return ret;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
303
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
304 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
305 * Send client-to-client typing notification over an established direct connection.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
307 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
308 * @param conn The already-connected ODC connection.
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
309 * @param typing If 0x0002, sends a "typing" message, 0x0001 sends "typed," and
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
310 * 0x0000 sends "stopped."
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
311 * @return Return 0 if no errors, otherwise return the error number.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
312 */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
313 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
314 {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
315 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
316 aim_frame_t *fr;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
317 aim_bstream_t *hdrbs;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
318 fu8_t *hdr;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
319 int hdrlen = 0x44;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
320
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
321 if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS))
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
322 return -EINVAL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
323
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
324 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
325 return -ENOMEM;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
326 memcpy(fr->hdr.rend.magic, "ODC2", 4);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
327 fr->hdr.rend.hdrlen = hdrlen;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
328
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
329 if (!(hdr = calloc(1, hdrlen))) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
330 aim_frame_destroy(fr);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
331 return -ENOMEM;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
332 }
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
333
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
334 hdrbs = &(fr->data);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
335 aim_bstream_init(hdrbs, hdr, hdrlen);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
336
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
337 aimbs_put16(hdrbs, 0x0006);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
338 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
339 aimbs_putraw(hdrbs, intdata->cookie, 8);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
340 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
341 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
342 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
343 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
344 aimbs_put32(hdrbs, 0x00000000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
345 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
346 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
347 aimbs_put16(hdrbs, 0x0000);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
348
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
349 if (typing == 0x0002)
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
350 aimbs_put16(hdrbs, 0x0002 | 0x0008);
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
351 else if (typing == 0x0001)
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
352 aimbs_put16(hdrbs, 0x0002 | 0x0004);
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
353 else
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
354 aimbs_put16(hdrbs, 0x0002);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
355
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
356 aimbs_put16(hdrbs, 0x0000);
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_putraw(hdrbs, sess->sn, strlen(sess->sn));
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
359
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
360 aim_bstream_setpos(hdrbs, 52); /* bleeehh */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
361
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
362 aimbs_put8(hdrbs, 0x00);
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);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
365 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
366 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
367 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
368 aimbs_put16(hdrbs, 0x0000);
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_put8(hdrbs, 0x00);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
371
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
372 /* end of hdr */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
373
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
374 aim_tx_enqueue(sess, fr);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
375
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
376 return 0;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
377 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
378
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
379 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
380 * Send client-to-client IM over an established direct connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
381 * Call this just like you would aim_send_im, to send a directim.
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
382 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
383 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
384 * @param conn The already-connected ODC connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
385 * @param msg Null-terminated string to send.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
386 * @param len The length of the message to send, including binary data.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
387 * @param encoding 0 for ascii, 2 for Unicode, 3 for ISO 8859-1.
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
388 * @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
389 * @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
390 */
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
391 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
392 {
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
393 aim_frame_t *fr;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
394 aim_bstream_t *hdrbs;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
395 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
396 int hdrlen = 0x44;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
397 fu8_t *hdr;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
398
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
399 if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !msg)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
400 return -EINVAL;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
401
4875
26837f462a66 [gaim-migrate @ 5205]
Mark Doliner <mark@kingant.net>
parents: 4870
diff changeset
402 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
403 return -ENOMEM;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
404
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
405 memcpy(fr->hdr.rend.magic, "ODC2", 4);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
406 fr->hdr.rend.hdrlen = hdrlen;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
407
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
408 if (!(hdr = calloc(1, hdrlen + len))) {
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
409 aim_frame_destroy(fr);
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
410 return -ENOMEM;
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
411 }
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
412
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
413 hdrbs = &(fr->data);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
414 aim_bstream_init(hdrbs, hdr, hdrlen + len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
415
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
416 aimbs_put16(hdrbs, 0x0006);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
417 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
418 aimbs_putraw(hdrbs, intdata->cookie, 8);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
419 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
420 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
421 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
422 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
423 aimbs_put32(hdrbs, len);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
424 aimbs_put16(hdrbs, encoding);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
425 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
426 aimbs_put16(hdrbs, 0x0000);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
427
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
428 /* 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
429 aimbs_put16(hdrbs, 0x0000 | isawaymsg);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
430
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
431 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
432 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
433 aimbs_putraw(hdrbs, sess->sn, strlen(sess->sn));
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
434
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
435 aim_bstream_setpos(hdrbs, 52); /* bleeehh */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
436
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
437 aimbs_put8(hdrbs, 0x00);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
438 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
439 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
440 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
441 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
442 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
443 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
444 aimbs_put16(hdrbs, 0x0000);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
445 aimbs_put8(hdrbs, 0x00);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
446
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
447 /* end of hdr2 */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
448
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
449 #if 0 /* XXX - this is how you send buddy icon info... */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
450 aimbs_put16(hdrbs, 0x0008);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
451 aimbs_put16(hdrbs, 0x000c);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
452 aimbs_put16(hdrbs, 0x0000);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
453 aimbs_put16(hdrbs, 0x1466);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
454 aimbs_put16(hdrbs, 0x0001);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
455 aimbs_put16(hdrbs, 0x2e0f);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
456 aimbs_put16(hdrbs, 0x393e);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
457 aimbs_put16(hdrbs, 0xcac8);
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
458 #endif
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
459 aimbs_putraw(hdrbs, msg, len);
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
460
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2931
diff changeset
461 aim_tx_enqueue(sess, fr);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
462
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
463 return 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
464 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
465
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
466 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
467 * Get the screen name of the peer of a direct connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
468 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
469 * @param conn The ODC connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
470 * @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
471 */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
472 faim_export const char *aim_odc_getsn(aim_conn_t *conn)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
473 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
474 struct aim_odc_intdata *intdata;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
475
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
476 if (!conn || !conn->internal)
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
477 return NULL;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
478
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
479 if ((conn->type != AIM_CONN_TYPE_RENDEZVOUS) ||
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
480 (conn->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM))
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
481 return NULL;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
482
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
483 intdata = (struct aim_odc_intdata *)conn->internal;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
484
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
485 return intdata->sn;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
486 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
487
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
488 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
489 * Find the conn of a direct connection with the given buddy.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
490 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
491 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
492 * @param sn The screen name of the buddy whose direct connection you want to find.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
493 * @return The conn for the direct connection with the given buddy, or NULL if no
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
494 * connection was found.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
495 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
496 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
497 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
498 aim_conn_t *cur;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
499 struct aim_odc_intdata *intdata;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
500
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
501 if (!sess || !sn || !strlen(sn))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
502 return NULL;
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 for (cur = sess->connlist; cur; cur = cur->next) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
505 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
506 intdata = cur->internal;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
507 if (!aim_sncmp(intdata->sn, sn))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
508 return cur;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
509 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
510 }
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 return NULL;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
513 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
514
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
515 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
516 * 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
517 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
518 * You'll want to set up some kind of watcher on this socket.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
519 * When the state changes, call aim_handlerendconnection with
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
520 * the connection returned by this. aim_handlerendconnection
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
521 * will accept the pending connection and stop listening.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
522 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
523 * @param sess The session
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
524 * @param conn The BOS conn.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
525 * @param priv A dummy priv value (we'll let it get filled in later)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
526 * (if you pass a %NULL, we alloc one).
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
527 * @param sn The screen name to connect to.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
528 * @return The new connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
529 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
530 faim_export aim_conn_t *aim_odc_initiate(aim_session_t *sess, const char *sn)
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 aim_conn_t *newconn;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
533 aim_msgcookie_t *cookie;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
534 struct aim_odc_intdata *priv;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
535 int listenfd;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
536 fu16_t port = 4443;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
537 fu8_t localip[4];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
538 fu8_t ck[8];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
539
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
540 if (aim_util_getlocalip(localip) == -1)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
541 return NULL;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
542
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
543 if ((listenfd = listenestablish(port)) == -1)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
544 return NULL;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
545
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
546 aim_im_sendch2_odcrequest(sess, ck, sn, localip, port);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
547
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
548 cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
549 memcpy(cookie->cookie, ck, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
550 cookie->type = AIM_COOKIETYPE_OFTIM;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
551
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
552 /* this one is for the cookie */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
553 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
554
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
555 memcpy(priv->cookie, ck, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
556 strncpy(priv->sn, sn, sizeof(priv->sn));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
557 cookie->data = priv;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
558 aim_cachecookie(sess, cookie);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
559
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
560 /* XXX - switch to aim_cloneconn()? */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
561 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER, NULL))) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
562 close(listenfd);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
563 return NULL;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
564 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
565
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
566 /* this one is for the conn */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
567 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
568
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
569 memcpy(priv->cookie, ck, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
570 strncpy(priv->sn, sn, sizeof(priv->sn));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
571
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
572 newconn->fd = listenfd;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
573 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
574 newconn->internal = priv;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
575 newconn->lastactivity = time(NULL);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
576
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
577 return newconn;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
578 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
579
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
580 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
581 * Connect directly to the given buddy for directim.
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
582 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
583 * This is a wrapper for aim_newconn.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
584 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
585 * If addr is NULL, the socket is not created, but the connection is
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
586 * allocated and setup to connect.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
587 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
588 * @param sess The Godly session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
589 * @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
590 * @param addr Address to connect to.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
591 * @return The new connection.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
592 */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
593 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
594 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
595 aim_conn_t *newconn;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
596 struct aim_odc_intdata *intdata;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
597
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
598 if (!sess || !sn)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
599 return NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
600
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
601 if (!(intdata = malloc(sizeof(struct aim_odc_intdata))))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
602 return NULL;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
603 memset(intdata, 0, sizeof(struct aim_odc_intdata));
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
604 memcpy(intdata->cookie, cookie, 8);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
605 strncpy(intdata->sn, sn, sizeof(intdata->sn));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
606 if (addr)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
607 strncpy(intdata->ip, addr, sizeof(intdata->ip));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
608
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
609 /* XXX - verify that non-blocking connects actually work */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
610 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, addr))) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
611 free(intdata);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
612 return NULL;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
613 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
614
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
615 newconn->internal = intdata;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
616 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
617
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
618 return newconn;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
619 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
620
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
621 /**
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
622 * Sometimes you just don't know with these kinds of people.
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
623 *
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
624 * @param sess The session.
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
625 * @param conn The ODC connection of the incoming data.
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
626 * @param frr The frame allocated for the incoming data.
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
627 * @param bs It stands for "bologna sandwich."
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
628 * @return Return 0 if no errors, otherwise return the error number.
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
629 */
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
630 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
631 {
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
632 aim_frame_t fr;
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
633 int ret = 0;
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
634 aim_rxcallback_t userfunc;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
635 fu32_t payloadlength;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
636 fu16_t flags, encoding;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
637 char *snptr = NULL;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
638
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
639 fr.conn = conn;
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 /* AAA - ugly */
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
642 aim_bstream_setpos(bs, 20);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
643 payloadlength = aimbs_get32(bs);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
644
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
645 aim_bstream_setpos(bs, 24);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
646 encoding = aimbs_get16(bs);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
647
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
648 aim_bstream_setpos(bs, 30);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
649 flags = aimbs_get16(bs);
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 aim_bstream_setpos(bs, 36);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
652 /* XXX - create an aimbs_getnullstr function? */
4913
6c02ee2b471d [gaim-migrate @ 5247]
Mark Doliner <mark@kingant.net>
parents: 4895
diff changeset
653 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
654
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
655 faimdprintf(sess, 2, "faim: OFT frame: handlehdr_odc: %04x / %04x / %s\n", payloadlength, flags, snptr);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
656
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
657 if (flags & 0x0008) {
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
658 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
659 ret = userfunc(sess, &fr, snptr, 2);
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
660 } else if (flags & 0x0004) {
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
661 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
662 ret = userfunc(sess, &fr, snptr, 1);
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
663 } else {
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
664 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
665 ret = userfunc(sess, &fr, snptr, 0);
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
666 }
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
667
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
668 if (payloadlength) {
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
669 char *msg;
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
670 int recvd = 0;
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
671 int i, isawaymsg;
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
672
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
673 isawaymsg = flags & 0x0001;
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
674
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
675 if (!(msg = calloc(1, payloadlength+1))) {
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
676 free(snptr);
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
677 return -ENOMEM;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
678 }
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
679
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
680 while (payloadlength - recvd) {
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
681 if (payloadlength - recvd >= 1024)
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
682 i = aim_recv(conn->fd, &msg[recvd], 1024);
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
683 else
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
684 i = aim_recv(conn->fd, &msg[recvd], payloadlength - recvd);
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
685 if (i <= 0) {
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
686 free(msg);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
687 free(snptr);
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
688 return -1;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
689 }
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
690 recvd = recvd + i;
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
691 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
692 ret = userfunc(sess, &fr, snptr, (double)recvd / payloadlength);
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
693 }
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
694
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
695 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
696 ret = userfunc(sess, &fr, snptr, msg, payloadlength, encoding, isawaymsg);
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
697
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
698 free(msg);
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
699 }
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
700
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
701 free(snptr);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4875
diff changeset
702
4870
773135edda4a [gaim-migrate @ 5200]
Mark Doliner <mark@kingant.net>
parents: 4832
diff changeset
703 return ret;
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
704 }
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
705
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
706 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
707 * 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
708 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
709 * You'll want to set up some kind of watcher on this socket.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
710 * When the state changes, call aim_handlerendconnection with
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
711 * the connection returned by this. aim_handlerendconnection
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
712 * will accept the pending connection and stop listening.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
713 *
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
714 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
715 * @param cookie This better be Mrs. Fields or I'm going to be pissed.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
716 * @param ip Should be 4 bytes, each byte is 1 quartet of the IP address.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
717 * @param port Ye olde port number to listen on.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
718 * @return Return the new conn if everything went as planned. Otherwise,
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
719 * return NULL.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
720 */
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
721 faim_export aim_conn_t *aim_sendfile_listen(aim_session_t *sess, const fu8_t *cookie, const fu8_t *ip, fu16_t port)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
722 {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
723 aim_conn_t *newconn;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
724 int listenfd;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
725
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
726 if ((listenfd = listenestablish(port)) == -1)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
727 return NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
728
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
729 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER, NULL))) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
730 close(listenfd);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
731 return NULL;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
732 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
733
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
734 newconn->fd = listenfd;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
735 newconn->subtype = AIM_CONN_SUBTYPE_OFT_SENDFILE;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
736 newconn->lastactivity = time(NULL);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
737
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
738 return newconn;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
739 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
740
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
741 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
742 * Extract an &aim_fileheader_t from the given buffer.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
743 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
744 * @param bs The should be from an incoming rendezvous packet.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
745 * @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
746 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
747 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
748 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
749 struct aim_fileheader_t *fh;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
750
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
751 if (!(fh = calloc(1, sizeof(struct aim_fileheader_t))))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
752 return NULL;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
753
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
754 /* The bstream should be positioned after the hdrtype. */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
755 aimbs_getrawbuf(bs, fh->bcookie, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
756 fh->encrypt = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
757 fh->compress = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
758 fh->totfiles = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
759 fh->filesleft = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
760 fh->totparts = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
761 fh->partsleft = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
762 fh->totsize = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
763 fh->size = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
764 fh->modtime = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
765 fh->checksum = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
766 fh->rfrcsum = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
767 fh->rfsize = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
768 fh->cretime = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
769 fh->rfcsum = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
770 fh->nrecvd = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
771 fh->recvcsum = aimbs_get32(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
772 aimbs_getrawbuf(bs, fh->idstring, 32);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
773 fh->flags = aimbs_get8(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
774 fh->lnameoffset = aimbs_get8(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
775 fh->lsizeoffset = aimbs_get8(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
776 aimbs_getrawbuf(bs, fh->dummy, 69);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
777 aimbs_getrawbuf(bs, fh->macfileinfo, 16);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
778 fh->nencode = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
779 fh->nlanguage = aimbs_get16(bs);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
780 aimbs_getrawbuf(bs, fh->name, 64); /* XXX - filenames longer than 64B */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
781
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
782 return fh;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
783 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
784
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
785 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
786 * Fills a buffer with network-order fh data
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
787 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
788 * @param bs A bstream to fill -- automatically initialized
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
789 * @param fh A struct aim_fileheader_t to get data from.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
790 * @return Return non-zero on error.
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 static int aim_oft_buildheader(aim_bstream_t *bs, struct aim_fileheader_t *fh)
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 fu8_t *hdr;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
795
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
796 if (!bs || !fh)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
797 return -EINVAL;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
798
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
799 if (!(hdr = (unsigned char *)calloc(1, 0x100 - 8)))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
800 return -ENOMEM;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3033
diff changeset
801
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
802 aim_bstream_init(bs, hdr, 0x100 - 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
803 aimbs_putraw(bs, fh->bcookie, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
804 aimbs_put16(bs, fh->encrypt);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
805 aimbs_put16(bs, fh->compress);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
806 aimbs_put16(bs, fh->totfiles);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
807 aimbs_put16(bs, fh->filesleft);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
808 aimbs_put16(bs, fh->totparts);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
809 aimbs_put16(bs, fh->partsleft);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
810 aimbs_put32(bs, fh->totsize);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
811 aimbs_put32(bs, fh->size);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
812 aimbs_put32(bs, fh->modtime);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
813 aimbs_put32(bs, fh->checksum);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
814 aimbs_put32(bs, fh->rfrcsum);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
815 aimbs_put32(bs, fh->rfsize);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
816 aimbs_put32(bs, fh->cretime);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
817 aimbs_put32(bs, fh->rfcsum);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
818 aimbs_put32(bs, fh->nrecvd);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
819 aimbs_put32(bs, fh->recvcsum);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
820 aimbs_putraw(bs, fh->idstring, 32);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
821 aimbs_put8(bs, fh->flags);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
822 aimbs_put8(bs, fh->lnameoffset);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
823 aimbs_put8(bs, fh->lsizeoffset);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
824 aimbs_putraw(bs, fh->dummy, 69);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
825 aimbs_putraw(bs, fh->macfileinfo, 16);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
826 aimbs_put16(bs, fh->nencode);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
827 aimbs_put16(bs, fh->nlanguage);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
828 aimbs_putraw(bs, fh->name, 64); /* XXX - filenames longer than 64B */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
829
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
830 return 0;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
831 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
832
4832
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
833 faim_export struct aim_oft_info *aim_oft_createnewheader(fu8_t *cookie, char *ip, fu32_t size, fu32_t modtime, char *filename)
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
834 {
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
835 struct aim_oft_info *new;
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
836
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
837 if (!(new = (struct aim_oft_info *)calloc(1, sizeof(struct aim_oft_info))))
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
838 return NULL;
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
839
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
840 if (cookie && (sizeof(cookie) == 8)) {
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
841 memcpy(new->cookie, cookie, 8);
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
842 memcpy(new->fh.bcookie, cookie, 8);
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
843 }
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
844 if (ip)
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
845 strncpy(new->ip, ip, 30);
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
846 new->fh.filesleft = 0;
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
847 new->fh.totparts = 1;
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
848 new->fh.partsleft = 1;
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
849 new->fh.totsize = size;
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
850 new->fh.size = size;
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
851 new->fh.modtime = modtime;
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
852 strcpy(new->fh.idstring, "OFT_Windows ICBMFT V1.1 32");
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
853 if (filename)
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
854 strncpy(new->fh.name, filename, 64);
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
855
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
856 return new;
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
857 }
edfe778868e2 [gaim-migrate @ 5157]
Mark Doliner <mark@kingant.net>
parents: 4826
diff changeset
858
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
859 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
860 * 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
861 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
862 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
863 * @param conn The already-connected OFT connection.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
864 * @param cookie The cookie associated with this file transfer.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
865 * @param filename The filename.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
866 * @param filesdone Number of files already transferred.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
867 * @param numfiles Total number of files.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
868 * @param size Size in bytes of this file.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
869 * @param totsize Size in bytes of all files combined.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
870 * @param checksum Funky checksum of this file.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
871 * @param flags Any flags you want, baby. Send 0x21 when sending the
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
872 * "AIM_CB_OFT_DONE" message, and "0x02" for everything else.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
873 * @return Return 0 if no errors, otherwise return the error number.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
874 */
4646
440d3d870b84 [gaim-migrate @ 4956]
Mark Doliner <mark@kingant.net>
parents: 4618
diff changeset
875 faim_export int aim_oft_sendheader(aim_session_t *sess, aim_conn_t *conn, fu16_t type, const fu8_t *cookie, const char *filename, fu16_t filesdone, fu16_t numfiles, fu32_t size, fu32_t totsize, fu32_t modtime, fu32_t checksum, fu8_t flags, fu32_t bytesreceived, fu32_t recvcsum)
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
876 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
877 aim_frame_t *newoft;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
878 struct aim_fileheader_t *fh;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
879
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
880 if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !filename)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
881 return -EINVAL;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
882
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
883 if (!(fh = (struct aim_fileheader_t *)calloc(1, sizeof(struct aim_fileheader_t))))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
884 return -ENOMEM;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
885
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 * If you are receiving a file, the cookie should be null, if you are sending a
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
888 * file, the cookie should be the same as the one used in the ICBM negotiation
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
889 * SNACs.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
890 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
891 if (cookie)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
892 memcpy(fh->bcookie, cookie, 8);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
893 fh->totfiles = numfiles;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
894 fh->filesleft = numfiles - filesdone;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
895 fh->totparts = 0x0001; /* set to 0x0002 sending Mac resource forks */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
896 fh->partsleft = 0x0001;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
897 fh->totsize = totsize;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
898 fh->size = size;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
899 fh->modtime = modtime;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
900 fh->checksum = checksum;
4646
440d3d870b84 [gaim-migrate @ 4956]
Mark Doliner <mark@kingant.net>
parents: 4618
diff changeset
901 fh->nrecvd = bytesreceived;
440d3d870b84 [gaim-migrate @ 4956]
Mark Doliner <mark@kingant.net>
parents: 4618
diff changeset
902 fh->recvcsum = recvcsum;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
903
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
904 strncpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring));
4646
440d3d870b84 [gaim-migrate @ 4956]
Mark Doliner <mark@kingant.net>
parents: 4618
diff changeset
905 fh->flags = flags;
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;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
908 memset(fh->dummy, 0, sizeof(fh->dummy));
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
909 memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
910
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
911 /* apparently 0 is ASCII, 2 is UCS-2 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
912 /* it is likely that 3 is ISO 8859-1 */
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
913 /* I think "nlanguage" might be the same thing as "subenc" in im.c */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
914 fh->nencode = 0x0000;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
915 fh->nlanguage = 0x0000;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
916
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
917 strncpy(fh->name, filename, sizeof(fh->name));
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
918 aim_oft_dirconvert_tostupid(fh->name);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
919
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
920 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, type, 0))) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
921 free(fh);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
922 return -ENOMEM;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
923 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
924
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
925 if (aim_oft_buildheader(&newoft->data, fh) == -1) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
926 aim_frame_destroy(newoft);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
927 free(fh);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
928 return -ENOMEM;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
929 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
930
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
931 memcpy(newoft->hdr.rend.magic, "OFT2", 4);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
932 newoft->hdr.rend.hdrlen = aim_bstream_curpos(&newoft->data);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
933
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
934 aim_tx_enqueue(sess, newoft);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
935
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
936 free(fh);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
937
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
938 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
939 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
940
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
941 /**
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
942 * Handle incoming data on a rendezvous connection. This is analogous to the
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
943 * consumesnac function in rxhandlers.c, and I really think this should probably
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
944 * 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
945 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
946 * @param sess The session.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
947 * @param fr The frame allocated for the incoming data.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
948 * @return Return 0 if the packet was handled correctly, otherwise return the
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
949 * error number.
3771
765769211688 [gaim-migrate @ 3910]
Rob Flynn <gaim@robflynn.com>
parents: 3752
diff changeset
950 */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
951 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
952 {
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 3771
diff changeset
953 aim_conn_t *conn = fr->conn;
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
954 int ret = 1;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
955
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
956 if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
957 if (fr->hdr.rend.type == 0x0001)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
958 ret = handlehdr_odc(sess, conn, fr, &fr->data);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
959 else
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
960 faimdprintf(sess, 0, "faim: 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
961
4826
e6654fab588b [gaim-migrate @ 5151]
Mark Doliner <mark@kingant.net>
parents: 4763
diff changeset
962 } else {
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
963 aim_rxcallback_t userfunc;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
964 struct aim_fileheader_t *header = aim_oft_getheader(&fr->data);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
965 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
966
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
967 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
968 ret = userfunc(sess, fr, conn, header->bcookie, header);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
969
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
970 free(header);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
971 }
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4002
diff changeset
972
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
973 if (ret == -1)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
974 aim_conn_close(conn);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
975
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
976 return ret;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
977 }