xref: /haiku/src/add-ons/kernel/file_systems/nfs4/RPCReply.cpp (revision 8b72ce26511afc3cc9984174a20f6786f0f93363)
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 
9 
10 #include "RPCReply.h"
11 
12 #include <debug.h>
13 #include <util/kernel_cpp.h>
14 
15 #include "RPCDefs.h"
16 
17 
18 using namespace RPC;
19 
20 
21 Reply::Reply(void* buffer, int size)
22 	:
23 	fError(B_OK),
24 	fStream(buffer, size),
25 	fBuffer(buffer)
26 {
27 	ASSERT(buffer != NULL);
28 
29 	fXID = fStream.GetUInt();
30 	if (fStream.GetInt() != REPLY) {
31 		fError = B_BAD_VALUE;
32 		return;
33 	}
34 
35 	if (fStream.GetInt() == MSG_ACCEPTED) {
36 		fStream.GetInt();
37 		fStream.GetOpaque(NULL);
38 
39 		switch (fStream.GetInt()) {
40 			case SUCCESS:
41 				return;
42 			case PROG_UNAVAIL:
43 			case PROG_MISMATCH:
44 			case PROC_UNAVAIL:
45 				fError = B_DEVICE_NOT_FOUND;
46 				return;
47 			case GARBAGE_ARGS:
48 				fError = B_MISMATCHED_VALUES;
49 				return;
50 			case SYSTEM_ERR:
51 				fError = B_ERROR;
52 				return;
53 			default:
54 				fError = B_BAD_VALUE;
55 				return;
56 		}
57 	} else {		// MSG_DENIED
58 		if (fStream.GetInt() == RPC_MISMATCH) {
59 			fError = B_DEVICE_NOT_FOUND;
60 			return;
61 		} else {	// AUTH_ERROR
62 			fError = B_PERMISSION_DENIED;
63 			return;
64 		}
65 	}
66 }
67 
68 
69 Reply::~Reply()
70 {
71 	free(fBuffer);
72 }
73 
74