Commit 357130cd authored by Mygod's avatar Mygod

Refine #989

parent d197ec2f
......@@ -20,6 +20,7 @@
package com.github.shadowsocks.database
import java.net.URLEncoder
import java.util.Locale
import android.os.Binder
......@@ -95,7 +96,8 @@ class Profile {
var kcpcli: String = "--crypt none --mode normal --mtu 1200 --nocomp --dscp 46 --parityshard 0"
override def toString = "ss://" + Base64.encodeToString("%s%s:%s@%s:%d".formatLocal(Locale.ENGLISH,
method, if (auth) "-auth" else "", password, host, remotePort).getBytes, Base64.NO_PADDING | Base64.NO_WRAP)
method, if (auth) "-auth" else "", password, host, remotePort).getBytes, Base64.NO_PADDING | Base64.NO_WRAP) +
'#' + URLEncoder.encode(name, "utf-8")
def isMethodUnsafe = "table".equalsIgnoreCase(method) || "rc4".equalsIgnoreCase(method)
}
......@@ -20,12 +20,14 @@
package com.github.shadowsocks.utils
import java.net.URLDecoder
import android.util.{Base64, Log}
import com.github.shadowsocks.database.Profile
object Parser {
val TAG = "ShadowParser"
private val pattern = "(?i)ss://([A-Za-z0-9+-/=_]+)(#.+)?".r
private val pattern = "(?i)ss://([A-Za-z0-9+-/=_]+)(#(.+))?".r
private val decodedPattern = "(?i)^((.+?)(-auth)??:(.*)@(.+?):(\\d+?))$".r
def findAll(data: CharSequence) = pattern.findAllMatchIn(if (data == null) "" else data).map(m => try
......@@ -38,7 +40,7 @@ object Parser {
profile.name = ss.group(5)
profile.host = profile.name
profile.remotePort = ss.group(6).toInt
if (m.group(2) != null) profile.name = m.group(2).substring(1)
if (m.group(2) != null) profile.name = URLDecoder.decode(m.group(3), "utf-8")
profile
case _ => null
}
......
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