19 #ifndef __XRD_CL_UTILS_HH__
20 #define __XRD_CL_UTILS_HH__
38 #include <sys/fsuid.h>
54 template<
class Container>
56 const std::string &input,
57 const std::string &delimiter )
65 end = input.find( delimiter, start );
67 if( end != std::string::npos )
70 length = input.length() - start;
73 result.push_back( input.substr( start, length ) );
75 start = end + delimiter.size();
77 while( end != std::string::npos );
84 const std::string &name,
91 const std::string &name,
92 const std::string &defaultVal );
123 const std::string &hostId,
124 std::vector<XrdNetAddr> &addresses );
140 const std::string &checkSumType,
147 const std::string &checkSumType,
148 const std::string &path );
159 uint16_t timeout = 0 );
168 uint16_t timeout = 0 );
173 static std::string
FQDNToCC(
const std::string &fqdn );
179 const std::string &path );
185 const std::string &file );
191 const std::string &dir );
196 static void Trim( std::string &str );
209 static std::string
Char2Hex( uint8_t *array, uint16_t size );
215 const std::string &checksum );
251 if( !st.
IsOK() )
return st;
253 qryResult.
Get( tmp );
269 if( !st.IsOK() )
return false;
283 if( !st.IsOK() )
return false;
330 class ScopedFsUidSetter
336 ScopedFsUidSetter(uid_t fsuid, gid_t fsgid,
const std::string &streamName)
337 : pFsUid(fsuid), pFsGid(fsgid), pStreamName(streamName)
347 pPrevFsUid = setfsuid(pFsUid);
349 if(setfsuid(pFsUid) != pFsUid) {
359 pPrevFsGid = setfsgid(pFsGid);
361 if(setfsgid(pFsGid) != pFsGid) {
371 ~ScopedFsUidSetter() {
374 if(pPrevFsUid >= 0) {
375 int retcode = setfsuid(pPrevFsUid);
376 log->Dump(
XRootDTransportMsg,
"[%s] Restored fsuid from %d to %d", pStreamName.c_str(), retcode, pPrevFsUid);
379 if(pPrevFsGid >= 0) {
380 int retcode = setfsgid(pPrevFsGid);
381 log->Dump(
XRootDTransportMsg,
"[%s] Restored fsgid from %d to %d", pStreamName.c_str(), retcode, pPrevFsGid);
393 const std::string &pStreamName;
404 #endif // __XRD_CL_UTILS_HH__
Definition: XrdClAnyObject.hh:32
Definition: XrdClUtils.hh:100
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.
void Get(Type &object)
Retrieve the object being held.
Definition: XrdClAnyObject.hh:78
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 bool HasXAttr(const XrdCl::URL &url)
Definition: XrdClUtils.hh:264
static void LogHostAddresses(Log *log, uint64_t type, const std::string &hostId, std::vector< XrdNetAddr > &addresses)
Log all the addresses on the list.
static bool HasPgRW(const XrdCl::URL &url)
Definition: XrdClUtils.hh:278
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:99
static std::string Char2Hex(uint8_t *array, uint16_t size)
Print a char array as hex.
~ScopedDescriptor()
Destructor.
Definition: XrdClUtils.hh:302
Procedure execution status.
Definition: XrdClStatus.hh:113
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:317
AddressType
Address type.
Definition: XrdClUtils.hh:97
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:48
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 XrdCl::XRootDStatus GetProtocolVersion(const XrdCl::URL url, int &protver)
Definition: XrdClUtils.hh:246
static const uint16_t ProtocolVersion
returns the protocol version
Definition: XrdClXRootDTransport.hh:50
static std::string BytesToString(uint64_t bytes)
Convert bytes to a human readable string.
int Release()
Release the descriptor being held.
Definition: XrdClUtils.hh:307
Request status.
Definition: XrdClXRootDResponses.hh:218
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:55
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.
#define kXR_PROTXATTVERSION
Definition: XProtocol.hh:71
const uint64_t XRootDTransportMsg
Definition: XrdClConstants.hh:37
Definition: XrdClUtils.hh:101
int pDescriptor
Definition: XrdClUtils.hh:323
Definition: XrdClUtils.hh:102
static Status GetHostAddresses(std::vector< XrdNetAddr > &addresses, const URL &url, AddressType type)
Resolve IP addresses.
ScopedDescriptor(int descriptor)
Constructor.
Definition: XrdClUtils.hh:297
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
static PostMaster * GetPostMaster()
Get default post master.
Definition: XrdClUtils.hh:103
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:123
Smart descriptor - closes the descriptor on destruction.
Definition: XrdClUtils.hh:291
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.
#define kXR_PROTPGRWVERSION
Definition: XProtocol.hh:73
Handle diagnostics.
Definition: XrdClLog.hh:100
static uint64_t GetElapsedMicroSecs(timeval start, timeval end)
Get the elapsed microseconds between two timevals.