* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseIpV4ProtocolHandler extends BaseProtocolHandler {
+ /**
+ * Port number
+ */
+ private $port = 0;
+
+ // Regular expression for validating IP:port UNLs
+ const UNL_REGEX = '([a-z]{1,}):\/\/\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})';
+
/**
* Protected constructor
*
// Call parent constructor
parent::__construct($className);
}
+
+ /**
+ * Setter for port number to satify HandleableProtocol
+ *
+ * @para $port The port number
+ * @return void
+ */
+ protected final function setPort ($port) {
+ // Set new port number
+ $this->port = $port;
+ }
+
+ /**
+ * Getter for port number to satify HandleableProtocol
+ *
+ * @return $port The port number
+ */
+ public final function getPort () {
+ // Return port number
+ return $this->port;
+ }
+
+ /**
+ * Validates given 'recipient' if it is a valid UNL. This means that the UNL
+ * can be parsed by the protocol handler.
+ *
+ * @param $packageData Valid raw package data
+ * @return $isValid Whether the UNL can be validated
+ */
+ public function isValidUniversalNodeLocatorByPackageData (array $packageData) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Is 'recipient' there?
+ assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+
+ // Is the correct handler choosen?
+ assert(substr($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 0, strlen($this->getHandlerName())) != $this->getHandlerName());
+
+ // Default is from generic validation
+ $isValid = $this->isValidUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], self::UNL_REGEX);
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: PACKAGE_DATA_RECIPIENT=' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ',isValid[' . gettype($isValid) . ']=' . intval($isValid));
+
+ // If this doesn't fail, continue validating the IP:port combination
+ if ($isValid === TRUE) {
+ // Okay, the basic test is passed, so reset the variable
+ $isValid = FALSE;
+
+ // ... and validate IP:port, first "parse" the UNL
+ $unlParts = $this->parseUnl($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // Debug die
+ die(__METHOD__ . ':PACKAGE_DATA_RECIPIENT=' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ',unlParts=' . print_r($unlParts, TRUE) . PHP_EOL);
+ } // END - if
+
+ // Return result
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: isValid=' . intval($isValid) . ' - EXIT!');
+ return $isValid;
+ }
}
// [EOF]