Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Christian Müller 2019-09-18 10:19:02 +02:00
commit f731daa637
6 changed files with 307 additions and 89 deletions

View file

@ -86,8 +86,11 @@ func (a *accessPoint) GetPropertyRSNFlags() (uint32, error) {
}
func (a *accessPoint) GetPropertySSID() (string, error) {
v, err := a.getSliceByteProperty(AccessPointPropertySsid)
return string(v), err
r, err := a.getSliceByteProperty(AccessPointPropertySsid)
if err != nil {
return "", err
}
return string(r), nil
}
func (a *accessPoint) GetPropertyFrequency() (uint32, error) {
@ -99,8 +102,11 @@ func (a *accessPoint) GetPropertyHWAddress() (string, error) {
}
func (a *accessPoint) GetPropertyMode() (Nm80211Mode, error) {
v, err := a.getUint32Property(AccessPointPropertyMode)
return Nm80211Mode(v), err
r, err := a.getUint32Property(AccessPointPropertyMode)
if err != nil {
return Nm80211ModeUnknown, err
}
return Nm80211Mode(r), nil
}
func (a *accessPoint) GetPropertyMaxBitrate() (uint32, error) {
@ -112,19 +118,52 @@ func (a *accessPoint) GetPropertyStrength() (uint8, error) {
}
func (a *accessPoint) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
Flags, err := a.GetPropertyFlags()
if err != nil {
return nil, err
}
WPAFlags, err := a.GetPropertyWPAFlags()
if err != nil {
return nil, err
}
RSNFlags, err := a.GetPropertyRSNFlags()
if err != nil {
return nil, err
}
SSID, err := a.GetPropertySSID()
if err != nil {
return nil, err
}
Frequency, err := a.GetPropertyFrequency()
if err != nil {
return nil, err
}
HWAddress, err := a.GetPropertyHWAddress()
if err != nil {
return nil, err
}
Mode, err := a.GetPropertyMode()
if err != nil {
return nil, err
}
MaxBitrate, err := a.GetPropertyMaxBitrate()
if err != nil {
return nil, err
}
Strength, err := a.GetPropertyStrength()
if err != nil {
return nil, err
}
m["Flags"], _ = a.GetPropertyFlags()
m["WPAFlags"], _ = a.GetPropertyWPAFlags()
m["RSNFlags"], _ = a.GetPropertyRSNFlags()
m["SSID"], _ = a.GetPropertySSID()
m["Frequency"], _ = a.GetPropertyFrequency()
m["HWAddress"], _ = a.GetPropertyHWAddress()
m["MaxBitrate"], _ = a.GetPropertyMaxBitrate()
m["Strength"], _ = a.GetPropertyStrength()
mode, _ := a.GetPropertyMode()
m["Mode"] = mode.String()
return json.Marshal(m)
return json.Marshal(map[string]interface{}{
"Flags": Flags,
"WPAFlags": WPAFlags,
"RSNFlags": RSNFlags,
"SSID": SSID,
"Frequency": Frequency,
"HWAddress": HWAddress,
"Mode": Mode.String(),
"MaxBitrate": MaxBitrate,
"Strength": Strength,
})
}

View file

@ -96,8 +96,11 @@ func (a *activeConnection) GetPropertyConnection() (Connection, error) {
if err != nil {
return nil, err
}
return NewConnection(path)
con, err := NewConnection(path)
if err != nil {
return nil, err
}
return con, nil
}
func (a *activeConnection) GetPropertySpecificObject() (AccessPoint, error) {
@ -105,8 +108,11 @@ func (a *activeConnection) GetPropertySpecificObject() (AccessPoint, error) {
if err != nil {
return nil, err
}
return NewAccessPoint(path)
ap, err := NewAccessPoint(path)
if err != nil {
return nil, err
}
return ap, nil
}
func (a *activeConnection) GetPropertyID() (string, error) {
@ -126,17 +132,15 @@ func (a *activeConnection) GetPropertyDevices() ([]Device, error) {
if err != nil {
return nil, err
}
devices := make([]Device, len(paths))
for i, path := range paths {
devices[i], err = DeviceFactory(path)
if err != nil {
return devices, err
return nil, err
}
}
return devices, nil
}
func (a *activeConnection) GetPropertyState() (NmActiveConnectionState, error) {
v, err := a.getUint32Property(ActiveConnectionPropertyState)
return NmActiveConnectionState(v), err
@ -147,25 +151,35 @@ func (a *activeConnection) GetPropertyStateFlags() (uint32, error) {
}
func (a *activeConnection) GetPropertyDefault() (bool, error) {
return a.getBoolProperty(ActiveConnectionPropertyDefault)
b, err := a.getProperty(ActiveConnectionPropertyDefault)
if err != nil {
return false, err
}
return b.(bool), nil
}
func (a *activeConnection) GetPropertyIP4Config() (IP4Config, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyIp4Config)
if err != nil || path == "/" {
if err != nil {
return nil, err
}
return NewIP4Config(path)
r, err := NewIP4Config(path)
if err != nil {
return nil, err
}
return r, nil
}
func (a *activeConnection) GetPropertyDHCP4Config() (DHCP4Config, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyDhcp4Config)
if err != nil || path == "/" {
if err != nil {
return nil, err
}
return NewDHCP4Config(path)
r, err := NewDHCP4Config(path)
if err != nil {
return nil, err
}
return r, nil
}
func (a *activeConnection) GetPropertyDefault6() (bool, error) {
@ -191,7 +205,11 @@ func (a *activeConnection) GetPropertyDHCP6Config() (DHCP6Config, error) {
}
func (a *activeConnection) GetPropertyVPN() (bool, error) {
return a.getBoolProperty(ActiveConnectionPropertyVpn)
ret, err := a.getProperty(ActiveConnectionPropertyVpn)
if err != nil {
return false, err
}
return ret.(bool), nil
}
func (a *activeConnection) GetPropertyMaster() (Device, error) {
@ -199,6 +217,9 @@ func (a *activeConnection) GetPropertyMaster() (Device, error) {
if err != nil {
return nil, err
}
return DeviceFactory(path)
r, err := DeviceFactory(path)
if err != nil {
return nil, err
}
return r, nil
}

View file

@ -46,8 +46,11 @@ func (c *dhcp4Config) GetPropertyOptions() (DHCP4Options, error) {
}
func (c *dhcp4Config) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
m["Options"], _ = c.GetPropertyOptions()
return json.Marshal(m)
Options, err := c.GetOptions()
if err != nil {
return nil, err
}
return json.Marshal(map[string]interface{}{
"Options": Options,
})
}

View file

@ -2,6 +2,7 @@ package gonetworkmanager
import (
"encoding/json"
"errors"
"github.com/godbus/dbus"
)
@ -192,8 +193,11 @@ func (d *device) GetPropertyFirmwareVersion() (string, error) {
}
func (d *device) GetPropertyState() (NmDeviceState, error) {
v, err := d.getUint32Property(DevicePropertyState)
return NmDeviceState(v), err
r, err := d.getUint32Property(DevicePropertyState)
if err != nil {
return NmDeviceStateFailed, err
}
return NmDeviceState(r), nil
}
func (d *device) GetPropertyActiveConnection() (ActiveConnection, error) {
@ -291,24 +295,51 @@ func (d *device) GetPropertyReal() (bool, error) {
return d.getBoolProperty(DevicePropertyReal)
}
func (d *device) marshalMap() map[string]interface{} {
m := make(map[string]interface{})
func (d *device) marshalMap() (map[string]interface{}, error) {
Interface, err := d.GetInterface()
if err != nil {
return nil, err
}
IPinterface, err := d.GetPropertyIpInterface()
if err != nil {
return nil, err
}
State, err := d.GetPropertyState()
if err != nil {
return nil, err
}
IP4Config, err := d.GetPropertyIP4Config()
if err != nil {
return nil, err
}
DHCP4Config, err := d.GetPropertyDHCP4Config()
if err != nil {
return nil, err
}
DeviceType, err := d.GetPropertyDeviceType()
if err != nil {
return nil, err
}
AvailableConnections, err := d.GetPropertyAvailableConnections()
if err != nil {
return nil, err
}
m["Interface"], _ = d.GetPropertyInterface()
m["IPInterface"], _ = d.GetPropertyIpInterface()
m["IP4Config"], _ = d.GetPropertyIP4Config()
m["DHCP4Config"], _ = d.GetPropertyDHCP4Config()
m["AvailableConnections"], _ = d.GetPropertyAvailableConnections()
state, _ := d.GetPropertyState()
m["State"] = state.String()
deviceType, _ := d.GetPropertyDeviceType()
m["DeviceType"] = deviceType.String()
return m
return map[string]interface{}{
"Interface": Interface,
"IP interface": IPinterface,
"State": State.String(),
"IP4Config": IP4Config,
"DHCP4Config": DHCP4Config,
"DeviceType": DeviceType.String(),
"AvailableConnections": AvailableConnections,
}, nil
}
func (d *device) MarshalJSON() ([]byte, error) {
return json.Marshal(d.marshalMap())
m, err := d.marshalMap()
if err != nil {
return nil, err
}
return json.Marshal(m)
}

View file

@ -292,12 +292,27 @@ func (c *ip4Config) GetPropertyWinsServerData() ([]string, error) {
}
func (c *ip4Config) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
Addresses, err := c.GetPropertyAddressData()
if err != nil {
return nil, err
}
Routes, err := c.GetPropertyRouteData()
if err != nil {
return nil, err
}
Nameservers, err := c.GetPropertyNameserverData()
if err != nil {
return nil, err
}
Domains, err := c.GetPropertyDomains()
if err != nil {
return nil, err
}
m["Addresses"], _ = c.GetPropertyAddressData()
m["Routes"], _ = c.GetPropertyRouteData()
m["Nameservers"], _ = c.GetPropertyNameserverData()
m["Domains"], _ = c.GetPropertyDomains()
return json.Marshal(m)
}
return json.Marshal(map[string]interface{}{
"Addresses": Addresses,
"Routes": Routes,
"Nameservers": Nameservers,
"Domains": Domains,
})
}

View file

@ -557,30 +557,139 @@ func (nm *networkManager) Unsubscribe() {
}
func (nm *networkManager) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
m["Devices"], _ = nm.GetPropertyDevices()
m["AllDevices"], _ = nm.GetPropertyAllDevices()
m["Checkpoints"], _ = nm.GetPropertyCheckpoints()
m["NetworkingEnabled"], _ = nm.GetPropertyNetworkingEnabled()
m["WirelessEnabled"], _ = nm.GetPropertyWirelessEnabled()
m["WirelessHardwareEnabled"], _ = nm.GetPropertyWirelessHardwareEnabled()
m["WwanEnabled"], _ = nm.GetPropertyWwanEnabled()
m["WwanHardwareEnabled"], _ = nm.GetPropertyWwanHardwareEnabled()
m["WimaxEnabled"], _ = nm.GetPropertyWimaxEnabled()
m["WimaxHardwareEnabled"], _ = nm.GetPropertyWimaxHardwareEnabled()
m["ActiveConnections"], _ = nm.GetPropertyActiveConnections()
m["PrimaryConnection"], _ = nm.GetPropertyPrimaryConnection()
m["PrimaryConnectionType"], _ = nm.GetPropertyPrimaryConnectionType()
m["Metered"], _ = nm.GetPropertyMetered()
m["ActivatingConnection"], _ = nm.GetPropertyActivatingConnection()
m["Startup"], _ = nm.GetPropertyStartup()
m["Version"], _ = nm.GetPropertyVersion()
m["Capabilities"], _ = nm.GetPropertyCapabilities()
m["State"], _ = nm.GetPropertyState()
m["Connectivity"], _ = nm.GetPropertyConnectivity()
m["ConnectivityCheckAvailable"], _ = nm.GetPropertyConnectivityCheckAvailable()
m["ConnectivityCheckEnabled"], _ = nm.GetPropertyConnectivityCheckEnabled()
Devices, err := n.GetPropertyDevices()
if err != nil {
return nil, err
}
return json.Marshal(m)
AllDevices, err := n.GetPropertyAllDevices()
if err != nil {
return nil, err
}
Checkpoints, err := n.GetPropertyCheckpoints()
if err != nil {
return nil, err
}
NetworkingEnabled, err := n.GetPropertyNetworkingEnabled()
if err != nil {
return nil, err
}
WirelessEnabled, err := n.GetPropertyWirelessEnabled()
if err != nil {
return nil, err
}
WirelessHardwareEnabled, err := n.GetPropertyWirelessHardwareEnabled()
if err != nil {
return nil, err
}
WwanEnabled, err := n.GetPropertyWwanEnabled()
if err != nil {
return nil, err
}
WwanHardwareEnabled, err := n.GetPropertyWwanHardwareEnabled()
if err != nil {
return nil, err
}
WimaxEnabled, err := n.GetPropertyWimaxEnabled()
if err != nil {
return nil, err
}
WimaxHardwareEnabled, err := n.GetPropertyWimaxHardwareEnabled()
if err != nil {
return nil, err
}
ActiveConnections, err := n.GetPropertyActiveConnections()
if err != nil {
return nil, err
}
PrimaryConnection, err := n.GetPropertyPrimaryConnection()
if err != nil {
return nil, err
}
PrimaryConnectionType, err := n.GetPropertyPrimaryConnectionType()
if err != nil {
return nil, err
}
Metered, err := n.GetPropertyMetered()
if err != nil {
return nil, err
}
ActivatingConnection, err := n.GetPropertyActivatingConnection()
if err != nil {
return nil, err
}
Startup, err := n.GetPropertyStartup()
if err != nil {
return nil, err
}
Version, err := n.GetPropertyVersion()
if err != nil {
return nil, err
}
Capabilities, err := n.GetPropertyCapabilities()
if err != nil {
return nil, err
}
State, err := n.GetPropertyState()
if err != nil {
return nil, err
}
Connectivity, err := n.GetPropertyConnectivity()
if err != nil {
return nil, err
}
ConnectivityCheckAvailable, err := n.GetPropertyConnectivityCheckAvailable()
if err != nil {
return nil, err
}
ConnectivityCheckEnabled, err := n.GetPropertyConnectivityCheckEnabled()
if err != nil {
return nil, err
}
return json.Marshal(map[string]interface{}{
"Devices": Devices,
"AllDevices": AllDevices,
"Checkpoints": Checkpoints,
"NetworkingEnabled": NetworkingEnabled,
"WirelessEnabled": WirelessEnabled,
"WirelessHardwareEnabled": WirelessHardwareEnabled,
"WwanEnabled": WwanEnabled,
"WwanHardwareEnabled": WwanHardwareEnabled,
"WimaxEnabled": WimaxEnabled,
"WimaxHardwareEnabled": WimaxHardwareEnabled,
"ActiveConnections": ActiveConnections,
"PrimaryConnection": PrimaryConnection,
"PrimaryConnectionType": PrimaryConnectionType,
"Metered": Metered,
"ActivatingConnection": ActivatingConnection,
"Startup": Startup,
"Version": Version,
"Capabilities": Capabilities,
"State": State,
"Connectivity": Connectivity,
"ConnectivityCheckAvailable": ConnectivityCheckAvailable,
"ConnectivityCheckEnabled": ConnectivityCheckEnabled,
})
}