19 #ifndef __XRD_CL_UTILS_HH__
20 #define __XRD_CL_UTILS_HH__
39 #include <sys/fsuid.h>
55 template<
class Container>
57 const std::string &input,
58 const std::string &delimiter )
73 const std::string &name,
80 const std::string &name,
81 const std::string &defaultVal );
112 const std::string &hostId,
113 std::vector<XrdNetAddr> &addresses );
129 const std::string &checkSumType,
136 const std::string &checkSumType,
137 const std::string &path );
148 uint16_t timeout = 0 );
157 uint16_t timeout = 0 );
162 static std::string
FQDNToCC(
const std::string &fqdn );
168 const std::string &path );
174 const std::string &file );
180 const std::string &dir );
185 static void Trim( std::string &str );
198 static std::string
Char2Hex( uint8_t *array, uint16_t size );
204 const std::string &checksum );
240 if( !st.
IsOK() )
return st;
242 qryResult.
Get( tmp );
258 if( !st.IsOK() )
return false;
272 if( !st.IsOK() )
return false;
283 static void SplitChunks( std::vector<ChunkList> &listsvec,
285 const uint32_t maxcs,
310 int desc = pDescriptor;
331 class ScopedFsUidSetter
337 ScopedFsUidSetter(uid_t fsuid, gid_t fsgid,
const std::string &streamName)
338 : pFsUid(fsuid), pFsGid(fsgid), pStreamName(streamName)
348 pPrevFsUid = setfsuid(pFsUid);
350 if(setfsuid(pFsUid) != pFsUid) {
360 pPrevFsGid = setfsgid(pFsGid);
362 if(setfsgid(pFsGid) != pFsGid) {
372 ~ScopedFsUidSetter() {
375 if(pPrevFsUid >= 0) {
376 int retcode = setfsuid(pPrevFsUid);
377 log->Dump(
XRootDTransportMsg,
"[%s] Restored fsuid from %d to %d", pStreamName.c_str(), retcode, pPrevFsUid);
380 if(pPrevFsGid >= 0) {
381 int retcode = setfsgid(pPrevFsGid);
382 log->Dump(
XRootDTransportMsg,
"[%s] Restored fsgid from %d to %d", pStreamName.c_str(), retcode, pPrevFsGid);
394 const std::string &pStreamName;
#define kXR_PROTXATTVERSION
#define kXR_PROTPGRWVERSION
void Get(Type &object)
Retrieve the object being held.
static Log * GetLog()
Get default log.
static PostMaster * GetPostMaster()
Get default post master.
The message representation used throughout the system.
A key-value pair map storing both keys and values as strings.
Smart descriptor - closes the descriptor on destruction.
~ScopedDescriptor()
Destructor.
ScopedDescriptor(int descriptor)
Constructor.
int GetDescriptor()
Get the descriptor.
int Release()
Release the descriptor being held.
static std::string TimeToString(time_t timestamp)
Convert timestamp to a string.
static XRootDStatus CheckTPCLite(const std::string &server, uint16_t timeout=0)
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 NormalizeChecksum(const std::string &name, const std::string &checksum)
Normalize checksum.
static Status ProcessConfig(std::map< std::string, std::string > &config, const std::string &file)
Process a config file and return key-value pairs.
static Status ProcessConfigDir(std::map< std::string, std::string > &config, const std::string &dir)
Process a config directory and return key-value pairs.
static std::string FQDNToCC(const std::string &fqdn)
Convert the fully qualified host name to country code.
static std::string InferChecksumType(const XrdCl::URL &source, const XrdCl::URL &destination, bool zip=false)
Automatically infer the right checksum type.
static void LogPropertyList(Log *log, uint64_t topic, const char *format, const PropertyList &list)
Log property list.
static std::string Char2Hex(uint8_t *array, uint16_t size)
Print a char array as hex.
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
static Status GetHostAddresses(std::vector< XrdNetAddr > &addresses, const URL &url, AddressType type)
Resolve IP addresses.
static uint64_t GetElapsedMicroSecs(timeval start, timeval end)
Get the elapsed microseconds between two timevals.
static std::vector< std::string > GetSupportedCheckSums(const XrdCl::URL &url)
Get supported checksum types for given URL.
static AddressType String2AddressType(const std::string &addressType)
Interpret a string as address type, default to IPAll.
static int GetIntParameter(const URL &url, const std::string &name, int 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 XRootDStatus GetLocalCheckSum(std::string &checkSum, const std::string &checkSumType, const std::string &path)
Get a checksum from local file.
static std::string BytesToString(uint64_t bytes)
Convert bytes to a human readable string.
static void Trim(std::string &str)
Trim a string.
static bool CheckEC(const Message *req, const URL &url)
Check if this client can support given EC redirect.
static bool HasXAttr(const XrdCl::URL &url)
static XRootDStatus GetRemoteCheckSum(std::string &checkSum, const std::string &checkSumType, const URL &url)
Get a checksum from a remote xrootd server.
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 XRootDStatus CheckTPC(const std::string &server, uint16_t timeout=0)
Check if peer supports tpc.
static XrdCl::XRootDStatus GetProtocolVersion(const XrdCl::URL url, int &protver)
static void SplitChunks(std::vector< ChunkList > &listsvec, const ChunkList &chunks, const uint32_t maxcs, const size_t maxc)
Split chunks in a ChunkList into one or more ChunkLists.
static bool HasPgRW(const XrdCl::URL &url)
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
const uint64_t XRootDTransportMsg
std::vector< ChunkInfo > ChunkList
List of chunks.
Procedure execution status.
bool IsOK() const
We're fine.
static const uint16_t ProtocolVersion
returns the protocol version