00001 #ifndef __OUC_ERRINFO_H__ 00002 #define __OUC_ERRINFO_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O u c E r r I n f o . h h */ 00006 /* */ 00007 /* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /* */ 00031 /******************************************************************************/ 00032 00033 #include <string.h> // For strlcpy() 00034 #include <sys/types.h> 00035 00036 #include "XrdOuc/XrdOucBuffer.hh" 00037 #include "XrdSys/XrdSysPlatform.hh" 00038 00039 /******************************************************************************/ 00040 /* X r d O u c E I */ 00041 /******************************************************************************/ 00042 00043 //----------------------------------------------------------------------------- 00047 //----------------------------------------------------------------------------- 00048 00049 struct XrdOucEI // Err information structure 00050 { 00051 static const size_t Max_Error_Len = 2048; 00052 static const int Path_Offset = 1024; 00053 00054 const char *user; 00055 int ucap; 00056 int code; 00057 char message[Max_Error_Len]; 00058 00059 static const int uVMask = 0x0000ffff; 00060 static const int uAsync = 0x80000000; 00061 static const int uUrlOK = 0x40000000; 00062 static const int uMProt = 0x20000000; 00063 static const int uReadR = 0x10000000; 00064 static const int uIPv4 = 0x08000000; 00065 static const int uIPv64 = 0x04000000; 00066 00067 static const int uPrip = 0x02000000; 00068 static const int uLclF = 0x01000000; 00069 static const int u48pls = 0x00800000; 00070 00071 inline void clear(const char *usr=0, int uc=0) 00072 {code=0; ucap = uc; message[0]='\0'; 00073 user = (usr ? usr : "?"); 00074 } 00075 00076 XrdOucEI &operator =(const XrdOucEI &rhs) 00077 {code = rhs.code; 00078 user = rhs.user; 00079 ucap = rhs.ucap; 00080 strcpy(message, rhs.message); 00081 return *this; 00082 } 00083 XrdOucEI(const char *usr, int uc=0) {clear(usr, uc);} 00084 }; 00085 00086 /******************************************************************************/ 00087 /* X r d O u c E r r I n f o */ 00088 /******************************************************************************/ 00089 00090 class XrdOucEICB; 00091 class XrdOucEnv; 00092 class XrdSysSemaphore; 00093 00094 //----------------------------------------------------------------------------- 00097 //----------------------------------------------------------------------------- 00098 00099 class XrdOucErrInfo 00100 { 00101 public: 00102 00103 //----------------------------------------------------------------------------- 00105 //----------------------------------------------------------------------------- 00106 00107 void clear() {Reset(); ErrInfo.clear();} 00108 00109 //----------------------------------------------------------------------------- 00113 //----------------------------------------------------------------------------- 00114 00115 inline void setErrArg(unsigned long long cbarg=0) {ErrCBarg = cbarg;} 00116 00117 //----------------------------------------------------------------------------- 00122 //----------------------------------------------------------------------------- 00123 00124 inline void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0) 00125 {ErrCB = cb; ErrCBarg = cbarg;} 00126 00127 //----------------------------------------------------------------------------- 00133 //----------------------------------------------------------------------------- 00134 00135 inline int setErrCode(int code) {return ErrInfo.code = code;} 00136 00137 //----------------------------------------------------------------------------- 00144 //----------------------------------------------------------------------------- 00145 00146 inline int setErrInfo(int code, const char *emsg) 00147 {strlcpy(ErrInfo.message, emsg, sizeof(ErrInfo.message)); 00148 if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;} 00149 return ErrInfo.code = code; 00150 } 00151 00152 //----------------------------------------------------------------------------- 00160 //----------------------------------------------------------------------------- 00161 00162 inline int setErrInfo(int code, const char *txtlist[], int n) 00163 {int i, j = 0, k = sizeof(ErrInfo.message), l; 00164 for (i = 0; i < n && k > 1; i++) 00165 {l = strlcpy(&ErrInfo.message[j], txtlist[i], k); 00166 j += l; k -= l; 00167 } 00168 if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;} 00169 return ErrInfo.code = code; 00170 } 00171 00172 //----------------------------------------------------------------------------- 00180 //----------------------------------------------------------------------------- 00181 00182 inline int setErrInfo(int code, XrdOucBuffer *buffP) 00183 {if (dataBuff) dataBuff->Recycle(); 00184 dataBuff = buffP; 00185 return ErrInfo.code = code; 00186 } 00187 00188 //----------------------------------------------------------------------------- 00192 //----------------------------------------------------------------------------- 00193 00194 inline void setErrUser(const char *user) {ErrInfo.user = (user ? user : "?");} 00195 00196 //----------------------------------------------------------------------------- 00200 //----------------------------------------------------------------------------- 00201 00202 inline unsigned long long getErrArg() {return ErrCBarg;} 00203 00204 //----------------------------------------------------------------------------- 00210 //----------------------------------------------------------------------------- 00211 00212 inline char *getMsgBuff(int &mblen) 00213 {mblen = sizeof(ErrInfo.message); 00214 return ErrInfo.message; 00215 } 00216 00217 //----------------------------------------------------------------------------- 00221 //----------------------------------------------------------------------------- 00222 00223 inline XrdOucEICB *getErrCB() {return ErrCB;} 00224 00225 //----------------------------------------------------------------------------- 00231 //----------------------------------------------------------------------------- 00232 00233 inline XrdOucEICB *getErrCB(unsigned long long &ap) 00234 {ap = ErrCBarg; return ErrCB;} 00235 00236 //----------------------------------------------------------------------------- 00240 //----------------------------------------------------------------------------- 00241 00242 inline int getErrInfo() {return ErrInfo.code;} 00243 00244 /* 00245 //----------------------------------------------------------------------------- 00251 //----------------------------------------------------------------------------- 00252 inline int getErrInfo(XrdOucEI &errParm) 00253 {errParm = ErrInfo; return ErrInfo.code;} 00254 */ 00255 //----------------------------------------------------------------------------- 00259 //----------------------------------------------------------------------------- 00260 00261 inline const char *getErrText() 00262 {if (dataBuff) return dataBuff->Data(); 00263 return (const char *)ErrInfo.message; 00264 } 00265 00266 //----------------------------------------------------------------------------- 00271 //----------------------------------------------------------------------------- 00272 00273 inline const char *getErrText(int &ecode) 00274 {ecode = ErrInfo.code; 00275 if (dataBuff) return dataBuff->Data(); 00276 return (const char *)ErrInfo.message; 00277 } 00278 00279 //----------------------------------------------------------------------------- 00283 //----------------------------------------------------------------------------- 00284 00285 inline int getErrTextLen() 00286 {if (dataBuff) return dataBuff->DataLen(); 00287 return strlen(ErrInfo.message); 00288 } 00289 00290 //----------------------------------------------------------------------------- 00294 //----------------------------------------------------------------------------- 00295 00296 inline const char *getErrUser() {return ErrInfo.user;} 00297 00298 //----------------------------------------------------------------------------- 00304 //----------------------------------------------------------------------------- 00305 00306 inline XrdOucEnv *getEnv() {return (ErrCB ? 0 : ErrEnv);} 00307 00308 //----------------------------------------------------------------------------- 00316 //----------------------------------------------------------------------------- 00317 00318 inline XrdOucEnv *setEnv(XrdOucEnv *newEnv) 00319 {XrdOucEnv *oldEnv = (ErrCB ? 0 : ErrEnv); 00320 ErrEnv = newEnv; 00321 ErrCB = 0; 00322 return oldEnv; 00323 } 00324 00325 //----------------------------------------------------------------------------- 00330 //----------------------------------------------------------------------------- 00331 00332 inline const char *getErrData() {return (dOff < 0 ? 0 : ErrInfo.message+dOff);} 00333 00334 //----------------------------------------------------------------------------- 00339 //----------------------------------------------------------------------------- 00340 00341 inline void setErrData(const char *Data, int Offs=0) 00342 {if (!Data) dOff = -1; 00343 else {strlcpy(ErrInfo.message+Offs, Data, 00344 sizeof(ErrInfo.message)-Offs); 00345 dOff = Offs; 00346 } 00347 } 00348 00349 //----------------------------------------------------------------------------- 00353 //----------------------------------------------------------------------------- 00354 00355 inline int getErrMid() {return mID;} 00356 00357 //----------------------------------------------------------------------------- 00361 //----------------------------------------------------------------------------- 00362 00363 inline void setErrMid(int mid) {mID = mid;} 00364 00365 //----------------------------------------------------------------------------- 00370 //----------------------------------------------------------------------------- 00371 00372 inline bool extData() {return (dataBuff != 0);} 00373 00374 //----------------------------------------------------------------------------- 00376 //----------------------------------------------------------------------------- 00377 00378 inline void Reset() 00379 {if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;} 00380 *ErrInfo.message = 0; 00381 ErrInfo.code = 0; 00382 } 00383 00384 //----------------------------------------------------------------------------- 00388 //----------------------------------------------------------------------------- 00389 00390 inline int getUCap() {return ErrInfo.ucap;} 00391 00392 //----------------------------------------------------------------------------- 00394 //----------------------------------------------------------------------------- 00395 00396 inline void setUCap(int ucval) {ErrInfo.ucap = ucval;} 00397 00398 //----------------------------------------------------------------------------- 00400 //----------------------------------------------------------------------------- 00401 00402 XrdOucErrInfo &operator =(const XrdOucErrInfo &rhs) 00403 {ErrInfo = rhs.ErrInfo; 00404 ErrCB = rhs.ErrCB; 00405 ErrCBarg= rhs.ErrCBarg; 00406 mID = rhs.mID; 00407 dOff = -1; 00408 if (rhs.dataBuff) dataBuff = rhs.dataBuff->Clone(); 00409 else dataBuff = 0; 00410 return *this; 00411 } 00412 00413 //----------------------------------------------------------------------------- 00421 //----------------------------------------------------------------------------- 00422 00423 XrdOucErrInfo(const char *user=0,XrdOucEICB *cb=0, 00424 unsigned long long ca=0, int mid=0, int uc=0) 00425 : ErrInfo(user, uc), ErrCB(cb), ErrCBarg(ca), mID(mid), 00426 dOff(-1), reserved(0), dataBuff(0) {} 00427 00428 //----------------------------------------------------------------------------- 00434 //----------------------------------------------------------------------------- 00435 00436 XrdOucErrInfo(const char *user, XrdOucEnv *envp, int uc=0) 00437 : ErrInfo(user, uc), ErrCB(0), ErrEnv(envp), mID(0), 00438 dOff(-1), reserved(0), dataBuff(0) {} 00439 00440 //----------------------------------------------------------------------------- 00446 //----------------------------------------------------------------------------- 00447 00448 XrdOucErrInfo(const char *user, int MonID, int uc=0) 00449 : ErrInfo(user, uc), ErrCB(0), ErrCBarg(0), mID(MonID), 00450 dOff(-1), reserved(0), dataBuff(0) {} 00451 00452 //----------------------------------------------------------------------------- 00454 //----------------------------------------------------------------------------- 00455 00456 virtual ~XrdOucErrInfo() {Reset();} 00457 00458 protected: 00459 00460 XrdOucEI ErrInfo; 00461 XrdOucEICB *ErrCB; 00462 union { 00463 unsigned long long ErrCBarg; 00464 XrdOucEnv *ErrEnv; 00465 }; 00466 int mID; 00467 short dOff; 00468 short reserved; 00469 XrdOucBuffer *dataBuff; 00470 }; 00471 00472 /******************************************************************************/ 00473 /* X r d O u c E I C B */ 00474 /******************************************************************************/ 00475 00476 //----------------------------------------------------------------------------- 00481 //----------------------------------------------------------------------------- 00482 00483 class XrdOucEICB 00484 { 00485 public: 00486 00487 //----------------------------------------------------------------------------- 00501 //----------------------------------------------------------------------------- 00502 00503 virtual void Done(int &Result, //I/O: Function result 00504 XrdOucErrInfo *eInfo, // In: Error Info 00505 const char *Path=0)=0;// In: Relevant path 00506 00507 //----------------------------------------------------------------------------- 00515 //----------------------------------------------------------------------------- 00516 00517 virtual int Same(unsigned long long arg1, unsigned long long arg2)=0; 00518 00519 //----------------------------------------------------------------------------- 00521 //----------------------------------------------------------------------------- 00522 00523 XrdOucEICB() {} 00524 virtual ~XrdOucEICB() {} 00525 }; 00526 #endif