- ft->state = 0;
- if (aim_recv(conn->fd, listing, ft->fh.size) != ft->fh.size)
- faimdprintf(sess, 2, "OFT get: file %s was short. (0x%lx)\n", ft->fh.name, ft->fh.size);
-
- if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x120b, 0))) {
- faimdprintf(sess, 2, "faim: aim_get_command_rendezvous: getfile listing: tx_new OFT failed\n");
- faim_mutex_unlock(&conn->active);
- free(listing);
- aim_conn_close(conn);
- return -1;
- }
-
- newoft->lock = 1;
-
- memcpy(newoft->hdr.oft.magic, "OFT2", 4);
- newoft->hdr.oft.hdr2len = 0x100 - 8;
-
- /* Protocol BS - set nrecvd to size of listing, recvcsum to
- listing checksum, flags to 0 */
-
- ft->fh.nrecvd = ft->fh.size;
- ft->fh.recvcsum = ft->fh.checksum;
- ft->fh.flags = 0;
-
- if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) {
- newoft->lock = 0;
- aim_frame_destroy(newoft);
- free(listing);
- faim_mutex_unlock(&conn->active);
- return -1;
- }
-
- if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh))))
- faimdprintf(sess, 2, "eek! bh fail listing\n");
-
- /* send the 120b */
- newoft->lock = 0;
- aim_tx_enqueue(sess, newoft);
- if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTING)) )
- ret = userfunc(sess, NULL, conn, ft, listing);
-
- faim_mutex_unlock(&conn->active);
- free(listing);
- return ret;
- }
- if (ft->state == 3) {
- /* waiting on file data */
- if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECEIVE)) ) {
- faim_mutex_unlock(&conn->active);
- return userfunc(sess, NULL, conn, ft);
- }
- faim_mutex_unlock(&conn->active);
- return 0;
- }
- if(ft->state == 4) {
- if( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILESTATE4)) ) {
- faim_mutex_unlock(&conn->active);
- return userfunc(sess, NULL, conn);
- }
- faim_mutex_unlock(&conn->active);
- aim_conn_close(conn);
- return 0;
- }
- }
-
- if ( (hdrlen = aim_recv(conn->fd, hdrbuf1, 6)) < 6) {
- faimdprintf(sess, 2, "faim: rend: read error (fd: %i) %02x%02x%02x%02x%02x%02x (%i)\n",
- conn->fd, hdrbuf1[0],hdrbuf1[1],hdrbuf1[2],hdrbuf1[3],hdrbuf1[4],hdrbuf1[5],hdrlen);
- faim_mutex_unlock(&conn->active);
- if (hdrlen < 0)
- perror("read");
- else { /* disconnected */
- char *screenname = NULL;
- int ret;
- struct aim_msgcookie_t *cook;
-
- switch(conn->subtype) {
- case AIM_CONN_SUBTYPE_OFT_DIRECTIM: {
- struct aim_directim_priv *priv = NULL;
- if (!(priv = (struct aim_directim_priv *)conn->priv) )
- return -1;
-
- screenname = strdup(priv->sn);
-
- cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTIM);
- aim_cookie_free(sess, cook);
- if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT)) ) {
- aim_conn_close(conn);
- ret = userfunc(sess, NULL, conn, screenname);
- free(screenname);
- return ret;
- }
- break;
- }
- case AIM_CONN_SUBTYPE_OFT_GETFILE: {
- struct aim_filetransfer_priv *priv;
- if (!(priv = (struct aim_filetransfer_priv *)conn->priv))
- return -1;
- screenname = strdup(priv->sn);
-
- cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTGET);
-
- aim_cookie_free(sess, cook);
-
- if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT)) ) {
- aim_conn_close(conn);
- ret = userfunc(sess, NULL, conn, screenname);
- free(screenname);
- return ret;
- }
- break;
- }
- case AIM_CONN_SUBTYPE_OFT_SENDFILE: {
- struct aim_filetransfer_priv *priv;
- if (!(priv = (struct aim_filetransfer_priv *)conn->priv))
- return -1;
-
- screenname = strdup(priv->sn);
-
- cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTSEND);
- aim_cookie_free(sess, cook);
- if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_SENDFILEDISCONNECT)) ) {
- aim_conn_close(conn);
- ret = userfunc(sess, NULL, conn, screenname);
- free(screenname);
- return ret;
- }
- break;
- }
- }
-
- aim_conn_close(conn);
- return -1;
- }
- }