コード例 #1
0
ファイル: ListSessionsServer.hpp プロジェクト: SysFera/vishnu
  /**
   * \brief Function to treat the listSessionServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListSessionServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListSessionOptions_ptr& options, std::string& query)
  {
    boost::posix_time::ptime pt;
    bool listAll = options->isAdminListOption();

    if (! userServer.isAdmin()
        && (! options->getUserId().empty() || listAll)) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }

    if(! options->getMachineId().empty()) {
      addOptionRequest("clmachine.name", options->getMachineId(), query);
    }

    if(! options->getUserId().empty()) {
      addOptionRequest("users.userid", options->getUserId(), query);
    } else {
      if (! listAll) {
        addOptionRequest("users.userid", userServer.getData().getUserId(), query);
      }
    }

    int status = options->getStatus();
    if (status == vishnu::STATUS_UNDEFINED) {
      status = vishnu::STATUS_ACTIVE;
    }

    addIntegerOptionRequest("state", status, query);

    if (options->getSessionClosePolicy()) {
      addIntegerOptionRequest("closepolicy", options->getSessionClosePolicy(), query);
    }

    if (options->getSessionInactivityDelay() < 0) {
      throw UMSVishnuException(ERRCODE_INCORRECT_TIMEOUT);
    }

    if (options->getSessionInactivityDelay()) {
      addIntegerOptionRequest("timeout", options->getSessionInactivityDelay(), query);
    }

    if (! options->getSessionId().empty()) {
      addOptionRequest("vsessionid", options->getSessionId(), query);
    }

    time_t startDate = static_cast<time_t>(options->getStartDateOption());
    if (startDate > 0) {
      addTimeRequest("creation", vishnu::timeToTimestamp(startDate), query, ">=");
    }

    time_t endDate = static_cast<time_t>(options->getEndDateOption());
    if (endDate > 0) {
      addTimeRequest("closure", vishnu::timeToTimestamp(endDate), query, "<=");
    }
  }
コード例 #2
0
ファイル: ListSessionsServer.hpp プロジェクト: absila/vishnu
  /**
   * \brief Function to treat the listSessionServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListSessionServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListSessionOptions_ptr& options, std::string& sqlRequest)
  {
    boost::posix_time::ptime pt;
    size_t userIdSize = options->getUserId().size();
    bool listAll = options->isAdminListOption();

    if ((!userServer.isAdmin()) && (userIdSize!=0 || listAll)) {
      UMSVishnuException e (ERRCODE_NO_ADMIN);
      throw e;
    }

    if(options->getMachineId().size()!=0) {
      //To check if the name of the machine is correct
      checkClientMachineName(options->getMachineId());

      sqlRequest = "SELECT vsessionid, userid, sessionkey, state, closepolicy, timeout, lastconnect,"
                   "creation, closure, authid from vsession, users, clmachine where vsession.users_numuserid=users.numuserid"
                   " and vsession.clmachine_numclmachineid=clmachine.numclmachineid";
      addOptionRequest("name", options->getMachineId(), sqlRequest);
    }

    if(userIdSize!=0) {
      //To check if the user id is correct
      checkUserId(options->getUserId());

      addOptionRequest("userid", options->getUserId(), sqlRequest);
    } else {
      if(!listAll) {
        addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
      }
    }

    int status = options->getStatus();
    if (status == vishnu::STATUS_UNDEFINED) {
      status = vishnu::STATUS_ACTIVE;
    }
    //To check the status value
    checkStatus(status);

    addIntegerOptionRequest("state", status, sqlRequest);

    int closePolicy = options->getSessionClosePolicy();
    //To check the closePolicy value
    checkClosePolicy(closePolicy);

    if(closePolicy) {
      addIntegerOptionRequest("closepolicy", closePolicy, sqlRequest);
    }

    int timeOut = options->getSessionInactivityDelay();
    if(timeOut < 0) {
      throw UMSVishnuException(ERRCODE_INCORRECT_TIMEOUT);
    }
    if(timeOut) {
      addIntegerOptionRequest("timeout", timeOut, sqlRequest);
    }

    if(options->getSessionId().size()!=0) {
      //To check if the session id is correct
      checkSessionId(options->getSessionId());

      addOptionRequest("vsessionid", options->getSessionId(), sqlRequest);
    }

    time_t startDate = static_cast<time_t>(options->getStartDateOption());
    if(startDate!=-1) {
      pt =  boost::posix_time::from_time_t(startDate);
      std::string startDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("creation", startDateStr, sqlRequest, ">=");
    }

    time_t endDate = static_cast<time_t>(options->getEndDateOption());
    if(endDate!=-1) {
      pt =  boost::posix_time::from_time_t(endDate);
      std::string endDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("closure", endDateStr, sqlRequest, "<=");
    }

  }