Example #1
0
static void stop(struct mwServiceFileTransfer *srvc) {
  while(srvc->transfers) {
    mwFileTransfer_free(srvc->transfers->data);
  }

  mwService_stopped(MW_SERVICE(srvc));
}
Example #2
0
/** 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);
			}
		}
	}
}