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