-
Notifications
You must be signed in to change notification settings - Fork 0
/
ue.cc
100 lines (84 loc) · 2.31 KB
/
ue.cc
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
#include "nexran.h"
namespace nexran {
std::map<std::string,JsonTypeMap> Ue::propertyTypes = {
{ "imsi",JsonTypeMap::STRING },
{ "tmsi",JsonTypeMap::STRING },
{ "crnti",JsonTypeMap::STRING },
{ "status",JsonTypeMap::OBJECT }
};
std::map<std::string,std::list<std::string>> Ue::propertyEnums;
std::map<HttpMethod,std::list<std::string>> Ue::required = {
{ HttpMethod::POST,{ "imsi" } }
};
std::map<HttpMethod,std::list<std::string>> Ue::optional = {
{ HttpMethod::POST,{ "tmsi" } }
};
std::map<HttpMethod,std::list<std::string>> Ue::disallowed = {
{ HttpMethod::POST,{ "crnti","status" } },
{ HttpMethod::PUT,{ "crnti","status" } }
};
void Ue::serialize(rapidjson::Writer<rapidjson::StringBuffer>& writer)
{
writer.StartObject();
writer.String("imsi");
writer.String(imsi.c_str());
writer.String("tmsi");
writer.String(tmsi.c_str());
writer.String("crnti");
writer.String(crnti.c_str());
writer.String("status");
writer.StartObject();
writer.String("connected");
writer.Bool(connected);
writer.EndObject();
writer.EndObject();
};
Ue *Ue::create(rapidjson::Document& d,AppError **ae)
{
if (!d.IsObject()) {
if (ae) {
if (!*ae)
*ae = new AppError(400);
(*ae)->add(std::string("request is not an object"));
}
return NULL;
}
const rapidjson::Value& obj = d.GetObject();
if (!Ue::validate_json(HttpMethod::POST,obj,ae))
return NULL;
Ue *ue;
if (obj.HasMember("tmsi"))
ue = new Ue(std::string(obj["imsi"].GetString()),
std::string(obj["tmsi"].GetString()),
std::string());
else
ue = new Ue(std::string(obj["imsi"].GetString()));
return ue;
}
bool Ue::update(rapidjson::Document& d,AppError **ae)
{
if (!d.IsObject()) {
if (ae) {
if (!*ae)
*ae = new AppError(400);
(*ae)->add(std::string("request is not an object"));
}
return NULL;
}
const rapidjson::Value& obj = d.GetObject();
if (!Ue::validate_json(HttpMethod::PUT,obj,ae))
return false;
if (obj.HasMember("imsi")
&& strcmp(imsi.c_str(),obj["imsi"].GetString()) != 0) {
if (ae) {
if (!*ae)
*ae = new AppError(403);
(*ae)->add(std::string("cannot modify immutable property: imsi"));
return false;
}
}
if (obj.HasMember("tmsi"))
tmsi = std::string(obj["tmsi"].GetString());
return true;
}
}