Implementation of Serice object into structure.
This commit is contained in:
		
							parent
							
								
									a2526dd3ed
								
							
						
					
					
						commit
						2cb1e3e2f2
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,3 +1,4 @@ | |||||||
| Debug | Debug | ||||||
| *.o | *.o | ||||||
| *~ | *~ | ||||||
|  | libServerCore.a | ||||||
|  | |||||||
| @ -1,8 +1,8 @@ | |||||||
| #ifndef __Command_h__ | #ifndef __Command_h__ | ||||||
| #define __Command_h__ | # define __Command_h__ | ||||||
| 
 | 
 | ||||||
| #include "includes" | # include "includes" | ||||||
| #include "Object.h" | # include "Object.h" | ||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
|     |     | ||||||
|  | |||||||
| @ -16,9 +16,7 @@ namespace core { | |||||||
|    } |    } | ||||||
|     |     | ||||||
|    bool CommandList::processRequest(std::string request, Session *session) {       |    bool CommandList::processRequest(std::string request, Session *session) {       | ||||||
| 
 |  | ||||||
|       bool found = false;       |       bool found = false;       | ||||||
|        |  | ||||||
|       for(auto *command : commands) { |       for(auto *command : commands) { | ||||||
| 	 if(command->check(request)) { | 	 if(command->check(request)) { | ||||||
| 	    command->processCommand(request, session); | 	    command->processCommand(request, session); | ||||||
| @ -26,7 +24,6 @@ namespace core { | |||||||
| 	    break; | 	    break; | ||||||
| 	 } | 	 } | ||||||
|       }   |       }   | ||||||
|        |  | ||||||
|       return found; |       return found; | ||||||
|    } |    } | ||||||
|     |     | ||||||
|  | |||||||
| @ -6,12 +6,34 @@ | |||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
| 
 | 
 | ||||||
|  |    ///
 | ||||||
|  |    /// CommandList
 | ||||||
|  |    ///
 | ||||||
|  |    /// This object organizes Command objects into a list that is used
 | ||||||
|  |    /// to parse an input and run the process associated with the 
 | ||||||
|  |    /// selected command. 
 | ||||||
|  |    ///
 | ||||||
|  |     | ||||||
|    class CommandList : public Command { |    class CommandList : public Command { | ||||||
|        |        | ||||||
|     public: |     public: | ||||||
|  |        | ||||||
|  |       ///
 | ||||||
|  |       /// The constructor for the object.
 | ||||||
|  |       ///
 | ||||||
|  |        | ||||||
|       CommandList(); |       CommandList(); | ||||||
|  |        | ||||||
|  |       ///
 | ||||||
|  |       /// The destructor for the object.
 | ||||||
|  |       ///
 | ||||||
|  |        | ||||||
|       ~CommandList(); |       ~CommandList(); | ||||||
| 
 | 
 | ||||||
|  |       ///
 | ||||||
|  |       /// Add a new command to the command list and assign a default search value.
 | ||||||
|  |       ///
 | ||||||
|  |        | ||||||
|       void add(Command &command, std::string name = ""); |       void add(Command &command, std::string name = ""); | ||||||
|        |        | ||||||
|       void remove(Command &command); |       void remove(Command &command); | ||||||
|  | |||||||
| @ -13,12 +13,12 @@ namespace core { | |||||||
|    ConsoleServer::~ConsoleServer() {} |    ConsoleServer::~ConsoleServer() {} | ||||||
|     |     | ||||||
|    void ConsoleServer::sendToConnectedConsoles(std::string out) { |    void ConsoleServer::sendToConnectedConsoles(std::string out) { | ||||||
|       for(auto *session : sessions)  |       for(auto *session : service->sessions)  | ||||||
| 	((ConsoleSession *)session)->writeLog(out); | 	((ConsoleSession *)session)->writeLog(out); | ||||||
|    } |    } | ||||||
|     |     | ||||||
|    Session * ConsoleServer::getSocketAccept() { |    Session * ConsoleServer::getSocketAccept() { | ||||||
|       return new ConsoleSession(ePoll, *this); |       return new ConsoleSession(ePoll, *this->service); | ||||||
|    } |    } | ||||||
|     |     | ||||||
|    void ConsoleServer::output(Session *session) {       |    void ConsoleServer::output(Session *session) {       | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ | |||||||
| 
 | 
 | ||||||
| #include "includes" | #include "includes" | ||||||
| #include "TCPServerSocket.h" | #include "TCPServerSocket.h" | ||||||
|  | #include "Service.h" | ||||||
| #include "Command.h" | #include "Command.h" | ||||||
| #include "Session.h" | #include "Session.h" | ||||||
| #include "EPoll.h" | #include "EPoll.h" | ||||||
|  | |||||||
| @ -1,12 +1,11 @@ | |||||||
| #include "ConsoleSession.h" | #include "ConsoleSession.h" | ||||||
|  | #include "Log.h" | ||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
|     |     | ||||||
|    ConsoleSession::ConsoleSession(EPoll &ePoll, ConsoleServer &server) : TerminalSession(ePoll, server) {  |    ConsoleSession::ConsoleSession(EPoll &ePoll, Service &service) : TerminalSession(ePoll, service) {} | ||||||
|    } |  | ||||||
|     |     | ||||||
|    ConsoleSession::~ConsoleSession() {     |    ConsoleSession::~ConsoleSession() {} | ||||||
|    } |  | ||||||
|     |     | ||||||
|    void ConsoleSession::output(std::stringstream &out) { |    void ConsoleSession::output(std::stringstream &out) { | ||||||
|       //   socket->output(out);
 |       //   socket->output(out);
 | ||||||
| @ -106,7 +105,7 @@ namespace core { | |||||||
| 	    saveCursor(); | 	    saveCursor(); | ||||||
| 	    setCursorLocation(16, 1); | 	    setCursorLocation(16, 1); | ||||||
| 	    out << "--> " << request << std::endl; | 	    out << "--> " << request << std::endl; | ||||||
| 	    server.commands.processRequest(request, this); | 	    service.commands.processRequest(request, this); | ||||||
| 	    restoreCursor(); | 	    restoreCursor(); | ||||||
| 	    send();		 | 	    send();		 | ||||||
| 	}   | 	}   | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ | |||||||
| 
 | 
 | ||||||
| #include "TerminalSession.h" | #include "TerminalSession.h" | ||||||
| #include "Session.h" | #include "Session.h" | ||||||
| #include "ConsoleServer.h" | #include "Service.h" | ||||||
| #include "CommandList.h" | #include "CommandList.h" | ||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
| @ -19,7 +19,7 @@ namespace core { | |||||||
|    class ConsoleSession : public TerminalSession { |    class ConsoleSession : public TerminalSession { | ||||||
|    |    | ||||||
|     public: |     public: | ||||||
|       ConsoleSession(EPoll &ePoll, ConsoleServer &server); |       ConsoleSession(EPoll &ePoll, Service &service); | ||||||
|       ~ConsoleSession();  |       ~ConsoleSession();  | ||||||
|     |     | ||||||
|       virtual void output(std::stringstream &out); |       virtual void output(std::stringstream &out); | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								Log.cpp
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								Log.cpp
									
									
									
									
									
								
							| @ -1,5 +1,6 @@ | |||||||
| #include "ConsoleSession.h" | #include "ConsoleSession.h" | ||||||
| #include "Log.h" | #include "Log.h" | ||||||
|  | #include "ConsoleServer.h" | ||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										19
									
								
								Session.cpp
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								Session.cpp
									
									
									
									
									
								
							| @ -1,14 +1,13 @@ | |||||||
| #include "Session.h" | #include "Session.h" | ||||||
| #include "Log.h" | #include "Log.h" | ||||||
| #include "TCPServerSocket.h" | #include "Service.h" | ||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
| 
 | 
 | ||||||
|    Session::Session(EPoll &ePoll, TCPServerSocket &server) : TCPSocket(ePoll), server(server) {  |    Session::Session(EPoll &ePoll, Service &service) : TCPSocket(ePoll), service(service) {} | ||||||
|    } |  | ||||||
|     |     | ||||||
|    Session::~Session() { |    Session::~Session() { | ||||||
|       server.removeFromSessionList(this); |       service.removeFromSessionList(this); | ||||||
|    } |    } | ||||||
|     |     | ||||||
|    void Session::init() {} |    void Session::init() {} | ||||||
| @ -17,14 +16,10 @@ namespace core { | |||||||
|       session->out << "|" << ipAddress.getClientAddressAndPort(); |       session->out << "|" << ipAddress.getClientAddressAndPort(); | ||||||
|    } |    } | ||||||
|     |     | ||||||
|    TCPServerSocket &Session::getServer() { |  | ||||||
|       return server; |  | ||||||
|    } |  | ||||||
|     |  | ||||||
|    void Session::protocol(std::string data = "") { |    void Session::protocol(std::string data = "") { | ||||||
|       if(data.length() > 0)  |       if(data.length() > 0)  | ||||||
| 			if(!server.commands.processRequest(data, this))  | 	if(!service.commands.processRequest(data, this))  | ||||||
| 				server.sessionErrorHandler("Invalid data received.", this); | 	  service.sessionErrorHandler("Invalid data received.", this); | ||||||
|    } |    } | ||||||
|     |     | ||||||
|    void Session::onConnected() { |    void Session::onConnected() { | ||||||
| @ -36,7 +31,7 @@ namespace core { | |||||||
|    } |    } | ||||||
|     |     | ||||||
|    void Session::sendToAll() { |    void Session::sendToAll() { | ||||||
|       for(auto session : server.sessions) {  |       for(auto session : service.sessions) {  | ||||||
| 	 if(session != this) | 	 if(session != this) | ||||||
| 	   session->write(out.str()); | 	   session->write(out.str()); | ||||||
|       } |       } | ||||||
| @ -44,7 +39,7 @@ namespace core { | |||||||
|    } |    } | ||||||
|     |     | ||||||
|    void Session::sendToAll(SessionFilter *filter) { |    void Session::sendToAll(SessionFilter *filter) { | ||||||
|       for(auto session : server.sessions) {  |       for(auto session : service.sessions) {  | ||||||
| 	 if(filter->test(*session)) { | 	 if(filter->test(*session)) { | ||||||
| 	    if(session != this) | 	    if(session != this) | ||||||
| 	      session->write(out.str()); | 	      session->write(out.str()); | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								Session.h
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								Session.h
									
									
									
									
									
								
							| @ -2,12 +2,12 @@ | |||||||
| #define __Session_h__ | #define __Session_h__ | ||||||
| 
 | 
 | ||||||
| #include "TCPSocket.h" | #include "TCPSocket.h" | ||||||
| //#include "TCPServerSocket.h"
 |  | ||||||
| #include "SessionFilter.h" | #include "SessionFilter.h" | ||||||
|  | //#include "Service.h"
 | ||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
|    |    | ||||||
| 	class TCPServerSocket; |    class Service; | ||||||
|     |     | ||||||
|    ///
 |    ///
 | ||||||
|    /// Session
 |    /// Session
 | ||||||
| @ -22,7 +22,7 @@ namespace core { | |||||||
|    class Session : public TCPSocket { |    class Session : public TCPSocket { | ||||||
|        |        | ||||||
|     public: |     public: | ||||||
|       Session(EPoll &ePoll, TCPServerSocket &server); |       Session(EPoll &ePoll, Service &service); | ||||||
|       ~Session();  |       ~Session();  | ||||||
|        |        | ||||||
|       virtual void init(); |       virtual void init(); | ||||||
| @ -53,8 +53,7 @@ namespace core { | |||||||
|        |        | ||||||
|       std::stringstream out; |       std::stringstream out; | ||||||
|        |        | ||||||
|       TCPServerSocket &getServer(); |       Service &service; | ||||||
|       TCPServerSocket &server; |  | ||||||
|        |        | ||||||
|     protected: |     protected: | ||||||
|        |        | ||||||
| @ -70,8 +69,6 @@ namespace core { | |||||||
|        |        | ||||||
|       virtual void protocol(std::string data);  |       virtual void protocol(std::string data);  | ||||||
|        |        | ||||||
|     private: |  | ||||||
|        |  | ||||||
|    }; |    }; | ||||||
|     |     | ||||||
| } | } | ||||||
|  | |||||||
| @ -11,24 +11,18 @@ namespace core { | |||||||
|       memset(&addr, 0, sizeof(addr)); |       memset(&addr, 0, sizeof(addr)); | ||||||
|       addr.sin_family = AF_INET; |       addr.sin_family = AF_INET; | ||||||
|       addr.sin_port = htons(port); |       addr.sin_port = htons(port); | ||||||
|        |  | ||||||
|       struct hostent *hp = gethostbyname(url.c_str()); |       struct hostent *hp = gethostbyname(url.c_str()); | ||||||
|        |  | ||||||
|       memcpy((void *)&addr.sin_addr, hp->h_addr_list[0], hp->h_length); |       memcpy((void *)&addr.sin_addr, hp->h_addr_list[0], hp->h_length); | ||||||
|        |        | ||||||
|       setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); |       setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); | ||||||
| 
 |  | ||||||
|       int yes = 1; |       int yes = 1; | ||||||
|       setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); |       setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); | ||||||
|        |  | ||||||
|       if(bind(getDescriptor(), (struct sockaddr *)&addr, sizeof(addr)) < 0)  |       if(bind(getDescriptor(), (struct sockaddr *)&addr, sizeof(addr)) < 0)  | ||||||
| 	throw Exception("Error on bind to socket"); | 	throw Exception("Error on bind to socket"); | ||||||
|        |  | ||||||
|       if(listen(getDescriptor(), 10) < 0)  |       if(listen(getDescriptor(), 10) < 0)  | ||||||
| 	throw Exception("Error on listen to socket"); | 	throw Exception("Error on listen to socket"); | ||||||
|        |  | ||||||
|       ePoll.registerSocket(this);       |       ePoll.registerSocket(this);       | ||||||
|        |       service = _getService(); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    TCPServerSocket::~TCPServerSocket() { |    TCPServerSocket::~TCPServerSocket() { | ||||||
| @ -38,51 +32,39 @@ namespace core { | |||||||
|    void TCPServerSocket::init() {} |    void TCPServerSocket::init() {} | ||||||
|     |     | ||||||
|    void TCPServerSocket::onDataReceived(std::string data) { |    void TCPServerSocket::onDataReceived(std::string data) { | ||||||
|        |  | ||||||
|       Log(LOG_DEBUG_2) << "Connection request on socket " << getDescriptor() << ".";       |       Log(LOG_DEBUG_2) << "Connection request on socket " << getDescriptor() << ".";       | ||||||
|        |  | ||||||
|       Session *session = accept(); |       Session *session = accept(); | ||||||
|       sessions.push_back(session);    |       service->sessions.push_back(session);    | ||||||
|    } |    } | ||||||
|     |     | ||||||
|    Session * TCPServerSocket::accept() {       |    Session * TCPServerSocket::accept() {       | ||||||
|        |  | ||||||
|       Session *session = getSocketAccept();       |       Session *session = getSocketAccept();       | ||||||
|       session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.address, &session->ipAddress.addressLength)); |       session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.address, &session->ipAddress.addressLength)); | ||||||
|       ePoll.registerSocket(session);    |       ePoll.registerSocket(session);    | ||||||
|        |  | ||||||
|       Log(LOG_DEBUG_2) << "Session started on socket " << session->getDescriptor() << "."; |       Log(LOG_DEBUG_2) << "Session started on socket " << session->getDescriptor() << "."; | ||||||
|        |  | ||||||
|       return session; |       return session; | ||||||
|    } |    } | ||||||
|     |     | ||||||
|    Session * TCPServerSocket::getSocketAccept() { |    Session * TCPServerSocket::getSocketAccept() { | ||||||
| 		return new Session(ePoll, *this); |       return new Session(ePoll, *service); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  |    Service * TCPServerSocket::_getService() { | ||||||
|  |       return getService(); | ||||||
|  |    } | ||||||
|  |     | ||||||
|  |    Service * TCPServerSocket::getService() { | ||||||
|  |       return new Service(*this);    | ||||||
|  |    } | ||||||
|     |     | ||||||
|    int TCPServerSocket::processCommand(std::string command, Session *session) {       |    int TCPServerSocket::processCommand(std::string command, Session *session) {       | ||||||
|        |  | ||||||
|       int sequence = 0;       |       int sequence = 0;       | ||||||
|        |       for(auto *sessionx : service->sessions) { | ||||||
|       for(auto *sessionx : sessions) { |  | ||||||
| 	 session->out << "|" << ++sequence; | 	 session->out << "|" << ++sequence; | ||||||
| 	 sessionx->output(session);  | 	 sessionx->output(session);  | ||||||
| 	 session->out << "|" << std::endl; | 	 session->out << "|" << std::endl; | ||||||
|       } |       } | ||||||
|        |  | ||||||
|       session->send(); |       session->send(); | ||||||
|    } |    } | ||||||
|     |     | ||||||
|    void TCPServerSocket::removeFromSessionList(Session *session) { |  | ||||||
|       std::vector<Session *>::iterator cursor; |  | ||||||
|       for(cursor = sessions.begin(); cursor < sessions.end(); ++cursor)   |  | ||||||
| 	if(*cursor == session) |  | ||||||
| 	  sessions.erase(cursor);    |  | ||||||
|    } |  | ||||||
|    |  | ||||||
| 	void TCPServerSocket::sessionErrorHandler(std::string errorString, Session *session) { |  | ||||||
| 		throw Exception(errorString); |  | ||||||
| 	} |  | ||||||
|   |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -3,8 +3,7 @@ | |||||||
| 
 | 
 | ||||||
| #include "Socket.h" | #include "Socket.h" | ||||||
| #include "TCPSocket.h" | #include "TCPSocket.h" | ||||||
| #include "Command.h" | #include "Service.h" | ||||||
| #include "CommandList.h" |  | ||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
|     |     | ||||||
| @ -41,23 +40,6 @@ namespace core { | |||||||
|        |        | ||||||
|       ~TCPServerSocket(); |       ~TCPServerSocket(); | ||||||
|        |        | ||||||
|       void removeFromSessionList(Session *session); |  | ||||||
|        |  | ||||||
|       ///
 |  | ||||||
|       /// The list of sessions that are currently open and being maintained by this object.
 |  | ||||||
|       ///
 |  | ||||||
|        |  | ||||||
|       std::vector<Session *> sessions;    |  | ||||||
| 
 |  | ||||||
| 		///
 |  | ||||||
| 		/// The commands object is a CommandList and is used to store Command objects to be 
 |  | ||||||
| 		/// parsed and run as data comes into the session.
 |  | ||||||
| 		///
 |  | ||||||
| 		 |  | ||||||
| 		CommandList commands; |  | ||||||
|        |  | ||||||
| 		virtual void sessionErrorHandler(std::string errorString, Session *session); |  | ||||||
| 
 |  | ||||||
|     protected: |     protected: | ||||||
|        |        | ||||||
|       virtual void init(); |       virtual void init(); | ||||||
| @ -72,6 +54,14 @@ namespace core { | |||||||
|        |        | ||||||
|       virtual Session * getSocketAccept(); |       virtual Session * getSocketAccept(); | ||||||
| 
 | 
 | ||||||
|  |       /// 
 | ||||||
|  |       /// TCP servers can have an associated Service object that provides services for
 | ||||||
|  |       /// sessions created by the server. You can extend the Service object and place 
 | ||||||
|  |       /// commands and server application support for extended servers.
 | ||||||
|  |       ///
 | ||||||
|  |        | ||||||
|  |       virtual Service * getService(); | ||||||
|  |        | ||||||
|       ///
 |       ///
 | ||||||
|       /// Override the virtual dataReceived since for the server these
 |       /// Override the virtual dataReceived since for the server these
 | ||||||
|       /// are requests to accept the new connection socket.
 |       /// are requests to accept the new connection socket.
 | ||||||
| @ -93,9 +83,12 @@ namespace core { | |||||||
|        |        | ||||||
|       int processCommand(std::string command, Session *session) override; |       int processCommand(std::string command, Session *session) override; | ||||||
| 
 | 
 | ||||||
|  |       Service *service; | ||||||
|  | 		       | ||||||
|     private: |     private: | ||||||
| 
 | 
 | ||||||
|       Session * accept(); |       Session * accept(); | ||||||
|  |       Service * _getService(); | ||||||
|        |        | ||||||
|    }; |    }; | ||||||
|     |     | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| #include "TLSServerSocket.h" | #include "TLSServerSocket.h" | ||||||
| #include "TLSSession.h" | #include "TLSSession.h" | ||||||
|  | #include "TLSService.h" | ||||||
| #include "EPoll.h" | #include "EPoll.h" | ||||||
| #include "Session.h" | #include "Session.h" | ||||||
| #include "Exception.h" | #include "Exception.h" | ||||||
| @ -18,24 +19,24 @@ namespace core { | |||||||
|    TLSServerSocket::TLSServerSocket(EPoll &ePoll, std::string url, short int port) : TCPServerSocket(ePoll, url, port) { |    TLSServerSocket::TLSServerSocket(EPoll &ePoll, std::string url, short int port) : TCPServerSocket(ePoll, url, port) { | ||||||
|       tlsServerInit();   |       tlsServerInit();   | ||||||
|       // TODO: Convert to use core::Exception object.
 |       // TODO: Convert to use core::Exception object.
 | ||||||
|       if(!(ctx = SSL_CTX_new(SSLv23_server_method())))  |       if(!(((TLSService *)service)->ctx = SSL_CTX_new(SSLv23_server_method())))  | ||||||
| 	throw std::string("Error while setting server method SSLv23.");      | 	throw Exception("Error while setting server method SSLv23.");      | ||||||
|       SSL_CTX_set_mode(ctx, SSL_MODE_RELEASE_BUFFERS | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); |       SSL_CTX_set_mode(((TLSService *)service)->ctx, SSL_MODE_RELEASE_BUFFERS | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); | ||||||
|       SSL_CTX_set_options(ctx, SSL_OP_NO_TICKET); |       SSL_CTX_set_options(((TLSService *)service)->ctx, SSL_OP_NO_TICKET); | ||||||
|       SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_SERVER); |       SSL_CTX_set_session_cache_mode(((TLSService *)service)->ctx, SSL_SESS_CACHE_SERVER); | ||||||
|       //   SSL_CTX_set_generate_session_id(ctx, generate_session_id);
 |       //   SSL_CTX_set_generate_session_id(ctx, generate_session_id);
 | ||||||
|       SSL_CTX_set_cipher_list(ctx, "ECDH-ECDSA-AES256-GCM-SHA384:DHE-DSS-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA256:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA"); |       SSL_CTX_set_cipher_list(((TLSService *)service)->ctx, "ECDH-ECDSA-AES256-GCM-SHA384:DHE-DSS-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA256:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA"); | ||||||
|       if(SSL_CTX_use_certificate_file(ctx, sip_cert, SSL_FILETYPE_PEM) <= 0)  |       if(SSL_CTX_use_certificate_file(((TLSService *)service)->ctx, sip_cert, SSL_FILETYPE_PEM) <= 0)  | ||||||
| 	throw Exception("Error looking up certificate."); | 	throw Exception("Error looking up certificate."); | ||||||
|       if(SSL_CTX_use_PrivateKey_file(ctx, sip_key, SSL_FILETYPE_PEM) < 0) |       if(SSL_CTX_use_PrivateKey_file(((TLSService *)service)->ctx, sip_key, SSL_FILETYPE_PEM) < 0) | ||||||
| 	throw Exception("Error with private key."); | 	throw Exception("Error with private key."); | ||||||
|       if(SSL_CTX_check_private_key(ctx) != 1) |       if(SSL_CTX_check_private_key(((TLSService *)service)->ctx) != 1) | ||||||
| 	throw Exception("Private key does not match certificate."); | 	throw Exception("Private key does not match certificate."); | ||||||
|       SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL); |       SSL_CTX_set_verify(((TLSService *)service)->ctx, SSL_VERIFY_PEER, NULL); | ||||||
|       SSL_CTX_set_verify_depth(ctx, 1); |       SSL_CTX_set_verify_depth(((TLSService *)service)->ctx, 1); | ||||||
|       if(!SSL_CTX_load_verify_locations(ctx, sip_cacert, NULL)) |       if(!SSL_CTX_load_verify_locations(((TLSService *)service)->ctx, sip_cacert, NULL)) | ||||||
| 	throw Exception("Cannot verify locations."); | 	throw Exception("Cannot verify locations."); | ||||||
|       SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(sip_cacert));        |       SSL_CTX_set_client_CA_list(((TLSService *)service)->ctx, SSL_load_client_CA_file(sip_cacert));        | ||||||
|       Log(LOG_DEBUG_1) << "Server key authenticated."; |       Log(LOG_DEBUG_1) << "Server key authenticated."; | ||||||
|    } |    } | ||||||
|     |     | ||||||
| @ -59,8 +60,13 @@ namespace core { | |||||||
|    } |    } | ||||||
|     |     | ||||||
|    Session * TLSServerSocket::getSocketAccept() { |    Session * TLSServerSocket::getSocketAccept() { | ||||||
|       Session *session = new TLSSession(ePoll, *this); |       Session *session = new TLSSession(ePoll, *this->service); | ||||||
|       return session; |       return session; | ||||||
|    } |    } | ||||||
|     |     | ||||||
|  |    Service * TLSServerSocket::getService() { | ||||||
|  |       return new TLSService(*this); | ||||||
|  |    } | ||||||
|  |     | ||||||
|  |     | ||||||
| } | } | ||||||
|  | |||||||
| @ -5,12 +5,7 @@ | |||||||
| #include "TCPServerSocket.h" | #include "TCPServerSocket.h" | ||||||
| #include "Command.h" | #include "Command.h" | ||||||
| #include "Session.h" | #include "Session.h" | ||||||
| #include <openssl/ssl.h> |  | ||||||
| #include <openssl/rand.h> |  | ||||||
| #include <openssl/err.h> |  | ||||||
| 
 | 
 | ||||||
| // Global values used by all TLS functions for this server socket.
 |  | ||||||
| // 
 |  | ||||||
| namespace core { | namespace core { | ||||||
|     |     | ||||||
|    ///
 |    ///
 | ||||||
| @ -41,10 +36,11 @@ namespace core { | |||||||
|        |        | ||||||
|       ~TLSServerSocket();  |       ~TLSServerSocket();  | ||||||
|        |        | ||||||
|       SSL_CTX *ctx; | //      SSL_CTX *ctx;
 | ||||||
|        |        | ||||||
|     protected: |     protected: | ||||||
|       Session * getSocketAccept() override; |       Session * getSocketAccept() override; | ||||||
|  |       Service * getService() override; | ||||||
|        |        | ||||||
|     private: |     private: | ||||||
|       void tlsServerInit(); |       void tlsServerInit(); | ||||||
|  | |||||||
| @ -1,8 +1,9 @@ | |||||||
| #include "TLSSession.h" | #include "TLSSession.h" | ||||||
|  | #include "TLSService.h" | ||||||
| #include "EPoll.h" | #include "EPoll.h" | ||||||
| #include "Log.h" | #include "Log.h" | ||||||
| #include "Exception.h" | #include "Exception.h" | ||||||
| #include <openssl/rand.h> | //#include <openssl/rand.h>
 | ||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
|     |     | ||||||
| @ -32,7 +33,7 @@ namespace core { | |||||||
| 	Log(LOG_DEBUG_3) << "No client certificate."; | 	Log(LOG_DEBUG_3) << "No client certificate."; | ||||||
|    } |    } | ||||||
|     |     | ||||||
|    TLSSession::TLSSession(EPoll &ePoll, TLSServerSocket &server) : Session(ePoll, server) {} |    TLSSession::TLSSession(EPoll &ePoll, Service &service) : Session(ePoll, service) {} | ||||||
|     |     | ||||||
|    void TLSSession::init() { |    void TLSSession::init() { | ||||||
|        |        | ||||||
| @ -44,7 +45,7 @@ namespace core { | |||||||
|        |        | ||||||
|       fcntl(getDescriptor(), F_SETFL, fcntl(getDescriptor(), F_GETFL, 0) | O_NONBLOCK); |       fcntl(getDescriptor(), F_SETFL, fcntl(getDescriptor(), F_GETFL, 0) | O_NONBLOCK); | ||||||
|        |        | ||||||
|       if(!(ssl = SSL_new(((core::TLSServerSocket &)server).ctx)))  |       if(!(ssl = SSL_new(((TLSService &)service).ctx)))  | ||||||
| 	throw std::string("Error creating new TLS socket.");      | 	throw std::string("Error creating new TLS socket.");      | ||||||
|        |        | ||||||
|       SSL_set_info_callback(ssl, handshake_complete); |       SSL_set_info_callback(ssl, handshake_complete); | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ namespace core { | |||||||
| 
 | 
 | ||||||
|     public: |     public: | ||||||
|        |        | ||||||
|       TLSSession(EPoll &ePoll, TLSServerSocket &server); |       TLSSession(EPoll &ePoll, Service &service); | ||||||
|       ~TLSSession(); |       ~TLSSession(); | ||||||
|        |        | ||||||
|       ///
 |       ///
 | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ | |||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
| 
 | 
 | ||||||
|    TerminalSession::TerminalSession(EPoll &ePoll, TCPServerSocket &server) : Session(ePoll, server) { |    TerminalSession::TerminalSession(EPoll &ePoll, Service &service) : Session(ePoll, service) { | ||||||
|    } |    } | ||||||
|     |     | ||||||
|    TerminalSession::~TerminalSession() { |    TerminalSession::~TerminalSession() { | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ | |||||||
| 
 | 
 | ||||||
| #include "includes" | #include "includes" | ||||||
| #include "Session.h" | #include "Session.h" | ||||||
|  | #include "TCPServerSocket.h" | ||||||
| 
 | 
 | ||||||
| namespace core { | namespace core { | ||||||
|     |     | ||||||
| @ -29,7 +30,7 @@ namespace core { | |||||||
|    class TerminalSession : public Session { |    class TerminalSession : public Session { | ||||||
|        |        | ||||||
|     public:    |     public:    | ||||||
|       TerminalSession(EPoll &ePoll, TCPServerSocket &server); |       TerminalSession(EPoll &ePoll, Service &service); | ||||||
|       ~TerminalSession(); |       ~TerminalSession(); | ||||||
|        |        | ||||||
|       int getLines(); |       int getLines(); | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								compile
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								compile
									
									
									
									
									
								
							| @ -11,11 +11,21 @@ do | |||||||
|     echo "OK" |     echo "OK" | ||||||
|    else |    else | ||||||
|     echo "ERROR" |     echo "ERROR" | ||||||
|  |     exit -1 | ||||||
|    fi    |    fi    | ||||||
|     |     | ||||||
| done | done | ||||||
| 
 | 
 | ||||||
| wait | wait | ||||||
| echo $list | echo -n "Building static library libServerCore.a..." | ||||||
| g++ -o main.cpp $list  | ar rcs libServerCore.a $list | ||||||
|  | if [ $? = '0' ] | ||||||
|  | then | ||||||
|  |  echo "OK" | ||||||
|  | else | ||||||
|  |  echo "ERROR" | ||||||
|  |  exit -1 | ||||||
|  | fi    | ||||||
| 
 | 
 | ||||||
|  | rm *.o | ||||||
|  | rm *~ | ||||||
|  | |||||||
							
								
								
									
										20
									
								
								compile~
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								compile~
									
									
									
									
									
								
							| @ -1,20 +0,0 @@ | |||||||
| #!/bin/bash |  | ||||||
| 
 |  | ||||||
| for file in *.cpp |  | ||||||
| do |  | ||||||
|    filename="${file%.*}" |  | ||||||
|    list="$list, $filename.o"   |  | ||||||
|    echo -n "Compiling $filename..." |  | ||||||
|    g++ -c $file |  | ||||||
|    if [ $? = '0' ] |  | ||||||
|    then |  | ||||||
|     echo "OK" |  | ||||||
|    else |  | ||||||
|     echo "ERROR" |  | ||||||
|    fi    |  | ||||||
|     |  | ||||||
| done |  | ||||||
| 
 |  | ||||||
| wait |  | ||||||
| echo $list |  | ||||||
| 
 |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Brad Arant
						Brad Arant