ArnLib  4.0.x
Active Registry Network
ArnServer.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2022 Michael Wiklund.
2 // All rights reserved.
3 // Contact: arnlib@wiklunden.se
4 //
5 // This file is part of the ArnLib - Active Registry Network.
6 // Parts of ArnLib depend on Qt and/or other libraries that have their own
7 // licenses. Usage of these other libraries is subject to their respective
8 // license agreements.
9 //
10 // GNU Lesser General Public License Usage
11 // This file may be used under the terms of the GNU Lesser General Public
12 // License version 2.1 as published by the Free Software Foundation and
13 // appearing in the file LICENSE_LGPL.txt included in the packaging of this
14 // file. In addition, as a special exception, you may use the rights described
15 // in the Nokia Qt LGPL Exception version 1.1, included in the file
16 // LGPL_EXCEPTION.txt in this package.
17 //
18 // GNU General Public License Usage
19 // Alternatively, this file may be used under the terms of the GNU General Public
20 // License version 3.0 as published by the Free Software Foundation and appearing
21 // in the file LICENSE_GPL.txt included in the packaging of this file.
22 //
23 // Other Usage
24 // Alternatively, this file may be used in accordance with the terms and conditions
25 // contained in a signed written agreement between you and Michael Wiklund.
26 //
27 // This program is distributed in the hope that it will be useful, but WITHOUT ANY
28 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
29 // PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
30 //
31 
32 #ifndef ARNSERVER_HPP
33 #define ARNSERVER_HPP
34 
35 #include "ArnLib_global.hpp"
36 #include "Arn.hpp"
37 #include "MQFlags.hpp"
38 #include "XStringMap.hpp"
39 #include <QObject>
40 #include <QHostAddress>
41 #include <QMap>
42 #include <QStringList>
43 
44 class ArnServerPrivate;
45 class ArnSync;
46 class ArnSyncLogin;
47 class ArnItemNetEar;
48 class ArnServer;
49 class QTcpServer;
50 class QTcpSocket;
51 
52 
53 class ArnServerSession : public QObject
54 {
55  Q_OBJECT
56 public:
57  ArnServerSession( QTcpSocket* socket, ArnServer* arnServer);
58 
59  QTcpSocket* socket() const;
61  QString loginUserName() const;
62  Arn::Allow getAllow() const;
63  void sendMessage( int type, const QByteArray& data = QByteArray());
64  bool getTraffic( quint64& in, quint64& out) const;
65 
66 signals:
67  void infoReceived( int type);
68  void loginCompleted();
69  void messageReceived( int type, const QByteArray& data);
70 
71 private slots:
72  void shutdown();
73  void doDestroyArnTree( const QString& path, bool isGlobal);
74  void onCommandDelete( const QString& path);
75  void doSyncStateChanged( int state);
76 
77 private:
78  QTcpSocket* _socket;
79  ArnServer* _arnServer;
80  ArnSync* _arnNetSync;
81  ArnItemNetEar* _arnNetEar;
82 };
83 
84 
86 
98 class ARNLIBSHARED_EXPORT ArnServer : public QObject
99 {
100  Q_OBJECT
101  Q_DECLARE_PRIVATE(ArnServer)
102 
103 public:
104  struct Type {
105  enum E {
106  NetSync
107  };
109  };
110 
112 
115  ArnServer( Type serverType, QObject *parent = arnNullptr);
116 
117  ~ArnServer();
118 
120 
124  void start( int port = -1, QHostAddress listenAddr = QHostAddress::Any);
125 
127 
129  int port();
130 
132 
135  QHostAddress listenAddress();
136 
138 
149  void addAccess( const QString& userName, const QString& password, Arn::Allow allow);
150 
152 
156  bool isDemandLogin() const;
157 
159 
163  void setDemandLogin( bool isDemandLogin);
164 
166 
175  void setNoLoginNets( const QStringList& noLoginNets);
176 
178 
181  QStringList noLoginNets() const;
182 
184 
188  bool isDemandLoginNet( const QHostAddress& remoteAddr) const;
189 
191 
199  void addFreePath( const QString& path);
200 
202 
206  QStringList freePaths() const;
207 
209 
222  void setWhoIAm( const Arn::XStringMap& whoIAmXsm);
223 
225  ArnSyncLogin* arnLogin() const;
226  ArnServerSession* getSession() const;
227  QByteArray whoIAm() const;
228 
229 signals:
230  void newSession();
231 
232 protected:
233  ArnServer( ArnServerPrivate& dd, QObject* parent);
234  ArnServerPrivate* const d_ptr;
236 
237 private slots:
238  void tcpConnection();
239 
240 private:
241 };
242 
243 #endif // ARNSERVER_HPP
Arn::XStringMap remoteWhoIAm() const
Definition: ArnServer.cpp:137
QTcpSocket * socket() const
Definition: ArnServer.cpp:131
Class for making an Arn Server.
Definition: ArnServer.hpp:98
Container class with string representation for serialized data.
Definition: XStringMap.hpp:107
bool getTraffic(quint64 &in, quint64 &out) const
Definition: ArnServer.cpp:169
ArnServerSession(QTcpSocket *socket, ArnServer *arnServer)
Definition: ArnServer.cpp:51
void messageReceived(int type, const QByteArray &data)
void infoReceived(int type)
QString loginUserName() const
Definition: ArnServer.cpp:145
#define ARNLIBSHARED_EXPORT
void sendMessage(int type, const QByteArray &data=QByteArray())
Definition: ArnServer.cpp:161
#define MQ_DECLARE_ENUM(EStruct)
Enums.
Definition: MQFlagsBase.hpp:70
Arn::Allow getAllow() const
Definition: ArnServer.cpp:153