ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TXNetSystem.cxx
Go to the documentation of this file.
1 // @(#)root/netx:$Id$
2 // Author: Frank Winklmeier, Fabrizio Furano
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, 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 // TXNetSystem //
15 // //
16 // Authors: Frank Winklmeier, Fabrizio Furano //
17 // INFN Padova, 2005 //
18 // //
19 // TXNetSystem is an extension of TNetSystem able to deal with new //
20 // xrootd servers. The class detects the nature of the server and //
21 // redirects the calls to TNetSystem in case of a rootd server. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "TEnv.h"
26 #include "TFileStager.h"
27 #include "TObjString.h"
28 #include "TROOT.h"
29 #include "TSocket.h"
30 #include "TString.h"
31 #include "TUrl.h"
32 #include "TVirtualMutex.h"
33 #include "TXNetFile.h"
34 #include "TXNetSystem.h"
35 
36 #include "XrdOuc/XrdOucString.hh"
37 #include "XrdClient/XrdClientVector.hh"
38 #include "XrdClient/XrdClientAdmin.hh"
40 #include "XrdClient/XrdClientConst.hh"
41 #include "XrdClient/XrdClientEnv.hh"
42 #include "XProtocol/XProtocol.hh"
43 
44 #include "XrdProofdXrdVers.h"
45 
47 
52 
53 typedef XrdClientVector<XrdOucString> VecString_t;
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Create system management class without connecting to server.
57 
58 TXNetSystem::TXNetSystem(Bool_t owner) : TNetSystem(owner), fDirList(0)
59 {
60  SetTitle("(x)rootd system administration");
61  fIsRootd = kFALSE;
62  fIsXRootd = kFALSE;
63  fDir = "";
64  fDirp = 0;
65  fUrl = "";
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Create system management class and connect to server specified by url.
70 
71 TXNetSystem::TXNetSystem(const char *url, Bool_t owner) : TNetSystem(owner), fDirList(0)
72 {
73  SetTitle("(x)rootd system administration");
74  fIsRootd = kFALSE;
75  fIsXRootd = kFALSE;
76  fDir = "";
77  fDirp = 0;
78  fUrl = url;
79 
82 
83  // Set debug level
84  EnvPutInt(NAME_DEBUG, gEnv->GetValue("XNet.Debug", -1));
85 
86  // The first time do some global initialization
87  if (!fgInitDone)
88  InitXrdClient();
89 
90  // Fill in user, host, port
92 
93  TXNetSystemConnectGuard cguard(this, url);
94  if (!cguard.IsValid() && !fIsRootd)
95  Error("TXNetSystem","fatal error: connection creation failed.");
96 
97  return;
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Init a connection to the server.
102 /// Returns a pointer to the appropriate instance of XrdClientAdmin or 0
103 /// in case of failure.
104 
105 XrdClientAdmin *TXNetSystem::Connect(const char *url)
106 {
107  // We need a dummy filename after the server url to connect
108  TString dummy = url;
109  dummy += "/dummy";
110 
111  XrdClientAdmin *cadm = TXNetSystem::GetClientAdmin(dummy);
112 
113  if (!cadm) {
114  Error("Connect","fatal error: new object creation failed.");
115  return cadm;
116  }
117 
118  // Do not block: restore old value after
119  Int_t maxOld = EnvGetLong(NAME_FIRSTCONNECTMAXCNT);
120 
121  // Try to connect to the server
122  gEnv->SetValue("XNet.FirstConnectMaxCnt", 1);
123  EnvPutInt(NAME_FIRSTCONNECTMAXCNT, 1);
124  if (cadm->Connect()) {
125  fIsXRootd = kTRUE;
126  EnvPutInt(NAME_FIRSTCONNECTMAXCNT, maxOld);
127  } else {
128  EnvPutInt(NAME_FIRSTCONNECTMAXCNT, maxOld);
129  if (fgRootdBC) {
130  Bool_t isRootd =
131  (cadm->GetClientConn()->GetServerType() == kSTRootd);
132  Int_t sd = cadm->GetClientConn()->GetOpenSockFD();
133  if (isRootd && sd > -1) {
134  //
135  // Create a TSocket on the open connection
136  TSocket *s = new TSocket(sd);
137 
138  // We will clean it by ourselves
140  gROOT->GetListOfSockets()->Remove(s);
141 
142  s->SetOption(kNoBlock, 0);
143 
144  // Find out the remote protocol (send the client protocol first)
146  if (rproto < 0) {
147  Error("TXNetSystem", "getting protocol of the rootd server");
148  cadm = 0;
149  return 0;
150  }
151  // Finalize TSocket initialization
152  s->SetRemoteProtocol(rproto);
153  TUrl uut((cadm->GetClientConn()
154  ->GetCurrentUrl()).GetUrl().c_str());
155  TString uu;
156  TXNetFile::FormUrl(uut,uu);
157  if (gDebug > 2)
158  Info("Connect"," url: %s",uu.Data());
159 
160  s->SetUrl(uu.Data());
161  s->SetService("rootd");
163  //
164  // Now we can check if we can create a TNetFile on the
165  // open connection
166  if (rproto > 13) {
167  //
168  // Remote support for reuse of open connection
169  TNetSystem::Create(uu, s);
170  } else {
171  //
172  // Open connection has been closed because could
173  // not be reused; TNetSystem will open a new connection
174  TNetSystem::Create(uu);
175  }
176 
177  // Type of server
178  fIsRootd = kTRUE;
179  cadm = 0;
180 
181  } else {
182  Error("Connect", "some severe error occurred while opening"
183  " the connection at %s - exit", url);
184  if (cadm && cadm->LastServerError())
185  Printf(" '%s'", cadm->LastServerError()->errmsg);
186  else
187  Printf(" (error message not available)");
188  cadm = 0;
189  return cadm;
190  }
191  } else {
192  Error("Connect",
193  "while opening the connection at %s - exit", url);
194  cadm = 0;
195  return cadm;
196  }
197  }
198 
199  return cadm;
200 }
201 
202 ////////////////////////////////////////////////////////////////////////////////
203 /// One-time initialization of some communication variables for xrootd protocol
204 
206 {
207  // Init vars with default debug level -1, so we do not get warnings
209 
210  // Only once
211  fgInitDone = kTRUE;
212 
213  // Print the tag, if required (only once)
214  if (gEnv->GetValue("XNet.PrintTAG",0) == 1)
215  Info("TXNetFile","(C) 2005 SLAC TXNetSystem (eXtended TNetSystem) %s",
216  gROOT->GetVersion());
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Open a directory. Returns a non-zero pointer (with no special
221 /// purpose) in case of success, 0 in case of error.
222 
223 void* TXNetSystem::OpenDirectory(const char* dir)
224 {
225  if (fIsXRootd) {
226  // Check if the directory exists
227  TXNetSystemConnectGuard cg(this, dir);
228  if (cg.IsValid()) {
229  fUrl = dir;
230  // Extract the directory name
231  fDir = TUrl(dir).GetFile();
232  fDirp = (void*)&fDir; // serves as directory pointer
233 
234  vecString dirs;
235  vecBool existDirs;
236  XrdOucString s(fDir.Data());
237  dirs.Push_back(s);
238  cg.ClientAdmin()->ExistDirs(dirs, existDirs);
239  cg.ClientAdmin()->GoBackToRedirector();
240  if (existDirs.GetSize()>0 && existDirs[0])
241  return fDirp;
242  else
243  cg.NotifyLastError();
244  }
245  return 0;
246  }
247 
248  if (gDebug > 1)
249  Info("OpenDirectory", "calling TNetSystem::OpenDirectory");
250  return TNetSystem::OpenDirectory(dir); // for a rootd
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Free(Close) the directory referenced by dirp
255 
257 {
258  if (fIsXRootd) {
259  if (dirp != fDirp) {
260  Error("FreeDirectory","invalid directory pointer (%p, %p)", dirp, fDirp);
261  return;
262  }
263  fDir = "";
264  fDirp = 0;
265  fDirEntry = "";
266  if (fDirList) {
267  ((VecString_t*)fDirList)->Clear();
268  delete ((VecString_t*)fDirList);
269  fDirList = 0;
270  }
271  return;
272  }
273 
274  if (gDebug > 1)
275  Info("FreeDirectory","calling TNetSystem::FreeDirectory");
276  return TNetSystem::FreeDirectory(dirp); // for a rootd
277 }
278 
279 ////////////////////////////////////////////////////////////////////////////////
280 /// Create a directory. Return 0 on success, -1 otherwise.
281 
283 {
284  if (fIsXRootd) {
285  TXNetSystemConnectGuard cg(this, dir);
286  if (cg.IsValid()) {
287  // use default permissions 755 to create directory
288  Bool_t ok = cg.ClientAdmin()->Mkdir(TUrl(dir).GetFile(),7,5,5);
289  cg.ClientAdmin()->GoBackToRedirector();
290  if (ok) {
291  return 0;
292  } else {
293  cg.NotifyLastError();
294  return -1;
295  }
296  }
297  }
298 
299  if (gDebug > 1)
300  Info("MakeDirectory","Calling TNetSystem::MakeDirectory");
301  return TNetSystem::MakeDirectory(dir); // for a rootd
302 }
303 
304 ////////////////////////////////////////////////////////////////////////////////
305 /// Get directory entry for directory referenced by dirp.
306 /// Returns 0 in case there are no more entries.
307 
308 const char* TXNetSystem::GetDirEntry(void *dirp)
309 {
310  if (fIsXRootd) {
311  if (dirp != fDirp) {
312  Error("GetDirEntry","invalid directory pointer");
313  return 0;
314  }
315 
316  // Only request new directory listing the first time called
317  if (!fDirList) {
318  TXNetSystemConnectGuard cg(this, fUrl);
319  if (cg.IsValid()) {
320  fDirList = new VecString_t;
321  Bool_t ok = cg.ClientAdmin()->DirList(fDir, *(VecString_t*)fDirList);
322  cg.ClientAdmin()->GoBackToRedirector();
323  if (!ok) {
324  cg.NotifyLastError();
325  delete (VecString_t*)fDirList;
326  fDirList = 0;
327  return 0;
328  }
329  }
330  }
331 
332  // Return entries one by one with each call of method
333  if (fDirList && ((VecString_t*)fDirList)->GetSize() > 0) {
334  fDirEntry = ((VecString_t*)fDirList)->Pop_front().c_str();
335  return fDirEntry.Data();
336  }
337  return 0; // until all of them have been returned
338  }
339 
340  if (gDebug > 1) Info("GetDirEntry","Calling TNetSystem::GetDirEntry");
341  return TNetSystem::GetDirEntry(dirp); // for a rootd
342 }
343 
344 ////////////////////////////////////////////////////////////////////////////////
345 /// Get info about a file. Info is returned in the form of a FileStat_t
346 /// structure (see TSystem.h).
347 /// The function returns 0 in case of success and 1 if the file could
348 /// not be stat'ed.
349 /// NOTICE: Not all information is available with an xrootd server.
350 
352 {
353  if (fIsXRootd) {
354  TXNetSystemConnectGuard cg(this, path);
355  if (cg.IsValid()) {
356 
357  Long_t id;
358  Long64_t size;
359  Long_t flags;
360  Long_t modtime;
361 
362  // Issue the request
363  TUrl urlpath(path);
364  Bool_t ok = cg.ClientAdmin()->Stat(urlpath.GetFile(),id,size,flags,modtime);
365  if (ok) {
366  // Save the endpoint path
367  urlpath.SetProtocol(cg.ClientAdmin()->GetCurrentUrl().Proto.c_str());
368  urlpath.SetHost(cg.ClientAdmin()->GetCurrentUrl().Host.c_str());
369  urlpath.SetPort(cg.ClientAdmin()->GetCurrentUrl().Port);
370  buf.fUrl = urlpath.GetUrl();
371  }
372  cg.ClientAdmin()->GoBackToRedirector();
373 
374  // Flag offline files
375  if (flags & kXR_offline) {
376  buf.fMode = kS_IFOFF;
377  } else if (ok) {
378  buf.fDev = (id >> 24);
379  buf.fIno = (id & 0x00FFFFFF);
380  buf.fUid = -1; // not all information available in xrootd
381  buf.fGid = -1; // not available
382  buf.fSize = size;
383  buf.fMtime = modtime;
384 
385  if (flags == 0) buf.fMode = kS_IFREG;
386  if (flags & kXR_xset) buf.fMode = (kS_IFREG|kS_IXUSR|kS_IXGRP|kS_IXOTH);
387  if (flags & kXR_isDir) buf.fMode = kS_IFDIR;
388  if (flags & kXR_other) buf.fMode = kS_IFSOCK;
389  if (flags & kXR_readable) buf.fMode |= kS_IRUSR;
390  if (flags & kXR_writable) buf.fMode |= kS_IWUSR;
391 
392  buf.fIsLink = 0; // not available
393  return 0;
394  } else {
395  if (gDebug > 0)
396  cg.NotifyLastError();
397  }
398  }
399  return 1;
400  }
401 
402  if (gDebug > 1)
403  Info("GetPathInfo","Calling TNetSystem::GetPathInfo");
404  return TNetSystem::GetPathInfo(path,buf); // for a rootd
405 }
406 
407 ////////////////////////////////////////////////////////////////////////////////
408 /// Check consistency of this helper with the one required
409 /// by 'path' or 'dirptr'.
410 
411 Bool_t TXNetSystem::ConsistentWith(const char *path, void *dirptr)
412 {
413  if (gDebug > 1)
414  Info("ConsistentWith",
415  "calling for path: %s, dir: %p", path, dirptr);
416 
417  return TNetSystem::ConsistentWith(path,dirptr); // for a rootd
418 }
419 
420 ////////////////////////////////////////////////////////////////////////////////
421 /// Returns FALSE if one can access a file using the specified access mode.
422 /// NB: for the time being mode is ignored for XROOTD (just checks existence
423 /// of the file or directory).
424 /// Mode is the same as for the Unix access(2) function.
425 /// Attention, bizarre convention of return value!!
426 
428 {
429  if (fIsXRootd) {
430  // Check only if the file or directory exists and
431  FileStat_t buf;
432  if (GetPathInfo(path, buf) == 0)
433  if (buf.fMode != kS_IFSOCK)
434  return kFALSE;
435  // The file could not be stated
436  return kTRUE;
437  }
438 
439  if (gDebug > 1)
440  Info("AccessPathName", "calling TNetSystem::AccessPathName");
441  return TNetSystem::AccessPathName(path,mode); // for a rootd
442 }
443 
444 ////////////////////////////////////////////////////////////////////////////////
445 /// Unlink 'path' on the remote server system.
446 /// Returns 0 on success, -1 otherwise.
447 
448 int TXNetSystem::Unlink(const char *path)
449 {
450  if (fIsXRootd) {
451 
452  TXNetSystemConnectGuard cg(this, path);
453  if (cg.IsValid()) {
454 
455  Long_t id;
456  Long64_t size;
457  Long_t flags;
458  Long_t modtime;
459 
460  // Extract the directory name
461  TString edir = TUrl(path).GetFile();
462  Bool_t ok = cg.ClientAdmin()->Stat(edir.Data(), id, size, flags, modtime);
463 
464  // Flag offline files
465  if (ok && !(flags & kXR_offline)) {
466  if (flags & kXR_isDir)
467  ok = cg.ClientAdmin()->Rmdir(edir.Data());
468  else
469  ok = cg.ClientAdmin()->Rm(edir.Data());
470  cg.ClientAdmin()->GoBackToRedirector();
471 
472  // Done
473  return ((ok) ? 0 : -1);
474  } else if (!ok) {
475  cg.ClientAdmin()->GoBackToRedirector();
476  cg.NotifyLastError();
477  }
478  }
479  }
480 
481  if (gDebug > 1)
482  Info("Unlink", "calling TNetSystem::Unlink");
483  return -1; // not implemented for rootd
484 }
485 
486 ////////////////////////////////////////////////////////////////////////////////
487 /// Check if the file defined by 'path' is ready to be used
488 
489 Bool_t TXNetSystem::IsOnline(const char *path)
490 {
491  // This is most efficiently done using GetPathInfo
492  FileStat_t st;
493  if (GetPathInfo(path, st) != 0) {
494  if (gDebug > 0)
495  Info("IsOnline", "path '%s' cannot be stat'ed", path);
496  return kFALSE;
497  }
498  if (R_ISOFF(st.fMode)) {
499  if (gDebug > 0)
500  Info("IsOnline", "path '%s' is offline", path);
501  return kFALSE;
502  }
503  // Done
504  return kTRUE;
505 }
506 
507 ////////////////////////////////////////////////////////////////////////////////
508 /// Issue a prepare request for file defined by 'path'
509 
510 Bool_t TXNetSystem::Prepare(const char *path, UChar_t option, UChar_t priority)
511 {
512  TXNetSystemConnectGuard cg(this, path);
513  if (cg.IsValid()) {
514  XrdOucString pathname = TUrl(path).GetFileAndOptions();
515  vecString vs;
516  vs.Push_back(pathname);
517  cg.ClientAdmin()->Prepare(vs, (kXR_char)option, (kXR_char)priority);
518  cg.ClientAdmin()->GoBackToRedirector();
519  if (gDebug >0)
520  Info("Prepare", "Got Status %d for %s",
521  cg.ClientAdmin()->LastServerResp()->status, pathname.c_str());
522  if (!(cg.ClientAdmin()->LastServerResp()->status)){
523  return kTRUE;
524  }
525  cg.NotifyLastError();
526  }
527 
528  // Done
529  return kFALSE;
530 }
531 
532 ////////////////////////////////////////////////////////////////////////////////
533 /// Issue a prepare request for a list of files defined by 'paths', which must
534 /// be of one of the following types: TFileInfo, TUrl, TObjString.
535 /// On output, bufout, if defined, points to a buffer form that can be used
536 /// with GetPathsInfo.
537 /// Return the number of paths found or -1 if any error occured.
538 
540  UChar_t opt, UChar_t prio, TString *bufout)
541 {
542  if (!paths) {
543  Warning("Prepare", "input list is empty!");
544  return -1;
545  }
546 
547  Int_t npaths = 0;
548 
549  TXNetSystemConnectGuard cg(this, "");
550  if (cg.IsValid()) {
551 
552  TString *buf = (bufout) ? bufout : new TString();
553 
554  // Prepare the buffer
555  TObject *o = 0;
556  TUrl u;
557  TString path;
558  TIter nxt(paths);
559  while ((o = nxt())) {
560  // Extract the path name from the allowed object types
562  if (pn == "") {
563  Warning("Prepare", "object is of unexpected type %s - ignoring", o->ClassName());
564  continue;
565  }
566  u.SetUrl(pn);
567  // The path
568  path = u.GetFileAndOptions();
569  path.ReplaceAll("\n","\r");
570  npaths++;
571  *buf += Form("%s\n", path.Data());
572  }
573 
574  Info("Prepare","buffer ready: issuing prepare (opt=%d, prio=%d) ...",
575  opt, prio);
576  cg.ClientAdmin()->Prepare(buf->Data(), (kXR_char)opt, (kXR_char)prio);
577  cg.ClientAdmin()->GoBackToRedirector();
578  if (!bufout)
579  delete buf;
580  if (gDebug >0)
581  Info("Prepare", "Got Status %d",
582  cg.ClientAdmin()->LastServerResp()->status);
583  if (!(cg.ClientAdmin()->LastServerResp()->status)){
584  return npaths;
585  }
586  cg.NotifyLastError();
587  }
588 
589  // Done
590  return -1;
591 }
592 
593 ////////////////////////////////////////////////////////////////////////////////
594 /// Retrieve status of a '\n'-separated list of files in 'paths'.
595 /// The information is returned as one UChar_t per file in 'info';
596 /// 'info' must be allocated by the caller.
597 
598 Bool_t TXNetSystem::GetPathsInfo(const char *paths, UChar_t *info)
599 {
600  if (!paths) {
601  Warning("GetPathsInfo", "input list is empty!");
602  return kFALSE;
603  }
604 
605  TXNetSystemConnectGuard cg(this, "");
606  if (cg.IsValid()) {
607  cg.ClientAdmin()->SysStatX(paths, info);
608  cg.ClientAdmin()->GoBackToRedirector();
609  if (gDebug >0)
610  Info("GetPathsInfo", "Got Status %d",
611  cg.ClientAdmin()->LastServerResp()->status);
612  if (!(cg.ClientAdmin()->LastServerResp()->status)){
613  return kTRUE;
614  }
615  cg.NotifyLastError();
616  }
617 
618  // Done
619  return kFALSE;
620 }
621 
622 ////////////////////////////////////////////////////////////////////////////////
623 /// Returns TRUE if the url in 'path' points to the local file system.
624 /// This is used to avoid going through the NIC card for local operations.
625 
627 {
628  if (fIsXRootd) {
629  TXNetSystemConnectGuard cg(this, path);
630  if (cg.IsValid()) {
631  if (cg.ClientAdmin()->GetClientConn()->GetServerType() != kSTDataXrootd) {
632  // Not an end point data server: cannot assert locality
633  return kFALSE;
634  }
635  }
636  }
637  // Either an end-point data server or 'rootd': check for locality
638  return TSystem::IsPathLocal(path);
639 }
640 
641 ////////////////////////////////////////////////////////////////////////////////
642 /// Get end-point url of a file. Info is returned in eurl.
643 /// The function returns 0 in case of success and 1 if the file could
644 /// not be stat'ed.
645 
646 Int_t TXNetSystem::Locate(const char *path, TString &eurl)
647 {
648  if (fIsXRootd) {
649  TXNetSystemConnectGuard cg(this, path);
650  if (cg.IsValid()) {
651 
652  // Extract the directory name
653  XrdClientLocate_Info li;
654  TString edir = TUrl(path).GetFile();
655 
656  if (cg.ClientAdmin()->Locate((kXR_char *)edir.Data(), li)) {
657  TUrl u(path);
658  XrdClientUrlInfo ui((const char *)&li.Location[0]);
659  // We got the IP address but we need the FQDN: if we did not resolve
660  // it yet do it and cache the result
661  TNamed *hn = 0;
662  if (fgAddrFQDN.GetSize() <= 0 ||
663  !(hn = dynamic_cast<TNamed *>(fgAddrFQDN.FindObject(ui.Host.c_str())))) {
664  TInetAddress a(gSystem->GetHostByName(ui.Host.c_str()));
665  if (strlen(a.GetHostName()) > 0)
666  hn = new TNamed(ui.Host.c_str(), a.GetHostName());
667  else
668  hn = new TNamed(ui.Host.c_str(), ui.Host.c_str());
669  fgAddrFQDN.Add(hn);
670  if (gDebug > 0)
671  Info("Locate","caching host name: %s", hn->GetTitle());
672  }
673  if (hn)
674  u.SetHost(hn->GetTitle());
675  else
676  u.SetHost(ui.Host.c_str());
677  u.SetPort(ui.Port);
678  eurl = u.GetUrl();
679  return 0;
680  }
681  cg.NotifyLastError();
682  }
683  return 1;
684  }
685 
686  // Not implemented
687  if (gDebug > 0) Info("Locate", "server not Xrootd: method not implemented!");
688  return -1;
689 }
690 
691 ////////////////////////////////////////////////////////////////////////////////
692 /// Checks if an admin for 'url' exists already.
693 /// Avoid duplications.
694 
695 XrdClientAdmin *TXNetSystem::GetClientAdmin(const char *url)
696 {
697  XrdClientAdmin *ca = 0;
698 
699  // ID key
700  TString key = TXNetSystem::GetKey(url);
701 
702  // If we have one for 'key', just use it
703  TXrdClientAdminWrapper *caw = 0;
704  if (fgAdminHash.GetSize() > 0 &&
705  (caw = dynamic_cast<TXrdClientAdminWrapper *>(fgAdminHash.FindObject(key.Data()))))
706  return caw->fXCA;
707 
708  // Create one and save the reference in the hash table
709  ca = new XrdClientAdmin(url);
710  fgAdminHash.Add(new TXrdClientAdminWrapper(key, ca));
711 
712  // Done
713  return ca;
714 }
715 
716 ////////////////////////////////////////////////////////////////////////////////
717 /// Build from uu a unique ID key used in hash tables
718 
719 TString TXNetSystem::GetKey(const char *url)
720 {
721  TUrl u(url);
722  TString key(u.GetUser());
723  if (!key.IsNull())
724  key += "@";
725  key += u.GetHost();
726  if (u.GetPort() > 0) {
727  key += ":";
728  key += u.GetPort();
729  }
730 
731  // Done
732  return key;
733 }
734 
735 //
736 // Wrapper class
737 //
738 ////////////////////////////////////////////////////////////////////////////////
739 /// Destructor: destroy the instance
740 
742 {
743  SafeDelete(fXCA);
744 }
745 
746 //
747 // Guard methods
748 //
749 ////////////////////////////////////////////////////////////////////////////////
750 /// Construct a guard object
751 
753  : fClientAdmin(0)
754 {
755  if (xn)
756  // Connect
757  fClientAdmin = (url && strlen(url) > 0) ? xn->Connect(url)
758  : xn->Connect(xn->fUrl);
759 }
760 
761 ////////////////////////////////////////////////////////////////////////////////
762 /// Destructor: close the connection
763 
765 {
766  fClientAdmin = 0;
767 }
768 
769 ////////////////////////////////////////////////////////////////////////////////
770 /// Print message about last occured error
771 
773 {
774  if (fClientAdmin)
775  if (fClientAdmin->GetClientConn())
776  Printf("Srv err: %s", fClientAdmin->GetClientConn()->LastServerError.errmsg);
777 }
const char * GetHost() const
Definition: TUrl.h:76
const char * GetDirEntry(void *dirp=0)
Get directory entry via rootd. Returns 0 in case no more entries.
Definition: TNetFile.cxx:1057
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
Definition: TNetFile.cxx:1105
void NotifyLastError()
Print message about last occured error.
void SetRemoteProtocol(Int_t rproto)
Definition: TSocket.h:181
TString fUrl
Definition: TXNetSystem.h:68
const char * GetHostName() const
Definition: TInetAddress.h:75
void SetPort(Int_t port)
Definition: TUrl.h:97
static TString GetPathName(TObject *o)
Return the path name contained in object 'o' allowing for TUrl, TObjString or TFileInfo.
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
Definition: TSystem.cxx:1222
long long Long64_t
Definition: RtypesCore.h:69
virtual int Unlink(const char *path)
Unlink 'path' on the remote server system.
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
Definition: TUrl.cxx:518
Bool_t IsOnline(const char *path)
Check if the file defined by 'path' is ready to be used.
bool IsValid() const
Definition: TXNetSystem.h:120
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:213
virtual Int_t SetOption(ESockOptions opt, Int_t val)
Set socket options.
Definition: TSocket.cxx:1017
This class represents a WWW compatible URL.
Definition: TUrl.h:41
Int_t fUid
Definition: TSystem.h:139
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
Definition: TUrl.cxx:108
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
This class represents an Internet Protocol (IP) address.
Definition: TInetAddress.h:40
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
VecStringVP_t fDirList
Definition: TXNetSystem.h:66
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:63
const Bool_t kFALSE
Definition: Rtypes.h:92
static Int_t GetRootdProtocol(TSocket *s)
Find out the remote rootd protocol version.
Definition: TXNetFile.cxx:421
Long_t fMtime
Definition: TSystem.h:142
void Create(const char *url, TSocket *sock=0)
Create a TNetSystem object.
Definition: TNetFile.cxx:874
static TString GetKey(const char *url)
Build from uu a unique ID key used in hash tables.
static THashList fgAdminHash
Definition: TXNetSystem.h:78
Long64_t fSize
Definition: TSystem.h:141
Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
Definition: TNetFile.cxx:1081
static THashList fgAddrFQDN
Definition: TXNetSystem.h:77
TXNetSystem(Bool_t owner=kTRUE)
Create system management class without connecting to server.
Definition: TXNetSystem.cxx:58
ClassImp(TXNetSystem)
XrdClientVector< XrdOucString > VecString_t
Definition: TXNetSystem.cxx:53
void SetServType(Int_t st)
Definition: TSocket.h:184
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=0)
Set the value of a resource or create a new resource.
Definition: TEnv.cxx:749
Int_t fMode
Definition: TSystem.h:138
const char * Data() const
Definition: TString.h:349
TXNetSystemConnectGuard(TXNetSystem *xn, const char *url)
Construct a guard object.
#define SafeDelete(p)
Definition: RConfig.h:436
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual Bool_t ConsistentWith(const char *path, void *dirptr)
Check consistency of this helper with the one required by 'path' or 'dirptr'.
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
void * fDirp
Definition: TXNetSystem.h:65
static XrdClientAdmin * GetClientAdmin(const char *url)
Checks if an admin for 'url' exists already.
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1126
TString fUrl
Definition: TSystem.h:144
virtual ~TXrdClientAdminWrapper()
Destructor: destroy the instance.
virtual Int_t Locate(const char *path, TString &endurl)
Get end-point url of a file.
XFontStruct * id
Definition: TGX11.cxx:108
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
static void SetEnv()
Set the relevant environment variables.
Definition: TXNetFile.cxx:1193
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Definition: TSystem.cxx:2193
XrdClientAdmin * ClientAdmin() const
Definition: TXNetSystem.h:122
XrdClientAdmin * fXCA
Definition: TXNetSystem.h:54
Int_t fGid
Definition: TSystem.h:140
TString fDirEntry
Definition: TXNetSystem.h:67
XrdClientAdmin * Connect(const char *url)
Init a connection to the server.
Bool_t fIsXRootd
Definition: TXNetSystem.h:63
Bool_t GetPathsInfo(const char *paths, UChar_t *info)
Retrieve status of a ' '-separated list of files in 'paths'.
Int_t GetPort() const
Definition: TUrl.h:87
~TXNetSystemConnectGuard()
Destructor: close the connection.
Bool_t fIsLink
Definition: TSystem.h:143
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
static void FormUrl(TUrl uut, TString &uu)
Form url for rootd socket.
Definition: TXNetFile.cxx:170
virtual const char * GetDirEntry(void *dirp)
Get directory entry for directory referenced by dirp.
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
Collection abstract base class.
Definition: TCollection.h:48
char * Form(const char *fmt,...)
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:499
static Bool_t fgRootdBC
Definition: TXNetSystem.h:71
void * OpenDirectory(const char *name)
Open a directory via rfiod.
Definition: TNetFile.cxx:998
Int_t MakeDirectory(const char *name)
Make a directory via rootd.
Definition: TNetFile.cxx:976
Bool_t fIsRootd
Definition: TXNetSystem.h:62
#define Printf
Definition: TGeoToOCC.h:18
virtual void * OpenDirectory(const char *dir)
Open a directory.
XrdClientAdmin * fClientAdmin
Definition: TXNetSystem.h:114
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:385
Bool_t Prepare(const char *path, UChar_t opt=8, UChar_t prio=0)
Issue a prepare request for file defined by 'path'.
void SetHost(const char *host)
Definition: TUrl.h:93
long Long_t
Definition: RtypesCore.h:50
virtual Int_t GetSize() const
Definition: TCollection.h:95
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
void dir(char *path=0)
Definition: rootalias.C:30
TNamed()
Definition: TNamed.h:40
void InitXrdClient()
One-time initialization of some communication variables for xrootd protocol.
static RooMathCoreReg dummy
EAccessMode
Definition: TSystem.h:54
Mother of all ROOT objects.
Definition: TObject.h:58
Bool_t ConsistentWith(const char *path, void *dirptr)
Check consistency of this helper with the one required by 'path' or 'dirptr'.
Definition: TNetFile.cxx:1127
virtual void FreeDirectory(void *dirp)
Free(Close) the directory referenced by dirp.
virtual void Add(TObject *obj)
Definition: TList.h:81
virtual Int_t MakeDirectory(const char *dir)
Create a directory. Return 0 on success, -1 otherwise.
static Bool_t fgInitDone
Definition: TXNetSystem.h:70
Long_t fIno
Definition: TSystem.h:137
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
virtual Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
void SetUrl(const char *url)
Definition: TSocket.h:185
TString fDir
Definition: TXNetSystem.h:64
unsigned char UChar_t
Definition: RtypesCore.h:34
void SetService(const char *service)
Definition: TSocket.h:183
Long_t fDev
Definition: TSystem.h:136
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
const char * GetUser() const
Definition: TUrl.h:74
void InitRemoteEntity(const char *url)
Parse and save coordinates of the remote entity (user, host, port, ...)
Definition: TNetFile.cxx:850
void FreeDirectory(void *dirp=0)
Free directory via rootd.
Definition: TNetFile.cxx:1032
const char * GetFile() const
Definition: TUrl.h:78
Bool_t R_ISOFF(Int_t mode)
Definition: TSystem.h:133
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904