summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/interfaces/interfaces.h
blob: 26abb7359e62a81ccabbc523520e600dad7332ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef INTERFACES_H
#define INTERFACES_H

#include <qstring.h>
#include <qstringlist.h>

#define INTERFACES_LOOPBACK "loopback"

#define INTERFACES_FAMILY_INET "inet"
#define INTERFACES_FAMILY_IPX "ipx"
#define INTERFACES_FAMILY_INET6 "inet6"

#define INTERFACES_METHOD_DHCP "dhcp"
#define INTERFACES_METHOD_STATIC "static"
#define INTERFACES_METHOD_PPP "ppp"

/**
 * This class provides a clean frontend for parsing the network interfaces file.
 * It provides helper functions to minipulate the options within the file.
 * See the interfaces man page for the syntax rules.
 */
class Interfaces {

public:
  Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
  QStringList getInterfaceList();
  
  bool isAuto(const QString &interface);
  bool setAuto(const QString &interface, bool setAuto);
  
  bool removeInterface();
  bool addInterface(const QString &interface, const QString &family, const QString &method);
  bool copyInterface(const QString &oldInterface, const QString &newInterface);
  bool setInterface(QString interface);
  inline bool isInterfaceSet();
  QString getInterfaceName(bool &error);
  bool setInterfaceName(const QString &newName);
  QString getInterfaceFamily(bool &error);
  bool setInterfaceFamily(const QString &newName);
  QString getInterfaceMethod(bool &error);
  bool setInterfaceMethod(const QString &newName);
  inline QString getInterfaceOption(const QString &option, bool &error); 
  inline bool setInterfaceOption(const QString &option, const QString &value);
  inline bool removeInterfaceOption(const QString &option, const QString &value);
  inline bool removeAllInterfaceOptions();
  
  bool setMapping(const QString &interface);
  bool removeMapping();
  inline void addMapping(const QString &options);
  inline bool setMap(const QString &map, const QString &value);
  inline bool removeMap(const QString &map, const QString &value);
  inline QString getMap(const QString &map, bool &error);
  inline bool setScript(const QString &argument);
  inline QString getScript(bool &error);
		  
  bool write();
  
private:
  bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator);
  bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value);
  bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value);
  QString getOption(const QStringList::Iterator &start, const QString &option, bool &error);
  bool removeAllOptions(const QStringList::Iterator &start);
  
  QString interfacesFile;
  QStringList interfaces;
  QStringList::Iterator currentIface;
  QStringList::Iterator currentMapping;

  QStringList acceptedFamily;
};

#endif

// interfaces