-
Notifications
You must be signed in to change notification settings - Fork 2
/
igddevice.h
80 lines (72 loc) · 2.04 KB
/
igddevice.h
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
#ifndef IGDDEVICE_H
#define IGDDEVICE_H
#include <QObject>
#include <QThread>
#include <QMutex>
#include <QStandardItemModel>
#include <QStandardItem>
#include <miniupnpc/miniupnpc.h>
#include <miniupnpc/upnpcommands.h>
class ScanThread : public QThread {
Q_OBJECT
protected:
void run();
public:
ScanThread(QObject*, UPNPDev*&, QMutex&);
private:
UPNPDev * & devlist;
QMutex & devlist_mutex;
};
class IGDDevice : public QObject {
Q_OBJECT
public:
IGDDevice(QObject *parent = NULL);
~IGDDevice();
static const int PortProtoSortRole = Qt::UserRole,
ExternalPortRole = Qt::UserRole + 1,
InternalIpRole = Qt::UserRole + 2,
InternalPortRole = Qt::UserRole + 3,
ProtocolRole = Qt::UserRole + 4,
DescriptionRole = Qt::UserRole + 5,
EnabledRole = Qt::UserRole + 6,
RemoteHostRole = Qt::UserRole + 7,
DurationRole = Qt::UserRole + 8;
static const uint ProtoInvalid = 2, ProtoTcp = 0, ProtoUdp = 1;
bool validIGD() {
return hasValidIGD;
}
const char* getLanIp() {
if(!validIGD()) {
return NULL;
}
return lanaddr;
}
const char* getExternalIp() {
if(!validIGD()) {
return NULL;
}
return externalip;
}
bool isConnected() { return connected; }
bool deletePortMapping(QString &error, QStandardItem *m);
bool addPortMappingFromStrings(QString &error, const QString &ExtPort, const QString &Protocol, const QString &IntPort, const QString &IntClient, const QString &Description);
QStandardItemModel *getForwardDataModel() { return mForwardData; }
public slots:
void scan();
void refresh();
signals:
void IgdStartScan();
void IgdScanFinished();
void IgdDataRefreshed();
private:
bool hasValidIGD, connected;
ScanThread *scanner;
QMutex devlist_mutex;
struct UPNPDev *devlist, *dev;
struct UPNPUrls urls;
struct IGDdatas data;
char lanaddr[16], externalip[16];
QStandardItemModel *mForwardData;
void readPortMappingsIntoModel();
};
#endif