From b0a30339d24caa4644b6b506cc91b631c35c5e56 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 4 Aug 2012 23:08:16 +0000 Subject: [PATCH] Added start ([[S]]) and end ([[E]]) marker for BASE64 stream --- .../helper/connection/class_BaseConnectionHelper.php | 5 ++++- .../streams/raw_data/input/class_RawDataInputStream.php | 3 +++ .../raw_data/output/class_RawDataOutputStream.php | 9 +++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index c9f1596ae..d2573681c 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -423,12 +423,15 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc // Deliver all data while ($sentBytes !== false) { // And deliver it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Sending out ' . strlen($encodedData) . ' bytes,MD5=' . md5($encodedData) . ',bufferSize=' . $bufferSize . ',diff=' . $this->diff); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Sending out ' . strlen($encodedData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff); + if ($this->diff >= 0) { // Send all out (encodedData is smaller than or equal buffer size) + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: MD5=' . md5(substr($encodedData, 0, ($bufferSize - $this->diff)))); $sentBytes = socket_write($socketResource, $encodedData, ($bufferSize - $this->diff)); } else { // Send buffer size out + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: MD5=' . md5(substr($encodedData, 0, $bufferSize))); $sentBytes = socket_write($socketResource, $encodedData, $bufferSize); } diff --git a/application/hub/main/streams/raw_data/input/class_RawDataInputStream.php b/application/hub/main/streams/raw_data/input/class_RawDataInputStream.php index 17fd75410..6fc9e077c 100644 --- a/application/hub/main/streams/raw_data/input/class_RawDataInputStream.php +++ b/application/hub/main/streams/raw_data/input/class_RawDataInputStream.php @@ -57,6 +57,9 @@ class RawDataInputStream extends BaseStream implements InputStreamable { * @todo Do we need to do something more here? */ public function streamData ($data) { + // Do we have start and end marker again? + assert((substr($data, 0, 5) == '[[S]]') && (substr($data, -5, 5) == '[[E]]')); + // Can it be validated? if ((strlen($data) % 4) != 0) { // Length modulo 4 must be zero, else it is an invalid Base64 message diff --git a/application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php b/application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php index f9c61f455..32fb286ba 100644 --- a/application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php +++ b/application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php @@ -53,8 +53,13 @@ class RawDataOutputStream extends BaseStream implements OutputStreamable { * @todo Do we need to do something more here? */ public function streamData ($data) { - // Encode the data with BASE64 encoding - $data = base64_encode($data); + /* + * Encode the data with BASE64 encoding and put it in a "frame": + * + * [[S]] - Start marker + * [[E]] - End marker + */ + $data = '[[S]]' . base64_encode($data) . '[[E]]'; // Return it return $data; -- 2.39.5