add intent filter for shadowsocks URI #51

This commit is contained in:
Max Lv
2013-12-01 14:56:15 +08:00
parent 1907ac2fef
commit 9511a616e9
10 changed files with 203 additions and 79 deletions
@@ -0,0 +1,34 @@
package com.github.shadowsocks.utils
import com.github.shadowsocks.database.Profile
import android.net.Uri
import android.util.{Log, Base64}
object Parser {
val TAG = "ShadowParser"
def parse (data: String): Option[Profile] = {
try {
Log.d(TAG, data)
val uri = Uri.parse(data.trim)
if (uri.isOpaque && uri.getScheme == Scheme.SS) {
val encoded = data.replace(Scheme.SS + ":", "")
val content = new String(Base64.decode(encoded, Base64.NO_PADDING), "UTF-8")
val info = content.split('@')
val encinfo = info(0).split(':')
val serverinfo = info(1).split(':')
val profile = new Profile
profile.name = serverinfo(0)
profile.host = serverinfo(0)
profile.remotePort = serverinfo(1).toInt
profile.localPort = 1080
profile.method = encinfo(0)
profile.password = encinfo(1)
return Some(profile)
}
} catch {
case ex : Exception => Log.e(TAG, "parser error", ex)// Ignore
}
None
}
}