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 <cstring> // 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 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)
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 //-----------------------------------------------------------------------------
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;
463 XrdOucEnv *ErrEnv;
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
XrdOucString Path
int emsg(int rc, char *msg)
size_t strlcpy(char *dst, const char *src, size_t sz)
char * Data() const
XrdOucBuffer * Clone(bool trim=true)
void Recycle()
Recycle the buffer. The buffer may be reused in the future.
virtual void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0)=0
virtual ~XrdOucEICB()
XrdOucEICB()
Constructor and destructor.
virtual int Same(unsigned long long arg1, unsigned long long arg2)=0
void clear()
Reset data and error information to null. Any appenadges are released.
const char * getErrText(int &ecode)
const char * getErrData()
XrdOucEICB * getErrCB()
XrdOucEI ErrInfo
void setErrArg(unsigned long long cbarg=0)
void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
void setErrUser(const char *user)
unsigned long long getErrArg()
const char * getErrText()
void setErrMid(int mid)
Set the monitoring identifier.
int setErrInfo(int code, const char *txtlist[], int n)
int setErrInfo(int code, const char *emsg)
XrdOucErrInfo(const char *user=0, XrdOucEICB *cb=0, unsigned long long ca=0, int mid=0, int uc=0)
char * getMsgBuff(int &mblen)
XrdOucEICB * getErrCB(unsigned long long &ap)
XrdOucErrInfo(const char *user, int MonID, int uc=0)
void setUCap(int ucval)
Set user capabilties.
XrdOucEnv * getEnv()
XrdOucBuffer * dataBuff
XrdOucEnv * setEnv(XrdOucEnv *newEnv)
const char * getErrUser()
void Reset()
Reset object to no message state. Call this method to release appendages.
XrdOucErrInfo(const char *user, XrdOucEnv *envp, int uc=0)
int setErrCode(int code)
int setErrInfo(int code, XrdOucBuffer *buffP)
XrdOucErrInfo & operator=(const XrdOucErrInfo &rhs)
Assignment operator.
XrdOucEICB * ErrCB
void setErrData(const char *Data, int Offs=0)
virtual ~XrdOucErrInfo()
Destructor.
static const int uRedirFlgs
ucap: Client supports "file://"
static const int uVMask
XrdOucEI & operator=(const XrdOucEI &rhs)
static const int uUrlOK
ucap: Supports async responses
static const int uIPv64
ucap: Supports only IPv4 info
char message[Max_Error_Len]
static const int uReadR
ucap: Supports multiple protocols
static const int uEcRedir
ucap: Client supports redirect flags
static const size_t Max_Error_Len
static const int uMProt
ucap: Supports url redirects
void clear(const char *usr=0, int uc=0)
ucap: Client support EC redirects
static const int Path_Offset
XrdOucEI(const char *usr, int uc=0)
static const int uLclF
ucap: Client is on a private net
static const int uAsync
ucap: Extract protocol version
static const int uIPv4
ucap: Supports read redirects
const char * user
static const int uPrip