19 #ifndef __XRD_CL_UTILS_HH__ 20 #define __XRD_CL_UTILS_HH__ 36 #include <sys/fsuid.h> 52 template<
class Container>
54 const std::string &input,
55 const std::string &delimiter )
63 end = input.find( delimiter, start );
65 if( end != std::string::npos )
68 length = input.length() - start;
71 result.push_back( input.substr( start, length ) );
73 start = end + delimiter.size();
75 while( end != std::string::npos );
82 const std::string &name,
89 const std::string &name,
90 const std::string &defaultVal );
121 const std::string &hostId,
122 std::vector<XrdNetAddr> &addresses );
138 const std::string &checkSumType,
145 const std::string &checkSumType,
146 const std::string &path );
157 uint16_t timeout = 0 );
166 uint16_t timeout = 0 );
171 static std::string
FQDNToCC(
const std::string &fqdn );
177 const std::string &path );
183 const std::string &file );
189 const std::string &dir );
194 static void Trim( std::string &str );
207 static std::string
Char2Hex( uint8_t *array, uint16_t size );
213 const std::string &checksum );
281 class ScopedFsUidSetter
287 ScopedFsUidSetter(uid_t fsuid, gid_t fsgid,
const std::string &streamName)
288 : pFsUid(fsuid), pFsGid(fsgid), pStreamName(streamName)
298 pPrevFsUid = setfsuid(pFsUid);
300 if(setfsuid(pFsUid) != pFsUid) {
310 pPrevFsGid = setfsgid(pFsGid);
312 if(setfsgid(pFsGid) != pFsGid) {
322 ~ScopedFsUidSetter() {
325 if(pPrevFsUid >= 0) {
326 int retcode = setfsuid(pPrevFsUid);
327 log->Dump(
XRootDTransportMsg,
"[%s] Restored fsuid from %d to %d", pStreamName.c_str(), retcode, pPrevFsUid);
330 if(pPrevFsGid >= 0) {
331 int retcode = setfsgid(pPrevFsGid);
332 log->Dump(
XRootDTransportMsg,
"[%s] Restored fsgid from %d to %d", pStreamName.c_str(), retcode, pPrevFsGid);
344 const std::string &pStreamName;
355 #endif // __XRD_CL_UTILS_HH__ Definition: XrdClUtils.hh:98
static std::string TimeToString(time_t timestamp)
Convert timestamp to a string.
static Status ProcessConfigDir(std::map< std::string, std::string > &config, const std::string &dir)
Process a config directory and return key-value pairs.
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
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:97
static std::string Char2Hex(uint8_t *array, uint16_t size)
Print a char array as hex.
~ScopedDescriptor()
Destructor.
Definition: XrdClUtils.hh:253
Procedure execution status.
Definition: XrdClStatus.hh:112
static bool CheckEC(const Message *req, const URL &url)
Check if this client can support given EC redirect.
int GetDescriptor()
Get the descriptor.
Definition: XrdClUtils.hh:268
AddressType
Address type.
Definition: XrdClUtils.hh:95
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:46
static Log * GetLog()
Get default log.
static XRootDStatus GetRemoteCheckSum(std::string &checkSum, const std::string &checkSumType, const URL &url)
Get a checksum from a remote xrootd server.
static std::string BytesToString(uint64_t bytes)
Convert bytes to a human readable string.
int Release()
Release the descriptor being held.
Definition: XrdClUtils.hh:258
Request status.
Definition: XrdClXRootDResponses.hh:218
Definition: XrdClAnyObject.hh:25
static XRootDStatus CheckTPCLite(const std::string &server, uint16_t timeout=0)
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:53
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:36
Definition: XrdClUtils.hh:99
int pDescriptor
Definition: XrdClUtils.hh:274
Definition: XrdClUtils.hh:100
static Status GetHostAddresses(std::vector< XrdNetAddr > &addresses, const URL &url, AddressType type)
Resolve IP addresses.
ScopedDescriptor(int descriptor)
Constructor.
Definition: XrdClUtils.hh:248
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:101
Smart descriptor - closes the descriptor on destruction.
Definition: XrdClUtils.hh:242
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:102
static uint64_t GetElapsedMicroSecs(timeval start, timeval end)
Get the elapsed microseconds between two timevals.