support scaning QR code

This commit is contained in:
Max Lv
2013-12-01 12:40:22 +08:00
parent aae95df436
commit 1907ac2fef
5 changed files with 112 additions and 11 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 ShadowParser {
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 == "shadow") {
val encoded = data.replace("shadow:", "")
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
}
}