Commit 4f3c7dd8 authored by Mygod's avatar Mygod

Use proper JSON support for config files

parent 923374a2
...@@ -24,7 +24,7 @@ import java.io.IOException ...@@ -24,7 +24,7 @@ import java.io.IOException
import java.net.InetAddress import java.net.InetAddress
import java.util import java.util
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import java.util.{Locale, Timer, TimerTask} import java.util.{Timer, TimerTask}
import android.app.Service import android.app.Service
import android.content.{BroadcastReceiver, Context, Intent, IntentFilter} import android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
...@@ -39,6 +39,7 @@ import com.github.shadowsocks.database.Profile ...@@ -39,6 +39,7 @@ import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.plugin.{PluginConfiguration, PluginManager, PluginOptions} import com.github.shadowsocks.plugin.{PluginConfiguration, PluginManager, PluginOptions}
import com.github.shadowsocks.utils._ import com.github.shadowsocks.utils._
import okhttp3.{Dns, FormBody, OkHttpClient, Request} import okhttp3.{Dns, FormBody, OkHttpClient, Request}
import org.json.JSONObject
import scala.collection.mutable import scala.collection.mutable
import scala.util.Random import scala.util.Random
...@@ -313,20 +314,18 @@ trait BaseService extends Service { ...@@ -313,20 +314,18 @@ trait BaseService extends Service {
} }
protected def buildShadowsocksConfig(file: String, localPortOffset: Int = 0): String = { protected def buildShadowsocksConfig(file: String, localPortOffset: Int = 0): String = {
val builder = new StringBuilder( val config = new JSONObject()
"""{"server": "%s", "server_port": %d, "local_port": %d, "password": "%s", "method": "%s"""" config.put("server", profile.host)
.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort + localPortOffset, config.put("server_port", profile.remotePort)
profile.password, profile.method)) config.put("local_port", profile.localPort + localPortOffset)
if (profile.auth) builder.append(""", "auth": true""") config.put("password", profile.password)
config.put("method", profile.method)
if (profile.auth) config.put("auth", true)
if (pluginPath != null) { if (pluginPath != null) {
builder.append(""", "plugin": """") config.put("plugin", pluginPath)
builder.append(pluginPath) config.put("plugin_opts", plugin.toString)
builder.append("""", "plugin_opts": """") }
builder.append(plugin.toString) IOUtils.writeString(file, config.toString)
builder.append('"')
}
builder.append('}')
IOUtils.writeString(file, builder.toString)
file file
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment