XRootD
XrdCpConfig.hh
Go to the documentation of this file.
1 #ifndef __XRDCPCONFIG_HH__
2 #define __XRDCPCONFIG_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d C p C o n f i g . h h */
6 /* */
7 /* (c) 2012 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 "XrdCks/XrdCksData.hh"
34 
35 #include <cctype>
36 #include <cstdint>
37 
38 #include <string>
39 #include <vector>
40 
41 struct option;
42 class XrdCks;
43 class XrdCksCalc;
44 class XrdCpFile;
45 class XrdSysError;
46 
47 class XrdCpConfig
48 {
49 public:
50 
51 struct defVar
52  { defVar *Next; // -> Next such definition, 0 if no more
53  const char *vName; // -> Variable name
54  union {const char *strVal; // -> String value if in strDefs
55  int intVal; // Integer value if in intDefs
56  };
57  defVar(const char *vn, const char *vl)
58  : Next(0), vName(vn), strVal(vl) {}
59  defVar(const char *vn, int vl)
60  : Next(0), vName(vn), intVal(vl) {}
61  };
62 
63  defVar *intDefs; // -> -DI settings
64  defVar *strDefs; // -> -DS settings
65  const char *dstOpq; // -> -OD setting (dest opaque)
66  const char *srcOpq; // -> -OS setting (src opaque)
67  const char *Pgm; // -> Program name
68  long long xRate; // -> xrate value in bytes/sec (0 if not set)
69  long long xRateThreshold; // -> xrate threshold value in bytes/sec (0 if not set)
70  int Parallel; // Number of simultaneous copy ops (1 to 4)
71  char *pHost; // -> SOCKS4 proxy hname (0 if none)
72  int pPort; // SOCKS4 proxy port
73  long long OpSpec; // Bit mask of set options (see Doxxxx)
74  int Dlvl; // Debug level (0 to 3)
75  int nSrcs; // Number of sources wanted (dflt 1)
76  int nStrm; // Number of streams wanted (dflt 1)
77  int Retry; // Max times to retry failed copy job
78  std::string RetryPolicy; // retry policy (to force or to continue)
79  int Verbose; // True if --verbose specified
80  int CksLen; // Binary length of checksum, if any
81 
82  int numFiles; // Number of source files
83  long long totBytes; // Total number of bytes for local files
84 
85 XrdCksData CksData; // Checksum information
86 XrdCks *CksMan; // -> Checksum manager
87 XrdCksCalc *CksObj; // -> Cks computation object (0 if no cks)
88 const char *CksVal; // -> Cks argument (0 if none)
89 
90 XrdCpFile *srcFile; // List of source files
91 XrdCpFile *dstFile; // The destination for the copy
92 
93 char *zipFile; // The file name if the URL points to a ZIP archive
94 
95 char *tcpTokenFile; // The file name with TPC src and dst tokens
96 
97 static XrdSysError *Log; // -> Error message object
98 
99 std::vector<std::string> AddCksVal; // -> Additional checksum argument
100 
101 std::vector<std::string> HttpHeaders; // -> -H | --header settings, as given.
102  // These are passed through verbatim;
103  // XrdClHttp does all the parsing and
104  // validation of their contents.
105 
106 static const uint64_t OpCksum = 'C'; // -adler -MD5 legacy -> DoCksrc
107 static const uint64_t DoCksrc = 0x0000000000000001LL; // --cksum <type>:source
108 static const uint64_t DoCksum = 0x0000000000000002LL; // --cksum <type>
109 static const uint64_t DoCkprt = 0x0000000000000004LL; // --cksum <type>:print
110 
111 static const uint64_t OpCoerce = 'F';
112 static const uint64_t DoCoerce = 0x0000000000000008LL; // -F | --coerce
113 
114 static const uint64_t OpDebug = 'd';
115 static const uint64_t DoDebug = 0x0000000000000010LL; // -d | --debug <val>
116 
117 static const uint64_t OpForce = 'f';
118 static const uint64_t DoForce = 0x0000000000000020LL; // -f | --force
119 
120 static const uint64_t OpHelp = 'h';
121 static const uint64_t DoHelp = 0x0000000000000040LL; // -h | --help
122 
123 static const uint64_t OpIfile = 'I';
124 static const uint64_t DoIfile = 0x0000000000000080LL; // -I | --infiles
125 
126 static const uint64_t OpLicense = 0x14; // --license
127 
128 static const uint64_t OpNoPbar = 'N'; // -N | --nopbar | -np {legacy}
129 static const uint64_t DoNoPbar = 0x0000000000000100LL;
130 
131 static const uint64_t OpPosc = 'P';
132 static const uint64_t DoPosc = 0x0000000000000200LL; // -P | --posc
133 
134 static const uint64_t OpProxy = 'D';
135 static const uint64_t DoProxy = 0x0000000000000400LL; // -D | --proxy
136 
137 static const uint64_t OpRecurse = 'r';
138 static const uint64_t OpRecursv = 'R'; // -r | --recursive | -R {legacy}
139 static const uint64_t DoRecurse = 0x0000000000000800LL;
140 
141 static const uint64_t OpRetry = 't';
142 static const uint64_t DoRetry = 0x0000000000001000LL; // -t | --retry
143 
144 static const uint64_t OpServer = 0x03;
145 static const uint64_t DoServer = 0x0000000000002000LL; // --server
146 
147 static const uint64_t OpSilent = 's';
148 static const uint64_t DoSilent = 0x0000000000004000LL; // -s | --silent
149 
150 static const uint64_t OpSources = 'y';
151 static const uint64_t DoSources = 0x0000000000008000LL; // -y | --sources
152 
153 static const uint64_t OpStreams = 'S';
154 static const uint64_t DoStreams = 0x0000000000010000LL; // -S | --streams
155 
156 static const uint64_t OpTpc = 'T'; // -T | --tpc [delegate] [push] {first | only}
157 static const uint64_t DoTpc = 0x0000000000020000LL; // --tpc {first | only}
158 static const uint64_t DoTpcOnly = 0x0000000000100000LL; // --tpc only
159 static const uint64_t DoTpcDlgt = 0x0000000000800000LL; // --tpc delegate ...
160 
161 static const uint64_t OpVerbose = 'v';
162 static const uint64_t DoVerbose = 0x0000000000040000LL; // -v | --verbose
163 
164 static const uint64_t OpVersion = 'V'; // -V | --version
165 
166 static const uint64_t OpXrate = 'X';
167 static const uint64_t DoXrate = 0x0000000000080000LL; // -X | --xrate
168 
169 static const uint64_t OpParallel = 0x04;
170 static const uint64_t DoParallel = 0x0000000000200000LL; // --parallel
171 
172 static const uint64_t OpDynaSrc = 'Z';
173 static const uint64_t DoDynaSrc = 0x0000000000400000LL; // --dynamic-src
174 
175 // const uint64_t DoTpcDlgt = 0x0000000000800000LL; // Marker for bit used
176 
177 static const uint64_t OpZip = 'z';
178 static const uint64_t DoZip = 0x0000000001000000LL; // -z | --zip
179 
180 static const uint64_t OpTlsNoData = 'E';
181 static const uint64_t DoTlsNoData = 0x0000000002000000LL; // -E | --tlsnodata
182 
183 static const uint64_t OpNoTlsOK = 0x05;
184 static const uint64_t DoNoTlsOK = 0x0000000004000000LL; // --notlsok
185 
186 static const uint64_t OpTlsMLF = 0x06;
187 static const uint64_t DoTlsMLF = 0x0000000008000000LL; // --tlsmetalink
188 
189 static const uint64_t OpPath = 'p';
190 static const uint64_t DoPath = 0x0000000010000000LL; // -p | --path
191 
192 static const uint64_t OpXAttr = 0x07;
193 static const uint64_t DoXAttr = 0x0000000020000000LL; // --xattr
194 
195 static const uint64_t OpZipMtlnCksum = 0x08;
196 static const uint64_t DoZipMtlnCksum = 0x0000000040000000LL; // --zip-mtln-cksum
197 
198 static const uint64_t OpRmOnBadCksum = 0x09;
199 static const uint64_t DoRmOnBadCksum = 0x0000000080000000LL; // --rm-bad-cksum
200 
201 static const uint64_t OpContinue = 0x10;
202 static const uint64_t DoContinue = 0x0000000100000000LL; // --continue
203 
204 static const uint64_t OpXrateThreshold = 0x11;
205 static const uint64_t DoXrateThreshold = 0x0000000200000000LL; // --xrate-threshold
206 
207 static const uint64_t OpRetryPolicy = 0x12;
208 static const uint64_t DoRetryPolicy = 0x0000000400000000LL; // --retry-policy
209 
210 static const uint64_t OpZipAppend = 0x13;
211 static const uint64_t DoZipAppend = 0x0000000800000000LL; // --zip-append
212 
213 static const uint64_t OpHttpHeader = 'H';
214 static const uint64_t DoHttpHeader = 0x0000001000000000LL; // -H | --header
215 static const uint64_t OpTpcTokenFile = 0x15;
216 static const uint64_t DoTpcTokenFile = 0x0000002000000000LL; // --tpc-token-file
217 
218 static const uint64_t DoTpcModePush = 0x0000004000000000LL; // --tpc ... push ...
219 
220 // Call Config with the parameters passed to main() to fill out this object. If
221 // the method returns then no errors have been found. Otherwise, it exits.
222 // The following options may be passed (largely to support legacy stuff):
223 //
224 static const int opt1Src = 0x00000001; // Only one source is allowed
225 static const int optNoXtnd = 0x00000002; // Do not index source directories
226 static const int optRmtRec = 0x00000004; // Allow remote recursive copy
227 static const int optNoStdIn = 0x00000008; // Disallow '-' as src for stdin
228 static const int optNoLclCp = 0x00000010; // Disallow local/local copy
229 
230  void Config(int argc, char **argv, int Opts=0);
231 
232 // Method to check for setting
233 //
234 inline int Want(uint64_t What) {return (OpSpec & What) != 0;}
235 
236  XrdCpConfig(const char *pgname);
237  ~XrdCpConfig();
238 
239 private:
240  int a2i(const char *item, int *val, int minv, int maxv=-1);
241  int a2l(const char *item, long long *val,
242  long long minv, long long maxv=-1);
243  int a2t(const char *item, int *val, int minv, int maxv=-1);
244  int a2x(const char *Val, char *Buff, int Vlen);
245  int a2z(const char *item, long long *val,
246  long long minv, long long maxv=-1);
247  int defCks(const char *opval);
248  int defOpq(const char *theOp);
249  int defOpt(const char *theOp, const char *theArg);
250  void defPxy(const char *opval);
251  const char *Human(long long Val, char *Buff, int Blen);
252  int Legacy(int oIndex);
253  int Legacy(const char *theOp, const char *theArg);
254  void License();
255  const char *OpName();
256  void ProcFile(const char *fname);
257  void Usage(int rc=0);
258 
259  static void toLower( char cstr[] )
260  {
261  for( int i = 0; cstr[i]; ++i )
262  cstr[i] = tolower( cstr[i] );
263  }
264 
265 
266  const char *PName;
267  int Opts;
268  int Argc;
269  char **Argv;
270  defVar *intDend;
271  defVar *strDend;
272 
273 static const char *opLetters;
274 static struct option opVec[];
275 
276 static const int dfltSrcs = 12;
277 
278  XrdCpFile *pFile;
279  XrdCpFile *pLast;
280  XrdCpFile *pPrev;
281  char *inFile;
282  char **parmVal;
283  int parmCnt;
284  int isLcl;
285 };
286 #endif
Definition: XrdCks.hh:92
const char * vName
Definition: XrdCpConfig.hh:53
defVar(const char *vn, const char *vl)
Definition: XrdCpConfig.hh:57
defVar(const char *vn, int vl)
Definition: XrdCpConfig.hh:59
static const uint64_t OpVerbose
Definition: XrdCpConfig.hh:161
static const uint64_t DoHelp
Definition: XrdCpConfig.hh:121
static const uint64_t OpXAttr
Definition: XrdCpConfig.hh:192
static const uint64_t DoProxy
Definition: XrdCpConfig.hh:135
defVar * intDefs
Definition: XrdCpConfig.hh:63
void Config(int argc, char **argv, int Opts=0)
Definition: XrdCpConfig.cc:210
static const uint64_t OpRecurse
Definition: XrdCpConfig.hh:137
char * tcpTokenFile
Definition: XrdCpConfig.hh:95
XrdCksCalc * CksObj
Definition: XrdCpConfig.hh:87
static const uint64_t OpContinue
Definition: XrdCpConfig.hh:201
static const uint64_t DoRetry
Definition: XrdCpConfig.hh:142
static const uint64_t DoStreams
Definition: XrdCpConfig.hh:154
std::vector< std::string > AddCksVal
Definition: XrdCpConfig.hh:99
static const uint64_t OpParallel
Definition: XrdCpConfig.hh:169
static const uint64_t OpZipAppend
Definition: XrdCpConfig.hh:210
const char * dstOpq
Definition: XrdCpConfig.hh:65
static const uint64_t DoZipMtlnCksum
Definition: XrdCpConfig.hh:196
XrdCksData CksData
Definition: XrdCpConfig.hh:85
static const uint64_t OpSilent
Definition: XrdCpConfig.hh:147
static const uint64_t OpTlsMLF
Definition: XrdCpConfig.hh:186
static const uint64_t OpNoTlsOK
Definition: XrdCpConfig.hh:183
XrdCks * CksMan
Definition: XrdCpConfig.hh:86
XrdCpFile * srcFile
Definition: XrdCpConfig.hh:90
const char * Pgm
Definition: XrdCpConfig.hh:67
XrdCpFile * dstFile
Definition: XrdCpConfig.hh:91
static const uint64_t OpRetryPolicy
Definition: XrdCpConfig.hh:207
static const uint64_t OpDebug
Definition: XrdCpConfig.hh:114
char * zipFile
Definition: XrdCpConfig.hh:93
XrdCpConfig(const char *pgname)
Definition: XrdCpConfig.cc:140
static const uint64_t OpRetry
Definition: XrdCpConfig.hh:141
static const uint64_t DoNoPbar
Definition: XrdCpConfig.hh:129
static const uint64_t OpXrateThreshold
Definition: XrdCpConfig.hh:204
static const uint64_t DoCoerce
Definition: XrdCpConfig.hh:112
static const uint64_t OpServer
Definition: XrdCpConfig.hh:144
static const uint64_t DoForce
Definition: XrdCpConfig.hh:118
static const uint64_t OpVersion
Definition: XrdCpConfig.hh:164
static const uint64_t OpTpc
Definition: XrdCpConfig.hh:156
static const uint64_t DoParallel
Definition: XrdCpConfig.hh:170
static const uint64_t DoRmOnBadCksum
Definition: XrdCpConfig.hh:199
static const uint64_t DoNoTlsOK
Definition: XrdCpConfig.hh:184
static const uint64_t OpPath
Definition: XrdCpConfig.hh:189
long long OpSpec
Definition: XrdCpConfig.hh:73
static const uint64_t OpRecursv
Definition: XrdCpConfig.hh:138
static const uint64_t OpProxy
Definition: XrdCpConfig.hh:134
static const uint64_t DoTpc
Definition: XrdCpConfig.hh:157
static const uint64_t DoDebug
Definition: XrdCpConfig.hh:115
char * pHost
Definition: XrdCpConfig.hh:71
static const uint64_t OpSources
Definition: XrdCpConfig.hh:150
std::vector< std::string > HttpHeaders
Definition: XrdCpConfig.hh:101
static const uint64_t DoCksum
Definition: XrdCpConfig.hh:108
defVar * strDefs
Definition: XrdCpConfig.hh:64
static const uint64_t OpPosc
Definition: XrdCpConfig.hh:131
static const uint64_t DoXrate
Definition: XrdCpConfig.hh:167
static const uint64_t DoCksrc
Definition: XrdCpConfig.hh:107
static const uint64_t DoTpcModePush
Definition: XrdCpConfig.hh:218
static const uint64_t OpZipMtlnCksum
Definition: XrdCpConfig.hh:195
static const uint64_t DoHttpHeader
Definition: XrdCpConfig.hh:214
static const int opt1Src
Definition: XrdCpConfig.hh:224
static const uint64_t OpXrate
Definition: XrdCpConfig.hh:166
static const uint64_t DoTpcDlgt
Definition: XrdCpConfig.hh:159
static const uint64_t DoZip
Definition: XrdCpConfig.hh:178
static const uint64_t DoVerbose
Definition: XrdCpConfig.hh:162
static const uint64_t DoContinue
Definition: XrdCpConfig.hh:202
static const uint64_t OpCksum
Definition: XrdCpConfig.hh:106
const char * CksVal
Definition: XrdCpConfig.hh:88
static const uint64_t DoRecurse
Definition: XrdCpConfig.hh:139
static const uint64_t OpTlsNoData
Definition: XrdCpConfig.hh:180
static const int optNoLclCp
Definition: XrdCpConfig.hh:228
static const uint64_t DoXrateThreshold
Definition: XrdCpConfig.hh:205
const char * srcOpq
Definition: XrdCpConfig.hh:66
static const uint64_t DoTpcTokenFile
Definition: XrdCpConfig.hh:216
static const uint64_t DoZipAppend
Definition: XrdCpConfig.hh:211
static const uint64_t OpIfile
Definition: XrdCpConfig.hh:123
static const uint64_t DoDynaSrc
Definition: XrdCpConfig.hh:173
static const uint64_t OpHttpHeader
Definition: XrdCpConfig.hh:213
int Want(uint64_t What)
Definition: XrdCpConfig.hh:234
long long xRate
Definition: XrdCpConfig.hh:68
static const int optNoStdIn
Definition: XrdCpConfig.hh:227
static const uint64_t OpNoPbar
Definition: XrdCpConfig.hh:128
static const uint64_t DoSources
Definition: XrdCpConfig.hh:151
static const uint64_t DoSilent
Definition: XrdCpConfig.hh:148
static const uint64_t OpForce
Definition: XrdCpConfig.hh:117
static const uint64_t OpRmOnBadCksum
Definition: XrdCpConfig.hh:198
static const uint64_t OpDynaSrc
Definition: XrdCpConfig.hh:172
static const uint64_t DoXAttr
Definition: XrdCpConfig.hh:193
static const int optNoXtnd
Definition: XrdCpConfig.hh:225
static const uint64_t DoTlsMLF
Definition: XrdCpConfig.hh:187
static const uint64_t OpZip
Definition: XrdCpConfig.hh:177
static const uint64_t OpLicense
Definition: XrdCpConfig.hh:126
static const uint64_t DoIfile
Definition: XrdCpConfig.hh:124
static const uint64_t OpHelp
Definition: XrdCpConfig.hh:120
static XrdSysError * Log
Definition: XrdCpConfig.hh:97
static const int optRmtRec
Definition: XrdCpConfig.hh:226
static const uint64_t DoRetryPolicy
Definition: XrdCpConfig.hh:208
std::string RetryPolicy
Definition: XrdCpConfig.hh:78
static const uint64_t DoPath
Definition: XrdCpConfig.hh:190
static const uint64_t DoPosc
Definition: XrdCpConfig.hh:132
static const uint64_t OpStreams
Definition: XrdCpConfig.hh:153
long long xRateThreshold
Definition: XrdCpConfig.hh:69
static const uint64_t OpCoerce
Definition: XrdCpConfig.hh:111
long long totBytes
Definition: XrdCpConfig.hh:83
static const uint64_t DoTpcOnly
Definition: XrdCpConfig.hh:158
static const uint64_t DoTlsNoData
Definition: XrdCpConfig.hh:181
static const uint64_t OpTpcTokenFile
Definition: XrdCpConfig.hh:215
static const uint64_t DoServer
Definition: XrdCpConfig.hh:145
static const uint64_t DoCkprt
Definition: XrdCpConfig.hh:109