1 /* 2 * Copyright 2012 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Paweł Dziepak, pdziepak@quarnos.org 7 */ 8 #ifndef REPLYINTERPRETER_H 9 #define REPLYINTERPRETER_H 10 11 12 #include <SupportDefs.h> 13 14 #include "NFS4Defs.h" 15 #include "RPCReply.h" 16 17 18 struct FSLocation { 19 const char* fRootPath; 20 const char** fLocations; 21 uint32 fCount; 22 23 ~FSLocation(); 24 }; 25 26 struct FSLocations { 27 const char* fRootPath; 28 FSLocation* fLocations; 29 uint32 fCount; 30 31 ~FSLocations(); 32 }; 33 34 struct AttrValue { 35 AttrValue(); 36 ~AttrValue(); 37 38 uint8 fAttribute; 39 bool fFreePointer; 40 union { 41 uint32 fValue32; 42 uint64 fValue64; 43 void* fPointer; 44 FSLocations* fLocations; 45 } fData; 46 }; 47 48 struct DirEntry { 49 const char* fName; 50 AttrValue* fAttrs; 51 uint32 fAttrCount; 52 53 DirEntry(); 54 ~DirEntry(); 55 }; 56 57 class ReplyInterpreter { 58 public: 59 ReplyInterpreter(RPC::Reply* reply = NULL); 60 ~ReplyInterpreter(); 61 62 inline status_t SetTo(RPC::Reply* reply); 63 inline void Reset(); 64 65 inline uint32 NFS4Error(); 66 67 status_t Access(uint32* supported, uint32* allowed); 68 status_t Close(); 69 status_t Create(); 70 status_t GetAttr(AttrValue** attrs, uint32* count); 71 status_t GetFH(Filehandle* fh); 72 status_t Link(); 73 inline status_t LookUp(); 74 inline status_t LookUpUp(); 75 status_t Open(uint32* id, uint32* seq, bool* confirm); 76 status_t OpenConfirm(uint32* stateSeq); 77 inline status_t PutFH(); 78 inline status_t PutRootFH(); 79 status_t Read(void* buffer, uint32* size, bool* eof); 80 status_t ReadDir(uint64* cookie, uint64* cookieVerf, 81 DirEntry** dirents, uint32* count, bool* eof); 82 status_t ReadLink(void* buffer, uint32* size, uint32 maxSize); 83 status_t Remove(); 84 status_t Rename(); 85 inline status_t Renew(); 86 inline status_t SaveFH(); 87 status_t SetClientID(uint64* clientid, uint64* verifier); 88 inline status_t SetClientIDConfirm(); 89 inline status_t Verify(); 90 status_t Write(uint32* size); 91 92 private: 93 void _ParseHeader(); 94 95 status_t _DecodeAttrs(XDR::ReadStream& stream, AttrValue** attrs, 96 uint32* count); 97 status_t _OperationError(Opcode op); 98 99 static status_t _NFS4ErrorToHaiku(uint32 x); 100 101 uint32 fNFS4Error; 102 bool fDecodeError; 103 RPC::Reply* fReply; 104 }; 105 106 107 inline status_t 108 ReplyInterpreter::SetTo(RPC::Reply* _reply) 109 { 110 if (fReply != NULL) 111 return B_DONT_DO_THAT; 112 113 fDecodeError = false; 114 fReply = _reply; 115 116 if (fReply != NULL) 117 _ParseHeader(); 118 119 return B_OK; 120 } 121 122 123 inline void 124 ReplyInterpreter::Reset() 125 { 126 delete fReply; 127 fReply = NULL; 128 fDecodeError = false; 129 } 130 131 132 inline uint32 133 ReplyInterpreter::NFS4Error() 134 { 135 return fNFS4Error; 136 } 137 138 139 inline status_t 140 ReplyInterpreter::LookUp() 141 { 142 return _OperationError(OpLookUp); 143 } 144 145 146 inline status_t 147 ReplyInterpreter::LookUpUp() 148 { 149 return _OperationError(OpLookUpUp); 150 } 151 152 153 inline status_t 154 ReplyInterpreter::PutFH() 155 { 156 return _OperationError(OpPutFH); 157 } 158 159 160 inline status_t 161 ReplyInterpreter::PutRootFH() 162 { 163 return _OperationError(OpPutRootFH); 164 } 165 166 167 inline status_t 168 ReplyInterpreter::Renew() 169 { 170 return _OperationError(OpRenew); 171 } 172 173 174 inline status_t 175 ReplyInterpreter::SaveFH() 176 { 177 return _OperationError(OpSaveFH); 178 } 179 180 181 inline status_t 182 ReplyInterpreter::SetClientIDConfirm() 183 { 184 return _OperationError(OpSetClientIDConfirm); 185 } 186 187 188 inline status_t 189 ReplyInterpreter::Verify() 190 { 191 return _OperationError(OpVerify); 192 } 193 194 195 #endif // REPLYINTERPRETER_H 196 197