diff --git a/sls/trunk/BUGS b/sls/trunk/BUGS new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/sls/trunk/TODO b/sls/trunk/TODO index 6e098cb649ea1ea39725a1afa2158dc214161d5e..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/sls/trunk/TODO +++ b/sls/trunk/TODO @@ -1,4 +0,0 @@ -Gerer les control-C sur les sockets. Le server ne ferme pas la connection... -Implementer un conn id pour qu'un serveur puisse numeroter les connecxions - - diff --git a/sls/trunk/src/client.cc b/sls/trunk/src/client.cc index ae6b77fedd5512d93f31e90f509386313739be48..48880188d2f7e37319c95901a58fdae3be7708cc 100644 --- a/sls/trunk/src/client.cc +++ b/sls/trunk/src/client.cc @@ -35,7 +35,13 @@ Client *Client::login(Connection &c) { return login_fail(c); if (sscanf(slogin.c_str(), "HOST %512s\n", loginbuf) == 1) { - std::cout << "Host " << loginbuf << " logged from " << c.getremoteip() + // check login and password + + // Register login and pass in client + + // Print succefful login + std::cout << "Connection id " << c.getid() << ": Host " << loginbuf + << " logged from " << c.getremoteip() << " on port " << c.getremoteport() << ".\n"; return new Daemon(c); } @@ -47,8 +53,7 @@ Client *Client::login(Connection &c) { } Client *Client::login_fail(Connection &c) { - std::cout << "Bad authentification from " << c.getremoteip() << " on port " - << c.getremoteport() << ".\n"; + std::cout << "Connection id " << c.getid() << ": Bad authentification.\n"; c.sendln("Bad authentification."); return 0; } diff --git a/sls/trunk/src/client_daemon.cc b/sls/trunk/src/client_daemon.cc index 4e32f3c862fa48cbf02ad0e45f11d267b1fd917a..641360050ebe77bdfcff5933d92eb461c0a28e04 100644 --- a/sls/trunk/src/client_daemon.cc +++ b/sls/trunk/src/client_daemon.cc @@ -22,6 +22,9 @@ Daemon::Daemon(Connection &c) : Client(c) {} void Daemon::exec() { + // send scripts + + // starting scripts + c_.sendln("EXIT"); - while (1) { c_.sendln("toto"); } } diff --git a/sls/trunk/src/connection.cc b/sls/trunk/src/connection.cc index 547292283727c4d2c52b94b6857be69540a319f9..288afbeba3f0e53a91ce83ad7cf0ed7fd09612bf 100644 --- a/sls/trunk/src/connection.cc +++ b/sls/trunk/src/connection.cc @@ -27,6 +27,14 @@ #include #include +/******************************************************************************* + ** Class method + ******************************************************************************/ +unsigned long int Connection::getconnid() { + static unsigned long int id = 1; + return id++; +} + /******************************************************************************* ** Public method ******************************************************************************/ @@ -36,13 +44,15 @@ * * @param fd socket of the connection (-1) is not exist */ -Connection::Connection(int fd) : socket_fd_(fd), local_port_(-1), remote_port_(-1) { +Connection::Connection(int fd) : socket_fd_(fd), local_port_(-1), remote_port_(-1), id_(0) { pthread_mutex_init(&c_mutex_, 0); pthread_mutex_init(&r_mutex_, 0); pthread_mutex_init(&w_mutex_, 0); - if (socket_fd_ >= 0) + if (socket_fd_ >= 0) { + id_ = getconnid(); setallinfo_(); + } } /** @@ -352,6 +362,10 @@ int Connection::getremoteport() { return port; } +unsigned long int Connection::getid() { + return id_; +} + int Connection::getsocket() { pthread_mutex_lock(&c_mutex_); int ret = socket_fd_; diff --git a/sls/trunk/src/connection.hh b/sls/trunk/src/connection.hh index 0379ff73877b761a55f0841e8d8716cf7065ac16..194cd85543b552c10938f6f7ee24bf3914f14143 100644 --- a/sls/trunk/src/connection.hh +++ b/sls/trunk/src/connection.hh @@ -22,6 +22,10 @@ # include class Connection { + // class methods +public: + unsigned long int getconnid(); + // public methods public: Connection(int fd = -1); @@ -51,6 +55,8 @@ public: string getremoteip(); int getremoteport(); + unsigned long int getid(); + int getsocket(); // protected methods @@ -75,6 +81,8 @@ protected: string local_ip_; string remote_ip_; + unsigned long int id_; + string rbuf_; // read buffer string wbuf_; // write buffer diff --git a/sls/trunk/src/server.cc b/sls/trunk/src/server.cc index e5a6d1f00cb02b50e4d9b5c0e2718b921e0fcafc..4886b3ab727388e2be3afe5ba21f127ab262c4e8 100644 --- a/sls/trunk/src/server.cc +++ b/sls/trunk/src/server.cc @@ -73,7 +73,7 @@ void Server::start(int port, size_t max_conn, bool verbose) { // check max conn if (threads_.size() >= max_conn_) { - std::cout << "Connection refused from ip " << nc->getremoteip() + std::cout << "Connection id " << nc->getid() << ": Refused from ip " << nc->getremoteip() << " on port " << nc->getremoteport() << ": Max connections reached.\n"; nc->disconnect(); @@ -81,8 +81,8 @@ void Server::start(int port, size_t max_conn, bool verbose) { } // Print connection - std::cout << "New connection from ip " << nc->getremoteip() - << " on port " << nc->getremoteport(); + std::cout << "Connection id " << nc->getid() << ": New connection from ip " + << nc->getremoteip() << " on port " << nc->getremoteport(); if (verbose_) std::cout << " (socket " << nc->getsocket() << ")" ; std::cout << ".\n"; @@ -177,16 +177,14 @@ void *Server::start_client(void *voidconn) { } } catch (const Error &e) { - std::cerr << "On connection " << conn->getremoteip() << " port " - << conn->getremoteport() << ": " << e << ".\n"; + std::cerr << "Connection id " << conn->getid() << ": " << e << ".\n"; } // stop connexion conn->disconnect(); // Print closing connection - std::cout << "Disconnected from ip " << conn->getremoteip() - << " on port " << conn->getremoteport() << ".\n"; + std::cout << "Connection id " << conn->getid() << ": Closed.\n"; // remove from thread set pthread_mutex_lock(&S.threads_mutex_);