// CFG: RAW-DATA-STACKER-CLASS
$cfg->setConfigEntry('raw_data_stacker_class', 'FiLoStacker');
+// CFG: MULTIPLE-MESSAGE-STACKER-CLASS
+$cfg->setConfigEntry('multiple_message_stacker_class', 'FiFoStacker');
+
// CFG: NODE-ANNOUNCEMENT-ANSWER-TEMPLATE-TYPE
$cfg->setConfigEntry('node_announcement_answer_template_type', 'xml/answer/announcement');
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * This exception is thrown when multiple messages are found in in-buffer.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class MultipleMessageSentException extends FrameworkException {
+ /**
+ * The super constructor for all exceptions
+ *
+ * @param $streamInstance An instance of a InputStreamable class
+ * @param $data The actual data
+ * @return void
+ */
+ public function __construct (InputStreamable $streamInstance, $data) {
+ // Construct the message
+ $message = sprintf('[%s:%d] Cannot handle multiple messages. Please split them before calling this method.',
+ $streamInstance->__toString(),
+ $this->getLine()
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0x906;
const EXCEPTION_REQUEST_NOT_ACCEPTED = 0x907;
const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED = 0x908;
+ const EXCEPTION_MULTIPLE_MESSAGE_SENT = 0x909;
// Message status codes
const MESSAGE_STATUS_CODE_OKAY = 'OKAY';
// Set handler instance
$assemblerInstance->setHandlerInstance($handlerInstance);
+ // Get stacker instance
+ $stackerInstance = ObjectFactory::createObjectByConfiguredName('multiple_message_stacker_class');
+
+ // And add it
+ $assemblerInstance->setStackerInstance($stackerInstance);
+
// Return the prepared instance
return $assemblerInstance;
}
// This will cause an assertition in next call, so simply wait for more data
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ': Pending data of ' . strlen($this->pendingData) . ' Bytes are incomplete, waiting for more ...');
return;
- } // END - if
+ } elseif (substr_count($this->pendingData, BaseRawDataHandler::STREAM_START_MARKER) > 1) {
+ /*
+ * Multiple messages found, so split off first message as the input
+ * stream can only handle one message per time.
+ */
+ }
// Init fake array
$packageContent = array(
* @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.
+ * @throws MultipleMessageSentException If the sender has sent two messages and both end up here
*/
public function streamData ($data) {
// Debug message
// Do we have start and end marker again?
assert($this->ifStartEndMarkersSet($data));
+ // Count of start and end markers must be the same
+ assert(substr_count($data, BaseRawDataHandler::STREAM_START_MARKER) == substr_count($data, BaseRawDataHandler::STREAM_END_MARKER));
+
+ // Check if more than two start markers exist and if so, split it.
+ if (substr_count($data, BaseRawDataHandler::STREAM_START_MARKER) > 1) {
+ // Please do it outside this method
+ throw new MultipleMessageSentException(array($this, $data), BaseHubSystem::EXCEPTION_MULTIPLE_MESSAGE_SENT);
+ } // END - if
+
// Remove both
$data = substr($data, strlen(BaseRawDataHandler::STREAM_START_MARKER), -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER));