Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-14 08:38:23

0001 #ifndef __XRDOUCUTILS_HH__
0002 #define __XRDOUCUTILS_HH__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                        X r d O u c U t i l s . h h                         */
0006 /*                                                                            */
0007 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 #include <sys/types.h>
0034 #include <sys/stat.h>
0035 #include <string>
0036 #include <unordered_set>
0037 #include <vector>
0038 
0039 class XrdSysError;
0040 class XrdOucString;
0041 class XrdOucStream;
0042 
0043 class XrdOucUtils
0044 {
0045 public:
0046 
0047 static const mode_t pathMode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
0048 
0049 static int   argList(char *args, char **argV, int argC);
0050 
0051 static char *bin2hex(char *inbuff, int dlen, char *buff, int blen, bool sep=true);
0052 
0053 static int hex2bin(const char *hex, char *bin, int size);
0054 
0055 static bool  endsWith(const char *text, const char *ending, int endlen);
0056 
0057 static char *eText(int rc, char *eBuff, int eBlen);
0058 
0059 static int   doIf(XrdSysError *eDest, XrdOucStream &Config,
0060                   const char *what, const char *hname, 
0061                                     const char *nname, const char *pname);
0062 
0063 static bool  findPgm(const char *pgm, XrdOucString& path);
0064  
0065 static int   fmtBytes(long long val, char *buff, int bsz);
0066 
0067 static char *genPath(const char *path, const char *inst, const char *psfx=0);
0068 
0069 static int   genPath(char *buff, int blen, const char *path, const char *psfx=0);
0070 
0071 static char *getFile(const char *path, int &rc, int maxsz=10240,
0072                      bool notempty=true);
0073 
0074 static bool  getGID(const char *gName, gid_t &gID);
0075 
0076 static bool  getUID(const char *uName, uid_t &uID, gid_t *gID=0);
0077 
0078 static int   GidName(gid_t gID, char *gName, int gNsz, time_t keepT=0);
0079 
0080 static int   GroupName(gid_t gID, char *gName, int gNsz);
0081 
0082 static const char *i2bstr(char *buff, int blen, int val, bool pad=false);
0083 
0084 static const char *HSize(size_t bytes, char* buff, int bsz);
0085 
0086 static char *Ident(long long  &mySID, char *iBuff, int iBlen,
0087                    const char *iHost, const char *iProg, const char *iName,
0088                    int Port);
0089 
0090 static const char *InstName(int TranOpt=0);
0091 
0092 static const char *InstName(const char *name, int Fillit=1);
0093 
0094 static int   is1of(char *val, const char **clist);
0095 
0096 static int   isFWD(const char *path, int *port=0, char *hBuff=0, int hBLen=0,
0097                    bool pTrim=false);
0098 
0099 static int   Log2(unsigned long long n);
0100 
0101 static int   Log10(unsigned long long n);
0102 
0103 static void  makeHome(XrdSysError &eDest, const char *inst);
0104 
0105 static bool  makeHome(XrdSysError &eDest, const char *inst,
0106                                           const char *path, mode_t mode);
0107 
0108 static int   makePath(char *path, mode_t mode, bool reset=false);
0109 
0110 static bool  mode2mask(const char *mode, mode_t &mask);
0111 
0112 static bool  parseLib(XrdSysError &eDest, XrdOucStream &Config,
0113                       const char *libName, char *&path, char **libparm);
0114 
0115 static char *parseHome(XrdSysError &eDest, XrdOucStream &Config, int &mode);
0116 
0117 static int   ReLink(const char *path, const char *target, mode_t mode=0);
0118 
0119 static void  Sanitize(char *instr, char subc='_');
0120  
0121 static char *subLogfn(XrdSysError &eDest, const char *inst, char *logfn);
0122 
0123 static void  toLower(char *str);
0124 
0125 static int   Token(const char **str, char delim, char *buff, int bsz);
0126 
0127 static void  Undercover(XrdSysError &eDest, int noLog, int *pipeFD = 0);
0128 
0129 static int   UidName(uid_t uID, char *uName, int uNsz, time_t keepT=0);
0130 
0131 static int   UserName(uid_t uID, char *uName, int uNsz);
0132 
0133 static
0134 const char  *ValPath(const char *path, mode_t allow, bool isdir);
0135 
0136 static bool PidFile(XrdSysError &eDest, const char *path);
0137 
0138 static int getModificationTime(const char * path, time_t & modificationTime);
0139 
0140 static void trim(std::string & str);
0141 
0142 static void trim(std::string_view & sv);
0143 
0144     XrdOucUtils() {}
0145     ~XrdOucUtils() {}
0146 
0147 };
0148 #endif