Пример #1
0
int mwFileTransfer_accept(struct mwFileTransfer *ft) {
  struct mwServiceFileTransfer *srvc;
  struct mwFileTransferHandler *handler;
  int ret;

  g_return_val_if_fail(ft != NULL, -1);
  g_return_val_if_fail(ft->channel != NULL, -1);
  g_return_val_if_fail(mwFileTransfer_isPending(ft), -1);
  g_return_val_if_fail(mwChannel_isIncoming(ft->channel), -1);
  g_return_val_if_fail(mwChannel_isState(ft->channel, mwChannel_WAIT), -1);

  g_return_val_if_fail(ft->service != NULL, -1);
  srvc = ft->service;

  g_return_val_if_fail(srvc->handler != NULL, -1);
  handler = srvc->handler;

  ret = mwChannel_accept(ft->channel);

  if(ret) {
    mwFileTransfer_close(ft, ERR_FAILURE);

  } else {
    ft_state(ft, mwFileTransfer_OPEN);
    if(handler->ft_opened)
      handler->ft_opened(ft);
  }

  return ret;
}
Пример #2
0
HANDLE CSametimeProto::AcceptFileTransfer(MCONTACT hContact, HANDLE hFt, char* save_path)
{

	mwFileTransfer* ft = (mwFileTransfer*)hFt;
	CSametimeProto* proto = getProtoFromMwFileTransfer(ft);
	debugLog(_T("CSametimeProto::AcceptFileTransfer() start"));

	FileTransferClientData* ftcd = new FileTransferClientData;
	memset(ftcd, 0, sizeof(FileTransferClientData));
	ftcd->ft = ft;
	ftcd->sending = false;
	ftcd->hFt = hFt;

	if (save_path) // save path
		ftcd->save_path = _strdup(save_path);
	else
		ftcd->save_path = 0;

	mwFileTransfer_setClientData(ft, (gpointer)ftcd, 0);

	char fp[MAX_PATH];
	char* fn = strrchr((char*)mwFileTransfer_getFileName(ft), '\\');
	if (fn) fn++;

	if (ftcd->save_path)
		mir_strcpy(fp, ftcd->save_path);
	else
		fp[0] = 0;

	if (fn) mir_strcat(fp, fn);
	else mir_strcat(fp, mwFileTransfer_getFileName(ft));

	ftcd->hFile = CreateFileA(fp, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0);
	if (ftcd->hFile == INVALID_HANDLE_VALUE) {
		debugLog(_T("CSametimeProto::AcceptFileTransfer() INVALID_HANDLE_VALUE"));
		mwFileTransfer_close(ft, mwFileTransfer_ERROR);
		return 0;
	}

	ftcd->hContact = hContact;

	mwFileTransfer_setClientData(ft, (gpointer)ftcd, 0);

	mwFileTransfer_accept(ft);
	return hFt;
}
Пример #3
0
static void recv_RECEIVED(struct mwFileTransfer *ft,
			  struct mwOpaque *data) {

  struct mwServiceFileTransfer *srvc;
  struct mwFileTransferHandler *handler;
  
  srvc = ft->service;
  handler = srvc->handler;

  if(! ft->remaining)
    ft_state(ft, mwFileTransfer_DONE);

  if(handler->ft_ack)
    handler->ft_ack(ft);

  if(! ft->remaining)
    mwFileTransfer_close(ft, mwFileTransfer_SUCCESS);
}
Пример #4
0
//returns 0 if finished with current file
int SendFileChunk(CSametimeProto* proto, mwFileTransfer* ft, FileTransferClientData* ftcd) {
	DWORD bytes_read;

	if (!ftcd || !ftcd->buffer)
		return 0;

	if (!ReadFile(ftcd->hFile, ftcd->buffer, FILE_BUFF_SIZE, &bytes_read, 0)) {
		proto->debugLog(_T("Sametime closing file transfer (SendFileChunk)"));
		mwFileTransfer_close(ft, mwFileTransfer_SUCCESS);
		return 0;
	}

	mwOpaque o;
	o.data = (unsigned char*)ftcd->buffer;
	o.len = bytes_read;
	mwFileTransfer_send(ft, &o);

	return bytes_read;
}
Пример #5
0
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);
}
Пример #6
0
int mwFileTransfer_offer(struct mwFileTransfer *ft) {
  struct mwServiceFileTransfer *srvc;
  struct mwFileTransferHandler *handler;

  g_return_val_if_fail(ft != NULL, -1);
  g_return_val_if_fail(ft->channel == NULL, -1);
  g_return_val_if_fail(mwFileTransfer_isNew(ft), -1);

  g_return_val_if_fail(ft->service != NULL, -1);
  srvc = ft->service;

  g_return_val_if_fail(srvc->handler != NULL, -1);
  handler = srvc->handler;

  ft_create_chan(ft);
  if(ft->channel) {
    ft_state(ft, mwFileTransfer_PENDING);
  } else {
    ft_state(ft, mwFileTransfer_ERROR);
    mwFileTransfer_close(ft, ERR_FAILURE);
  }

  return 0;
}