summaryrefslogtreecommitdiffstats
path: root/knetworkconf/knetworkconf/knetworkconfigparser.h
blob: f0af15f64333a03d8816a2991f4a98bc22c932c2 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/***************************************************************************
                          knetworkconfigparser.h  -  description
                             -------------------
    begin                : Mon Jan 13 2003
    copyright            : (C) 2003 by Juan Luis Baptiste
    email                : jbaptiste@merlinux.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KNETWORKCONFIGPARSER_H
#define KNETWORKCONFIGPARSER_H

#define BACKEND_PATH "knetworkconf/backends/network-conf"
#define ETHERNET_IFACE_TYPE "ethernet"
#define WIRELESS_IFACE_TYPE "wireless"
#define LOOPBACK_IFACE_TYPE "loopback"

#define WIRELESS_WEP_KEY_TYPE_ASCII "ascii"
#define WIRELESS_WEP_KEY_TYPE_HEXADECIMAL "hexadecimal"

#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

#include <kapp.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <tqobject.h>
#include <tqdir.h>
#include <tqfile.h>
#include <tqstring.h>
#include <tqprocess.h>
#include <tqdom.h>
#include <tqlabel.h>
#include <tqcheckbox.h>

#include <klistbox.h>
#include <ksimpleconfig.h>
#include <kstandarddirs.h>
#include <kdebug.h>

#include "knetworkinfo.h"
#include "kdetectdistrodlg.h"
#include "kreloadnetworkdlg.h"
#include "kinterfaceupdowndlg.h"
#include "kselectdistrodlg.h"

/**
  *@author Juan Luis Baptiste
  */

class KNetworkConfigParser : public TQObject {
  Q_OBJECT
  public:
    KNetworkConfigParser();
    ~KNetworkConfigParser();
    /** return tyhe number of configured devices. */
    unsigned numDevices();
    void setProgramVersion(TQString ver);
    /** Reads /proc/net/route looking for the default gateway. */
    void loadRoutingInfo(KRoutingInfo *routingInfo);
    /** Saves the new network configuration. */
    void saveNetworkInfo(KNetworkInfo *networkInfo);
    /** Loads the network info from a xml file generated by the gnome system tools
        network backends that are included with this app. */
    KNetworkInfo * getNetworkInfo();
    TQProcess * proc;
    TQProcess * procDetect;
    TQProcess * procSaveNetworkInfo;
    /** Variable to know if there is an dhcp device configured, so we can know if we need to save the defauilt gw info or not. */
    bool dhcpDevice;
    KNetworkInterface * getDeviceInfo(TQString device);


  public slots:
    /** runs gst to find out the state of network devices.It runs the command:
    $knetworkconf_home/backends/networkconf [--platform platform] -d list_ifaces */
    void listIfaces(const TQString &platform);

  private slots:
   /** Runs the gst backend to get network values. You can pass to the script a specific platform to load using the platform parameter.  */
    void runDetectionScript(TQString platform);  
    void readIfconfigOutput();
    void readNetworkInfo();
    void readFromStdoutReloadScript();
    /** emits a signal when the network changes have benn saved. */
    void sendNetworkInfoSavedSignalSlot();
    /** Concatenates into a TQString the xml output of the network backend. */
    void concatXMLOutputSlot();
    void readXMLErrSlot();
    /** Shows the dialog with all the supported platforms by GST. */
    void showSupportedPlatformsDialogSlot();
    /** Parses the xml ouput generated by GST that has all the supported platforms. */
    void readSupportedPlatformsSlot();
    /** No descriptions */
    void readListIfacesSlot();
    void readFromStdoutSaveNetworkInfo();
    /** Calls runDetectionScript(). */
    void listIfacesSlot();
    /** save process has exited */
    void processExitedSlot();
                
  private:
    //TQPtrList<KNetworkInterface> deviceList;
    TQPtrList<KNetworkInterface>  tempList;
    KNetworkInterface *newDevice;
    bool isUp;
    /** Counts the number of configured devices that had been found. */
    unsigned _numDevices;
    KRoutingInfo *routingInfo;
    KDNSInfo *dnsInfo;
    TQString programVersion;
    /**  The output of ifconfig command that needs to be parsed in readIfconfigOutput()*/
    TQString ifconfigOutput;
    KNetworkInfo * networkInfo;
    TQPtrList<KKnownHostInfo> knownHostsList;
    TQString hexIPv4ToDecIPv4(const TQString &hex);
    /** lists all platforms supported by GST. */
    void loadSupportedPlatforms();
    /** Returns the info of a platform in the form of 'key:value' . */
    TQString getPlatformInfo(TQDomElement platform);
    /** save process is running */
    bool processRunning;

    /** Shows a progress dialog while the networl is being reloaded. */
    KInterfaceUpDownDlg * kpdReloadStatusDlg;
    TQProcess *procReloadNetwork;
    TQString reloadScriptOutput;
    /** Contains the network configuration en xml format. */
    /** List of supported platforms. */
    TQStringList supportedPlatformsList;
    TQString xmlOuput;
    TQString xmlErr;
    /** Temporal device list to be used when loading the dhcp devices info */
    TQPtrList<KNetworkInterface> tempDevList;
    /** Parses all of the <statichost>...</statichost> entries in the xml configuration file. */
    KKnownHostInfo * getStaticHostInfo(TQDomElement host);
    /** Saves the option to show again or not the platform using KSimpleConfig*/
    void saveAskAgain(const TQString &platform, bool askAgain);
    /**Returns if the show platform should be shown again or not and the saved platform*/
    bool readAskAgain(TQString &platform);
    void parseNetworkInfo(TQDomNode node, KNetworkInfo *networkInfo, bool isProfile);
    void addRoutingInfoToXMLDoc(TQDomDocument *doc, TQDomNode *root, KRoutingInfo *routingInfo);
    void addDNSInfoToXMLDoc(TQDomDocument *doc, TQDomNode *root, KDNSInfo *dnsInfo);    
    void addNetworkInterfacesToXMLDoc(TQDomDocument *doc, TQDomNode *root, TQPtrList<KNetworkInterface> devList);
    void addNetworkProfilesToXMLDoc(TQDomDocument *doc, TQDomNode *root, TQPtrList<KNetworkInfo> profileList);
    
  protected: // Protected methods
    /** Parses all of the <interface>...</interface> entries in the xml configuration file. */
    virtual KNetworkInterface *getInterfaceInfo(TQDomElement interface, const TQString &type);
    /** Parses all of the <interface>...</interface> entries in the xml configuration file. Returns a KWirelessInterface 
    object that contains all the info of the wireless interface. */    
    virtual KWirelessInterface *getWirelessInterfaceInfo(TQDomElement interface, const TQString &type);

  signals: // Signals
    /** emmited when the xml file is finished reading. */
    void readyLoadingNetworkInfo();
    
    /** emmited when the xml file saved and the backend has finished executing. */
//    void readySavingNetworkInfo();
    
    /** Signal that is sent when fillDevices() has finished fllind the dhcp devices. */
    void readyIfconfigOutputSignal();
    /** Signal emmited when the platform can't be auto-detected. */
    void errorDetectingPlatform();
    /** signal emmited when the parsing of the xml of the supported platform list. */
    void readyLoadingSupportedPlatforms();
    /** signal emmited when the config parser needs to set read only the GUI because 
        some error in the parsing, or the platform isn't supported.*/
    void setReadOnly(bool);
};

#endif