Exemplo n.º 1
0
/**
* \brief Function to close the session
* \return raises an exception on error
*/
int
SessionServer::close() {

  std::string closePolicyStr = "";
  UserServer user = UserServer(SessionServer(msession.getSessionKey()));
  CommandServer commanderServer = CommandServer(SessionServer(msession.getSessionKey()));
  //The init function initializes login and password using the sessionKey
  user.init();
  //If The user exist
  if (user.exist()) {
    int state = getState();
    //if the session is not already closed
    if (state != 0) {
      //if no running commands
      if (!commanderServer.isRunning()) {
        mdatabaseVishnu->process((boost::format("UPDATE vsession"
                                                " SET state=0"
                                                " WHERE sessionkey='%1%';")%mdatabaseVishnu->escapeData(msession.getSessionKey())).str());
        mdatabaseVishnu->process((boost::format("UPDATE vsession"
                                                " SET closure=CURRENT_TIMESTAMP"
                                                " WHERE sessionkey='%1%';")%mdatabaseVishnu->escapeData(msession.getSessionKey())).str());
      } else {
        //To get the close policy associated to the session
        closePolicyStr = (boost::format(" WHERE sessionkey='%1%';")%mdatabaseVishnu->escapeData(msession.getSessionKey())).str();
        getAttribut(closePolicyStr, "closepolicy");
        //If the session close policy is CLOSE_ON_DISCONNECT
        if (convertToInt(closePolicyStr) == 2) {
          disconnetToTimeout(user);
        }  else {
          throw  UMSVishnuException (ERRCODE_COMMAND_RUNNING);
        }
      }
    } else {
      UMSVishnuException e (ERRCODE_SESSIONKEY_EXPIRED);
      throw e;
    }
  } //END If The user exist
  return 0;
}//END: close()
Exemplo n.º 2
0
/**
* \brief Function to close the session
* \return raises an exception on error
*/
int
SessionServer::close() {
  UserServer user = UserServer(SessionServer(msession.getSessionKey()));
  CommandServer commanderServer = CommandServer(SessionServer(msession.getSessionKey()));

  // initialize and check the user
  user.init();
  if (! user.exist()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_USER, user.getData().getUserId());
  }

  if (getState() == vishnu::SESSION_CLOSED) {
    throw UMSVishnuException (ERRCODE_SESSIONKEY_EXPIRED);
  }

  if (! commanderServer.isRunning()) {
    mdatabase->process(boost::str(boost::format("UPDATE vsession"
                                                " SET state=%1%"
                                                " WHERE sessionkey='%2%';")
                                  % vishnu::SESSION_CLOSED
                                  % mdatabase->escapeData(msession.getSessionKey())));

    mdatabase->process(boost::str(boost::format("UPDATE vsession"
                                                " SET closure=CURRENT_TIMESTAMP"
                                                " WHERE sessionkey='%1%';")
                                  % mdatabase->escapeData(msession.getSessionKey())));
  } else {
    int closePolicy = vishnu::convertToInt(getAttributFromSessionKey(msession.getSessionKey(), "closepolicy"));
    if (closePolicy == vishnu::CLOSE_ON_DISCONNECT) {
      disconnetToTimeout();
    } else {
      throw  UMSVishnuException (ERRCODE_COMMAND_RUNNING);
    }
  }

  return 0;
}