|
||||
File indexing completed on 2025-01-30 10:27:54
0001 #ifndef __OUC_ERRINFO_H__ 0002 #define __OUC_ERRINFO_H__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d O u c E r r I n f o . h h */ 0006 /* */ 0007 /* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */ 0008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 0009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 0010 /* */ 0011 /* This file is part of the XRootD software suite. */ 0012 /* */ 0013 /* XRootD is free software: you can redistribute it and/or modify it under */ 0014 /* the terms of the GNU Lesser General Public License as published by the */ 0015 /* Free Software Foundation, either version 3 of the License, or (at your */ 0016 /* option) any later version. */ 0017 /* */ 0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0021 /* License for more details. */ 0022 /* */ 0023 /* You should have received a copy of the GNU Lesser General Public License */ 0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0026 /* */ 0027 /* The copyright holder's institutional names and contributor's names may not */ 0028 /* be used to endorse or promote products derived from this software without */ 0029 /* specific prior written permission of the institution or contributor. */ 0030 /* */ 0031 /******************************************************************************/ 0032 0033 #include <cstring> // For strlcpy() 0034 #include <sys/types.h> 0035 0036 #include "XrdOuc/XrdOucBuffer.hh" 0037 #include "XrdSys/XrdSysPlatform.hh" 0038 0039 /******************************************************************************/ 0040 /* X r d O u c E I */ 0041 /******************************************************************************/ 0042 0043 //----------------------------------------------------------------------------- 0044 //! The XrdOucEI struct encapsulates error information. It uses a fixed buffer 0045 //! for message text and tracing information. It also allows extended 0046 //! information to be recorded in an appendage. It cannot be directly used. 0047 //----------------------------------------------------------------------------- 0048 0049 struct XrdOucEI // Err information structure 0050 { 0051 static const size_t Max_Error_Len = 2048; 0052 static const int Path_Offset = 1024; 0053 0054 const char *user; 0055 int ucap; 0056 int code; 0057 char message[Max_Error_Len]; 0058 0059 static const int uVMask = 0x0000ffff; //! ucap: Extract protocol version 0060 static const int uAsync = 0x80000000; //! ucap: Supports async responses 0061 static const int uUrlOK = 0x40000000; //! ucap: Supports url redirects 0062 static const int uMProt = 0x20000000; //! ucap: Supports multiple protocols 0063 static const int uReadR = 0x10000000; //! ucap: Supports read redirects 0064 static const int uIPv4 = 0x08000000; //! ucap: Supports only IPv4 info 0065 static const int uIPv64 = 0x04000000; //! ucap: Supports IPv6|IPv4 info and 0066 //! uIPv4 says IPv4 is prefered 0067 static const int uPrip = 0x02000000; //! ucap: Client is on a private net 0068 static const int uLclF = 0x01000000; //! ucap: Client supports "file://" 0069 static const int uRedirFlgs = 0x00800000; //! ucap: Client supports redirect flags 0070 static const int uEcRedir = 0x00400000; //! ucap: Client support EC redirects 0071 0072 inline void clear(const char *usr=0, int uc=0) 0073 {code=0; ucap = uc; message[0]='\0'; 0074 user = (usr ? usr : "?"); 0075 } 0076 0077 XrdOucEI &operator =(const XrdOucEI &rhs) 0078 {code = rhs.code; 0079 user = rhs.user; 0080 ucap = rhs.ucap; 0081 strcpy(message, rhs.message); 0082 return *this; 0083 } 0084 XrdOucEI(const char *usr, int uc=0) {clear(usr, uc);} 0085 }; 0086 0087 /******************************************************************************/ 0088 /* X r d O u c E r r I n f o */ 0089 /******************************************************************************/ 0090 0091 class XrdOucEICB; 0092 class XrdOucEnv; 0093 class XrdSysSemaphore; 0094 0095 //----------------------------------------------------------------------------- 0096 //! The XrdOucErrInfo class is used to communicate data, error, and callback 0097 //! information between plug-ins. 0098 //----------------------------------------------------------------------------- 0099 0100 class XrdOucErrInfo 0101 { 0102 public: 0103 0104 //----------------------------------------------------------------------------- 0105 //! Reset data and error information to null. Any appenadges are released. 0106 //----------------------------------------------------------------------------- 0107 0108 void clear() {Reset(); ErrInfo.clear();} 0109 0110 //----------------------------------------------------------------------------- 0111 //! Set callback argument. 0112 //! 0113 //! @param cbarg - An opaque 8-byte call-back argument. 0114 //----------------------------------------------------------------------------- 0115 0116 inline void setErrArg(unsigned long long cbarg=0) {ErrCBarg = cbarg;} 0117 0118 //----------------------------------------------------------------------------- 0119 //! Set callback information. 0120 //! 0121 //! @param cb - Pointer to the object describing the callback. 0122 //! @param cbarg - An opaque 8-byte call-back argument. 0123 //----------------------------------------------------------------------------- 0124 0125 inline void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0) 0126 {ErrCB = cb; ErrCBarg = cbarg;} 0127 0128 //----------------------------------------------------------------------------- 0129 //! Set error code. Any existing error text remains intact. 0130 //! 0131 //! @param code - The error number describing the error. 0132 //! 0133 //! @return code - The error number. 0134 //----------------------------------------------------------------------------- 0135 0136 inline int setErrCode(int code) {return ErrInfo.code = code;} 0137 0138 //----------------------------------------------------------------------------- 0139 //! Set error code and error text. 0140 //! 0141 //! @param code - The error number describing the error. 0142 //! @param emsg - The error message text. 0143 //! 0144 //! @return code - The error number. 0145 //----------------------------------------------------------------------------- 0146 0147 inline int setErrInfo(int code, const char *emsg) 0148 {strlcpy(ErrInfo.message, emsg, sizeof(ErrInfo.message)); 0149 if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;} 0150 return ErrInfo.code = code; 0151 } 0152 0153 //----------------------------------------------------------------------------- 0154 //! Set error code and error text. 0155 //! 0156 //! @param code - The error number describing the error. 0157 //! @param txtlist - A vector of error message text segments. 0158 //! @param n - The number of valid elements in txtlist. 0159 //! 0160 //! @return code - The error number. 0161 //----------------------------------------------------------------------------- 0162 0163 inline int setErrInfo(int code, const char *txtlist[], int n) 0164 {int i, j = 0, k = sizeof(ErrInfo.message), l; 0165 for (i = 0; i < n && k > 1; i++) 0166 {l = strlcpy(&ErrInfo.message[j], txtlist[i], k); 0167 j += l; k -= l; 0168 } 0169 if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;} 0170 return ErrInfo.code = code; 0171 } 0172 0173 //----------------------------------------------------------------------------- 0174 //! Set error code and error text. 0175 //! 0176 //! @param code - The error number describing the error. 0177 //! @param buffP - Pointer to the data buffer holding the error text, This 0178 //! object takes ownership of the buffer and recycles it. 0179 //! 0180 //! @return code - The error number. 0181 //----------------------------------------------------------------------------- 0182 0183 inline int setErrInfo(int code, XrdOucBuffer *buffP) 0184 {if (dataBuff) dataBuff->Recycle(); 0185 dataBuff = buffP; 0186 return ErrInfo.code = code; 0187 } 0188 0189 //----------------------------------------------------------------------------- 0190 //! Set user pointer. 0191 //! 0192 //! @param user - Pointer to a stable storage area containing the username. 0193 //----------------------------------------------------------------------------- 0194 0195 inline void setErrUser(const char *user) {ErrInfo.user = (user ? user : "?");} 0196 0197 //----------------------------------------------------------------------------- 0198 //! Obtain the callback argument. 0199 //! 0200 //! @return The argument value currently in effect. 0201 //----------------------------------------------------------------------------- 0202 0203 inline unsigned long long getErrArg() {return ErrCBarg;} 0204 0205 //----------------------------------------------------------------------------- 0206 //! Get the pointer to the internal message buffer along with its size. 0207 //! 0208 //! @param mblen - Reference to where the size it to be returned. 0209 //! 0210 //! @return Pointer to the internal message buffer. 0211 //----------------------------------------------------------------------------- 0212 0213 inline char *getMsgBuff(int &mblen) 0214 {mblen = sizeof(ErrInfo.message); 0215 return ErrInfo.message; 0216 } 0217 0218 //----------------------------------------------------------------------------- 0219 //! Get the callback object. 0220 //! 0221 //! @return Pointer to the callback object. 0222 //----------------------------------------------------------------------------- 0223 0224 inline XrdOucEICB *getErrCB() {return ErrCB;} 0225 0226 //----------------------------------------------------------------------------- 0227 //! Get the callback object and its argument. 0228 //! 0229 //! @param ap - Reference to where the callback argument is returned. 0230 //! 0231 //! @return Pointer to the callback object, ap holds the argument. 0232 //----------------------------------------------------------------------------- 0233 0234 inline XrdOucEICB *getErrCB(unsigned long long &ap) 0235 {ap = ErrCBarg; return ErrCB;} 0236 0237 //----------------------------------------------------------------------------- 0238 //! Get the error code. 0239 //! 0240 //! @return The error code that was previously set. 0241 //----------------------------------------------------------------------------- 0242 0243 inline int getErrInfo() {return ErrInfo.code;} 0244 0245 /* 0246 //----------------------------------------------------------------------------- 0247 //! Get a copy of the error information. 0248 //! 0249 //! @param errParm - Reference to where error information is to be copied. 0250 //! 0251 //! @return The error code that was previously set. 0252 //----------------------------------------------------------------------------- 0253 inline int getErrInfo(XrdOucEI &errParm) 0254 {errParm = ErrInfo; return ErrInfo.code;} 0255 */ 0256 //----------------------------------------------------------------------------- 0257 //! Get a pointer to the error text. 0258 //! 0259 //! @return The pointer to the internal error text. 0260 //----------------------------------------------------------------------------- 0261 0262 inline const char *getErrText() 0263 {if (dataBuff) return dataBuff->Data(); 0264 return (const char *)ErrInfo.message; 0265 } 0266 0267 //----------------------------------------------------------------------------- 0268 //! Get a pointer to the error text and the error code. 0269 //! 0270 //! @param ecode - Reference to where the error code is to be returned. 0271 //! @return The pointer to the internal error text. 0272 //----------------------------------------------------------------------------- 0273 0274 inline const char *getErrText(int &ecode) 0275 {ecode = ErrInfo.code; 0276 if (dataBuff) return dataBuff->Data(); 0277 return (const char *)ErrInfo.message; 0278 } 0279 0280 //----------------------------------------------------------------------------- 0281 //! Get the error text length (optimized for external buffers). 0282 //! 0283 //! @return The mesage length. 0284 //----------------------------------------------------------------------------- 0285 0286 inline int getErrTextLen() 0287 {if (dataBuff) return dataBuff->DataLen(); 0288 return strlen(ErrInfo.message); 0289 } 0290 0291 //----------------------------------------------------------------------------- 0292 //! Get a pointer to user information. 0293 //! 0294 //! @return The pointer to the user string. 0295 //----------------------------------------------------------------------------- 0296 0297 inline const char *getErrUser() {return ErrInfo.user;} 0298 0299 //----------------------------------------------------------------------------- 0300 //! Get a pointer to the error environment that was previously set. 0301 //! 0302 //! @return =0 - A callback is in effect which is mutually exclusive of 0303 //! conaining an error environment (i.e. no environment). 0304 //! @return !0 - Pointer to the error environment. 0305 //----------------------------------------------------------------------------- 0306 0307 inline XrdOucEnv *getEnv() {return (ErrCB ? 0 : ErrEnv);} 0308 0309 //----------------------------------------------------------------------------- 0310 //! Set the error environment and return the previous environment. This call 0311 //! destroys any callback information that may have existed. 0312 //! 0313 //! @param newEnv - Pointer to the new error environment. 0314 //! 0315 //! @return =0 - No previous envuironment existed. 0316 //! @return !0 - Pointer to the previous error environment. 0317 //----------------------------------------------------------------------------- 0318 0319 inline XrdOucEnv *setEnv(XrdOucEnv *newEnv) 0320 {XrdOucEnv *oldEnv = (ErrCB ? 0 : ErrEnv); 0321 ErrEnv = newEnv; 0322 ErrCB = 0; 0323 return oldEnv; 0324 } 0325 0326 //----------------------------------------------------------------------------- 0327 //! Get the error tracing data. 0328 //! 0329 //! @return =0 - No tracing data has been set. 0330 //! @return !0 - Pointer to error tracing data. 0331 //----------------------------------------------------------------------------- 0332 0333 inline const char *getErrData() {return (dOff < 0 ? 0 : ErrInfo.message+dOff);} 0334 0335 //----------------------------------------------------------------------------- 0336 //! Set the error tracing data (this is always placed in the internal buffer) 0337 //! 0338 //! @param Data - Pointer to the error tracing data. 0339 //! @param Offs - Ofset into the message buffer where the data is to be set. 0340 //----------------------------------------------------------------------------- 0341 0342 inline void setErrData(const char *Data, int Offs=0) 0343 {if (!Data) dOff = -1; 0344 else {strlcpy(ErrInfo.message+Offs, Data, 0345 sizeof(ErrInfo.message)-Offs); 0346 dOff = Offs; 0347 } 0348 } 0349 0350 //----------------------------------------------------------------------------- 0351 //! Get the monitoring identifier. 0352 //! 0353 //! @return The monitoring identifier. 0354 //----------------------------------------------------------------------------- 0355 0356 inline int getErrMid() {return mID;} 0357 0358 //----------------------------------------------------------------------------- 0359 //! Set the monitoring identifier. 0360 //----------------------------------------------------------------------------- 0361 0362 inline void setErrMid(int mid) {mID = mid;} 0363 0364 //----------------------------------------------------------------------------- 0365 //! Check if this object will return extended data (can optimize Reset() calls). 0366 //! 0367 //! @return true - there is extended data. 0368 //! false - there is no extended data. 0369 //----------------------------------------------------------------------------- 0370 0371 inline bool extData() {return (dataBuff != 0);} 0372 0373 //----------------------------------------------------------------------------- 0374 //! Reset object to no message state. Call this method to release appendages. 0375 //----------------------------------------------------------------------------- 0376 0377 inline void Reset() 0378 {if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;} 0379 *ErrInfo.message = 0; 0380 ErrInfo.code = 0; 0381 } 0382 0383 //----------------------------------------------------------------------------- 0384 //! Get user capabilties. 0385 //! 0386 //! @return the user capabilities. 0387 //----------------------------------------------------------------------------- 0388 0389 inline int getUCap() {return ErrInfo.ucap;} 0390 0391 //----------------------------------------------------------------------------- 0392 //! Set user capabilties. 0393 //----------------------------------------------------------------------------- 0394 0395 inline void setUCap(int ucval) {ErrInfo.ucap = ucval;} 0396 0397 //----------------------------------------------------------------------------- 0398 //! Assignment operator 0399 //----------------------------------------------------------------------------- 0400 0401 XrdOucErrInfo &operator =(const XrdOucErrInfo &rhs) 0402 {ErrInfo = rhs.ErrInfo; 0403 ErrCB = rhs.ErrCB; 0404 ErrCBarg= rhs.ErrCBarg; 0405 mID = rhs.mID; 0406 dOff = -1; 0407 if (rhs.dataBuff) dataBuff = rhs.dataBuff->Clone(); 0408 else dataBuff = 0; 0409 return *this; 0410 } 0411 0412 //----------------------------------------------------------------------------- 0413 //! Constructor 0414 //! 0415 //! @param user - Pointer to he user string in stable storage. 0416 //! @param cb - Pointer to the callback object (zero if none). 0417 //! @param ca - The callback argument. 0418 //! @param mid - The monitoring identifier. 0419 //! @param uc - The user capabilities. 0420 //----------------------------------------------------------------------------- 0421 0422 XrdOucErrInfo(const char *user=0,XrdOucEICB *cb=0, 0423 unsigned long long ca=0, int mid=0, int uc=0) 0424 : ErrInfo(user, uc), ErrCB(cb), ErrCBarg(ca), mID(mid), 0425 dOff(-1), reserved(0), dataBuff(0) {} 0426 0427 //----------------------------------------------------------------------------- 0428 //! Constructor 0429 //! 0430 //! @param user - Pointer to he user string in stable storage. 0431 //! @param envp - Pointer to the error environment. 0432 //! @param uc - The user capabilities. 0433 //----------------------------------------------------------------------------- 0434 0435 XrdOucErrInfo(const char *user, XrdOucEnv *envp, int uc=0) 0436 : ErrInfo(user, uc), ErrCB(0), ErrEnv(envp), mID(0), 0437 dOff(-1), reserved(0), dataBuff(0) {} 0438 0439 //----------------------------------------------------------------------------- 0440 //! Constructor 0441 //! 0442 //! @param user - Pointer to he user string in stable storage. 0443 //! @param MonID - The monitoring identifier. 0444 //! @param uc - The user capabilities. 0445 //----------------------------------------------------------------------------- 0446 0447 XrdOucErrInfo(const char *user, int MonID, int uc=0) 0448 : ErrInfo(user, uc), ErrCB(0), ErrCBarg(0), mID(MonID), 0449 dOff(-1), reserved(0), dataBuff(0) {} 0450 0451 //----------------------------------------------------------------------------- 0452 //! Destructor 0453 //----------------------------------------------------------------------------- 0454 0455 virtual ~XrdOucErrInfo() {Reset();} 0456 0457 protected: 0458 0459 XrdOucEI ErrInfo; 0460 XrdOucEICB *ErrCB; 0461 union { 0462 unsigned long long ErrCBarg; 0463 XrdOucEnv *ErrEnv; 0464 }; 0465 int mID; 0466 short dOff; 0467 short reserved; 0468 XrdOucBuffer *dataBuff; 0469 }; 0470 0471 /******************************************************************************/ 0472 /* X r d O u c E I C B */ 0473 /******************************************************************************/ 0474 0475 //----------------------------------------------------------------------------- 0476 //! The XrdOucEICB is the object that instantiates a callback. This abstract 0477 //! class is used to define the callback interface. It is normally handled by 0478 //! classes that know how to deal with this object in a user friendly way 0479 //! (e.g. XrdOucCallBack). 0480 //----------------------------------------------------------------------------- 0481 0482 class XrdOucEICB 0483 { 0484 public: 0485 0486 //----------------------------------------------------------------------------- 0487 //! Invoke a callback after an operation completes. 0488 //! 0489 //! @param Result - the original function's result (may be changed). 0490 //! @param eInfo - Associated error information. The eInfo object may not be 0491 //! modified until it's own callback Done() method is called, if 0492 //! supplied. If the callback function in eInfo is zero, then 0493 //! the eInfo object is deleted by the invoked callback. 0494 //! Otherwise, that method must be invoked by this callback 0495 //! function after the actual callback message is sent. This 0496 //! allows the callback requestor to do post-processing and be 0497 //! asynchronous being assured that the callback completed. 0498 //! @param Path - Optionally, the path related to thid request. It is used 0499 //! for tracing and detailed monitoring purposes. 0500 //----------------------------------------------------------------------------- 0501 0502 virtual void Done(int &Result, //I/O: Function result 0503 XrdOucErrInfo *eInfo, // In: Error Info 0504 const char *Path=0)=0;// In: Relevant path 0505 0506 //----------------------------------------------------------------------------- 0507 //! Determine if two callback arguments refer to the same client. 0508 //! 0509 //! @param arg1 - The first callback argument. 0510 //! @param arg2 - The second callback argument. 0511 //! 0512 //! @return !0 - The arguments refer to the same client. 0513 //! @return =0 - The arguments refer to the different clients. 0514 //----------------------------------------------------------------------------- 0515 0516 virtual int Same(unsigned long long arg1, unsigned long long arg2)=0; 0517 0518 //----------------------------------------------------------------------------- 0519 //! Constructor and destructor 0520 //----------------------------------------------------------------------------- 0521 0522 XrdOucEICB() {} 0523 virtual ~XrdOucEICB() {} 0524 }; 0525 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |