Fix response size

This commit is contained in:
Christoph Hagen 2023-08-09 17:13:03 +02:00
parent 5ce8ec864d
commit 5fc450ee63
2 changed files with 8 additions and 7 deletions

View File

@ -73,7 +73,7 @@ private:
void processMessage(AuthenticatedMessage* message); void processMessage(AuthenticatedMessage* message);
SesameEvent verifyAndProcessReceivedMessage(AuthenticatedMessage* message); SesameEvent verifyAndProcessReceivedMessage(AuthenticatedMessage* message);
uint16_t prepareResponseBuffer(SesameEvent event, uint8_t deviceId = 0); void prepareResponseBuffer(SesameEvent event, uint8_t deviceId = 0);
void sendPreparedLocalResponse(AsyncWebServerRequest *request); void sendPreparedLocalResponse(AsyncWebServerRequest *request);
void sendPreparedServerResponse(); void sendPreparedServerResponse();
}; };

View File

@ -55,8 +55,7 @@ void SesameController::loop(uint32_t millis) {
// MARK: Local // MARK: Local
void void SesameController::handleLocalMessage(AsyncWebServerRequest *request) {
SesameController::handleLocalMessage(AsyncWebServerRequest *request) {
if (!request->hasParam(messageUrlParameter)) { if (!request->hasParam(messageUrlParameter)) {
Serial.println("Missing url parameter"); Serial.println("Missing url parameter");
prepareResponseBuffer(SesameEvent::InvalidUrlParameter); prepareResponseBuffer(SesameEvent::InvalidUrlParameter);
@ -147,19 +146,21 @@ bool allowMessageResponse(SesameEvent event) {
} }
} }
uint16_t SesameController::prepareResponseBuffer(SesameEvent event, uint8_t deviceId) { void SesameController::prepareResponseBuffer(SesameEvent event, uint8_t deviceId) {
*responseStatus = event; *responseStatus = event;
responseSize = 1;
if (!allowMessageResponse(event)) { if (!allowMessageResponse(event)) {
return 1; return;
} }
responseMessage->message.time = timeCheck.getEpochTime(); responseMessage->message.time = timeCheck.getEpochTime();
responseMessage->message.id = storage.getNextMessageCounter(deviceId); responseMessage->message.id = storage.getNextMessageCounter(deviceId);
responseMessage->message.device = deviceId; responseMessage->message.device = deviceId;
if (!authenticateMessage(responseMessage, keyConfig.localKey, keySize)) { if (!authenticateMessage(responseMessage, keyConfig.localKey, keySize)) {
*responseStatus = SesameEvent::InvalidResponseAuthentication; *responseStatus = SesameEvent::InvalidResponseAuthentication;
return 1; return;
} }
return 1 + AUTHENTICATED_MESSAGE_SIZE; responseSize += AUTHENTICATED_MESSAGE_SIZE;
} }
// MARK: Reconnecting // MARK: Reconnecting