libktorrent  2.1.1
upnprouter.h
1 /***************************************************************************
2  * Copyright (C) 2005-2007 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #ifndef KTUPNPROUTER_H
22 #define KTUPNPROUTER_H
23 
24 #include <QUrl>
25 #include <QStringList>
26 
27 #include <net/portlist.h>
28 #include <ktorrent_export.h>
29 
30 class KJob;
31 
32 namespace bt
33 {
34  class HTTPRequest;
35  class WaitJob;
36 
40  struct KTORRENT_EXPORT UPnPService
41  {
42  QString serviceid;
43  QString servicetype;
44  QString controlurl;
45  QString eventsuburl;
46  QString scpdurl;
47 
48  UPnPService();
49  UPnPService(const UPnPService & s);
50 
56  void setProperty(const QString & name,const QString & value);
57 
61  void clear();
62 
68  UPnPService & operator = (const UPnPService & s);
69  };
70 
74  struct KTORRENT_EXPORT UPnPDeviceDescription
75  {
76  QString friendlyName;
77  QString manufacturer;
78  QString modelDescription;
79  QString modelName;
80  QString modelNumber;
81 
87  void setProperty(const QString & name,const QString & value);
88  };
89 
96  class KTORRENT_EXPORT UPnPRouter : public QObject
97  {
98  Q_OBJECT
99  public:
106  UPnPRouter(const QString & server,const QUrl &location,bool verbose = false);
107  ~UPnPRouter() override;
108 
110  void setVerbose(bool v);
111 
113  QString getServer() const;
114 
116  QUrl getLocation() const;
117 
120 
123 
125  QString getError() const;
126 
128  QString getExternalIP() const;
129 
134 
139  void addService(const UPnPService & s);
140 
141 #if 0
142 
146  void isPortForwarded(const net::Port & port);
147 #endif
148 
153  void forward(const net::Port & port);
154 
161  void undoForward(const net::Port & port,bt::WaitJob* waitjob = 0);
162 
166  class Visitor
167  {
168  public:
169  virtual ~Visitor() {}
170 
177  virtual void forwarding(const net::Port & port, bool pending, const UPnPService* service) = 0;
178  };
179 
184  void visit(Visitor* visitor) const;
185 
186 
187  private Q_SLOTS:
188  void forwardResult(HTTPRequest* r);
189  void undoForwardResult(HTTPRequest* r);
190  void getExternalIPResult(HTTPRequest* r);
191  void downloadFinished(KJob* j);
192 
193  Q_SIGNALS:
197  void stateChanged();
198 
204  void xmlFileDownloaded(UPnPRouter* r,bool success);
205 
206  private:
207  class UPnPRouterPrivate;
208  UPnPRouterPrivate* d;
209  };
210 
211 }
212 
213 #endif
bt::UPnPRouter::downloadXMLFile
void downloadXMLFile()
bt::UPnPDeviceDescription::setProperty
void setProperty(const QString &name, const QString &value)
bt::UPnPRouter::getLocation
QUrl getLocation() const
Get the location of it's xml description.
bt::UPnPRouter::addService
void addService(const UPnPService &s)
bt::WaitJob
Definition: waitjob.h:57
bt::UPnPRouter::getDescription
const UPnPDeviceDescription & getDescription() const
Get the device description (const version)
bt::UPnPRouter::getExternalIP
QString getExternalIP() const
Get the router's external IP.
bt::UPnPService
Definition: upnprouter.h:41
bt::UPnPRouter::getError
QString getError() const
Get the current error (null string if there is none)
bt::UPnPRouter::undoForward
void undoForward(const net::Port &port, bt::WaitJob *waitjob=0)
bt::UPnPRouter::getServer
QString getServer() const
Get the name of the server.
bt::HTTPRequest
Definition: httprequest.h:59
bt::UPnPRouter
Definition: upnprouter.h:97
bt::UPnPRouter::getDescription
UPnPDeviceDescription & getDescription()
Get the device description.
bt::UPnPDeviceDescription
Definition: upnprouter.h:75
bt::UPnPRouter::visit
void visit(Visitor *visitor) const
bt::UPnPRouter::setVerbose
void setVerbose(bool v)
Disable or enable verbose logging.
bt::UPnPService::clear
void clear()
net::Port
Definition: portlist.h:54
bt::UPnPRouter::Visitor::forwarding
virtual void forwarding(const net::Port &port, bool pending, const UPnPService *service)=0
bt::UPnPRouter::xmlFileDownloaded
void xmlFileDownloaded(UPnPRouter *r, bool success)
bt::UPnPRouter::Visitor
Definition: upnprouter.h:167
bt::UPnPRouter::forward
void forward(const net::Port &port)
bt::UPnPService::setProperty
void setProperty(const QString &name, const QString &value)
bt::UPnPRouter::stateChanged
void stateChanged()
bt::UPnPRouter::UPnPRouter
UPnPRouter(const QString &server, const QUrl &location, bool verbose=false)