diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt b/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt index d903769..daf04c8 100644 --- a/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt +++ b/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt | |||
@@ -44,22 +44,22 @@ data class VpnInterfaceConfiguration(val addresses: List<CidrAddress> = emptyLis | |||
44 | val blocking: Boolean = false, | 44 | val blocking: Boolean = false, |
45 | val mtu: Int? = null) { | 45 | val mtu: Int? = null) { |
46 | companion object { | 46 | companion object { |
47 | private val KEY_ADDRESSES = "Address" | 47 | private const val KEY_ADDRESSES = "Address" |
48 | private val KEY_ROUTES = "Route" | 48 | private const val KEY_ROUTES = "Route" |
49 | private val KEY_DNS_SERVERS = "DNSServer" | 49 | private const val KEY_DNS_SERVERS = "DNSServer" |
50 | private val KEY_SEARCH_DOMAINS = "SearchDomain" | 50 | private const val KEY_SEARCH_DOMAINS = "SearchDomain" |
51 | private val KEY_ALLOWED_APPLICATIONS = "AllowApplication" | 51 | private const val KEY_ALLOWED_APPLICATIONS = "AllowApplication" |
52 | private val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication" | 52 | private const val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication" |
53 | private val KEY_ALLOWED_FAMILIES = "AllowFamily" | 53 | private const val KEY_ALLOWED_FAMILIES = "AllowFamily" |
54 | private val KEY_ALLOW_BYPASS = "AllowBypass" | 54 | private const val KEY_ALLOW_BYPASS = "AllowBypass" |
55 | private val KEY_BLOCKING = "Blocking" | 55 | private const val KEY_BLOCKING = "Blocking" |
56 | private val KEY_MTU = "MTU" | 56 | private const val KEY_MTU = "MTU" |
57 | 57 | ||
58 | private val INVITATION_KEY_ADDRESSES = "Ifconfig" | 58 | private const val INVITATION_KEY_ADDRESSES = "Ifconfig" |
59 | private val INVITATION_KEY_ROUTES = "Route" | 59 | private const val INVITATION_KEY_ROUTES = "Route" |
60 | 60 | ||
61 | fun fromIfaceConfiguration(f: File) = fromIfaceConfiguration(Configurations().properties(f)) | 61 | fun fromIfaceConfiguration(f: File) = fromIfaceConfiguration(Configurations().properties(f)) |
62 | fun fromIfaceConfiguration(c: Configuration) = VpnInterfaceConfiguration( | 62 | private fun fromIfaceConfiguration(c: Configuration) = VpnInterfaceConfiguration( |
63 | c.getCidrList(KEY_ADDRESSES), | 63 | c.getCidrList(KEY_ADDRESSES), |
64 | c.getCidrList(KEY_ROUTES), | 64 | c.getCidrList(KEY_ROUTES), |
65 | c.getStringList(KEY_DNS_SERVERS), | 65 | c.getStringList(KEY_DNS_SERVERS), |
@@ -72,7 +72,7 @@ data class VpnInterfaceConfiguration(val addresses: List<CidrAddress> = emptyLis | |||
72 | c.getInteger(KEY_MTU, null)) | 72 | c.getInteger(KEY_MTU, null)) |
73 | 73 | ||
74 | fun fromInvitation(f: File) = fromInvitation(Configurations().properties(f)) | 74 | fun fromInvitation(f: File) = fromInvitation(Configurations().properties(f)) |
75 | fun fromInvitation(c: Configuration) = VpnInterfaceConfiguration( | 75 | private fun fromInvitation(c: Configuration) = VpnInterfaceConfiguration( |
76 | c.getStringList(INVITATION_KEY_ADDRESSES) | 76 | c.getStringList(INVITATION_KEY_ADDRESSES) |
77 | .map { applyIgnoringException(CidrAddress.Companion::fromSlashSeparated, it) } | 77 | .map { applyIgnoringException(CidrAddress.Companion::fromSlashSeparated, it) } |
78 | .filterNotNull(), | 78 | .filterNotNull(), |
@@ -83,10 +83,10 @@ data class VpnInterfaceConfiguration(val addresses: List<CidrAddress> = emptyLis | |||
83 | 83 | ||
84 | fun write(f: File) = FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration::class.java) | 84 | fun write(f: File) = FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration::class.java) |
85 | .configure(Parameters().properties().setFile(f.apply { createNewFile() })).let { builder -> | 85 | .configure(Parameters().properties().setFile(f.apply { createNewFile() })).let { builder -> |
86 | builder.configuration.let { cfg -> | 86 | builder.configuration.let { cfg -> |
87 | addresses.forEach { cfg.addProperty(KEY_ADDRESSES, it.toSlashSeparated()) } | 87 | addresses.forEach { cfg.addProperty(KEY_ADDRESSES, it.toSlashSeparated()) } |
88 | routes.forEach { cfg.addProperty(KEY_ROUTES, it.toSlashSeparated()) } | 88 | routes.forEach { cfg.addProperty(KEY_ROUTES, it.toSlashSeparated()) } |
89 | } | ||
90 | builder.save() | ||
89 | } | 91 | } |
90 | builder.save() | ||
91 | } | ||
92 | } | 92 | } |