Skip to content

Commit a36e6a4

Browse files
authored
add build flag MO_ENABLE_LOCAL_AUTH (#303)
* add build flag MO_ENABLE_LOCAL_AUTH * update changelog
1 parent 8fa0258 commit a36e6a4

21 files changed

+117
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- File index ([#270](https://github.com/matth-x/MicroOcpp/pull/270))
1616
- Config `Cst_TxStartOnPowerPathClosed` to put back TxStartPoint ([#271](https://github.com/matth-x/MicroOcpp/pull/271))
1717
- Build flag `MO_ENABLE_V16_RESERVATION=0` disables Reservation module ([#302](https://github.com/matth-x/MicroOcpp/pull/302))
18+
- Build flag `MO_ENABLE_LOCAL_AUTH=0` disables LocalAuthList module ([#303](https://github.com/matth-x/MicroOcpp/pull/303))
1819
- Function `bool isConnected()` in `Connection` interface ([#282](https://github.com/matth-x/MicroOcpp/pull/282))
1920
- Build flags for customizing memory limits of SmartCharging ([#260](https://github.com/matth-x/MicroOcpp/pull/260))
2021
- SConscript ([#287](https://github.com/matth-x/MicroOcpp/pull/287))

src/MicroOcpp.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,11 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden
287287
model.setConnectors(std::move(connectors));
288288
model.setHeartbeatService(std::unique_ptr<HeartbeatService>(
289289
new HeartbeatService(*context)));
290+
291+
#if MO_ENABLE_LOCAL_AUTH
290292
model.setAuthorizationService(std::unique_ptr<AuthorizationService>(
291293
new AuthorizationService(*context, filesystem)));
294+
#endif //MO_ENABLE_LOCAL_AUTH
292295

293296
#if MO_ENABLE_V16_RESERVATION
294297
model.setReservationService(std::unique_ptr<ReservationService>(

src/MicroOcpp/Model/Authorization/AuthorizationData.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Copyright Matthias Akstaller 2019 - 2024
33
// MIT License
44

5+
#include <MicroOcpp/Version.h>
6+
7+
#if MO_ENABLE_LOCAL_AUTH
8+
59
#include <MicroOcpp/Model/Authorization/AuthorizationData.h>
610

711
using namespace MicroOcpp;
@@ -152,3 +156,5 @@ MicroOcpp::AuthorizationStatus MicroOcpp::deserializeAuthorizationStatus(const c
152156
return AuthorizationStatus::UNDEFINED;
153157
}
154158
}
159+
160+
#endif //MO_ENABLE_LOCAL_AUTH

src/MicroOcpp/Model/Authorization/AuthorizationData.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#ifndef MO_AUTHORIZATIONDATA_H
66
#define MO_AUTHORIZATIONDATA_H
77

8+
#include <MicroOcpp/Version.h>
9+
10+
#if MO_ENABLE_LOCAL_AUTH
11+
812
#include <MicroOcpp/Operations/CiStrings.h>
913
#include <MicroOcpp/Core/Time.h>
1014
#include <ArduinoJson.h>
@@ -64,4 +68,5 @@ class AuthorizationData {
6468

6569
}
6670

71+
#endif //MO_ENABLE_LOCAL_AUTH
6772
#endif

src/MicroOcpp/Model/Authorization/AuthorizationList.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Copyright Matthias Akstaller 2019 - 2024
33
// MIT License
44

5+
#include <MicroOcpp/Version.h>
6+
7+
#if MO_ENABLE_LOCAL_AUTH
8+
59
#include <MicroOcpp/Model/Authorization/AuthorizationList.h>
610
#include <MicroOcpp/Debug.h>
711

@@ -194,3 +198,5 @@ void AuthorizationList::writeJson(JsonArray authListOut, bool compact) {
194198
size_t AuthorizationList::size() {
195199
return localAuthorizationList.size();
196200
}
201+
202+
#endif //MO_ENABLE_LOCAL_AUTH

src/MicroOcpp/Model/Authorization/AuthorizationList.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#ifndef MO_AUTHORIZATIONLIST_H
66
#define MO_AUTHORIZATIONLIST_H
77

8+
#include <MicroOcpp/Version.h>
9+
10+
#if MO_ENABLE_LOCAL_AUTH
11+
812
#include <MicroOcpp/Model/Authorization/AuthorizationData.h>
913
#include <vector>
1014

@@ -41,4 +45,5 @@ class AuthorizationList {
4145

4246
}
4347

48+
#endif //MO_ENABLE_LOCAL_AUTH
4449
#endif

src/MicroOcpp/Model/Authorization/AuthorizationService.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Copyright Matthias Akstaller 2019 - 2024
33
// MIT License
44

5+
#include <MicroOcpp/Version.h>
6+
7+
#if MO_ENABLE_LOCAL_AUTH
8+
59
#include <MicroOcpp/Model/Authorization/AuthorizationService.h>
610
#include <MicroOcpp/Model/ConnectorBase/Connector.h>
711
#include <MicroOcpp/Core/FilesystemUtils.h>
@@ -192,3 +196,5 @@ void AuthorizationService::notifyAuthorization(const char *idTag, JsonObject idT
192196
context.initiateRequest(std::move(statusNotification));
193197
}
194198
}
199+
200+
#endif //MO_ENABLE_LOCAL_AUTH

src/MicroOcpp/Model/Authorization/AuthorizationService.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#ifndef MO_AUTHORIZATIONSERVICE_H
66
#define MO_AUTHORIZATIONSERVICE_H
77

8+
#include <MicroOcpp/Version.h>
9+
10+
#if MO_ENABLE_LOCAL_AUTH
11+
812
#include <MicroOcpp/Model/Authorization/AuthorizationList.h>
913
#include <MicroOcpp/Core/FilesystemAdapter.h>
1014
#include <MicroOcpp/Core/Configuration.h>
@@ -39,4 +43,5 @@ class AuthorizationService {
3943

4044
}
4145

46+
#endif //MO_ENABLE_LOCAL_AUTH
4247
#endif

src/MicroOcpp/Model/ConnectorBase/Connector.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -591,12 +591,14 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
591591

592592
MO_DBG_DEBUG("Begin transaction process (%s), prepare", idTag != nullptr ? idTag : "");
593593

594-
AuthorizationData *localAuth = nullptr;
594+
bool localAuthFound = false;
595+
const char *parentIdTag = nullptr; //locally stored parentIdTag
595596
bool offlineBlockedAuth = false; //if offline authorization will be blocked by local auth list entry
596597

597598
//check local OCPP whitelist
598-
if (model.getAuthorizationService()) {
599-
localAuth = model.getAuthorizationService()->getLocalAuthorization(idTag);
599+
#if MO_ENABLE_LOCAL_AUTH
600+
if (auto authService = model.getAuthorizationService()) {
601+
auto localAuth = authService->getLocalAuthorization(idTag);
600602

601603
//check authorization status
602604
if (localAuth && localAuth->getAuthorizationStatus() != AuthorizationStatus::Accepted) {
@@ -611,21 +613,26 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
611613
offlineBlockedAuth = true;
612614
localAuth = nullptr;
613615
}
616+
617+
if (localAuth) {
618+
localAuthFound = true;
619+
parentIdTag = localAuth->getParentIdTag();
620+
}
614621
}
622+
#endif //MO_ENABLE_LOCAL_AUTH
615623

616624
int reservationId = -1;
617625
bool offlineBlockedResv = false; //if offline authorization will be blocked by reservation
618626

619-
#if MO_ENABLE_V16_RESERVATION
620627
//check if blocked by reservation
628+
#if MO_ENABLE_V16_RESERVATION
621629
if (model.getReservationService()) {
622-
const char *parentIdTag = localAuth ? localAuth->getParentIdTag() : nullptr;
623630

624631
auto reservation = model.getReservationService()->getReservation(
625632
connectorId,
626633
idTag,
627634
parentIdTag);
628-
635+
629636
if (reservation) {
630637
reservationId = reservation->getReservationId();
631638
}
@@ -645,12 +652,14 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
645652
} else {
646653
//parentIdTag unkown but local authorization failed in any case
647654
MO_DBG_INFO("connector %u reserved - no local auth", connectorId);
648-
localAuth = nullptr;
655+
localAuthFound = false;
649656
}
650657
}
651658
}
659+
#else
660+
(void)parentIdTag;
652661
#endif //MO_ENABLE_V16_RESERVATION
653-
662+
654663
transaction = allocateTransaction();
655664

656665
if (!transaction) {
@@ -668,7 +677,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
668677
transaction->setBeginTimestamp(model.getClock().now());
669678

670679
//check for local preauthorization
671-
if (localAuth && localPreAuthorizeBool && localPreAuthorizeBool->getBool()) {
680+
if (localAuthFound && localPreAuthorizeBool && localPreAuthorizeBool->getBool()) {
672681
MO_DBG_DEBUG("Begin transaction process (%s), preauthorized locally", idTag != nullptr ? idTag : "");
673682

674683
if (reservationId >= 0) {
@@ -735,7 +744,6 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
735744
});
736745

737746
//capture local auth and reservation check in for timeout handler
738-
bool localAuthFound = localAuth;
739747
authorize->setOnTimeoutListener([this, tx,
740748
offlineBlockedAuth,
741749
offlineBlockedResv,

src/MicroOcpp/Model/Model.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ void Model::setHeartbeatService(std::unique_ptr<HeartbeatService> hs) {
164164
capabilitiesUpdated = true;
165165
}
166166

167+
#if MO_ENABLE_LOCAL_AUTH
167168
void Model::setAuthorizationService(std::unique_ptr<AuthorizationService> as) {
168169
authorizationService = std::move(as);
169170
capabilitiesUpdated = true;
@@ -172,6 +173,7 @@ void Model::setAuthorizationService(std::unique_ptr<AuthorizationService> as) {
172173
AuthorizationService *Model::getAuthorizationService() {
173174
return authorizationService.get();
174175
}
176+
#endif //MO_ENABLE_LOCAL_AUTH
175177

176178
#if MO_ENABLE_V16_RESERVATION
177179
void Model::setReservationService(std::unique_ptr<ReservationService> rs) {
@@ -283,12 +285,14 @@ void Model::updateSupportedStandardProfiles() {
283285
}
284286
}
285287

288+
#if MO_ENABLE_LOCAL_AUTH
286289
if (authorizationService) {
287290
if (!strstr(supportedFeatureProfilesString->getString(), "LocalAuthListManagement")) {
288291
if (!buf.empty()) buf += ',';
289292
buf += "LocalAuthListManagement";
290293
}
291294
}
295+
#endif //MO_ENABLE_LOCAL_AUTH
292296

293297
#if MO_ENABLE_V16_RESERVATION
294298
if (reservationService) {

0 commit comments

Comments
 (0)