xrootd
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 
13 // $Id$
14 
15 #include <stddef.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 
19 class XrdSysError;
20 struct iovec;
21 
22 /******************************************************************************/
23 /* P a r a m e t e r s */
24 /******************************************************************************/
25 
27 {// PT_Convert = 0x00, // Convert based on the below (same as char here)
28  PT_Ignore = 0x01, // Both: Skip the pup entry
29  PT_Mark = 0x02, // Pack: Mark &iov element in *Data
30  PT_Skip = 0x03, // Pack: Skip iov element
31  PT_MandS = 0x04, // Pack: Mark and Skip
32  PT_Fence = 0x05, // Unpk: Remaining entries are optional
33  PT_Datlen = 0x06, // Unpk: Set prv unpacked data length as an int
34  PT_Totlen = 0x07, // Pack: Set total packed data length as an int
35  PT_End = 0x0e, // Both: End of list (always the last element)
36  PT_EndFill = 0x0f, // Both: End of list (always the last element)
37  // Pack: *(Base+Doffs) = totlen as net short
38 
39  PT_char = 0x00, // Both: Character
40  PT_short = 0x80, // Both: Unsigned
41  PT_int = 0xa0, // Both: Unsigned
42  PT_longlong= 0xc0, // Both: Unsigned
43  PT_special = 0xe0, // Both: Reserved
44 
45  PT_Inline = 0x10, // Internal use
46  PT_MaskB = 0x60, // Internal Use
47  PT_MaskT = 0xe0, // Internal Use
48  PT_Mask = 0xf0, // Internal Use
49  PT_MaskD = 0x0f // Internal Use
50 };
51 
53 { int Doffs; // Offset(data source or target)
54  short Dlen; // If (Dlen < 0) Dlen = strlen(Data)+1;
55  unsigned char Name; // Name index of this element
56  unsigned char Dtype; // One of XrdOucPupType
57 };
58 
60 { const char **NList; // -> Array of name pointers
61  int NLnum; // Number of elements in NList
62 
63  XrdOucPupNames(const char **nlist=0, int nlnum=0)
64  {NList = nlist; NLnum = nlnum;}
66 };
67 
68 #define setPUP0(Type) {0, -1, 0, PT_ ## Type}
69 
70 #define setPUP1(Name,Type,Base,Var) \
71  {offsetof(Base,Var), -1, Name, PT_ ## Type}
72 
73 #define setPUP2(Name,Type,Base,Var,Dlen) \
74  {offsetof(Base,Var), Dlen, Name, PT_ ## Type}
75 
76 /******************************************************************************/
77 /* X r d O u c P u p */
78 /******************************************************************************/
79 
80 class XrdOucPup
81 {
82 public:
83 
84 static const int MaxLen = 0x7ff;
85 
86 // Pack #1: Packs a true null terminated character string. The result is placed
87 // in iovec which must have at least two elements. Always returns the
88 // length of the packed result with iovec updated to point to the
89 // next free element.
90 //
91 static int Pack(struct iovec **, const char *, unsigned short &buff);
92 
93 // Pack #2: Packs a binary stream of length dlen. The result is placed
94 // in iovec which must have at least two elements. Always returns the
95 // length of the packed result with iovec updated to point to the
96 // next free element.
97 //
98 static int Pack(struct iovec **, const char *, unsigned short &, int dlen);
99 
100 // Pack #3: Packs an int into buff and returns the length of the result. The
101 // pointer to buff is updated to point to the next free byte. The
102 // sizeof(buff) must be at least sizeof(int)+1.
103 //
104 static int Pack(char **buff, unsigned int data);
105 
106 // Pack #4: Packs a binary stream of length dlen when dlen >= 0; Otherwise,
107 // it packs a string where dlen is strlen(data)+1. The results is
108 // placed in buff which must be atleast dlen+2 long. It returns the
109 // length of the packed result with buff updated to point to the
110 // next free byte.
111 //
112 static int Pack(char **buff, const char *data, int dlen=-1);
113 
114 // Pack #5: Packs arbitrary data as directed by XrdOucPupArgs. Data comes from
115 // an area pointed to by (Base+PupArgs.Doffs). The reults is placed in
116 // iovec (1st arg). The 2nd iovec arg points to the last element+1 and
117 // is used to check for an over-run. The Work buffer is used to hold
118 // interleaved meta-data and should be sized 9*number of conversions.
119 // Returns the actual number of elements used or zero upon an error.
120 //
121  int Pack(struct iovec *, struct iovec *, XrdOucPupArgs *,
122  char *Base, char *Work);
123 
124 // Unpack #1: Unpacks a character or binary string in buff bounded by bend.
125 // The pointer to the string is placed in data and it length in dlen.
126 // Returns true upon success and false upon failure.
127 //
128 static int Unpack(char **buff, const char *bend, char **data, int &dlen);
129 
130 // Unpack #2: Unpacks an arbitrary stream in buff bounded by bend as directed
131 // by pup. Arg Base is the address of the buffer where data is to be
132 // placed as directed by (base+pup->Doffs). All variables in this
133 // buffer (e.g., pointers, ints, etc) must be properly aligned.
134 // Returns true upon success and false otherwise.
135 //
136  int Unpack(const char *buff, const char *bend, XrdOucPupArgs *pup,
137  char *base);
138 
140  {eDest = erp, Names = nms;}
142 
143 private:
144  int eMsg(const char *etxt, int ino, XrdOucPupArgs *pup);
145 
148 };
149 #endif