]>
Commit | Line | Data |
---|---|---|
37ee990e | 1 | /* |
646c6b52 | 2 | * File transfer (OFT) and DirectIM (ODC). |
3 | * (OSCAR File Transfer, Oscar Direct Connect(ion?) | |
37ee990e | 4 | */ |
5 | ||
37ee990e | 6 | #define FAIM_INTERNAL |
dd60ff8b | 7 | #include <aim.h> |
7392c79f | 8 | |
646c6b52 | 9 | |
5ac21963 | 10 | #ifndef _WIN32 |
78b3fb13 | 11 | #include <netdb.h> |
12 | #include <sys/socket.h> | |
13 | #include <netinet/in.h> | |
7392c79f | 14 | #include <sys/utsname.h> /* for aim_directim_initiate */ |
37ee990e | 15 | |
7392c79f | 16 | #include <arpa/inet.h> /* for inet_ntoa */ |
37ee990e | 17 | |
5ac21963 | 18 | #endif |
7392c79f | 19 | |
37ee990e | 20 | /* TODO: |
37ee990e | 21 | o look for memory leaks.. there's going to be shitloads, i'm sure. |
7392c79f | 22 | */ |
23 | ||
59e1da90 | 24 | struct aim_directim_intdata { |
25 | fu8_t cookie[8]; | |
26 | char sn[MAXSNLEN+1]; | |
27 | char ip[22]; | |
28 | }; | |
29 | ||
c5f5b7f1 | 30 | static int listenestablish(fu16_t portnum); |
37ee990e | 31 | static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr); |
32 | ||
33 | /** | |
59e1da90 | 34 | * aim_handlerendconnect - call this to accept OFT connections and set up the required structures |
37ee990e | 35 | * @sess: the session |
36 | * @cur: the conn the incoming connection is on | |
37 | * | |
38 | * call this when you get an outstanding read on a conn with subtype | |
646c6b52 | 39 | * AIM_CONN_SUBTYPE_RENDEZVOUS_OUT, it will clone the current |
40 | * &aim_conn_t and tweak things as appropriate. the new conn and the | |
41 | * listener conn are both returned to the client in the | |
42 | * %AIM_CB_FAM_OFT, %AIM_CB_OFT_<CLASS>INITIATE callback. | |
37ee990e | 43 | */ |
c5f5b7f1 | 44 | faim_export int aim_handlerendconnect(aim_session_t *sess, aim_conn_t *cur) |
37ee990e | 45 | { |
c5f5b7f1 | 46 | int acceptfd = 0; |
47 | struct sockaddr cliaddr; | |
48 | int clilen = sizeof(cliaddr); | |
49 | int ret = 0; | |
50 | aim_conn_t *newconn; | |
7392c79f | 51 | |
c5f5b7f1 | 52 | if ((acceptfd = accept(cur->fd, &cliaddr, &clilen)) == -1) |
53 | return 0; /* not an error */ | |
646c6b52 | 54 | |
c5f5b7f1 | 55 | if (cliaddr.sa_family != AF_INET) { /* just in case IPv6 really is happening */ |
56 | close(acceptfd); | |
57 | aim_conn_close(cur); | |
58 | return -1; | |
59 | } | |
646c6b52 | 60 | |
c5f5b7f1 | 61 | if (!(newconn = aim_cloneconn(sess, cur))) { |
62 | close(acceptfd); | |
63 | aim_conn_close(cur); | |
64 | return -1; | |
65 | } | |
37ee990e | 66 | |
c5f5b7f1 | 67 | newconn->type = AIM_CONN_TYPE_RENDEZVOUS; |
68 | newconn->fd = acceptfd; | |
7392c79f | 69 | |
c5f5b7f1 | 70 | if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { |
71 | struct aim_directim_intdata *priv; | |
72 | aim_rxcallback_t userfunc; | |
7392c79f | 73 | |
c5f5b7f1 | 74 | priv = (struct aim_directim_intdata *)(newconn->internal = cur->internal); |
75 | cur->internal = NULL; | |
646c6b52 | 76 | |
c5f5b7f1 | 77 | snprintf(priv->ip, sizeof(priv->ip), "%s:%u", |
78 | inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), | |
79 | ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); | |
646c6b52 | 80 | |
c5f5b7f1 | 81 | if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE))) |
82 | ret = userfunc(sess, NULL, newconn, cur); | |
7392c79f | 83 | |
c5f5b7f1 | 84 | } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) { |
85 | #if 0 | |
86 | struct aim_filetransfer_priv *priv; | |
87 | aim_rxcallback_t userfunc; | |
646c6b52 | 88 | |
7392c79f | 89 | |
c5f5b7f1 | 90 | newconn->priv = cur->priv; |
91 | cur->priv = NULL; | |
92 | priv = (struct aim_filetransfer_priv *)newconn->priv; | |
7392c79f | 93 | |
c5f5b7f1 | 94 | snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); |
7392c79f | 95 | |
c5f5b7f1 | 96 | if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE))) |
97 | ret = userfunc(sess, NULL, newconn, cur); | |
98 | #endif | |
99 | } else { | |
100 | faimdprintf(sess, 1,"Got a Connection on a listener that's not Rendezvous(??!) Closing conn.\n"); | |
101 | aim_conn_close(newconn); | |
102 | ret = -1; | |
103 | } | |
37ee990e | 104 | |
c5f5b7f1 | 105 | return ret; |
7392c79f | 106 | } |
d410cf58 | 107 | |
646c6b52 | 108 | /** |
37ee990e | 109 | * aim_send_im_direct - send IM client-to-client over established connection |
110 | * @sess: session to conn | |
111 | * @conn: directim connection | |
112 | * @msg: null-terminated string to send; if this is NULL, it will send a "typing" notice. | |
113 | * | |
646c6b52 | 114 | * Call this just like you would aim_send_im, to send a directim. You |
115 | * _must_ have previously established the directim connection. | |
7392c79f | 116 | */ |
d410cf58 | 117 | faim_export int aim_send_im_direct(aim_session_t *sess, aim_conn_t *conn, const char *msg) |
646c6b52 | 118 | { |
c5f5b7f1 | 119 | struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal; |
120 | aim_frame_t *fr; | |
121 | aim_bstream_t hdrbs; /* XXX this should be within aim_frame_t */ | |
122 | ||
123 | if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS)) | |
124 | return -EINVAL; | |
125 | ||
126 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, strlen(msg)))) | |
127 | return -ENOMEM; | |
128 | ||
129 | memcpy(fr->hdr.oft.magic, "ODC2", 4); | |
130 | ||
131 | fr->hdr.oft.hdr2len = 0x44; | |
132 | ||
133 | if (!(fr->hdr.oft.hdr2 = calloc(1, fr->hdr.oft.hdr2len))) { | |
134 | aim_frame_destroy(fr); | |
135 | return -ENOMEM; | |
136 | } | |
137 | ||
138 | aim_bstream_init(&hdrbs, fr->hdr.oft.hdr2, fr->hdr.oft.hdr2len); | |
139 | ||
140 | aimbs_put16(&hdrbs, 0x0006); | |
141 | aimbs_put16(&hdrbs, 0x0000); | |
142 | aimbs_putraw(&hdrbs, intdata->cookie, 8); | |
143 | aimbs_put16(&hdrbs, 0x0000); | |
144 | aimbs_put16(&hdrbs, 0x0000); | |
145 | aimbs_put16(&hdrbs, 0x0000); | |
146 | aimbs_put16(&hdrbs, 0x0000); | |
147 | aimbs_put32(&hdrbs, strlen(msg)); | |
148 | aimbs_put16(&hdrbs, 0x0000); | |
149 | aimbs_put16(&hdrbs, 0x0000); | |
150 | aimbs_put16(&hdrbs, 0x0000); | |
151 | ||
152 | /* flags -- 0x000e for "typing", 0x0000 for message */ | |
153 | aimbs_put16(&hdrbs, msg ? 0x0000 : 0x000e); | |
154 | ||
155 | aimbs_put16(&hdrbs, 0x0000); | |
156 | aimbs_put16(&hdrbs, 0x0000); | |
157 | aimbs_putraw(&hdrbs, sess->sn, strlen(sess->sn)); | |
158 | ||
159 | aim_bstream_setpos(&hdrbs, 52); /* bleeehh */ | |
160 | ||
161 | aimbs_put8(&hdrbs, 0x00); | |
162 | aimbs_put16(&hdrbs, 0x0000); | |
163 | aimbs_put16(&hdrbs, 0x0000); | |
164 | aimbs_put16(&hdrbs, 0x0000); | |
165 | aimbs_put16(&hdrbs, 0x0000); | |
166 | aimbs_put16(&hdrbs, 0x0000); | |
167 | aimbs_put16(&hdrbs, 0x0000); | |
168 | aimbs_put16(&hdrbs, 0x0000); | |
169 | ||
170 | /* end of hdr2 */ | |
171 | ||
172 | if (msg) { | |
173 | #if 0 /* XXX this is how you send buddy icon info... */ | |
174 | i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008); | |
175 | i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c); | |
176 | i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
177 | i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466); | |
178 | i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001); | |
179 | i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x2e0f); | |
180 | i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x393e); | |
181 | i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0xcac8); | |
182 | #endif | |
183 | aimbs_putraw(&fr->data, msg, strlen(msg)); | |
184 | } | |
7392c79f | 185 | |
c5f5b7f1 | 186 | aim_tx_enqueue(sess, fr); |
d410cf58 | 187 | |
c5f5b7f1 | 188 | return 0; |
37ee990e | 189 | } |
7392c79f | 190 | |
646c6b52 | 191 | /* XXX: give the client author the responsibility of setting up a |
192 | * listener, then we no longer have a libfaim problem with broken | |
193 | * solaris *innocent smile* -jbm */ | |
194 | ||
c5f5b7f1 | 195 | static int getlocalip(fu8_t *ip) |
196 | { | |
197 | struct hostent *hptr; | |
198 | char localhost[129]; | |
199 | ||
200 | /* XXX if available, use getaddrinfo() */ | |
201 | /* XXX allow client to specify which IP to use for multihomed boxes */ | |
202 | ||
203 | if (gethostname(localhost, 128) < 0) | |
204 | return -1; | |
205 | ||
206 | if (!(hptr = gethostbyname(localhost))) | |
207 | return -1; | |
208 | ||
209 | memcpy(ip, hptr->h_addr_list[0], 4); | |
210 | ||
211 | return 0; | |
212 | } | |
213 | ||
214 | /* XXX this should probably go in im.c */ | |
215 | static int aim_request_directim(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu8_t *ip, fu16_t port, fu8_t *ckret) | |
216 | { | |
217 | fu8_t ck[8]; | |
218 | aim_frame_t *fr; | |
219 | aim_snacid_t snacid; | |
220 | aim_tlvlist_t *tl = NULL, *itl = NULL; | |
221 | int hdrlen, i; | |
222 | fu8_t *hdr; | |
223 | aim_bstream_t hdrbs; | |
224 | ||
225 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 256+strlen(destsn)))) | |
226 | return -ENOMEM; | |
227 | ||
228 | snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); | |
229 | aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); | |
230 | ||
231 | /* | |
232 | * Generate a random message cookie | |
233 | * | |
234 | * This cookie needs to be alphanumeric and NULL-terminated to be | |
235 | * TOC-compatible. | |
236 | * | |
237 | * XXX have I mentioned these should be generated in msgcookie.c? | |
238 | * | |
239 | */ | |
240 | for (i = 0; i < 7; i++) | |
241 | ck[i] = 0x30 + ((fu8_t) rand() % 10); | |
242 | ck[7] = '\0'; | |
243 | ||
244 | if (ckret) | |
245 | memcpy(ckret, ck, 8); | |
246 | ||
247 | /* Cookie */ | |
248 | aimbs_putraw(&fr->data, ck, 8); | |
249 | ||
250 | /* Channel */ | |
251 | aimbs_put16(&fr->data, 0x0002); | |
252 | ||
253 | /* Destination SN */ | |
254 | aimbs_put8(&fr->data, strlen(destsn)); | |
255 | aimbs_putraw(&fr->data, destsn, strlen(destsn)); | |
256 | ||
257 | aim_addtlvtochain_noval(&tl, 0x0003); | |
258 | ||
259 | hdrlen = 2+8+16+6+8+6+4; | |
260 | hdr = malloc(hdrlen); | |
261 | aim_bstream_init(&hdrbs, hdr, hdrlen); | |
262 | ||
263 | aimbs_put16(&hdrbs, 0x0000); | |
264 | aimbs_putraw(&hdrbs, ck, 8); | |
265 | aim_putcap(&hdrbs, AIM_CAPS_IMIMAGE); | |
266 | ||
267 | aim_addtlvtochain16(&itl, 0x000a, 0x0001); | |
268 | aim_addtlvtochain_raw(&itl, 0x0003, 4, ip); | |
269 | aim_addtlvtochain16(&itl, 0x0005, port); | |
270 | aim_addtlvtochain_noval(&itl, 0x000f); | |
271 | ||
272 | aim_writetlvchain(&hdrbs, &itl); | |
273 | ||
274 | aim_addtlvtochain_raw(&tl, 0x0005, aim_bstream_curpos(&hdrbs), hdr); | |
275 | ||
276 | aim_writetlvchain(&fr->data, &tl); | |
277 | ||
278 | free(hdr); | |
279 | aim_freetlvchain(&itl); | |
280 | aim_freetlvchain(&tl); | |
281 | ||
282 | aim_tx_enqueue(sess, fr); | |
283 | ||
284 | return 0; | |
285 | } | |
286 | ||
646c6b52 | 287 | /** |
37ee990e | 288 | * aim_directim_intitiate - For those times when we want to open up the directim channel ourselves. |
289 | * @sess: your session, | |
290 | * @conn: the BOS conn, | |
646c6b52 | 291 | * @priv: a dummy priv value (we'll let it get filled in later) (if you pass a %NULL, we alloc one) |
37ee990e | 292 | * @destsn: the SN to connect to. |
293 | * | |
7392c79f | 294 | */ |
c5f5b7f1 | 295 | faim_export aim_conn_t *aim_directim_initiate(aim_session_t *sess, aim_conn_t *conn, const char *destsn) |
37ee990e | 296 | { |
c5f5b7f1 | 297 | aim_conn_t *newconn; |
298 | aim_msgcookie_t *cookie; | |
299 | struct aim_directim_intdata *priv; | |
300 | int listenfd; | |
301 | fu16_t port = 4443; | |
302 | fu8_t localip[4]; | |
303 | fu8_t ck[8]; | |
37ee990e | 304 | |
c5f5b7f1 | 305 | if (getlocalip(localip) == -1) |
306 | return NULL; | |
7392c79f | 307 | |
c5f5b7f1 | 308 | if ((listenfd = listenestablish(port)) == -1) |
309 | return NULL; | |
37ee990e | 310 | |
c5f5b7f1 | 311 | aim_request_directim(sess, conn, destsn, localip, port, ck); |
7392c79f | 312 | |
c5f5b7f1 | 313 | cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t)); |
314 | memcpy(cookie->cookie, ck, 8); | |
315 | cookie->type = AIM_COOKIETYPE_OFTIM; | |
7392c79f | 316 | |
c5f5b7f1 | 317 | priv = (struct aim_directim_intdata *)calloc(1, sizeof(struct aim_directim_intdata)); |
7392c79f | 318 | |
c5f5b7f1 | 319 | memcpy(priv->cookie, ck, 8); |
320 | memcpy(priv->sn, destsn, sizeof(priv->sn)); | |
321 | cookie->data = priv; | |
322 | aim_cachecookie(sess, cookie); | |
7392c79f | 323 | |
c5f5b7f1 | 324 | /* XXX switch to aim_cloneconn()? */ |
325 | if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL))) { | |
326 | close(listenfd); | |
327 | return NULL; | |
328 | } | |
7392c79f | 329 | |
c5f5b7f1 | 330 | /* this one is for the conn */ |
331 | priv = (struct aim_directim_intdata *)calloc(1, sizeof(struct aim_directim_intdata)); | |
7392c79f | 332 | |
c5f5b7f1 | 333 | memcpy(priv->cookie, ck, 8); |
334 | memcpy(priv->sn, destsn, sizeof(priv->sn)); | |
7392c79f | 335 | |
c5f5b7f1 | 336 | newconn->fd = listenfd; |
337 | newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; | |
338 | newconn->internal = priv; | |
339 | newconn->lastactivity = time(NULL); | |
7392c79f | 340 | |
c5f5b7f1 | 341 | faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd); |
7392c79f | 342 | |
c5f5b7f1 | 343 | return newconn; |
7392c79f | 344 | } |
345 | ||
d410cf58 | 346 | #if 0 |
646c6b52 | 347 | /** |
348 | * unsigned int aim_oft_listener_clean - close up old listeners | |
37ee990e | 349 | * @sess: session to clean up in |
350 | * @age: maximum age in seconds | |
351 | * | |
352 | * returns number closed, -1 on error. | |
871e2fd0 | 353 | */ |
37ee990e | 354 | faim_export unsigned int aim_oft_listener_clean(struct aim_session_t *sess, time_t age) |
355 | { | |
356 | struct aim_conn_t *cur; | |
357 | time_t now; | |
358 | unsigned int hit = 0; | |
359 | ||
646c6b52 | 360 | if (!sess) |
37ee990e | 361 | return -1; |
362 | now = time(NULL); | |
363 | faim_mutex_lock(&sess->connlistlock); | |
364 | for(cur = sess->connlist;cur; cur = cur->next) | |
646c6b52 | 365 | if (cur->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { |
37ee990e | 366 | faim_mutex_lock(&cur->active); |
367 | if (cur->lastactivity < (now - age) ) { | |
368 | faim_mutex_unlock(&cur->active); | |
369 | aim_conn_close(cur); | |
370 | hit++; | |
371 | } else | |
372 | faim_mutex_unlock(&cur->active); | |
373 | } | |
374 | faim_mutex_unlock(&sess->connlistlock); | |
375 | return hit; | |
376 | } | |
d410cf58 | 377 | #endif |
871e2fd0 | 378 | |
c5f5b7f1 | 379 | faim_export const char *aim_directim_getsn(aim_conn_t *conn) |
380 | { | |
381 | struct aim_directim_intdata *intdata; | |
382 | ||
383 | if (!conn) | |
384 | return NULL; | |
385 | ||
386 | if ((conn->type != AIM_CONN_TYPE_RENDEZVOUS) || | |
387 | (conn->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM)) | |
388 | return NULL; | |
389 | ||
390 | if (!conn->internal) | |
391 | return NULL; | |
392 | ||
393 | intdata = (struct aim_directim_intdata *)conn->internal; | |
394 | ||
395 | return intdata->sn; | |
396 | } | |
397 | ||
646c6b52 | 398 | /** |
37ee990e | 399 | * aim_directim_connect - connect to buddy for directim |
400 | * @sess: the session to append the conn to, | |
c5f5b7f1 | 401 | * @sn: the SN we're connecting to |
402 | * @addr: address to connect to | |
403 | * | |
404 | * This is a wrapper for aim_newconn. | |
405 | * | |
406 | * If addr is NULL, the socket is not created, but the connection is | |
407 | * allocated and setup to connect. | |
37ee990e | 408 | * |
37ee990e | 409 | */ |
c5f5b7f1 | 410 | faim_export aim_conn_t *aim_directim_connect(aim_session_t *sess, const char *sn, const char *addr, const fu8_t *cookie) |
37ee990e | 411 | { |
c5f5b7f1 | 412 | aim_conn_t *newconn; |
413 | struct aim_directim_intdata *intdata; | |
7392c79f | 414 | |
c5f5b7f1 | 415 | if (!sess || !sn) |
416 | return NULL; | |
37ee990e | 417 | |
c5f5b7f1 | 418 | if (!(intdata = malloc(sizeof(struct aim_directim_intdata)))) |
419 | return NULL; | |
420 | memset(intdata, 0, sizeof(struct aim_directim_intdata)); | |
37ee990e | 421 | |
c5f5b7f1 | 422 | memcpy(intdata->cookie, cookie, 8); |
423 | strncpy(intdata->sn, sn, sizeof(intdata->sn)); | |
424 | strncpy(intdata->ip, addr, sizeof(intdata->ip)); | |
425 | ||
426 | /* XXX verify that non-blocking connects actually work */ | |
427 | if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, addr))) { | |
428 | free(intdata); | |
429 | return NULL; | |
430 | } | |
431 | ||
432 | if (!newconn || (newconn->fd == -1)) { | |
433 | free(intdata); | |
434 | return newconn; | |
435 | } | |
436 | ||
437 | newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; | |
438 | newconn->internal = intdata; | |
439 | ||
440 | return newconn; | |
37ee990e | 441 | } |
7392c79f | 442 | |
646c6b52 | 443 | /** |
37ee990e | 444 | * aim_directim_getconn - find a directim conn for buddy name |
445 | * @sess: your session, | |
446 | * @name: the name to get, | |
447 | * | |
448 | * returns conn for directim with name, %NULL if none found. | |
449 | * | |
871e2fd0 | 450 | */ |
c5f5b7f1 | 451 | faim_export aim_conn_t *aim_directim_getconn(aim_session_t *sess, const char *name) |
871e2fd0 | 452 | { |
c5f5b7f1 | 453 | aim_conn_t *cur; |
37ee990e | 454 | |
c5f5b7f1 | 455 | if (!sess || !name || !strlen(name)) |
456 | return NULL; | |
37ee990e | 457 | |
c5f5b7f1 | 458 | for (cur = sess->connlist; cur; cur = cur->next) { |
459 | struct aim_directim_intdata *intdata; | |
460 | ||
461 | if ((cur->type != AIM_CONN_TYPE_RENDEZVOUS) || (cur->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM)) | |
462 | continue; | |
37ee990e | 463 | |
c5f5b7f1 | 464 | intdata = cur->internal; |
465 | ||
466 | if (aim_sncmp(intdata->sn, name) == 0) | |
467 | break; | |
468 | } | |
469 | ||
470 | return cur; | |
37ee990e | 471 | } |
871e2fd0 | 472 | |
646c6b52 | 473 | /** |
37ee990e | 474 | * aim_accepttransfer - accept a file transfer request |
475 | * @sess: the session, | |
476 | * @conn: the BOS conn for the CAP reply | |
477 | * @sn: the screenname to send it to, | |
478 | * @cookie: the cookie used | |
479 | * @ip: the ip to connect to | |
480 | * @listingfiles: number of files to share | |
481 | * @listingtotsize: total size of shared files | |
482 | * @listingsize: length of the listing file(buffer) | |
483 | * @listingchecksum: checksum of the listing | |
484 | * @rendid: capability type (%AIM_CAPS_GETFILE or %AIM_CAPS_SENDFILE) | |
871e2fd0 | 485 | * |
646c6b52 | 486 | * Returns new connection or %NULL on error. |
d410cf58 | 487 | * |
488 | * XXX this should take a struct. | |
871e2fd0 | 489 | */ |
d410cf58 | 490 | faim_export aim_conn_t *aim_accepttransfer(aim_session_t *sess, |
491 | aim_conn_t *conn, | |
492 | const char *sn, const fu8_t *cookie, | |
493 | const fu8_t *ip, | |
494 | fu16_t listingfiles, | |
495 | fu16_t listingtotsize, | |
496 | fu16_t listingsize, | |
497 | fu32_t listingchecksum, | |
498 | fu16_t rendid) | |
499 | { | |
500 | return NULL; | |
501 | #if 0 | |
7392c79f | 502 | struct command_tx_struct *newpacket, *newoft; |
871e2fd0 | 503 | struct aim_conn_t *newconn; |
37ee990e | 504 | struct aim_fileheader_t *fh; |
871e2fd0 | 505 | struct aim_filetransfer_priv *priv; |
506 | struct aim_msgcookie_t *cachedcook; | |
7392c79f | 507 | int curbyte, i; |
7392c79f | 508 | |
646c6b52 | 509 | if (!sess || !conn || !sn || !cookie || !ip) { |
37ee990e | 510 | return NULL; |
646c6b52 | 511 | } |
871e2fd0 | 512 | |
646c6b52 | 513 | newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip); |
37ee990e | 514 | |
646c6b52 | 515 | if (!newconn || (newconn->fd == -1)) { |
516 | perror("aim_newconn"); | |
517 | faimdprintf(sess, 2, "could not connect to %s (fd: %i)\n", ip, newconn?newconn->fd:0); | |
518 | return newconn; | |
519 | } else { | |
520 | priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)); | |
521 | ||
522 | memcpy(priv->cookie, cookie, 8); | |
523 | priv->state = 0; | |
524 | strncpy(priv->sn, sn, MAXSNLEN); | |
525 | strncpy(priv->ip, ip, sizeof(priv->ip)); | |
526 | newconn->priv = (void *)priv; | |
527 | ||
528 | faimdprintf(sess, 2, "faim: connected to peer (fd = %d)\n", newconn->fd); | |
529 | } | |
530 | ||
531 | if (rendid == AIM_CAPS_GETFILE) { | |
532 | newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE; | |
7392c79f | 533 | |
646c6b52 | 534 | faimdprintf(sess, 2, "faim: getfile request accept\n"); |
37ee990e | 535 | |
646c6b52 | 536 | if (!(newoft = aim_tx_new(sess, newconn, AIM_FRAMETYPE_OFT, 0x1108, 0))) { |
537 | faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
538 | /* XXX: conn leak here */ | |
871e2fd0 | 539 | return NULL; |
37ee990e | 540 | } |
541 | ||
871e2fd0 | 542 | newoft->lock = 1; |
871e2fd0 | 543 | memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
37ee990e | 544 | newoft->hdr.oft.hdr2len = 0x100 - 8; |
7392c79f | 545 | |
646c6b52 | 546 | if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) { |
547 | /* XXX: conn leak here */ | |
548 | perror("calloc"); | |
871e2fd0 | 549 | return NULL; |
646c6b52 | 550 | } |
7392c79f | 551 | |
37ee990e | 552 | fh->encrypt = 0x0000; |
553 | fh->compress = 0x0000; | |
554 | fh->totfiles = listingfiles; | |
555 | fh->filesleft = listingfiles; /* is this right -- total parts and parts left?*/ | |
556 | fh->totparts = 0x0001; | |
557 | fh->partsleft = 0x0001; | |
558 | fh->totsize = listingtotsize; | |
559 | fh->size = listingsize; /* ls -l listing.txt */ | |
560 | fh->modtime = (int)time(NULL); /* we'll go with current time for now */ | |
561 | fh->checksum = listingchecksum; | |
562 | fh->rfcsum = 0x00000000; | |
563 | fh->rfsize = 0x00000000; | |
564 | fh->cretime = 0x00000000; | |
565 | fh->rfcsum = 0x00000000; | |
566 | fh->nrecvd = 0x00000000; | |
567 | fh->recvcsum = 0x00000000; | |
568 | memset(fh->idstring, 0, sizeof(fh->idstring)); | |
569 | memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring)); | |
570 | fh->flags = 0x02; | |
571 | fh->lnameoffset = 0x1a; | |
572 | fh->lsizeoffset = 0x10; | |
573 | memset(fh->dummy, 0, sizeof(fh->dummy)); | |
574 | memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo)); | |
575 | ||
576 | /* we need to figure out these encodings for filenames */ | |
577 | fh->nencode = 0x0000; | |
578 | fh->nlanguage = 0x0000; | |
579 | memset(fh->name, 0, sizeof(fh->name)); | |
580 | memcpy(fh->name, "listing.txt", sizeof(fh->name)); | |
581 | ||
582 | if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
583 | newoft->lock = 0; | |
d410cf58 | 584 | aim_frame_destroy(newoft); |
646c6b52 | 585 | /* XXX: conn leak */ |
586 | perror("calloc (1)"); | |
37ee990e | 587 | return NULL; |
588 | } | |
7392c79f | 589 | |
37ee990e | 590 | memcpy(fh->bcookie, cookie, 8); |
7392c79f | 591 | |
646c6b52 | 592 | if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, fh))) |
593 | faimdprintf(sess, 1, "eek, bh fail!\n"); | |
871e2fd0 | 594 | |
595 | newoft->lock = 0; | |
596 | aim_tx_enqueue(sess, newoft); | |
37ee990e | 597 | |
646c6b52 | 598 | if (!(cachedcook = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)))) { |
599 | faimdprintf(sess, 1, "faim: accepttransfer: couldn't calloc cachedcook. yeep!\n"); | |
600 | /* XXX: more cleanup, conn leak */ | |
601 | perror("calloc (2)"); | |
37ee990e | 602 | return NULL; |
603 | } | |
7392c79f | 604 | |
37ee990e | 605 | memcpy(&(priv->fh), fh, sizeof(struct aim_fileheader_t)); |
606 | memcpy(cachedcook->cookie, cookie, 8); | |
607 | ||
608 | cachedcook->type = AIM_COOKIETYPE_OFTGET; | |
609 | cachedcook->data = (void *)priv; | |
7392c79f | 610 | |
646c6b52 | 611 | if (aim_cachecookie(sess, cachedcook) == -1) |
612 | faimdprintf(sess, 1, "faim: ERROR caching message cookie\n"); | |
37ee990e | 613 | |
646c6b52 | 614 | free(fh); |
37ee990e | 615 | |
646c6b52 | 616 | /* OSCAR CAP accept packet */ |
617 | ||
618 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(sn)+4+2+8+16))) { | |
619 | return NULL; | |
620 | } | |
621 | } else { | |
622 | return NULL; | |
623 | } | |
624 | ||
625 | newpacket->lock = 1; | |
626 | curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid); | |
37ee990e | 627 | |
646c6b52 | 628 | for (i = 0; i < 8; i++) |
629 | curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]); | |
37ee990e | 630 | |
646c6b52 | 631 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); |
632 | curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sn)); | |
633 | curbyte += aimutil_putstr(newpacket->data+curbyte, sn, strlen(sn)); | |
634 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
635 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x001a); | |
636 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002 /* accept*/); | |
37ee990e | 637 | |
646c6b52 | 638 | for (i = 0;i < 8; i++) |
639 | curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]); | |
871e2fd0 | 640 | |
646c6b52 | 641 | curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid); |
642 | newpacket->lock = 0; | |
643 | aim_tx_enqueue(sess, newpacket); | |
7392c79f | 644 | |
646c6b52 | 645 | return newconn; |
d410cf58 | 646 | #endif |
7392c79f | 647 | } |
648 | ||
646c6b52 | 649 | /** |
37ee990e | 650 | * aim_getlisting(FILE *file) -- get an aim_fileheader_t for a given FILE* |
651 | * @file is an opened listing file | |
7392c79f | 652 | * |
871e2fd0 | 653 | * returns a pointer to the filled-in fileheader_t |
654 | * | |
646c6b52 | 655 | * Currently omits checksum. we'll fix this when AOL breaks us, i |
871e2fd0 | 656 | * guess. |
657 | * | |
7392c79f | 658 | */ |
d410cf58 | 659 | faim_export struct aim_fileheader_t *aim_getlisting(aim_session_t *sess, FILE *file) |
7392c79f | 660 | { |
d410cf58 | 661 | return NULL; |
662 | #if 0 | |
7392c79f | 663 | struct aim_fileheader_t *fh; |
871e2fd0 | 664 | u_long totsize = 0, size = 0, checksum = 0xffff0000; |
665 | short totfiles = 0; | |
666 | char *linebuf, sizebuf[9]; | |
667 | ||
668 | int linelength = 1024; | |
669 | ||
670 | /* XXX: if we have a line longer than 1024chars, God help us. */ | |
646c6b52 | 671 | if ( (linebuf = (char *)calloc(1, linelength)) == NULL ) { |
672 | faimdprintf(sess, 2, "linebuf calloc failed\n"); | |
871e2fd0 | 673 | return NULL; |
674 | } | |
675 | ||
646c6b52 | 676 | if (fseek(file, 0, SEEK_END) == -1) { /* use this for sanity check */ |
871e2fd0 | 677 | perror("getlisting END1 fseek:"); |
646c6b52 | 678 | faimdprintf(sess, 2, "getlising fseek END1 error\n"); |
871e2fd0 | 679 | } |
680 | ||
646c6b52 | 681 | if ((size = ftell(file)) == -1) { |
871e2fd0 | 682 | perror("getlisting END1 getpos:"); |
646c6b52 | 683 | faimdprintf(sess, 2, "getlising getpos END1 error\n"); |
871e2fd0 | 684 | } |
685 | ||
646c6b52 | 686 | if (fseek(file, 0, SEEK_SET) != 0) { |
871e2fd0 | 687 | perror("getlesting fseek(SET):"); |
646c6b52 | 688 | faimdprintf(sess, 2, "faim: getlisting: couldn't seek to beginning of listing file\n"); |
871e2fd0 | 689 | } |
690 | ||
37ee990e | 691 | memset(linebuf, 0, linelength); |
871e2fd0 | 692 | |
693 | size = 0; | |
694 | ||
695 | while(fgets(linebuf, linelength, file)) { | |
696 | totfiles++; | |
37ee990e | 697 | memset(sizebuf, 0, 9); |
871e2fd0 | 698 | |
699 | size += strlen(linebuf); | |
700 | ||
646c6b52 | 701 | if (strlen(linebuf) < 23) { |
702 | faimdprintf(sess, 2, "line \"%s\" too short. skipping\n", linebuf); | |
871e2fd0 | 703 | continue; |
704 | } | |
646c6b52 | 705 | if (linebuf[strlen(linebuf)-1] != '\n') { |
706 | faimdprintf(sess, 2, "faim: OFT: getlisting -- hit EOF or line too long!\n"); | |
871e2fd0 | 707 | } |
708 | ||
709 | memcpy(sizebuf, linebuf+17, 8); | |
710 | ||
711 | totsize += strtol(sizebuf, NULL, 10); | |
37ee990e | 712 | memset(linebuf, 0, linelength); |
871e2fd0 | 713 | } |
714 | ||
646c6b52 | 715 | if (fseek(file, 0, SEEK_SET) == -1) { |
871e2fd0 | 716 | perror("getlisting END2 fseek:"); |
646c6b52 | 717 | faimdprintf(sess, 2, "getlising fseek END2 error\n"); |
871e2fd0 | 718 | } |
719 | ||
720 | free(linebuf); | |
721 | ||
722 | /* we're going to ignore checksumming the data for now -- that | |
723 | * requires walking the whole listing.txt. it should probably be | |
724 | * done at register time and cached, but, eh. */ | |
7392c79f | 725 | |
646c6b52 | 726 | if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) |
7392c79f | 727 | return NULL; |
728 | ||
729 | fh->encrypt = 0x0000; | |
871e2fd0 | 730 | fh->compress = 0x0000; |
731 | fh->totfiles = totfiles; | |
732 | fh->filesleft = totfiles; /* is this right ?*/ | |
7392c79f | 733 | fh->totparts = 0x0001; |
734 | fh->partsleft = 0x0001; | |
871e2fd0 | 735 | fh->totsize = totsize; |
736 | fh->size = size; /* ls -l listing.txt */ | |
737 | fh->modtime = (int)time(NULL); /* we'll go with current time for now */ | |
738 | fh->checksum = checksum; /* XXX: checksum ! */ | |
7392c79f | 739 | fh->rfcsum = 0x00000000; |
740 | fh->rfsize = 0x00000000; | |
741 | fh->cretime = 0x00000000; | |
742 | fh->rfcsum = 0x00000000; | |
743 | fh->nrecvd = 0x00000000; | |
744 | fh->recvcsum = 0x00000000; | |
745 | ||
871e2fd0 | 746 | /* memset(fh->idstring, 0, sizeof(fh->idstring)); */ |
747 | memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring)); | |
748 | memset(fh->idstring+strlen(fh->idstring), 0, sizeof(fh->idstring)-strlen(fh->idstring)); | |
7392c79f | 749 | |
750 | fh->flags = 0x02; | |
751 | fh->lnameoffset = 0x1a; | |
752 | fh->lsizeoffset = 0x10; | |
753 | ||
871e2fd0 | 754 | /* memset(fh->dummy, 0, sizeof(fh->dummy)); */ |
755 | memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo)); | |
7392c79f | 756 | |
871e2fd0 | 757 | fh->nencode = 0x0000; /* we need to figure out these encodings for filenames */ |
7392c79f | 758 | fh->nlanguage = 0x0000; |
759 | ||
871e2fd0 | 760 | /* memset(fh->name, 0, sizeof(fh->name)); */ |
761 | memcpy(fh->name, "listing.txt", sizeof(fh->name)); | |
762 | memset(fh->name+strlen(fh->name), 0, 64-strlen(fh->name)); | |
7392c79f | 763 | |
646c6b52 | 764 | faimdprintf(sess, 2, "faim: OFT: listing fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name)))); |
7392c79f | 765 | return fh; |
d410cf58 | 766 | #endif |
7392c79f | 767 | } |
768 | ||
646c6b52 | 769 | /** |
37ee990e | 770 | * aim_listenestablish - create a listening socket on a port. |
771 | * @portnum: the port number to bind to. | |
772 | * | |
773 | * you need to call accept() when it's connected. returns your fd | |
774 | * | |
7392c79f | 775 | */ |
c5f5b7f1 | 776 | static int listenestablish(fu16_t portnum) |
7392c79f | 777 | { |
37ee990e | 778 | #if defined(__linux__) |
c5f5b7f1 | 779 | /* XXX what other OS's support getaddrinfo? */ |
780 | int listenfd; | |
781 | const int on = 1; | |
782 | struct addrinfo hints, *res, *ressave; | |
783 | char serv[5]; | |
784 | ||
785 | snprintf(serv, sizeof(serv), "%d", portnum); | |
786 | memset(&hints, 0, sizeof(struct addrinfo)); | |
787 | hints.ai_flags = AI_PASSIVE; | |
788 | hints.ai_family = AF_UNSPEC; | |
789 | hints.ai_socktype = SOCK_STREAM; | |
790 | if (getaddrinfo(NULL /*any IP*/, serv, &hints, &res) != 0) { | |
791 | perror("getaddrinfo"); | |
792 | return -1; | |
793 | } | |
794 | ressave = res; | |
795 | do { | |
796 | listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | |
797 | if (listenfd < 0) | |
798 | continue; | |
799 | setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); | |
800 | if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0) | |
801 | break; | |
802 | /* success */ | |
803 | close(listenfd); | |
804 | } while ( (res = res->ai_next) ); | |
805 | ||
806 | if (!res) | |
807 | return -1; | |
808 | ||
809 | if (listen(listenfd, 1024)!=0) { | |
810 | perror("listen"); | |
811 | return -1; | |
812 | } | |
813 | ||
814 | freeaddrinfo(ressave); | |
815 | return listenfd; | |
816 | #else | |
817 | int listenfd; | |
818 | const int on = 1; | |
819 | struct sockaddr_in sockin; | |
820 | ||
821 | if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { | |
822 | perror("socket(listenfd)"); | |
823 | return -1; | |
824 | } | |
825 | ||
826 | if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on) != 0)) { | |
827 | perror("setsockopt(listenfd)"); | |
828 | close(listenfd); | |
829 | return -1; | |
830 | } | |
831 | ||
832 | memset(&sockin, 0, sizeof(struct sockaddr_in)); | |
833 | sockin.sin_family = AF_INET; | |
834 | sockin.sin_port = htons(portnum); | |
835 | ||
836 | if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) { | |
837 | perror("bind(listenfd)"); | |
838 | close(listenfd); | |
839 | return -1; | |
840 | } | |
841 | if (listen(listenfd, 4) != 0) { | |
842 | perror("listen(listenfd)"); | |
843 | close(listenfd); | |
844 | return -1; | |
845 | } | |
846 | return listenfd; | |
847 | #endif | |
848 | } | |
37ee990e | 849 | |
c5f5b7f1 | 850 | static int getcommand_getfile(aim_session_t *sess, aim_conn_t *conn) |
851 | { | |
852 | #if 0 | |
853 | struct aim_filetransfer_priv *ft; | |
854 | aim_rxcallback_t userfunc; | |
855 | ||
856 | ft = conn->priv; | |
857 | if (ft->state == 2) { | |
858 | /* waiting on listing data */ | |
859 | int ret = 0; | |
860 | char *listing; | |
861 | struct command_tx_struct *newoft; | |
862 | ||
863 | if (!(listing = malloc(ft->fh.size))) | |
864 | return -1; | |
865 | ||
866 | ft->state = 0; | |
867 | if (aim_recv(conn->fd, listing, ft->fh.size) != ft->fh.size) | |
868 | faimdprintf(sess, 2, "OFT get: file %s was short. (0x%lx)\n", ft->fh.name, ft->fh.size); | |
869 | ||
870 | if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x120b, 0))) { | |
871 | faimdprintf(sess, 2, "faim: aim_get_command_rendezvous: getfile listing: tx_new OFT failed\n"); | |
872 | faim_mutex_unlock(&conn->active); | |
873 | free(listing); | |
874 | aim_conn_close(conn); | |
875 | return -1; | |
876 | } | |
877 | ||
878 | memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
879 | newoft->hdr.oft.hdr2len = 0x100 - 8; | |
880 | ||
881 | /* Protocol BS - set nrecvd to size of listing, recvcsum to listing checksum, flags to 0 */ | |
882 | ||
883 | ft->fh.nrecvd = ft->fh.size; | |
884 | ft->fh.recvcsum = ft->fh.checksum; | |
885 | ft->fh.flags = 0; | |
886 | ||
887 | if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
888 | aim_frame_destroy(newoft); | |
889 | free(listing); | |
890 | return -1; | |
891 | } | |
892 | ||
893 | if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) | |
894 | faimdprintf(sess, 2, "eek! bh fail listing\n"); | |
895 | ||
896 | /* send the 120b */ | |
897 | aim_tx_enqueue(sess, newoft); | |
898 | if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTING)) ) | |
899 | ret = userfunc(sess, NULL, conn, ft, listing); | |
900 | ||
901 | free(listing); | |
902 | return ret; | |
903 | } | |
904 | ||
905 | if (ft->state == 3) { | |
906 | /* waiting on file data */ | |
907 | if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECEIVE)) ) | |
908 | return userfunc(sess, NULL, conn, ft); | |
909 | return 0; | |
910 | } | |
911 | ||
912 | if (ft->state == 4) { | |
913 | if( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILESTATE4)) ) | |
914 | return userfunc(sess, NULL, conn); | |
915 | aim_conn_close(conn); | |
916 | return 0; | |
917 | } | |
918 | ||
919 | return 0; | |
37ee990e | 920 | #else |
c5f5b7f1 | 921 | return -1; |
922 | #endif | |
923 | } | |
646c6b52 | 924 | |
59e1da90 | 925 | static void connclose_sendfile(aim_session_t *sess, aim_conn_t *conn) |
c5f5b7f1 | 926 | { |
c5f5b7f1 | 927 | aim_msgcookie_t *cook; |
928 | struct aim_filetransfer_priv *priv = (struct aim_filetransfer_priv *)conn->priv; | |
37ee990e | 929 | |
c5f5b7f1 | 930 | cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTSEND); |
931 | aim_cookie_free(sess, cook); | |
37ee990e | 932 | |
59e1da90 | 933 | return; |
934 | } | |
646c6b52 | 935 | |
59e1da90 | 936 | static void connkill_sendfile(aim_session_t *sess, aim_conn_t *conn) |
937 | { | |
938 | ||
939 | free(conn->internal); | |
c5f5b7f1 | 940 | |
941 | return; | |
942 | } | |
943 | ||
59e1da90 | 944 | static void connclose_getfile(aim_session_t *sess, aim_conn_t *conn) |
c5f5b7f1 | 945 | { |
c5f5b7f1 | 946 | aim_msgcookie_t *cook; |
947 | struct aim_filetransfer_priv *priv = (struct aim_filetransfer_priv *)conn->priv; | |
948 | ||
949 | cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTGET); | |
950 | aim_cookie_free(sess, cook); | |
951 | ||
59e1da90 | 952 | return; |
953 | } | |
c5f5b7f1 | 954 | |
59e1da90 | 955 | static void connkill_getfile(aim_session_t *sess, aim_conn_t *conn) |
956 | { | |
957 | ||
958 | free(conn->internal); | |
c5f5b7f1 | 959 | |
960 | return; | |
961 | } | |
962 | ||
59e1da90 | 963 | static void connclose_directim(aim_session_t *sess, aim_conn_t *conn) |
c5f5b7f1 | 964 | { |
c5f5b7f1 | 965 | struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal; |
c5f5b7f1 | 966 | aim_msgcookie_t *cook; |
967 | ||
968 | cook = aim_uncachecookie(sess, intdata->cookie, AIM_COOKIETYPE_OFTIM); | |
969 | aim_cookie_free(sess, cook); | |
970 | ||
59e1da90 | 971 | return; |
972 | } | |
973 | ||
974 | static void connkill_directim(aim_session_t *sess, aim_conn_t *conn) | |
975 | { | |
976 | ||
977 | free(conn->internal); | |
978 | ||
979 | return; | |
980 | } | |
981 | ||
982 | faim_internal void aim_conn_close_rend(aim_session_t *sess, aim_conn_t *conn) | |
983 | { | |
c5f5b7f1 | 984 | |
59e1da90 | 985 | if (conn->type != AIM_CONN_TYPE_RENDEZVOUS) |
986 | return; | |
987 | ||
988 | if (conn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) | |
989 | connclose_sendfile(sess, conn); | |
990 | else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) | |
991 | connclose_getfile(sess, conn); | |
992 | else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) | |
993 | connclose_directim(sess, conn); | |
994 | ||
995 | return; | |
996 | } | |
997 | ||
998 | faim_internal void aim_conn_kill_rend(aim_session_t *sess, aim_conn_t *conn) | |
999 | { | |
1000 | ||
1001 | if (conn->type != AIM_CONN_TYPE_RENDEZVOUS) | |
1002 | return; | |
1003 | ||
1004 | if (conn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) | |
1005 | connkill_sendfile(sess, conn); | |
1006 | else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) | |
1007 | connkill_getfile(sess, conn); | |
1008 | else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) | |
1009 | connkill_directim(sess, conn); | |
c5f5b7f1 | 1010 | |
1011 | return; | |
1012 | } | |
1013 | ||
1014 | static int handlehdr_directim(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) | |
1015 | { | |
1016 | aim_frame_t fr; | |
1017 | aim_rxcallback_t userfunc; | |
1018 | fu32_t payloadlength; | |
1019 | fu16_t flags; | |
1020 | char *snptr = NULL; | |
1021 | ||
1022 | fr.conn = conn; | |
1023 | ||
1024 | payloadlength = aimutil_get32(hdr+22); | |
1025 | flags = aimutil_get16(hdr+32); | |
1026 | snptr = (char *)hdr+38; | |
1027 | ||
1028 | faimdprintf(sess, 2, "faim: OFT frame: handlehdr_directim: %04x / %04x / %s\n", payloadlength, flags, snptr); | |
1029 | ||
1030 | if (flags == 0x000e) { | |
1031 | int ret = 0; | |
1032 | ||
1033 | if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING))) | |
1034 | ret = userfunc(sess, &fr, snptr); | |
1035 | ||
1036 | return ret; | |
1037 | ||
1038 | } else if ((flags == 0x0000) && payloadlength) { | |
1039 | char *msg; | |
1040 | int ret = 0; | |
1041 | ||
1042 | if (!(msg = calloc(1, payloadlength+1))) | |
1043 | return -1; | |
1044 | ||
1045 | if (aim_recv(conn->fd, msg, payloadlength) < payloadlength) { | |
1046 | free(msg); | |
1047 | return -1; | |
1048 | } | |
1049 | ||
1050 | msg[payloadlength] = '\0'; | |
1051 | ||
1052 | if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) ) | |
1053 | ret = userfunc(sess, &fr, snptr, msg); | |
1054 | ||
1055 | free(msg); | |
1056 | ||
1057 | return ret; | |
1058 | } | |
1059 | ||
1060 | return 0; | |
1061 | } | |
1062 | ||
1063 | static int handlehdr_getfile_listing(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) | |
7392c79f | 1064 | { |
d410cf58 | 1065 | #if 0 |
c5f5b7f1 | 1066 | struct aim_filetransfer_priv *ft; |
1067 | struct aim_fileheader_t *fh; | |
1068 | struct aim_msgcookie_t *cook; | |
1069 | struct command_tx_struct *newoft; | |
1070 | aim_rxcallback_t userfunc; | |
1071 | ||
1072 | faimdprintf(sess, 2,"faim: rend: fileget 0x1108\n"); | |
1073 | fh = aim_oft_getfh(hdr); | |
646c6b52 | 1074 | |
37ee990e | 1075 | faim_mutex_unlock(&conn->active); |
4dd56961 | 1076 | |
c5f5b7f1 | 1077 | if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
1078 | free(fh); | |
1079 | return -1; | |
1080 | } | |
646c6b52 | 1081 | |
c5f5b7f1 | 1082 | ft = cook->data; |
646c6b52 | 1083 | |
c5f5b7f1 | 1084 | /* we're waaaaiiiting.. for listing.txt */ |
1085 | ft->state = 2; | |
37ee990e | 1086 | |
c5f5b7f1 | 1087 | memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); |
1088 | free(fh); | |
37ee990e | 1089 | |
c5f5b7f1 | 1090 | if(aim_cachecookie(sess, cook) == -1) { |
1091 | faimdprintf(sess, 1, "error caching cookie\n"); | |
1092 | return -1; | |
1093 | } | |
37ee990e | 1094 | |
c5f5b7f1 | 1095 | if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x1209, 0))) { |
1096 | aim_conn_close(conn); | |
1097 | return -1; | |
1098 | } | |
37ee990e | 1099 | |
c5f5b7f1 | 1100 | memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
1101 | newoft->hdr.oft.hdr2len = 0x100 - 8; | |
37ee990e | 1102 | |
c5f5b7f1 | 1103 | if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { |
1104 | newoft->lock = 0; | |
1105 | aim_frame_destroy(newoft); | |
1106 | return -1; | |
1107 | } | |
37ee990e | 1108 | |
c5f5b7f1 | 1109 | if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) { |
1110 | newoft->lock = 0; | |
1111 | aim_frame_destroy(newoft); | |
1112 | return -1; | |
1113 | } | |
37ee990e | 1114 | |
c5f5b7f1 | 1115 | newoft->lock = 0; |
1116 | aim_tx_enqueue(sess, newoft); | |
1117 | #endif | |
1118 | return -1; | |
1119 | } | |
37ee990e | 1120 | |
c5f5b7f1 | 1121 | static int handlehdr_getfile_listing2(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
1122 | { | |
1123 | #if 0 | |
1124 | struct aim_filetransfer_priv *ft; | |
1125 | struct aim_fileheader_t *fh; | |
1126 | struct aim_msgcookie_t *cook; | |
1127 | int ret = 0; | |
1128 | aim_rxcallback_t userfunc; | |
1129 | ||
1130 | fh = aim_oft_getfh(hdr); | |
37ee990e | 1131 | |
c5f5b7f1 | 1132 | if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) |
1133 | faimdprintf(sess, 2, "shit, no cookie in 0x1209. (%i/%s)going to crash..\n", AIM_COOKIETYPE_OFTGET, fh->bcookie); | |
646c6b52 | 1134 | |
c5f5b7f1 | 1135 | ft = cook->data; |
646c6b52 | 1136 | |
c5f5b7f1 | 1137 | if (ft->fh.size != fh->size) |
1138 | faimdprintf(sess, 2, "hrm. ft->fh.size (%ld) != fh->size (%ld). um. using ft->fh.size\n", ft->fh.size, fh->size); | |
37ee990e | 1139 | |
c5f5b7f1 | 1140 | if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ))) |
1141 | ret = userfunc(sess, NULL, conn, fh); | |
37ee990e | 1142 | |
c5f5b7f1 | 1143 | faimdprintf(sess, 2, "faim: get_command_rendezvous: hit end of 1209\n"); |
37ee990e | 1144 | |
c5f5b7f1 | 1145 | free(fh); |
646c6b52 | 1146 | |
c5f5b7f1 | 1147 | return ret; |
1148 | #else | |
1149 | return -1; | |
1150 | #endif | |
1151 | } | |
646c6b52 | 1152 | |
c5f5b7f1 | 1153 | static int handlehdr_getfile_listing3(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
1154 | { | |
1155 | #if 0 | |
1156 | struct aim_filetransfer_priv *ft; | |
1157 | struct aim_msgcookie_t *cook; | |
1158 | struct aim_fileheader_t *fh; | |
1159 | aim_rxcallback_t userfunc; | |
646c6b52 | 1160 | |
c5f5b7f1 | 1161 | fh = aim_oft_getfh(hdr); |
37ee990e | 1162 | |
c5f5b7f1 | 1163 | if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
1164 | free(fh); | |
1165 | return -1; | |
1166 | } | |
646c6b52 | 1167 | |
c5f5b7f1 | 1168 | free(fh); |
646c6b52 | 1169 | |
c5f5b7f1 | 1170 | ft = cook->data; |
871e2fd0 | 1171 | |
c5f5b7f1 | 1172 | if (aim_cachecookie(sess, cook) == -1) |
1173 | return -1; | |
3b101546 | 1174 | |
c5f5b7f1 | 1175 | if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGRXCONFIRM))) |
1176 | return userfunc(sess, NULL, conn); | |
1177 | #endif | |
1178 | return -1; | |
1179 | } | |
871e2fd0 | 1180 | |
c5f5b7f1 | 1181 | static int handlehdr_getfile_request(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
1182 | { | |
1183 | #if 0 | |
1184 | struct aim_filetransfer_priv *ft; | |
1185 | struct aim_msgcookie_t *cook; | |
1186 | struct aim_fileheader_t *fh; | |
1187 | struct command_tx_struct *newoft; | |
1188 | int i = 0; | |
1189 | aim_rxcallback_t userfunc; | |
3b101546 | 1190 | |
c5f5b7f1 | 1191 | fh = aim_oft_getfh(hdr); |
3b101546 | 1192 | |
c5f5b7f1 | 1193 | if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
1194 | free(fh); | |
1195 | return -1; | |
1196 | } | |
3b101546 | 1197 | |
c5f5b7f1 | 1198 | ft = cook->data; |
1199 | memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); | |
1200 | free(fh); | |
871e2fd0 | 1201 | |
c5f5b7f1 | 1202 | aim_cachecookie(sess, cook); |
871e2fd0 | 1203 | |
c5f5b7f1 | 1204 | faimdprintf(sess, 2, "faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name); |
871e2fd0 | 1205 | |
c5f5b7f1 | 1206 | if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) ) |
1207 | i = userfunc(sess, NULL, conn, &(ft->fh), cook->cookie); | |
871e2fd0 | 1208 | |
c5f5b7f1 | 1209 | if (i < 0) |
1210 | return i; | |
871e2fd0 | 1211 | |
c5f5b7f1 | 1212 | if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0101, 0))) { |
1213 | faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n"); | |
1214 | return -1; | |
1215 | } | |
871e2fd0 | 1216 | |
c5f5b7f1 | 1217 | newoft->lock = 1; |
1218 | memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
1219 | newoft->hdr.oft.hdr2len = 0x100 - 8; | |
871e2fd0 | 1220 | |
c5f5b7f1 | 1221 | if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { |
1222 | aim_frame_destroy(newoft); | |
1223 | return -1; | |
1224 | } | |
7392c79f | 1225 | |
c5f5b7f1 | 1226 | /* protocol BS: nrecvd, recvcsum to 0, flags to 0x20. */ |
1227 | ft->fh.nrecvd = 0; | |
1228 | ft->fh.recvcsum = 0; | |
1229 | ft->fh.flags = 0x20; | |
7392c79f | 1230 | |
c5f5b7f1 | 1231 | aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)); |
7392c79f | 1232 | |
c5f5b7f1 | 1233 | newoft->lock = 0; |
1234 | aim_tx_enqueue(sess, newoft); | |
646c6b52 | 1235 | |
c5f5b7f1 | 1236 | faimdprintf(sess, 2, "faim: OFT: OFT file header enqueued.\n"); |
646c6b52 | 1237 | |
c5f5b7f1 | 1238 | return i; |
1239 | #else | |
1240 | return -1; | |
1241 | #endif | |
1242 | } | |
871e2fd0 | 1243 | |
c5f5b7f1 | 1244 | static int handlehdr_getfile_sending(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
1245 | { | |
1246 | #if 0 | |
1247 | struct aim_fileheader_t *fh; | |
1248 | struct aim_filetransfer_priv *ft; | |
1249 | struct aim_msgcookie_t *cook; | |
1250 | struct command_tx_struct *newoft; | |
1251 | aim_rxcallback_t userfunc; | |
871e2fd0 | 1252 | |
c5f5b7f1 | 1253 | fh = aim_oft_getfh(hdr); |
7392c79f | 1254 | |
c5f5b7f1 | 1255 | if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
1256 | free(fh); | |
1257 | return -1; | |
1258 | } | |
7392c79f | 1259 | |
c5f5b7f1 | 1260 | free(fh); |
646c6b52 | 1261 | |
c5f5b7f1 | 1262 | ft = cook->data; |
7392c79f | 1263 | |
c5f5b7f1 | 1264 | ft->state = 3; |
7392c79f | 1265 | |
c5f5b7f1 | 1266 | if (aim_cachecookie(sess, cook) == -1) |
1267 | return -1; | |
7392c79f | 1268 | |
c5f5b7f1 | 1269 | faimdprintf(sess, 2, "faim: fileget: %s seems to want to send %s\n", ft->sn, ft->fh.name); |
7392c79f | 1270 | |
c5f5b7f1 | 1271 | if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) { |
1272 | faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n"); | |
1273 | return -1; | |
1274 | } | |
4dd56961 | 1275 | |
c5f5b7f1 | 1276 | newoft->lock = 1; |
1277 | memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
871e2fd0 | 1278 | |
c5f5b7f1 | 1279 | newoft->hdr.oft.hdr2len = 0x100 - 8; |
7392c79f | 1280 | |
c5f5b7f1 | 1281 | if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { |
1282 | aim_frame_destroy(newoft); | |
1283 | return -1; | |
1284 | } | |
7392c79f | 1285 | |
c5f5b7f1 | 1286 | aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)); |
7392c79f | 1287 | |
c5f5b7f1 | 1288 | newoft->lock = 0; |
1289 | aim_tx_enqueue(sess, newoft); | |
7392c79f | 1290 | |
c5f5b7f1 | 1291 | faimdprintf(sess, 2, "faim: OFT: OFT 0x0202 enqueued.\n"); |
646c6b52 | 1292 | |
c5f5b7f1 | 1293 | if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL) |
1294 | return 1; | |
1295 | #else | |
1296 | return -1; | |
1297 | #endif | |
1298 | } | |
646c6b52 | 1299 | |
c5f5b7f1 | 1300 | static int handlehdr_getfile_recv(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
1301 | { | |
1302 | #if 0 | |
1303 | struct aim_fileheader_t *fh; | |
1304 | struct aim_filetransfer_priv *ft; | |
1305 | struct aim_msgcookie_t *cook; | |
1306 | int ret = 1; | |
1307 | aim_rxcallback_t userfunc; | |
7392c79f | 1308 | |
c5f5b7f1 | 1309 | fh = aim_oft_getfh(hdr); |
7392c79f | 1310 | |
c5f5b7f1 | 1311 | if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
1312 | free(fh); | |
1313 | return -1; | |
1314 | } | |
7392c79f | 1315 | |
c5f5b7f1 | 1316 | ft = cook->data; |
7392c79f | 1317 | |
c5f5b7f1 | 1318 | faimdprintf(sess, 2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n"); |
4dd56961 | 1319 | |
c5f5b7f1 | 1320 | if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) ) |
1321 | ret = userfunc(sess, NULL, conn, fh); | |
871e2fd0 | 1322 | |
c5f5b7f1 | 1323 | free(fh); |
646c6b52 | 1324 | |
c5f5b7f1 | 1325 | return ret; |
1326 | #else | |
1327 | return -1; | |
1328 | #endif | |
1329 | } | |
646c6b52 | 1330 | |
c5f5b7f1 | 1331 | static int handlehdr_getfile_finish(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
1332 | { | |
1333 | #if 0 | |
1334 | struct aim_fileheader_t *fh; | |
1335 | aim_rxcallback_t userfunc; | |
871e2fd0 | 1336 | |
c5f5b7f1 | 1337 | fh = aim_oft_getfh(hdr); |
871e2fd0 | 1338 | |
c5f5b7f1 | 1339 | faimdprintf(sess, 2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n"); |
871e2fd0 | 1340 | |
c5f5b7f1 | 1341 | if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) ) |
1342 | userfunc(sess, NULL, conn, fh); | |
871e2fd0 | 1343 | |
c5f5b7f1 | 1344 | free(fh); |
1345 | #endif | |
7392c79f | 1346 | |
c5f5b7f1 | 1347 | return -1; |
1348 | } | |
9e8c4225 | 1349 | |
c5f5b7f1 | 1350 | /** |
1351 | * aim_get_command_rendezvous - OFT equivalent of aim_get_command | |
1352 | * @sess: session to work on | |
1353 | * @conn: conn to pull data from | |
1354 | * | |
1355 | * this reads and handles data from conn->fd. currently a little rough | |
1356 | * around the edges | |
1357 | */ | |
1358 | faim_internal int aim_get_command_rendezvous(aim_session_t *sess, aim_conn_t *conn) | |
1359 | { | |
1360 | fu8_t hdrbuf1[6]; | |
1361 | fu8_t *hdr = NULL; | |
1362 | int hdrlen, hdrtype; | |
1363 | int ret = -1; | |
1364 | ||
1365 | if (!sess || !conn) | |
1366 | return -1; | |
1367 | ||
1368 | memset(hdrbuf1, 0, sizeof(hdrbuf1)); | |
1369 | ||
1370 | /* I guess? I didn't understand any of that mess... */ | |
1371 | if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) | |
1372 | return getcommand_getfile(sess, conn); | |
1373 | ||
1374 | /* XXX fix all the error cases here */ | |
1375 | if (aim_recv(conn->fd, hdrbuf1, 6) < 6) { | |
1376 | ||
1377 | faimdprintf(sess, 2, "faim: rend: read error (fd: %i)\n", conn->fd); | |
1378 | ||
c5f5b7f1 | 1379 | aim_conn_close(conn); |
1380 | ||
1381 | return -1; | |
1382 | } | |
1383 | ||
1384 | hdrlen = aimutil_get16(hdrbuf1+4); | |
1385 | hdrlen -= 6; | |
1386 | ||
1387 | hdr = malloc(hdrlen); | |
1388 | ||
1389 | if (aim_recv(conn->fd, hdr, hdrlen) < hdrlen) { | |
1390 | faimdprintf(sess, 2, "faim: rend: read2 error on %d (%d)\n", conn->fd, hdrlen); | |
1391 | free(hdr); | |
1392 | aim_conn_close(conn); | |
1393 | return -1; | |
1394 | } | |
1395 | ||
1396 | hdrtype = aimutil_get16(hdr); | |
1397 | ||
1398 | if (hdrtype == 0x0001) | |
1399 | ret = handlehdr_directim(sess, conn, hdr); | |
1400 | else if (hdrtype == 0x1108) /* getfile listing.txt incoming tx->rx */ | |
1401 | ret = handlehdr_getfile_listing(sess, conn, hdr); | |
1402 | else if (hdrtype == 0x1209) /* get file listing ack rx->tx */ | |
1403 | ret = handlehdr_getfile_listing2(sess, conn, hdr); | |
1404 | else if (hdrtype == 0x120b) /* get file listing rx confirm */ | |
1405 | ret = handlehdr_getfile_listing3(sess, conn, hdr); | |
1406 | else if (hdrtype == 0x120c) /* getfile request */ | |
1407 | ret = handlehdr_getfile_request(sess, conn, hdr); | |
1408 | else if (hdrtype == 0x0101) /* getfile sending data */ | |
1409 | ret = handlehdr_getfile_sending(sess, conn, hdr); | |
1410 | else if (hdrtype == 0x0202) /* getfile recv data */ | |
1411 | ret = handlehdr_getfile_recv(sess, conn, hdr); | |
1412 | else if (hdrtype == 0x0204) /* getfile finished */ | |
1413 | ret = handlehdr_getfile_finish(sess, conn, hdr); | |
1414 | else { | |
1415 | faimdprintf(sess, 2,"faim: OFT frame: uknown type %04x\n", hdrtype); | |
1416 | ret = -1; | |
1417 | } | |
1418 | ||
1419 | free(hdr); | |
1420 | ||
1421 | if (ret == -1) | |
1422 | aim_conn_close(conn); | |
1423 | ||
1424 | return ret; | |
7392c79f | 1425 | } |
d410cf58 | 1426 | |
1427 | #if 0 | |
646c6b52 | 1428 | /** |
1429 | * aim_oft_getfh - extracts an &aim_fileheader_t from buffer hdr. | |
37ee990e | 1430 | * @hdr: buffer to extract header from |
1431 | * | |
646c6b52 | 1432 | * returns pointer to new struct on success; %NULL on error. |
871e2fd0 | 1433 | * |
7392c79f | 1434 | */ |
37ee990e | 1435 | static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr) |
7392c79f | 1436 | { |
1437 | struct aim_fileheader_t *fh; | |
1438 | int i, j; | |
646c6b52 | 1439 | if (!(fh = calloc(1, sizeof(struct aim_fileheader_t)))) |
7392c79f | 1440 | return NULL; |
37ee990e | 1441 | |
7392c79f | 1442 | /* [0] and [1] are the type. we can ignore those here. */ |
7392c79f | 1443 | i = 2; |
7392c79f | 1444 | for(j = 0; j < 8; j++, i++) |
1445 | fh->bcookie[j] = hdr[i]; | |
1446 | fh->encrypt = aimutil_get16(hdr+i); | |
1447 | i += 2; | |
1448 | fh->compress = aimutil_get16(hdr+i); | |
1449 | i += 2; | |
1450 | fh->totfiles = aimutil_get16(hdr+i); | |
1451 | i += 2; | |
1452 | fh->filesleft = aimutil_get16(hdr+i); | |
1453 | i += 2; | |
1454 | fh->totparts = aimutil_get16(hdr+i); | |
1455 | i += 2; | |
1456 | fh->partsleft = aimutil_get16(hdr+i); | |
1457 | i += 2; | |
1458 | fh->totsize = aimutil_get32(hdr+i); | |
1459 | i += 4; | |
1460 | fh->size = aimutil_get32(hdr+i); | |
1461 | i += 4; | |
1462 | fh->modtime = aimutil_get32(hdr+i); | |
1463 | i += 4; | |
1464 | fh->checksum = aimutil_get32(hdr+i); | |
1465 | i += 4; | |
1466 | fh->rfrcsum = aimutil_get32(hdr+i); | |
1467 | i += 4; | |
1468 | fh->rfsize = aimutil_get32(hdr+i); | |
1469 | i += 4; | |
1470 | fh->cretime = aimutil_get32(hdr+i); | |
1471 | i += 4; | |
1472 | fh->rfcsum = aimutil_get32(hdr+i); | |
1473 | i += 4; | |
1474 | fh->nrecvd = aimutil_get32(hdr+i); | |
1475 | i += 4; | |
1476 | fh->recvcsum = aimutil_get32(hdr+i); | |
1477 | i += 4; | |
7392c79f | 1478 | memcpy(fh->idstring, hdr+i, 32); |
1479 | i += 32; | |
7392c79f | 1480 | fh->flags = aimutil_get8(hdr+i); |
1481 | i += 1; | |
1482 | fh->lnameoffset = aimutil_get8(hdr+i); | |
1483 | i += 1; | |
1484 | fh->lsizeoffset = aimutil_get8(hdr+i); | |
1485 | i += 1; | |
7392c79f | 1486 | memcpy(fh->dummy, hdr+i, 69); |
1487 | i += 69; | |
7392c79f | 1488 | memcpy(fh->macfileinfo, hdr+i, 16); |
1489 | i += 16; | |
7392c79f | 1490 | fh->nencode = aimutil_get16(hdr+i); |
1491 | i += 2; | |
1492 | fh->nlanguage = aimutil_get16(hdr+i); | |
1493 | i += 2; | |
7392c79f | 1494 | memcpy(fh->name, hdr+i, 64); |
1495 | i += 64; | |
7392c79f | 1496 | return fh; |
37ee990e | 1497 | } |
d410cf58 | 1498 | #endif |
871e2fd0 | 1499 | |
646c6b52 | 1500 | /** |
37ee990e | 1501 | * aim_oft_checksum - calculate oft checksum of buffer |
1502 | * @buffer: buffer of data to checksum | |
1503 | * @bufsize: size of buffer | |
1504 | * @checksum: pointer to integer to place result in (pointer!) | |
37ee990e | 1505 | * |
646c6b52 | 1506 | * |
1507 | * Note that checksum is a pointer. Checksum should be filled with | |
37ee990e | 1508 | * 0xFFFF0000 for each new file; you can have this checksum chunks of |
1509 | * files in series if you just call it repeatedly in a for(; ; ) loop | |
646c6b52 | 1510 | * and don't reset the checksum between each call. And you thought we |
37ee990e | 1511 | * didn't care about you and your pathetic client's meomry footprint |
1512 | * ;^) | |
1513 | * | |
646c6b52 | 1514 | * |
1515 | * Also, it's been said that this is incorrect as currently | |
1516 | * written. You were warned. | |
37ee990e | 1517 | */ |
d410cf58 | 1518 | faim_export fu32_t aim_oft_checksum(aim_session_t *sess, const char *buffer, int bufsize, fu32_t *checksum) |
646c6b52 | 1519 | { |
d410cf58 | 1520 | return 0xdeadbeef; |
1521 | #if 0 | |
1522 | fu16_t check0, check1; | |
646c6b52 | 1523 | int i; |
d410cf58 | 1524 | |
646c6b52 | 1525 | check0 = ((*checksum & 0xFF000000) >> 16); |
1526 | check1 = ((*checksum & 0x00ff0000) >> 16); | |
1527 | for(i = 0; i < bufsize; i++) { | |
1528 | if (i % 2) { /* use check1 -- second byte */ | |
1529 | if ( (short)buffer[i] > check1 ) { /* wrapping */ | |
1530 | check1 += 0x100; /* this is a cheap way to wrap */ | |
1531 | ||
1532 | /* if we're wrapping, decrement the other one */ | |
1533 | /* XXX: check this corner case */ | |
1534 | if (check0 == 0) | |
1535 | check0 = 0x00ff; | |
1536 | else | |
1537 | check0--; | |
1538 | } | |
1539 | check1 -= buffer[i]; | |
1540 | } else { /* use check0 -- first byte */ | |
1541 | if ( (short)buffer[i] > check0 ) { /* wrapping */ | |
1542 | check0 += 0x100; /* this is a cheap way to wrap */ | |
871e2fd0 | 1543 | |
646c6b52 | 1544 | /* if we're wrapping, decrement the other one */ |
1545 | /* XXX: check this corner case */ | |
1546 | if (check1 == 0) | |
1547 | check1 = 0x00ff; | |
1548 | else | |
1549 | check1--; | |
1550 | } | |
1551 | check0 -= buffer[i]; | |
1552 | } | |
1553 | } | |
37ee990e | 1554 | |
646c6b52 | 1555 | if (check0 > 0xff || check1 > 0xff) { |
1556 | /* they shouldn't be able to do this. error! */ | |
1557 | faimdprintf(sess, 2, "check0 or check1 is too high: 0x%04x, 0x%04x\n", check0, check1); | |
1558 | return -1; | |
1559 | } | |
37ee990e | 1560 | |
646c6b52 | 1561 | /* grab just the lowest byte; this should be clean, but just in |
1562 | case */ | |
1563 | check0 &= 0xff; | |
1564 | check1 &= 0xff; | |
37ee990e | 1565 | |
646c6b52 | 1566 | *checksum = ((check0 * 0x1000000) + (check1 * 0x10000)); |
1567 | return *checksum; | |
d410cf58 | 1568 | #endif |
37ee990e | 1569 | } |
871e2fd0 | 1570 | |
d410cf58 | 1571 | #if 0 |
646c6b52 | 1572 | /** |
37ee990e | 1573 | * aim_oft_buildheader - fills a buffer with network-order fh data |
1574 | * @dest: buffer to fill -- pre-alloced | |
1575 | * @fh: fh to get data from | |
871e2fd0 | 1576 | * |
37ee990e | 1577 | * returns length written; -1 on error. |
871e2fd0 | 1578 | * DOES NOT DO BOUNDS CHECKING! |
37ee990e | 1579 | * |
871e2fd0 | 1580 | */ |
d410cf58 | 1581 | static int oft_buildheader(unsigned char *dest, struct aim_fileheader_t *fh) |
37ee990e | 1582 | { |
871e2fd0 | 1583 | int i, curbyte; |
646c6b52 | 1584 | if (!dest || !fh) |
871e2fd0 | 1585 | return -1; |
37ee990e | 1586 | curbyte = 0; |
1587 | for(i = 0; i < 8; i++) | |
1588 | curbyte += aimutil_put8(dest+curbyte, fh->bcookie[i]); | |
1589 | curbyte += aimutil_put16(dest+curbyte, fh->encrypt); | |
1590 | curbyte += aimutil_put16(dest+curbyte, fh->compress); | |
1591 | curbyte += aimutil_put16(dest+curbyte, fh->totfiles); | |
1592 | curbyte += aimutil_put16(dest+curbyte, fh->filesleft); | |
1593 | curbyte += aimutil_put16(dest+curbyte, fh->totparts); | |
1594 | curbyte += aimutil_put16(dest+curbyte, fh->partsleft); | |
1595 | curbyte += aimutil_put32(dest+curbyte, fh->totsize); | |
1596 | curbyte += aimutil_put32(dest+curbyte, fh->size); | |
1597 | curbyte += aimutil_put32(dest+curbyte, fh->modtime); | |
1598 | curbyte += aimutil_put32(dest+curbyte, fh->checksum); | |
1599 | curbyte += aimutil_put32(dest+curbyte, fh->rfrcsum); | |
1600 | curbyte += aimutil_put32(dest+curbyte, fh->rfsize); | |
1601 | curbyte += aimutil_put32(dest+curbyte, fh->cretime); | |
1602 | curbyte += aimutil_put32(dest+curbyte, fh->rfcsum); | |
1603 | curbyte += aimutil_put32(dest+curbyte, fh->nrecvd); | |
1604 | curbyte += aimutil_put32(dest+curbyte, fh->recvcsum); | |
1605 | memcpy(dest+curbyte, fh->idstring, 32); | |
871e2fd0 | 1606 | curbyte += 32; |
37ee990e | 1607 | curbyte += aimutil_put8(dest+curbyte, fh->flags); |
1608 | curbyte += aimutil_put8(dest+curbyte, fh->lnameoffset); | |
1609 | curbyte += aimutil_put8(dest+curbyte, fh->lsizeoffset); | |
1610 | memcpy(dest+curbyte, fh->dummy, 69); | |
871e2fd0 | 1611 | curbyte += 69; |
37ee990e | 1612 | memcpy(dest+curbyte, fh->macfileinfo, 16); |
871e2fd0 | 1613 | curbyte += 16; |
37ee990e | 1614 | curbyte += aimutil_put16(dest+curbyte, fh->nencode); |
1615 | curbyte += aimutil_put16(dest+curbyte, fh->nlanguage); | |
1616 | memset(dest+curbyte, 0x00, 64); | |
1617 | memcpy(dest+curbyte, fh->name, 64); | |
871e2fd0 | 1618 | |
37ee990e | 1619 | /* XXX: Filenames longer than 64B */ |
871e2fd0 | 1620 | curbyte += 64; |
871e2fd0 | 1621 | return curbyte; |
1622 | } | |
d410cf58 | 1623 | #endif |
871e2fd0 | 1624 | |
646c6b52 | 1625 | /** |
1626 | * aim_getfile_intitiate - Request an OFT getfile session | |
37ee990e | 1627 | * @sess: your session, |
1628 | * @conn: the BOS conn, | |
1629 | * @destsn is the SN to connect to. | |
646c6b52 | 1630 | * |
1631 | * returns a new &aim_conn_t on success, %NULL on error | |
871e2fd0 | 1632 | */ |
d410cf58 | 1633 | faim_export aim_conn_t *aim_getfile_initiate(aim_session_t *sess, aim_conn_t *conn, const char *destsn) |
37ee990e | 1634 | { |
d410cf58 | 1635 | return NULL; |
1636 | #if 0 | |
871e2fd0 | 1637 | struct command_tx_struct *newpacket; |
646c6b52 | 1638 | struct aim_conn_t *newconn; |
1639 | struct aim_filetransfer_priv *priv; | |
1640 | struct aim_msgcookie_t *cookie; | |
1641 | int curbyte, i, listenfd; | |
1642 | short port = 4443; | |
1643 | struct hostent *hptr; | |
1644 | struct utsname myname; | |
1645 | char cap[16]; | |
1646 | char d[4]; | |
37ee990e | 1647 | |
646c6b52 | 1648 | /* Open our socket */ |
871e2fd0 | 1649 | |
646c6b52 | 1650 | if ( (listenfd = aim_listenestablish(port)) == -1) |
1651 | return NULL; | |
871e2fd0 | 1652 | |
646c6b52 | 1653 | /* get our local IP */ |
871e2fd0 | 1654 | |
646c6b52 | 1655 | if (uname(&myname) < 0) |
1656 | return NULL; | |
1657 | if ( (hptr = gethostbyname(myname.nodename)) == NULL) | |
1658 | return NULL; | |
1659 | memcpy(&d, hptr->h_addr_list[0], 4); | |
871e2fd0 | 1660 | |
646c6b52 | 1661 | aim_putcap(cap, 16, AIM_CAPS_GETFILE); |
871e2fd0 | 1662 | |
646c6b52 | 1663 | /* create the OSCAR packet */ |
871e2fd0 | 1664 | |
646c6b52 | 1665 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(destsn)+4+4+0x42))) |
1666 | return NULL; | |
1667 | newpacket->lock = 1; | |
871e2fd0 | 1668 | |
646c6b52 | 1669 | /* lock struct */ |
1670 | curbyte = 0; | |
1671 | curbyte += aim_putsnac(newpacket->data+curbyte, 0x0004, 0x0006, 0x0000, sess->snac_nextid); | |
871e2fd0 | 1672 | |
646c6b52 | 1673 | /* XXX: check the cookie before commiting to using it */ |
871e2fd0 | 1674 | |
646c6b52 | 1675 | /* Generate a random message cookie |
1676 | * This cookie needs to be alphanumeric and NULL-terminated to be TOC-compatible. */ | |
1677 | for (i=0; i<7; i++) | |
1678 | curbyte += aimutil_put8(newpacket->data+curbyte, 0x30 + ((u_char) random() % 10)); | |
871e2fd0 | 1679 | |
646c6b52 | 1680 | curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); |
871e2fd0 | 1681 | |
646c6b52 | 1682 | /* grab all the data for cookie caching. */ |
1683 | ||
1684 | if (!(cookie = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)))) | |
1685 | return NULL; | |
1686 | memcpy(cookie->cookie, newpacket->data+curbyte-8, 8); | |
1687 | cookie->type = AIM_COOKIETYPE_OFTGET; | |
871e2fd0 | 1688 | |
646c6b52 | 1689 | if (!(priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) |
1690 | return NULL; | |
1691 | memcpy(priv->cookie, cookie, 8); | |
1692 | memcpy(priv->sn, destsn, sizeof(priv->sn)); | |
1693 | memcpy(priv->fh.name, "listing.txt", strlen("listing.txt")); | |
1694 | priv->state = 1; | |
871e2fd0 | 1695 | |
646c6b52 | 1696 | cookie->data = priv; |
871e2fd0 | 1697 | |
646c6b52 | 1698 | aim_cachecookie(sess, cookie); |
1699 | ||
1700 | /* Channel ID */ | |
1701 | curbyte += aimutil_put16(newpacket->data+curbyte,0x0002); | |
871e2fd0 | 1702 | |
646c6b52 | 1703 | /* Destination SN (prepended with byte length) */ |
1704 | curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn)); | |
1705 | curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn)); | |
1706 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); | |
1707 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
871e2fd0 | 1708 | |
646c6b52 | 1709 | /* enTLV start */ |
1710 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
1711 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0042); | |
871e2fd0 | 1712 | |
646c6b52 | 1713 | /* Flag data / ICBM Parameters? */ |
1714 | curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
1715 | curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
871e2fd0 | 1716 | |
646c6b52 | 1717 | /* Cookie */ |
1718 | curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cookie, 8); | |
871e2fd0 | 1719 | |
646c6b52 | 1720 | /* Capability String */ |
1721 | curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cap, 0x10); | |
871e2fd0 | 1722 | |
646c6b52 | 1723 | /* 000a/0002 : 0001 */ |
1724 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a); | |
1725 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
1726 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); | |
871e2fd0 | 1727 | |
646c6b52 | 1728 | /* 0003/0004: IP address */ |
1729 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); | |
1730 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004); | |
1731 | for(i = 0; i < 4; i++) | |
1732 | curbyte += aimutil_put8(newpacket->data+curbyte, d[i]); | |
871e2fd0 | 1733 | |
646c6b52 | 1734 | /* already in network byte order */ |
37ee990e | 1735 | |
646c6b52 | 1736 | /* 0005/0002: Port */ |
1737 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
1738 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
1739 | curbyte += aimutil_put16(newpacket->data+curbyte, port); | |
871e2fd0 | 1740 | |
646c6b52 | 1741 | /* 000f/0000: ?? */ |
1742 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f); | |
1743 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
871e2fd0 | 1744 | |
646c6b52 | 1745 | /* 2711/000c: ?? */ |
1746 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x2711); | |
1747 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x000c); | |
1748 | curbyte += aimutil_put32(newpacket->data+curbyte, 0x00120001); | |
871e2fd0 | 1749 | |
646c6b52 | 1750 | for(i = 0; i < 0x000c - 4; i++) |
1751 | curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
871e2fd0 | 1752 | |
646c6b52 | 1753 | newpacket->commandlen = curbyte; |
1754 | newpacket->lock = 0; | |
1755 | aim_tx_enqueue(sess, newpacket); | |
871e2fd0 | 1756 | |
646c6b52 | 1757 | /* allocate and set up our connection */ |
871e2fd0 | 1758 | |
646c6b52 | 1759 | i = fcntl(listenfd, F_GETFL, 0); |
1760 | fcntl(listenfd, F_SETFL, i | O_NONBLOCK); | |
1761 | newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL); | |
871e2fd0 | 1762 | |
646c6b52 | 1763 | if (!newconn){ |
1764 | perror("aim_newconn"); | |
1765 | return NULL; | |
1766 | } | |
871e2fd0 | 1767 | |
646c6b52 | 1768 | newconn->fd = listenfd; |
1769 | newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE; | |
1770 | newconn->priv = priv; | |
1771 | faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd); | |
871e2fd0 | 1772 | |
646c6b52 | 1773 | return newconn; |
d410cf58 | 1774 | #endif |
37ee990e | 1775 | } |
1776 | ||
646c6b52 | 1777 | /** |
37ee990e | 1778 | * aim_oft_getfile_request - request a particular file over an established getfile connection |
1779 | * @sess: your session | |
1780 | * @conn: the established OFT getfile connection | |
1781 | * @name: filename to request | |
1782 | * @size: size of the file | |
1783 | * | |
646c6b52 | 1784 | * |
1785 | * returns -1 on error, 0 on successful enqueuing | |
37ee990e | 1786 | */ |
d410cf58 | 1787 | faim_export int aim_oft_getfile_request(aim_session_t *sess, aim_conn_t *conn, const char *name, int size) |
37ee990e | 1788 | { |
d410cf58 | 1789 | return -EINVAL; |
1790 | #if 0 | |
37ee990e | 1791 | struct command_tx_struct *newoft; |
1792 | struct aim_filetransfer_priv *ft; | |
646c6b52 | 1793 | if (!sess || !conn || !conn->priv || !name) |
1794 | return -1; | |
37ee990e | 1795 | |
646c6b52 | 1796 | if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x120c, 0))) { |
1797 | faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
1798 | return -1; | |
1799 | } | |
37ee990e | 1800 | |
646c6b52 | 1801 | newoft->lock = 1; |
37ee990e | 1802 | |
646c6b52 | 1803 | memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
1804 | newoft->hdr.oft.hdr2len = 0x100 - 8; | |
37ee990e | 1805 | |
646c6b52 | 1806 | ft = (struct aim_filetransfer_priv *)conn->priv; |
1807 | ft->fh.filesleft = 1; | |
1808 | ft->fh.totfiles = 1; | |
1809 | ft->fh.totparts = 1; | |
1810 | ft->fh.partsleft = 1; | |
1811 | ft->fh.totsize = size; | |
1812 | ft->fh.size = size; | |
1813 | ft->fh.checksum = 0; | |
1814 | memcpy(ft->fh.name, name, strlen(name)); | |
1815 | memset(ft->fh.name+strlen(name), 0, 1); | |
1816 | ||
1817 | if (!(newoft->hdr.oft.hdr2 = (unsigned char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
1818 | newoft->lock = 0; | |
d410cf58 | 1819 | aim_frame_destroy(newoft); |
646c6b52 | 1820 | return -1; |
1821 | } | |
37ee990e | 1822 | |
646c6b52 | 1823 | if (!(aim_oft_buildheader(newoft->hdr.oft.hdr2, &(ft->fh)))) { |
1824 | newoft->lock = 0; | |
d410cf58 | 1825 | aim_frame_destroy(newoft); |
646c6b52 | 1826 | return -1; |
1827 | } | |
37ee990e | 1828 | |
646c6b52 | 1829 | newoft->lock = 0; |
37ee990e | 1830 | |
646c6b52 | 1831 | aim_tx_enqueue(sess, newoft); |
1832 | return 0; | |
d410cf58 | 1833 | #endif |
37ee990e | 1834 | } |
1835 | ||
646c6b52 | 1836 | /** |
37ee990e | 1837 | * aim_oft_getfile_ack - acknowledge a getfile download as complete |
1838 | * @sess: your session | |
1839 | * @conn: the getfile conn to send the ack over | |
1840 | * | |
646c6b52 | 1841 | * Call this function after you have read all the data in a particular |
1842 | * filetransfer. Returns -1 on error, 0 on apparent success | |
37ee990e | 1843 | * |
1844 | */ | |
d410cf58 | 1845 | faim_export int aim_oft_getfile_ack(aim_session_t *sess, aim_conn_t *conn) |
646c6b52 | 1846 | { |
d410cf58 | 1847 | return -EINVAL; |
1848 | #if 0 | |
37ee990e | 1849 | struct command_tx_struct *newoft; |
1850 | struct aim_filetransfer_priv *ft; | |
871e2fd0 | 1851 | |
646c6b52 | 1852 | if (!sess || !conn || !conn->priv) |
37ee990e | 1853 | return -1; |
871e2fd0 | 1854 | |
646c6b52 | 1855 | if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) { |
1856 | faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
37ee990e | 1857 | return -1; |
1858 | } | |
871e2fd0 | 1859 | |
37ee990e | 1860 | newoft->lock = 1; |
871e2fd0 | 1861 | |
37ee990e | 1862 | memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
1863 | newoft->hdr.oft.hdr2len = 0x100-8; | |
871e2fd0 | 1864 | |
37ee990e | 1865 | if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { |
1866 | newoft->lock = 0; | |
d410cf58 | 1867 | aim_frame_destroy(newoft); |
37ee990e | 1868 | return -1; |
1869 | } | |
871e2fd0 | 1870 | |
37ee990e | 1871 | ft = (struct aim_filetransfer_priv *)conn->priv; |
871e2fd0 | 1872 | |
646c6b52 | 1873 | if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) { |
37ee990e | 1874 | newoft->lock = 0; |
d410cf58 | 1875 | aim_frame_destroy(newoft); |
37ee990e | 1876 | return -1; |
1877 | } | |
871e2fd0 | 1878 | |
37ee990e | 1879 | newoft->lock = 0; |
1880 | aim_tx_enqueue(sess, newoft); | |
1881 | return 0; | |
d410cf58 | 1882 | #endif |
871e2fd0 | 1883 | } |
37ee990e | 1884 | |
646c6b52 | 1885 | /** |
37ee990e | 1886 | * aim_oft_getfile_end - end a getfile. |
1887 | * @sess: your session | |
1888 | * @conn: the getfile connection | |
1889 | * | |
1890 | * call this before you close the getfile connection if you're on the | |
1891 | * receiving/requesting end. | |
1892 | */ | |
d410cf58 | 1893 | faim_export int aim_oft_getfile_end(aim_session_t *sess, aim_conn_t *conn) |
37ee990e | 1894 | { |
d410cf58 | 1895 | return -EINVAL; |
1896 | #if 0 | |
37ee990e | 1897 | struct command_tx_struct *newoft; |
1898 | struct aim_filetransfer_priv *ft; | |
1899 | ||
646c6b52 | 1900 | if (!sess || !conn || !conn->priv) |
37ee990e | 1901 | return -1; |
871e2fd0 | 1902 | |
646c6b52 | 1903 | if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0204, 0))) { |
1904 | faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
37ee990e | 1905 | return -1; |
1906 | } | |
1907 | ||
1908 | newoft->lock = 1; | |
1909 | ||
1910 | memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
1911 | newoft->hdr.oft.hdr2len = 0x100 - 8; | |
1912 | ||
1913 | if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
1914 | newoft->lock = 0; | |
d410cf58 | 1915 | aim_frame_destroy(newoft); |
37ee990e | 1916 | return -1; |
1917 | } | |
1918 | ||
1919 | ft = (struct aim_filetransfer_priv *)conn->priv; | |
1920 | ft->state = 4; /* no longer wanting data */ | |
1921 | ft->fh.nrecvd = ft->fh.size; | |
1922 | ft->fh.recvcsum = ft->fh.checksum; | |
1923 | ft->fh.flags = 0x21; | |
1924 | ||
646c6b52 | 1925 | if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) { |
37ee990e | 1926 | newoft->lock = 0; |
d410cf58 | 1927 | aim_frame_destroy(newoft); |
37ee990e | 1928 | return -1; |
1929 | } | |
1930 | ||
1931 | newoft->lock = 0; | |
1932 | aim_tx_enqueue(sess, newoft); | |
1933 | ||
1934 | return 0; | |
d410cf58 | 1935 | #endif /* 0 */ |
37ee990e | 1936 | } |
d410cf58 | 1937 |