XProtocol.hh

Go to the documentation of this file.
00001 #ifndef __XPROTOCOL_H
00002 #define __XPROTOCOL_H
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                          X P r o t o c o l . h h                           */
00006 /*                                                                            */
00007 /* (c) 2012 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00033 //#ifndef __GNUC__
00034 //#define __attribute__(x)
00035 //#ifdef SUNCC
00036 //#pragma pack(4)
00037 //#endif
00038 //#endif
00039 
00040 #ifdef __CINT__
00041 #define __attribute__(x)
00042 #endif
00043 
00044 // The following is the binary representation of the protocol version here.
00045 // Protocol version is repesented as three base10 digits x.y.z with x having no
00046 // upper limit (i.e. n.9.9 + 1 -> n+1.0.0). The kXR_PROTSIGNVERSION defines the
00047 // protocol version where request signing became available.
00048 //
00049 #define kXR_PROTOCOLVERSION  0x00000310
00050 #define kXR_PROTSIGNVERSION  0x00000310
00051 #define kXR_PROTOCOLVSTRING "3.1.0"
00052 
00053 #include "XProtocol/XPtypes.hh"
00054 
00055 // KINDS of SERVERS
00056 //
00057 //
00058 #define kXR_DataServer 1
00059 #define kXR_LBalServer 0
00060 
00061 // The below are defined for protocol version 2.9.7 or higher
00062 // These are the flag value in the kXR_protool response
00063 //
00064 #define kXR_isManager 0x00000002
00065 #define kXR_isServer  0x00000001
00066 #define kXR_attrMeta  0x00000100
00067 #define kXR_attrProxy 0x00000200
00068 #define kXR_attrSuper 0x00000400
00069 
00070 #define kXR_maxReqRetry 10
00071 
00072 // Kind of error inside a XTNetFile's routine (temporary)
00073 //
00074 enum XReqErrorType {
00075    kGENERICERR = 0,    // Generic error
00076    kREAD,              // Error while reading from stream
00077    kWRITE,             // Error while writing to stream
00078    kREDIRCONNECT,      // Error redirecting to a given host
00079    kOK,                // Everything seems ok
00080    kNOMORESTREAMS      // No more available stream IDs for
00081                        // async processing
00082 };
00083 
00084 //______________________________________________
00085 // PROTOCOL DEFINITION: CLIENT'S REQUESTS TYPES
00086 //______________________________________________
00087 // 
00088 enum XRequestTypes {
00089    kXR_auth    =  3000,
00090    kXR_query,   // 3001
00091    kXR_chmod,   // 3002
00092    kXR_close,   // 3003
00093    kXR_dirlist, // 3004
00094    kXR_getfile, // 3005
00095    kXR_protocol,// 3006
00096    kXR_login,   // 3007
00097    kXR_mkdir,   // 3008
00098    kXR_mv,      // 3009
00099    kXR_open,    // 3010
00100    kXR_ping,    // 3011
00101    kXR_putfile, // 3012
00102    kXR_read,    // 3013
00103    kXR_rm,      // 3014
00104    kXR_rmdir,   // 3015
00105    kXR_sync,    // 3016
00106    kXR_stat,    // 3017
00107    kXR_set,     // 3018
00108    kXR_write,   // 3019
00109    kXR_admin,   // 3020
00110    kXR_prepare, // 3021
00111    kXR_statx,   // 3022
00112    kXR_endsess, // 3023
00113    kXR_bind,    // 3024
00114    kXR_readv,   // 3025
00115    kXR_verifyw, // 3026
00116    kXR_locate,  // 3027
00117    kXR_truncate,// 3028
00118    kXR_sigver,  // 3029
00119    kXR_decrypt, // 3030
00120    kXR_REQFENCE // Always last valid request code +1
00121 };
00122 
00123 // OPEN MODE FOR A REMOTE FILE
00124 enum XOpenRequestMode {
00125    kXR_ur = 0x100,
00126    kXR_uw = 0x080,
00127    kXR_ux = 0x040,
00128    kXR_gr = 0x020,
00129    kXR_gw = 0x010,
00130    kXR_gx = 0x008,
00131    kXR_or = 0x004,
00132    kXR_ow = 0x002,
00133    kXR_ox = 0x001
00134 };
00135 
00136 enum XMkdirOptions {
00137    kXR_mknone  = 0,
00138    kXR_mkdirpath  = 1
00139 };
00140 
00141 // this is a bitmask
00142 enum XLoginAbility {
00143    kXR_nothing =   0,
00144    kXR_fullurl =   1,
00145    kXR_multipr =   3,
00146    kXR_readrdok=   4,
00147    kXR_hasipv64=   8,
00148    kXR_onlyprv4=  16,
00149    kXR_onlyprv6=  32
00150 };
00151 
00152 // this is a bitmask
00153 enum XLoginCapVer {
00154    kXR_lcvnone = 0,
00155    kXR_vermask = 63,
00156    kXR_asyncap = 128
00157 };
00158 
00159 // this is a single number that goes into capver as the version
00160 //
00161 enum XLoginVersion {
00162    kXR_ver000 = 0,  // Old clients predating history
00163    kXR_ver001 = 1,  // Generally implemented 2005 protocol
00164    kXR_ver002 = 2,  // Same as 1 but adds asyncresp recognition
00165    kXR_ver003 = 3,  // The 2011-2012 rewritten client
00166    kXR_ver004 = 4   // The 2016 sign-capable   client
00167 };
00168 
00169 enum XStatRequestOption {
00170    kXR_vfs    = 1
00171 };
00172 
00173 enum XStatRespFlags {
00174    kXR_file    = 0,
00175    kXR_xset    = 1,
00176    kXR_isDir   = 2,
00177    kXR_other   = 4,
00178    kXR_offline = 8,
00179    kXR_readable=16,
00180    kXR_writable=32,
00181    kXR_poscpend=64,
00182    kXR_bkpexist=128
00183 };
00184 
00185 enum XDirlistRequestOption {
00186    kXR_online = 1,
00187    kXR_dstat  = 2
00188 };
00189 
00190 enum XOpenRequestOption {
00191    kXR_compress = 1,      // also locate (return unique hosts)
00192    kXR_delete   = 2,
00193    kXR_force    = 4,
00194    kXR_new      = 8,
00195    kXR_open_read= 16,
00196    kXR_open_updt= 32,
00197    kXR_async    = 64,
00198    kXR_refresh  = 128,   // also locate
00199    kXR_mkpath   = 256,
00200    kXR_prefname = 256,   // only locate
00201    kXR_open_apnd= 512,
00202    kXR_retstat  = 1024,
00203    kXR_replica  = 2048,
00204    kXR_posc     = 4096,
00205    kXR_nowait   = 8192,  // also locate
00206    kXR_seqio    =16384,
00207    kXR_open_wrto=32768
00208 };
00209 
00210 enum XProtocolRequestFlags {
00211    kXR_secreqs  = 1      // Return security requirements
00212 };
00213 
00214 enum XQueryType {
00215    kXR_QStats = 1,
00216    kXR_QPrep  = 2,
00217    kXR_Qcksum = 3,
00218    kXR_Qxattr = 4,
00219    kXR_Qspace = 5,
00220    kXR_Qckscan= 6,
00221    kXR_Qconfig= 7,
00222    kXR_Qvisa  = 8,
00223    kXR_Qopaque=16,
00224    kXR_Qopaquf=32,
00225    kXR_Qopaqug=64
00226 };
00227 
00228 enum XVerifyType {
00229    kXR_nocrc  = 0,
00230    kXR_crc32  = 1
00231 };
00232 
00233 enum XLogonType {
00234    kXR_useruser  = 0,
00235    kXR_useradmin = 1
00236 };
00237 
00238 // Andy's request for async/unsolicited
00239 enum XPrepRequestOption {
00240    kXR_cancel = 1,
00241    kXR_notify = 2,
00242    kXR_noerrs = 4,
00243    kXR_stage  = 8,
00244    kXR_wmode  = 16,
00245    kXR_coloc  = 32,
00246    kXR_fresh  = 64
00247 };
00248 
00249 // Version used for kXR_decrypt and kXR_sigver and is set in
00250 // Set in SigverRequest::version, DecryptRequest::version and
00251 // ServerResponseReqs_Protocol::secver
00252 #define kXR_secver_0  0
00253 
00254 // Flags for kXR_decrypt and kXR_sigver
00255 enum XSecFlags {
00256    kXR_nodata   = 1  // Request payload was not hashed or encrypted
00257 };
00258 
00259 // Cryptography used for kXR_sigver SigverRequest::crypto
00260 enum XSecCrypto {
00261    kXR_SHA256   = 0x01,   // Hash used
00262    kXR_HashMask = 0x0f,   // Mak to extract the hash type
00263    kXR_rsaKey   = 0x80    // The rsa key was used
00264 };
00265 
00266 //_______________________________________________
00267 // PROTOCOL DEFINITION: SERVER'S RESPONSES TYPES
00268 //_______________________________________________
00269 //
00270 enum XResponseType {
00271    kXR_ok      = 0,
00272    kXR_oksofar = 4000,
00273    kXR_attn,
00274    kXR_authmore,
00275    kXR_error,
00276    kXR_redirect,
00277    kXR_wait,
00278    kXR_waitresp,
00279    kXR_noResponsesYet = 10000
00280 };
00281 
00282 //_______________________________________________
00283 // PROTOCOL DEFINITION: SERVER"S ATTN CODES
00284 //_______________________________________________
00285 
00286 enum XActionCode {
00287    kXR_asyncab = 5000,
00288    kXR_asyncdi,
00289    kXR_asyncms,
00290    kXR_asyncrd,
00291    kXR_asyncwt,
00292    kXR_asyncav,
00293    kXR_asynunav,
00294    kXR_asyncgo,
00295    kXR_asynresp
00296 };
00297 
00298 //_______________________________________________
00299 // PROTOCOL DEFINITION: SERVER'S ERROR CODES
00300 //_______________________________________________
00301 //
00302 enum XErrorCode {
00303    kXR_ArgInvalid = 3000,
00304    kXR_ArgMissing,
00305    kXR_ArgTooLong,
00306    kXR_FileLocked,
00307    kXR_FileNotOpen,
00308    kXR_FSError,
00309    kXR_InvalidRequest,
00310    kXR_IOError,
00311    kXR_NoMemory,
00312    kXR_NoSpace,
00313    kXR_NotAuthorized,
00314    kXR_NotFound,
00315    kXR_ServerError,
00316    kXR_Unsupported,
00317    kXR_noserver,
00318    kXR_NotFile,
00319    kXR_isDirectory,
00320    kXR_Cancelled,
00321    kXR_ChkLenErr,
00322    kXR_ChkSumErr,
00323    kXR_inProgress,
00324    kXR_overQuota,
00325    kXR_SigVerErr,
00326    kXR_DecryptErr,
00327    kXR_ERRFENCE,    // Always last valid errcode + 1
00328    kXR_noErrorYet = 10000
00329 };
00330 
00331 
00332 //______________________________________________
00333 // PROTOCOL DEFINITION: CLIENT'S REQUESTS STRUCTS
00334 //______________________________________________
00335 // 
00336 // We need to pack structures sent all over the net!
00337 // __attribute__((packed)) assures no padding bytes.
00338 //
00339 // Nice bodies of the headers for the client requests.
00340 // Note that the protocol specifies these values to be in network
00341 //  byte order when sent
00342 //
00343 // G.Ganis: use of flat structures to avoid packing options
00344 
00345 struct ClientAdminRequest {
00346    kXR_char  streamid[2];
00347    kXR_unt16 requestid;
00348    kXR_char reserved[16];
00349    kXR_int32  dlen;
00350 };
00351 struct ClientAuthRequest {
00352    kXR_char  streamid[2];
00353    kXR_unt16 requestid;
00354    kXR_char reserved[12];
00355    kXR_char credtype[4];
00356    kXR_int32  dlen;
00357 };
00358 struct ClientBindRequest {
00359    kXR_char  streamid[2];
00360    kXR_unt16 requestid;
00361    kXR_char  sessid[16];
00362    kXR_int32  dlen;
00363 };
00364 struct ClientChmodRequest {
00365    kXR_char  streamid[2];
00366    kXR_unt16 requestid;
00367    kXR_char  reserved[14];
00368    kXR_unt16 mode;
00369    kXR_int32  dlen;
00370 };
00371 struct ClientCloseRequest {
00372    kXR_char  streamid[2];
00373    kXR_unt16 requestid;
00374    kXR_char fhandle[4];
00375    kXR_int64 fsize;
00376    kXR_char reserved[4];
00377    kXR_int32  dlen;
00378 };
00379 struct ClientDecryptRequest {
00380    kXR_char  streamid[2];
00381    kXR_unt16 requestid;
00382    kXR_unt16 expectrid; // Request code of subsequent request
00383    kXR_char  version;   // Security version being used (see enum XSecVersion)
00384    kXR_char  flags;     // One or more flags defined in enum XSecFlags
00385    kXR_char  reserved[12];
00386    kXR_int32 dlen;
00387 };
00388 struct ClientDirlistRequest {
00389    kXR_char  streamid[2];
00390    kXR_unt16 requestid;
00391    kXR_char reserved[15];
00392    kXR_char options[1];
00393    kXR_int32  dlen;
00394 };
00395 struct ClientEndsessRequest {
00396    kXR_char  streamid[2];
00397    kXR_unt16 requestid;
00398    kXR_char  sessid[16];
00399    kXR_int32  dlen;
00400 };
00401 struct ClientGetfileRequest {
00402    kXR_char  streamid[2];
00403    kXR_unt16 requestid;
00404    kXR_int32 options;
00405    kXR_char reserved[8];
00406    kXR_int32 buffsz;
00407    kXR_int32  dlen;
00408 };
00409 struct ClientLocateRequest {
00410    kXR_char  streamid[2];
00411    kXR_unt16 requestid;
00412    kXR_unt16 options;
00413    kXR_char reserved[14];
00414    kXR_int32  dlen;
00415 };
00416 struct ClientLoginRequest {
00417    kXR_char  streamid[2];
00418    kXR_unt16 requestid;
00419    kXR_int32 pid;
00420    kXR_char username[8];
00421    kXR_char reserved;
00422    kXR_char ability;       // See XLoginAbility enum flags
00423    kXR_char capver[1];     // See XLoginCapVer  enum flags
00424    kXR_char role[1];
00425    kXR_int32  dlen;
00426 };
00427 struct ClientMkdirRequest {
00428    kXR_char  streamid[2];
00429    kXR_unt16 requestid;
00430    kXR_char options[1];
00431    kXR_char reserved[13];
00432    kXR_unt16 mode;
00433    kXR_int32  dlen;
00434 };
00435 struct ClientMvRequest {
00436    kXR_char  streamid[2];
00437    kXR_unt16 requestid;
00438    kXR_char reserved[14];
00439    kXR_int16  arg1len;
00440    kXR_int32  dlen;
00441 };
00442 struct ClientOpenRequest {
00443    kXR_char  streamid[2];
00444    kXR_unt16 requestid;
00445    kXR_unt16 mode;
00446    kXR_unt16 options;
00447    kXR_char  reserved[12];
00448    kXR_int32  dlen;
00449 };
00450 
00451 struct ClientPingRequest {
00452    kXR_char  streamid[2];
00453    kXR_unt16 requestid;
00454    kXR_char reserved[16];
00455    kXR_int32  dlen;
00456 };
00457 struct ClientProtocolRequest {
00458    kXR_char  streamid[2];
00459    kXR_unt16 requestid;
00460    kXR_int32 clientpv;      // 2.9.7 or higher
00461    kXR_char  flags;         // 3.1.0 or higher
00462    kXR_char  reserved[11];
00463    kXR_int32 dlen;
00464 };
00465 struct ClientPrepareRequest {
00466    kXR_char  streamid[2];
00467    kXR_unt16 requestid;
00468    kXR_char  options;
00469    kXR_char  prty;
00470    kXR_unt16 port;          // 2.9.9 or higher
00471    kXR_char  reserved[12];
00472    kXR_int32 dlen;
00473 };
00474 struct ClientPutfileRequest {
00475    kXR_char  streamid[2];
00476    kXR_unt16 requestid;
00477    kXR_int32 options;
00478    kXR_char  reserved[8];
00479    kXR_int32 buffsz;
00480    kXR_int32  dlen;
00481 };
00482 struct ClientQueryRequest {
00483    kXR_char  streamid[2];
00484    kXR_unt16 requestid;
00485    kXR_unt16 infotype;
00486    kXR_char  reserved1[2];
00487    kXR_char  fhandle[4];
00488    kXR_char  reserved2[8];
00489    kXR_int32 dlen;
00490 };
00491 struct ClientReadRequest {
00492    kXR_char  streamid[2];
00493    kXR_unt16 requestid;
00494    kXR_char fhandle[4];
00495    kXR_int64 offset;
00496    kXR_int32 rlen;
00497    kXR_int32  dlen;
00498 };
00499 struct ClientReadVRequest {
00500    kXR_char  streamid[2];
00501    kXR_unt16 requestid;
00502    kXR_char  reserved[15];
00503    kXR_char  pathid;
00504    kXR_int32 dlen;
00505 };
00506 struct ClientRmRequest {
00507    kXR_char  streamid[2];
00508    kXR_unt16 requestid;
00509    kXR_char reserved[16];
00510    kXR_int32  dlen;
00511 };
00512 struct ClientRmdirRequest {
00513    kXR_char  streamid[2];
00514    kXR_unt16 requestid;
00515    kXR_char reserved[16];
00516    kXR_int32  dlen;
00517 };
00518 struct ClientSetRequest {
00519    kXR_char  streamid[2];
00520    kXR_unt16 requestid;
00521    kXR_char reserved[15];
00522    kXR_char  modifier;  // For security purposes, should be zero
00523    kXR_int32  dlen;
00524 };
00525 struct ClientSigverRequest {
00526    kXR_char  streamid[2];
00527    kXR_unt16 requestid;
00528    kXR_unt16 expectrid; // Request code of subsequent request
00529    kXR_char  version;   // Security version being used (see XSecVersion)
00530    kXR_char  flags;     // One or more flags defined in enum (see XSecFlags)
00531    kXR_unt64 seqno;     // Monotonically increasing number (part of hash)
00532    kXR_char  crypto;    // Cryptography used (see XSecCrypto)
00533    kXR_char  rsvd2[3];
00534    kXR_int32 dlen;
00535 };
00536 struct ClientStatRequest {
00537    kXR_char  streamid[2];
00538    kXR_unt16 requestid;
00539    kXR_char  options;
00540    kXR_char reserved[11];
00541    kXR_char fhandle[4];
00542    kXR_int32  dlen;
00543 };
00544 struct ClientSyncRequest {
00545    kXR_char  streamid[2];
00546    kXR_unt16 requestid;
00547    kXR_char fhandle[4];
00548    kXR_char reserved[12];
00549    kXR_int32  dlen;
00550 };
00551 struct ClientTruncateRequest {
00552    kXR_char  streamid[2];
00553    kXR_unt16 requestid;
00554    kXR_char fhandle[4];
00555    kXR_int64 offset;
00556    kXR_char reserved[4];
00557    kXR_int32  dlen;
00558 };
00559 struct ClientWriteRequest {
00560    kXR_char  streamid[2];
00561    kXR_unt16 requestid;
00562    kXR_char fhandle[4];
00563    kXR_int64 offset;
00564    kXR_char  pathid;
00565    kXR_char reserved[3];
00566    kXR_int32  dlen;
00567 };
00568 struct ClientVerifywRequest {
00569    kXR_char  streamid[2];
00570    kXR_unt16 requestid;
00571    kXR_char  fhandle[4];
00572    kXR_int64 offset;
00573    kXR_char  pathid;
00574    kXR_char  vertype;       // One of XVerifyType
00575    kXR_char  reserved[2];
00576    kXR_int32 dlen;          // Includes crc length
00577 };
00578 
00579 struct ClientRequestHdr {
00580    kXR_char  streamid[2];
00581    kXR_unt16 requestid;
00582    kXR_char  body[16];
00583    kXR_int32  dlen;
00584 };
00585 
00586 typedef union {
00587    struct ClientRequestHdr header;
00588    struct ClientAdminRequest admin;
00589    struct ClientAuthRequest auth;
00590    struct ClientBindRequest bind;
00591    struct ClientChmodRequest chmod;
00592    struct ClientCloseRequest close;
00593    struct ClientDecryptRequest decrypt;
00594    struct ClientDirlistRequest dirlist;
00595    struct ClientEndsessRequest endsess;
00596    struct ClientGetfileRequest getfile;
00597    struct ClientLocateRequest locate;
00598    struct ClientLoginRequest login;
00599    struct ClientMkdirRequest mkdir;
00600    struct ClientMvRequest mv;
00601    struct ClientOpenRequest open;
00602    struct ClientPingRequest ping;
00603    struct ClientPrepareRequest prepare;
00604    struct ClientProtocolRequest protocol;
00605    struct ClientPutfileRequest putfile;
00606    struct ClientQueryRequest query;
00607    struct ClientReadRequest read;
00608    struct ClientReadVRequest readv;
00609    struct ClientRmRequest rm;
00610    struct ClientRmdirRequest rmdir;
00611    struct ClientSetRequest set;
00612    struct ClientSigverRequest sigver;
00613    struct ClientStatRequest stat;
00614    struct ClientSyncRequest sync;
00615    struct ClientTruncateRequest truncate;
00616    struct ClientWriteRequest write;
00617 } ClientRequest;
00618 
00619 typedef union {
00620    struct ClientRequestHdr header;
00621    struct ClientDecryptRequest decrypt;
00622    struct ClientSigverRequest sigver;
00623 } SecurityRequest;
00624 
00625 struct readahead_list {
00626    kXR_char fhandle[4];
00627    kXR_int32 rlen;
00628    kXR_int64 offset;
00629 };
00630 
00631 struct read_args {
00632    kXR_char       pathid;
00633    kXR_char       reserved[7];
00634    // his struct is followed by an array of readahead_list
00635 };
00636 
00637 //_____________________________________________________________________
00638 //   PROTOCOL DEFINITION: SERVER'S RESPONSE
00639 //_____________________________________________________________________
00640 //
00641 
00642 // Nice header for the server response.
00643 // Note that the protocol specifies these values to be in network
00644 // byte order when sent
00645 //
00646 // G.Ganis: The following structures never need padding bytes:
00647 //          no need of packing options
00648 
00649 struct ServerResponseHeader {
00650    kXR_char streamid[2];
00651    kXR_unt16 status;
00652    kXR_int32  dlen;
00653 };
00654 
00655 // Body for the kXR_bind response... useful
00656 struct ServerResponseBody_Bind {
00657     kXR_char substreamid;
00658 };
00659 
00660 // Body for the kXR_open response... useful
00661 struct ServerResponseBody_Open {
00662    kXR_char fhandle[4];
00663    kXR_int32 cpsize;   // cpsize & cptype returned if kXR_compress *or*
00664    kXR_char cptype[4]; // kXR_retstat is specified
00665 }; // info will follow if kXR_retstat is specified
00666 
00667 // The following information is returned in the response body when kXR_secreqs
00668 // is set in ClientProtocolRequest::flags. Note that the size of secvec is
00669 // defined by secvsz and will not be present when secvsz == 0.
00670 struct ServerResponseSVec_Protocol {
00671    kXR_char  reqindx;     // Request index
00672    kXR_char  reqsreq;     // Request signing requirement
00673 };
00674 
00675 struct ServerResponseReqs_Protocol {
00676    kXR_char  theTag;      // Always the character 'S' to identify struct
00677    kXR_char  rsvd;        // Reserved for the future (always 0 for now)
00678    kXR_char  secver;      // Security version
00679    kXR_char  secopt;      // Security options
00680    kXR_char  seclvl;      // Security level when secvsz == 0
00681    kXR_char  secvsz;      // Number of items in secvec (i.e. its length/2)
00682    ServerResponseSVec_Protocol secvec;
00683 };
00684 
00685 // Options reflected in protocol response ServerResponseReqs_Protocol::secopt
00686 //
00687 #define kXR_secOData 0x01
00688 #define kXR_secOFrce 0x02
00689 
00690 // Security level definitions (these are predefined but can be over-ridden)
00691 //
00692 #define kXR_secNone       0
00693 #define kXR_secCompatible 1
00694 #define kXR_secStandard   2
00695 #define kXR_secIntense    3
00696 #define kXR_secPedantic   4
00697 
00698 // Requirements one of which set in each ServerResponseReqs_Protocol::secvec
00699 //
00700 #define kXR_signIgnore    0
00701 #define kXR_signLikely    1
00702 #define kXR_signNeeded    2
00703 
00704 // Body for the kXR_protocol response... useful
00705 struct ServerResponseBody_Protocol {
00706    kXR_int32 pval;
00707    kXR_int32 flags;
00708    ServerResponseReqs_Protocol secreq; // Only for V3.1.0+ && if requested
00709 };
00710 
00711 // Handy definition of the size of the protocol response when the security
00712 // information is not present.
00713 //
00714 #define kXR_ShortProtRespLen sizeof(ServerResponseBody_Protocol)-\
00715                              sizeof(ServerResponseReqs_Protocol)
00716 
00717 struct ServerResponseBody_Login {
00718    kXR_char  sessid[16];
00719    kXR_char  sec[4096]; // Should be sufficient for every use
00720 };
00721 
00722 struct ServerResponseBody_Redirect {
00723    kXR_int32 port;
00724    char host[4096]; // Should be sufficient for every use
00725 };
00726 
00727 struct ServerResponseBody_Error {
00728    kXR_int32 errnum;
00729    char errmsg[4096]; // Should be sufficient for every use
00730 };
00731 
00732 struct ServerResponseBody_Wait {
00733    kXR_int32 seconds;
00734    char infomsg[4096]; // Should be sufficient for every use
00735 };
00736 
00737 struct ServerResponseBody_Waitresp {
00738    kXR_int32 seconds;
00739 };
00740 
00741 struct ServerResponseBody_Attn {
00742    kXR_int32 actnum;
00743    char parms[4096]; // Should be sufficient for every use
00744 };
00745 
00746 struct ServerResponseBody_Attn_asyncrd {
00747    kXR_int32 actnum;
00748    kXR_int32 port;
00749    char host[4092];
00750 };
00751 
00752 struct ServerResponseBody_Attn_asynresp {
00753    kXR_int32            actnum;
00754    char reserved[4];
00755    ServerResponseHeader resphdr;
00756    char respdata[4096];
00757 };
00758 
00759 struct ServerResponseBody_Attn_asyncwt {
00760    kXR_int32 actnum;
00761    kXR_int32 wsec;
00762 };
00763 
00764 struct ServerResponseBody_Attn_asyncdi {
00765    kXR_int32 actnum;
00766    kXR_int32 wsec;
00767    kXR_int32 msec;
00768 };
00769 
00770 struct ServerResponseBody_Authmore {
00771    char data[4096];
00772 };
00773 
00774 struct ServerResponseBody_Buffer {
00775    char data[4096];
00776 };
00777 
00778 struct ServerResponse
00779 {
00780   ServerResponseHeader hdr;
00781   union
00782   {
00783     ServerResponseBody_Error    error;
00784     ServerResponseBody_Authmore authmore;
00785     ServerResponseBody_Wait     wait;
00786     ServerResponseBody_Waitresp waitresp;
00787     ServerResponseBody_Redirect redirect;
00788     ServerResponseBody_Attn     attn;
00789     ServerResponseBody_Protocol protocol;
00790     ServerResponseBody_Login    login;
00791     ServerResponseBody_Buffer   buffer;
00792     ServerResponseBody_Bind     bind;
00793   } body;
00794 };
00795 
00796 void ServerResponseHeader2NetFmt(struct ServerResponseHeader *srh);
00797 
00798 // The fields to be sent as initial handshake
00799 struct ClientInitHandShake {
00800    kXR_int32 first;
00801    kXR_int32 second;
00802    kXR_int32 third;
00803    kXR_int32 fourth;
00804    kXR_int32 fifth;
00805 };
00806 
00807 // The body received after the first handshake's header
00808 struct ServerInitHandShake {
00809    kXR_int32 msglen;
00810    kXR_int32 protover;
00811    kXR_int32 msgval;
00812 };
00813 
00814 
00815 
00816 typedef kXR_int32 ServerResponseType;
00817 
00818 struct ALIGN_CHECK {char chkszreq[25-sizeof(ClientRequest)];
00819    char chkszrsp[ 9-sizeof(ServerResponseHeader)];
00820 };
00821 
00822 /******************************************************************************/
00823 /*                   X P r o t o c o l   U t i l i t i e s                    */
00824 /******************************************************************************/
00825 
00826 #include <errno.h>
00827 #if defined(WIN32)
00828 #if !defined(ENOTBLK)
00829 #  define ENOTBLK 15
00830 #endif
00831 #if !defined(ETXTBSY)
00832 #define ETXTBSY 26
00833 #endif
00834 #if !defined(ENOBUFS)
00835 #define ENOBUFS 105
00836 #endif
00837 #if !defined(ENETUNREACH)
00838 #define ENETUNREACH 114
00839 #endif
00840 #endif
00841   
00842 class XProtocol
00843 {
00844 public:
00845 
00846 // mapError() is the occicial mapping from errno to xrootd protocol error.
00847 //
00848 static int mapError(int rc)
00849       {if (rc < 0) rc = -rc;
00850        switch(rc)
00851           {case ENOENT:       return kXR_NotFound;
00852            case EPERM:        return kXR_NotAuthorized;
00853            case EACCES:       return kXR_NotAuthorized;
00854            case EIO:          return kXR_IOError;
00855            case ENOMEM:       return kXR_NoMemory;
00856            case ENOBUFS:      return kXR_NoMemory;
00857            case ENOSPC:       return kXR_NoSpace;
00858            case ENAMETOOLONG: return kXR_ArgTooLong;
00859            case ENETUNREACH:  return kXR_noserver;
00860            case ENOTBLK:      return kXR_NotFile;
00861            case EISDIR:       return kXR_isDirectory;
00862            case EEXIST:       return kXR_InvalidRequest;
00863            case ETXTBSY:      return kXR_inProgress;
00864            case ENODEV:       return kXR_FSError;
00865            case EFAULT:       return kXR_ServerError;
00866            case EDOM:         return kXR_ChkSumErr;
00867            case EDQUOT:       return kXR_overQuota;
00868            case EILSEQ:       return kXR_SigVerErr;
00869            case ERANGE:       return kXR_DecryptErr;
00870            default:           return kXR_FSError;
00871           }
00872       }
00873 
00874 static int toErrno( int xerr )
00875 {
00876     switch(xerr)
00877        {case kXR_ArgInvalid:    return EINVAL;
00878         case kXR_ArgMissing:    return EINVAL;
00879         case kXR_ArgTooLong:    return ENAMETOOLONG;
00880         case kXR_FileLocked:    return EDEADLK;
00881         case kXR_FileNotOpen:   return EBADF;
00882         case kXR_FSError:       return EIO;
00883         case kXR_InvalidRequest:return EEXIST;
00884         case kXR_IOError:       return EIO;
00885         case kXR_NoMemory:      return ENOMEM;
00886         case kXR_NoSpace:       return ENOSPC;
00887         case kXR_NotAuthorized: return EACCES;
00888         case kXR_NotFound:      return ENOENT;
00889         case kXR_ServerError:   return ENOMSG;
00890         case kXR_Unsupported:   return ENOSYS;
00891         case kXR_noserver:      return EHOSTUNREACH;
00892         case kXR_NotFile:       return ENOTBLK;
00893         case kXR_isDirectory:   return EISDIR;
00894         case kXR_Cancelled:     return ECANCELED;
00895         case kXR_ChkLenErr:     return EDOM;
00896         case kXR_ChkSumErr:     return EDOM;
00897         case kXR_inProgress:    return EINPROGRESS;
00898         case kXR_overQuota:     return EDQUOT;
00899         case kXR_SigVerErr:     return EILSEQ;
00900         case kXR_DecryptErr:    return ERANGE;
00901         default:                return ENOMSG;
00902        }
00903 }
00904 
00905 static const char *errName(kXR_int32 errCode);
00906 
00907 static const char *reqName(kXR_unt16 reqCode);
00908 };
00909 #endif

Generated on 13 Mar 2017 for xrootd by  doxygen 1.4.7