Logo ROOT  
Reference Guide
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 "TSystem.h"
35#include "TEnv.h"
36#include "TBase64.h"
37#include "TVirtualPerfStats.h"
38#include "TDavixFileInternal.h"
39#include "TSocket.h"
40
41#include <errno.h>
42#include <stdlib.h>
43#include <unistd.h>
44#include <fcntl.h>
45#include <davix.hpp>
46#include <sstream>
47#include <string>
48#include <cstring>
49
50
51extern const std::string VERSION;
52extern const std::string gUserAgent;
53
54// The prefix that is used to find the variables in the gEnv
55#define ENVPFX "Davix."
56
58
59using namespace Davix;
60
61extern const char* grid_mode_opt;
62extern const char* ca_check_opt;
63extern const char* s3_seckey_opt;
64extern const char* s3_acckey_opt;
65
66////////////////////////////////////////////////////////////////////////////////
67
69 TSystem(url),
70 d_ptr(new TDavixFileInternal(url, "WEB"))
71{
72 d_ptr->init();
73 SetTitle("WebDAV system administration");
74}
75
76////////////////////////////////////////////////////////////////////////////////
77
79 TSystem(),
80 d_ptr(new TDavixFileInternal("", "WEB"))
81{
82 d_ptr->init();
83 SetTitle("WebDAV system administration");
84}
85
86////////////////////////////////////////////////////////////////////////////////
87
89{
91}
92
93////////////////////////////////////////////////////////////////////////////////
94
96{
97 d_ptr->davixPosix->closedir(static_cast<DAVIX_DIR *>(dirp), NULL);
98 d_ptr->removeDird(dirp);
99}
100
101////////////////////////////////////////////////////////////////////////////////
102
103const char *TDavixSystem::GetDirEntry(void *dirp)
104{
105 struct dirent *dir;
106 DavixError *davixErr = NULL;
107 if (((dir = d_ptr->davixPosix->readdir(static_cast<DAVIX_DIR *>(dirp), &davixErr)) == NULL)
108 && (davixErr != NULL)) {
109 Error("DavixReaddir", "failed to readdir the directory: %s (%d)",
110 davixErr->getErrMsg().c_str(), davixErr->getStatus());
111 DavixError::clearError(&davixErr);
112 }
113 return (dir) ? (dir->d_name) : NULL;
114}
115
116////////////////////////////////////////////////////////////////////////////////
117
118void *TDavixSystem::OpenDirectory(const char *dir)
119{
120 DavixError *davixErr = NULL;
121 DAVIX_DIR *d;
122 if ((d = d_ptr->davixPosix->opendir(d_ptr->davixParam, dir, &davixErr)) == NULL) {
123 Error("DavixOpendir", "failed to opendir the directory: %s (%d)",
124 davixErr->getErrMsg().c_str(), davixErr->getStatus());
125 DavixError::clearError(&davixErr);
126 } else {
127 d_ptr->addDird(d);
128 }
129 return d;
130}
131
132////////////////////////////////////////////////////////////////////////////////
133
134Bool_t TDavixSystem::ConsistentWith(const char * /*path*/, void *dirptr)
135{
136 return (Bool_t) d_ptr->isMyDird(dirptr);
137}
138
139////////////////////////////////////////////////////////////////////////////////
140
142{
143 struct stat st;
144
145 if (!d_ptr->DavixStat(path, &st)) return 1;
146 buf.fDev = 0;
147 buf.fIno = 0;
148 buf.fMode = st.st_mode; // protection (combination of EFileModeMask bits)
149
150 buf.fUid = st.st_uid; // user id of owner
151 buf.fGid = st.st_gid; // group id of owner
152 buf.fSize = st.st_size; // total size in bytes
153 buf.fMtime = st.st_mtime; // modification date
154 buf.fIsLink = kFALSE; // symbolic link
155 buf.fUrl = path; // end point url of file
156
157 return 0;
158}
159
160////////////////////////////////////////////////////////////////////////////////
161
163{
164 (void) path;
165 return kFALSE;
166}
167
168////////////////////////////////////////////////////////////////////////////////
169
170Int_t TDavixSystem::Locate(const char *path, TString &endurl)
171{
172 DavixError *davixErr = NULL;
173 ssize_t ret;
174 ReplicaVec vecRep;
175 DavFile f(*d_ptr->davixContext, Uri(path));
176 if ((ret = f.getAllReplicas(d_ptr->davixParam,
177 vecRep,
178 &davixErr)) < 0) {
179 Error("DavixLocate", "failed to Locate file: %s (%d)",
180 davixErr->getErrMsg().c_str(), davixErr->getStatus());
181 DavixError::clearError(&davixErr);
182 return 1;
183 }
184 if (vecRep.size() > 0) {
185 endurl = vecRep[0].uri.getString().c_str();
186 } else {
187 endurl = path;
188 }
189 if (gDebug > 0)
190 Info("DavixLocate", "Davix Locate %s to %s", path, endurl.Data());
191
192 return 0;
193}
194
195////////////////////////////////////////////////////////////////////////////////
196
198{
199 DavixError *davixErr = NULL;
200 int ret;
201 if ((ret = d_ptr->davixPosix->mkdir(d_ptr->davixParam, dir, 0755, &davixErr)) < 0) {
202 Error("DavixMkdir", "failed to create the directory: %s (%d)",
203 davixErr->getErrMsg().c_str(), davixErr->getStatus());
204 DavixError::clearError(&davixErr);
205 }
206 return ret;
207}
208
209////////////////////////////////////////////////////////////////////////////////
210
211int TDavixSystem::Unlink(const char *path)
212{
213 DavixError *davixErr = NULL;
214 int ret;
215 if ((ret = d_ptr->davixPosix->unlink(d_ptr->davixParam, path, &davixErr)) < 0) {
216 Error("DavixUnlink", "failed to unlink the file: %s (%d)",
217 davixErr->getErrMsg().c_str(), davixErr->getStatus());
218 DavixError::clearError(&davixErr);
219 }
220 return ret;
221}
#define SafeDelete(p)
Definition: RConfig.hxx:550
#define d(i)
Definition: RSha256.hxx:102
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
#define ClassImp(name)
Definition: Rtypes.h:365
R__EXTERN Int_t gDebug
Definition: Rtypes.h:91
const char * s3_seckey_opt
Definition: TDavixFile.cxx:70
const std::string VERSION
const char * ca_check_opt
Definition: TDavixFile.cxx:69
const char * s3_acckey_opt
Definition: TDavixFile.cxx:71
const char * grid_mode_opt
Definition: TDavixFile.cxx:68
const std::string gUserAgent
typedef void((*Func_t)())
void addDird(void *fd)
Definition: TDavixFile.cxx:726
Davix::RequestParams * davixParam
bool isMyDird(void *fd)
Definition: TDavixFile.cxx:717
Davix::DavPosix * davixPosix
Int_t DavixStat(const char *url, struct stat *st)
Definition: TDavixFile.cxx:517
Davix::Context * davixContext
void removeDird(void *fd)
Definition: TDavixFile.cxx:734
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
Definition: TDavixSystem.h:43
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:880
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:268
Int_t fMode
Definition: TSystem.h:128
Long64_t fSize
Definition: TSystem.h:131
Long_t fDev
Definition: TSystem.h:126
TString fUrl
Definition: TSystem.h:134
Int_t fGid
Definition: TSystem.h:130
Long_t fMtime
Definition: TSystem.h:132
Long_t fIno
Definition: TSystem.h:127
Bool_t fIsLink
Definition: TSystem.h:133
Int_t fUid
Definition: TSystem.h:129