summaryrefslogtreecommitdiff
path: root/client/SslClient.h
blob: 3a00de509f7fd6a91f2bb329f0cd4afa8f851d21 (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

#ifndef SSL_CLIENT_H
#define SSL_CLIENT_H

#include <QAbstractSocket>
#include <QObject>
#include "client.h"

using std::string;

class QByteArray;
class QSslSocket;
class QSslError;
class QString;

/**
 * @brief	Client-server communication class<br/>
 * 			- Uses SSL protocol to communicate with server
 * 			- Requests config/static or generic proxy lists/firewall list
 * 			- Server port - 13666
 * 			- Request format: [0x13 0x13 rcode 0x14 0x14]
 * 			- Reply format: [0x13 0x13 rcode [data] 0x14 0x14]
 * 			- Request codes:
 * 				-# 0x01 - request client config
 *				-# 0x02 - request generic proxy list
 * 				-# 0x04 - request static proxy list
 * 				-# 0x08 - request firewall host list
 */
class SslClient: public QObject
{
	Q_OBJECT
public:
	/**
	 * @enum	RequestType	Enumerates all possible request types
	 */
	enum RequestType
	{
		/**
		 * @brief	Request generic config
		 */
		Config = 0x01,
		/**
		 * @brief	Request generic proxy list
		 */
		GenericProxyList = 0x02,
		/**
		 * @brief	Request static proxy list
		 */
		StaticProxyList = 0x04,
		/**
		 * @brief	Request list of firewalled hosts
		 */
		FirewallList = 0x08
	};
	
	/**
	 * @brief	setup ssl socket ans it's type, certificates and key<br/>
	 * 			Default server address will be used: 127.0.0.1
	 */
	SslClient();
	
	/**
	 * @brief	setup ssl socket ans it's type, certificates and key
	 * @param	addr	server address or hostname to connect to
	 */
	SslClient(string &addr);
	
	/**
	 * @brief 	setup ssl socket ans it's type, certificates and key
	 * @param	addr	server address or hostname to connect to
	 */
	SslClient(char* addr);
	
	/**
	 * @brief	set server address to connect to
	 * @param	addr	server address or hostname to connect to
	 */
	void SetServerAddr(char* addr);
	
	/**
	 * @brief	Request generic proxy list
	 * @param	type	type of request to send
	 */
	void SendRequest(RequestType type);
signals:
	/**
	 * @brief	This signal is emited when data is recieved as a reply to
	 *			particular request
	 * @param	type	of request this reply corresponds to
	 */
	void ReplyRecieved(SslClient::RequestType &type, QByteArray &confdata);
private slots:
	void Connected();
	void Disconnected();
	void DataRecieved();
	void Error(QAbstractSocket::SocketError socketError);
	void PeerVerifyError(const QSslError &error);
	void SslErrors(const QList<QSslError> &errors);
private:
	QSslSocket *sslSocket;
	QString server;
	unsigned short port;
};

#endif