ewmscp  ..
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
davixCommon Class Reference

#include <davixCommon.h>

Inheritance diagram for davixCommon:
[legend]
Collaboration diagram for davixCommon:
[legend]

Public Member Functions

 davixCommon (davixConfigObject &configObj)
 
bool pathExists (const std::string &path) override
 
std::unique_ptr< const genericStatgetStat (const std::string &path, bool followLink) override
 
- Public Member Functions inherited from pathHandler
virtual ~pathHandler ()=default
 
virtual std::string getXattr (const std::string &, const std::string &)
 

Static Public Member Functions

static void getPassword (const std::string &prompt, std::string &password)
 

Public Attributes

Davix::RequestParams params
 
Davix::DavPosix posix
 

Protected Member Functions

int loginCallbackInner (std::string &login, std::string &password, int count)
 

Static Protected Member Functions

static int loginCallback (void *userdata, const Davix::SessionInfo &info, std::string &login, std::string &password, int count, Davix::DavixError **err)
 

Protected Attributes

Davix::Context context
 
std::string loginName
 
std::string passWord
 

Detailed Description

Definition at line 193 of file davixCommon.h.

Constructor & Destructor Documentation

◆ davixCommon()

davixCommon::davixCommon ( davixConfigObject configObj)

Definition at line 107 of file davixCommon.cpp.

107  :
108  posix(&context) {
109  configObj.apply(params);
110  if ((! configObj.accessConfigured()) && (! configObj.noAuth)) {
111  params.setClientLoginPasswordCallback(loginCallback, this);
113  }
114 }

References davixConfigObject::accessConfigured(), davixConfigObject::apply(), loginCallback(), loginCallbackInner(), loginName, davixConfigObject::noAuth, params, and passWord.

Here is the call graph for this function:

Member Function Documentation

◆ getPassword()

void davixCommon::getPassword ( const std::string &  prompt,
std::string &  password 
)
static

Definition at line 125 of file davixCommon.cpp.

125  {
126  std::cerr << prompt;
127  std::cerr.flush();
128  struct termios old_term, new_term;
129  throwcall::good0(tcgetattr(0, &old_term), "tcgetattr on stdin");
130  new_term = old_term;
131  new_term.c_lflag &= ~ECHO;
132  throwcall::good0(tcsetattr(0, TCSAFLUSH, &new_term), "tcsetattr on stdin");
133  std::cin >> password;
134  throwcall::good0(tcsetattr(0, TCSAFLUSH, &old_term), "tcsetattr on stdin");
135  std::cerr << "\n";
136 }

References throwcall::good0().

Referenced by davixCfgX509::applySingle(), and loginCallbackInner().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStat()

std::unique_ptr< const genericStat > davixCommon::getStat ( const std::string &  path,
bool  followLink 
)
overridevirtual

Implements pathHandler.

Definition at line 185 of file davixCommon.cpp.

186  {
187  errorReport report(__func__, "stat", path);
188  Davix::StatInfo statBuf;
189  if (posix.stat64(&params, path, &statBuf, report)) {
190  report.throwUp();
191  }
192  auto stat = new genericStat();
193  auto prePathPart = path.find("//");
194  if (prePathPart != std::remove_reference<decltype(path)>::type::npos) {
195  prePathPart = path.find("/", prePathPart + 2);
196  }
197  stat->device = std::hash<std::string> {}(path.substr(0, prePathPart));
198  stat->size = statBuf.size;
199  stat->sizeOnDisk = statBuf.size;
200  stat->blksize = 16 * 1024 * 1024;
201  stat->aTime = genericStat::clock_type::time_point(std::chrono::seconds(statBuf.atime));
202  stat->mTime = genericStat::clock_type::time_point(std::chrono::seconds(statBuf.mtime));
203  stat->timeResolution = std::chrono::seconds(1);
204  stat->mode = statBuf.mode;
205  #ifdef DAVIX_API_VERSION
206  #if DAVIX_API_VERSION >= 20160621
207  stat->ownerUid = statBuf.owner;
208  stat->ownerGid = statBuf.group;
209  #endif
210  #endif
211  return std::unique_ptr<const genericStat>(stat);
212 };

References params, posix, and errorReport::throwUp().

Referenced by davixIoCommon::getStat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loginCallback()

int davixCommon::loginCallback ( void *  userdata,
const Davix::SessionInfo &  info,
std::string &  login,
std::string &  password,
int  count,
Davix::DavixError **  err 
)
staticprotected

Definition at line 116 of file davixCommon.cpp.

121  {
122  return static_cast<davixCommon*>(userdata)->loginCallbackInner(login, password, count);
123 }

References loginCallbackInner().

Referenced by davixCommon().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loginCallbackInner()

int davixCommon::loginCallbackInner ( std::string &  login,
std::string &  password,
int  count 
)
protected

Definition at line 138 of file davixCommon.cpp.

140  {
141  if (count < 1) {
142  if (passWord.empty() || loginName.empty()) {
143  std::cerr << "Basic authentication - server is asking for username and password:\n";
144  }
145  } else {
146  std::cerr << "Authentication failure, try again:\n";
147  passWord.clear();
148  loginName.clear();
149  }
150  if (loginName.empty()) {
151  std::cerr << "Login: ";
152  std::cerr.flush();
153  std::cin >> login;
154  if (login.empty()) {
155  login = getenv("USER");
156  std::cerr << "using '" << login << "' as login name\n";
157  }
158  loginName = login;
159  } else {
160  login = loginName;
161  }
162  if (passWord.empty()) {
163  getPassword("Password:", password);
164  passWord = password;
165  } else {
166  password = passWord;
167  }
168  return 0;
169 }

References getPassword(), loginName, and passWord.

Referenced by davixCommon(), and loginCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pathExists()

bool davixCommon::pathExists ( const std::string &  path)
overridevirtual

Implements pathHandler.

Definition at line 174 of file davixCommon.cpp.

174  {
175  errorReport report(__func__, "stat", path);
176  Davix::StatInfo statBuf;
177  if (posix.stat64(&params, path, &statBuf, report)) {
178  if (report->getStatus() == Davix::StatusCode::FileNotFound) {
179  return false;
180  }
181  report.throwUp();
182  }
183  return true;
184 };

References params, posix, and errorReport::throwUp().

Here is the call graph for this function:

Member Data Documentation

◆ context

Davix::Context davixCommon::context
protected

Definition at line 195 of file davixCommon.h.

◆ loginName

std::string davixCommon::loginName
protected

Definition at line 200 of file davixCommon.h.

Referenced by davixCommon(), and loginCallbackInner().

◆ params

Davix::RequestParams davixCommon::params

◆ passWord

std::string davixCommon::passWord
protected

Definition at line 201 of file davixCommon.h.

Referenced by davixCommon(), and loginCallbackInner().

◆ posix

Davix::DavPosix davixCommon::posix

The documentation for this class was generated from the following files:
davixCommon::loginName
std::string loginName
Definition: davixCommon.h:200
davixCommon::context
Davix::Context context
Definition: davixCommon.h:195
genericStat
generic stat abstraction class Used to abstract the variants of the stat structure.
Definition: genericStat.h:12
davixConfigObject::accessConfigured
bool accessConfigured() const
Definition: davixCommon.cpp:103
davixCommon
Definition: davixCommon.h:193
davixCommon::loginCallback
static int loginCallback(void *userdata, const Davix::SessionInfo &info, std::string &login, std::string &password, int count, Davix::DavixError **err)
Definition: davixCommon.cpp:116
davixConfigObject::noAuth
options::single< bool > noAuth
Definition: davixCommon.h:180
davixCommon::getPassword
static void getPassword(const std::string &prompt, std::string &password)
Definition: davixCommon.cpp:125
errorReport
class for easy error handling with davix ensures proper cleanup of the error report when going out of...
Definition: davixCommon.h:12
davixCommon::passWord
std::string passWord
Definition: davixCommon.h:201
davixCommon::posix
Davix::DavPosix posix
Definition: davixCommon.h:198
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40
davixCommon::params
Davix::RequestParams params
Definition: davixCommon.h:197
davixCommon::loginCallbackInner
int loginCallbackInner(std::string &login, std::string &password, int count)
Definition: davixCommon.cpp:138
davixConfigObject::apply
void apply(Davix::RequestParams &params)
Definition: davixCommon.cpp:94