*/
const STACKER_NAME_DECODED_CHUNKED = 'package_chunked_decoded';
+ /**
+ * Stacker name for decompressed XML
+ */
+ const STACKER_NAME_PACKAGE_DECOMPRESSED_XML = 'package_decompressed_xml';
+
/**************************************************************************
* Stacker for incoming messages *
**************************************************************************/
self::STACKER_NAME_DECODED_INCOMING,
self::STACKER_NAME_DECODED_HANDLED,
self::STACKER_NAME_DECODED_CHUNKED,
- self::STACKER_NAME_NEW_MESSAGE,
+ self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML,
self::STACKER_NAME_PROCESSED_MESSAGE,
self::STACKER_NAME_OUTGOING_STREAM
), $forceReInit);
* @param $packageInstance An instance of a DeliverablePackage class
* @return void
* @throws InvalidArgumentException If the package content does not have expected amount of entries
- * @throws InvalidDataChecksumException If the checksum doesn't match
*/
public function handleReceivedPackageInstance (DeliverablePackage $packageInstance) {
// Is the package content set?
// Checksum of the _decoded_ data
$packageInstance->setContentChecksum($decodedContent[self::INDEX_CHECKSUM]);
- // Is the checksum valid?
- if (!$this->isChecksumValid($packageInstance)) {
- // Is not the same, so throw an exception here
- throw new InvalidDataChecksumException(array($this, $packageInstance), self::EXCEPTION_INVALID_DATA_CHECKSUM);
- }
-
- /*
- * The checksum is the same, then it can be decompressed safely. The
- * original message is at this point fully decoded.
- */
+ // Decompress raw XML stream
$packageInstance->setRawXml($this->getCompressorInstance()->decompressStream($packageInstance->getRawXml()));
// And push it on the next stack
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_NEW_MESSAGE, $packageInstance);
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML, $packageInstance);
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
public function isNewMessageArrived () {
// Determine if the stack is not empty
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!');
- $hasArrived = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_NEW_MESSAGE));
+ $hasArrived = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML));
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: hasArrived=%d - EXIT!', intval($hasArrived)));
+ return $hasArrived;
+ }
+
+ /**
+ * Checks whether decoded package's XML is pending for parsing
+ *
+ * @return $hasArrived Whether a new package has arrived for processing
+ */
+ public function isDecodedPackageXmlPending () {
+ // Determine if the stack is not empty
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!');
+ $hasArrived = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML));
// Return it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: hasArrived=%d - EXIT!', intval($hasArrived)));
}
/**
- * Handles newly arrived messages
+ * Handles newly arrived message
*
* @return void
* @throws BadMethodCallException If no new message has arrived
}
// Get it from the stacker, it is the full array with the decoded message
- $packageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
+ $messageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
// Generate the hash of comparing it
- /* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE)));
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s,senderId=%s,senderPrivateKeyHash=%s', $packageInstance->__toString(), $packageInstance->getSenderId(), $packageInstance->getSenderPrivateKeyHash()));
- if (empty($packageInstance->getSenderId())) {
- // Invalid $packageInstance
- throw new InvalidArgumentException('packageInstance does not contain senderId');
- } elseif (empty($packageInstance->getSenderPrivateKeyHash())) {
+ /* DEBUG-DIE: */ die(sprintf('[%s:%d]: messageInstance=%s', __METHOD__, __LINE__, print_r($messageInstance, TRUE)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: messageInstance=%s,senderId=%s,senderPrivateKeyHash=%s', $messageInstance->__toString(), $messageInstance->getSenderId(), $messageInstance->getSenderPrivateKeyHash()));
+ if (empty($messageInstance->getSenderId())) {
+ // Invalid $messageInstance
+ throw new InvalidArgumentException('messageInstance does not contain senderId');
+ } elseif (empty($messageInstance->getSenderPrivateKeyHash())) {
// This needs fixing
throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), BaseHubSystem::EXCEPTION_INVALID_PRIVATE_KEY_HASH);
- } elseif (!$this->isPackageHashValid($packageInstance)) {
+ } elseif (!$this->isPackageHashValid($messageInstance)) {
// Is not valid, so throw an exception here
- exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . chr(10));
+ exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . PHP_EOL);
}
// Now get a filter chain back from factory with given tags array
- $chainInstance = PackageFilterChainFactory::createChainByTagsArray($packageInstance->getContentHash());
+ $chainInstance = PackageFilterChainFactory::createChainByTagsArray($messageInstance->getContentHash());
/*
* Process the message through all filters, note that all other
- * elements from $packageInstance are no longer needed.
+ * elements from $messageInstance are no longer needed.
*/
- $chainInstance->processMessage($packageInstance, $this);
+ $chainInstance->processMessage($messageInstance, $this);
/*
* Post-processing of message data (this won't remove the message from
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
}
+ /**
+ * Handles package's decoded XML
+ *
+ * @return void
+ * @throws BadMethodCallException If no new package has arrived
+ * @throws InvalidArgumentException If $packageInstance contains no senderId
+ * @throws InvalidPrivateKeyHashException If the private key-hash is empty
+ * @todo Implement verification of all sent tags here?
+ */
+ public function handleDecodedPackageXml () {
+ // Make sure there is at least one package
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!');
+ if (!$this->isDecodedPackageXmlPending()) {
+ // Bad method call
+ throw new BadMethodCallException('No package waiting XML parsing');
+ }
+
+ // Get it from the stacker, it is the full array with the decoded package (raw XML)
+ $packageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML);
+
+ // Generate the hash of comparing it
+ /* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s,senderId=%s,senderPrivateKeyHash=%s', $packageInstance->__toString(), $packageInstance->getSenderId(), $packageInstance->getSenderPrivateKeyHash()));
+ if (empty($packageInstance->getSenderId())) {
+ // Invalid $packageInstance
+ throw new InvalidArgumentException('packageInstance does not contain senderId');
+ } elseif (empty($packageInstance->getSenderPrivateKeyHash())) {
+ // This needs fixing
+ throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), BaseHubSystem::EXCEPTION_INVALID_PRIVATE_KEY_HASH);
+ } elseif (!$this->isPackageHashValid($packageInstance)) {
+ // Is not valid, so throw an exception here
+ exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . PHP_EOL);
+ }
+
+ // Parse package's XML into a message instance
+ /* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE)));
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
+ }
+
/**
* Checks whether a processed message is pending for "interpretation"
*