xrootd
XrdOucErrInfo.hh
Go to the documentation of this file.
1 #ifndef __OUC_ERRINFO_H__
2 #define __OUC_ERRINFO_H__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c E r r I n f o . h h */
6 /* */
7 /* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /* */
31 /******************************************************************************/
32 
33 #include <string.h> // For strlcpy()
34 #include <sys/types.h>
35 
36 #include "XrdOuc/XrdOucBuffer.hh"
37 #include "XrdSys/XrdSysPlatform.hh"
38 
39 /******************************************************************************/
40 /* X r d O u c E I */
41 /******************************************************************************/
42 
43 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 
49 struct XrdOucEI // Err information structure
50 {
51  static const size_t Max_Error_Len = 2048;
52  static const int Path_Offset = 1024;
53 
54 const char *user;
55  int ucap;
56  int code;
58 
59 static const int uVMask = 0x0000ffff;
60 static const int uAsync = 0x80000000;
61 static const int uUrlOK = 0x40000000;
62 static const int uMProt = 0x20000000;
63 static const int uReadR = 0x10000000;
64 static const int uIPv4 = 0x08000000;
65 static const int uIPv64 = 0x04000000;
66 static const int uPrip = 0x02000000;
68 
69 inline void clear(const char *usr=0, int uc=0)
70  {code=0; ucap = uc; message[0]='\0';
71  user = (usr ? usr : "?");
72  }
73 
75  {code = rhs.code;
76  user = rhs.user;
77  ucap = rhs.ucap;
78  strcpy(message, rhs.message);
79  return *this;
80  }
81  XrdOucEI(const char *usr, int uc=0) {clear(usr, uc);}
82 };
83 
84 /******************************************************************************/
85 /* X r d O u c E r r I n f o */
86 /******************************************************************************/
87 
88 class XrdOucEICB;
89 class XrdOucEnv;
90 class XrdSysSemaphore;
91 
92 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
96 
98 {
99 public:
100 
101 //-----------------------------------------------------------------------------
103 //-----------------------------------------------------------------------------
104 
105  void clear() {Reset(); ErrInfo.clear();}
106 
107 //-----------------------------------------------------------------------------
111 //-----------------------------------------------------------------------------
112 
113 inline void setErrArg(unsigned long long cbarg=0) {ErrCBarg = cbarg;}
114 
115 //-----------------------------------------------------------------------------
120 //-----------------------------------------------------------------------------
121 
122 inline void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
123  {ErrCB = cb; ErrCBarg = cbarg;}
124 
125 //-----------------------------------------------------------------------------
131 //-----------------------------------------------------------------------------
132 
133 inline int setErrCode(int code) {return ErrInfo.code = code;}
134 
135 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
143 
144 inline int setErrInfo(int code, const char *emsg)
145  {strlcpy(ErrInfo.message, emsg, sizeof(ErrInfo.message));
146  if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;}
147  return ErrInfo.code = code;
148  }
149 
150 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
159 
160 inline int setErrInfo(int code, const char *txtlist[], int n)
161  {int i, j = 0, k = sizeof(ErrInfo.message), l;
162  for (i = 0; i < n && k > 1; i++)
163  {l = strlcpy(&ErrInfo.message[j], txtlist[i], k);
164  j += l; k -= l;
165  }
166  if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;}
167  return ErrInfo.code = code;
168  }
169 
170 //-----------------------------------------------------------------------------
178 //-----------------------------------------------------------------------------
179 
180 inline int setErrInfo(int code, XrdOucBuffer *buffP)
181  {if (dataBuff) dataBuff->Recycle();
182  dataBuff = buffP;
183  return ErrInfo.code = code;
184  }
185 
186 //-----------------------------------------------------------------------------
190 //-----------------------------------------------------------------------------
191 
192 inline void setErrUser(const char *user) {ErrInfo.user = (user ? user : "?");}
193 
194 //-----------------------------------------------------------------------------
198 //-----------------------------------------------------------------------------
199 
200 inline unsigned long long getErrArg() {return ErrCBarg;}
201 
202 //-----------------------------------------------------------------------------
208 //-----------------------------------------------------------------------------
209 
210 inline char *getMsgBuff(int &mblen)
211  {mblen = sizeof(ErrInfo.message);
212  return ErrInfo.message;
213  }
214 
215 //-----------------------------------------------------------------------------
219 //-----------------------------------------------------------------------------
220 
221 inline XrdOucEICB *getErrCB() {return ErrCB;}
222 
223 //-----------------------------------------------------------------------------
229 //-----------------------------------------------------------------------------
230 
231 inline XrdOucEICB *getErrCB(unsigned long long &ap)
232  {ap = ErrCBarg; return ErrCB;}
233 
234 //-----------------------------------------------------------------------------
238 //-----------------------------------------------------------------------------
239 
240 inline int getErrInfo() {return ErrInfo.code;}
241 
242 /*
243 //-----------------------------------------------------------------------------
249 //-----------------------------------------------------------------------------
250 inline int getErrInfo(XrdOucEI &errParm)
251  {errParm = ErrInfo; return ErrInfo.code;}
252 */
253 //-----------------------------------------------------------------------------
257 //-----------------------------------------------------------------------------
258 
259 inline const char *getErrText()
260  {if (dataBuff) return dataBuff->Data();
261  return (const char *)ErrInfo.message;
262  }
263 
264 //-----------------------------------------------------------------------------
269 //-----------------------------------------------------------------------------
270 
271 inline const char *getErrText(int &ecode)
272  {ecode = ErrInfo.code;
273  if (dataBuff) return dataBuff->Data();
274  return (const char *)ErrInfo.message;
275  }
276 
277 //-----------------------------------------------------------------------------
281 //-----------------------------------------------------------------------------
282 
283 inline int getErrTextLen()
284  {if (dataBuff) return dataBuff->DataLen();
285  return strlen(ErrInfo.message);
286  }
287 
288 //-----------------------------------------------------------------------------
292 //-----------------------------------------------------------------------------
293 
294 inline const char *getErrUser() {return ErrInfo.user;}
295 
296 //-----------------------------------------------------------------------------
302 //-----------------------------------------------------------------------------
303 
304 inline XrdOucEnv *getEnv() {return (ErrCB ? 0 : ErrEnv);}
305 
306 //-----------------------------------------------------------------------------
314 //-----------------------------------------------------------------------------
315 
316 inline XrdOucEnv *setEnv(XrdOucEnv *newEnv)
317  {XrdOucEnv *oldEnv = (ErrCB ? 0 : ErrEnv);
318  ErrEnv = newEnv;
319  ErrCB = 0;
320  return oldEnv;
321  }
322 
323 //-----------------------------------------------------------------------------
328 //-----------------------------------------------------------------------------
329 
330 inline const char *getErrData() {return (dOff < 0 ? 0 : ErrInfo.message+dOff);}
331 
332 //-----------------------------------------------------------------------------
337 //-----------------------------------------------------------------------------
338 
339 inline void setErrData(const char *Data, int Offs=0)
340  {if (!Data) dOff = -1;
341  else {strlcpy(ErrInfo.message+Offs, Data,
342  sizeof(ErrInfo.message)-Offs);
343  dOff = Offs;
344  }
345  }
346 
347 //-----------------------------------------------------------------------------
351 //-----------------------------------------------------------------------------
352 
353 inline int getErrMid() {return mID;}
354 
355 //-----------------------------------------------------------------------------
359 //-----------------------------------------------------------------------------
360 
361 inline void setErrMid(int mid) {mID = mid;}
362 
363 //-----------------------------------------------------------------------------
368 //-----------------------------------------------------------------------------
369 
370 inline bool extData() {return (dataBuff != 0);}
371 
372 //-----------------------------------------------------------------------------
374 //-----------------------------------------------------------------------------
375 
376 inline void Reset()
377  {if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;}
378  *ErrInfo.message = 0;
379  ErrInfo.code = 0;
380  }
381 
382 //-----------------------------------------------------------------------------
386 //-----------------------------------------------------------------------------
387 
388 inline int getUCap() {return ErrInfo.ucap;}
389 
390 //-----------------------------------------------------------------------------
392 //-----------------------------------------------------------------------------
393 
394 inline void setUCap(int ucval) {ErrInfo.ucap = ucval;}
395 
396 //-----------------------------------------------------------------------------
398 //-----------------------------------------------------------------------------
399 
401  {ErrInfo = rhs.ErrInfo;
402  ErrCB = rhs.ErrCB;
403  ErrCBarg= rhs.ErrCBarg;
404  mID = rhs.mID;
405  dOff = -1;
406  if (rhs.dataBuff) dataBuff = rhs.dataBuff->Clone();
407  else dataBuff = 0;
408  return *this;
409  }
410 
411 //-----------------------------------------------------------------------------
419 //-----------------------------------------------------------------------------
420 
421  XrdOucErrInfo(const char *user=0,XrdOucEICB *cb=0,
422  unsigned long long ca=0, int mid=0, int uc=0)
423  : ErrInfo(user, uc), ErrCB(cb), ErrCBarg(ca), mID(mid),
424  dOff(-1), reserved(0), dataBuff(0) {}
425 
426 //-----------------------------------------------------------------------------
432 //-----------------------------------------------------------------------------
433 
434  XrdOucErrInfo(const char *user, XrdOucEnv *envp, int uc=0)
435  : ErrInfo(user, uc), ErrCB(0), ErrEnv(envp), mID(0),
436  dOff(-1), reserved(0), dataBuff(0) {}
437 
438 //-----------------------------------------------------------------------------
444 //-----------------------------------------------------------------------------
445 
446  XrdOucErrInfo(const char *user, int MonID, int uc=0)
447  : ErrInfo(user, uc), ErrCB(0), ErrCBarg(0), mID(MonID),
448  dOff(-1), reserved(0), dataBuff(0) {}
449 
450 //-----------------------------------------------------------------------------
452 //-----------------------------------------------------------------------------
453 
454 virtual ~XrdOucErrInfo() {Reset();}
455 
456 protected:
457 
460 union {
461 unsigned long long ErrCBarg;
463  };
464 int mID;
465 short dOff;
466 short reserved;
467 XrdOucBuffer *dataBuff;
468 };
469 
470 /******************************************************************************/
471 /* X r d O u c E I C B */
472 /******************************************************************************/
473 
474 //-----------------------------------------------------------------------------
479 //-----------------------------------------------------------------------------
480 
482 {
483 public:
484 
485 //-----------------------------------------------------------------------------
499 //-----------------------------------------------------------------------------
500 
501 virtual void Done(int &Result, //I/O: Function result
502  XrdOucErrInfo *eInfo, // In: Error Info
503  const char *Path=0)=0;// In: Relevant path
504 
505 //-----------------------------------------------------------------------------
513 //-----------------------------------------------------------------------------
514 
515 virtual int Same(unsigned long long arg1, unsigned long long arg2)=0;
516 
517 //-----------------------------------------------------------------------------
519 //-----------------------------------------------------------------------------
520 
522 virtual ~XrdOucEICB() {}
523 };
524 #endif
void clear(const char *usr=0, int uc=0)
ucap: Client is on a private net
Definition: XrdOucErrInfo.hh:69
void setUCap(int ucval)
Set user capabilties.
Definition: XrdOucErrInfo.hh:394
void setErrUser(const char *user)
Definition: XrdOucErrInfo.hh:192
XrdOucErrInfo & operator=(const XrdOucErrInfo &rhs)
Assignment operator.
Definition: XrdOucErrInfo.hh:400
const char * getErrText()
Definition: XrdOucErrInfo.hh:259
int ucap
Definition: XrdOucErrInfo.hh:55
void setErrMid(int mid)
Definition: XrdOucErrInfo.hh:361
virtual ~XrdOucEICB()
Definition: XrdOucErrInfo.hh:522
const char * getErrData()
Definition: XrdOucErrInfo.hh:330
const char * getErrText(int &ecode)
Definition: XrdOucErrInfo.hh:271
void Reset()
Reset object to no message state. Call this method to release appendages.
Definition: XrdOucErrInfo.hh:376
static const int uIPv4
ucap: Supports read redirects
Definition: XrdOucErrInfo.hh:64
static const size_t Max_Error_Len
Definition: XrdOucErrInfo.hh:51
XrdOucEI & operator=(const XrdOucEI &rhs)
Definition: XrdOucErrInfo.hh:74
int getErrMid()
Definition: XrdOucErrInfo.hh:353
int getUCap()
Definition: XrdOucErrInfo.hh:388
XrdOucEICB * ErrCB
Definition: XrdOucErrInfo.hh:459
char message[Max_Error_Len]
Definition: XrdOucErrInfo.hh:57
int code
Definition: XrdOucErrInfo.hh:56
XrdOucBuffer * dataBuff
Definition: XrdOucErrInfo.hh:467
int getErrInfo()
Definition: XrdOucErrInfo.hh:240
int mID
Definition: XrdOucErrInfo.hh:464
int setErrInfo(int code, const char *txtlist[], int n)
Definition: XrdOucErrInfo.hh:160
short dOff
Definition: XrdOucErrInfo.hh:465
void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
Definition: XrdOucErrInfo.hh:122
int getErrTextLen()
Definition: XrdOucErrInfo.hh:283
void setErrData(const char *Data, int Offs=0)
Definition: XrdOucErrInfo.hh:339
XrdOucEI(const char *usr, int uc=0)
Definition: XrdOucErrInfo.hh:81
Definition: XrdOucErrInfo.hh:97
static const int uIPv64
ucap: Supports only IPv4 info
Definition: XrdOucErrInfo.hh:65
virtual void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0)=0
Definition: XrdSysPthread.hh:332
const char * user
Definition: XrdOucErrInfo.hh:54
static const int uVMask
Definition: XrdOucErrInfo.hh:59
Definition: XrdOucErrInfo.hh:49
Definition: XrdOucEnv.hh:41
unsigned long long ErrCBarg
Definition: XrdOucErrInfo.hh:461
static const int uMProt
ucap: Supports url redirects
Definition: XrdOucErrInfo.hh:62
virtual ~XrdOucErrInfo()
Destructor.
Definition: XrdOucErrInfo.hh:454
void setErrArg(unsigned long long cbarg=0)
Definition: XrdOucErrInfo.hh:113
int setErrInfo(int code, XrdOucBuffer *buffP)
Definition: XrdOucErrInfo.hh:180
char * getMsgBuff(int &mblen)
Definition: XrdOucErrInfo.hh:210
XrdOucEnv * getEnv()
Definition: XrdOucErrInfo.hh:304
static const int uAsync
ucap: Extract protocol version
Definition: XrdOucErrInfo.hh:60
bool extData()
Definition: XrdOucErrInfo.hh:370
XrdOucEICB * getErrCB(unsigned long long &ap)
Definition: XrdOucErrInfo.hh:231
virtual int Same(unsigned long long arg1, unsigned long long arg2)=0
unsigned long long getErrArg()
Definition: XrdOucErrInfo.hh:200
static const int uPrip
Definition: XrdOucErrInfo.hh:67
const char * getErrUser()
Definition: XrdOucErrInfo.hh:294
static const int uUrlOK
ucap: Supports async responses
Definition: XrdOucErrInfo.hh:61
XrdOucErrInfo(const char *user, int MonID, int uc=0)
Definition: XrdOucErrInfo.hh:446
XrdOucEI ErrInfo
Definition: XrdOucErrInfo.hh:458
static const int Path_Offset
Definition: XrdOucErrInfo.hh:52
short reserved
Definition: XrdOucErrInfo.hh:466
XrdOucEICB()
Constructor and destructor.
Definition: XrdOucErrInfo.hh:521
XrdOucErrInfo(const char *user=0, XrdOucEICB *cb=0, unsigned long long ca=0, int mid=0, int uc=0)
Definition: XrdOucErrInfo.hh:421
XrdOucEnv * setEnv(XrdOucEnv *newEnv)
Definition: XrdOucErrInfo.hh:316
int setErrCode(int code)
Definition: XrdOucErrInfo.hh:133
void clear()
Reset data and error information to null. Any appenadges are released.
Definition: XrdOucErrInfo.hh:105
XrdOucErrInfo(const char *user, XrdOucEnv *envp, int uc=0)
Definition: XrdOucErrInfo.hh:434
Definition: XrdOucErrInfo.hh:481
int setErrInfo(int code, const char *emsg)
Definition: XrdOucErrInfo.hh:144
XrdOucEICB * getErrCB()
Definition: XrdOucErrInfo.hh:221
static const int uReadR
ucap: Supports multiple protocols
Definition: XrdOucErrInfo.hh:63
XrdOucEnv * ErrEnv
Definition: XrdOucErrInfo.hh:462
size_t strlcpy(char *dst, const char *src, size_t size)