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