Implement SIP002
https://github.com/shadowsocks/shadowsocks-org/issues/27
This commit is contained in:
@@ -20,13 +20,13 @@
|
||||
|
||||
package com.github.shadowsocks.database
|
||||
|
||||
import java.net.URLEncoder
|
||||
import java.util.Locale
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.os.Binder
|
||||
import android.text.TextUtils
|
||||
import android.util.Base64
|
||||
import com.github.shadowsocks.plugin.PluginConfiguration
|
||||
import com.github.shadowsocks.utils.Key
|
||||
import com.j256.ormlite.field.{DataType, DatabaseField}
|
||||
|
||||
@@ -93,11 +93,19 @@ class Profile {
|
||||
def nameIsEmpty: Boolean = name == null || name.isEmpty
|
||||
def getName: String = if (nameIsEmpty) formattedAddress else name
|
||||
|
||||
override def toString: String = "ss://" + Base64.encodeToString("%s:%s@%s:%d".formatLocal(Locale.ENGLISH,
|
||||
method, password, host, remotePort).getBytes, Base64.NO_PADDING | Base64.NO_WRAP) +
|
||||
(if (TextUtils.isEmpty(name)) "" else '#' + URLEncoder.encode(name, "utf-8"))
|
||||
|
||||
def isMethodUnsafe: Boolean = "table".equalsIgnoreCase(method) || "rc4".equalsIgnoreCase(method)
|
||||
def toUri: Uri = {
|
||||
val builder = new Uri.Builder()
|
||||
.scheme("ss")
|
||||
.authority("%s@%s:%d".formatLocal(Locale.ENGLISH,
|
||||
Base64.encodeToString("%s:%s".formatLocal(Locale.ENGLISH, method, password).getBytes,
|
||||
Base64.NO_PADDING | Base64.NO_WRAP | Base64.URL_SAFE), host, remotePort))
|
||||
val configuration = new PluginConfiguration(plugin)
|
||||
if (configuration.selected.nonEmpty)
|
||||
builder.appendQueryParameter(Key.plugin, configuration.selectedOptions.toString)
|
||||
if (!nameIsEmpty) builder.fragment(name)
|
||||
builder.build()
|
||||
}
|
||||
override def toString: String = toUri.toString
|
||||
|
||||
def serialize(editor: SharedPreferences.Editor): SharedPreferences.Editor = editor
|
||||
.putString(Key.name, name)
|
||||
|
||||
Reference in New Issue
Block a user