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 static const int uLclF = 0x01000000;
69 static const int u48pls = 0x00800000;
70 
71 inline void clear(const char *usr=0, int uc=0)
72  {code=0; ucap = uc; message[0]='\0';
73  user = (usr ? usr : "?");
74  }
75 
77  {code = rhs.code;
78  user = rhs.user;
79  ucap = rhs.ucap;
80  strcpy(message, rhs.message);
81  return *this;
82  }
83  XrdOucEI(const char *usr, int uc=0) {clear(usr, uc);}
84 };
85 
86 /******************************************************************************/
87 /* X r d O u c E r r I n f o */
88 /******************************************************************************/
89 
90 class XrdOucEICB;
91 class XrdOucEnv;
92 class XrdSysSemaphore;
93 
94 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
98 
100 {
101 public:
102 
103 //-----------------------------------------------------------------------------
105 //-----------------------------------------------------------------------------
106 
107  void clear() {Reset(); ErrInfo.clear();}
108 
109 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
114 
115 inline void setErrArg(unsigned long long cbarg=0) {ErrCBarg = cbarg;}
116 
117 //-----------------------------------------------------------------------------
122 //-----------------------------------------------------------------------------
123 
124 inline void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
125  {ErrCB = cb; ErrCBarg = cbarg;}
126 
127 //-----------------------------------------------------------------------------
133 //-----------------------------------------------------------------------------
134 
135 inline int setErrCode(int code) {return ErrInfo.code = code;}
136 
137 //-----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------
145 
146 inline int setErrInfo(int code, const char *emsg)
147  {strlcpy(ErrInfo.message, emsg, sizeof(ErrInfo.message));
148  if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;}
149  return ErrInfo.code = code;
150  }
151 
152 //-----------------------------------------------------------------------------
160 //-----------------------------------------------------------------------------
161 
162 inline int setErrInfo(int code, const char *txtlist[], int n)
163  {int i, j = 0, k = sizeof(ErrInfo.message), l;
164  for (i = 0; i < n && k > 1; i++)
165  {l = strlcpy(&ErrInfo.message[j], txtlist[i], k);
166  j += l; k -= l;
167  }
168  if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;}
169  return ErrInfo.code = code;
170  }
171 
172 //-----------------------------------------------------------------------------
180 //-----------------------------------------------------------------------------
181 
182 inline int setErrInfo(int code, XrdOucBuffer *buffP)
183  {if (dataBuff) dataBuff->Recycle();
184  dataBuff = buffP;
185  return ErrInfo.code = code;
186  }
187 
188 //-----------------------------------------------------------------------------
192 //-----------------------------------------------------------------------------
193 
194 inline void setErrUser(const char *user) {ErrInfo.user = (user ? user : "?");}
195 
196 //-----------------------------------------------------------------------------
200 //-----------------------------------------------------------------------------
201 
202 inline unsigned long long getErrArg() {return ErrCBarg;}
203 
204 //-----------------------------------------------------------------------------
210 //-----------------------------------------------------------------------------
211 
212 inline char *getMsgBuff(int &mblen)
213  {mblen = sizeof(ErrInfo.message);
214  return ErrInfo.message;
215  }
216 
217 //-----------------------------------------------------------------------------
221 //-----------------------------------------------------------------------------
222 
223 inline XrdOucEICB *getErrCB() {return ErrCB;}
224 
225 //-----------------------------------------------------------------------------
231 //-----------------------------------------------------------------------------
232 
233 inline XrdOucEICB *getErrCB(unsigned long long &ap)
234  {ap = ErrCBarg; return ErrCB;}
235 
236 //-----------------------------------------------------------------------------
240 //-----------------------------------------------------------------------------
241 
242 inline int getErrInfo() {return ErrInfo.code;}
243 
244 /*
245 //-----------------------------------------------------------------------------
251 //-----------------------------------------------------------------------------
252 inline int getErrInfo(XrdOucEI &errParm)
253  {errParm = ErrInfo; return ErrInfo.code;}
254 */
255 //-----------------------------------------------------------------------------
259 //-----------------------------------------------------------------------------
260 
261 inline const char *getErrText()
262  {if (dataBuff) return dataBuff->Data();
263  return (const char *)ErrInfo.message;
264  }
265 
266 //-----------------------------------------------------------------------------
271 //-----------------------------------------------------------------------------
272 
273 inline const char *getErrText(int &ecode)
274  {ecode = ErrInfo.code;
275  if (dataBuff) return dataBuff->Data();
276  return (const char *)ErrInfo.message;
277  }
278 
279 //-----------------------------------------------------------------------------
283 //-----------------------------------------------------------------------------
284 
285 inline int getErrTextLen()
286  {if (dataBuff) return dataBuff->DataLen();
287  return strlen(ErrInfo.message);
288  }
289 
290 //-----------------------------------------------------------------------------
294 //-----------------------------------------------------------------------------
295 
296 inline const char *getErrUser() {return ErrInfo.user;}
297 
298 //-----------------------------------------------------------------------------
304 //-----------------------------------------------------------------------------
305 
306 inline XrdOucEnv *getEnv() {return (ErrCB ? 0 : ErrEnv);}
307 
308 //-----------------------------------------------------------------------------
316 //-----------------------------------------------------------------------------
317 
318 inline XrdOucEnv *setEnv(XrdOucEnv *newEnv)
319  {XrdOucEnv *oldEnv = (ErrCB ? 0 : ErrEnv);
320  ErrEnv = newEnv;
321  ErrCB = 0;
322  return oldEnv;
323  }
324 
325 //-----------------------------------------------------------------------------
330 //-----------------------------------------------------------------------------
331 
332 inline const char *getErrData() {return (dOff < 0 ? 0 : ErrInfo.message+dOff);}
333 
334 //-----------------------------------------------------------------------------
339 //-----------------------------------------------------------------------------
340 
341 inline void setErrData(const char *Data, int Offs=0)
342  {if (!Data) dOff = -1;
343  else {strlcpy(ErrInfo.message+Offs, Data,
344  sizeof(ErrInfo.message)-Offs);
345  dOff = Offs;
346  }
347  }
348 
349 //-----------------------------------------------------------------------------
353 //-----------------------------------------------------------------------------
354 
355 inline int getErrMid() {return mID;}
356 
357 //-----------------------------------------------------------------------------
361 //-----------------------------------------------------------------------------
362 
363 inline void setErrMid(int mid) {mID = mid;}
364 
365 //-----------------------------------------------------------------------------
370 //-----------------------------------------------------------------------------
371 
372 inline bool extData() {return (dataBuff != 0);}
373 
374 //-----------------------------------------------------------------------------
376 //-----------------------------------------------------------------------------
377 
378 inline void Reset()
379  {if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;}
380  *ErrInfo.message = 0;
381  ErrInfo.code = 0;
382  }
383 
384 //-----------------------------------------------------------------------------
388 //-----------------------------------------------------------------------------
389 
390 inline int getUCap() {return ErrInfo.ucap;}
391 
392 //-----------------------------------------------------------------------------
394 //-----------------------------------------------------------------------------
395 
396 inline void setUCap(int ucval) {ErrInfo.ucap = ucval;}
397 
398 //-----------------------------------------------------------------------------
400 //-----------------------------------------------------------------------------
401 
403  {ErrInfo = rhs.ErrInfo;
404  ErrCB = rhs.ErrCB;
405  ErrCBarg= rhs.ErrCBarg;
406  mID = rhs.mID;
407  dOff = -1;
408  if (rhs.dataBuff) dataBuff = rhs.dataBuff->Clone();
409  else dataBuff = 0;
410  return *this;
411  }
412 
413 //-----------------------------------------------------------------------------
421 //-----------------------------------------------------------------------------
422 
423  XrdOucErrInfo(const char *user=0,XrdOucEICB *cb=0,
424  unsigned long long ca=0, int mid=0, int uc=0)
425  : ErrInfo(user, uc), ErrCB(cb), ErrCBarg(ca), mID(mid),
426  dOff(-1), reserved(0), dataBuff(0) {}
427 
428 //-----------------------------------------------------------------------------
434 //-----------------------------------------------------------------------------
435 
436  XrdOucErrInfo(const char *user, XrdOucEnv *envp, int uc=0)
437  : ErrInfo(user, uc), ErrCB(0), ErrEnv(envp), mID(0),
438  dOff(-1), reserved(0), dataBuff(0) {}
439 
440 //-----------------------------------------------------------------------------
446 //-----------------------------------------------------------------------------
447 
448  XrdOucErrInfo(const char *user, int MonID, int uc=0)
449  : ErrInfo(user, uc), ErrCB(0), ErrCBarg(0), mID(MonID),
450  dOff(-1), reserved(0), dataBuff(0) {}
451 
452 //-----------------------------------------------------------------------------
454 //-----------------------------------------------------------------------------
455 
456 virtual ~XrdOucErrInfo() {Reset();}
457 
458 protected:
459 
462 union {
463 unsigned long long ErrCBarg;
465  };
466 int mID;
467 short dOff;
468 short reserved;
470 };
471 
472 /******************************************************************************/
473 /* X r d O u c E I C B */
474 /******************************************************************************/
475 
476 //-----------------------------------------------------------------------------
481 //-----------------------------------------------------------------------------
482 
484 {
485 public:
486 
487 //-----------------------------------------------------------------------------
501 //-----------------------------------------------------------------------------
502 
503 virtual void Done(int &Result, //I/O: Function result
504  XrdOucErrInfo *eInfo, // In: Error Info
505  const char *Path=0)=0;// In: Relevant path
506 
507 //-----------------------------------------------------------------------------
515 //-----------------------------------------------------------------------------
516 
517 virtual int Same(unsigned long long arg1, unsigned long long arg2)=0;
518 
519 //-----------------------------------------------------------------------------
521 //-----------------------------------------------------------------------------
522 
524 virtual ~XrdOucEICB() {}
525 };
526 #endif
void clear(const char *usr=0, int uc=0)
ucap: Undocumented removed in R5
Definition: XrdOucErrInfo.hh:71
void setUCap(int ucval)
Set user capabilties.
Definition: XrdOucErrInfo.hh:396
void setErrUser(const char *user)
Definition: XrdOucErrInfo.hh:194
XrdOucErrInfo & operator=(const XrdOucErrInfo &rhs)
Assignment operator.
Definition: XrdOucErrInfo.hh:402
const char * getErrText()
Definition: XrdOucErrInfo.hh:261
int ucap
Definition: XrdOucErrInfo.hh:55
void setErrMid(int mid)
Definition: XrdOucErrInfo.hh:363
virtual ~XrdOucEICB()
Definition: XrdOucErrInfo.hh:524
char * Data() const
Definition: XrdOucBuffer.hh:181
const char * getErrData()
Definition: XrdOucErrInfo.hh:332
const char * getErrText(int &ecode)
Definition: XrdOucErrInfo.hh:273
void Reset()
Reset object to no message state. Call this method to release appendages.
Definition: XrdOucErrInfo.hh:378
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:76
int getErrMid()
Definition: XrdOucErrInfo.hh:355
int getUCap()
Definition: XrdOucErrInfo.hh:390
XrdOucEICB * ErrCB
Definition: XrdOucErrInfo.hh:461
char message[Max_Error_Len]
Definition: XrdOucErrInfo.hh:57
int code
Definition: XrdOucErrInfo.hh:56
XrdOucBuffer * Clone(bool trim=true)
XrdOucBuffer * dataBuff
Definition: XrdOucErrInfo.hh:469
int getErrInfo()
Definition: XrdOucErrInfo.hh:242
int mID
Definition: XrdOucErrInfo.hh:466
int setErrInfo(int code, const char *txtlist[], int n)
Definition: XrdOucErrInfo.hh:162
short dOff
Definition: XrdOucErrInfo.hh:467
void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
Definition: XrdOucErrInfo.hh:124
int getErrTextLen()
Definition: XrdOucErrInfo.hh:285
void setErrData(const char *Data, int Offs=0)
Definition: XrdOucErrInfo.hh:341
XrdOucEI(const char *usr, int uc=0)
Definition: XrdOucErrInfo.hh:83
Definition: XrdOucErrInfo.hh:99
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:403
const char * user
Definition: XrdOucErrInfo.hh:54
static const int uVMask
Definition: XrdOucErrInfo.hh:59
static const int uLclF
ucap: Client is on a private net
Definition: XrdOucErrInfo.hh:68
Definition: XrdOucErrInfo.hh:49
Definition: XrdOucEnv.hh:41
unsigned long long ErrCBarg
Definition: XrdOucErrInfo.hh:463
static const int uMProt
ucap: Supports url redirects
Definition: XrdOucErrInfo.hh:62
virtual ~XrdOucErrInfo()
Destructor.
Definition: XrdOucErrInfo.hh:456
void setErrArg(unsigned long long cbarg=0)
Definition: XrdOucErrInfo.hh:115
static const int u48pls
ucap: Client supports "file://"
Definition: XrdOucErrInfo.hh:69
int setErrInfo(int code, XrdOucBuffer *buffP)
Definition: XrdOucErrInfo.hh:182
int DataLen()
Definition: XrdOucBuffer.hh:199
char * getMsgBuff(int &mblen)
Definition: XrdOucErrInfo.hh:212
XrdOucEnv * getEnv()
Definition: XrdOucErrInfo.hh:306
static const int uAsync
ucap: Extract protocol version
Definition: XrdOucErrInfo.hh:60
bool extData()
Definition: XrdOucErrInfo.hh:372
XrdOucEICB * getErrCB(unsigned long long &ap)
Definition: XrdOucErrInfo.hh:233
virtual int Same(unsigned long long arg1, unsigned long long arg2)=0
unsigned long long getErrArg()
Definition: XrdOucErrInfo.hh:202
static const int uPrip
Definition: XrdOucErrInfo.hh:67
Definition: XrdOucBuffer.hh:140
const char * getErrUser()
Definition: XrdOucErrInfo.hh:296
static const int uUrlOK
ucap: Supports async responses
Definition: XrdOucErrInfo.hh:61
XrdOucErrInfo(const char *user, int MonID, int uc=0)
Definition: XrdOucErrInfo.hh:448
XrdOucEI ErrInfo
Definition: XrdOucErrInfo.hh:460
static const int Path_Offset
Definition: XrdOucErrInfo.hh:52
short reserved
Definition: XrdOucErrInfo.hh:468
XrdOucEICB()
Constructor and destructor.
Definition: XrdOucErrInfo.hh:523
XrdOucErrInfo(const char *user=0, XrdOucEICB *cb=0, unsigned long long ca=0, int mid=0, int uc=0)
Definition: XrdOucErrInfo.hh:423
XrdOucEnv * setEnv(XrdOucEnv *newEnv)
Definition: XrdOucErrInfo.hh:318
void Recycle()
Recycle the buffer. The buffer may be reused in the future.
Definition: XrdOucBuffer.hh:220
int setErrCode(int code)
Definition: XrdOucErrInfo.hh:135
void clear()
Reset data and error information to null. Any appenadges are released.
Definition: XrdOucErrInfo.hh:107
XrdOucErrInfo(const char *user, XrdOucEnv *envp, int uc=0)
Definition: XrdOucErrInfo.hh:436
Definition: XrdOucErrInfo.hh:483
int setErrInfo(int code, const char *emsg)
Definition: XrdOucErrInfo.hh:146
XrdOucEICB * getErrCB()
Definition: XrdOucErrInfo.hh:223
static const int uReadR
ucap: Supports multiple protocols
Definition: XrdOucErrInfo.hh:63
XrdOucEnv * ErrEnv
Definition: XrdOucErrInfo.hh:464
size_t strlcpy(char *dst, const char *src, size_t size)