Mercurial > pidgin
annotate src/protocols/oscar/ft.c @ 3718:fd3880c03f0d
[gaim-migrate @ 3851]
global.mak introduced
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Wed, 16 Oct 2002 20:00:51 +0000 |
parents | 988485669631 |
children | b32474e522fa |
rev | line source |
---|---|
2086 | 1 /* |
2 * File transfer (OFT) and DirectIM (ODC). | |
3 * (OSCAR File Transfer, Oscar Direct Connect(ion?) | |
4 */ | |
5 | |
6 #define FAIM_INTERNAL | |
2931 | 7 |
2711
b7455c506979
[gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
8 #ifdef HAVE_CONFIG_H |
b7455c506979
[gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
9 #include <config.h> |
b7455c506979
[gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
10 #endif |
2086 | 11 #include <aim.h> |
12 | |
13 | |
14 #ifndef _WIN32 | |
15 #include <netdb.h> | |
16 #include <sys/socket.h> | |
17 #include <netinet/in.h> | |
18 #include <sys/utsname.h> /* for aim_directim_initiate */ | |
3630 | 19 #include <arpa/inet.h> /* for inet_ntoa */ |
3646
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
20 #endif |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
21 |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
22 #include "gaim.h" |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
23 |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
24 #ifdef _WIN32 |
3630 | 25 #include "win32dep.h" |
26 #endif | |
2086 | 27 |
28 | |
29 /* TODO: | |
30 o look for memory leaks.. there's going to be shitloads, i'm sure. | |
31 */ | |
32 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
33 struct aim_directim_intdata { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
34 fu8_t cookie[8]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
35 char sn[MAXSNLEN+1]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
36 char ip[22]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
37 }; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
38 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
39 static int listenestablish(fu16_t portnum); |
3630 | 40 static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr); |
2086 | 41 |
42 /** | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
43 * aim_handlerendconnect - call this to accept OFT connections and set up the required structures |
2086 | 44 * @sess: the session |
45 * @cur: the conn the incoming connection is on | |
46 * | |
47 * call this when you get an outstanding read on a conn with subtype | |
48 * AIM_CONN_SUBTYPE_RENDEZVOUS_OUT, it will clone the current | |
49 * &aim_conn_t and tweak things as appropriate. the new conn and the | |
50 * listener conn are both returned to the client in the | |
51 * %AIM_CB_FAM_OFT, %AIM_CB_OFT_<CLASS>INITIATE callback. | |
52 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
53 faim_export int aim_handlerendconnect(aim_session_t *sess, aim_conn_t *cur) |
2086 | 54 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
55 int acceptfd = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
56 struct sockaddr cliaddr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
57 int clilen = sizeof(cliaddr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
58 int ret = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
59 aim_conn_t *newconn; |
2086 | 60 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
61 if ((acceptfd = accept(cur->fd, &cliaddr, &clilen)) == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
62 return 0; /* not an error */ |
2086 | 63 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
64 if (cliaddr.sa_family != AF_INET) { /* just in case IPv6 really is happening */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
65 close(acceptfd); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
66 aim_conn_close(cur); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
67 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
68 } |
2086 | 69 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
70 if (!(newconn = aim_cloneconn(sess, cur))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
71 close(acceptfd); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
72 aim_conn_close(cur); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
73 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
74 } |
2086 | 75 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
76 newconn->type = AIM_CONN_TYPE_RENDEZVOUS; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
77 newconn->fd = acceptfd; |
2086 | 78 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
79 if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
80 struct aim_directim_intdata *priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
81 aim_rxcallback_t userfunc; |
2086 | 82 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
83 priv = (struct aim_directim_intdata *)(newconn->internal = cur->internal); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
84 cur->internal = NULL; |
2086 | 85 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
86 snprintf(priv->ip, sizeof(priv->ip), "%s:%u", |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
87 inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
88 ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); |
2086 | 89 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
90 if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
91 ret = userfunc(sess, NULL, newconn, cur); |
2086 | 92 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
93 } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
94 struct aim_filetransfer_priv *priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
95 aim_rxcallback_t userfunc; |
2086 | 96 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
97 newconn->priv = cur->priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
98 cur->priv = NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
99 priv = (struct aim_filetransfer_priv *)newconn->priv; |
2086 | 100 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
101 snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); |
2086 | 102 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
103 if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
104 ret = userfunc(sess, NULL, newconn, cur); |
3630 | 105 } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) { |
106 struct aim_filetransfer_priv *ft; | |
107 aim_rxcallback_t userfunc; | |
108 | |
109 /* The new conn automatically inherits the priv value | |
110 * of cur. */ | |
111 cur->priv = NULL; | |
112 ft = (struct aim_filetransfer_priv *)newconn->priv; | |
113 | |
114 snprintf(ft->ip, sizeof(ft->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); | |
115 | |
116 if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE))) | |
117 ret = userfunc(sess, NULL, newconn, cur); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
118 } else { |
2844
e63cd7fdd9eb
[gaim-migrate @ 2857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2764
diff
changeset
|
119 faimdprintf(sess, 1,"Got a Connection on a listener that's not Rendezvous Closing conn.\n"); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
120 aim_conn_close(newconn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
121 ret = -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
122 } |
2086 | 123 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
124 return ret; |
2086 | 125 } |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
126 |
2086 | 127 /** |
2993 | 128 * aim_send_typing - send client-to-client typing notification over established connection |
2086 | 129 * @sess: session to conn |
130 * @conn: directim connection | |
2993 | 131 * @typing: If true, notify user has started typing; if false, notify user has stopped. |
2086 | 132 * |
2993 | 133 * The connection must have been previously established. |
2086 | 134 */ |
2993 | 135 faim_export int aim_send_typing(aim_session_t *sess, aim_conn_t *conn, int typing) |
2086 | 136 { |
2993 | 137 |
138 struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
139 aim_frame_t *fr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
140 aim_bstream_t hdrbs; /* XXX this should be within aim_frame_t */ |
2086 | 141 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
142 if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
143 return -EINVAL; |
2086 | 144 |
2993 | 145 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, 0))) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
146 return -ENOMEM; |
2086 | 147 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
148 memcpy(fr->hdr.oft.magic, "ODC2", 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
149 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
150 fr->hdr.oft.hdr2len = 0x44; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
151 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
152 if (!(fr->hdr.oft.hdr2 = calloc(1, fr->hdr.oft.hdr2len))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
153 aim_frame_destroy(fr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
154 return -ENOMEM; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
155 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
156 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
157 aim_bstream_init(&hdrbs, fr->hdr.oft.hdr2, fr->hdr.oft.hdr2len); |
2086 | 158 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
159 aimbs_put16(&hdrbs, 0x0006); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
160 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
161 aimbs_putraw(&hdrbs, intdata->cookie, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
162 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
163 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
164 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
165 aimbs_put16(&hdrbs, 0x0000); |
2993 | 166 aimbs_put32(&hdrbs, 0x00000000); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
167 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
168 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
169 aimbs_put16(&hdrbs, 0x0000); |
2086 | 170 |
2993 | 171 /* flags -- 0x000e for "started typing", 0x0002 for "stopped typing */ |
172 aimbs_put16(&hdrbs, ( typing ? 0x000e : 0x0002)); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
173 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
174 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
175 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
176 aimbs_putraw(&hdrbs, sess->sn, strlen(sess->sn)); |
2993 | 177 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
178 aim_bstream_setpos(&hdrbs, 52); /* bleeehh */ |
2086 | 179 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
180 aimbs_put8(&hdrbs, 0x00); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
181 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
182 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
183 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
184 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
185 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
186 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
187 aimbs_put16(&hdrbs, 0x0000); |
2086 | 188 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
189 /* end of hdr2 */ |
2086 | 190 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
191 aim_tx_enqueue(sess, fr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
192 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
193 return 0; |
2086 | 194 } |
195 | |
2993 | 196 /** |
197 * aim_send_im_direct - send IM client-to-client over established connection | |
198 * @sess: session to conn | |
199 * @conn: directim connection | |
3033 | 200 * @msg: null-terminated string to send. |
201 * len: The length of the message to send, including binary data. | |
2993 | 202 * |
203 * Call this just like you would aim_send_im, to send a directim. You | |
204 * _must_ have previously established the directim connection. | |
205 */ | |
3033 | 206 faim_export int aim_send_im_direct(aim_session_t *sess, aim_conn_t *conn, const char *msg, int len) |
2993 | 207 { |
208 struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal; | |
209 aim_frame_t *fr; | |
210 aim_bstream_t hdrbs; /* XXX this should be within aim_frame_t */ | |
211 | |
212 if (!sess || !conn || !msg || (conn->type != AIM_CONN_TYPE_RENDEZVOUS)) | |
213 return -EINVAL; | |
214 | |
3033 | 215 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, len))) |
2993 | 216 return -ENOMEM; |
217 | |
218 memcpy(fr->hdr.oft.magic, "ODC2", 4); | |
219 | |
220 fr->hdr.oft.hdr2len = 0x44; | |
221 | |
222 if (!(fr->hdr.oft.hdr2 = calloc(1, fr->hdr.oft.hdr2len))) { | |
223 aim_frame_destroy(fr); | |
224 return -ENOMEM; | |
225 } | |
226 | |
227 aim_bstream_init(&hdrbs, fr->hdr.oft.hdr2, fr->hdr.oft.hdr2len); | |
228 | |
229 aimbs_put16(&hdrbs, 0x0006); | |
230 aimbs_put16(&hdrbs, 0x0000); | |
231 aimbs_putraw(&hdrbs, intdata->cookie, 8); | |
232 aimbs_put16(&hdrbs, 0x0000); | |
233 aimbs_put16(&hdrbs, 0x0000); | |
234 aimbs_put16(&hdrbs, 0x0000); | |
235 aimbs_put16(&hdrbs, 0x0000); | |
3033 | 236 aimbs_put32(&hdrbs, len); |
2993 | 237 aimbs_put16(&hdrbs, 0x0000); |
238 aimbs_put16(&hdrbs, 0x0000); | |
239 aimbs_put16(&hdrbs, 0x0000); | |
240 | |
241 /* flags -- 0x000e for "started typing", 0x0002 for "stopped typing, 0x0000 for message */ | |
242 aimbs_put16(&hdrbs, 0x0000); | |
243 | |
244 aimbs_put16(&hdrbs, 0x0000); | |
245 aimbs_put16(&hdrbs, 0x0000); | |
246 aimbs_putraw(&hdrbs, sess->sn, strlen(sess->sn)); | |
247 | |
248 aim_bstream_setpos(&hdrbs, 52); /* bleeehh */ | |
249 | |
250 aimbs_put8(&hdrbs, 0x00); | |
251 aimbs_put16(&hdrbs, 0x0000); | |
252 aimbs_put16(&hdrbs, 0x0000); | |
253 aimbs_put16(&hdrbs, 0x0000); | |
254 aimbs_put16(&hdrbs, 0x0000); | |
255 aimbs_put16(&hdrbs, 0x0000); | |
256 aimbs_put16(&hdrbs, 0x0000); | |
257 aimbs_put16(&hdrbs, 0x0000); | |
258 | |
259 /* end of hdr2 */ | |
260 | |
261 #if 0 /* XXX this is how you send buddy icon info... */ | |
262 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008); | |
263 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c); | |
264 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
265 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466); | |
266 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001); | |
267 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x2e0f); | |
268 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x393e); | |
269 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0xcac8); | |
270 #endif | |
3033 | 271 aimbs_putraw(&fr->data, msg, len); |
2993 | 272 |
273 aim_tx_enqueue(sess, fr); | |
274 | |
275 return 0; | |
276 } | |
277 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
278 static int getlocalip(fu8_t *ip) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
279 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
280 struct hostent *hptr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
281 char localhost[129]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
282 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
283 /* XXX if available, use getaddrinfo() */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
284 /* XXX allow client to specify which IP to use for multihomed boxes */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
285 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
286 if (gethostname(localhost, 128) < 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
287 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
288 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
289 if (!(hptr = gethostbyname(localhost))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
290 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
291 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
292 memcpy(ip, hptr->h_addr_list[0], 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
293 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
294 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
295 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
296 |
2086 | 297 /** |
298 * aim_directim_intitiate - For those times when we want to open up the directim channel ourselves. | |
299 * @sess: your session, | |
300 * @conn: the BOS conn, | |
301 * @priv: a dummy priv value (we'll let it get filled in later) (if you pass a %NULL, we alloc one) | |
302 * @destsn: the SN to connect to. | |
303 * | |
304 */ | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
305 faim_export aim_conn_t *aim_directim_initiate(aim_session_t *sess, const char *destsn) |
2086 | 306 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
307 aim_conn_t *newconn; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
308 aim_msgcookie_t *cookie; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
309 struct aim_directim_intdata *priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
310 int listenfd; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
311 fu16_t port = 4443; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
312 fu8_t localip[4]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
313 fu8_t ck[8]; |
2086 | 314 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
315 if (getlocalip(localip) == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
316 return NULL; |
2086 | 317 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
318 if ((listenfd = listenestablish(port)) == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
319 return NULL; |
2086 | 320 |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
321 aim_request_directim(sess, destsn, localip, port, ck); |
2086 | 322 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
323 cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
324 memcpy(cookie->cookie, ck, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
325 cookie->type = AIM_COOKIETYPE_OFTIM; |
2086 | 326 |
2247
f721ae9582d5
[gaim-migrate @ 2257]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
327 /* this one is for the cookie */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
328 priv = (struct aim_directim_intdata *)calloc(1, sizeof(struct aim_directim_intdata)); |
2086 | 329 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
330 memcpy(priv->cookie, ck, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
331 strncpy(priv->sn, destsn, sizeof(priv->sn)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
332 cookie->data = priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
333 aim_cachecookie(sess, cookie); |
2086 | 334 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
335 /* XXX switch to aim_cloneconn()? */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
336 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
337 close(listenfd); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
338 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
339 } |
2086 | 340 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
341 /* this one is for the conn */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
342 priv = (struct aim_directim_intdata *)calloc(1, sizeof(struct aim_directim_intdata)); |
2086 | 343 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
344 memcpy(priv->cookie, ck, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
345 strncpy(priv->sn, destsn, sizeof(priv->sn)); |
2086 | 346 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
347 newconn->fd = listenfd; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
348 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
349 newconn->internal = priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
350 newconn->lastactivity = time(NULL); |
2086 | 351 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
352 faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd); |
2086 | 353 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
354 return newconn; |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
355 } |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
356 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
357 /** |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
358 * aim_sendfile_intitiate - For those times when we want to send the file ourselves. |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
359 * @sess: your session, |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
360 * @conn: the BOS conn, |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
361 * @destsn: the SN to connect to. |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
362 * @filename: the name of the files you want to send |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
363 * |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
364 */ |
3630 | 365 faim_export aim_conn_t *aim_sendfile_initiate(aim_session_t *sess, const char *destsn, const char *filename, fu16_t numfiles, fu32_t totsize, char *cookret) |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
366 { |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
367 aim_conn_t *newconn; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
368 aim_msgcookie_t *cookie; |
3630 | 369 struct aim_filetransfer_priv *ft; |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
370 int listenfd; |
3630 | 371 |
372 /* Due to other limitations, we can only initiate one | |
373 * sendfile transfer at a time, so it seems safe to | |
374 * restrict the listener to a single port. -- wtm | |
375 */ | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
376 fu16_t port = 4443; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
377 fu8_t localip[4]; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
378 fu8_t ck[8]; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
379 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
380 if (getlocalip(localip) == -1) |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
381 return NULL; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
382 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
383 if ((listenfd = listenestablish(port)) == -1) |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
384 return NULL; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
385 |
3630 | 386 { |
387 /* XXX */ | |
388 char *basename = g_path_get_basename(filename); | |
389 aim_request_sendfile(sess, destsn, basename, | |
390 numfiles, totsize, localip, port, ck); | |
391 g_free(basename); | |
392 } | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
393 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
394 cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t)); |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
395 memcpy(cookie->cookie, ck, 8); |
3630 | 396 cookie->type = AIM_COOKIETYPE_OFTSEND; |
397 memcpy(cookret, ck, 8); | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
398 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
399 /* this one is for the cookie */ |
3630 | 400 ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)); |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
401 |
3630 | 402 memcpy(ft->cookie, ck, 8); |
403 strncpy(ft->sn, destsn, sizeof(ft->sn)); | |
404 cookie->data = ft; | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
405 aim_cachecookie(sess, cookie); |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
406 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
407 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL))) { |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
408 close(listenfd); |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
409 return NULL; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
410 } |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
411 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
412 /* this one is for the conn */ |
3630 | 413 ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)); |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
414 |
3630 | 415 memcpy(ft->cookie, ck, 8); |
416 strncpy(ft->sn, destsn, sizeof(ft->sn)); | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
417 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
418 newconn->fd = listenfd; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
419 newconn->subtype = AIM_CONN_SUBTYPE_OFT_SENDFILE; |
3630 | 420 newconn->priv = ft; |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
421 newconn->lastactivity = time(NULL); |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
422 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
423 faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd); |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
424 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
425 return newconn; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
426 } |
2086 | 427 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
428 #if 0 |
2086 | 429 /** |
430 * unsigned int aim_oft_listener_clean - close up old listeners | |
431 * @sess: session to clean up in | |
432 * @age: maximum age in seconds | |
433 * | |
434 * returns number closed, -1 on error. | |
435 */ | |
3630 | 436 faim_export unsigned int aim_oft_listener_clean(aim_session_t *sess, |
437 time_t age) | |
2086 | 438 { |
3630 | 439 aim_conn_t *cur; |
2086 | 440 time_t now; |
441 unsigned int hit = 0; | |
442 | |
443 if (!sess) | |
444 return -1; | |
445 now = time(NULL); | |
446 for(cur = sess->connlist;cur; cur = cur->next) | |
447 if (cur->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { | |
448 if (cur->lastactivity < (now - age) ) { | |
449 aim_conn_close(cur); | |
450 hit++; | |
3630 | 451 } |
2086 | 452 } |
453 return hit; | |
454 } | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
455 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
456 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
457 faim_export const char *aim_directim_getsn(aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
458 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
459 struct aim_directim_intdata *intdata; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
460 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
461 if (!conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
462 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
463 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
464 if ((conn->type != AIM_CONN_TYPE_RENDEZVOUS) || |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
465 (conn->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
466 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
467 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
468 if (!conn->internal) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
469 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
470 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
471 intdata = (struct aim_directim_intdata *)conn->internal; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
472 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
473 return intdata->sn; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
474 } |
2086 | 475 |
476 /** | |
477 * aim_directim_connect - connect to buddy for directim | |
478 * @sess: the session to append the conn to, | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
479 * @sn: the SN we're connecting to |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
480 * @addr: address to connect to |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
481 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
482 * This is a wrapper for aim_newconn. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
483 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
484 * 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
|
485 * allocated and setup to connect. |
2086 | 486 * |
487 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
488 faim_export aim_conn_t *aim_directim_connect(aim_session_t *sess, const char *sn, const char *addr, const fu8_t *cookie) |
2086 | 489 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
490 aim_conn_t *newconn; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
491 struct aim_directim_intdata *intdata; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
492 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
493 if (!sess || !sn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
494 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
495 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
496 if (!(intdata = malloc(sizeof(struct aim_directim_intdata)))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
497 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
498 memset(intdata, 0, sizeof(struct aim_directim_intdata)); |
2086 | 499 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
500 memcpy(intdata->cookie, cookie, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
501 strncpy(intdata->sn, sn, sizeof(intdata->sn)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
502 if (addr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
503 strncpy(intdata->ip, addr, sizeof(intdata->ip)); |
2086 | 504 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
505 /* XXX verify that non-blocking connects actually work */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
506 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, addr))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
507 free(intdata); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
508 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
509 } |
2086 | 510 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
511 if (!newconn) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
512 free(intdata); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
513 return newconn; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
514 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
515 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
516 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
517 newconn->internal = intdata; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
518 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
519 return newconn; |
2086 | 520 } |
521 | |
522 /** | |
523 * aim_directim_getconn - find a directim conn for buddy name | |
524 * @sess: your session, | |
525 * @name: the name to get, | |
526 * | |
527 * returns conn for directim with name, %NULL if none found. | |
528 * | |
529 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
530 faim_export aim_conn_t *aim_directim_getconn(aim_session_t *sess, const char *name) |
2086 | 531 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
532 aim_conn_t *cur; |
2086 | 533 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
534 if (!sess || !name || !strlen(name)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
535 return NULL; |
2086 | 536 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
537 for (cur = sess->connlist; cur; cur = cur->next) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
538 struct aim_directim_intdata *intdata; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
539 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
540 if ((cur->type != AIM_CONN_TYPE_RENDEZVOUS) || (cur->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
541 continue; |
2086 | 542 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
543 intdata = cur->internal; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
544 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
545 if (aim_sncmp(intdata->sn, name) == 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
546 break; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
547 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
548 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
549 return cur; |
2086 | 550 } |
551 | |
552 /** | |
553 * aim_accepttransfer - accept a file transfer request | |
554 * @sess: the session, | |
555 * @conn: the BOS conn for the CAP reply | |
556 * @sn: the screenname to send it to, | |
557 * @cookie: the cookie used | |
558 * @ip: the ip to connect to | |
3630 | 559 * @port: the port to use |
560 * @rendid: capability type (%AIM_CAPS_GETFILE or %AIM_CAPS_SENDFILE) | |
561 * | |
2086 | 562 * @listingfiles: number of files to share |
563 * @listingtotsize: total size of shared files | |
564 * @listingsize: length of the listing file(buffer) | |
565 * @listingchecksum: checksum of the listing | |
566 * | |
567 * Returns new connection or %NULL on error. | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
568 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
569 * XXX this should take a struct. |
2086 | 570 */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
571 faim_export aim_conn_t *aim_accepttransfer(aim_session_t *sess, |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
572 aim_conn_t *conn, |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
573 const char *sn, const fu8_t *cookie, |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
574 const fu8_t *ip, |
3630 | 575 fu16_t port, |
576 fu16_t rendid, | |
577 ...) | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
578 { |
3630 | 579 aim_frame_t *newpacket; |
580 aim_conn_t *newconn; | |
2086 | 581 struct aim_filetransfer_priv *priv; |
3630 | 582 int i; |
583 char addr[21]; | |
2086 | 584 |
585 if (!sess || !conn || !sn || !cookie || !ip) { | |
586 return NULL; | |
587 } | |
588 | |
3630 | 589 /* OSCAR CAP accept packet */ |
590 | |
591 | |
592 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0002, 10+8+2+1+strlen(sn)+4+2+8+16))) { | |
593 return NULL; | |
594 } | |
595 | |
596 aim_putsnac(&newpacket->data, 0x0004, 0x0006, 0x0000, sess->snacid_next); | |
597 | |
598 for (i = 0; i < 8; i++) | |
599 aimbs_put8(&newpacket->data, cookie[i]); | |
600 | |
601 aimbs_put16(&newpacket->data, 0x0002); | |
602 aimbs_put8(&newpacket->data, strlen(sn)); | |
603 aimbs_putraw(&newpacket->data, sn, strlen(sn)); | |
604 aimbs_put16(&newpacket->data, 0x0005); | |
605 aimbs_put16(&newpacket->data, 0x001a); | |
606 aimbs_put16(&newpacket->data, AIM_RENDEZVOUS_ACCEPT); | |
607 | |
608 for (i = 0; i < 8; i++) /* yes, again... */ | |
609 aimbs_put8(&newpacket->data, cookie[i]); | |
610 | |
611 aim_putcap(&newpacket->data, rendid); | |
612 aim_tx_enqueue(sess, newpacket); | |
613 | |
614 | |
615 g_snprintf(addr, sizeof(addr), "%s:%d", ip, port); | |
616 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, addr); | |
617 | |
618 if (newconn->status & AIM_CONN_STATUS_CONNERR) { | |
619 return NULL; | |
620 } | |
2086 | 621 |
622 if (!newconn || (newconn->fd == -1)) { | |
623 perror("aim_newconn"); | |
624 faimdprintf(sess, 2, "could not connect to %s (fd: %i)\n", ip, newconn?newconn->fd:0); | |
625 return newconn; | |
626 } | |
627 | |
3630 | 628 priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)); |
629 | |
630 memcpy(priv->cookie, cookie, 8); | |
631 priv->state = 0; | |
632 strncpy(priv->sn, sn, MAXSNLEN); | |
633 strncpy(priv->ip, ip, sizeof(priv->ip)); | |
634 newconn->priv = (void *)priv; | |
635 | |
636 faimdprintf(sess, 2, "faim: connected to peer (fd = %d)\n", newconn->fd); | |
637 | |
638 if (rendid == AIM_CAPS_GETFILE) { | |
639 return NULL; /* This should never happen for now. -- wtm */ | |
640 #if 0 | |
641 struct aim_fileheader_t *fh; | |
642 aim_frame_t *newoft; | |
643 aim_msgcookie_t *cachedcook; | |
644 /* XXX take the following parameters fu16_t listingfiles, | |
645 fu16_t listingtotsize, | |
646 fu16_t listingsize, | |
647 fu32_t listingchecksum, */ | |
648 | |
2086 | 649 newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE; |
650 | |
651 faimdprintf(sess, 2, "faim: getfile request accept\n"); | |
652 | |
653 if (!(newoft = aim_tx_new(sess, newconn, AIM_FRAMETYPE_OFT, 0x1108, 0))) { | |
654 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
655 /* XXX: conn leak here */ | |
656 return NULL; | |
657 } | |
658 | |
659 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
660 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
661 | |
662 if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) { | |
663 /* XXX: conn leak here */ | |
664 perror("calloc"); | |
665 return NULL; | |
666 } | |
667 | |
668 fh->encrypt = 0x0000; | |
669 fh->compress = 0x0000; | |
670 fh->totfiles = listingfiles; | |
671 fh->filesleft = listingfiles; /* is this right -- total parts and parts left?*/ | |
672 fh->totparts = 0x0001; | |
673 fh->partsleft = 0x0001; | |
674 fh->totsize = listingtotsize; | |
675 fh->size = listingsize; /* ls -l listing.txt */ | |
676 fh->modtime = (int)time(NULL); /* we'll go with current time for now */ | |
677 fh->checksum = listingchecksum; | |
678 fh->rfcsum = 0x00000000; | |
679 fh->rfsize = 0x00000000; | |
680 fh->cretime = 0x00000000; | |
681 fh->rfcsum = 0x00000000; | |
682 fh->nrecvd = 0x00000000; | |
683 fh->recvcsum = 0x00000000; | |
684 memset(fh->idstring, 0, sizeof(fh->idstring)); | |
3630 | 685 strncpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring)); |
2086 | 686 fh->flags = 0x02; |
687 fh->lnameoffset = 0x1a; | |
688 fh->lsizeoffset = 0x10; | |
689 memset(fh->dummy, 0, sizeof(fh->dummy)); | |
690 memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo)); | |
691 | |
692 /* we need to figure out these encodings for filenames */ | |
693 fh->nencode = 0x0000; | |
694 fh->nlanguage = 0x0000; | |
695 memset(fh->name, 0, sizeof(fh->name)); | |
3630 | 696 strncpy(fh->name, "listing.txt", sizeof(fh->name)); |
2086 | 697 |
698 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
699 aim_frame_destroy(newoft); |
2086 | 700 /* XXX: conn leak */ |
701 perror("calloc (1)"); | |
702 return NULL; | |
703 } | |
704 | |
705 memcpy(fh->bcookie, cookie, 8); | |
706 | |
707 if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, fh))) | |
708 faimdprintf(sess, 1, "eek, bh fail!\n"); | |
709 | |
710 aim_tx_enqueue(sess, newoft); | |
711 | |
3630 | 712 if (!(cachedcook = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t)))) { |
2086 | 713 faimdprintf(sess, 1, "faim: accepttransfer: couldn't calloc cachedcook. yeep!\n"); |
714 /* XXX: more cleanup, conn leak */ | |
715 perror("calloc (2)"); | |
716 return NULL; | |
717 } | |
718 | |
719 memcpy(&(priv->fh), fh, sizeof(struct aim_fileheader_t)); | |
720 memcpy(cachedcook->cookie, cookie, 8); | |
721 | |
722 cachedcook->type = AIM_COOKIETYPE_OFTGET; | |
3630 | 723 /* XXX doesn't priv need to be copied so we don't |
724 * double free? -- wtm | |
725 */ | |
2086 | 726 cachedcook->data = (void *)priv; |
727 | |
728 if (aim_cachecookie(sess, cachedcook) == -1) | |
729 faimdprintf(sess, 1, "faim: ERROR caching message cookie\n"); | |
730 | |
731 free(fh); | |
3630 | 732 #endif |
733 | |
734 } else if (rendid == AIM_CAPS_SENDFILE) { | |
735 newconn->subtype = AIM_CONN_SUBTYPE_OFT_SENDFILE; | |
736 priv->fh.recvcsum = 0xffff0000; | |
2086 | 737 } else { |
738 return NULL; | |
739 } | |
3630 | 740 |
741 return newconn; | |
742 } | |
743 | |
744 /* conn is a BOS connection over which to send the cancel msg */ | |
745 faim_export int aim_canceltransfer(aim_session_t *sess, aim_conn_t *conn, | |
746 const char *cookie, const char *sn, int rendid) | |
747 { | |
748 aim_frame_t *newpacket; | |
749 int i; | |
750 | |
751 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0002, 10+8+2+1+strlen(sn)+4+2+8+16))) { | |
752 return 1; | |
753 } | |
2086 | 754 |
3630 | 755 aim_putsnac(&newpacket->data, 0x0004, 0x0006, 0x0000, sess->snacid_next); |
2086 | 756 |
757 for (i = 0; i < 8; i++) | |
3630 | 758 aimbs_put8(&newpacket->data, cookie[i]); |
2086 | 759 |
3630 | 760 aimbs_put16(&newpacket->data, 0x0002); |
761 aimbs_put8(&newpacket->data, strlen(sn)); | |
762 aimbs_putraw(&newpacket->data, sn, strlen(sn)); | |
763 aimbs_put16(&newpacket->data, 0x0005); | |
764 aimbs_put16(&newpacket->data, 0x001a); | |
765 aimbs_put16(&newpacket->data, AIM_RENDEZVOUS_CANCEL); | |
2086 | 766 |
3630 | 767 for (i = 0; i < 8; i++) |
768 aimbs_put8(&newpacket->data, cookie[i]); | |
769 | |
770 aim_putcap(&newpacket->data, rendid); | |
2086 | 771 aim_tx_enqueue(sess, newpacket); |
772 | |
3630 | 773 return 0; |
2086 | 774 } |
775 | |
776 /** | |
777 * aim_getlisting(FILE *file) -- get an aim_fileheader_t for a given FILE* | |
778 * @file is an opened listing file | |
779 * | |
780 * returns a pointer to the filled-in fileheader_t | |
781 * | |
782 * Currently omits checksum. we'll fix this when AOL breaks us, i | |
783 * guess. | |
784 * | |
785 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
786 faim_export struct aim_fileheader_t *aim_getlisting(aim_session_t *sess, FILE *file) |
2086 | 787 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
788 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
789 #if 0 |
2086 | 790 struct aim_fileheader_t *fh; |
791 u_long totsize = 0, size = 0, checksum = 0xffff0000; | |
792 short totfiles = 0; | |
793 char *linebuf, sizebuf[9]; | |
794 | |
795 int linelength = 1024; | |
796 | |
797 /* XXX: if we have a line longer than 1024chars, God help us. */ | |
798 if ( (linebuf = (char *)calloc(1, linelength)) == NULL ) { | |
799 faimdprintf(sess, 2, "linebuf calloc failed\n"); | |
800 return NULL; | |
801 } | |
802 | |
803 if (fseek(file, 0, SEEK_END) == -1) { /* use this for sanity check */ | |
804 perror("getlisting END1 fseek:"); | |
805 faimdprintf(sess, 2, "getlising fseek END1 error\n"); | |
806 } | |
807 | |
808 if ((size = ftell(file)) == -1) { | |
809 perror("getlisting END1 getpos:"); | |
810 faimdprintf(sess, 2, "getlising getpos END1 error\n"); | |
811 } | |
812 | |
813 if (fseek(file, 0, SEEK_SET) != 0) { | |
814 perror("getlesting fseek(SET):"); | |
815 faimdprintf(sess, 2, "faim: getlisting: couldn't seek to beginning of listing file\n"); | |
816 } | |
817 | |
818 memset(linebuf, 0, linelength); | |
819 | |
820 size = 0; | |
821 | |
822 while(fgets(linebuf, linelength, file)) { | |
823 totfiles++; | |
824 memset(sizebuf, 0, 9); | |
825 | |
826 size += strlen(linebuf); | |
827 | |
828 if (strlen(linebuf) < 23) { | |
829 faimdprintf(sess, 2, "line \"%s\" too short. skipping\n", linebuf); | |
830 continue; | |
831 } | |
832 if (linebuf[strlen(linebuf)-1] != '\n') { | |
833 faimdprintf(sess, 2, "faim: OFT: getlisting -- hit EOF or line too long!\n"); | |
834 } | |
835 | |
836 memcpy(sizebuf, linebuf+17, 8); | |
837 | |
838 totsize += strtol(sizebuf, NULL, 10); | |
839 memset(linebuf, 0, linelength); | |
840 } | |
841 | |
842 if (fseek(file, 0, SEEK_SET) == -1) { | |
843 perror("getlisting END2 fseek:"); | |
844 faimdprintf(sess, 2, "getlising fseek END2 error\n"); | |
845 } | |
846 | |
847 free(linebuf); | |
848 | |
849 /* we're going to ignore checksumming the data for now -- that | |
850 * requires walking the whole listing.txt. it should probably be | |
851 * done at register time and cached, but, eh. */ | |
852 | |
853 if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) | |
854 return NULL; | |
855 | |
856 fh->encrypt = 0x0000; | |
857 fh->compress = 0x0000; | |
858 fh->totfiles = totfiles; | |
859 fh->filesleft = totfiles; /* is this right ?*/ | |
860 fh->totparts = 0x0001; | |
861 fh->partsleft = 0x0001; | |
862 fh->totsize = totsize; | |
863 fh->size = size; /* ls -l listing.txt */ | |
864 fh->modtime = (int)time(NULL); /* we'll go with current time for now */ | |
865 fh->checksum = checksum; /* XXX: checksum ! */ | |
866 fh->rfcsum = 0x00000000; | |
867 fh->rfsize = 0x00000000; | |
868 fh->cretime = 0x00000000; | |
869 fh->rfcsum = 0x00000000; | |
870 fh->nrecvd = 0x00000000; | |
871 fh->recvcsum = 0x00000000; | |
872 | |
873 /* memset(fh->idstring, 0, sizeof(fh->idstring)); */ | |
874 memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring)); | |
875 memset(fh->idstring+strlen(fh->idstring), 0, sizeof(fh->idstring)-strlen(fh->idstring)); | |
876 | |
877 fh->flags = 0x02; | |
878 fh->lnameoffset = 0x1a; | |
879 fh->lsizeoffset = 0x10; | |
880 | |
881 /* memset(fh->dummy, 0, sizeof(fh->dummy)); */ | |
882 memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo)); | |
883 | |
884 fh->nencode = 0x0000; /* we need to figure out these encodings for filenames */ | |
885 fh->nlanguage = 0x0000; | |
886 | |
887 /* memset(fh->name, 0, sizeof(fh->name)); */ | |
3630 | 888 strncpy(fh->name, "listing.txt", sizeof(fh->name)); |
2086 | 889 memset(fh->name+strlen(fh->name), 0, 64-strlen(fh->name)); |
890 | |
891 faimdprintf(sess, 2, "faim: OFT: listing fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name)))); | |
892 return fh; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
893 #endif |
2086 | 894 } |
895 | |
896 /** | |
897 * aim_listenestablish - create a listening socket on a port. | |
898 * @portnum: the port number to bind to. | |
899 * | |
900 * you need to call accept() when it's connected. returns your fd | |
901 * | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
902 * XXX: give the client author the responsibility of setting up a |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
903 * listener, then we no longer have a libfaim problem with broken |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
904 * solaris *innocent smile* -jbm |
2086 | 905 */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
906 static int listenestablish(fu16_t portnum) |
2086 | 907 { |
2711
b7455c506979
[gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
908 #if HAVE_GETADDRINFO |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
909 int listenfd; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
910 const int on = 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
911 struct addrinfo hints, *res, *ressave; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
912 char serv[5]; |
2086 | 913 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
914 snprintf(serv, sizeof(serv), "%d", portnum); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
915 memset(&hints, 0, sizeof(struct addrinfo)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
916 hints.ai_flags = AI_PASSIVE; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
917 hints.ai_family = AF_UNSPEC; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
918 hints.ai_socktype = SOCK_STREAM; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
919 if (getaddrinfo(NULL /*any IP*/, serv, &hints, &res) != 0) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
920 perror("getaddrinfo"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
921 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
922 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
923 ressave = res; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
924 do { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
925 listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
926 if (listenfd < 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
927 continue; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
928 setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
929 if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
930 break; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
931 /* success */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
932 close(listenfd); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
933 } while ( (res = res->ai_next) ); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
934 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
935 if (!res) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
936 return -1; |
2086 | 937 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
938 if (listen(listenfd, 1024)!=0) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
939 perror("listen"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
940 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
941 } |
2086 | 942 |
3630 | 943 fcntl(listenfd, F_SETFL, O_NONBLOCK); |
944 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
945 freeaddrinfo(ressave); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
946 return listenfd; |
2086 | 947 #else |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
948 int listenfd; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
949 const int on = 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
950 struct sockaddr_in sockin; |
2086 | 951 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
952 if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
953 perror("socket(listenfd)"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
954 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
955 } |
2086 | 956 |
2421
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2247
diff
changeset
|
957 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) != 0) { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
958 perror("setsockopt(listenfd)"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
959 close(listenfd); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
960 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
961 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
962 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
963 memset(&sockin, 0, sizeof(struct sockaddr_in)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
964 sockin.sin_family = AF_INET; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
965 sockin.sin_port = htons(portnum); |
2086 | 966 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
967 if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
968 perror("bind(listenfd)"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
969 close(listenfd); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
970 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
971 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
972 if (listen(listenfd, 4) != 0) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
973 perror("listen(listenfd)"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
974 close(listenfd); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
975 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
976 } |
3630 | 977 fcntl(listenfd, F_SETFL, O_NONBLOCK); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
978 return listenfd; |
2086 | 979 #endif |
980 } | |
981 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
982 static int getcommand_getfile(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
983 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
984 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
985 struct aim_filetransfer_priv *ft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
986 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
987 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
988 ft = conn->priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
989 if (ft->state == 2) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
990 /* waiting on listing data */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
991 int ret = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
992 char *listing; |
3630 | 993 aim_frame_t *newoft; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
994 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
995 if (!(listing = malloc(ft->fh.size))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
996 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
997 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
998 ft->state = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
999 if (aim_recv(conn->fd, listing, ft->fh.size) != ft->fh.size) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1000 faimdprintf(sess, 2, "OFT get: file %s was short. (0x%lx)\n", ft->fh.name, ft->fh.size); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1001 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1002 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x120b, 0))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1003 faimdprintf(sess, 2, "faim: aim_get_command_rendezvous: getfile listing: tx_new OFT failed\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1004 free(listing); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1005 aim_conn_close(conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1006 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1007 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1008 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1009 memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1010 newoft->hdr.oft.hdr2len = 0x100 - 8; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1011 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1012 /* Protocol BS - set nrecvd to size of listing, recvcsum to listing checksum, flags to 0 */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1013 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1014 ft->fh.nrecvd = ft->fh.size; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1015 ft->fh.recvcsum = ft->fh.checksum; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1016 ft->fh.flags = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1017 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1018 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1019 aim_frame_destroy(newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1020 free(listing); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1021 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1022 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1023 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1024 if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1025 faimdprintf(sess, 2, "eek! bh fail listing\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1026 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1027 /* send the 120b */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1028 aim_tx_enqueue(sess, newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1029 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTING)) ) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1030 ret = userfunc(sess, NULL, conn, ft, listing); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1031 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1032 free(listing); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1033 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1034 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1035 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1036 if (ft->state == 3) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1037 /* waiting on file data */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1038 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECEIVE)) ) |
3630 | 1039 return userfunc(sess, NULL, conn, ft->fh.name, |
1040 ft->fh.size); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1041 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1042 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1043 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1044 if (ft->state == 4) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1045 if( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILESTATE4)) ) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1046 return userfunc(sess, NULL, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1047 aim_conn_close(conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1048 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1049 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1050 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1051 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1052 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1053 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1054 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1055 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1056 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1057 static void connclose_sendfile(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1058 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1059 aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1060 struct aim_filetransfer_priv *priv = (struct aim_filetransfer_priv *)conn->priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1061 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1062 cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTSEND); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1063 aim_cookie_free(sess, cook); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1064 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1065 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1066 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1067 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1068 static void connkill_sendfile(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1069 { |
3630 | 1070 /* XXX we don't free conn->priv here because it is currently |
1071 * freed in the caller. If that ever changes, we should | |
1072 * free it here. -- wtm | |
1073 */ | |
1074 conn->priv = NULL; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1075 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1076 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1077 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1078 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1079 static void connclose_getfile(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1080 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1081 aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1082 struct aim_filetransfer_priv *priv = (struct aim_filetransfer_priv *)conn->priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1083 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1084 cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTGET); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1085 aim_cookie_free(sess, cook); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1086 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1087 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1088 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1089 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1090 static void connkill_getfile(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1091 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1092 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1093 free(conn->internal); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1094 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1095 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1096 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1097 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1098 static void connclose_directim(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1099 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1100 struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1101 aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1102 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1103 cook = aim_uncachecookie(sess, intdata->cookie, AIM_COOKIETYPE_OFTIM); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1104 aim_cookie_free(sess, cook); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1105 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1106 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1107 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1108 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1109 static void connkill_directim(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1110 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1111 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1112 free(conn->internal); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1113 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1114 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1115 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1116 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1117 faim_internal void aim_conn_close_rend(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1118 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1119 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1120 if (conn->type != AIM_CONN_TYPE_RENDEZVOUS) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1121 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1122 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1123 if (conn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1124 connclose_sendfile(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1125 else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1126 connclose_getfile(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1127 else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1128 connclose_directim(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1129 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1130 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1131 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1132 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1133 faim_internal void aim_conn_kill_rend(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1134 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1135 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1136 if (conn->type != AIM_CONN_TYPE_RENDEZVOUS) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1137 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1138 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1139 if (conn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1140 connkill_sendfile(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1141 else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1142 connkill_getfile(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1143 else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1144 connkill_directim(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1145 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1146 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1147 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1148 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1149 static int handlehdr_directim(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1150 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1151 aim_frame_t fr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1152 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1153 fu32_t payloadlength; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1154 fu16_t flags; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1155 char *snptr = NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1156 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1157 fr.conn = conn; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1158 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1159 payloadlength = aimutil_get32(hdr+22); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1160 flags = aimutil_get16(hdr+32); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1161 snptr = (char *)hdr+38; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1162 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1163 faimdprintf(sess, 2, "faim: OFT frame: handlehdr_directim: %04x / %04x / %s\n", payloadlength, flags, snptr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1164 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1165 if (flags == 0x000e) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1166 int ret = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1167 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1168 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING))) |
2993 | 1169 ret = userfunc(sess, &fr, snptr, 1); |
1170 | |
1171 return ret; | |
1172 | |
1173 } else if (flags == 0x0002) { | |
1174 int ret = 0; | |
1175 | |
1176 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING))) | |
1177 ret = userfunc(sess, &fr, snptr, 0); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1178 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1179 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1180 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1181 } else if ((flags == 0x0000) && payloadlength) { |
2993 | 1182 char *msg, *msg2; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1183 int ret = 0; |
2993 | 1184 int recvd = 0; |
1185 int i; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1186 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1187 if (!(msg = calloc(1, payloadlength+1))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1188 return -1; |
2993 | 1189 msg2 = msg; |
1190 | |
1191 while (payloadlength - recvd) { | |
1192 if (payloadlength - recvd >= 1024) | |
1193 i = aim_recv(conn->fd, msg2, 1024); | |
1194 else | |
1195 i = aim_recv(conn->fd, msg2, payloadlength - recvd); | |
3012 | 1196 if (i <= 0) { |
2993 | 1197 free(msg); |
1198 return -1; | |
1199 } | |
1200 recvd = recvd + i; | |
1201 msg2 = msg2 + i; | |
3033 | 1202 if ((userfunc=aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_IMAGETRANSFER))) |
2993 | 1203 userfunc(sess, &fr, snptr, (double)recvd / payloadlength); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1204 } |
2993 | 1205 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1206 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) ) |
2993 | 1207 ret = userfunc(sess, &fr, snptr, msg, payloadlength); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1208 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1209 free(msg); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1210 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1211 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1212 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1213 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1214 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1215 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1216 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1217 static int handlehdr_getfile_listing(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1218 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1219 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1220 struct aim_filetransfer_priv *ft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1221 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1222 struct aim_msgcookie_t *cook; |
3630 | 1223 aim_frame_t *newoft; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1224 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1225 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1226 faimdprintf(sess, 2,"faim: rend: fileget 0x1108\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1227 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1228 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1229 faim_mutex_unlock(&conn->active); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1230 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1231 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1232 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1233 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1234 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1235 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1236 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1237 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1238 /* we're waaaaiiiting.. for listing.txt */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1239 ft->state = 2; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1240 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1241 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1242 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1243 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1244 if(aim_cachecookie(sess, cook) == -1) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1245 faimdprintf(sess, 1, "error caching cookie\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1246 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1247 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1248 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1249 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x1209, 0))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1250 aim_conn_close(conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1251 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1252 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1253 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1254 memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1255 newoft->hdr.oft.hdr2len = 0x100 - 8; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1256 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1257 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1258 newoft->lock = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1259 aim_frame_destroy(newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1260 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1261 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1262 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1263 if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1264 newoft->lock = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1265 aim_frame_destroy(newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1266 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1267 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1268 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1269 newoft->lock = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1270 aim_tx_enqueue(sess, newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1271 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1272 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1273 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1274 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1275 static int handlehdr_getfile_listing2(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1276 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1277 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1278 struct aim_filetransfer_priv *ft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1279 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1280 struct aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1281 int ret = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1282 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1283 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1284 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1285 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1286 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1287 faimdprintf(sess, 2, "shit, no cookie in 0x1209. (%i/%s)going to crash..\n", AIM_COOKIETYPE_OFTGET, fh->bcookie); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1288 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1289 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1290 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1291 if (ft->fh.size != fh->size) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1292 faimdprintf(sess, 2, "hrm. ft->fh.size (%ld) != fh->size (%ld). um. using ft->fh.size\n", ft->fh.size, fh->size); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1293 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1294 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1295 ret = userfunc(sess, NULL, conn, fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1296 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1297 faimdprintf(sess, 2, "faim: get_command_rendezvous: hit end of 1209\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1298 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1299 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1300 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1301 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1302 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1303 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1304 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1305 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1306 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1307 static int handlehdr_getfile_listing3(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1308 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1309 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1310 struct aim_filetransfer_priv *ft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1311 struct aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1312 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1313 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1314 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1315 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1316 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1317 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1318 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1319 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1320 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1321 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1322 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1323 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1324 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1325 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1326 if (aim_cachecookie(sess, cook) == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1327 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1328 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1329 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGRXCONFIRM))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1330 return userfunc(sess, NULL, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1331 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1332 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1333 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1334 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1335 static int handlehdr_getfile_request(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1336 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1337 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1338 struct aim_filetransfer_priv *ft; |
3630 | 1339 aim_msgcookie_t *cook; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1340 struct aim_fileheader_t *fh; |
3630 | 1341 aim_frame_t *newoft; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1342 int i = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1343 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1344 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1345 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1346 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1347 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1348 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1349 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1350 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1351 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1352 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1353 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1354 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1355 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1356 aim_cachecookie(sess, cook); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1357 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1358 faimdprintf(sess, 2, "faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1359 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1360 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) ) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1361 i = userfunc(sess, NULL, conn, &(ft->fh), cook->cookie); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1362 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1363 if (i < 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1364 return i; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1365 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1366 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0101, 0))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1367 faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1368 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1369 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1370 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1371 memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1372 newoft->hdr.oft.hdr2len = 0x100 - 8; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1373 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1374 if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1375 aim_frame_destroy(newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1376 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1377 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1378 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1379 /* protocol BS: nrecvd, recvcsum to 0, flags to 0x20. */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1380 ft->fh.nrecvd = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1381 ft->fh.recvcsum = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1382 ft->fh.flags = 0x20; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1383 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1384 aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1385 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1386 aim_tx_enqueue(sess, newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1387 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1388 faimdprintf(sess, 2, "faim: OFT: OFT file header enqueued.\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1389 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1390 return i; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1391 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1392 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1393 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1394 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1395 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1396 static int handlehdr_getfile_sending(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1397 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1398 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1399 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1400 struct aim_filetransfer_priv *ft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1401 struct aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1402 struct command_tx_struct *newoft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1403 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1404 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1405 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1406 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1407 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1408 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1409 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1410 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1411 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1412 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1413 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1414 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1415 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1416 ft->state = 3; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1417 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1418 if (aim_cachecookie(sess, cook) == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1419 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1420 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1421 faimdprintf(sess, 2, "faim: fileget: %s seems to want to send %s\n", ft->sn, ft->fh.name); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1422 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1423 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1424 faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1425 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1426 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1427 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1428 newoft->lock = 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1429 memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1430 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1431 newoft->hdr.oft.hdr2len = 0x100 - 8; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1432 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1433 if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1434 aim_frame_destroy(newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1435 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1436 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1437 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1438 aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1439 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1440 newoft->lock = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1441 aim_tx_enqueue(sess, newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1442 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1443 faimdprintf(sess, 2, "faim: OFT: OFT 0x0202 enqueued.\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1444 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1445 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1446 return 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1447 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1448 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1449 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1450 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1451 |
3630 | 1452 static int handlehdr_sendfile_sending(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
1453 { | |
1454 struct aim_filetransfer_priv *ft; | |
1455 struct aim_fileheader_t *fh; | |
1456 aim_frame_t *newoft; | |
1457 aim_rxcallback_t userfunc; | |
1458 | |
1459 fh = aim_oft_getfh(hdr); | |
1460 | |
1461 /* We receive a null cookie for the first file; we must fill | |
1462 * it in to authenticate ourselves. -- wtm | |
1463 */ | |
1464 ft = conn->priv; | |
1465 memcpy(&(fh->bcookie), ft->cookie, 8); | |
1466 | |
1467 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); | |
1468 free(fh); | |
1469 | |
1470 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) { | |
1471 faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n"); | |
1472 return -1; | |
1473 } | |
1474 | |
1475 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
1476 | |
1477 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
1478 | |
1479 if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { | |
1480 aim_frame_destroy(newoft); | |
1481 return -1; | |
1482 } | |
1483 | |
1484 if (!aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, | |
1485 &(ft->fh))) { | |
1486 return -1; | |
1487 } | |
1488 | |
1489 aim_tx_enqueue(sess, newoft); | |
1490 | |
1491 faimdprintf(sess, 2, "faim: OFT: OFT 0x0202 enqueued.\n"); | |
1492 | |
1493 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL) | |
1494 return 1; | |
1495 | |
1496 { | |
1497 char *cur; | |
1498 /* Convert the directory separator: it is sent | |
1499 * as ^A (0x01). | |
1500 */ | |
1501 while ((cur = strchr(ft->fh.name, 0x01))) { | |
1502 *cur = G_DIR_SEPARATOR; | |
1503 } | |
1504 } | |
1505 return userfunc(sess, NULL, conn, ft->fh.name, ft->fh.size); | |
1506 } | |
1507 | |
1508 | |
1509 /* | |
1510 * These were originally described by Josh Myer: | |
1511 * http://www.geocrawler.com/archives/3/896/2000/9/0/4291064/ | |
1512 * -- wtm | |
1513 */ | |
1514 static int handlehdr_sendfile_resume(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) { | |
1515 aim_frame_t *newoft; | |
1516 aim_msgcookie_t *cook; | |
1517 struct aim_fileheader_t *fh; | |
1518 struct aim_filetransfer_priv *ft; | |
1519 | |
1520 fh = aim_oft_getfh(hdr); | |
1521 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTSEND))) { | |
1522 free(fh); | |
1523 return -1; | |
1524 } | |
1525 ft = (struct aim_filetransfer_priv *)cook->data; | |
1526 | |
1527 ft->fh.nrecvd = fh->nrecvd; | |
1528 ft->fh.recvcsum = fh->recvcsum; | |
1529 strncpy(ft->fh.name, fh->name, sizeof(ft->fh.name)); | |
1530 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0106, 0))) { | |
1531 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
1532 free(fh); | |
1533 return -1; | |
1534 } | |
1535 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
1536 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
1537 | |
1538 if (!(newoft->hdr.oft.hdr2 = (unsigned char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
1539 aim_frame_destroy(newoft); | |
1540 return -1; | |
1541 } | |
1542 | |
1543 if (!(aim_oft_buildheader(newoft->hdr.oft.hdr2, &(ft->fh)))) { | |
1544 aim_frame_destroy(newoft); | |
1545 free(fh); | |
1546 return -1; | |
1547 } | |
1548 | |
1549 aim_tx_enqueue(sess, newoft); | |
1550 free(fh); | |
1551 | |
1552 return 0; | |
1553 } | |
1554 | |
1555 static int handlehdr_sendfile_recv(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) { | |
1556 struct aim_fileheader_t *fh; | |
1557 aim_msgcookie_t *cook; | |
1558 int ret = 1; | |
1559 struct aim_filetransfer_priv *ft; | |
1560 aim_rxcallback_t userfunc; | |
1561 | |
1562 fh = aim_oft_getfh(hdr); | |
1563 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTSEND))) { | |
1564 free(fh); | |
1565 return -1; | |
1566 } | |
1567 ft = (struct aim_filetransfer_priv *)cook->data; | |
1568 | |
1569 faimdprintf(sess, 2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n"); | |
1570 | |
1571 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) ) | |
1572 ret = userfunc(sess, NULL, conn, ft->fh.nrecvd); | |
1573 | |
1574 free(fh); | |
1575 | |
1576 return ret; | |
1577 } | |
1578 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1579 static int handlehdr_getfile_recv(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1580 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1581 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1582 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1583 struct aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1584 int ret = 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1585 aim_rxcallback_t userfunc; |
3630 | 1586 struct aim_filetransfer_priv *ft; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1587 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1588 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1589 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1590 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1591 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1592 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1593 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1594 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1595 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1596 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1597 faimdprintf(sess, 2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1598 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1599 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) ) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1600 ret = userfunc(sess, NULL, conn, fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1601 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1602 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1603 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1604 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1605 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1606 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1607 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1608 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1609 |
3630 | 1610 static int handlehdr_sendfile_finish(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
1611 { | |
1612 struct aim_fileheader_t *fh; | |
1613 aim_msgcookie_t *cook; | |
1614 aim_rxcallback_t userfunc; | |
1615 | |
1616 fh = aim_oft_getfh(hdr); | |
1617 | |
1618 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTSEND))) { | |
1619 free(fh); | |
1620 return -1; | |
1621 } | |
1622 | |
1623 faimdprintf(sess, 2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n"); | |
1624 | |
1625 debug_printf("wtm: they sent csum %x\n", fh->recvcsum); | |
1626 | |
1627 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) ) | |
1628 userfunc(sess, NULL, conn, fh->bcookie); | |
1629 | |
1630 free(fh); | |
1631 return 0; | |
1632 } | |
1633 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1634 static int handlehdr_getfile_finish(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1635 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1636 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1637 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1638 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1639 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1640 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1641 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1642 faimdprintf(sess, 2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1643 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1644 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) ) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1645 userfunc(sess, NULL, conn, fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1646 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1647 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1648 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1649 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1650 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1651 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1652 |
2086 | 1653 /** |
1654 * aim_get_command_rendezvous - OFT equivalent of aim_get_command | |
1655 * @sess: session to work on | |
1656 * @conn: conn to pull data from | |
1657 * | |
1658 * this reads and handles data from conn->fd. currently a little rough | |
1659 * around the edges | |
1660 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1661 faim_internal int aim_get_command_rendezvous(aim_session_t *sess, aim_conn_t *conn) |
2086 | 1662 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1663 fu8_t hdrbuf1[6]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1664 fu8_t *hdr = NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1665 int hdrlen, hdrtype; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1666 int ret = -1; |
2086 | 1667 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1668 if (!sess || !conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1669 return -1; |
2086 | 1670 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1671 memset(hdrbuf1, 0, sizeof(hdrbuf1)); |
2086 | 1672 |
3630 | 1673 if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) { |
1674 /* This should never happen yet. -- wtm */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1675 return getcommand_getfile(sess, conn); |
3630 | 1676 } |
2086 | 1677 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1678 /* XXX fix all the error cases here */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1679 if (aim_recv(conn->fd, hdrbuf1, 6) < 6) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1680 faimdprintf(sess, 2, "faim: rend: read error (fd: %i)\n", conn->fd); |
2086 | 1681 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1682 aim_conn_close(conn); |
2086 | 1683 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1684 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1685 } |
2086 | 1686 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1687 hdrlen = aimutil_get16(hdrbuf1+4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1688 hdrlen -= 6; |
2086 | 1689 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1690 hdr = malloc(hdrlen); |
2086 | 1691 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1692 if (aim_recv(conn->fd, hdr, hdrlen) < hdrlen) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1693 faimdprintf(sess, 2, "faim: rend: read2 error on %d (%d)\n", conn->fd, hdrlen); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1694 free(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1695 aim_conn_close(conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1696 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1697 } |
2086 | 1698 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1699 hdrtype = aimutil_get16(hdr); |
2086 | 1700 |
3630 | 1701 if (conn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) { |
1702 switch(hdrtype) { | |
1703 case 0x0101: | |
1704 ret = handlehdr_sendfile_sending(sess, conn, hdr); | |
1705 break; | |
1706 case 0x0205: | |
1707 /* This seems equivalent to 0x0202, | |
1708 * but has the nrecvd and nrecvcsum | |
1709 * fields filled in. We send back a | |
1710 * 0x0106, and get then a 0x0207 which | |
1711 * we treat just like a 0x0202. -- wtm */ | |
1712 ret = handlehdr_sendfile_resume(sess, | |
1713 conn, hdr); | |
1714 break; | |
1715 case 0x0207: /* see above */; | |
1716 case 0x0202: | |
1717 ret = handlehdr_sendfile_recv(sess, conn, hdr); | |
1718 break; | |
1719 case 0x0204: | |
1720 ret = handlehdr_sendfile_finish(sess, conn, hdr); | |
1721 break; | |
1722 default: | |
1723 debug_printf("unknown header type %x received", hdrtype); | |
1724 ret = -1; | |
1725 break; | |
1726 } | |
1727 free(hdr); | |
1728 if (ret == -1) | |
1729 aim_conn_close(conn); | |
1730 return ret; | |
1731 } | |
1732 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1733 if (hdrtype == 0x0001) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1734 ret = handlehdr_directim(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1735 else if (hdrtype == 0x1108) /* getfile listing.txt incoming tx->rx */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1736 ret = handlehdr_getfile_listing(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1737 else if (hdrtype == 0x1209) /* get file listing ack rx->tx */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1738 ret = handlehdr_getfile_listing2(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1739 else if (hdrtype == 0x120b) /* get file listing rx confirm */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1740 ret = handlehdr_getfile_listing3(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1741 else if (hdrtype == 0x120c) /* getfile request */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1742 ret = handlehdr_getfile_request(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1743 else if (hdrtype == 0x0101) /* getfile sending data */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1744 ret = handlehdr_getfile_sending(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1745 else if (hdrtype == 0x0202) /* getfile recv data */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1746 ret = handlehdr_getfile_recv(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1747 else if (hdrtype == 0x0204) /* getfile finished */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1748 ret = handlehdr_getfile_finish(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1749 else { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1750 faimdprintf(sess, 2,"faim: OFT frame: uknown type %04x\n", hdrtype); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1751 ret = -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1752 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1753 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1754 free(hdr); |
2086 | 1755 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1756 if (ret == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1757 aim_conn_close(conn); |
2086 | 1758 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1759 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1760 } |
2086 | 1761 |
1762 /** | |
1763 * aim_oft_getfh - extracts an &aim_fileheader_t from buffer hdr. | |
1764 * @hdr: buffer to extract header from | |
1765 * | |
1766 * returns pointer to new struct on success; %NULL on error. | |
1767 * | |
1768 */ | |
1769 static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr) | |
1770 { | |
1771 struct aim_fileheader_t *fh; | |
1772 int i, j; | |
1773 if (!(fh = calloc(1, sizeof(struct aim_fileheader_t)))) | |
1774 return NULL; | |
1775 | |
1776 /* [0] and [1] are the type. we can ignore those here. */ | |
1777 i = 2; | |
1778 for(j = 0; j < 8; j++, i++) | |
1779 fh->bcookie[j] = hdr[i]; | |
1780 fh->encrypt = aimutil_get16(hdr+i); | |
1781 i += 2; | |
1782 fh->compress = aimutil_get16(hdr+i); | |
1783 i += 2; | |
1784 fh->totfiles = aimutil_get16(hdr+i); | |
1785 i += 2; | |
1786 fh->filesleft = aimutil_get16(hdr+i); | |
1787 i += 2; | |
1788 fh->totparts = aimutil_get16(hdr+i); | |
1789 i += 2; | |
1790 fh->partsleft = aimutil_get16(hdr+i); | |
1791 i += 2; | |
1792 fh->totsize = aimutil_get32(hdr+i); | |
1793 i += 4; | |
1794 fh->size = aimutil_get32(hdr+i); | |
1795 i += 4; | |
1796 fh->modtime = aimutil_get32(hdr+i); | |
1797 i += 4; | |
1798 fh->checksum = aimutil_get32(hdr+i); | |
1799 i += 4; | |
1800 fh->rfrcsum = aimutil_get32(hdr+i); | |
1801 i += 4; | |
1802 fh->rfsize = aimutil_get32(hdr+i); | |
1803 i += 4; | |
1804 fh->cretime = aimutil_get32(hdr+i); | |
1805 i += 4; | |
1806 fh->rfcsum = aimutil_get32(hdr+i); | |
1807 i += 4; | |
1808 fh->nrecvd = aimutil_get32(hdr+i); | |
1809 i += 4; | |
1810 fh->recvcsum = aimutil_get32(hdr+i); | |
1811 i += 4; | |
1812 memcpy(fh->idstring, hdr+i, 32); | |
1813 i += 32; | |
1814 fh->flags = aimutil_get8(hdr+i); | |
1815 i += 1; | |
1816 fh->lnameoffset = aimutil_get8(hdr+i); | |
1817 i += 1; | |
1818 fh->lsizeoffset = aimutil_get8(hdr+i); | |
1819 i += 1; | |
1820 memcpy(fh->dummy, hdr+i, 69); | |
1821 i += 69; | |
1822 memcpy(fh->macfileinfo, hdr+i, 16); | |
1823 i += 16; | |
1824 fh->nencode = aimutil_get16(hdr+i); | |
1825 i += 2; | |
1826 fh->nlanguage = aimutil_get16(hdr+i); | |
1827 i += 2; | |
1828 memcpy(fh->name, hdr+i, 64); | |
1829 i += 64; | |
1830 return fh; | |
1831 } | |
1832 | |
1833 /** | |
1834 * aim_oft_checksum - calculate oft checksum of buffer | |
1835 * @buffer: buffer of data to checksum | |
1836 * @bufsize: size of buffer | |
3630 | 1837 * @prevcheck: previous checksum |
2086 | 1838 * |
3630 | 1839 * Prevcheck should be 0xFFFF0000 for each new file; you can have this |
1840 * checksum chunks of files in series if you just call it repeatedly in a | |
1841 * for(; ; ) loop and don't reset the checksum between each call. And you | |
1842 * thought we didn't care about you and your pathetic client's meomry | |
1843 * footprint ;^) | |
2086 | 1844 * |
3630 | 1845 * Thanks to Graham Booker for providing this improved checksum |
1846 * routine, which is simpler and should be more accurate than Josh | |
1847 * Meyer's original code. -- wtm | |
2086 | 1848 * |
3630 | 1849 * This algorithim works every time I have tried it. The other fails |
1850 * sometimes. So, AOL who thought this up? It has got to be the weirdest | |
1851 * checksum I have ever seen. | |
2086 | 1852 */ |
3630 | 1853 faim_export fu32_t aim_oft_checksum(const unsigned char *buffer, int bufferlen, int prevcheck) { |
1854 fu32_t check = (prevcheck >> 16) & 0xffff, oldcheck; | |
1855 int i; | |
1856 unsigned short val; | |
1857 | |
1858 for(i=0;i<bufferlen;i++){ | |
1859 oldcheck = check; | |
1860 if(i&1){ | |
1861 val = buffer[i]; | |
1862 } else { | |
1863 val = buffer[i] << 8; | |
1864 } | |
1865 check -= val; | |
1866 /* The follownig appears to be necessary.... It happens every once in a while and the checksum doesn't fail. */ | |
1867 if(check > oldcheck) { | |
1868 check--; | |
1869 } | |
1870 } | |
1871 check = ((check & 0x0000ffff) + (check >> 16)); | |
1872 check = ((check & 0x0000ffff) + (check >> 16)); | |
1873 return check << 16; | |
1874 } | |
2086 | 1875 |
3630 | 1876 faim_export fu32_t aim_update_checksum(aim_session_t *sess, aim_conn_t *conn, |
1877 const unsigned char *buffer, int len) { | |
1878 struct aim_filetransfer_priv *ft = conn->priv; | |
2086 | 1879 |
3630 | 1880 ft->fh.nrecvd += len; |
1881 ft->fh.recvcsum = aim_oft_checksum(buffer, len, ft->fh.recvcsum); | |
2086 | 1882 |
3630 | 1883 return 0; |
1884 } | |
2086 | 1885 |
1886 /** | |
1887 * aim_oft_buildheader - fills a buffer with network-order fh data | |
1888 * @dest: buffer to fill -- pre-alloced | |
1889 * @fh: fh to get data from | |
1890 * | |
1891 * returns length written; -1 on error. | |
1892 * DOES NOT DO BOUNDS CHECKING! | |
1893 * | |
1894 */ | |
3630 | 1895 faim_export int aim_oft_buildheader(unsigned char *dest, struct aim_fileheader_t *fh) |
2086 | 1896 { |
1897 int i, curbyte; | |
1898 if (!dest || !fh) | |
1899 return -1; | |
1900 curbyte = 0; | |
1901 for(i = 0; i < 8; i++) | |
1902 curbyte += aimutil_put8(dest+curbyte, fh->bcookie[i]); | |
1903 curbyte += aimutil_put16(dest+curbyte, fh->encrypt); | |
1904 curbyte += aimutil_put16(dest+curbyte, fh->compress); | |
1905 curbyte += aimutil_put16(dest+curbyte, fh->totfiles); | |
1906 curbyte += aimutil_put16(dest+curbyte, fh->filesleft); | |
1907 curbyte += aimutil_put16(dest+curbyte, fh->totparts); | |
1908 curbyte += aimutil_put16(dest+curbyte, fh->partsleft); | |
1909 curbyte += aimutil_put32(dest+curbyte, fh->totsize); | |
1910 curbyte += aimutil_put32(dest+curbyte, fh->size); | |
1911 curbyte += aimutil_put32(dest+curbyte, fh->modtime); | |
1912 curbyte += aimutil_put32(dest+curbyte, fh->checksum); | |
1913 curbyte += aimutil_put32(dest+curbyte, fh->rfrcsum); | |
1914 curbyte += aimutil_put32(dest+curbyte, fh->rfsize); | |
1915 curbyte += aimutil_put32(dest+curbyte, fh->cretime); | |
1916 curbyte += aimutil_put32(dest+curbyte, fh->rfcsum); | |
1917 curbyte += aimutil_put32(dest+curbyte, fh->nrecvd); | |
1918 curbyte += aimutil_put32(dest+curbyte, fh->recvcsum); | |
1919 memcpy(dest+curbyte, fh->idstring, 32); | |
1920 curbyte += 32; | |
1921 curbyte += aimutil_put8(dest+curbyte, fh->flags); | |
1922 curbyte += aimutil_put8(dest+curbyte, fh->lnameoffset); | |
1923 curbyte += aimutil_put8(dest+curbyte, fh->lsizeoffset); | |
1924 memcpy(dest+curbyte, fh->dummy, 69); | |
1925 curbyte += 69; | |
1926 memcpy(dest+curbyte, fh->macfileinfo, 16); | |
1927 curbyte += 16; | |
1928 curbyte += aimutil_put16(dest+curbyte, fh->nencode); | |
1929 curbyte += aimutil_put16(dest+curbyte, fh->nlanguage); | |
1930 memset(dest+curbyte, 0x00, 64); | |
1931 memcpy(dest+curbyte, fh->name, 64); | |
1932 | |
1933 /* XXX: Filenames longer than 64B */ | |
1934 curbyte += 64; | |
1935 return curbyte; | |
1936 } | |
1937 | |
1938 /** | |
1939 * aim_getfile_intitiate - Request an OFT getfile session | |
1940 * @sess: your session, | |
1941 * @conn: the BOS conn, | |
1942 * @destsn is the SN to connect to. | |
1943 * | |
1944 * returns a new &aim_conn_t on success, %NULL on error | |
1945 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1946 faim_export aim_conn_t *aim_getfile_initiate(aim_session_t *sess, aim_conn_t *conn, const char *destsn) |
2086 | 1947 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1948 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1949 #if 0 |
2086 | 1950 struct command_tx_struct *newpacket; |
1951 struct aim_conn_t *newconn; | |
1952 struct aim_filetransfer_priv *priv; | |
1953 struct aim_msgcookie_t *cookie; | |
1954 int curbyte, i, listenfd; | |
1955 short port = 4443; | |
1956 struct hostent *hptr; | |
1957 struct utsname myname; | |
1958 char cap[16]; | |
1959 char d[4]; | |
1960 | |
1961 /* Open our socket */ | |
1962 | |
1963 if ( (listenfd = aim_listenestablish(port)) == -1) | |
1964 return NULL; | |
1965 | |
1966 /* get our local IP */ | |
1967 | |
1968 if (uname(&myname) < 0) | |
1969 return NULL; | |
1970 if ( (hptr = gethostbyname(myname.nodename)) == NULL) | |
1971 return NULL; | |
1972 memcpy(&d, hptr->h_addr_list[0], 4); | |
1973 | |
1974 aim_putcap(cap, 16, AIM_CAPS_GETFILE); | |
1975 | |
1976 /* create the OSCAR packet */ | |
1977 | |
1978 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(destsn)+4+4+0x42))) | |
1979 return NULL; | |
1980 newpacket->lock = 1; | |
1981 | |
1982 /* lock struct */ | |
1983 curbyte = 0; | |
1984 curbyte += aim_putsnac(newpacket->data+curbyte, 0x0004, 0x0006, 0x0000, sess->snac_nextid); | |
1985 | |
1986 /* XXX: check the cookie before commiting to using it */ | |
1987 | |
1988 /* Generate a random message cookie | |
1989 * This cookie needs to be alphanumeric and NULL-terminated to be TOC-compatible. */ | |
1990 for (i=0; i<7; i++) | |
1991 curbyte += aimutil_put8(newpacket->data+curbyte, 0x30 + ((u_char) random() % 10)); | |
1992 | |
1993 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
1994 | |
1995 /* grab all the data for cookie caching. */ | |
1996 | |
1997 if (!(cookie = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)))) | |
1998 return NULL; | |
1999 memcpy(cookie->cookie, newpacket->data+curbyte-8, 8); | |
2000 cookie->type = AIM_COOKIETYPE_OFTGET; | |
2001 | |
2002 if (!(priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) | |
2003 return NULL; | |
2004 memcpy(priv->cookie, cookie, 8); | |
2005 memcpy(priv->sn, destsn, sizeof(priv->sn)); | |
2006 memcpy(priv->fh.name, "listing.txt", strlen("listing.txt")); | |
2007 priv->state = 1; | |
2008 | |
2009 cookie->data = priv; | |
2010 | |
2011 aim_cachecookie(sess, cookie); | |
2012 | |
2013 /* Channel ID */ | |
2014 curbyte += aimutil_put16(newpacket->data+curbyte,0x0002); | |
2015 | |
2016 /* Destination SN (prepended with byte length) */ | |
2017 curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn)); | |
2018 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn)); | |
2019 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); | |
2020 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
2021 | |
2022 /* enTLV start */ | |
2023 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
2024 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0042); | |
2025 | |
2026 /* Flag data / ICBM Parameters? */ | |
2027 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
2028 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
2029 | |
2030 /* Cookie */ | |
2031 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cookie, 8); | |
2032 | |
2033 /* Capability String */ | |
2034 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cap, 0x10); | |
2035 | |
2036 /* 000a/0002 : 0001 */ | |
2037 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a); | |
2038 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
2039 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); | |
2040 | |
2041 /* 0003/0004: IP address */ | |
2042 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); | |
2043 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004); | |
2044 for(i = 0; i < 4; i++) | |
2045 curbyte += aimutil_put8(newpacket->data+curbyte, d[i]); | |
2046 | |
2047 /* already in network byte order */ | |
2048 | |
2049 /* 0005/0002: Port */ | |
2050 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
2051 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
2052 curbyte += aimutil_put16(newpacket->data+curbyte, port); | |
2053 | |
2054 /* 000f/0000: ?? */ | |
2055 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f); | |
2056 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
2057 | |
2058 /* 2711/000c: ?? */ | |
2059 curbyte += aimutil_put16(newpacket->data+curbyte, 0x2711); | |
2060 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000c); | |
2061 curbyte += aimutil_put32(newpacket->data+curbyte, 0x00120001); | |
2062 | |
2063 for(i = 0; i < 0x000c - 4; i++) | |
2064 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
2065 | |
2066 newpacket->commandlen = curbyte; | |
2067 newpacket->lock = 0; | |
2068 aim_tx_enqueue(sess, newpacket); | |
2069 | |
2070 /* allocate and set up our connection */ | |
2071 | |
2072 i = fcntl(listenfd, F_GETFL, 0); | |
2073 fcntl(listenfd, F_SETFL, i | O_NONBLOCK); | |
2074 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL); | |
2075 | |
2076 if (!newconn){ | |
2077 perror("aim_newconn"); | |
2078 return NULL; | |
2079 } | |
2080 | |
2081 newconn->fd = listenfd; | |
2082 newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE; | |
2083 newconn->priv = priv; | |
2084 faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd); | |
2085 | |
2086 return newconn; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2087 #endif |
2086 | 2088 } |
2089 | |
2090 /** | |
2091 * aim_oft_getfile_request - request a particular file over an established getfile connection | |
2092 * @sess: your session | |
2093 * @conn: the established OFT getfile connection | |
2094 * @name: filename to request | |
2095 * @size: size of the file | |
2096 * | |
2097 * | |
2098 * returns -1 on error, 0 on successful enqueuing | |
2099 */ | |
3630 | 2100 #if 0 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2101 faim_export int aim_oft_getfile_request(aim_session_t *sess, aim_conn_t *conn, const char *name, int size) |
2086 | 2102 { |
3630 | 2103 aim_frame_t *newoft; |
2086 | 2104 struct aim_filetransfer_priv *ft; |
2105 if (!sess || !conn || !conn->priv || !name) | |
2106 return -1; | |
2107 | |
2108 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x120c, 0))) { | |
2109 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
2110 return -1; | |
2111 } | |
2112 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
2113 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
2114 | |
2115 ft = (struct aim_filetransfer_priv *)conn->priv; | |
2116 ft->fh.filesleft = 1; | |
2117 ft->fh.totfiles = 1; | |
2118 ft->fh.totparts = 1; | |
2119 ft->fh.partsleft = 1; | |
2120 ft->fh.totsize = size; | |
2121 ft->fh.size = size; | |
2122 ft->fh.checksum = 0; | |
2123 memcpy(ft->fh.name, name, strlen(name)); | |
2124 memset(ft->fh.name+strlen(name), 0, 1); | |
2125 | |
2126 if (!(newoft->hdr.oft.hdr2 = (unsigned char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2127 aim_frame_destroy(newoft); |
2086 | 2128 return -1; |
2129 } | |
2130 | |
2131 if (!(aim_oft_buildheader(newoft->hdr.oft.hdr2, &(ft->fh)))) { | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2132 aim_frame_destroy(newoft); |
2086 | 2133 return -1; |
2134 } | |
2135 | |
3630 | 2136 aim_tx_enqueue(sess, newoft); |
2137 return 0; | |
2138 } | |
2139 #endif | |
2140 | |
2141 /* Identify a file that we are about to send by transmitting the | |
2142 * appropriate header. | |
2143 */ | |
2144 faim_export int aim_oft_sendfile_request(aim_session_t *sess, aim_conn_t *conn, const char *name, int filesdone, int numfiles, int size, int totsize) | |
2145 { | |
2146 aim_frame_t *newoft; | |
2147 aim_msgcookie_t *cook; | |
2148 struct aim_filetransfer_priv *ft = (struct aim_filetransfer_priv *)conn->priv; | |
2149 struct aim_fileheader_t *fh; | |
2150 | |
2151 if (!sess || !conn || !name) | |
2152 return -1; | |
2153 | |
2154 /* Authenticate whomever connected to our listener by checking | |
2155 * that the correct cookie was proivided. */ | |
2156 if (!(cook = aim_checkcookie(sess, ft->cookie, | |
2157 AIM_COOKIETYPE_OFTSEND))) { | |
2158 return -1; | |
2159 } | |
2160 | |
2161 if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) | |
2162 return -1; | |
2163 | |
2164 fh->encrypt = 0x0000; | |
2165 fh->compress = 0x0000; | |
2166 fh->totfiles = numfiles; | |
2167 fh->filesleft = numfiles - filesdone; | |
2168 fh->totparts = 0x0001; | |
2169 fh->partsleft = 0x0001; | |
2170 fh->totsize = totsize; | |
2171 fh->size = size; | |
2172 fh->modtime = (int)time(NULL); /* we'll go with current time for now */ | |
2173 fh->checksum = 0xffffffff; /* XXX: checksum ! */ | |
2174 fh->rfcsum = 0x00000000; | |
2175 fh->rfsize = 0x00000000; | |
2176 fh->cretime = 0x00000000; | |
2177 fh->rfcsum = 0x00000000; | |
2178 fh->nrecvd = 0x00000000; /* always zero initially */ | |
2179 fh->recvcsum = 0x00000000; /* ditto */ | |
2180 | |
2181 strncpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring)); | |
2182 fh->flags = 0x02; | |
2183 fh->lnameoffset = 0x1a; | |
2184 fh->lsizeoffset = 0x10; | |
2185 memset(fh->dummy, 0, sizeof(fh->dummy)); | |
2186 memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo)); | |
2187 | |
2188 /* we need to figure out these encodings for filenames */ | |
2189 fh->nencode = 0x0000; | |
2190 fh->nlanguage = 0x0000; | |
2191 | |
2192 { | |
2193 /* Don't "show full pathname to buddy", just because it is | |
2194 * non-portable. -- wtm | |
2195 */ | |
2196 char *basename = g_path_get_basename(name); | |
2197 strncpy(fh->name, basename, sizeof(fh->name)); | |
2198 g_free(basename); | |
2199 } | |
2200 | |
2201 memcpy(fh->bcookie, cook->cookie, 8); | |
2202 /* Update both headers to be safe. */ | |
2203 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); | |
2204 memcpy(&(((struct aim_filetransfer_priv *)cook->data)->fh), fh, | |
2205 sizeof(struct aim_fileheader_t)); | |
2206 | |
2207 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0101, 0))) { | |
2208 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
2209 free(fh); | |
2210 return -1; | |
2211 } | |
2212 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
2213 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
2214 | |
2215 if (!(newoft->hdr.oft.hdr2 = (unsigned char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
2216 aim_frame_destroy(newoft); | |
2217 free(fh); | |
2218 return -1; | |
2219 } | |
2220 | |
2221 if (!(aim_oft_buildheader(newoft->hdr.oft.hdr2, fh))) { | |
2222 aim_frame_destroy(newoft); | |
2223 free(fh); | |
2224 return -1; | |
2225 } | |
2086 | 2226 |
2227 aim_tx_enqueue(sess, newoft); | |
3630 | 2228 free(fh); |
2086 | 2229 return 0; |
2230 } | |
2231 | |
2232 /** | |
2233 * aim_oft_getfile_ack - acknowledge a getfile download as complete | |
2234 * @sess: your session | |
2235 * @conn: the getfile conn to send the ack over | |
2236 * | |
2237 * Call this function after you have read all the data in a particular | |
2238 * filetransfer. Returns -1 on error, 0 on apparent success | |
2239 * | |
2240 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2241 faim_export int aim_oft_getfile_ack(aim_session_t *sess, aim_conn_t *conn) |
2086 | 2242 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2243 return -EINVAL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2244 #if 0 |
2086 | 2245 struct command_tx_struct *newoft; |
2246 struct aim_filetransfer_priv *ft; | |
2247 | |
2248 if (!sess || !conn || !conn->priv) | |
2249 return -1; | |
2250 | |
2251 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) { | |
2252 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
2253 return -1; | |
2254 } | |
2255 | |
2256 newoft->lock = 1; | |
2257 | |
2258 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
2259 newoft->hdr.oft.hdr2len = 0x100-8; | |
2260 | |
2261 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
2262 newoft->lock = 0; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2263 aim_frame_destroy(newoft); |
2086 | 2264 return -1; |
2265 } | |
2266 | |
2267 ft = (struct aim_filetransfer_priv *)conn->priv; | |
2268 | |
2269 if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) { | |
2270 newoft->lock = 0; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2271 aim_frame_destroy(newoft); |
2086 | 2272 return -1; |
2273 } | |
2274 | |
2275 newoft->lock = 0; | |
2276 aim_tx_enqueue(sess, newoft); | |
2277 return 0; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2278 #endif |
2086 | 2279 } |
2280 | |
2281 /** | |
3630 | 2282 * aim_oft_end - end a getfile/sendfile. |
2086 | 2283 * @sess: your session |
2284 * @conn: the getfile connection | |
2285 * | |
2286 * call this before you close the getfile connection if you're on the | |
2287 * receiving/requesting end. | |
2288 */ | |
3630 | 2289 faim_export int aim_oft_end(aim_session_t *sess, aim_conn_t *conn) |
2086 | 2290 { |
3630 | 2291 aim_frame_t *newoft; |
2086 | 2292 struct aim_filetransfer_priv *ft; |
2293 | |
2294 if (!sess || !conn || !conn->priv) | |
2295 return -1; | |
2296 | |
2297 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0204, 0))) { | |
2298 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
2299 return -1; | |
2300 } | |
2301 | |
2302 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
2303 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
2304 | |
2305 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2306 aim_frame_destroy(newoft); |
2086 | 2307 return -1; |
2308 } | |
2309 | |
2310 ft = (struct aim_filetransfer_priv *)conn->priv; | |
2311 ft->state = 4; /* no longer wanting data */ | |
2312 ft->fh.flags = 0x21; | |
2313 | |
2314 if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) { | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2315 aim_frame_destroy(newoft); |
2086 | 2316 return -1; |
2317 } | |
2318 | |
2319 aim_tx_enqueue(sess, newoft); | |
2320 | |
2321 return 0; | |
2322 } | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2323 |