Merge branch 'protocol-version' into next
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 1 Jan 2011 18:17:58 +0000 (19:17 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 1 Jan 2011 18:17:58 +0000 (19:17 +0100)
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
src/main/resources/templates/insert/sone.xml

index fa0063e..4328f02 100644 (file)
@@ -55,6 +55,9 @@ public class SoneDownloader extends AbstractService {
        /** The logger. */
        private static final Logger logger = Logging.getLogger(SoneDownloader.class);
 
+       /** The maximum protocol version. */
+       private static final int MAX_PROTOCOL_VERSION = 0;
+
        /** The core. */
        private final Core core;
 
@@ -221,6 +224,27 @@ public class SoneDownloader extends AbstractService {
                        return null;
                }
 
+               Integer protocolVersion = null;
+               String soneProtocolVersion = soneXml.getValue("protocol-version", null);
+               if (soneProtocolVersion != null) {
+                       protocolVersion = Numbers.safeParseInteger(soneProtocolVersion);
+               }
+               if (protocolVersion == null) {
+                       logger.log(Level.INFO, "No protocol version found, assuming 0.");
+                       protocolVersion = 0;
+               }
+
+               if (protocolVersion < 0) {
+                       logger.log(Level.WARNING, "Invalid protocol version: " + protocolVersion + "! Not parsing Sone.");
+                       return null;
+               }
+
+               /* check for valid versions. */
+               if (protocolVersion > MAX_PROTOCOL_VERSION) {
+                       logger.log(Level.WARNING, "Unknown protocol version: " + protocolVersion + "! Not parsing Sone.");
+                       return null;
+               }
+
                String soneTime = soneXml.getValue("time", null);
                if (soneTime == null) {
                        /* TODO - mark Sone as bad. */
index 4e8cbae..7d3c8aa 100644 (file)
@@ -2,6 +2,7 @@
 <sone>
 
        <time><% currentSone.time></time>
+       <protocol-version>0</protocol-version>
 
        <client>
                <name>Sone</name>