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