xrootd
Loading...
Searching...
No Matches
XrdOucPup.hh
Go to the documentation of this file.
1#ifndef __XRDOUCPUP_HH__
2#define __XRDOUCPUP_HH__
3/******************************************************************************/
4/* */
5/* X r d O u c P u p . h h */
6/* */
7/* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* All Rights Reserved */
9/* Produced by Andrew Hanushevsky for Stanford University under contract */
10/* DE-AC02-76-SFO0515 with the Department of Energy */
11/* */
12/* This file is part of the XRootD software suite. */
13/* */
14/* XRootD is free software: you can redistribute it and/or modify it under */
15/* the terms of the GNU Lesser General Public License as published by the */
16/* Free Software Foundation, either version 3 of the License, or (at your */
17/* option) any later version. */
18/* */
19/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22/* License for more details. */
23/* */
24/* You should have received a copy of the GNU Lesser General Public License */
25/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27/* */
28/* The copyright holder's institutional names and contributor's names may not */
29/* be used to endorse or promote products derived from this software without */
30/* specific prior written permission of the institution or contributor. */
31/******************************************************************************/
32
33#include <stddef.h>
34#include <sys/types.h>
35#include <sys/stat.h>
36
37class XrdSysError;
38struct iovec;
39
40/******************************************************************************/
41/* P a r a m e t e r s */
42/******************************************************************************/
43
45{// PT_Convert = 0x00, // Convert based on the below (same as char here)
46 PT_Ignore = 0x01, // Both: Skip the pup entry
47 PT_Mark = 0x02, // Pack: Mark &iov element in *Data
48 PT_Skip = 0x03, // Pack: Skip iov element
49 PT_MandS = 0x04, // Pack: Mark and Skip
50 PT_Fence = 0x05, // Unpk: Remaining entries are optional
51 PT_Datlen = 0x06, // Unpk: Set prv unpacked data length as an int
52 PT_Totlen = 0x07, // Pack: Set total packed data length as an int
53 PT_End = 0x0e, // Both: End of list (always the last element)
54 PT_EndFill = 0x0f, // Both: End of list (always the last element)
55 // Pack: *(Base+Doffs) = totlen as net short
56
57 PT_char = 0x00, // Both: Character
58 PT_short = 0x80, // Both: Unsigned
59 PT_int = 0xa0, // Both: Unsigned
60 PT_longlong= 0xc0, // Both: Unsigned
61 PT_special = 0xe0, // Both: Reserved
62
63 PT_Inline = 0x10, // Internal use
64 PT_MaskB = 0x60, // Internal Use
65 PT_MaskT = 0xe0, // Internal Use
66 PT_Mask = 0xf0, // Internal Use
67 PT_MaskD = 0x0f // Internal Use
68};
69
71{ int Doffs; // Offset(data source or target)
72 short Dlen; // If (Dlen < 0) Dlen = strlen(Data)+1;
73 unsigned char Name; // Name index of this element
74 unsigned char Dtype; // One of XrdOucPupType
75};
76
78{ const char **NList; // -> Array of name pointers
79 int NLnum; // Number of elements in NList
80
81 XrdOucPupNames(const char **nlist=0, int nlnum=0)
82 {NList = nlist; NLnum = nlnum;}
84};
85
86#define setPUP0(Type) {0, -1, 0, PT_ ## Type}
87
88#define setPUP1(Name,Type,Base,Var) \
89 {offsetof(Base,Var), -1, Name, PT_ ## Type}
90
91#define setPUP2(Name,Type,Base,Var,Dlen) \
92 {offsetof(Base,Var), Dlen, Name, PT_ ## Type}
93
94/******************************************************************************/
95/* X r d O u c P u p */
96/******************************************************************************/
97
99{
100public:
101
102static const int MaxLen = 0x7ff;
103
104// Pack #1: Packs a true null terminated character string. The result is placed
105// in iovec which must have at least two elements. Always returns the
106// length of the packed result with iovec updated to point to the
107// next free element.
108//
109static int Pack(struct iovec **, const char *, unsigned short &buff);
110
111// Pack #2: Packs a binary stream of length dlen. The result is placed
112// in iovec which must have at least two elements. Always returns the
113// length of the packed result with iovec updated to point to the
114// next free element.
115//
116static int Pack(struct iovec **, const char *, unsigned short &, int dlen);
117
118// Pack #3: Packs an int into buff and returns the length of the result. The
119// pointer to buff is updated to point to the next free byte. The
120// sizeof(buff) must be at least sizeof(int)+1.
121//
122static int Pack(char **buff, unsigned int data);
123
124// Pack #4: Packs a binary stream of length dlen when dlen >= 0; Otherwise,
125// it packs a string where dlen is strlen(data)+1. The results is
126// placed in buff which must be atleast dlen+2 long. It returns the
127// length of the packed result with buff updated to point to the
128// next free byte.
129//
130static int Pack(char **buff, const char *data, int dlen=-1);
131
132// Pack #5: Packs arbitrary data as directed by XrdOucPupArgs. Data comes from
133// an area pointed to by (Base+PupArgs.Doffs). The reults is placed in
134// iovec (1st arg). The 2nd iovec arg points to the last element+1 and
135// is used to check for an over-run. The Work buffer is used to hold
136// interleaved meta-data and should be sized 9*number of conversions.
137// Returns the actual number of elements used or zero upon an error.
138//
139 int Pack(struct iovec *, struct iovec *, XrdOucPupArgs *,
140 char *Base, char *Work);
141
142// Unpack #1: Unpacks a character or binary string in buff bounded by bend.
143// The pointer to the string is placed in data and it length in dlen.
144// Returns true upon success and false upon failure.
145//
146static int Unpack(char **buff, const char *bend, char **data, int &dlen);
147
148// Unpack #2: Unpacks an arbitrary stream in buff bounded by bend as directed
149// by pup. Arg Base is the address of the buffer where data is to be
150// placed as directed by (base+pup->Doffs). All variables in this
151// buffer (e.g., pointers, ints, etc) must be properly aligned.
152// Returns true upon success and false otherwise.
153//
154 int Unpack(const char *buff, const char *bend, XrdOucPupArgs *pup,
155 char *base);
156
158 {eDest = erp, Names = nms;}
160
161private:
162 int eMsg(const char *etxt, int ino, XrdOucPupArgs *pup);
163
166};
167#endif
XrdOucPupType
Definition XrdOucPup.hh:45
@ PT_Totlen
Definition XrdOucPup.hh:52
@ PT_MandS
Definition XrdOucPup.hh:49
@ PT_special
Definition XrdOucPup.hh:61
@ PT_short
Definition XrdOucPup.hh:58
@ PT_MaskD
Definition XrdOucPup.hh:67
@ PT_Datlen
Definition XrdOucPup.hh:51
@ PT_Fence
Definition XrdOucPup.hh:50
@ PT_int
Definition XrdOucPup.hh:59
@ PT_Mask
Definition XrdOucPup.hh:66
@ PT_EndFill
Definition XrdOucPup.hh:54
@ PT_MaskT
Definition XrdOucPup.hh:65
@ PT_Skip
Definition XrdOucPup.hh:48
@ PT_MaskB
Definition XrdOucPup.hh:64
@ PT_Inline
Definition XrdOucPup.hh:63
@ PT_char
Definition XrdOucPup.hh:57
@ PT_longlong
Definition XrdOucPup.hh:60
@ PT_Mark
Definition XrdOucPup.hh:47
@ PT_Ignore
Definition XrdOucPup.hh:46
@ PT_End
Definition XrdOucPup.hh:53
Definition XrdOucPup.hh:99
int Unpack(const char *buff, const char *bend, XrdOucPupArgs *pup, char *base)
XrdOucPupNames * Names
Definition XrdOucPup.hh:165
static int Pack(char **buff, unsigned int data)
static const int MaxLen
Definition XrdOucPup.hh:102
static int Unpack(char **buff, const char *bend, char **data, int &dlen)
static int Pack(char **buff, const char *data, int dlen=-1)
int Pack(struct iovec *, struct iovec *, XrdOucPupArgs *, char *Base, char *Work)
static int Pack(struct iovec **, const char *, unsigned short &, int dlen)
int eMsg(const char *etxt, int ino, XrdOucPupArgs *pup)
static int Pack(struct iovec **, const char *, unsigned short &buff)
XrdOucPup(XrdSysError *erp=0, XrdOucPupNames *nms=0)
Definition XrdOucPup.hh:157
~XrdOucPup()
Definition XrdOucPup.hh:159
XrdSysError * eDest
Definition XrdOucPup.hh:164
Definition XrdSysError.hh:90
Definition XrdOucPup.hh:71
short Dlen
Definition XrdOucPup.hh:72
unsigned char Name
Definition XrdOucPup.hh:73
int Doffs
Definition XrdOucPup.hh:71
unsigned char Dtype
Definition XrdOucPup.hh:74
Definition XrdOucPup.hh:78
int NLnum
Definition XrdOucPup.hh:79
XrdOucPupNames(const char **nlist=0, int nlnum=0)
Definition XrdOucPup.hh:81
~XrdOucPupNames()
Definition XrdOucPup.hh:83
const char ** NList
Definition XrdOucPup.hh:78