Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TDavixSystem.cxx
Go to the documentation of this file.
1// @(#)root/net:$Id$
2// Author: Adrien Devresse and Fabrizio Furano
3
4/*************************************************************************
5 * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TDavixSystem //
15// //
16// A TSystem specialization for HTTP and WebDAV //
17// It supports HTTP and HTTPS in a number of dialects and options //
18// e.g. S3 is one of them //
19// Other caracteristics come from the full support of Davix, //
20// e.g. full redirection support in any circumstance //
21// //
22// Authors: Adrien Devresse (CERN IT/SDC) //
23// Fabrizio Furano (CERN IT/SDC) //
24// //
25// September 2013 //
26// //
27//////////////////////////////////////////////////////////////////////////
28
29#include "TDavixSystem.h"
30#include "TROOT.h"
31#include "TSocket.h"
32#include "Bytes.h"
33#include "TError.h"
34#include "TBase64.h"
35#include "TVirtualPerfStats.h"
36#include "TDavixFileInternal.h"
37
38#include <errno.h>
39#include <stdlib.h>
40#include <unistd.h>
41#include <fcntl.h>
42#include <davix.hpp>
43#include <sstream>
44#include <string>
45#include <cstring>
46
47
48extern const std::string VERSION;
49extern const std::string gUserAgent;
50
51// The prefix that is used to find the variables in the gEnv
52#define ENVPFX "Davix."
53
55
56using namespace Davix;
57
58extern const char* grid_mode_opt;
59extern const char* ca_check_opt;
60extern const char* s3_seckey_opt;
61extern const char* s3_acckey_opt;
62
63////////////////////////////////////////////////////////////////////////////////
64
66 TSystem(url),
67 d_ptr(new TDavixFileInternal(url, "WEB"))
68{
69 d_ptr->init();
70 SetTitle("WebDAV system administration");
71}
72
73////////////////////////////////////////////////////////////////////////////////
74
76 TSystem(),
77 d_ptr(new TDavixFileInternal("", "WEB"))
78{
79 d_ptr->init();
80 SetTitle("WebDAV system administration");
81}
82
83////////////////////////////////////////////////////////////////////////////////
84
86{
88}
89
90////////////////////////////////////////////////////////////////////////////////
91
93{
94 d_ptr->davixPosix->closedir(static_cast<DAVIX_DIR *>(dirp), NULL);
95 d_ptr->removeDird(dirp);
96}
97
98////////////////////////////////////////////////////////////////////////////////
99
100const char *TDavixSystem::GetDirEntry(void *dirp)
101{
102 struct dirent *dir;
103 DavixError *davixErr = NULL;
104 if (((dir = d_ptr->davixPosix->readdir(static_cast<DAVIX_DIR *>(dirp), &davixErr)) == NULL)
105 && (davixErr != NULL)) {
106 Error("DavixReaddir", "failed to readdir the directory: %s (%d)",
107 davixErr->getErrMsg().c_str(), davixErr->getStatus());
108 DavixError::clearError(&davixErr);
109 }
110 return (dir) ? (dir->d_name) : NULL;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114
115void *TDavixSystem::OpenDirectory(const char *dir)
116{
117 DavixError *davixErr = NULL;
118 DAVIX_DIR *d;
119 if ((d = d_ptr->davixPosix->opendir(d_ptr->davixParam, dir, &davixErr)) == NULL) {
120 Error("DavixOpendir", "failed to opendir the directory: %s (%d)",
121 davixErr->getErrMsg().c_str(), davixErr->getStatus());
122 DavixError::clearError(&davixErr);
123 } else {
124 d_ptr->addDird(d);
125 }
126 return d;
127}
128
129////////////////////////////////////////////////////////////////////////////////
130
131Bool_t TDavixSystem::ConsistentWith(const char * /*path*/, void *dirptr)
132{
133 return (Bool_t) d_ptr->isMyDird(dirptr);
134}
135
136////////////////////////////////////////////////////////////////////////////////
137
139{
140 struct stat st;
141
142 if (!d_ptr->DavixStat(path, &st)) return 1;
143 buf.fDev = 0;
144 buf.fIno = 0;
145 buf.fMode = st.st_mode; // protection (combination of EFileModeMask bits)
146
147 buf.fUid = st.st_uid; // user id of owner
148 buf.fGid = st.st_gid; // group id of owner
149 buf.fSize = st.st_size; // total size in bytes
150 buf.fMtime = st.st_mtime; // modification date
151 buf.fIsLink = kFALSE; // symbolic link
152 buf.fUrl = path; // end point url of file
153
154 return 0;
155}
156
157////////////////////////////////////////////////////////////////////////////////
158
160{
161 (void) path;
162 return kFALSE;
163}
164
165////////////////////////////////////////////////////////////////////////////////
166
167Int_t TDavixSystem::Locate(const char *path, TString &endurl)
168{
169 DavixError *davixErr = NULL;
170 ssize_t ret;
171 ReplicaVec vecRep;
172 DavFile f(*d_ptr->davixContext, Uri(path));
173 if ((ret = f.getAllReplicas(d_ptr->davixParam,
174 vecRep,
175 &davixErr)) < 0) {
176 Error("DavixLocate", "failed to Locate file: %s (%d)",
177 davixErr->getErrMsg().c_str(), davixErr->getStatus());
178 DavixError::clearError(&davixErr);
179 return 1;
180 }
181 if (vecRep.size() > 0) {
182 endurl = vecRep[0].uri.getString().c_str();
183 } else {
184 endurl = path;
185 }
186 if (gDebug > 0)
187 Info("DavixLocate", "Davix Locate %s to %s", path, endurl.Data());
188
189 return 0;
190}
191
192////////////////////////////////////////////////////////////////////////////////
193
195{
196 DavixError *davixErr = NULL;
197 int ret;
198 if ((ret = d_ptr->davixPosix->mkdir(d_ptr->davixParam, dir, 0755, &davixErr)) < 0) {
199 Error("DavixMkdir", "failed to create the directory: %s (%d)",
200 davixErr->getErrMsg().c_str(), davixErr->getStatus());
201 DavixError::clearError(&davixErr);
202 }
203 return ret;
204}
205
206////////////////////////////////////////////////////////////////////////////////
207
208int TDavixSystem::Unlink(const char *path)
209{
210 DavixError *davixErr = NULL;
211 int ret;
212 if ((ret = d_ptr->davixPosix->unlink(d_ptr->davixParam, path, &davixErr)) < 0) {
213 Error("DavixUnlink", "failed to unlink the file: %s (%d)",
214 davixErr->getErrMsg().c_str(), davixErr->getStatus());
215 DavixError::clearError(&davixErr);
216 }
217 return ret;
218}
#define SafeDelete(p)
Definition RConfig.hxx:547
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
const Bool_t kFALSE
Definition RtypesCore.h:92
#define ClassImp(name)
Definition Rtypes.h:364
const char * s3_seckey_opt
const std::string VERSION
const char * ca_check_opt
const char * s3_acckey_opt
const char * grid_mode_opt
const std::string gUserAgent
Int_t gDebug
Definition TROOT.cxx:590
typedef void((*Func_t)())
void addDird(void *fd)
Davix::RequestParams * davixParam
bool isMyDird(void *fd)
Davix::DavPosix * davixPosix
Int_t DavixStat(const char *url, struct stat *st)
Davix::Context * davixContext
void removeDird(void *fd)
virtual Int_t MakeDirectory(const char *dir)
Make a directory.
virtual void * OpenDirectory(const char *dir)
Open a directory. Returns 0 if directory does not exist.
virtual Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
virtual void FreeDirectory(void *dirp)
Free a directory.
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
virtual ~TDavixSystem()
virtual Int_t Locate(const char *path, TString &endurl)
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
virtual Bool_t ConsistentWith(const char *path, void *dirptr)
Check consistency of this helper with the one required by 'path' or 'dirptr'.
TDavixFileInternal * d_ptr
virtual int Unlink(const char *path)
Unlink, i.e.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:893
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:867
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
Abstract base class defining a generic interface to the underlying Operating System.
Definition TSystem.h:266
Int_t fMode
Definition TSystem.h:127
Long64_t fSize
Definition TSystem.h:130
Long_t fDev
Definition TSystem.h:125
TString fUrl
Definition TSystem.h:133
Int_t fGid
Definition TSystem.h:129
Long_t fMtime
Definition TSystem.h:131
Long_t fIno
Definition TSystem.h:126
Bool_t fIsLink
Definition TSystem.h:132
Int_t fUid
Definition TSystem.h:128