-
Notifications
You must be signed in to change notification settings - Fork 1
/
mininfs_server.cpp
132 lines (106 loc) · 3.9 KB
/
mininfs_server.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// miniNFS
// for Json::value
#include <json/json.h>
#include <json/reader.h>
#include <json/writer.h>
#include <json/value.h>
#include <string>
// for JsonRPCCPP
#include <iostream>
#include "mininfs_server.h"
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <stdio.h>
// ecs251
#include "Core.h"
#include "Directory.h"
#include "Shadow_Directory.h"
#include <time.h>
using namespace jsonrpc;
using namespace std;
class Mymininfs_Server : public mininfs_Server
{
public:
Mymininfs_Server(AbstractServerConnector &connector, serverVersion_t type);
virtual Json::Value LookUp(const std::string& action, const std::string& arguments, const std::string& class_id, const std::string& fhandle, const std::string& filename, const std::string& host_url, const std::string& object_id, const std::string& owner_vsID);
virtual Json::Value Create(const std::string& action, const std::string& arguments, const std::string& class_id, const std::string& created_class_id, const std::string& fhandle, const std::string& filename, const std::string& host_url, const std::string& object_id, const std::string& owner_vsID, const std::string& sattr);
virtual Json::Value dumpJ(const std::string& action, const std::string& arguments, const std::string& class_id, const std::string& host_url, const std::string& object_id, const std::string& owner_vsID);
};
Mymininfs_Server::Mymininfs_Server(AbstractServerConnector &connector, serverVersion_t type)
: mininfs_Server(connector, type)
{
std::cout << "Mymininfs_Server Object created" << std::endl;
}
Directory *mounted;
// member function
Json::Value
Mymininfs_Server::LookUp(const std::string& action, const std::string& arguments, const std::string& class_id, const std::string& fhandle, const std::string& filename, const std::string& host_url, const std::string& object_id, const std::string& owner_vsID)
{
Json::Value result;
std::cout << action << " " << arguments << " " << owner_vsID << std::endl;
std::cout << "SFelixWu receiving LookUp" << std::endl;
if (fhandle != "00000002") // inode 2 is the root
{
result["status"] = "NFSERR_STALE";
}
else
{
result = mounted->LookUp(fhandle, filename);
}
return result;
}
Json::Value
Mymininfs_Server::Create(const std::string& action, const std::string& arguments, const std::string& class_id, const std::string& created_class_id, const std::string& fhandle, const std::string& filename, const std::string& host_url, const std::string& object_id, const std::string& owner_vsID, const std::string& sattr)
{
Json::Value result;
std::cout << action << " " << arguments << " " << owner_vsID << std::endl;
std::cout << "SFelixWu receiving Create" << std::endl;
if (fhandle != "00000002")
{
result["status"] = "NFSERR_STALE";
}
else
{
result = mounted->Create(fhandle, filename, sattr);
}
return result;
}
Json::Value
Mymininfs_Server::dumpJ(const std::string& action, const std::string& arguments, const std::string& class_id, const std::string& host_url, const std::string& object_id, const std::string& owner_vsID)
{
Json::Value result;
std::cout << action << " " << arguments << " " << owner_vsID << std::endl;
std::cout << "SFelixWu receiving dumpJ" << std::endl;
if (object_id != "00000002")
{
result["status"] = "NFSERR_STALE";
}
else
{
Json::Value *myv_ptr = mounted->dumpJ();
if (myv_ptr != NULL)
{
result = *myv_ptr;
result["status"] = "NFS_OK";
}
else
{
result["status"] = "NFSERR_STALE";
}
}
return result;
}
int
main()
{
Directory NFS_root
{ "http://169.237.6.102", "1234567890", "Directory", "00000000", "root", "00000002" };
mounted = (&NFS_root);
HttpServer httpserver(8384);
Mymininfs_Server s(httpserver,
JSONRPC_SERVER_V1V2); // hybrid server (json-rpc 1.0 & 2.0)
s.StartListening();
std::cout << "Hit enter to stop the server" << endl;
getchar();
s.StopListening();
return 0;
}