示例#1
0
/*
 * Set archive operations.
 */
int
SamrftArchiveOp(
	SamrftImpl_t *rftd,
	char *path,
	const char *ops)
{
	int rc = -1;
	int error;

	if (rftd->remotehost) {
		SendCommand(rftd, "%s %s %s", SAMRFT_CMD_ARCHIVEOP, path, ops);
		if (GetReply(rftd) >= 0) {
			rc = GetArchiveOpReply(rftd, &error);
			if (rc < 0) {
				SetErrno = error;
			}
		}
	} else {
		struct sam_fileops_arg arg;

		arg.path.ptr = path;
		arg.ops.ptr = ops;
		rc = sam_syscall(SC_archive, &arg, sizeof (arg));
	}
	return (rc);
}
示例#2
0
const GetFileListRPC::FileList *
GetFileListRPC::operator()(const std::string &f, bool grouping,
    bool smartGrouping)
{
    debug3 << "Executing GetFileList(" << f.c_str()
           << (grouping?"true":"false") << ", "
           << (smartGrouping?"true":"false") << ", "
           << ") RPC\n";

    // Store the arguments.
    filter = f;
    automaticFileGrouping = grouping;
    smartFileGrouping = smartGrouping;

    // Try to execute the RPC.
    Execute();

    // If the RPC returned an error, throw an exception.
    if(GetReply()->GetStatus() == error)
    {
        EXCEPTION0(GetFileListException);
    }

    return &fileList;
}
示例#3
0
void ReadModule::HandleCommand() {
  int reply_size = -1;
  bool state = false;
  char *reply = GetReply(cmd_socket, state, true, reply_size);
  if (reply == NULL) return;
  std::cout << "HandleCommand: " << std::string(reply, reply_size) << std::endl;
  if (reply_size < 2) std::cerr << "Error: Reply is not large for magic header + command string" << std::endl;
  char magic_value = reply[0];
  reply[reply_size-1] = '\0';
  if (magic_value == 0x01) { // connect to command...
    std::string name = std::string(reply+1);
    int pos = name.find("->");
    if (pos == std::string::npos) {
      std::cerr << "Error: no -> separator in connect command" << std::endl;
      return;
    }
    std::string source = name.substr(0, pos);
    std::string target = name.substr(pos+2); // todo: 
    std::cout << "Connect from " << source << " to " << target << std::endl;
    Connect(source, target);
  } else {
    std::cerr << "Error: Unknown command!" << std::endl;
  }
  SendAck(cmd_socket, true);
  delete [] reply;
}
示例#4
0
void CFtpDialog::ChangeDirectory()
{
	if (fSocket < 0)
	{
		beep();
		return;
	}

	try
	{
		s_printf(fSocketFD, "cwd %s\r\n", fPath);

		GetReply();

		if (*fReply != '2')
			THROW(("Changing directory failed.\n%s", fReply));

		ListDirectory();
	}
	catch (HErr& err)
	{
		err.DoError();
	}

	GetPWD();
} // CFtpDialog::ChangeDirectory
示例#5
0
/*
 * Make directory on remote host.
 */
int
SamrftMkdir(
	SamrftImpl_t *rftd,
	char *dirname,
	SamrftCreateAttr_t *creat)
{
	int rc = 0;
	int error;

	if (rftd->remotehost) {

		SendCommand(rftd, "%s %s %d %d %d", SAMRFT_CMD_MKDIR, dirname,
		    creat->mode, creat->uid, creat->gid);
		if (GetReply(rftd) >= 0) {
			rc = GetMkdirReply(rftd, &error);
			if (rc < 0) {
				SetErrno = error;
			}
		}
	} else {

		if (mkdir(dirname, (creat->mode & S_IAMB)) == 0) {
			/*
			 * If creating a directory on an NFS mount point,
			 * daemon does not have permission to change the
			 * ownership. Ignore chown errors.
			 */
			(void) chown(dirname, creat->uid, creat->gid);
		} else {
			rc = -1;
		}
	}
	return (rc);
}
示例#6
0
/*
 * Get information for file system on remote host.  Set offline flag
 * to include the size of all SAM-FS offline files in the capacity.
 */
int
SamrftStatvfs(
	SamrftImpl_t *rftd,
	char *path,
	boolean_t offlineFiles,
	struct statvfs64 *buf)
{
	int error;
	int rc = -1;

	if (rftd->remotehost) {
		SendCommand(rftd, "%s %s %d", SAMRFT_CMD_STATVFS,
		    path, offlineFiles);
		if (GetReply(rftd) >= 0) {
			rc = GetStatvfsReply(rftd, buf, &error);
		}
	} else {
		fsize_t offlineFileSize;

		rc = statvfs64(path, buf);
		if (rc == 0 && (strcmp(buf->f_basetype, "samfs") == 0) &&
		    offlineFiles == B_TRUE) {
			offlineFileSize = DiskVolsOfflineFiles(path);
			/*
			 * Adjust capacity to include size of offline files.
			 */
			buf->f_blocks += offlineFileSize / buf->f_frsize;
		}
	}
	return (rc);
}
示例#7
0
/*
 * Get information for file on remote host.
 */
int
SamrftStat(
	SamrftImpl_t *rftd,
	char *filename,
	SamrftStatInfo_t *buf)
{
	int error;
	int rc = -1;

	if (rftd->remotehost) {
		SendCommand(rftd, "%s %s", SAMRFT_CMD_STAT, filename);
		if (GetReply(rftd) >= 0) {
			rc = GetStatReply(rftd, buf, &error);
		}
	} else {
		struct stat64 sb;

		rc = stat64(filename, &sb);
		if (rc == 0) {
			buf->mode = sb.st_mode;
			buf->uid  = sb.st_uid;
			buf->gid  = sb.st_gid;
			buf->size = sb.st_size;
		}
	}
	return (rc);
}
示例#8
0
/*
 * Move read/write file pointer on remote host.
 */
int
SamrftSeek(
	SamrftImpl_t *rftd,
	off64_t setpos,
	int whence,
	off64_t *offset)
{
	int rc = -1;
	int error;

	if (rftd->remotehost) {
		SendCommand(rftd, "%s %lld %d",
		    SAMRFT_CMD_SEEK, setpos, whence);
		if (GetReply(rftd) >= 0) {
			rc = GetSeekReply(rftd, offset, &error);
			if (rc < 0) {
				SetErrno = error;
			}
		}
	} else {
		*offset = lseek64(rftd->fd, setpos, whence);
		if (*offset != -1) {
			rc = 0;
		}
	}
	return (rc);
}
示例#9
0
/*
 * Load removable-media volume on remote host.  Parameter attr
 * is a pointer to a sam_rminfo structure describing information
 * about the removable-media to be loaded.
 */
int
SamrftLoadVol(
	SamrftImpl_t *rftd,
	struct sam_rminfo *attr,
	int oflag)
{
	int error;
	int rc = -1;

	Trace(TR_RFT, "Samrft [%d] load volume %s.%s %d",
	    traceRftd(rftd), attr->media, attr->section[0].vsn, oflag);

	/*
	 * If first open following connect, initialize data ports.
	 */
	if (rftd->crew == NULL) {
		if (initDataPorts(rftd) < 0) {
			return (rc);
		}
	}

	SendCommand(rftd, "%s %d %s %s %s %s %s %d", SAMRFT_CMD_LOADVOL,
	    attr->flags, attr->file_id, attr->owner_id, attr->group_id,
	    attr->media, attr->section[0].vsn, oflag);

	if (GetReply(rftd) >= 0) {
		rc = GetLoadVolReply(rftd, &error);
	}
	return (rc);
}
示例#10
0
/*
 * Close directory on remote host.
 */
void
SamrftClosedir(
	SamrftImpl_t *rftd,
	int dirp)
{
	SendCommand(rftd, "%s %d", SAMRFT_CMD_CLOSEDIR, dirp);
	(void) GetReply(rftd);
}
示例#11
0
	void Handle(const CString& sNick) {
		if (m_Messaged.HasItem(sNick))
			return;

		if (m_pUser->IsUserAttached())
			return;

		m_Messaged.AddItem(sNick);
		PutIRC("PRIVMSG " + sNick + " :" + GetReply());
	}
示例#12
0
void TCPClientThread::PushReply() {
  if (!data_waiting)
    return ;  // Nothing to push

  GetReply();  // Wait for request to finish.

  reply = new ServerToClientReply(reply); // Create new and push old.
  data_waiting = false;
  _RPT0(0, "TCPClient: Pushed reply.\n");
}
示例#13
0
/*
 * Write to file on remote host.
 */
size_t
SamrftWrite(
	SamrftImpl_t *rftd,
	void *buf,
	size_t nbytes)
{
	int rc;
	int error;
	size_t bytes_written;

#if 0
	Trace(TR_RFT, "Samrft [%d] write %d", fileno(rftd->cin), nbytes);
#endif

	if (rftd->remotehost) {
		/*
		 * Send command.  Used as information by client to
		 * start reading data sockets.  A reply is not expected until
		 * the data transfer has completed.
		 */
		SendCommand(rftd, "%s %d", SAMRFT_CMD_SEND, nbytes);

		rc = SendData(rftd, buf, nbytes);

		if (GetReply(rftd) >= 0) {
			rc = GetSendReply(rftd, &error);
			if (rc < 0) {
				if (error == 0) {
					/* Short write failure. */
					SetErrno = ENOSPC;
				} else {
					SetErrno = error;
				}
				bytes_written = (long)-1;
			} else {
				bytes_written = nbytes;
			}
		}
	} else {
		/*
		 * Write to local file.
		 */
		bytes_written = write(rftd->fd, buf, nbytes);
		if (bytes_written != nbytes && errno == 0) {
			/* Short write failure. */
			SetErrno = ENOSPC;
		}
	}

#if 0
	Trace(TR_RFT, "Samrft [%d] write complete %d",
	    traceRftd(rftd), bytes_written);
#endif
	return (bytes_written);
}
//
// Calls each of the Get functions.
//
void CAccessDialog::GetAll(Access_Spec * spec)
{
	spec->size = GetSize();
	spec->of_size = GetAccess();
	spec->reads = GetReads();
	spec->random = GetRandom();
	spec->delay = GetDelay();
	spec->burst = GetBurst();
	spec->align = GetAlign();
	spec->reply = GetReply();
}
示例#15
0
/*
 * Remove directory on remote host.
 */
int
SamrftRmdir(
	SamrftImpl_t *rftd,
	char *dirname)
{
	int rc;

	SendCommand(rftd, "%s %s", SAMRFT_CMD_RMDIR, dirname);
	rc = GetReply(rftd);
	return (rc);
}
//
// User selected "No Reply" radio button - disable reply size edit boxes, other stuff
//
void CAccessDialog::OnRNoReply()
{
	// Get the current reply size.
	DWORD old_reply = GetReply();

	// Disable the reply controls.
	EnableMKBControls(&reply_controls, FALSE);
	// Set the reply size in the access spec to "none".
	SetReply(0);
	// Set the (disabled) reply size controls to the last value shown.
	SetMKBSpinners(&reply_controls, old_reply);
}
示例#17
0
bool ReadModule::ReceiveAck(zmq::socket_t *s, bool & state, bool blocking) {
  int reply_size = 0;
  char *reply = GetReply(s, state, blocking, reply_size);
  if (reply == NULL) return false;
  std::string req = std::string(reply);
  delete [] reply;
  if (req.find("ACK") != std::string::npos) {
    if (debug) std::cout << "Got ACK, thanks!" << std::endl;
    return true;
  }
  std::cerr << "Error: got \"" << req << "\", no ACK, state compromised" << std::endl;
  return false;
}
示例#18
0
/*
 * Check if mount point on remote host is available.
 */
int
SamrftIsMounted(
	SamrftImpl_t *rftd,
	char *mount_point)
{
	int mounted = 0;

	SendCommand(rftd, "%s %s", SAMRFT_CMD_ISMOUNTED, mount_point);
	if (GetReply(rftd) >= 0) {
		mounted = GetIsMountedReply(rftd);
	}
	return (mounted);
}
示例#19
0
	virtual void OnModCommand(const CString& sCommand) {
		const CString& sCmd = sCommand.Token(0);

		if (sCmd.Equals("SHOW")) {
			PutModule("Current reply is: " + GetNV("Reply")
					+ " (" + GetReply() + ")");
		} else if (sCmd.Equals("SET")) {
			SetReply(sCommand.Token(1, true));
			PutModule("New reply set");
		} else {
			PutModule("Available commands are:");
			PutModule("Show        - Displays the current query reply");
			PutModule("Set <reply> - Sets a new reply");
		}
	}
示例#20
0
	void Handle(const CString& sNick) {
		CIRCSock *pIRCSock = GetUser()->GetIRCSock();
		if (!pIRCSock)
			// WTF?
			return;
		if (sNick == pIRCSock->GetNick())
			return;
		if (m_Messaged.HasItem(sNick))
			return;

		if (m_pUser->IsUserAttached())
			return;

		m_Messaged.AddItem(sNick);
		PutIRC("PRIVMSG " + sNick + " :" + GetReply());
	}
示例#21
0
/*
 * Open a disk file on remote host.
 */
int
SamrftOpen(
	SamrftImpl_t *rftd,
	char *filename,
	int oflag,
	SamrftCreateAttr_t *creat)
{
	int rc;
	int error;

	Trace(TR_RFT, "Samrft [%d] open file %s %d %x",
	    traceRftd(rftd), filename, oflag, creat);

	/*
	 * If first open following connect, initialize data ports.
	 */
	if (rftd->crew == NULL) {
		if (initDataPorts(rftd) < 0) {
			return (-1);
		}
	}

	if (rftd->remotehost) {
		if (creat) {
			SendCommand(rftd, "%s %s %d %d %d %d %d",
			    SAMRFT_CMD_OPEN, filename, oflag,
			    TRUE, creat->mode, creat->uid, creat->gid);
		} else {
			SendCommand(rftd, "%s %s %d %d",
			    SAMRFT_CMD_OPEN, filename, oflag,
			    FALSE);
		}
		if (GetReply(rftd) >= 0) {
			rc = GetOpenReply(rftd, &error);
			if (rc < 0) {
				SetErrno = error;
			}
		}
	} else {
		/*
		 * Open file on local machine.
		 */
		rc = openLocalFile(rftd, filename, oflag, creat);
	}

	return (rc);
}
示例#22
0
/*
 * Unlink file or directory on local or remote host.
 */
int
SamrftUnlink(
	SamrftImpl_t *rftd,
	char *name
)
{
	int rc;

	if (rftd->remotehost) {
		SendCommand(rftd, "%s %s", SAMRFT_CMD_UNLINK, name);
		rc = GetReply(rftd);
	} else {
		rc = unlink(name);
	}

	return (rc);
}
示例#23
0
/*
 * Position removable-media on remote host.
 */
int
SamrftSeekVol(
	SamrftImpl_t *rftd,
	int block)
{
	int error;
	int rc = -1;

	Trace(TR_RFT, "Samrft [%d] seek vol %d", traceRftd(rftd), block);

	SendCommand(rftd, "%s %d", SAMRFT_CMD_SEEKVOL, block);

	if (GetReply(rftd) >= 0) {
		rc = GetSeekVolReply(rftd, &error);
	}
	return (rc);
}
示例#24
0
/*
 * Unload removable-media volume on remote host.
 */
int
SamrftUnloadVol(
	SamrftImpl_t *rftd,
	struct sam_ioctl_rmunload *unload)
{
	int error;
	int rc = -1;

	Trace(TR_RFT, "Samrft [%d] unload volume %d",
	    traceRftd(rftd), unload->flags);

	SendCommand(rftd, "%s %d", SAMRFT_CMD_UNLOADVOL, unload->flags);

	if (GetReply(rftd) >= 0) {
		rc = GetUnloadVolReply(rftd, &unload->position, &error);
	}
	return (rc);
}
示例#25
0
/*
 * Get removable-media information on remote host.
 */
int
SamrftGetVolInfo(
	SamrftImpl_t *rftd,
	struct sam_rminfo *getrm,
	int *eq)
{
	int error;
	int rc = -1;

	Trace(TR_RFT, "Samrft [%d] get volinfo", traceRftd(rftd));

	SendCommand(rftd, "%s", SAMRFT_CMD_GETVOLINFO);

	if (GetReply(rftd) >= 0) {
		rc = GetVolInfoReply(rftd, getrm, eq, &error);
	}
	return (rc);
}
示例#26
0
/*
 * Accumulate space used for selected path.  Space used is calculated
 * by walking the entire path and stat each file.  This method will
 * accumulate space used for online and offline files.
 */
int
SamrftSpaceUsed(
	SamrftImpl_t *rftd,
	char *path,
	fsize_t *used)
{
	int error;
	int rc = -1;

	if (rftd->remotehost) {
		SendCommand(rftd, "%s %s", SAMRFT_CMD_SPACEUSED, path);
		if (GetReply(rftd) >= 0) {
			rc = GetSpaceUsedReply(rftd, used, &error);
		}
	} else {
		*used = DiskVolsAccumSpaceUsed(path);
	}
	return (rc);
}
示例#27
0
/*
 *	Read from file on remote host.
 */
size_t
SamrftRead(
	SamrftImpl_t *rftd,
	void *buf,
	size_t nbytes)
{
	int rc;
	int error;
	size_t bytes_read;

#if 0
	Trace(TR_RFT, "Samrft [%d] read %d", traceRftd(rftd), nbytes);
#endif

	if (rftd->remotehost) {

		SendCommand(rftd, "%s %d", SAMRFT_CMD_RECV, nbytes);

		rc = ReceiveData(rftd, buf, nbytes);

		if (GetReply(rftd) >= 0) {
			rc = GetRecvReply(rftd, &error);
			if (rc < 0) {
				SetErrno = error;
				bytes_read = (long)-1;
			} else {
				bytes_read = nbytes;
			}
		}
	} else {
		/*
		 * Read data from local file.
		 */
		bytes_read = read(rftd->fd, buf, nbytes);
	}

#if 0
	Trace(TR_RFT, "Samrft [%d] read complete %d",
	    traceRftd(rftd), bytes_read);
#endif

	return (bytes_read);
}
示例#28
0
/*
 * Open directory on remote host.
 */
int
SamrftOpendir(
	SamrftImpl_t *rftd,
	char *dirname,
	int *dirp)
{
	int rc = -1;
	int error;

	SendCommand(rftd, "%s %s", SAMRFT_CMD_OPENDIR, dirname);
	if (GetReply(rftd) >= 0) {
		rc = GetOpendirReply(rftd, dirp, &error);
		if (rc < 0) {
			SetErrno = error;
		}
	}

	return (rc);
}
示例#29
0
/*
 * Read directory on remote host.
 */
int
SamrftReaddir(
	SamrftImpl_t *rftd,
	int dirp,
	SamrftReaddirInfo_t *dir_info)
{
	int rc = -1;
	int error;

	SendCommand(rftd, "%s %d", SAMRFT_CMD_READDIR, dirp);
	if (GetReply(rftd) >= 0) {
		rc = GetReaddirReply(rftd, dir_info, &error);
		if (rc < 0) {
			SetErrno = error;
		}
	}

	return (rc);
}
示例#30
0
int* ReadModule::readInput(bool blocking) {
  pthread_mutex_lock(&cmdMutex);
  int reply_size = -1;
  char *reply = GetReply(portInputIn.sock, portInputIn.ready, blocking, reply_size);
  if (!portInputIn.ready) {
    delete [] reply;
    pthread_mutex_unlock(&cmdMutex);
    return NULL;
  }
  if (reply == NULL) {
    pthread_mutex_unlock(&cmdMutex);
    return NULL;
  }
  SendAck(portInputIn.sock, portInputIn.ready);
  pthread_mutex_unlock(&cmdMutex);
  if (reply_size < 1) std::cerr << "Error: Reply is not large enough to store a value!" << std::endl;
  std::stringstream ss; ss.clear(); ss.str("");
  ss << std::string(reply);
  ss >> portInputValue;
  delete [] reply;
  return &portInputValue;
}