forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthorize.cpp
More file actions
122 lines (97 loc) · 3.48 KB
/
Authorize.cpp
File metadata and controls
122 lines (97 loc) · 3.48 KB
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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Operations/Authorize.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Model/Authorization/AuthorizationService.h>
#include <MicroOcpp/Debug.h>
using namespace MicroOcpp;
namespace MicroOcpp {
namespace Ocpp16 {
Authorize::Authorize(Model& model, const char *idTagIn) : MemoryManaged("v16.Operation.", "Authorize"), model(model) {
if (idTagIn && strnlen(idTagIn, IDTAG_LEN_MAX + 2) <= IDTAG_LEN_MAX) {
snprintf(idTag, IDTAG_LEN_MAX + 1, "%s", idTagIn);
} else {
MO_DBG_WARN("Format violation of idTag. Discard idTag");
}
}
const char* Authorize::getOperationType(){
return "Authorize";
}
std::unique_ptr<JsonDoc> Authorize::createReq() {
auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(1) + (IDTAG_LEN_MAX + 1));
JsonObject payload = doc->to<JsonObject>();
payload["idTag"] = idTag;
return doc;
}
void Authorize::processConf(JsonObject payload){
const char *idTagInfo = payload["idTagInfo"]["status"] | "not specified";
if (!strcmp(idTagInfo, "Accepted")) {
MO_DBG_INFO("Request has been accepted");
} else {
MO_DBG_INFO("Request has been denied. Reason: %s", idTagInfo);
}
#if MO_ENABLE_LOCAL_AUTH
if (auto authService = model.getAuthorizationService()) {
authService->notifyAuthorization(idTag, payload["idTagInfo"]);
}
#endif //MO_ENABLE_LOCAL_AUTH
}
void Authorize::processReq(JsonObject payload){
/*
* Ignore Contents of this Req-message, because this is for debug purposes only
*/
}
std::unique_ptr<JsonDoc> Authorize::createConf(){
auto doc = makeJsonDoc(getMemoryTag(), 2 * JSON_OBJECT_SIZE(1));
JsonObject payload = doc->to<JsonObject>();
JsonObject idTagInfo = payload.createNestedObject("idTagInfo");
idTagInfo["status"] = "Accepted";
return doc;
}
} // namespace Ocpp16
} // namespace MicroOcpp
#if MO_ENABLE_V201
namespace MicroOcpp {
namespace Ocpp201 {
Authorize::Authorize(Model& model, const IdToken& idToken) : MemoryManaged("v201.Operation.Authorize"), model(model) {
this->idToken = idToken;
}
const char* Authorize::getOperationType(){
return "Authorize";
}
std::unique_ptr<JsonDoc> Authorize::createReq() {
auto doc = makeJsonDoc(getMemoryTag(),
JSON_OBJECT_SIZE(1) +
JSON_OBJECT_SIZE(2));
JsonObject payload = doc->to<JsonObject>();
payload["idToken"]["idToken"] = idToken.get();
payload["idToken"]["type"] = idToken.getTypeCstr();
return doc;
}
void Authorize::processConf(JsonObject payload){
const char *idTagInfo = payload["idTokenInfo"]["status"] | "_Undefined";
if (!strcmp(idTagInfo, "Accepted")) {
MO_DBG_INFO("Request has been accepted");
} else {
MO_DBG_INFO("Request has been denied. Reason: %s", idTagInfo);
}
//if (model.getAuthorizationService()) {
// model.getAuthorizationService()->notifyAuthorization(idTag, payload["idTagInfo"]);
//}
}
void Authorize::processReq(JsonObject payload){
/*
* Ignore Contents of this Req-message, because this is for debug purposes only
*/
}
std::unique_ptr<JsonDoc> Authorize::createConf(){
auto doc = makeJsonDoc(getMemoryTag(), 2 * JSON_OBJECT_SIZE(1));
JsonObject payload = doc->to<JsonObject>();
JsonObject idTagInfo = payload.createNestedObject("idTokenInfo");
idTagInfo["status"] = "Accepted";
return doc;
}
} // namespace Ocpp201
} // namespace MicroOcpp
#endif //MO_ENABLE_V201