56 static const std::string
VERSION =
"0.2.0";
58 static const std::string
gUserAgent =
"ROOT/" + std::string(
gROOT->GetVersion()) +
59 " TDavixFile/" + VERSION +
" davix/" + Davix::version();
62 #define ENVPFX "Davix."
66 using namespace Davix;
85 if (!str)
return false;
87 if (!strcmp(str,
"n") || !strcmp(str,
"no") || !strcmp(str,
"0") || !strcmp(str,
"false"))
return true;
101 old_flag |= (O_CREAT | O_WRONLY | O_TRUNC);
104 old_flag |= (O_RDWR);
117 davix_set_log_level(0);
120 davix_set_log_level(DAVIX_LOG_WARNING);
123 davix_set_log_level(DAVIX_LOG_VERBOSE);
126 davix_set_log_level(DAVIX_LOG_DEBUG);
129 davix_set_log_level(DAVIX_LOG_ALL);
141 char default_proxy[64];
142 const char *genvvar = 0, *genvvar1 = 0;
146 ucert = ukey = genvvar;
148 Info(
"TDavixFile_http_get_ucert",
"Found proxy in gEnv");
153 if (getenv(
"X509_USER_PROXY")) {
155 Info(
"TDavixFile_http_get_ucert",
"Found proxy in X509_USER_PROXY");
156 ucert = ukey = getenv(
"X509_USER_PROXY");
161 snprintf(default_proxy,
sizeof(default_proxy),
"/tmp/x509up_u%d",
164 if (access(default_proxy, R_OK) == 0) {
166 Info(
"TDavixFile_http_get_ucert",
"Found proxy in /tmp");
167 ucert = ukey = default_proxy;
174 if (genvvar || genvvar1) {
176 Info(
"TDavixFile_http_get_ucert",
"Found cert and key in gEnv");
184 if (getenv(
"X509_USER_CERT"))
185 ucert = getenv(
"X509_USER_CERT");
186 if (getenv(
"X509_USER_KEY"))
187 ukey = getenv(
"X509_USER_KEY");
189 if ((ucert.size() > 0) || (ukey.size() > 0)) {
191 Info(
"TDavixFile_http_get_ucert",
"Found cert and key in gEnv");
200 Davix::X509Credential *cert, Davix::DavixError **err)
204 std::string ucert, ukey;
207 if (ucert.empty() || ukey.empty()) {
208 Davix::DavixError::setupError(err,
"TDavixFile",
209 Davix::StatusCode::AuthentificationError,
210 "Could not set the user's proxy or certificate");
213 return cert->loadFromFilePEM(ukey, ucert,
"", err);
242 DavixError *davixErr =
NULL;
245 Error(
"DavixOpen",
"can not open file with davix: %s (%d)",
246 davixErr->getErrMsg().c_str(), davixErr->getStatus());
247 DavixError::clearError(&davixErr);
250 davixPosix->fadvise(fd, 0, 300, Davix::AdviseRandom);
260 DavixError *davixErr =
NULL;
262 Error(
"DavixClose",
"can not to close file with davix: %s (%d)",
263 davixErr->getErrMsg().c_str(), davixErr->getStatus());
264 DavixError::clearError(&davixErr);
272 const char *env_var =
NULL;
275 Info(
"enableGridMode",
" grid mode enabled !");
277 if( ( env_var = getenv(
"X509_CERT_DIR")) ==
NULL){
278 env_var=
"/etc/grid-security/certificates/";
280 davixParam->addCertificateAuthorityPath(env_var);
282 Info(
"enableGridMode",
"Adding CAdir %s", env_var);
290 Info(
"setS3Auth",
" Aws S3 tokens configured");
291 davixParam->setAwsAuthorizationKeys(key, token);
292 davixParam->setProtocol(RequestProtocol::AwsS3);
299 const char *env_var =
NULL, *env_var2 =
NULL;
301 davixParam->setTransparentRedirectionSupport(
true);
307 davixParam->addCertificateAuthorityPath(env_var);
309 Info(
"parseConfig",
"Add CAdir: %s", env_var);
312 bool ca_check_local = !
isno(
gEnv->
GetValue(
"Davix.GSI.CACheck", (
const char *)
"y"));
315 Info(
"parseConfig",
"Setting CAcheck to %s", ((ca_check_local) ? (
"true") : (
"false")));
318 if (((env_var =
gEnv->
GetValue(
"Davix.S3.SecretKey", getenv(
"S3_SECRET_KEY"))) !=
NULL)
319 && ((env_var2 =
gEnv->
GetValue(
"Davix.S3.AccessKey", getenv(
"S3_ACCESS_KEY"))) !=
NULL)) {
320 Info(
"parseConfig",
"Setting S3 SecretKey and AccessKey. Access Key : %s ", env_var2);
321 davixParam->setAwsAuthorizationKeys(env_var, env_var2);
324 env_var =
gEnv->
GetValue(
"Davix.GSI.GridMode", (
const char *)
"y");
334 std::stringstream
ss(option);
336 std::vector<std::string> parsed_options;
338 std::string s3seckey, s3acckey;
340 while (std::getline(ss, item,
' ')) {
341 parsed_options.push_back(item);
344 for (std::vector<std::string>::iterator it = parsed_options.begin(); it < parsed_options.end(); ++it) {
365 if (s3seckey.size() > 0) {
389 DavixError *davixErr =
NULL;
393 Error(
"DavixStat",
"can not stat the file with davix: %s (%d)",
394 davixErr->getErrMsg().c_str(), davixErr->getStatus());
395 DavixError::clearError(&davixErr);
455 Error(
"Seek",
"seeking from end in archive is not (yet) supported");
461 Info(
"Seek",
" move cursor to %lld"
480 Info(
"ReadBuffer",
"%lld bytes of data read sequentially"
481 " (%d requested)", ret, len);
499 Info(
"ReadBuffer",
"%lld bytes of data read from offset"
500 " %lld (%d requested)", ret, pos, len);
512 d_ptr->
davixPosix->fadvise(fd, static_cast<dav_off_t>(offs), static_cast<dav_size_t>(len), Davix::AdviseRandom);
515 Info(
"ReadBufferAsync",
"%d bytes of data prefected from offset"
516 " %lld ", len, offs);
533 Info(
"ReadBuffers",
"%lld bytes of data read from a list of %d buffers",
552 Info(
"WriteBuffer",
"%lld bytes of data write"
553 " %d requested", ret, len);
576 std::vector<void *>::iterator
f = std::find(
dirdVec.begin(),
dirdVec.end(), fd);
593 std::vector<void *>::iterator
f = std::find(
dirdVec.begin(),
dirdVec.end(), fd);
606 Info(
"GetSize",
"file size requested: %lld", (
Long64_t)st.st_size);
637 DavixError *davixErr =
NULL;
642 Error(
"DavixReadBuffer",
"can not read data with davix: %s (%d)",
643 davixErr->getErrMsg().c_str(), davixErr->getStatus());
644 DavixError::clearError(&davixErr);
657 DavixError *davixErr =
NULL;
662 Error(
"DavixWriteBuffer",
"can not write data with davix: %s (%d)",
663 davixErr->getErrMsg().c_str(), davixErr->getStatus());
664 DavixError::clearError(&davixErr);
677 DavixError *davixErr =
NULL;
682 Error(
"DavixPReadBuffer",
"can not read data with davix: %s (%d)",
683 davixErr->getErrMsg().c_str(), davixErr->getStatus());
684 DavixError::clearError(&davixErr);
697 DavixError *davixErr =
NULL;
699 DavIOVecInput in[nbuf];
700 DavIOVecOuput
out[nbuf];
703 for (
Int_t i = 0; i < nbuf; ++i) {
704 in[i].diov_buffer = &buf[lastPos];
705 in[i].diov_offset = pos[i];
706 in[i].diov_size = len[i];
712 Error(
"DavixReadBuffers",
"can not read data with davix: %s (%d)",
713 davixErr->getErrMsg().c_str(), davixErr->getStatus());
714 DavixError::clearError(&davixErr);
static void ConfigureDavixLogLevel()
static const std::string gUserAgent
const char * s3_seckey_opt
const char * open_mode_read
const char * open_mode_update
void Init(Bool_t init)
Initialize a TFile object.
static void TDavixFile_http_get_ucert(std::string &ucert, std::string &ukey)
void setS3Auth(const std::string &key, const std::string &token)
Davix::RequestParams * davixParam
Small helper to keep current directory context.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via HTTP.
TDavixFileInternal * d_ptr
Long64_t DavixReadBuffer(Davix_fd *fd, char *buf, Int_t len)
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
virtual Bool_t WriteBuffer(const char *buffer, Int_t bufferLength)
Write a buffer to the file.
void eventStop(Double_t t, Long64_t len)
set TFile state info
Davix_fd * getDavixFileInstance()
const char * open_mode_create
Long64_t DavixReadBuffers(Davix_fd *fd, char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Davix::DavPosix * davixPosix
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
virtual Long64_t GetSize() const
Returns the current file size.
void Info(const char *location, const char *msgfmt,...)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void Error(const char *location, const char *msgfmt,...)
Int_t DavixStat(const char *url, struct stat *st)
ClassImp(TDavixFile) using namespace Davix
static Context * davix_context_s
Long64_t DavixWriteBuffer(Davix_fd *fd, const char *buf, Int_t len)
Long64_t fEND
Last used byte in file.
virtual Bool_t ReadBufferAsync(Long64_t offs, Int_t len)
static Davix::Context * getDavixInstance()
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
void removeDird(void *fd)
bool isno(const char *str)
virtual void Init(Bool_t create)
Initialize a TFile object.
virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read the nbuf blocks described in arrays pos and len.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
std::vector< void * > dirdVec
const char * grid_mode_opt
static const std::string VERSION
The TTimeStamp encapsulates seconds and ns since EPOCH.
const char * s3_acckey_opt
int configure_open_flag(const std::string &str, int old_flag)
void enableGridMode()
Enable the grid mode The grid Mode configure automatically all grid-CA path, VOMS authentication and ...
typedef void((*Func_t)())
const char * ca_check_opt
static int TDavixFile_http_authn_cert_X509(void *userdata, const Davix::SessionInfo &info, Davix::X509Credential *cert, Davix::DavixError **err)
Long64_t fArchiveOffset
!Offset at which file starts in archive
TDavixFile(const char *url, Option_t *option="", const char *ftitle="", Int_t compress=1)
Open function for TDavixFile.
Long64_t fOffset
!Seek offset cache
Long64_t DavixPReadBuffer(Davix_fd *fd, char *buf, Long64_t pos, Int_t len)
void setCACheck(Bool_t check)
Enable or disable certificate authority check.
void parseParams(Option_t *option)
intput params
Long64_t fBytesRead
Number of bytes read from this file.
Davix::Context * davixContext
const char * open_mode_new