From 54184f28893c4ea584a9c31808481c94e655b381 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Mon, 19 Nov 2018 14:48:21 +0000
Subject: [PATCH] Util: Switch users of net.minidev.json to com.json.simple
 Tested with bundled 1.1.1 and Debian/Ubuntu 2.3.0

---
 .../src/com/vuze/plugins/mlab/MLabRunner.java   | 11 ++++++-----
 .../java/src/edu/internet2/ndt/JSONUtils.java   |  4 ++--
 core/java/src/net/i2p/util/DNSOverHTTPS.java    | 17 +++++++++--------
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java b/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java
index ba640194f3..4a42eb104e 100644
--- a/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java
+++ b/apps/routerconsole/java/src/com/vuze/plugins/mlab/MLabRunner.java
@@ -30,9 +30,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import edu.internet2.ndt.Tcpbw100;
 
-import net.minidev.json.JSONObject;
-import net.minidev.json.parser.JSONParser;
-import net.minidev.json.parser.ParseException;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
 
 import net.i2p.I2PAppContext;
 import net.i2p.data.DataHelper;
@@ -136,9 +136,10 @@ public class MLabRunner {
                             int code = eepget.getStatusCode();
                             if (code != 200)
                                 throw new IOException("ns fetch failed: " + code);
-                            JSONParser parser = new JSONParser(JSONParser.MODE_PERMISSIVE);
+                            JSONParser parser = new JSONParser();
                             byte[] b = baos.toByteArray();
-                            JSONObject map = (JSONObject) parser.parse(b);
+                            String s = new String(b, "ISO-8859-1");
+                            JSONObject map = (JSONObject) parser.parse(s);
                             if (map == null) {
                                 throw new IOException("no map");
                             }
diff --git a/apps/routerconsole/java/src/edu/internet2/ndt/JSONUtils.java b/apps/routerconsole/java/src/edu/internet2/ndt/JSONUtils.java
index 401d5c81a3..de73547170 100644
--- a/apps/routerconsole/java/src/edu/internet2/ndt/JSONUtils.java
+++ b/apps/routerconsole/java/src/edu/internet2/ndt/JSONUtils.java
@@ -1,7 +1,7 @@
 package edu.internet2.ndt;
 
-import net.minidev.json.JSONObject;
-import net.minidev.json.JSONValue;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
 import java.util.Iterator;
 import java.util.Map;
 
diff --git a/core/java/src/net/i2p/util/DNSOverHTTPS.java b/core/java/src/net/i2p/util/DNSOverHTTPS.java
index c475496dd4..42761e07b5 100644
--- a/core/java/src/net/i2p/util/DNSOverHTTPS.java
+++ b/core/java/src/net/i2p/util/DNSOverHTTPS.java
@@ -12,9 +12,9 @@ import java.util.Map;
 
 import gnu.getopt.Getopt;
 
-import net.minidev.json.JSONArray;
-import net.minidev.json.JSONObject;
-import net.minidev.json.parser.JSONParser;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
 
 import net.i2p.I2PAppContext;
 import net.i2p.data.DataHelper;
@@ -98,7 +98,7 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
         _log = ctx.logManager().getLog(DNSOverHTTPS.class);
         state = sslState;
         baos = new ByteArrayOutputStream(512);
-        parser = new JSONParser(JSONParser.MODE_PERMISSIVE);
+        parser = new JSONParser();
     }
 
     public enum Type { V4_ONLY, V6_ONLY, V4_PREFERRED, V6_PREFERRED }
@@ -255,12 +255,13 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
             log("Got response in " + (end - fetchStart) + "ms");
             byte[] b = baos.toByteArray();
             try {
-                JSONObject map = (JSONObject) parser.parse(b);
+                String s = new String(b, "ISO-8859-1");
+                JSONObject map = (JSONObject) parser.parse(s);
                 if (map == null) {
                     log("No map");
                     return null;
                 }
-                Integer status = (Integer) map.get("Status");
+                Number status = (Number) map.get("Status");
                 if (status == null || status.intValue() != 0) {
                     log("Bad status: " + status);
                     return null;
@@ -280,7 +281,7 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
                             log("no data");
                             continue;
                         }
-                        Integer typ = (Integer) a.get("type");
+                        Number typ = (Number) a.get("type");
                         if (typ == null)
                             continue;
                         String name = (String) a.get("name");
@@ -314,7 +315,7 @@ public class DNSOverHTTPS implements EepGet.StatusListener {
                             log("name mismatch: " + name);
                             continue;
                         }
-                        Integer ttl = (Integer) a.get("TTL");
+                        Number ttl = (Number) a.get("TTL");
                         int ittl = (ttl != null) ? Math.min(ttl.intValue(), MAX_TTL) : 3600;
                         long expires = end + (ittl * 1000L);
                         Map<String, Result> cache = isv6 ? v6Cache : v4Cache;
-- 
GitLab