void CSametimeProto::CancelFileTransfer(HANDLE hFt) { mwFileTransfer* ft = (mwFileTransfer*)hFt; CSametimeProto* proto = getProtoFromMwFileTransfer(ft); debugLog(_T("CSametimeProto::CancelFileTransfer() start")); FileTransferClientData* ftcd = (FileTransferClientData*)mwFileTransfer_getClientData(ft); if (ftcd) { while (ftcd && mwFileTransfer_isDone(ftcd->ft)) ftcd = ftcd->next; if (ftcd) mwFileTransfer_cancel(ftcd->ft); } else mwFileTransfer_cancel(ft); }
/** receive a chunk of a file from an inbound file transfer. */ void mwFileTransfer_recv(mwFileTransfer* ft, struct mwOpaque* data) { CSametimeProto* proto = getProtoFromMwFileTransfer(ft); FileTransferClientData* ftcd = (FileTransferClientData*)mwFileTransfer_getClientData(ft); proto->debugLog(_T("mwFileTransfer_recv() start")); DWORD bytes_written; if (!WriteFile(ftcd->hFile, data->data, data->len, &bytes_written, 0)) { proto->debugLog(_T("mwFileTransfer_recv() !WriteFile")); mwFileTransfer_cancel(ft); proto->ProtoBroadcastAck(ftcd->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ftcd->hFt, 0); proto->debugLog(_T("mwFileTransfer_recv() ACKRESULT_FAILED")); } else { mwFileTransfer_ack(ft); // acknowledge chunk PROTOFILETRANSFERSTATUS pfts = { 0 }; pfts.cbSize = sizeof(pfts); pfts.flags = PFTS_UTF; pfts.hContact = ftcd->hContact; if (ftcd->sending == 1) { pfts.flags |= PFTS_SENDING; } pfts.pszFiles = NULL; pfts.totalFiles = 1; pfts.currentFileNumber = 0; pfts.totalBytes = mwFileTransfer_getFileSize(ft); pfts.totalProgress = mwFileTransfer_getSent(ft); pfts.szWorkingDir = ftcd->save_path; pfts.szCurrentFile = (char*)mwFileTransfer_getFileName(ft); pfts.currentFileSize = mwFileTransfer_getFileSize(ft); pfts.currentFileProgress = mwFileTransfer_getSent(ft); pfts.currentFileTime = 0; //? proto->ProtoBroadcastAck(ftcd->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ftcd->hFt, (LPARAM)&pfts); proto->debugLog(_T("mwFileTransfer_recv() ACKRESULT_DATA")); if (mwFileTransfer_isDone(ft)) { proto->ProtoBroadcastAck(ftcd->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ftcd->hFt, 0); proto->debugLog(_T("mwFileTransfer_recv() ACKRESULT_SUCCESS")); } } }
static void recv_channelDestroy(struct mwServiceFileTransfer *srvc, struct mwChannel *chan, struct mwMsgChannelDestroy *msg) { struct mwFileTransferHandler *handler; struct mwFileTransfer *ft; guint32 code; code = msg->reason; g_return_if_fail(srvc->handler != NULL); handler = srvc->handler; ft = mwChannel_getServiceData(chan); g_return_if_fail(ft != NULL); ft->channel = NULL; if(! mwFileTransfer_isDone(ft)) ft_state(ft, mwFileTransfer_CANCEL_REMOTE); mwFileTransfer_close(ft, code); }
/** a file transfer has been closed. Check the status of the file transfer to determine if the transfer was complete or if it had been interrupted */ void mwFileTransfer_closed(mwFileTransfer* ft, guint32 code) { CSametimeProto* proto = getProtoFromMwFileTransfer(ft); FileTransferClientData* ftcd = (FileTransferClientData*)mwFileTransfer_getClientData(ft); proto->debugLog(_T("mwFileTransfer_closed() start")); if (ftcd) { if (ftcd->hFile != INVALID_HANDLE_VALUE) CloseHandle(ftcd->hFile); if (code != mwFileTransfer_SUCCESS || !mwFileTransfer_isDone(ft)) { if (!ftcd->sending) { char fn[MAX_PATH]; if (ftcd->save_path) mir_strcpy(fn, ftcd->save_path); else fn[0] = 0; mir_strcat(fn, mwFileTransfer_getFileName(ft)); DeleteFileA(fn); } if (code == mwFileTransfer_REJECTED) proto->ProtoBroadcastAck(ftcd->hContact, ACKTYPE_FILE, ACKRESULT_DENIED, ftcd->hFt, 0); else proto->ProtoBroadcastAck(ftcd->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ftcd->hFt, 0); if (ftcd->sending) { FileTransferClientData* ftcd_next = ftcd->next; while(ftcd_next) { mwFileTransfer_free((mwFileTransfer*)ftcd_next->ft); FileTransferClientData *ftcd_temp = ftcd_next->next; if (ftcd_next->hFile != INVALID_HANDLE_VALUE) CloseHandle(ftcd_next->hFile); if (ftcd_next->save_path) free(ftcd_next->save_path); if (ftcd_next->buffer) delete[] ftcd_next->buffer; delete ftcd_next; ftcd_next = ftcd_temp; } } else { mwFileTransfer_removeClientData(ft); if (ftcd->save_path) free(ftcd->save_path); if (ftcd->buffer) delete[] ftcd->buffer; delete ftcd; mwFileTransfer_free(ft); } } else { if (ftcd->sending) { // check if we have more files to send... if (ftcd->next) { proto->ProtoBroadcastAck(ftcd->hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ftcd->hFt, 0); mwFileTransfer_offer(ftcd->next->ft); } } else { proto->ProtoBroadcastAck(ftcd->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ftcd->hFt, 0); mwFileTransfer_removeClientData(ft); if (ftcd->save_path) free(ftcd->save_path); if (ftcd->buffer) delete[] ftcd->buffer; delete ftcd; mwFileTransfer_free(ft); } } } }