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