From 9c680e8826cc775818cbbd939a3eb77f9cb34073 Mon Sep 17 00:00:00 2001 From: Rick Watson Date: Sun, 2 Jun 2019 23:15:56 +0100 Subject: [PATCH] Resolve some typos Use nullptr over NULL Fix confusing regexp Fix issue with non-compliant JWT encoding --- interface/src/forms/APSettingsForm.js | 4 +- interface/src/forms/OTASettingsForm.js | 2 +- interface/src/forms/SecuritySettingsForm.js | 2 +- interface/src/forms/UserForm.js | 4 +- interface/src/forms/WiFiSettingsForm.js | 236 ++++++++++---------- src/APSettingsService.cpp | 2 +- src/ArduinoJsonJWT.cpp | 10 +- src/AsyncArduinoJson6.h | 6 +- src/AsyncJsonWebHandler.h | 2 +- src/OTASettingsService.cpp | 2 +- src/SecurityManager.h | 6 +- 11 files changed, 137 insertions(+), 139 deletions(-) diff --git a/interface/src/forms/APSettingsForm.js b/interface/src/forms/APSettingsForm.js index 3447616..582241d 100644 --- a/interface/src/forms/APSettingsForm.js +++ b/interface/src/forms/APSettingsForm.js @@ -65,7 +65,7 @@ class APSettingsForm extends React.Component { isAPEnabled(apSettings.provision_mode) && @@ -84,57 +84,57 @@ class WiFiSettingsForm extends React.Component { return (
{ - !wifiSettingsFetched ? - -
- - - Loading... - -
- - : wifiSettings ? - - - { - selectedNetwork ? this.renderSelectedNetwork() : - - } - { - !isNetworkOpen(selectedNetwork) && - - } - - + + + Loading... + +
+ + : wifiSettings ? + + + { + selectedNetwork ? this.renderSelectedNetwork() : + + } + { + !isNetworkOpen(selectedNetwork) && + + } - + + - { - wifiSettings.static_ip_config && - - - - - - - - } + { + wifiSettings.static_ip_config && + + + + + + + + } - - - + - : + : -
- - {errorMessage} - - -
- } + + } ); } diff --git a/src/APSettingsService.cpp b/src/APSettingsService.cpp index a5f966d..98ceb58 100644 --- a/src/APSettingsService.cpp +++ b/src/APSettingsService.cpp @@ -46,7 +46,7 @@ void APSettingsService::stopAP() { Serial.println("Stopping captive portal"); _dnsServer->stop(); delete _dnsServer; - _dnsServer = NULL; + _dnsServer = nullptr; } Serial.println("Stopping software access point"); WiFi.softAPdisconnect(true); diff --git a/src/ArduinoJsonJWT.cpp b/src/ArduinoJsonJWT.cpp index 0c945dc..2a50d5d 100644 --- a/src/ArduinoJsonJWT.cpp +++ b/src/ArduinoJsonJWT.cpp @@ -69,14 +69,14 @@ void ArduinoJsonJWT::parseJWT(String jwt, JsonDocument &jsonDocument) { return; } // must have signature of correct length - int signatureDelimieterIndex = jwt.length() - JWT_SIG_SIZE - 1; - if (jwt.lastIndexOf('.') != signatureDelimieterIndex) { + int signatureDelimiterIndex = jwt.length() - JWT_SIG_SIZE - 1; + if (jwt.lastIndexOf('.') != signatureDelimiterIndex) { return; } // signature must be correct - String signature = jwt.substring(signatureDelimieterIndex + 1); - jwt = jwt.substring(0, signatureDelimieterIndex); + String signature = jwt.substring(signatureDelimiterIndex + 1); + jwt = jwt.substring(0, signatureDelimiterIndex); if (sign(jwt) != signature){ return; } @@ -115,7 +115,7 @@ String ArduinoJsonJWT::encode(const char *cstr, int inputLen) { String value = String(buffer); // remove padding and convert to URL safe form - while (value.charAt(value.length() - 1) == '='){ + while (value.length() > 0 && value.charAt(value.length() - 1) == '='){ value.remove(value.length() - 1); } value.replace('+', '-'); diff --git a/src/AsyncArduinoJson6.h b/src/AsyncArduinoJson6.h index f075d46..b95ea6c 100644 --- a/src/AsyncArduinoJson6.h +++ b/src/AsyncArduinoJson6.h @@ -109,7 +109,7 @@ public: } virtual void handleRequest(AsyncWebServerRequest *request) override final { if(_onRequest) { - if (request->_tempObject != NULL) { + if (request->_tempObject != nullptr) { DynamicJsonDocument _jsonDocument(_maxContentLength); DeserializationError err = deserializeJson(_jsonDocument, (uint8_t*)(request->_tempObject)); if (err == DeserializationError::Ok) { @@ -127,10 +127,10 @@ public: virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) override final { if (_onRequest) { _contentLength = total; - if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) { + if (total > 0 && request->_tempObject == nullptr && total < _maxContentLength) { request->_tempObject = malloc(total); } - if (request->_tempObject != NULL) { + if (request->_tempObject != nullptr) { memcpy((uint8_t*)(request->_tempObject) + index, data, len); } } diff --git a/src/AsyncJsonWebHandler.h b/src/AsyncJsonWebHandler.h index 8489f76..dde3470 100644 --- a/src/AsyncJsonWebHandler.h +++ b/src/AsyncJsonWebHandler.h @@ -31,7 +31,7 @@ class AsyncJsonWebHandler: public AsyncWebHandler { AsyncJsonWebHandler() : _method(HTTP_POST|HTTP_PUT|HTTP_PATCH), - _onRequest(NULL), + _onRequest(nullptr), _maxContentLength(ASYNC_JSON_REQUEST_DEFAULT_MAX_SIZE), _uri() {} diff --git a/src/OTASettingsService.cpp b/src/OTASettingsService.cpp index 2c9490a..f891448 100644 --- a/src/OTASettingsService.cpp +++ b/src/OTASettingsService.cpp @@ -40,7 +40,7 @@ void OTASettingsService::writeToJsonObject(JsonObject& root) { void OTASettingsService::configureArduinoOTA() { if (_arduinoOTA){ delete _arduinoOTA; - _arduinoOTA = NULL; + _arduinoOTA = nullptr; } if (_enabled) { Serial.println("Starting OTA Update Service"); diff --git a/src/SecurityManager.h b/src/SecurityManager.h index 0b35fb9..b8c514f 100644 --- a/src/SecurityManager.h +++ b/src/SecurityManager.h @@ -37,11 +37,9 @@ class Authentication { boolean _authenticated; public: Authentication(User& user): _user(new User(user)), _authenticated(true) {} - Authentication() : _user(NULL), _authenticated(false) {} + Authentication() : _user(nullptr), _authenticated(false) {} ~Authentication() { - if (_user != NULL){ - delete(_user); - } + delete(_user); } User* getUser() { return _user;