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