xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdOuc
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
;
57
char
message
[
Max_Error_Len
];
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
67
static
const
int
uPrip
= 0x02000000;
68
69
inline
void
clear
(
const
char
*usr=0,
int
uc=0)
70
{
code
=0;
ucap
= uc;
message
[0]=
'\0'
;
71
user
= (usr ? usr :
"?"
);
72
}
73
74
XrdOucEI
&
operator =
(
const
XrdOucEI
&rhs)
75
{
code
= rhs.
code
;
76
user
= rhs.
user
;
77
ucap
= rhs.
ucap
;
78
strcpy(
message
, rhs.
message
);
79
return
*
this
;
80
}
81
XrdOucEI
(
const
char
*usr,
int
uc=0) {
clear
(usr, uc);}
82
};
83
84
/******************************************************************************/
85
/* X r d O u c E r r I n f o */
86
/******************************************************************************/
87
88
class
XrdOucEICB
;
89
class
XrdOucEnv
;
90
class
XrdSysSemaphore
;
91
92
//-----------------------------------------------------------------------------
95
//-----------------------------------------------------------------------------
96
97
class
XrdOucErrInfo
98
{
99
public
:
100
101
//-----------------------------------------------------------------------------
103
//-----------------------------------------------------------------------------
104
105
void
clear
() {
Reset
();
ErrInfo
.
clear
();}
106
107
//-----------------------------------------------------------------------------
111
//-----------------------------------------------------------------------------
112
113
inline
void
setErrArg
(
unsigned
long
long
cbarg=0) {
ErrCBarg
= cbarg;}
114
115
//-----------------------------------------------------------------------------
120
//-----------------------------------------------------------------------------
121
122
inline
void
setErrCB
(
XrdOucEICB
*cb,
unsigned
long
long
cbarg=0)
123
{
ErrCB
= cb;
ErrCBarg
= cbarg;}
124
125
//-----------------------------------------------------------------------------
131
//-----------------------------------------------------------------------------
132
133
inline
int
setErrCode
(
int
code) {
return
ErrInfo
.
code
= code;}
134
135
//-----------------------------------------------------------------------------
142
//-----------------------------------------------------------------------------
143
144
inline
int
setErrInfo
(
int
code,
const
char
*emsg)
145
{
strlcpy
(
ErrInfo
.
message
, emsg,
sizeof
(
ErrInfo
.
message
));
146
if
(
dataBuff
) {
dataBuff
->Recycle();
dataBuff
= 0;}
147
return
ErrInfo
.
code
= code;
148
}
149
150
//-----------------------------------------------------------------------------
158
//-----------------------------------------------------------------------------
159
160
inline
int
setErrInfo
(
int
code,
const
char
*txtlist[],
int
n)
161
{
int
i, j = 0, k =
sizeof
(
ErrInfo
.
message
), l;
162
for
(i = 0; i < n && k > 1; i++)
163
{l =
strlcpy
(&
ErrInfo
.
message
[j], txtlist[i], k);
164
j += l; k -= l;
165
}
166
if
(
dataBuff
) {
dataBuff
->Recycle();
dataBuff
= 0;}
167
return
ErrInfo
.
code
= code;
168
}
169
170
//-----------------------------------------------------------------------------
178
//-----------------------------------------------------------------------------
179
180
inline
int
setErrInfo
(
int
code, XrdOucBuffer *buffP)
181
{
if
(
dataBuff
)
dataBuff
->Recycle();
182
dataBuff
= buffP;
183
return
ErrInfo
.
code
= code;
184
}
185
186
//-----------------------------------------------------------------------------
190
//-----------------------------------------------------------------------------
191
192
inline
void
setErrUser
(
const
char
*user) {
ErrInfo
.
user
= (user ? user :
"?"
);}
193
194
//-----------------------------------------------------------------------------
198
//-----------------------------------------------------------------------------
199
200
inline
unsigned
long
long
getErrArg
() {
return
ErrCBarg
;}
201
202
//-----------------------------------------------------------------------------
208
//-----------------------------------------------------------------------------
209
210
inline
char
*
getMsgBuff
(
int
&mblen)
211
{mblen =
sizeof
(
ErrInfo
.
message
);
212
return
ErrInfo
.
message
;
213
}
214
215
//-----------------------------------------------------------------------------
219
//-----------------------------------------------------------------------------
220
221
inline
XrdOucEICB
*
getErrCB
() {
return
ErrCB
;}
222
223
//-----------------------------------------------------------------------------
229
//-----------------------------------------------------------------------------
230
231
inline
XrdOucEICB
*
getErrCB
(
unsigned
long
long
&ap)
232
{ap =
ErrCBarg
;
return
ErrCB
;}
233
234
//-----------------------------------------------------------------------------
238
//-----------------------------------------------------------------------------
239
240
inline
int
getErrInfo
() {
return
ErrInfo
.
code
;}
241
242
//-----------------------------------------------------------------------------
248
//-----------------------------------------------------------------------------
249
/*
250
inline int getErrInfo(XrdOucEI &errParm)
251
{errParm = ErrInfo; return ErrInfo.code;}
252
*/
253
//-----------------------------------------------------------------------------
257
//-----------------------------------------------------------------------------
258
259
inline
const
char
*
getErrText
()
260
{
if
(
dataBuff
)
return
dataBuff
->Data();
261
return
(
const
char
*)
ErrInfo
.
message
;
262
}
263
264
//-----------------------------------------------------------------------------
269
//-----------------------------------------------------------------------------
270
271
inline
const
char
*
getErrText
(
int
&ecode)
272
{ecode =
ErrInfo
.
code
;
273
if
(
dataBuff
)
return
dataBuff
->Data();
274
return
(
const
char
*)
ErrInfo
.
message
;
275
}
276
277
//-----------------------------------------------------------------------------
281
//-----------------------------------------------------------------------------
282
283
inline
int
getErrTextLen
()
284
{
if
(
dataBuff
)
return
dataBuff
->DataLen();
285
return
strlen(
ErrInfo
.
message
);
286
}
287
288
//-----------------------------------------------------------------------------
292
//-----------------------------------------------------------------------------
293
294
inline
const
char
*
getErrUser
() {
return
ErrInfo
.
user
;}
295
296
//-----------------------------------------------------------------------------
302
//-----------------------------------------------------------------------------
303
304
inline
XrdOucEnv
*
getEnv
() {
return
(
ErrCB
? 0 :
ErrEnv
);}
305
306
//-----------------------------------------------------------------------------
314
//-----------------------------------------------------------------------------
315
316
inline
XrdOucEnv
*
setEnv
(
XrdOucEnv
*newEnv)
317
{
XrdOucEnv
*oldEnv = (
ErrCB
? 0 :
ErrEnv
);
318
ErrEnv
= newEnv;
319
ErrCB
= 0;
320
return
oldEnv;
321
}
322
323
//-----------------------------------------------------------------------------
328
//-----------------------------------------------------------------------------
329
330
inline
const
char
*
getErrData
() {
return
(
dOff
< 0 ? 0 :
ErrInfo
.
message
+
dOff
);}
331
332
//-----------------------------------------------------------------------------
337
//-----------------------------------------------------------------------------
338
339
inline
void
setErrData
(
const
char
*Data,
int
Offs=0)
340
{
if
(!Data)
dOff
= -1;
341
else
{
strlcpy
(
ErrInfo
.
message
+Offs, Data,
342
sizeof
(
ErrInfo
.
message
)-Offs);
343
dOff
= Offs;
344
}
345
}
346
347
//-----------------------------------------------------------------------------
351
//-----------------------------------------------------------------------------
352
353
inline
int
getErrMid
() {
return
mID
;}
354
355
//-----------------------------------------------------------------------------
359
//-----------------------------------------------------------------------------
360
361
inline
void
setErrMid
(
int
mid) {
mID
= mid;}
362
363
//-----------------------------------------------------------------------------
368
//-----------------------------------------------------------------------------
369
370
inline
bool
extData
() {
return
(
dataBuff
!= 0);}
371
372
//-----------------------------------------------------------------------------
374
//-----------------------------------------------------------------------------
375
376
inline
void
Reset
()
377
{
if
(
dataBuff
) {
dataBuff
->Recycle();
dataBuff
= 0;}
378
*
ErrInfo
.
message
= 0;
379
ErrInfo
.
code
= 0;
380
}
381
382
//-----------------------------------------------------------------------------
386
//-----------------------------------------------------------------------------
387
388
inline
int
getUCap
() {
return
ErrInfo
.
ucap
;}
389
390
//-----------------------------------------------------------------------------
392
//-----------------------------------------------------------------------------
393
394
inline
void
setUCap
(
int
ucval) {
ErrInfo
.
ucap
= ucval;}
395
396
//-----------------------------------------------------------------------------
398
//-----------------------------------------------------------------------------
399
400
XrdOucErrInfo
&
operator =
(
const
XrdOucErrInfo
&rhs)
401
{
ErrInfo
= rhs.
ErrInfo
;
402
ErrCB
= rhs.
ErrCB
;
403
ErrCBarg
= rhs.
ErrCBarg
;
404
mID
= rhs.
mID
;
405
dOff
= -1;
406
if
(rhs.
dataBuff
)
dataBuff
= rhs.
dataBuff
->Clone();
407
else
dataBuff
= 0;
408
return
*
this
;
409
}
410
411
//-----------------------------------------------------------------------------
419
//-----------------------------------------------------------------------------
420
421
XrdOucErrInfo
(
const
char
*user=0,
XrdOucEICB
*cb=0,
422
unsigned
long
long
ca=0,
int
mid=0,
int
uc=0)
423
:
ErrInfo
(user, uc),
ErrCB
(cb),
ErrCBarg
(ca),
mID
(mid),
424
dOff
(-1),
reserved
(0),
dataBuff
(0) {}
425
426
//-----------------------------------------------------------------------------
432
//-----------------------------------------------------------------------------
433
434
XrdOucErrInfo
(
const
char
*user,
XrdOucEnv
*envp,
int
uc=0)
435
:
ErrInfo
(user, uc),
ErrCB
(0),
ErrEnv
(envp),
mID
(0),
436
dOff
(-1),
reserved
(0),
dataBuff
(0) {}
437
438
//-----------------------------------------------------------------------------
444
//-----------------------------------------------------------------------------
445
446
XrdOucErrInfo
(
const
char
*user,
int
MonID,
int
uc=0)
447
:
ErrInfo
(user, uc),
ErrCB
(0),
ErrCBarg
(0),
mID
(MonID),
448
dOff
(-1),
reserved
(0),
dataBuff
(0) {}
449
450
//-----------------------------------------------------------------------------
452
//-----------------------------------------------------------------------------
453
454
virtual
~XrdOucErrInfo
() {
Reset
();}
455
456
protected
:
457
458
XrdOucEI
ErrInfo
;
459
XrdOucEICB
*
ErrCB
;
460
union
{
461
unsigned
long
long
ErrCBarg
;
462
XrdOucEnv
*
ErrEnv
;
463
};
464
int
mID
;
465
short
dOff
;
466
short
reserved
;
467
XrdOucBuffer *
dataBuff
;
468
};
469
470
/******************************************************************************/
471
/* X r d O u c E I C B */
472
/******************************************************************************/
473
474
//-----------------------------------------------------------------------------
479
//-----------------------------------------------------------------------------
480
481
class
XrdOucEICB
482
{
483
public
:
484
485
//-----------------------------------------------------------------------------
499
//-----------------------------------------------------------------------------
500
501
virtual
void
Done
(
int
&Result,
//I/O: Function result
502
XrdOucErrInfo
*eInfo,
// In: Error Info
503
const
char
*Path=0)=0;
// In: Relevant path
504
505
//-----------------------------------------------------------------------------
513
//-----------------------------------------------------------------------------
514
515
virtual
int
Same
(
unsigned
long
long
arg1,
unsigned
long
long
arg2)=0;
516
517
//-----------------------------------------------------------------------------
519
//-----------------------------------------------------------------------------
520
521
XrdOucEICB
() {}
522
virtual
~XrdOucEICB
() {}
523
};
524
#endif
Generated by
1.8.3.1