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 00070 inline void clear(const char *usr=0, int uc=0) 00071 {code=0; ucap = uc; message[0]='\0'; 00072 user = (usr ? usr : "?"); 00073 } 00074 00075 XrdOucEI &operator =(const XrdOucEI &rhs) 00076 {code = rhs.code; 00077 user = rhs.user; 00078 ucap = rhs.ucap; 00079 strcpy(message, rhs.message); 00080 return *this; 00081 } 00082 XrdOucEI(const char *usr, int uc=0) {clear(usr, uc);} 00083 }; 00084 00085 /******************************************************************************/ 00086 /* X r d O u c E r r I n f o */ 00087 /******************************************************************************/ 00088 00089 class XrdOucEICB; 00090 class XrdOucEnv; 00091 class XrdSysSemaphore; 00092 00093 //----------------------------------------------------------------------------- 00096 //----------------------------------------------------------------------------- 00097 00098 class XrdOucErrInfo 00099 { 00100 public: 00101 00102 //----------------------------------------------------------------------------- 00104 //----------------------------------------------------------------------------- 00105 00106 void clear() {Reset(); ErrInfo.clear();} 00107 00108 //----------------------------------------------------------------------------- 00112 //----------------------------------------------------------------------------- 00113 00114 inline void setErrArg(unsigned long long cbarg=0) {ErrCBarg = cbarg;} 00115 00116 //----------------------------------------------------------------------------- 00121 //----------------------------------------------------------------------------- 00122 00123 inline void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0) 00124 {ErrCB = cb; ErrCBarg = cbarg;} 00125 00126 //----------------------------------------------------------------------------- 00132 //----------------------------------------------------------------------------- 00133 00134 inline int setErrCode(int code) {return ErrInfo.code = code;} 00135 00136 //----------------------------------------------------------------------------- 00143 //----------------------------------------------------------------------------- 00144 00145 inline int setErrInfo(int code, const char *emsg) 00146 {strlcpy(ErrInfo.message, emsg, sizeof(ErrInfo.message)); 00147 if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;} 00148 return ErrInfo.code = code; 00149 } 00150 00151 //----------------------------------------------------------------------------- 00159 //----------------------------------------------------------------------------- 00160 00161 inline int setErrInfo(int code, const char *txtlist[], int n) 00162 {int i, j = 0, k = sizeof(ErrInfo.message), l; 00163 for (i = 0; i < n && k > 1; i++) 00164 {l = strlcpy(&ErrInfo.message[j], txtlist[i], k); 00165 j += l; k -= l; 00166 } 00167 if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;} 00168 return ErrInfo.code = code; 00169 } 00170 00171 //----------------------------------------------------------------------------- 00179 //----------------------------------------------------------------------------- 00180 00181 inline int setErrInfo(int code, XrdOucBuffer *buffP) 00182 {if (dataBuff) dataBuff->Recycle(); 00183 dataBuff = buffP; 00184 return ErrInfo.code = code; 00185 } 00186 00187 //----------------------------------------------------------------------------- 00191 //----------------------------------------------------------------------------- 00192 00193 inline void setErrUser(const char *user) {ErrInfo.user = (user ? user : "?");} 00194 00195 //----------------------------------------------------------------------------- 00199 //----------------------------------------------------------------------------- 00200 00201 inline unsigned long long getErrArg() {return ErrCBarg;} 00202 00203 //----------------------------------------------------------------------------- 00209 //----------------------------------------------------------------------------- 00210 00211 inline char *getMsgBuff(int &mblen) 00212 {mblen = sizeof(ErrInfo.message); 00213 return ErrInfo.message; 00214 } 00215 00216 //----------------------------------------------------------------------------- 00220 //----------------------------------------------------------------------------- 00221 00222 inline XrdOucEICB *getErrCB() {return ErrCB;} 00223 00224 //----------------------------------------------------------------------------- 00230 //----------------------------------------------------------------------------- 00231 00232 inline XrdOucEICB *getErrCB(unsigned long long &ap) 00233 {ap = ErrCBarg; return ErrCB;} 00234 00235 //----------------------------------------------------------------------------- 00239 //----------------------------------------------------------------------------- 00240 00241 inline int getErrInfo() {return ErrInfo.code;} 00242 00243 /* 00244 //----------------------------------------------------------------------------- 00250 //----------------------------------------------------------------------------- 00251 inline int getErrInfo(XrdOucEI &errParm) 00252 {errParm = ErrInfo; return ErrInfo.code;} 00253 */ 00254 //----------------------------------------------------------------------------- 00258 //----------------------------------------------------------------------------- 00259 00260 inline const char *getErrText() 00261 {if (dataBuff) return dataBuff->Data(); 00262 return (const char *)ErrInfo.message; 00263 } 00264 00265 //----------------------------------------------------------------------------- 00270 //----------------------------------------------------------------------------- 00271 00272 inline const char *getErrText(int &ecode) 00273 {ecode = ErrInfo.code; 00274 if (dataBuff) return dataBuff->Data(); 00275 return (const char *)ErrInfo.message; 00276 } 00277 00278 //----------------------------------------------------------------------------- 00282 //----------------------------------------------------------------------------- 00283 00284 inline int getErrTextLen() 00285 {if (dataBuff) return dataBuff->DataLen(); 00286 return strlen(ErrInfo.message); 00287 } 00288 00289 //----------------------------------------------------------------------------- 00293 //----------------------------------------------------------------------------- 00294 00295 inline const char *getErrUser() {return ErrInfo.user;} 00296 00297 //----------------------------------------------------------------------------- 00303 //----------------------------------------------------------------------------- 00304 00305 inline XrdOucEnv *getEnv() {return (ErrCB ? 0 : ErrEnv);} 00306 00307 //----------------------------------------------------------------------------- 00315 //----------------------------------------------------------------------------- 00316 00317 inline XrdOucEnv *setEnv(XrdOucEnv *newEnv) 00318 {XrdOucEnv *oldEnv = (ErrCB ? 0 : ErrEnv); 00319 ErrEnv = newEnv; 00320 ErrCB = 0; 00321 return oldEnv; 00322 } 00323 00324 //----------------------------------------------------------------------------- 00329 //----------------------------------------------------------------------------- 00330 00331 inline const char *getErrData() {return (dOff < 0 ? 0 : ErrInfo.message+dOff);} 00332 00333 //----------------------------------------------------------------------------- 00338 //----------------------------------------------------------------------------- 00339 00340 inline void setErrData(const char *Data, int Offs=0) 00341 {if (!Data) dOff = -1; 00342 else {strlcpy(ErrInfo.message+Offs, Data, 00343 sizeof(ErrInfo.message)-Offs); 00344 dOff = Offs; 00345 } 00346 } 00347 00348 //----------------------------------------------------------------------------- 00352 //----------------------------------------------------------------------------- 00353 00354 inline int getErrMid() {return mID;} 00355 00356 //----------------------------------------------------------------------------- 00360 //----------------------------------------------------------------------------- 00361 00362 inline void setErrMid(int mid) {mID = mid;} 00363 00364 //----------------------------------------------------------------------------- 00369 //----------------------------------------------------------------------------- 00370 00371 inline bool extData() {return (dataBuff != 0);} 00372 00373 //----------------------------------------------------------------------------- 00375 //----------------------------------------------------------------------------- 00376 00377 inline void Reset() 00378 {if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;} 00379 *ErrInfo.message = 0; 00380 ErrInfo.code = 0; 00381 } 00382 00383 //----------------------------------------------------------------------------- 00387 //----------------------------------------------------------------------------- 00388 00389 inline int getUCap() {return ErrInfo.ucap;} 00390 00391 //----------------------------------------------------------------------------- 00393 //----------------------------------------------------------------------------- 00394 00395 inline void setUCap(int ucval) {ErrInfo.ucap = ucval;} 00396 00397 //----------------------------------------------------------------------------- 00399 //----------------------------------------------------------------------------- 00400 00401 XrdOucErrInfo &operator =(const XrdOucErrInfo &rhs) 00402 {ErrInfo = rhs.ErrInfo; 00403 ErrCB = rhs.ErrCB; 00404 ErrCBarg= rhs.ErrCBarg; 00405 mID = rhs.mID; 00406 dOff = -1; 00407 if (rhs.dataBuff) dataBuff = rhs.dataBuff->Clone(); 00408 else dataBuff = 0; 00409 return *this; 00410 } 00411 00412 //----------------------------------------------------------------------------- 00420 //----------------------------------------------------------------------------- 00421 00422 XrdOucErrInfo(const char *user=0,XrdOucEICB *cb=0, 00423 unsigned long long ca=0, int mid=0, int uc=0) 00424 : ErrInfo(user, uc), ErrCB(cb), ErrCBarg(ca), mID(mid), 00425 dOff(-1), reserved(0), dataBuff(0) {} 00426 00427 //----------------------------------------------------------------------------- 00433 //----------------------------------------------------------------------------- 00434 00435 XrdOucErrInfo(const char *user, XrdOucEnv *envp, int uc=0) 00436 : ErrInfo(user, uc), ErrCB(0), ErrEnv(envp), mID(0), 00437 dOff(-1), reserved(0), dataBuff(0) {} 00438 00439 //----------------------------------------------------------------------------- 00445 //----------------------------------------------------------------------------- 00446 00447 XrdOucErrInfo(const char *user, int MonID, int uc=0) 00448 : ErrInfo(user, uc), ErrCB(0), ErrCBarg(0), mID(MonID), 00449 dOff(-1), reserved(0), dataBuff(0) {} 00450 00451 //----------------------------------------------------------------------------- 00453 //----------------------------------------------------------------------------- 00454 00455 virtual ~XrdOucErrInfo() {Reset();} 00456 00457 protected: 00458 00459 XrdOucEI ErrInfo; 00460 XrdOucEICB *ErrCB; 00461 union { 00462 unsigned long long ErrCBarg; 00463 XrdOucEnv *ErrEnv; 00464 }; 00465 int mID; 00466 short dOff; 00467 short reserved; 00468 XrdOucBuffer *dataBuff; 00469 }; 00470 00471 /******************************************************************************/ 00472 /* X r d O u c E I C B */ 00473 /******************************************************************************/ 00474 00475 //----------------------------------------------------------------------------- 00480 //----------------------------------------------------------------------------- 00481 00482 class XrdOucEICB 00483 { 00484 public: 00485 00486 //----------------------------------------------------------------------------- 00500 //----------------------------------------------------------------------------- 00501 00502 virtual void Done(int &Result, //I/O: Function result 00503 XrdOucErrInfo *eInfo, // In: Error Info 00504 const char *Path=0)=0;// In: Relevant path 00505 00506 //----------------------------------------------------------------------------- 00514 //----------------------------------------------------------------------------- 00515 00516 virtual int Same(unsigned long long arg1, unsigned long long arg2)=0; 00517 00518 //----------------------------------------------------------------------------- 00520 //----------------------------------------------------------------------------- 00521 00522 XrdOucEICB() {} 00523 virtual ~XrdOucEICB() {} 00524 }; 00525 #endif