Klaus - 2014-04-13

Dear all,

interacting with linknx using telnet via port 1028 is quite powerful, but has a little draw-back: it is not possible to terminate the session gracefully. Therefore I suggest to add another 'admin' command to do so ==> <admin><quit/></admin>

The following patch - based on the linknx-0.0.1.32 sources will do the trick. May by Jean-Francois will add this later to next release.

Have fun,

Klaus

*** xmlserver.cpp   2014-04-13 14:36:23.575321861 +0200
--- ../../linknx-0.0.1.32/src/xmlserver.cpp 2013-11-07 00:21:29.000000000 +0100
*************** XmlServer::~XmlServer ()
*** 45,51 ****
      close (fd_m);
  }

! bool XmlServer::deregister (ClientConnection * con)
  {
      connections_m.remove(con);
      return 1;
--- 45,52 ----
      close (fd_m);
  }

! bool
! XmlServer::deregister (ClientConnection * con)
  {
      connections_m.remove(con);
      return 1;
*************** void XmlServer::Run (pth_sem_t *stop1)
*** 156,162 ****
          if (cfd != -1)
          {
              ClientConnection *c = new ClientConnection (this, cfd);
-             debugStream("XmlServer") << "new client connection on port:" << cfd << endlog;
              connections_m.push_back(c);
              c->Start ();
          }
--- 157,162 ----
*************** ClientConnection::~ClientConnection ()
*** 186,195 ****

  void ClientConnection::Run (pth_sem_t * stop1)
  {
-   bool quitLoop = false;
-   
      pth_event_t stop = pth_event (PTH_EVENT_SEM, stop1);
!     while ((pth_event_status (stop) != PTH_STATUS_OCCURRED) && !quitLoop)
      {
          if (readmessage (stop) == -1)
              break;
--- 186,193 ----

  void ClientConnection::Run (pth_sem_t * stop1)
  {
      pth_event_t stop = pth_event (PTH_EVENT_SEM, stop1);
!     while (pth_event_status (stop) != PTH_STATUS_OCCURRED)
      {
          if (readmessage (stop) == -1)
              break;
*************** void ClientConnection::Run (pth_sem_t *
*** 514,525 ****
                  ticpp::Iterator< ticpp::Element > pAdmin;
                  for ( pAdmin = pMsg->FirstChildElement(); pAdmin != pAdmin.end(); pAdmin++ )
                  {
!                   if (pAdmin->Value() == "quit")      // klenssen: allow telnet sessions to be terminated actively
!                   {
!                       debugStream("ClientConnection") << "ADMIN: received 'quit' command --> terminate active session" << endlog;
!                       quitLoop = true;
!                   }
!                   else if (pAdmin->Value() == "save")
                      {
                          std::string filename = pAdmin->GetAttribute("file");
                          if (filename == "")
--- 512,518 ----
                  ticpp::Iterator< ticpp::Element > pAdmin;
                  for ( pAdmin = pMsg->FirstChildElement(); pAdmin != pAdmin.end(); pAdmin++ )
                  {
!                     if (pAdmin->Value() == "save")
                      {
                          std::string filename = pAdmin->GetAttribute("file");
                          if (filename == "")
*************** int ClientConnection::readmessage (pth_e
*** 678,684 ****
          msg << msgbuf_m;
      }

!     while ((i = pth_read_ev (fd_m, &buf, sizeof(buf), stop)) > 0)
      {
          std::string tstr(buf, i);
          std::string::size_type len = tstr.find_first_of('\004');
--- 671,677 ----
          msg << msgbuf_m;
      }

!     while ((i = pth_read_ev (fd_m, &buf, 256, stop)) > 0)
      {
          std::string tstr(buf, i);
          std::string::size_type len = tstr.find_first_of('\004');