xrootd
XProtocol.hh
Go to the documentation of this file.
1 #ifndef __XPROTOCOL_H
2 #define __XPROTOCOL_H
3 /******************************************************************************/
4 /* */
5 /* X P r o t o c o l . 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 //#ifndef __GNUC__
34 //#define __attribute__(x)
35 //#ifdef SUNCC
36 //#pragma pack(4)
37 //#endif
38 //#endif
39 
40 #ifdef __CINT__
41 #define __attribute__(x)
42 #endif
43 
44 // The following is the binary representation of the protocol version here.
45 // Protocol version is repesented as three base10 digits x.y.z with x having no
46 // upper limit (i.e. n.9.9 + 1 -> n+1.0.0).
47 //
48 #define kXR_PROTOCOLVERSION 0x00000300
49 #define kXR_PROTOCOLVSTRING "3.0.0"
50 
51 #include "XProtocol/XPtypes.hh"
52 
53 // KINDS of SERVERS
54 //
55 //
56 #define kXR_DataServer 1
57 #define kXR_LBalServer 0
58 
59 // The below are defined for protocol version 2.9.7 or higher
60 //
61 #define kXR_isManager 0x00000002
62 #define kXR_isServer 0x00000001
63 #define kXR_attrMeta 0x00000100
64 #define kXR_attrProxy 0x00000200
65 #define kXR_attrSuper 0x00000400
66 
67 #define kXR_maxReqRetry 10
68 
69 //
70 // Kind of error inside a XTNetFile's routine (temporary)
71 //
73  kGENERICERR = 0, // Generic error
74  kREAD, // Error while reading from stream
75  kWRITE, // Error while writing to stream
76  kREDIRCONNECT, // Error redirecting to a given host
77  kOK, // Everything seems ok
78  kNOMORESTREAMS // No more available stream IDs for
79  // async processing
80 };
81 
82 //______________________________________________
83 // PROTOCOL DEFINITION: CLIENT'S REQUESTS TYPES
84 //______________________________________________
85 //
87  kXR_auth = 3000,
88  kXR_query, // 3001
89  kXR_chmod, // 3002
90  kXR_close, // 3003
91  kXR_dirlist, // 3004
92  kXR_getfile, // 3005
93  kXR_protocol,// 3006
94  kXR_login, // 3007
95  kXR_mkdir, // 3008
96  kXR_mv, // 3009
97  kXR_open, // 3010
98  kXR_ping, // 3011
99  kXR_putfile, // 3012
100  kXR_read, // 3013
101  kXR_rm, // 3014
102  kXR_rmdir, // 3015
103  kXR_sync, // 3016
104  kXR_stat, // 3017
105  kXR_set, // 3018
106  kXR_write, // 3019
107  kXR_admin, // 3020
108  kXR_prepare, // 3021
109  kXR_statx, // 3022
110  kXR_endsess, // 3023
111  kXR_bind, // 3024
112  kXR_readv, // 3025
113  kXR_verifyw, // 3026
114  kXR_locate, // 3027
115  kXR_truncate // 3028
116 };
117 
118 // OPEN MODE FOR A REMOTE FILE
120  kXR_ur = 0x100,
121  kXR_uw = 0x080,
122  kXR_ux = 0x040,
123  kXR_gr = 0x020,
124  kXR_gw = 0x010,
125  kXR_gx = 0x008,
126  kXR_or = 0x004,
127  kXR_ow = 0x002,
128  kXR_ox = 0x001
129 };
130 
134 };
135 
136 // this is a bitmask
145 };
146 
147 // this is a bitmask
152 };
153 
154 // this is a single number that goes into capver as the version
155 //
157  kXR_ver000 = 0, // Old clients predating history
158  kXR_ver001 = 1, // Generally implemented 2005 protocol
159  kXR_ver002 = 2, // Same as 1 but adds asyncresp recognition
160  kXR_ver003 = 3 // The 2011-2012 rewritten client
161 };
162 
165 };
166 
168  kXR_file = 0,
169  kXR_xset = 1,
177 };
178 
182 };
183 
188  kXR_new = 8,
191  kXR_async = 64,
192  kXR_refresh = 128, // also locate
193  kXR_mkpath = 256,
194  kXR_prefname = 256, // only locate
196  kXR_retstat = 1024,
197  kXR_replica = 2048,
198  kXR_posc = 4096,
199  kXR_nowait = 8192, // also locate
200  kXR_seqio =16384,
202 };
203 
216 };
217 
221 };
222 
226 };
227 
228 // Andy's request for async/unsolicited
234  kXR_wmode = 16,
235  kXR_coloc = 32,
237 };
238 
239 //_______________________________________________
240 // PROTOCOL DEFINITION: SERVER'S RESPONSES TYPES
241 //_______________________________________________
242 //
244  kXR_ok = 0,
245  kXR_oksofar = 4000,
253 };
254 
255 //_______________________________________________
256 // PROTOCOL DEFINITION: SERVER"S ATTN CODES
257 //_______________________________________________
258 
260  kXR_asyncab = 5000,
269 };
270 
271 //_______________________________________________
272 // PROTOCOL DEFINITION: SERVER'S ERROR CODES
273 //_______________________________________________
274 //
298 };
299 
300 
301 //______________________________________________
302 // PROTOCOL DEFINITION: CLIENT'S REQUESTS STRUCTS
303 //______________________________________________
304 //
305 // We need to pack structures sent all over the net!
306 // __attribute__((packed)) assures no padding bytes.
307 //
308 // Nice bodies of the headers for the client requests.
309 // Note that the protocol specifies these values to be in network
310 // byte order when sent
311 //
312 // G.Ganis: use of flat structures to avoid packing options
313 
319 };
326 };
332 };
339 };
347 };
354 };
360 };
368 };
375 };
382  kXR_char ability; // See XLoginAbility enum flags
383  kXR_char capver[1]; // See XLoginCapVer enum flags
386 };
394 };
400 };
408 };
409 
415 };
419  kXR_int32 clientpv; // 2.9.7 or higher
422 };
428  kXR_unt16 port; // 2.9.9 or higher
431 };
439 };
448 };
456 };
463 };
469 };
475 };
481 };
489 };
496 };
504 };
513 };
520  kXR_char vertype; // One of XVerifyType
522  kXR_int32 dlen; // Includes crc length
523 };
524 
530 };
531 
532 typedef union {
533  struct ClientRequestHdr header;
534  struct ClientAdminRequest admin;
535  struct ClientAuthRequest auth;
536  struct ClientBindRequest bind;
537  struct ClientChmodRequest chmod;
538  struct ClientCloseRequest close;
539  struct ClientDirlistRequest dirlist;
540  struct ClientEndsessRequest endsess;
541  struct ClientGetfileRequest getfile;
542  struct ClientLocateRequest locate;
543  struct ClientLoginRequest login;
544  struct ClientMkdirRequest mkdir;
545  struct ClientMvRequest mv;
546  struct ClientOpenRequest open;
547  struct ClientPingRequest ping;
548  struct ClientPrepareRequest prepare;
549  struct ClientProtocolRequest protocol;
550  struct ClientPutfileRequest putfile;
551  struct ClientQueryRequest query;
552  struct ClientReadRequest read;
553  struct ClientReadVRequest readv;
554  struct ClientRmRequest rm;
555  struct ClientRmdirRequest rmdir;
556  struct ClientSetRequest set;
557  struct ClientStatRequest stat;
558  struct ClientSyncRequest sync;
559  struct ClientTruncateRequest truncate;
560  struct ClientWriteRequest write;
561 } ClientRequest;
562 
567 };
568 
569 struct read_args {
572  // his struct is followed by an array of readahead_list
573 };
574 
575 //_____________________________________________________________________
576 // PROTOCOL DEFINITION: SERVER'S RESPONSE
577 //_____________________________________________________________________
578 //
579 
580 // Nice header for the server response.
581 // Note that the protocol specifies these values to be in network
582 // byte order when sent
583 //
584 // G.Ganis: The following structures never need padding bytes:
585 // no need of packing options
586 
591 };
592 
593 // Body for the kXR_bind response... useful
596 };
597 
598 // Body for the kXR_open response... useful
601  kXR_int32 cpsize; // cpsize & cptype returned if kXR_compress *or*
602  kXR_char cptype[4]; // kXR_retstat is specified
603 }; // info will follow if kXR_retstat is specified
604 
605 // Body for the kXR_protocol response... useful
609 };
610 
613  kXR_char sec[4096]; // Should be sufficient for every use
614 };
615 
618  char host[4096]; // Should be sufficient for every use
619 };
620 
623  char errmsg[4096]; // Should be sufficient for every use
624 };
625 
628  char infomsg[4096]; // Should be sufficient for every use
629 };
630 
633 };
634 
637  char parms[4096]; // Should be sufficient for every use
638 };
639 
643  char host[4092];
644 };
645 
648  char reserved[4];
650  char respdata[4096];
651 };
652 
656 };
657 
662 };
663 
665  char data[4096];
666 };
667 
669  char data[4096];
670 };
671 
673 {
675  union
676  {
687  } body;
688 };
689 
691 
692 // The fields to be sent as initial handshake
699 };
700 
701 // The body received after the first handshake's header
706 };
707 
708 
709 
711 
712 struct ALIGN_CHECK {char chkszreq[25-sizeof(ClientRequest)];
713  char chkszrsp[ 9-sizeof(ServerResponseHeader)];
714 };
715 
716 /******************************************************************************/
717 /* X P r o t o c o l U t i l i t i e s */
718 /******************************************************************************/
719 
720 #include <errno.h>
721 #if defined(WIN32)
722 #if !defined(ENOTBLK)
723 # define ENOTBLK 15
724 #endif
725 #if !defined(ETXTBSY)
726 #define ETXTBSY 26
727 #endif
728 #if !defined(ENOBUFS)
729 #define ENOBUFS 105
730 #endif
731 #if !defined(ENETUNREACH)
732 #define ENETUNREACH 114
733 #endif
734 #endif
735 
737 {
738 public:
739 
740 // mapError() is the occicial mapping from errno to xrootd protocol error.
741 //
742 static int mapError(int rc)
743  {if (rc < 0) rc = -rc;
744  switch(rc)
745  {case ENOENT: return kXR_NotFound;
746  case EPERM: return kXR_NotAuthorized;
747  case EACCES: return kXR_NotAuthorized;
748  case EIO: return kXR_IOError;
749  case ENOMEM: return kXR_NoMemory;
750  case ENOBUFS: return kXR_NoMemory;
751  case ENOSPC: return kXR_NoSpace;
752  case ENAMETOOLONG: return kXR_ArgTooLong;
753  case ENETUNREACH: return kXR_noserver;
754  case ENOTBLK: return kXR_NotFile;
755  case EISDIR: return kXR_isDirectory;
756  case EEXIST: return kXR_InvalidRequest;
757  case ETXTBSY: return kXR_inProgress;
758  default: return kXR_FSError;
759  }
760  }
761 };
762 #endif