19 #ifndef __XRD_CL_UTILS_HH__ 20 #define __XRD_CL_UTILS_HH__ 36 #include <sys/fsuid.h> 50 template<
class Container>
52 const std::string &input,
53 const std::string &delimiter )
61 end = input.find( delimiter, start );
63 if( end != std::string::npos )
66 length = input.length() - start;
69 result.push_back( input.substr( start, length ) );
71 start = end + delimiter.size();
73 while( end != std::string::npos );
80 const std::string &name,
87 const std::string &name,
88 const std::string &defaultVal );
119 const std::string &hostId,
120 std::vector<XrdNetAddr> &addresses );
136 const std::string &checkSumType,
137 const std::string &server,
138 const std::string &path );
144 const std::string &checkSumType,
145 const std::string &path );
156 uint16_t timeout = 0 );
165 uint16_t timeout = 0 );
170 static std::string
FQDNToCC(
const std::string &fqdn );
176 const std::string &path );
182 const std::string &file );
187 static void Trim( std::string &str );
200 static std::string
Char2Hex( uint8_t *array, uint16_t size );
206 const std::string &checksum );
269 class ScopedFsUidSetter
275 ScopedFsUidSetter(uid_t fsuid, gid_t fsgid,
const std::string &streamName)
276 : pFsUid(fsuid), pFsGid(fsgid), pStreamName(streamName)
286 pPrevFsUid = setfsuid(pFsUid);
288 if(setfsuid(pFsUid) != pFsUid) {
298 pPrevFsGid = setfsgid(pFsGid);
300 if(setfsgid(pFsGid) != pFsGid) {
310 ~ScopedFsUidSetter() {
313 if(pPrevFsUid >= 0) {
314 int retcode = setfsuid(pPrevFsUid);
315 log->Dump(
XRootDTransportMsg,
"[%s] Restored fsuid from %d to %d", pStreamName.c_str(), retcode, pPrevFsUid);
318 if(pPrevFsGid >= 0) {
319 int retcode = setfsgid(pPrevFsGid);
320 log->Dump(
XRootDTransportMsg,
"[%s] Restored fsgid from %d to %d", pStreamName.c_str(), retcode, pPrevFsGid);
332 const std::string &pStreamName;
343 #endif // __XRD_CL_UTILS_HH__ Definition: XrdClUtils.hh:96
static std::string TimeToString(time_t timestamp)
Convert timestamp to a string.
static std::string FQDNToCC(const std::string &fqdn)
Convert the fully qualified host name to country code.
static void LogHostAddresses(Log *log, uint64_t type, const std::string &hostId, std::vector< XrdNetAddr > &addresses)
Log all the addresses on the list.
static std::string GetStringParameter(const URL &url, const std::string &name, const std::string &defaultVal)
Get a parameter either from the environment or URL.
static Status GetDirectoryEntries(std::vector< std::string > &entries, const std::string &path)
Get directory entries.
static std::vector< std::string > GetSupportedCheckSums(const XrdCl::URL &url)
Get supported checksum types for given URL.
Definition: XrdClUtils.hh:95
static std::string Char2Hex(uint8_t *array, uint16_t size)
Print a char array as hex.
~ScopedDescriptor()
Destructor.
Definition: XrdClUtils.hh:241
Procedure execution status.
Definition: XrdClStatus.hh:109
int GetDescriptor()
Get the descriptor.
Definition: XrdClUtils.hh:256
AddressType
Address type.
Definition: XrdClUtils.hh:93
static int GetIntParameter(const URL &url, const std::string &name, int defaultVal)
Get a parameter either from the environment or URL.
Random utilities.
Definition: XrdClUtils.hh:44
static Log * GetLog()
Get default log.
static std::string BytesToString(uint64_t bytes)
Convert bytes to a human readable string.
int Release()
Release the descriptor being held.
Definition: XrdClUtils.hh:246
Request status.
Definition: XrdClXRootDResponses.hh:212
Definition: XrdClAnyObject.hh:25
static XRootDStatus CheckTPCLite(const std::string &server, uint16_t timeout=0)
static XRootDStatus GetRemoteCheckSum(std::string &checkSum, const std::string &checkSumType, const std::string &server, const std::string &path)
Get a checksum from a remote xrootd server.
static Status ProcessConfig(std::map< std::string, std::string > &config, const std::string &file)
Process a config file and return key-value pairs.
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
Definition: XrdClUtils.hh:51
static XRootDStatus CheckTPC(const std::string &server, uint16_t timeout=0)
Check if peer supports tpc.
static std::string NormalizeChecksum(const std::string &name, const std::string &checksum)
Normalize checksum.
URL representation.
Definition: XrdClURL.hh:30
#define close(a)
Definition: XrdPosix.hh:43
static XRootDStatus GetLocalCheckSum(std::string &checkSum, const std::string &checkSumType, const std::string &path)
Get a checksum from local file.
const uint64_t XRootDTransportMsg
Definition: XrdClConstants.hh:34
Definition: XrdClUtils.hh:97
int pDescriptor
Definition: XrdClUtils.hh:262
Definition: XrdClUtils.hh:98
static Status GetHostAddresses(std::vector< XrdNetAddr > &addresses, const URL &url, AddressType type)
Resolve IP addresses.
ScopedDescriptor(int descriptor)
Constructor.
Definition: XrdClUtils.hh:236
static AddressType String2AddressType(const std::string &addressType)
Interpret a string as address type, default to IPAll.
static std::string InferChecksumType(const XrdCl::URL &source, const XrdCl::URL &destination, bool zip=false)
A key-value pair map storing both keys and values as strings.
Definition: XrdClPropertyList.hh:40
Definition: XrdClUtils.hh:99
Smart descriptor - closes the descriptor on destruction.
Definition: XrdClUtils.hh:230
static void LogPropertyList(Log *log, uint64_t topic, const char *format, const PropertyList &list)
Log property list.
static void Trim(std::string &str)
Trim a string.
Handle diagnostics.
Definition: XrdClLog.hh:101
static uint64_t GetElapsedMicroSecs(timeval start, timeval end)
Get the elapsed microseconds between two timevals.