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