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