*/
class BaseHubSystem extends BaseFrameworkSystem {
// Exception codes
- const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x900;
- const EXCEPTION_CHUNK_ALREADY_ASSEMBLED = 0x901;
- const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED = 0x902;
- const EXCEPTION_INVALID_CONNECTION_TYPE = 0x903;
- const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED = 0x904;
+ const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x900;
+ const EXCEPTION_CHUNK_ALREADY_ASSEMBLED = 0x901;
+ const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED = 0x902;
+ const EXCEPTION_INVALID_CONNECTION_TYPE = 0x903;
+ const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED = 0x904;
+ const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4 = 0x905;
// Message status codes
const MESSAGE_STATUS_CODE_OKAY = 'OKAY';
} elseif (empty($rawData)) {
// The peer did send nothing to us which is now being ignored
return;
+ } else {
+ /*
+ * All is fine at this point. So it is okay to add the raw data to
+ * the stacker. Here it doesn't matter if the raw data is a
+ * well-formed BASE64-encoded message with start and markers. This
+ * will be checked later on.
+ */
+ $this->addRawDataToStacker($rawData);
}
-
- // Add the raw data to the stacker
- $this->addRawDataToStacker($rawData);
}
}
<?php
/**
- * A RawDataInputStream class
+ * A class for handling incoming (encoded) raw data with start and end markers.
+ * The "stream" is being verified by its length (if modulo 4 of it is always
+ * zero) and if the "stream" contains all valid characters (the BASE64
+ * "alphabet").
+ *
+ * Since the latest refacturing this class works "handler-less".
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
// Get a new instance
$streamInstance = new RawDataInputStream();
- // Set the handler instance
- $streamInstance->setHandlerInstance($handlerInstance);
-
// Return the instance
return $streamInstance;
}
* @param $data The data (string mostly) to "stream"
* @return $data The data (string mostly) to "stream"
* @todo Do we need to do something more here?
+ * @throws Base64EncodingModuloException If the data's length modulo 4 is not zero
+ * @throws Base64EncodingBadException If the data contains characters which are not in the "alphabet" of BASE64 messages.
*/
public function streamData ($data) {
// Do we have start and end marker again?
// Can it be validated?
if ((strlen($data) % 4) != 0) {
// Length modulo 4 must be zero, else it is an invalid Base64 message
- $handlerInstance->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MODULO);
- $data = false;
+ throw new Base64EncodingModuloException(array($this, $data), self::EXCEPTION_BASE64_ENCODING_NOT_MODULO_4);
} elseif (!$this->isBase64Encoded($data)) {
// Is not a valid Base64-encoded message
- $handlerInstance->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MESSAGE);
- $data = false;
+ throw new Base64EncodingBadException(array($this, $data), self::EXCEPTION_BASE64_BAD_ENCODING);
} else {
// Decode the data with BASE64-encoding
$data = base64_decode($data);