mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 13:03:45 +02:00
more error checking when parsing JSON for network list
remove "multicastSubscriptions" field as it isn't used anyway
This commit is contained in:
parent
89cb0e260a
commit
c8750e5812
2 changed files with 127 additions and 66 deletions
|
@ -2,13 +2,6 @@
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSAppTransportSecurity</key>
|
|
||||||
<dict>
|
|
||||||
<key>NSAllowsArbitraryLoads</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
<key>LSUIElement</key>
|
|
||||||
<true/>
|
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>en</string>
|
<string>en</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
|
@ -28,9 +21,16 @@
|
||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1</string>
|
<string>2</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||||
|
<key>LSUIElement</key>
|
||||||
|
<true/>
|
||||||
|
<key>NSAppTransportSecurity</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSAllowsArbitraryLoads</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
<string>Copyright © 2016 ZeroTier, Inc. All rights reserved.</string>
|
<string>Copyright © 2016 ZeroTier, Inc. All rights reserved.</string>
|
||||||
<key>NSMainNibFile</key>
|
<key>NSMainNibFile</key>
|
||||||
|
|
|
@ -65,7 +65,6 @@ class Network: NSObject, NSCoding {
|
||||||
var dhcp: Bool = false
|
var dhcp: Bool = false
|
||||||
var mac: String = ""
|
var mac: String = ""
|
||||||
var mtu: Int = 0
|
var mtu: Int = 0
|
||||||
var multicastSubscriptions: [String] = [String]()
|
|
||||||
var name: String = ""
|
var name: String = ""
|
||||||
var netconfRevision: Int = 232
|
var netconfRevision: Int = 232
|
||||||
var nwid: UInt64 = 0
|
var nwid: UInt64 = 0
|
||||||
|
@ -78,29 +77,53 @@ class Network: NSObject, NSCoding {
|
||||||
init(jsonData: [String: AnyObject]) {
|
init(jsonData: [String: AnyObject]) {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
let aa = jsonData["assignedAddresses"] as! [String]
|
if let aa = jsonData["assignedAddresses"] as? [String] {
|
||||||
for a in aa {
|
for a in aa {
|
||||||
assignedAddresses.append(a)
|
assignedAddresses.append(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
bridge = (jsonData["bridge"] as! NSNumber).boolValue
|
|
||||||
broadcastEnabled = (jsonData["broadcastEnabled"] as! NSNumber).boolValue
|
|
||||||
dhcp = (jsonData["dhcp"] as! NSNumber).boolValue
|
|
||||||
mac = jsonData["mac"] as! String
|
|
||||||
mtu = (jsonData["mtu"] as! NSNumber).integerValue
|
|
||||||
|
|
||||||
let multSubs = jsonData["multicastSubscriptions"] as! [String]
|
|
||||||
for ms in multSubs {
|
|
||||||
multicastSubscriptions.append(ms)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
name = jsonData["name"] as! String
|
if let b = jsonData["bridge"] as? NSNumber {
|
||||||
netconfRevision = (jsonData["netconfRevision"] as! NSNumber).integerValue
|
bridge = b.boolValue
|
||||||
nwid = UInt64((jsonData["nwid"] as! String), radix: 16)!
|
}
|
||||||
portDeviceName = jsonData["portDeviceName"] as! String
|
|
||||||
portError = (jsonData["portError"] as! NSNumber).integerValue
|
|
||||||
|
|
||||||
let statusStr = jsonData["status"] as! String
|
if let b = jsonData["broadcastEnabled"] as? NSNumber {
|
||||||
|
broadcastEnabled = b.boolValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if let d = jsonData["dhcp"] as? NSNumber {
|
||||||
|
dhcp = d.boolValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if let m = jsonData["mac"] as? String {
|
||||||
|
mac = m
|
||||||
|
}
|
||||||
|
|
||||||
|
if let m = jsonData["mtu"] as? NSNumber {
|
||||||
|
mtu = m.integerValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if let n = jsonData["name"] as? String {
|
||||||
|
name = n
|
||||||
|
}
|
||||||
|
|
||||||
|
if let n = jsonData["netconfRevision"] as? NSNumber {
|
||||||
|
netconfRevision = n.integerValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if let n = UInt64((jsonData["nwid"] as! String), radix: 16) {
|
||||||
|
nwid = n
|
||||||
|
}
|
||||||
|
|
||||||
|
if let p = jsonData["portDeviceName"] as? String {
|
||||||
|
portDeviceName = p
|
||||||
|
}
|
||||||
|
|
||||||
|
if let p = jsonData["portError"] as? NSNumber {
|
||||||
|
portError = p.integerValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if let statusStr = jsonData["status"] as? String {
|
||||||
switch statusStr {
|
switch statusStr {
|
||||||
case "REQUESTING_CONFIGURATION":
|
case "REQUESTING_CONFIGURATION":
|
||||||
status = .REQUESTING_CONFIGURATION
|
status = .REQUESTING_CONFIGURATION
|
||||||
|
@ -117,8 +140,9 @@ class Network: NSObject, NSCoding {
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let typeStr = jsonData["type"] as! String
|
if let typeStr = jsonData["type"] as? String {
|
||||||
switch typeStr {
|
switch typeStr {
|
||||||
case "PRIVATE":
|
case "PRIVATE":
|
||||||
type = .PRIVATE
|
type = .PRIVATE
|
||||||
|
@ -127,27 +151,65 @@ class Network: NSObject, NSCoding {
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if it's being initialized via JSON, it's connected
|
// if it's being initialized via JSON, it's connected
|
||||||
connected = true
|
connected = true
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.addressesKey) {
|
||||||
self.assignedAddresses = aDecoder.decodeObjectForKey(PropertyKeys.addressesKey) as! [String]
|
self.assignedAddresses = aDecoder.decodeObjectForKey(PropertyKeys.addressesKey) as! [String]
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.bridgeKey) {
|
||||||
self.bridge = aDecoder.decodeBoolForKey(PropertyKeys.bridgeKey)
|
self.bridge = aDecoder.decodeBoolForKey(PropertyKeys.bridgeKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.broadcastKey) {
|
||||||
self.broadcastEnabled = aDecoder.decodeBoolForKey(PropertyKeys.broadcastKey)
|
self.broadcastEnabled = aDecoder.decodeBoolForKey(PropertyKeys.broadcastKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.dhcpKey) {
|
||||||
self.dhcp = aDecoder.decodeBoolForKey(PropertyKeys.dhcpKey)
|
self.dhcp = aDecoder.decodeBoolForKey(PropertyKeys.dhcpKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.macKey) {
|
||||||
self.mac = aDecoder.decodeObjectForKey(PropertyKeys.macKey) as! String
|
self.mac = aDecoder.decodeObjectForKey(PropertyKeys.macKey) as! String
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.mtuKey) {
|
||||||
self.mtu = aDecoder.decodeIntegerForKey(PropertyKeys.mtuKey)
|
self.mtu = aDecoder.decodeIntegerForKey(PropertyKeys.mtuKey)
|
||||||
self.multicastSubscriptions = aDecoder.decodeObjectForKey(PropertyKeys.multicastKey) as! [String]
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.nameKey) {
|
||||||
self.name = aDecoder.decodeObjectForKey(PropertyKeys.nameKey) as! String
|
self.name = aDecoder.decodeObjectForKey(PropertyKeys.nameKey) as! String
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.netconfKey) {
|
||||||
self.netconfRevision = aDecoder.decodeIntegerForKey(PropertyKeys.netconfKey)
|
self.netconfRevision = aDecoder.decodeIntegerForKey(PropertyKeys.netconfKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.nwidKey) {
|
||||||
self.nwid = (aDecoder.decodeObjectForKey(PropertyKeys.nwidKey) as! NSNumber).unsignedLongLongValue
|
self.nwid = (aDecoder.decodeObjectForKey(PropertyKeys.nwidKey) as! NSNumber).unsignedLongLongValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.portNameKey) {
|
||||||
self.portDeviceName = aDecoder.decodeObjectForKey(PropertyKeys.portNameKey) as! String
|
self.portDeviceName = aDecoder.decodeObjectForKey(PropertyKeys.portNameKey) as! String
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.portErrorKey) {
|
||||||
self.portError = aDecoder.decodeIntegerForKey(PropertyKeys.portErrorKey)
|
self.portError = aDecoder.decodeIntegerForKey(PropertyKeys.portErrorKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.statusKey) {
|
||||||
self.status = NetworkStatus(rawValue: aDecoder.decodeIntegerForKey(PropertyKeys.statusKey))!
|
self.status = NetworkStatus(rawValue: aDecoder.decodeIntegerForKey(PropertyKeys.statusKey))!
|
||||||
|
}
|
||||||
|
|
||||||
|
if aDecoder.containsValueForKey(PropertyKeys.typeKey) {
|
||||||
self.type = NetworkType(rawValue: aDecoder.decodeIntegerForKey(PropertyKeys.typeKey))!
|
self.type = NetworkType(rawValue: aDecoder.decodeIntegerForKey(PropertyKeys.typeKey))!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func encodeWithCoder(aCoder: NSCoder) {
|
func encodeWithCoder(aCoder: NSCoder) {
|
||||||
aCoder.encodeObject(self.assignedAddresses, forKey: PropertyKeys.addressesKey)
|
aCoder.encodeObject(self.assignedAddresses, forKey: PropertyKeys.addressesKey)
|
||||||
|
@ -156,7 +218,6 @@ class Network: NSObject, NSCoding {
|
||||||
aCoder.encodeBool(self.dhcp, forKey: PropertyKeys.dhcpKey)
|
aCoder.encodeBool(self.dhcp, forKey: PropertyKeys.dhcpKey)
|
||||||
aCoder.encodeObject(self.mac, forKey: PropertyKeys.macKey)
|
aCoder.encodeObject(self.mac, forKey: PropertyKeys.macKey)
|
||||||
aCoder.encodeInteger(self.mtu, forKey: PropertyKeys.mtuKey)
|
aCoder.encodeInteger(self.mtu, forKey: PropertyKeys.mtuKey)
|
||||||
aCoder.encodeObject(self.multicastSubscriptions, forKey: PropertyKeys.multicastKey)
|
|
||||||
aCoder.encodeObject(self.name, forKey: PropertyKeys.nameKey)
|
aCoder.encodeObject(self.name, forKey: PropertyKeys.nameKey)
|
||||||
aCoder.encodeInteger(self.netconfRevision, forKey: PropertyKeys.netconfKey)
|
aCoder.encodeInteger(self.netconfRevision, forKey: PropertyKeys.netconfKey)
|
||||||
aCoder.encodeObject(NSNumber(unsignedLongLong: self.nwid), forKey: PropertyKeys.nwidKey)
|
aCoder.encodeObject(NSNumber(unsignedLongLong: self.nwid), forKey: PropertyKeys.nwidKey)
|
||||||
|
|
Loading…
Add table
Reference in a new issue