ewmscp  ..
Classes | Public Member Functions | Static Private Attributes | List of all members
inputHandler::libssh Class Reference

#include <inputHandlerLibssh.h>

Inheritance diagram for inputHandler::libssh:
[legend]
Collaboration diagram for inputHandler::libssh:
[legend]

Classes

class  readerLibssh
 
class  SftpDirectory
 

Public Member Functions

 libssh ()
 
 ~libssh () override=default
 
std::unique_ptr< readernewReader (const std::string &aPath, copyRequest::stateType &state, const genericStat &inititalStat) override
 get a reader for the file at path More...
 
bool readLinkTarget (const std::string &path, std::vector< char > &target) override
 read link target from a symlink More...
 
std::unique_ptr< DirectorygetDirectory (const std::string &path) override
 
- Public Member Functions inherited from inputHandler::base
virtual ~base () override=default
 
virtual std::unique_ptr< acl::listgetAclData (const std::string &)
 
- Public Member Functions inherited from pathHandler
virtual ~pathHandler ()=default
 
virtual std::string getXattr (const std::string &, const std::string &)
 
- Public Member Functions inherited from libsshCommon
void reconnectSessions ()
 
template<typename T >
std::unique_ptr< T, void(*)(T *)> getUniquePtr (T *obj, void(*deleter)(T *))
 
 libsshCommon (sshOptions &aOpt)
 
 ~libsshCommon () override
 
bool pathExists (const std::string &path) override
 
std::unique_ptr< const genericStatgetStat (const std::string &path, bool followLink) override
 
const sftp_statvfs_struct & getVfsStat (const std::string &path)
 

Static Private Attributes

static factoryTemplate< libsshfactory
 

Additional Inherited Members

- Static Public Member Functions inherited from inputHandler::base
static basenewHandler (const std::string &name)
 create an instance of an inputHandler, select by name More...
 
template<class T >
static void addAllowedNamesToOption (T &option)
 
- Public Attributes inherited from libsshCommon
ssh_session session
 
sftp_session sftp
 
- Protected Member Functions inherited from inputHandler::base
 base ()=default
 
- Protected Member Functions inherited from libsshCommon
void openSessions ()
 
void closeSessions ()
 
- Static Protected Member Functions inherited from inputHandler::base
static std::map< std::string, factoryClass * > & getFactoryMap ()
 
- Protected Attributes inherited from libsshCommon
sshOptionsopt
 
bool reconnecting
 

Detailed Description

Definition at line 14 of file inputHandlerLibssh.h.

Constructor & Destructor Documentation

◆ libssh()

inputHandler::libssh::libssh ( )

Definition at line 20 of file inputHandlerLibssh.cpp.

20  :
22  }

◆ ~libssh()

inputHandler::libssh::~libssh ( )
overridedefault

Member Function Documentation

◆ getDirectory()

std::unique_ptr< base::Directory > inputHandler::libssh::getDirectory ( const std::string &  path)
overridevirtual

Implements inputHandler::base.

Definition at line 194 of file inputHandlerLibssh.cpp.

194  {
195  return std::unique_ptr<Directory>(new SftpDirectory(*this, path));
196  }

◆ newReader()

std::unique_ptr< base::reader > inputHandler::libssh::newReader ( const std::string &  path,
copyRequest::stateType state,
const genericStat inititalStat 
)
overridevirtual

get a reader for the file at path

Returns
unique ptr to a file reader.
Exceptions
std::system_errorif file can't be opened File will be closed when the pointer goes out of scope.
Parameters
[in]path[in] path to the file to be opened for reading
[in,out]state[in,out] state may be set to vanished if the file does not exist
[in]inititalStat[in] genericStat data of the file encountered before reading, needed for checking unchangedness at the end

Implements inputHandler::base.

Definition at line 24 of file inputHandlerLibssh.cpp.

26  {
27  return std::unique_ptr<base::reader>(new readerLibssh(aPath,
28  *this,
29  state,
30  inititalStat));
31  }

◆ readLinkTarget()

bool inputHandler::libssh::readLinkTarget ( const std::string &  ,
std::vector< char > &   
)
overridevirtual

read link target from a symlink

Parameters
[in]pathis the path to the link
[in,out]targetis a vector that the link target gets written into, must be large enough
Returns
true if link could be read, false if the link does not exist
Exceptions
std::system_errorif the link could not be read
std::runtime_errorif the target size is larger than target.size()

Reimplemented from inputHandler::base.

Definition at line 34 of file inputHandlerLibssh.cpp.

35  {
36  auto targetString = sftp_readlink(sftp, path.c_str());
37  if (targetString == nullptr && sftp_get_error(sftp) == SSH_FX_NO_SUCH_FILE) {
38  return false;
39  }
40  throwcall::sftp::badval(targetString, nullptr, *this, "could not read link ", path);
41  auto linklength = strlen(targetString);
42  if (linklength >= target.size()) {
43  ssh_string_free_char(targetString);
44  throw std::runtime_error("link size increased after stat for " + path);
45  }
46  for (auto c = targetString; *c; c++) {
47  target.at(c - targetString) = *c;
48  }
49  ssh_string_free_char(targetString);
50  target[linklength] = '\0';
51 
52  return true;
53  }

References throwcall::sftp::badval(), and libsshCommon::sftp.

Here is the call graph for this function:

Member Data Documentation

◆ factory

factoryTemplate<libssh> inputHandler::libssh::factory
staticprivate

Definition at line 15 of file inputHandlerLibssh.h.


The documentation for this class was generated from the following files:
inputHandler::inputConfig
static daosFsCommon::daosOptions inputConfig("daosFsIn")
libsshCommon::sftp
sftp_session sftp
Definition: libsshCommon.h:28
throwcall::sftp::badval
T badval(T call, t badvalue, libsshCommon &handler, const Args &... args)
Definition: libsshCommon.h:82
libsshCommon::libsshCommon
libsshCommon(sshOptions &aOpt)
Definition: libsshCommon.cpp:113