diff --git a/src/Socialbox/Classes/StandardMethods/GetSessionState.php b/src/Socialbox/Classes/StandardMethods/GetSessionState.php new file mode 100644 index 0000000..ebe20f1 --- /dev/null +++ b/src/Socialbox/Classes/StandardMethods/GetSessionState.php @@ -0,0 +1,20 @@ +headers = $headers; $this->requestBody = $requestBody; - $this->clientName = $headers[StandardHeaders::CLIENT_NAME->value]; - $this->clientVersion = $headers[StandardHeaders::CLIENT_VERSION->value]; + $this->clientName = $headers[StandardHeaders::CLIENT_NAME->value] ?? null; + $this->clientVersion = $headers[StandardHeaders::CLIENT_VERSION->value] ?? null; $this->requestType = RequestType::from($headers[StandardHeaders::REQUEST_TYPE->value]); $this->identifyAs = $headers[StandardHeaders::IDENTIFY_AS->value] ?? null; $this->sessionUuid = $headers[StandardHeaders::SESSION_UUID->value] ?? null; diff --git a/src/Socialbox/Socialbox.php b/src/Socialbox/Socialbox.php index f0ba517..b9c2553 100644 --- a/src/Socialbox/Socialbox.php +++ b/src/Socialbox/Socialbox.php @@ -43,20 +43,6 @@ return; } - if(!isset($requestHeaders[StandardHeaders::CLIENT_NAME->value])) - { - http_response_code(400); - print('Missing required header: ' . StandardHeaders::CLIENT_NAME->value); - return; - } - - if(!isset($requestHeaders[StandardHeaders::CLIENT_VERSION->value])) - { - http_response_code(400); - print('Missing required header: ' . StandardHeaders::CLIENT_VERSION->value); - return; - } - $clientRequest = new ClientRequest($requestHeaders, file_get_contents('php://input') ?? null); // Handle the request type, only `init` and `dhe` are not encrypted using the session's encrypted key @@ -94,6 +80,21 @@ */ private static function handleInitiateSession(ClientRequest $clientRequest): void { + + if(!isset($requestHeaders[StandardHeaders::CLIENT_NAME->value])) + { + http_response_code(400); + print('Missing required header: ' . StandardHeaders::CLIENT_NAME->value); + return; + } + + if(!isset($requestHeaders[StandardHeaders::CLIENT_VERSION->value])) + { + http_response_code(400); + print('Missing required header: ' . StandardHeaders::CLIENT_VERSION->value); + return; + } + if(!$clientRequest->headerExists(StandardHeaders::PUBLIC_KEY)) { http_response_code(400); @@ -148,6 +149,7 @@ } // Create the session UUID + // TODO: Save client name and version to the database $sessionUuid = SessionManager::createSession($clientRequest->getHeader(StandardHeaders::PUBLIC_KEY), $registeredPeer); http_response_code(201); // Created print($sessionUuid); // Return the session UUID @@ -265,6 +267,15 @@ */ private static function handleRpc(ClientRequest $clientRequest): void { + if(!$clientRequest->headerExists(StandardHeaders::SESSION_UUID)) + { + Logger::getLogger()->verbose('Missing required header: ' . StandardHeaders::SESSION_UUID->value); + + http_response_code(412); + print('Missing required header: ' . StandardHeaders::SESSION_UUID->value); + return; + } + try { $clientRequests = $clientRequest->getRpcRequests();