--- /dev/null
+<?php
+/**
+ * An DhtBootstrapAnswer template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Some XML nodes must be available for later data extraction
+ */
+ const DHT_BOOTSTRAP_DATA_SESSION_ID = 'my-session-id';
+ const DHT_BOOTSTRAP_DATA_NODE_STATUS = 'my-status';
+ const DHT_BOOTSTRAP_DATA_EXTERNAL_IP = 'my-external-ip';
+ const DHT_BOOTSTRAP_DATA_INTERNAL_IP = 'my-internal-ip';
+ const DHT_BOOTSTRAP_DATA_LISTEN_PORT = 'my-listen-port';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init sub-nodes array
+ $this->subNodes = array(
+ // These nodes don't contain any data
+ 'my-data',
+ 'your-data',
+ // Data from *this* node
+ self::DHT_BOOTSTRAP_DATA_EXTERNAL_IP,
+ self::DHT_BOOTSTRAP_DATA_INTERNAL_IP,
+ self::DHT_BOOTSTRAP_DATA_LISTEN_PORT,
+ self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
+ self::DHT_BOOTSTRAP_DATA_SESSION_ID,
+ // Data from other node
+ 'your-external-ip',
+ 'your-internal-ip',
+ 'your-session-id',
+ // Answer status (generic field)
+ self::ANSWER_STATUS,
+ );
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlDhtBootstrapAnswerTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlDhtBootstrapAnswerTemplateEngine();
+
+ // Init instance
+ $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap_answer');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ * @todo Find something useful with this!
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ /*
+ * Assign the found characters to variable and use the last entry from
+ * stack as the name.
+ */
+ parent::assignVariable($this->getStackerInstance()->getNamed('node_dht_bootstrap_answer'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getDhtBootstrapAnswerCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the dht_bootstrap-answer
+ *
+ * @return void
+ */
+ protected function startDhtBootstrapAnswer () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'dht_bootstrap-answer');
+ }
+
+ /**
+ * Starts the my-data
+ *
+ * @return void
+ */
+ protected function startMyData () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'my-data');
+ }
+
+ /**
+ * Starts the my-external-ip
+ *
+ * @return void
+ */
+ protected function startMyExternalIp () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_EXTERNAL_IP);
+ }
+
+ /**
+ * Starts the my-internal-ip
+ *
+ * @return void
+ */
+ protected function startMyInternalIp () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_INTERNAL_IP);
+ }
+
+ /**
+ * Starts the my-tcp-port
+ *
+ * @return void
+ */
+ protected function startMyListenPort () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_LISTEN_PORT);
+ }
+
+ /**
+ * Starts the my-session-id
+ *
+ * @return void
+ */
+ protected function startMySessionId () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
+ }
+
+ /**
+ * Starts the my-status
+ *
+ * @return void
+ */
+ protected function startMyStatus () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
+ }
+
+ /**
+ * Finishes the my-status
+ *
+ * @return void
+ */
+ protected function finishMyStatus () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-session-id
+ *
+ * @return void
+ */
+ protected function finishMySessionId () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-tcp-port
+ *
+ * @return void
+ */
+ protected function finishMyListenPort () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-internal-ip
+ *
+ * @return void
+ */
+ protected function finishMyInternalIp () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-external-ip
+ *
+ * @return void
+ */
+ protected function finishMyExternalIp () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-data
+ *
+ * @return void
+ */
+ protected function finishMyData () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Starts the your-data
+ *
+ * @return void
+ */
+ protected function startYourData () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'your-data');
+ }
+
+ /**
+ * Starts the your-external-ip
+ *
+ * @return void
+ */
+ protected function startYourExternalIp () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'your-external-ip');
+ }
+
+ /**
+ * Starts the your-internal-ip
+ *
+ * @return void
+ */
+ protected function startYourInternalIp () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'your-internal-ip');
+ }
+
+ /**
+ * Starts the your-session-id
+ *
+ * @return void
+ */
+ protected function startYourSessionId () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'your-session-id');
+ }
+
+ /**
+ * Finishes the your-session-id
+ *
+ * @return void
+ */
+ protected function finishYourSessionId () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the your-internal-ip
+ *
+ * @return void
+ */
+ protected function finishYourInternalIp () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the your-external-ip
+ *
+ * @return void
+ */
+ protected function finishYourExternalIp () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the your-data
+ *
+ * @return void
+ */
+ protected function finishYourData () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the dht_bootstrap-answer
+ *
+ * @return void
+ */
+ protected function finishDhtBootstrapAnswer () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+An XML template for answering DHT bootstrap requests from other nodes. This
+template may be used to indicate that this node does not want to receive
+DHT bootstrap requests.
+
+@author Roland Haeder <webmaster@ship-simu.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.ship-simu.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/>
+//-->
+<dht-bootstrap-answer>
+ <!--
+ The following data is from this node.
+ //-->
+ <my-data>
+ <!--
+ This node's external IP/hostname
+ //-->
+ <my-external-ip>{?my_external_ip?}</my-external-ip>
+ <!--
+ This node's internal IP/hostname
+ //-->
+ <my-internal-ip>{?my_internal_ip?}</my-internal-ip>
+ <!--
+ This node's TCP/UDP listen port
+ //-->
+ <my-listen-port>{?my_listen_port?}</my-listen-port>
+ <!--
+ This node's session id
+ //-->
+ <my-session-id>{?my_session_id?}</my-session-id>
+ <!--
+ This node's status
+ //-->
+ <my-status>{?my_status?}</my-status>
+ </my-data>
+ <!--
+ The following data is the other node's data. This data is being sent to
+ confirm that it has been received correctly.
+ //-->
+ <your-data>
+ <!--
+ Other node's external IP/hostname
+ //-->
+ <your-external-ip>{?your_external_ip?}</your-external-ip>
+ <!--
+ Other node's internal IP/hostname
+ //-->
+ <your-internal-ip>{?your_internal_ip?}</your-internal-ip>
+ <!--
+ Other node's session id
+ //-->
+ <your-session-id>{?your_session_id?}</your-session-id>
+ </your-data>
+ <!--
+ Status of this answer. This can be something like OKAY if all went fine or
+ any other error code.
+ //-->
+ <answer-status>{?answer_status?}</answer-status>
+ <!--
+ Initial DHT data, this will be other nodes that have the DHT active.
+ //-->
+ <dht-nodes-list>
+ <!--
+ The actual DHT data.
+ //-->
+ {?dht_nodes?}
+ </dht-nodes-list>
+</dht-bootstrap-answer>