xrootd
Loading...
Searching...
No Matches
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
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 uRedirFlgs = 0x00800000;
70static const int uEcRedir = 0x00400000;
71
72inline 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
91class XrdOucEICB;
92class XrdOucEnv;
93class XrdSysSemaphore;
94
95//-----------------------------------------------------------------------------
98//-----------------------------------------------------------------------------
99
101{
102public:
103
104//-----------------------------------------------------------------------------
106//-----------------------------------------------------------------------------
107
108 void clear() {Reset(); ErrInfo.clear();}
109
110//-----------------------------------------------------------------------------
114//-----------------------------------------------------------------------------
115
116inline void setErrArg(unsigned long long cbarg=0) {ErrCBarg = cbarg;}
117
118//-----------------------------------------------------------------------------
123//-----------------------------------------------------------------------------
124
125inline void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
126 {ErrCB = cb; ErrCBarg = cbarg;}
127
128//-----------------------------------------------------------------------------
134//-----------------------------------------------------------------------------
135
136inline int setErrCode(int code) {return ErrInfo.code = code;}
137
138//-----------------------------------------------------------------------------
145//-----------------------------------------------------------------------------
146
147inline 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
163inline 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
183inline int setErrInfo(int code, XrdOucBuffer *buffP)
184 {if (dataBuff) dataBuff->Recycle();
185 dataBuff = buffP;
186 return ErrInfo.code = code;
187 }
188
189//-----------------------------------------------------------------------------
193//-----------------------------------------------------------------------------
194
195inline void setErrUser(const char *user) {ErrInfo.user = (user ? user : "?");}
196
197//-----------------------------------------------------------------------------
201//-----------------------------------------------------------------------------
202
203inline unsigned long long getErrArg() {return ErrCBarg;}
204
205//-----------------------------------------------------------------------------
211//-----------------------------------------------------------------------------
212
213inline char *getMsgBuff(int &mblen)
214 {mblen = sizeof(ErrInfo.message);
215 return ErrInfo.message;
216 }
217
218//-----------------------------------------------------------------------------
222//-----------------------------------------------------------------------------
223
224inline XrdOucEICB *getErrCB() {return ErrCB;}
225
226//-----------------------------------------------------------------------------
232//-----------------------------------------------------------------------------
233
234inline XrdOucEICB *getErrCB(unsigned long long &ap)
235 {ap = ErrCBarg; return ErrCB;}
236
237//-----------------------------------------------------------------------------
241//-----------------------------------------------------------------------------
242
243inline int getErrInfo() {return ErrInfo.code;}
244
245/*
246//-----------------------------------------------------------------------------
252//-----------------------------------------------------------------------------
253inline int getErrInfo(XrdOucEI &errParm)
254 {errParm = ErrInfo; return ErrInfo.code;}
255*/
256//-----------------------------------------------------------------------------
260//-----------------------------------------------------------------------------
261
262inline const char *getErrText()
263 {if (dataBuff) return dataBuff->Data();
264 return (const char *)ErrInfo.message;
265 }
266
267//-----------------------------------------------------------------------------
272//-----------------------------------------------------------------------------
273
274inline 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
286inline int getErrTextLen()
287 {if (dataBuff) return dataBuff->DataLen();
288 return strlen(ErrInfo.message);
289 }
290
291//-----------------------------------------------------------------------------
295//-----------------------------------------------------------------------------
296
297inline const char *getErrUser() {return ErrInfo.user;}
298
299//-----------------------------------------------------------------------------
305//-----------------------------------------------------------------------------
306
307inline XrdOucEnv *getEnv() {return (ErrCB ? 0 : ErrEnv);}
308
309//-----------------------------------------------------------------------------
317//-----------------------------------------------------------------------------
318
319inline XrdOucEnv *setEnv(XrdOucEnv *newEnv)
320 {XrdOucEnv *oldEnv = (ErrCB ? 0 : ErrEnv);
321 ErrEnv = newEnv;
322 ErrCB = 0;
323 return oldEnv;
324 }
325
326//-----------------------------------------------------------------------------
331//-----------------------------------------------------------------------------
332
333inline const char *getErrData() {return (dOff < 0 ? 0 : ErrInfo.message+dOff);}
334
335//-----------------------------------------------------------------------------
340//-----------------------------------------------------------------------------
341
342inline 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
356inline int getErrMid() {return mID;}
357
358//-----------------------------------------------------------------------------
360//-----------------------------------------------------------------------------
361
362inline void setErrMid(int mid) {mID = mid;}
363
364//-----------------------------------------------------------------------------
369//-----------------------------------------------------------------------------
370
371inline bool extData() {return (dataBuff != 0);}
372
373//-----------------------------------------------------------------------------
375//-----------------------------------------------------------------------------
376
377inline void Reset()
378 {if (dataBuff) {dataBuff->Recycle(); dataBuff = 0;}
379 *ErrInfo.message = 0;
380 ErrInfo.code = 0;
381 }
382
383//-----------------------------------------------------------------------------
387//-----------------------------------------------------------------------------
388
389inline int getUCap() {return ErrInfo.ucap;}
390
391//-----------------------------------------------------------------------------
393//-----------------------------------------------------------------------------
394
395inline 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
455virtual ~XrdOucErrInfo() {Reset();}
456
457protected:
458
461union {
462unsigned long long ErrCBarg;
464 };
465int mID;
466short dOff;
469};
470
471/******************************************************************************/
472/* X r d O u c E I C B */
473/******************************************************************************/
474
475//-----------------------------------------------------------------------------
480//-----------------------------------------------------------------------------
481
483{
484public:
485
486//-----------------------------------------------------------------------------
500//-----------------------------------------------------------------------------
501
502virtual 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
516virtual int Same(unsigned long long arg1, unsigned long long arg2)=0;
517
518//-----------------------------------------------------------------------------
520//-----------------------------------------------------------------------------
521
523virtual ~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:101
const char * getErrUser()
Definition XrdOucErrInfo.hh:297
XrdOucEICB * getErrCB()
Definition XrdOucErrInfo.hh:224
void clear()
Reset data and error information to null. Any appenadges are released.
Definition XrdOucErrInfo.hh:108
const char * getErrText(int &ecode)
Definition XrdOucErrInfo.hh:274
XrdOucEICB * getErrCB(unsigned long long &ap)
Definition XrdOucErrInfo.hh:234
XrdOucEnv * ErrEnv
Definition XrdOucErrInfo.hh:463
XrdOucErrInfo & operator=(const XrdOucErrInfo &rhs)
Assignment operator.
Definition XrdOucErrInfo.hh:401
XrdOucEnv * getEnv()
Definition XrdOucErrInfo.hh:307
int getErrTextLen()
Definition XrdOucErrInfo.hh:286
char * getMsgBuff(int &mblen)
Definition XrdOucErrInfo.hh:213
XrdOucEI ErrInfo
Definition XrdOucErrInfo.hh:459
void setErrArg(unsigned long long cbarg=0)
Definition XrdOucErrInfo.hh:116
void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
Definition XrdOucErrInfo.hh:125
short reserved
Definition XrdOucErrInfo.hh:467
XrdOucEnv * setEnv(XrdOucEnv *newEnv)
Definition XrdOucErrInfo.hh:319
void setErrUser(const char *user)
Definition XrdOucErrInfo.hh:195
const char * getErrData()
Definition XrdOucErrInfo.hh:333
short dOff
Definition XrdOucErrInfo.hh:466
unsigned long long getErrArg()
Definition XrdOucErrInfo.hh:203
const char * getErrText()
Definition XrdOucErrInfo.hh:262
void setErrMid(int mid)
Set the monitoring identifier.
Definition XrdOucErrInfo.hh:362
int setErrInfo(int code, const char *txtlist[], int n)
Definition XrdOucErrInfo.hh:163
bool extData()
Definition XrdOucErrInfo.hh:371
int setErrInfo(int code, const char *emsg)
Definition XrdOucErrInfo.hh:147
int getErrInfo()
Definition XrdOucErrInfo.hh:243
XrdOucErrInfo(const char *user=0, XrdOucEICB *cb=0, unsigned long long ca=0, int mid=0, int uc=0)
Definition XrdOucErrInfo.hh:422
int mID
Definition XrdOucErrInfo.hh:465
XrdOucErrInfo(const char *user, int MonID, int uc=0)
Definition XrdOucErrInfo.hh:447
void setUCap(int ucval)
Set user capabilties.
Definition XrdOucErrInfo.hh:395
XrdOucBuffer * dataBuff
Definition XrdOucErrInfo.hh:468
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:136
int setErrInfo(int code, XrdOucBuffer *buffP)
Definition XrdOucErrInfo.hh:183
unsigned long long ErrCBarg
Definition XrdOucErrInfo.hh:462
int getErrMid()
Definition XrdOucErrInfo.hh:356
int getUCap()
Definition XrdOucErrInfo.hh:389
XrdOucEICB * ErrCB
Definition XrdOucErrInfo.hh:460
void setErrData(const char *Data, int Offs=0)
Definition XrdOucErrInfo.hh:342
virtual ~XrdOucErrInfo()
Destructor.
Definition XrdOucErrInfo.hh:455
Definition XrdSysPthread.hh:494
Definition XrdOucErrInfo.hh:50
int ucap
Definition XrdOucErrInfo.hh:55
XrdOucEI & operator=(const XrdOucEI &rhs)
Definition XrdOucErrInfo.hh:77
int code
Definition XrdOucErrInfo.hh:56
static const int uRedirFlgs
ucap: Client supports "file://"
Definition XrdOucErrInfo.hh:69
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 int uEcRedir
ucap: Client supports redirect flags
Definition XrdOucErrInfo.hh:70
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 support EC redirects
Definition XrdOucErrInfo.hh:72
static const int Path_Offset
Definition XrdOucErrInfo.hh:52
XrdOucEI(const char *usr, int uc=0)
Definition XrdOucErrInfo.hh:84
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