haiku/headers/os/add-ons/network_settings/NetworkSettings.h

202 lines
4.9 KiB
C
Raw Normal View History

/*
* Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, axeld@pinc-software.de
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#include <vector>
#include <Message.h>
#include <Messenger.h>
#include <NetworkAddress.h>
#include <Path.h>
#include <StringList.h>
namespace BNetworkKit {
class BNetworkSettings {
public:
static const uint32 kMsgInterfaceSettingsUpdated = 'SUif';
static const uint32 kMsgNetworkSettingsUpdated = 'SUnw';
static const uint32 kMsgServiceSettingsUpdated = 'SUsv';
public:
BNetworkSettings();
~BNetworkSettings();
status_t GetNextInterface(uint32& cookie,
BMessage& interface);
status_t GetInterface(const char* name,
BMessage& interface);
status_t AddInterface(const BMessage& interface);
status_t RemoveInterface(const char* name);
* Remove the BNetworkDevice::AddPersistentNetwork() again and instead introduce BNetworkRoster::{Count|GetNext|Add|Remove}PersistentNetwork() as it fits better (thanks Philippe for the heads up). * Implement the backend for these functions in the net_server and also move conversion of the wireless_network based format into the settings based format there. * Implement removal of a network from the settings and make adding a new network with the same name replace the old one instead of just adding multiple ones. Might need to change this in the future depending on how we want to handle multiple networks with the same name (i.e. distinguish based on BSSID or similar). * Fix apparent oversight that caused configured networks _not_ to be used in the auto join attempt. * Remove auto joining open networks. I've been bitten by that more than once now because we happen to have an open network in the neighbourhood that I now accidentally used to transfer quite a bit of (unencrypted) stuff before noticing... In the future, one will instead have to explicitly join an open network once and store that config. Note that the driver will actually still auto-associate with open networks due to how things are set up currently. Note also that the auto join will fire join requests whenever there's a disassociation event, so you might see spurious join dialogs when the wpa_supplicant actually just re-establishes the connection. * Make join requests async again. Instead of waiting for a synchronous reply of the wpa_supplicant we instead return success when the request has been sent. While the API call might still be made synchronous again in the future, the net_server should really not block on an external application. In the case of the wpa_supplicant we would otherwise deadlock when using the new *PersistentNetwork() API after a successful join, and in other cases we might just unacceptably delay other calls. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42816 a95241bf-73f2-0310-859d-f6bbb57e9c96
2011-10-09 23:56:19 +04:00
int32 CountNetworks() const;
status_t GetNextNetwork(uint32& cookie,
* Remove the BNetworkDevice::AddPersistentNetwork() again and instead introduce BNetworkRoster::{Count|GetNext|Add|Remove}PersistentNetwork() as it fits better (thanks Philippe for the heads up). * Implement the backend for these functions in the net_server and also move conversion of the wireless_network based format into the settings based format there. * Implement removal of a network from the settings and make adding a new network with the same name replace the old one instead of just adding multiple ones. Might need to change this in the future depending on how we want to handle multiple networks with the same name (i.e. distinguish based on BSSID or similar). * Fix apparent oversight that caused configured networks _not_ to be used in the auto join attempt. * Remove auto joining open networks. I've been bitten by that more than once now because we happen to have an open network in the neighbourhood that I now accidentally used to transfer quite a bit of (unencrypted) stuff before noticing... In the future, one will instead have to explicitly join an open network once and store that config. Note that the driver will actually still auto-associate with open networks due to how things are set up currently. Note also that the auto join will fire join requests whenever there's a disassociation event, so you might see spurious join dialogs when the wpa_supplicant actually just re-establishes the connection. * Make join requests async again. Instead of waiting for a synchronous reply of the wpa_supplicant we instead return success when the request has been sent. While the API call might still be made synchronous again in the future, the net_server should really not block on an external application. In the case of the wpa_supplicant we would otherwise deadlock when using the new *PersistentNetwork() API after a successful join, and in other cases we might just unacceptably delay other calls. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42816 a95241bf-73f2-0310-859d-f6bbb57e9c96
2011-10-09 23:56:19 +04:00
BMessage& network) const;
status_t GetNetwork(const char* name,
BMessage& network);
status_t AddNetwork(const BMessage& network);
* Remove the BNetworkDevice::AddPersistentNetwork() again and instead introduce BNetworkRoster::{Count|GetNext|Add|Remove}PersistentNetwork() as it fits better (thanks Philippe for the heads up). * Implement the backend for these functions in the net_server and also move conversion of the wireless_network based format into the settings based format there. * Implement removal of a network from the settings and make adding a new network with the same name replace the old one instead of just adding multiple ones. Might need to change this in the future depending on how we want to handle multiple networks with the same name (i.e. distinguish based on BSSID or similar). * Fix apparent oversight that caused configured networks _not_ to be used in the auto join attempt. * Remove auto joining open networks. I've been bitten by that more than once now because we happen to have an open network in the neighbourhood that I now accidentally used to transfer quite a bit of (unencrypted) stuff before noticing... In the future, one will instead have to explicitly join an open network once and store that config. Note that the driver will actually still auto-associate with open networks due to how things are set up currently. Note also that the auto join will fire join requests whenever there's a disassociation event, so you might see spurious join dialogs when the wpa_supplicant actually just re-establishes the connection. * Make join requests async again. Instead of waiting for a synchronous reply of the wpa_supplicant we instead return success when the request has been sent. While the API call might still be made synchronous again in the future, the net_server should really not block on an external application. In the case of the wpa_supplicant we would otherwise deadlock when using the new *PersistentNetwork() API after a successful join, and in other cases we might just unacceptably delay other calls. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42816 a95241bf-73f2-0310-859d-f6bbb57e9c96
2011-10-09 23:56:19 +04:00
status_t RemoveNetwork(const char* name);
const BMessage& Services() const;
status_t GetNextService(uint32& cookie,
BMessage& service);
status_t GetService(const char* name, BMessage& service);
status_t AddService(const BMessage& service);
status_t RemoveService(const char* name);
status_t StartMonitoring(const BMessenger& target);
status_t StopMonitoring(const BMessenger& target);
status_t Update(BMessage* message);
private:
status_t _Load(const char* name = NULL,
uint32* _type = NULL);
status_t _Save(const char* name = NULL);
BPath _Path(BPath& parent, const char* name);
status_t _GetPath(const char* name, BPath& path);
status_t _StartWatching(const char* name,
const BMessenger& target);
bool _IsWatching(const BMessenger& target) const
{ return fListener == target; }
bool _IsWatching() const
{ return fListener.IsValid(); }
status_t _ConvertNetworkToSettings(BMessage& message);
status_t _ConvertNetworkFromSettings(BMessage& message);
status_t _GetItem(BMessage& container,
const char* itemField,
const char* nameField, const char* name,
int32& _index, BMessage& item);
status_t _RemoveItem(BMessage& container,
const char* itemField,
const char* nameField, const char* name,
const char* store = NULL);
private:
BMessenger fListener;
BMessage fInterfaces;
BMessage fNetworks;
BMessage fServices;
};
class BNetworkInterfaceAddressSettings {
public:
BNetworkInterfaceAddressSettings(
const BMessage& data);
~BNetworkInterfaceAddressSettings();
int Family() const;
bool AutoConfigure() const;
const BNetworkAddress&
Address() const;
const BNetworkAddress&
Mask() const;
const BNetworkAddress&
Peer() const;
const BNetworkAddress&
Broadcast() const;
const BNetworkAddress&
Gateway() const;
private:
int32 fFamily;
bool fAutoConfigure;
BNetworkAddress fAddress;
BNetworkAddress fMask;
BNetworkAddress fPeer;
BNetworkAddress fBroadcast;
BNetworkAddress fGateway;
};
class BNetworkInterfaceSettings {
public:
BNetworkInterfaceSettings(
const BMessage& message);
~BNetworkInterfaceSettings();
const char* Name() const;
};
} // namespace BNetworkKit
class BNetworkServiceAddressSettings {
public:
BNetworkServiceAddressSettings();
BNetworkServiceAddressSettings(
const BMessage& data, int family = -1,
int type = -1, int protocol = -1,
int port = -1);
~BNetworkServiceAddressSettings();
int Family() const;
void SetFamily(int family);
int Protocol() const;
void SetProtocol(int protocol);
int Type() const;
void SetType(int type);
const BNetworkAddress&
Address() const;
BNetworkAddress& Address();
status_t GetMessage(BMessage& data);
bool operator==(
const BNetworkServiceAddressSettings& other)
const;
private:
int32 fFamily;
int fProtocol;
int fType;
BNetworkAddress fAddress;
};
class BNetworkServiceSettings {
public:
BNetworkServiceSettings(
const BMessage& message);
~BNetworkServiceSettings();
status_t InitCheck() const;
const char* Name() const;
bool IsStandAlone() const;
int32 CountArguments() const;
const char* ArgumentAt(int32 index) const;
int32 CountAddresses() const;
const BNetworkServiceAddressSettings&
AddressAt(int32 index) const;
private:
const BMessage& fData;
BStringList fArguments;
std::vector<BNetworkServiceAddressSettings>
fAddresses;
};
#endif // SETTINGS_H