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
38
39/******************************************************************************/
40/* X r d O u c E I */
41/******************************************************************************/
42
43//-----------------------------------------------------------------------------
47//-----------------------------------------------------------------------------
48
49struct XrdOucEI // Err information structure
50{
51 static const size_t Max_Error_Len = 2048;
52 static const int Path_Offset = 1024;
53
54const char *user;
55 int ucap;
56 int code;
58
59static const int uVMask = 0x0000ffff;
60static const int uAsync = 0x80000000;
61static const int uUrlOK = 0x40000000;
62static const int uMProt = 0x20000000;
63static const int uReadR = 0x10000000;
64static const int uIPv4 = 0x08000000;
65static const int uIPv64 = 0x04000000;
67static const int uPrip = 0x02000000;
68static const int uLclF = 0x01000000;
69static const int u48pls = 0x00800000;
70
71inline 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
90class XrdOucEICB;
91class XrdOucEnv;
92class XrdSysSemaphore;
93
94//-----------------------------------------------------------------------------
97//-----------------------------------------------------------------------------
98
100{
101public:
102
103//-----------------------------------------------------------------------------
105//-----------------------------------------------------------------------------
106
107 void clear() {Reset(); ErrInfo.clear();}
108
109//-----------------------------------------------------------------------------
113//-----------------------------------------------------------------------------
114
115inline void setErrArg(unsigned long long cbarg=0) {ErrCBarg = cbarg;}
116
117//-----------------------------------------------------------------------------
122//-----------------------------------------------------------------------------
123
124inline void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
125 {ErrCB = cb; ErrCBarg = cbarg;}
126
127//-----------------------------------------------------------------------------
133//-----------------------------------------------------------------------------
134
135inline int setErrCode(int code) {return ErrInfo.code = code;}
136
137//-----------------------------------------------------------------------------
144//-----------------------------------------------------------------------------
145
146inline 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
162inline 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
182inline int setErrInfo(int code, XrdOucBuffer *buffP)
183 {if (dataBuff) dataBuff->Recycle();
184 dataBuff = buffP;
185 return ErrInfo.code = code;
186 }
187
188//-----------------------------------------------------------------------------
192//-----------------------------------------------------------------------------
193
194inline void setErrUser(const char *user) {ErrInfo.user = (user ? user : "?");}
195
196//-----------------------------------------------------------------------------
200//-----------------------------------------------------------------------------
201
202inline unsigned long long getErrArg() {return ErrCBarg;}
203
204//-----------------------------------------------------------------------------
210//-----------------------------------------------------------------------------
211
212inline char *getMsgBuff(int &mblen)
213 {mblen = sizeof(ErrInfo.message);
214 return ErrInfo.message;
215 }
216
217//-----------------------------------------------------------------------------
221//-----------------------------------------------------------------------------
222
223inline XrdOucEICB *getErrCB() {return ErrCB;}
224
225//-----------------------------------------------------------------------------
231//-----------------------------------------------------------------------------
232
233inline XrdOucEICB *getErrCB(unsigned long long &ap)
234 {ap = ErrCBarg; return ErrCB;}
235
236//-----------------------------------------------------------------------------
240//-----------------------------------------------------------------------------
241
242inline int getErrInfo() {return ErrInfo.code;}
243
244/*
245//-----------------------------------------------------------------------------
251//-----------------------------------------------------------------------------
252inline int getErrInfo(XrdOucEI &errParm)
253 {errParm = ErrInfo; return ErrInfo.code;}
254*/
255//-----------------------------------------------------------------------------
259//-----------------------------------------------------------------------------
260
261inline const char *getErrText()
262 {if (dataBuff) return dataBuff->Data();
263 return (const char *)ErrInfo.message;
264 }
265
266//-----------------------------------------------------------------------------
271//-----------------------------------------------------------------------------
272
273inline 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
285inline int getErrTextLen()
286 {if (dataBuff) return dataBuff->DataLen();
287 return strlen(ErrInfo.message);
288 }
289
290//-----------------------------------------------------------------------------
294//-----------------------------------------------------------------------------
295
296inline const char *getErrUser() {return ErrInfo.user;}
297
298//-----------------------------------------------------------------------------
304//-----------------------------------------------------------------------------
305
306inline XrdOucEnv *getEnv() {return (ErrCB ? 0 : ErrEnv);}
307
308//-----------------------------------------------------------------------------
316//-----------------------------------------------------------------------------
317
318inline XrdOucEnv *setEnv(XrdOucEnv *newEnv)
319 {XrdOucEnv *oldEnv = (ErrCB ? 0 : ErrEnv);
320 ErrEnv = newEnv;
321 ErrCB = 0;
322 return oldEnv;
323 }
324
325//-----------------------------------------------------------------------------
330//-----------------------------------------------------------------------------
331
332inline const char *getErrData() {return (dOff < 0 ? 0 : ErrInfo.message+dOff);}
333
334//-----------------------------------------------------------------------------
339//-----------------------------------------------------------------------------
340
341inline 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
355inline int getErrMid() {return mID;}
356
357//-----------------------------------------------------------------------------
361//-----------------------------------------------------------------------------
362
363inline void setErrMid(int mid) {mID = mid;}
364
365//-----------------------------------------------------------------------------
370//-----------------------------------------------------------------------------
371
372inline bool extData() {return (dataBuff != 0);}
373
374//-----------------------------------------------------------------------------
376//-----------------------------------------------------------------------------
377
378inline void Reset()
379 {if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;}
380 *ErrInfo.message = 0;
381 ErrInfo.code = 0;
382 }
383
384//-----------------------------------------------------------------------------
388//-----------------------------------------------------------------------------
389
390inline int getUCap() {return ErrInfo.ucap;}
391
392//-----------------------------------------------------------------------------
394//-----------------------------------------------------------------------------
395
396inline 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
456virtual ~XrdOucErrInfo() {Reset();}
457
458protected:
459
462union {
463unsigned long long ErrCBarg;
465 };
466int mID;
467short dOff;
470};
471
472/******************************************************************************/
473/* X r d O u c E I C B */
474/******************************************************************************/
475
476//-----------------------------------------------------------------------------
481//-----------------------------------------------------------------------------
482
484{
485public:
486
487//-----------------------------------------------------------------------------
501//-----------------------------------------------------------------------------
502
503virtual 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
517virtual int Same(unsigned long long arg1, unsigned long long arg2)=0;
518
519//-----------------------------------------------------------------------------
521//-----------------------------------------------------------------------------
522
524virtual ~XrdOucEICB() {}
525};
526#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:484
virtual void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0)=0
virtual ~XrdOucEICB()
Definition: XrdOucErrInfo.hh:524
XrdOucEICB()
Constructor and destructor.
Definition: XrdOucErrInfo.hh:523
virtual int Same(unsigned long long arg1, unsigned long long arg2)=0
Definition: XrdOucEnv.hh:42
Definition: XrdOucErrInfo.hh:100
const char * getErrUser()
Definition: XrdOucErrInfo.hh:296
XrdOucEICB * getErrCB()
Definition: XrdOucErrInfo.hh:223
void clear()
Reset data and error information to null. Any appenadges are released.
Definition: XrdOucErrInfo.hh:107
const char * getErrText(int &ecode)
Definition: XrdOucErrInfo.hh:273
XrdOucEICB * getErrCB(unsigned long long &ap)
Definition: XrdOucErrInfo.hh:233
XrdOucEnv * ErrEnv
Definition: XrdOucErrInfo.hh:464
XrdOucErrInfo & operator=(const XrdOucErrInfo &rhs)
Assignment operator.
Definition: XrdOucErrInfo.hh:402
XrdOucEnv * getEnv()
Definition: XrdOucErrInfo.hh:306
int getErrTextLen()
Definition: XrdOucErrInfo.hh:285
char * getMsgBuff(int &mblen)
Definition: XrdOucErrInfo.hh:212
XrdOucEI ErrInfo
Definition: XrdOucErrInfo.hh:460
void setErrArg(unsigned long long cbarg=0)
Definition: XrdOucErrInfo.hh:115
void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
Definition: XrdOucErrInfo.hh:124
short reserved
Definition: XrdOucErrInfo.hh:468
XrdOucEnv * setEnv(XrdOucEnv *newEnv)
Definition: XrdOucErrInfo.hh:318
void setErrUser(const char *user)
Definition: XrdOucErrInfo.hh:194
const char * getErrData()
Definition: XrdOucErrInfo.hh:332
short dOff
Definition: XrdOucErrInfo.hh:467
unsigned long long getErrArg()
Definition: XrdOucErrInfo.hh:202
const char * getErrText()
Definition: XrdOucErrInfo.hh:261
void setErrMid(int mid)
Definition: XrdOucErrInfo.hh:363
int setErrInfo(int code, const char *txtlist[], int n)
Definition: XrdOucErrInfo.hh:162
bool extData()
Definition: XrdOucErrInfo.hh:372
int setErrInfo(int code, const char *emsg)
Definition: XrdOucErrInfo.hh:146
int getErrInfo()
Definition: XrdOucErrInfo.hh:242
XrdOucErrInfo(const char *user=0, XrdOucEICB *cb=0, unsigned long long ca=0, int mid=0, int uc=0)
Definition: XrdOucErrInfo.hh:423
int mID
Definition: XrdOucErrInfo.hh:466
XrdOucErrInfo(const char *user, int MonID, int uc=0)
Definition: XrdOucErrInfo.hh:448
void setUCap(int ucval)
Set user capabilties.
Definition: XrdOucErrInfo.hh:396
XrdOucBuffer * dataBuff
Definition: XrdOucErrInfo.hh:469
void Reset()
Reset object to no message state. Call this method to release appendages.
Definition: XrdOucErrInfo.hh:378
XrdOucErrInfo(const char *user, XrdOucEnv *envp, int uc=0)
Definition: XrdOucErrInfo.hh:436
int setErrCode(int code)
Definition: XrdOucErrInfo.hh:135
int setErrInfo(int code, XrdOucBuffer *buffP)
Definition: XrdOucErrInfo.hh:182
unsigned long long ErrCBarg
Definition: XrdOucErrInfo.hh:463
int getErrMid()
Definition: XrdOucErrInfo.hh:355
int getUCap()
Definition: XrdOucErrInfo.hh:390
XrdOucEICB * ErrCB
Definition: XrdOucErrInfo.hh:461
void setErrData(const char *Data, int Offs=0)
Definition: XrdOucErrInfo.hh:341
virtual ~XrdOucErrInfo()
Destructor.
Definition: XrdOucErrInfo.hh:456
Definition: XrdSysPthread.hh:404
Definition: XrdOucErrInfo.hh:50
int ucap
Definition: XrdOucErrInfo.hh:55
XrdOucEI & operator=(const XrdOucEI &rhs)
Definition: XrdOucErrInfo.hh:76
int code
Definition: XrdOucErrInfo.hh:56
static const int uVMask
Definition: XrdOucErrInfo.hh:59
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: Undocumented removed in R5
Definition: XrdOucErrInfo.hh:71
static const int u48pls
ucap: Client supports "file://"
Definition: XrdOucErrInfo.hh:69
static const int Path_Offset
Definition: XrdOucErrInfo.hh:52
XrdOucEI(const char *usr, int uc=0)
Definition: XrdOucErrInfo.hh:83
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