RDK Documentation (Open Sourced RDK Components)
tcpOpensslProxyServer.h
1 #ifndef TRM_QT_WEBSOCKETSERVER_H
2 #define TRM_QT_WEBSOCKETSERVER_H
3 
4 #include <openssl/ssl.h>
5 
6 #include <iostream>
7 #include <QtCore/QObject>
8 #include <QString>
9 
10 #include <unordered_map>
11 #include <functional>
12 
13 #include <chrono> // std::chrono::seconds
14 
15 class tcpOpensslProxyServer : public QObject
16 {
17 Q_OBJECT
18 
19 public:
22  int setUpServer(const char* ipAddress, unsigned short port_num, const char *ca_pem,
23  const char *cert_pem, const char *key_pem);
24 
25 signals:
26  void newConnection (int clientId, tcpOpensslProxyServer* ss);
27  void connected (int clientId, QString msg);
28  void messageReceived (int clientId, char* message, size_t len);
29  void disconnected (int clientId);
30  void socketError (QString err);
31  void sslErrors (QString err);
32  void acceptError (QString err);
33  void peerVerifyError (QString err);
34 
35 
36 private:
37  void freeSSLContext(SSL_CTX *ctx);
38  SSL_CTX * get_server_context_pk12(const char *ca_pem,
39  const char *cert_pk12, const char *pass);
40  int get_socket(const char* ipAddress, unsigned short port_num);
41  bool SetSocketBlockingEnabled(int fd, bool blocking);
42 
43  void onSocketError (QString err);
44  void setPingMsg (int clientId, const char* uniqueId, int len);
45  std::unordered_map <int, std::chrono::high_resolution_clock::time_point> m_clientPingTimeList;
46 
47 public:
48  bool m_isServerprocessingEnabled;
49  std::unordered_map <int, SSL*> m_clientSSLCtxList;
50  std::unordered_map <int, bool*> m_clientSSLIsReadEnabledList;
51  std::unordered_map <int, std::string> m_clientPingMsgList;
52  SSL_CTX *m_serverSSlCtx;
53  int m_serverSocketListenfd;
54  tcpOpensslProxyServer* m_instanceServer;
55 
56  std::function<void(int, char*, unsigned int)> onMessageReceivedCallBack;
57  std::function<void(int, long long unsigned int, QByteArray&)> onPongCallBack;
58 
59  void closeClient(int clientId);
60  void closeAllClients();
61  void stopServer();
62 
63  void onNewConnection (int clientId, tcpOpensslProxyServer* ss);
64  void onConnected (int clientId, QString msg);
65  void onMessageReceived (int clientId, char* message, size_t len);
66  void onDisconnected (int clientId);
67  void onSslErrors (QString err);
68  void onPeerVerifyError (QString err);
69  void onAcceptError (QString err);
70 
71  void sendTextMessage (int clientId, const char* buffer, int len);
72  void ping (int clientId);
73  void onPong (int clientId, char* msg, int len);
74 };
75 
76 #endif //TRM_QT_WEBSOCKETSERVER_H
tcpOpensslProxyServer
Definition: tcpOpensslProxyServer.h:15