regex simplification
This commit is contained in:
parent
717b642fd1
commit
87bcfde75c
@ -32,8 +32,8 @@ class NetworkConfigurationParser
|
||||
up = true
|
||||
when /^description/
|
||||
description = /^description (.+)/.match(line).try &.[1]
|
||||
when /^inet6? alias .*/
|
||||
ipstr = /^inet6? alias ([a-f0-9:.\/]+)/.match(line).try &.[1]
|
||||
when /^inet6? alias (?<ip>[a-f0-9:.\/]+)/
|
||||
ipstr = $~["ip"]
|
||||
if ipstr.nil?
|
||||
puts "wrong IP address alias, line #{line}"
|
||||
next
|
||||
@ -50,8 +50,8 @@ class NetworkConfigurationParser
|
||||
# IP address is autoconfigured
|
||||
main_ip_v6 = Autoconfiguration.new
|
||||
|
||||
when /^inet6? .*/
|
||||
ipstr = /^inet6? ([a-f0-9:.\/]+)/.match(line).try &.[1]
|
||||
when /^inet6? (?<ip>[a-f0-9:.\/]+)/
|
||||
ipstr = $~["ip"]
|
||||
if ipstr.nil?
|
||||
puts "wrong IP address, line #{line}"
|
||||
next
|
||||
@ -62,10 +62,10 @@ class NetworkConfigurationParser
|
||||
main_ip_v6 = IPAddress.parse ipstr
|
||||
end
|
||||
|
||||
when /^join [^ \t]+ wpakey .*/
|
||||
when /^join (?<ssid>[^ \t]+) wpakey (?<wpakey>[^ \t]+)/
|
||||
# WPA2-PSK, other security mechanisms are not supported, yet
|
||||
ssid = /^join ([^ \t]+)/.match(line).try &.[1]
|
||||
wpakeystr = /^join [^ \t]+ wpakey ([^ \t]+)/.match(line).try &.[1]
|
||||
ssid = $~["ssid"]
|
||||
wpakeystr = $~["wpakey"]
|
||||
|
||||
if ssid.nil?
|
||||
puts "wrong SSID in line: #{line}"
|
||||
@ -80,31 +80,20 @@ class NetworkConfigurationParser
|
||||
new_ap = WirelessAPSetup.new ssid, WirelessAPSetup::WPA.new(wpakeystr)
|
||||
wireless_networks[ssid] = new_ap
|
||||
|
||||
when /^network [^ \t]+ inet6 autoconf/
|
||||
ssid = /^network ([^ \t]+)/.match(line).try &.[1]
|
||||
ipstr = /^network [^ \t]+ inet6? ([^ \t]+)/.match(line).try &.[1]
|
||||
when /^network (?<ssid>[^ \t]+) inet6 autoconf/
|
||||
ssid = $~["ssid"]
|
||||
|
||||
if ssid.nil?
|
||||
puts "wrong SSID in line: #{line}"
|
||||
next
|
||||
end
|
||||
|
||||
if ipstr.nil?
|
||||
puts "wrong ip address in line: #{line}"
|
||||
next
|
||||
end
|
||||
|
||||
access_point = wireless_networks[ssid].not_nil!
|
||||
access_point.main_ip_v6 = Autoconfiguration.new
|
||||
|
||||
when /^network [^ \t]+ inet6? .*/
|
||||
ssid = nil
|
||||
ipstr = nil
|
||||
|
||||
/^network (?<ssid>[^ \t]+) inet6? (?<ip>[^ \t]+)/.match(line).try do |m|
|
||||
ssid = m["ssid"]
|
||||
ipstr = m["ip"]
|
||||
end
|
||||
when /^network (?<ssid>[^ \t]+) inet6? (?<ip>[^ \t]+)/
|
||||
ssid = $~["ssid"]
|
||||
ipstr = $~["ip"]
|
||||
|
||||
if ssid.nil?
|
||||
puts "wrong SSID in line: #{line}"
|
||||
@ -127,8 +116,8 @@ class NetworkConfigurationParser
|
||||
puts "wrong ip address in line: #{line} (neither ipv4 or ipv6)"
|
||||
end
|
||||
|
||||
when /^network [^ ]+ dhcp6?/
|
||||
ssid = /^network (?<ssid>[^ \t]+)/.match(line).try &.["ssid"]
|
||||
when /^network (?<ssid>[^ \t]+) dhcp6?/
|
||||
ssid = $~["ssid"]
|
||||
|
||||
if ssid.nil?
|
||||
puts "wrong SSID in line: #{line}"
|
||||
@ -145,14 +134,9 @@ class NetworkConfigurationParser
|
||||
puts "wrong dhcp instruction in line: #{line}"
|
||||
end
|
||||
|
||||
when /^network [^ ]+ dns .*/
|
||||
ssid = nil
|
||||
ipstr = nil
|
||||
|
||||
/^network (?<ssid>[^ \t]+) dns (?<ip>[^ \t]+)/.match(line).try do |m|
|
||||
ssid = m["ssid"]
|
||||
ipstr = m["ip"]
|
||||
end
|
||||
when /^network (?<ssid>[^ \t]+) dns (?<ip>[^ \t]+)/
|
||||
ssid = $~["ssid"]
|
||||
ipstr = $~["ip"]
|
||||
|
||||
if ssid.nil?
|
||||
puts "wrong SSID in line: #{line}"
|
||||
@ -168,15 +152,11 @@ class NetworkConfigurationParser
|
||||
ipaddr = IPAddress.parse ipstr
|
||||
access_point.dns.addresses << ipaddr.to_s
|
||||
|
||||
when /^mtu [0-9]+/
|
||||
mtu = /^mtu ([0-9]+)/.match(line).try &.[1].to_i
|
||||
when /^mtu (?<mtu>[0-9]+)/
|
||||
mtu = $~["mtu"].to_i
|
||||
|
||||
when /^dns [^ \t]+/
|
||||
ipstr = nil
|
||||
|
||||
/^dns (?<ip>[^ \t]+)/.match(line).try do |m|
|
||||
ipstr = m["ip"]
|
||||
end
|
||||
when /^dns (?<ip>[^ \t]+)/
|
||||
ipstr = $~["ip"]
|
||||
|
||||
if ipstr.nil?
|
||||
puts "wrong ip address in line: #{line}"
|
||||
|
Loading…
Reference in New Issue
Block a user