xrootd
XProtocol.hh
Go to the documentation of this file.
1 #ifndef __XPROTOCOL_H
2 #define __XPROTOCOL_H
3 
4 //#ifndef __GNUC__
5 //#define __attribute__(x)
6 //#ifdef SUNCC
7 //#pragma pack(4)
8 //#endif
9 //#endif
10 
11 #ifdef __CINT__
12 #define __attribute__(x)
13 #endif
14 
15 // The following is the binary representation of the protocol version here.
16 // Protocol version is repesented as three base10 digits x.y.z with x having no
17 // upper limit (i.e. n.9.9 + 1 -> n+1.0.0).
18 //
19 #define kXR_PROTOCOLVERSION 0x00000297
20 #define kXR_PROTOCOLVSTRING "2.9.7"
21 
22 #include "XProtocol/XPtypes.hh"
23 
24 // KINDS of SERVERS
25 //
26 //
27 #define kXR_DataServer 1
28 #define kXR_LBalServer 0
29 
30 // The below are defined for protocol version 2.9.7 or higher
31 //
32 #define kXR_isManager 0x00000002
33 #define kXR_isServer 0x00000001
34 #define kXR_attrMeta 0x00000100
35 #define kXR_attrProxy 0x00000200
36 #define kXR_attrSuper 0x00000400
37 
38 #define kXR_maxReqRetry 10
39 
40 //
41 // Kind of error inside a XTNetFile's routine (temporary)
42 //
44  kGENERICERR = 0, // Generic error
45  kREAD, // Error while reading from stream
46  kWRITE, // Error while writing to stream
47  kREDIRCONNECT, // Error redirecting to a given host
48  kOK, // Everything seems ok
49  kNOMORESTREAMS // No more available stream IDs for
50  // async processing
51 };
52 
53 //______________________________________________
54 // PROTOCOL DEFINITION: CLIENT'S REQUESTS TYPES
55 //______________________________________________
56 //
58  kXR_auth = 3000,
59  kXR_query, // 3001
60  kXR_chmod, // 3002
61  kXR_close, // 3003
62  kXR_dirlist, // 3004
63  kXR_getfile, // 3005
64  kXR_protocol,// 3006
65  kXR_login, // 3007
66  kXR_mkdir, // 3008
67  kXR_mv, // 3009
68  kXR_open, // 3010
69  kXR_ping, // 3011
70  kXR_putfile, // 3012
71  kXR_read, // 3013
72  kXR_rm, // 3014
73  kXR_rmdir, // 3015
74  kXR_sync, // 3016
75  kXR_stat, // 3017
76  kXR_set, // 3018
77  kXR_write, // 3019
78  kXR_admin, // 3020
79  kXR_prepare, // 3021
80  kXR_statx, // 3022
81  kXR_endsess, // 3023
82  kXR_bind, // 3024
83  kXR_readv, // 3025
84  kXR_verifyw, // 3026
85  kXR_locate, // 3027
86  kXR_truncate // 3028
87 };
88 
89 // OPEN MODE FOR A REMOTE FILE
91  kXR_ur = 0x100,
92  kXR_uw = 0x080,
93  kXR_ux = 0x040,
94  kXR_gr = 0x020,
95  kXR_gw = 0x010,
96  kXR_gx = 0x008,
97  kXR_or = 0x004,
98  kXR_ow = 0x002,
99  kXR_ox = 0x001
100 };
101 
105 };
106 
107 // this is a bitmask
112 };
113 
114 // this is a single number that goes into capver as the version
115 //
117  kXR_ver000 = 0, // Old clients predating history
118  kXR_ver001 = 1, // Generally implemented 2005 protocol
119  kXR_ver002 = 2, // Same as 1 but adds asyncresp recognition
120  kXR_ver003 = 3 // The 2011-2012 rewritten client
121 };
122 
125 };
126 
128  kXR_file = 0,
129  kXR_xset = 1,
136 };
137 
140 };
141 
146  kXR_new = 8,
149  kXR_async = 64,
150  kXR_refresh = 128,
151  kXR_mkpath = 256,
153  kXR_retstat = 1024,
154  kXR_replica = 2048,
155  kXR_posc = 4096,
156  kXR_nowait = 8192,
157  kXR_seqio =16384
158 };
159 
171 };
172 
176 };
177 
181 };
182 
183 // Andy's request for async/unsolicited
189  kXR_wmode = 16,
190  kXR_coloc = 32,
192 };
193 
194 //_______________________________________________
195 // PROTOCOL DEFINITION: SERVER'S RESPONSES TYPES
196 //_______________________________________________
197 //
199  kXR_ok = 0,
200  kXR_oksofar = 4000,
208 };
209 
210 //_______________________________________________
211 // PROTOCOL DEFINITION: SERVER"S ATTN CODES
212 //_______________________________________________
213 
215  kXR_asyncab = 5000,
224 };
225 
226 //_______________________________________________
227 // PROTOCOL DEFINITION: SERVER'S ERROR CODES
228 //_______________________________________________
229 //
253 };
254 
255 
256 //______________________________________________
257 // PROTOCOL DEFINITION: CLIENT'S REQUESTS STRUCTS
258 //______________________________________________
259 //
260 // We need to pack structures sent all over the net!
261 // __attribute__((packed)) assures no padding bytes.
262 //
263 // Nice bodies of the headers for the client requests.
264 // Note that the protocol specifies these values to be in network
265 // byte order when sent
266 //
267 // G.Ganis: use of flat structures to avoid packing options
268 
274 };
281 };
287 };
294 };
302 };
309 };
315 };
323 };
330 };
340 };
348 };
354 };
362 };
363 
369 };
373  kXR_int32 clientpv; // 2.9.7 or higher
376 };
384 };
392 };
401 };
409 };
415 };
421 };
427 };
433 };
441 };
448 };
456 };
465 };
472  kXR_char vertype; // One of XVerifyType
474  kXR_int32 dlen; // Includes crc length
475 };
476 
482 };
483 
484 typedef union {
485  struct ClientRequestHdr header;
486  struct ClientAdminRequest admin;
487  struct ClientAuthRequest auth;
488  struct ClientBindRequest bind;
489  struct ClientChmodRequest chmod;
491  struct ClientDirlistRequest dirlist;
492  struct ClientEndsessRequest endsess;
493  struct ClientGetfileRequest getfile;
494  struct ClientLocateRequest locate;
495  struct ClientLoginRequest login;
497  struct ClientMvRequest mv;
499  struct ClientPingRequest ping;
501  struct ClientProtocolRequest protocol;
502  struct ClientPutfileRequest putfile;
503  struct ClientQueryRequest query;
506  struct ClientRmRequest rm;
508  struct ClientSetRequest set;
510  struct ClientSyncRequest sync;
513 } ClientRequest;
514 
519 };
520 
521 struct read_args {
524  // his struct is followed by an array of readahead_list
525 };
526 
527 //_____________________________________________________________________
528 // PROTOCOL DEFINITION: SERVER'S RESPONSE
529 //_____________________________________________________________________
530 //
531 
532 // Nice header for the server response.
533 // Note that the protocol specifies these values to be in network
534 // byte order when sent
535 //
536 // G.Ganis: The following structures never need padding bytes:
537 // no need of packing options
538 
543 };
544 
545 // Body for the kXR_bind response... useful
548 };
549 
550 // Body for the kXR_open response... useful
553  kXR_int32 cpsize; // cpsize & cptype returned if kXR_compress *or*
554  kXR_char cptype[4]; // kXR_retstat is specified
555 }; // info will follow if kXR_retstat is specified
556 
557 // Body for the kXR_protocol response... useful
561 };
562 
565  kXR_char sec[4096]; // Should be sufficient for every use
566 };
567 
570  char host[4096]; // Should be sufficient for every use
571 };
572 
575  char errmsg[4096]; // Should be sufficient for every use
576 };
577 
580  char infomsg[4096]; // Should be sufficient for every use
581 };
582 
585 };
586 
589  char parms[4096]; // Should be sufficient for every use
590 };
591 
595  char host[4092];
596 };
597 
600  char reserved[4];
602  char respdata[4096];
603 };
604 
608 };
609 
614 };
615 
617  char data[4096];
618 };
619 
621  char data[4096];
622 };
623 
625 {
627  union
628  {
638  } body;
639 };
640 
642 
643 // The fields to be sent as initial handshake
650 };
651 
652 // The body received after the first handshake's header
657 };
658 
659 
660 
662 
663 struct ALIGN_CHECK {char chkszreq[25-sizeof(ClientRequest)];
664  char chkszrsp[ 9-sizeof(ServerResponseHeader)];
665 };
666 
667 /******************************************************************************/
668 /* X P r o t o c o l U t i l i t i e s */
669 /******************************************************************************/
670 
671 #include <errno.h>
672 #if defined(WIN32)
673 #if !defined(ENOTBLK)
674 # define ENOTBLK 15
675 #endif
676 #if !defined(ETXTBSY)
677 #define ETXTBSY 26
678 #endif
679 #if !defined(ENOBUFS)
680 #define ENOBUFS 105
681 #endif
682 #if !defined(ENETUNREACH)
683 #define ENETUNREACH 114
684 #endif
685 #endif
686 
688 {
689 public:
690 
691 // mapError() is the occicial mapping from errno to xrootd protocol error.
692 //
693 static int mapError(int rc)
694  {if (rc < 0) rc = -rc;
695  switch(rc)
696  {case ENOENT: return kXR_NotFound;
697  case EPERM: return kXR_NotAuthorized;
698  case EACCES: return kXR_NotAuthorized;
699  case EIO: return kXR_IOError;
700  case ENOMEM: return kXR_NoMemory;
701  case ENOBUFS: return kXR_NoMemory;
702  case ENOSPC: return kXR_NoSpace;
703  case ENAMETOOLONG: return kXR_ArgTooLong;
704  case ENETUNREACH: return kXR_noserver;
705  case ENOTBLK: return kXR_NotFile;
706  case EISDIR: return kXR_isDirectory;
707  case EEXIST: return kXR_InvalidRequest;
708  case ETXTBSY: return kXR_inProgress;
709  default: return kXR_FSError;
710  }
711  }
712 };
713 #endif