Beispiel #1
1
void ViewerCmdLine::parseOptionsFile()
{
  StringStorage pathToIniFile = m_options[OPTIONS_FILE];
  if (pathToIniFile.findChar(_T('\\')) == -1) {
    StringStorage newPathToIniFile;
    newPathToIniFile.format(_T(".\\%s"), pathToIniFile.getString());
    pathToIniFile = newPathToIniFile;
  }
  IniFileSettingsManager sm(pathToIniFile.getString());
  sm.setApplicationName(_T("connection"));

  StringStorage host;
  if (!sm.getString(_T("host"), &host)) {
    throw CommandLineFormatException(_T("Could not read options file."));
  }
  StringStorage port;
  if (sm.getString(_T("port"), &port)) {
    StringStorage hostString;
    hostString.format(_T("%s:%s"), host.getString(), port.getString());
    m_conData->setHost(&hostString);
  } else {
    m_conData->setHost(&host);
  }

  StringStorage password;
  sm.getString(_T("password"), &password);
  if (!password.isEmpty()) {
    m_conData->setCryptedPassword(&password);
  } else {
    parsePassword();
  }
  
  sm.setApplicationName(_T("options"));
  m_conConf->loadFromStorage(&sm);
}
Beispiel #2
1
void ViewerCmdLine::parse()
{
  const CmdLineOption options[] = {
    HELP,
    HELP_SHORT,
    OPTIONS_FILE,
    LISTEN,
    HOST,
    PORT,
    PASSWORD,
    SHOW_CONTROLS,
    VIEW_ONLY,
    USE_CLIPBOARD,
    SCALE,
    FULL_SCREEN,
    WARN_FULL_SCREEN,
    ENCODING,
    COPY_RECT,
    MOUSE_CURSOR,
    MOUSE_LOCAL,
    MOUSE_SWAP,
    JPEG_IMAGE_QUALITY,
    COMPRESSION_LEVEL
  };

  if (!processCmdLine(&options[0], sizeof(options) / sizeof(CmdLineOption))) {
    throw CommandLineFormatException();
  }

  if (isHelpPresent()) {
    throw CommandLineFormatHelp();
  }


  if (m_wpcl.getArgumentsCount() > 2) {
    throw CommandLineFormatException();
  }

  if (m_wpcl.getArgumentsCount() > 1) {
    if (isPresent(ViewerCmdLine::HOST)) {
      throw CommandLineFormatException();
    }
  }

  if (isPresent(ViewerCmdLine::OPTIONS_FILE)) {
    parseOptionsFile();
  } else {
    if (isPresent(ViewerCmdLine::LISTEN)) {
      *m_isListening = true;
    } else {
      if (!parseHost()) {
        throw CommandLineFormatException();
      }
    }
  }
  parsePassword();
  parseEncoding();
  parseMouseShape();
  parseMouseCursor();
  parseScale();
  parseFullScreen();
  parseCompressionLevel();
  parseWarnFullScr();
  parseMouseSwap();
  parseUseClipboard();
  parseShowControl();
  parseCopyRect();
  parseViewOnly();
  parseJpegImageQuality();
}
void ControlCommandLine::setVncPort()
{
    if ( ( hasSetVncPortFlag() && ! hasPortableFlag() && m_foundKeys.size() > 1 ) ||
        ( hasSetVncPortFlag() &&  hasPortableFlag()  && ! hasVncIniDirectoryFlag() && m_foundKeys.size() > 2 )  ||
        ( hasSetVncPortFlag() &&  hasPortableFlag() && hasVncIniDirectoryFlag() && m_foundKeys.size() > 3 ) ) {
            throw CommandLineFormatException();
    } else {
        optionSpecified(SET_VNC_PORT, &m_vncPort);
        optionSpecified(VNC_INI_DIRECTORY, &m_vncIniDirectoryPath);

    }
}
void ControlCommandLine::setVncPortAndPrimaryPassword()
{
    if ( ( hasSetVncPortFlag() && hasSetVncPasswordFlag() && ! hasPortableFlag() && m_foundKeys.size() > 2 ) ||
        ( hasSetVncPortFlag() && hasSetVncPasswordFlag() &&  hasPortableFlag()  && ! hasVncIniDirectoryFlag() && m_foundKeys.size() > 3 )  ||
        ( hasSetVncPortFlag() && hasSetVncPasswordFlag() &&  hasPortableFlag() && hasVncIniDirectoryFlag() && m_foundKeys.size() > 4 ) ) {
            throw CommandLineFormatException();
    } else {
        optionSpecified(SET_PRIMARY_VNC_PASSWORD, &m_vncPassword);
        optionSpecified(SET_CONTROL_PASSWORD, &m_controlPassword);
        optionSpecified(SET_VNC_PORT, &m_vncPort);
        optionSpecified(VNC_INI_DIRECTORY, &m_vncIniDirectoryPath);
    }
}
void ControlCommandLine::parse(const CommandLineArgs *cmdArgs)
{
  CommandLineFormat fmt[] = {
    { PASSWORD_FILE, NEEDS_ARG },
    { CONFIG_RELOAD, NO_ARG },
    { DISCONNECT_ALL, NO_ARG },
    { CONNECT, NEEDS_ARG },
    { SHUTDOWN, NO_ARG },
    { SET_PRIMARY_VNC_PASSWORD, NEEDS_ARG },
    { SET_CONTROL_PASSWORD, NEEDS_ARG },
    { CHECK_SERVICE_PASSWORDS, NO_ARG },
    { SHARE_PRIMARY, NO_ARG },
    { SHARE_RECT, NEEDS_ARG },
    { SHARE_DISPLAY, NEEDS_ARG },
    { SHARE_WINDOW, NEEDS_ARG },
    { SHARE_FULL, NO_ARG },
    { CONTROL_SERVICE, NO_ARG },
    { CONTROL_APPLICATION, NO_ARG },
    { CONFIG_APPLICATION, NO_ARG },
    { CONFIG_SERVICE, NO_ARG },
    { SLAVE_MODE, NO_ARG },
    { DONT_ELEVATE, NO_ARG }
  };

  if (!CommandLine::parse(fmt, sizeof(fmt) / sizeof(CommandLineFormat), cmdArgs)) {
    throw CommandLineFormatException();
  }

  if (hasConfigServiceFlag() && ((int)m_foundKeys.size() > (optionSpecified(DONT_ELEVATE) ? 2 : 1))) {
    throw CommandLineFormatException();
  }

  if (hasConfigAppFlag() && m_foundKeys.size() > 1) {
    throw CommandLineFormatException();
  }

  bool hasPassFile = hasPasswordFile();
  if (hasPassFile) {
    optionSpecified(PASSWORD_FILE, &m_passwordFile);
  }

  if (hasShareRect()) {
    StringStorage strRect;
    optionSpecified(SHARE_RECT, &strRect);
    parseRectCoordinates(&strRect);
  }

  if (hasShareDisplay()) {
    StringStorage strDisplayNumber;
    optionSpecified(SHARE_DISPLAY, &strDisplayNumber);
    parseDisplayNumber(&strDisplayNumber);
  }

  if (hasShareWindow()) {
    optionSpecified(SHARE_WINDOW, &m_windowHeaderName);
  }

  if (hasKillAllFlag() && hasReloadFlag()) {
    throw CommandLineFormatException();
  }

  if (hasConnectFlag()) {
    optionSpecified(CONNECT, &m_connectHostName);
  }

  if ((hasSetVncPasswordFlag() || hasSetControlPasswordFlag()) && m_foundKeys.size() > 1) {
    throw CommandLineFormatException();
  } else {
    optionSpecified(SET_CONTROL_PASSWORD, &m_controlPassword);
    optionSpecified(SET_PRIMARY_VNC_PASSWORD, &m_vncPassword);
  }

  if ((hasControlServiceFlag() || hasControlAppFlag()) && (isSlave()) && (m_foundKeys.size() > 2)) {
    throw CommandLineFormatException();
  }

  bool hasNotSlaveControl = (hasControlServiceFlag() || hasControlAppFlag()) && !isSlave();
  if ((hasNotSlaveControl && !hasPassFile && m_foundKeys.size() > 2) ||
      (hasNotSlaveControl && hasPassFile && m_foundKeys.size() != 3)) {
    throw CommandLineFormatException();
  }

  if (m_foundKeys.size() == 0) {
    throw CommandLineFormatException();
  }
}
void ControlCommandLine::parse(const TCHAR *commandLine)
{
  CommandLineFormat fmt[] = {
    { PASSWORD_FILE, NEEDS_ARG },
    { CONFIG_RELOAD, NO_ARG },
    { DISCONNECT_ALL, NO_ARG },
    { CONNECT, NEEDS_ARG },
    { SHUTDOWN, NO_ARG },
    { SET_PRIMARY_VNC_PASSWORD, NEEDS_ARG },
    { SET_CONTROL_PASSWORD, NEEDS_ARG },
    { CONTROL_SERVICE, NO_ARG },
    { CONTROL_APPLICATION, NO_ARG },
    { CONFIG_APPLICATION, NO_ARG },
    { CONFIG_SERVICE, NO_ARG },
    { SLAVE_MODE, NO_ARG },
    { DONT_ELEVATE, NO_ARG },
    { PORTABLE, NO_ARG },
    { SET_VNC_PORT, NEEDS_ARG },
    { VNC_INI_DIRECTORY, NEEDS_ARG },

  };

  if (!CommandLine::parse(fmt, sizeof(fmt) / sizeof(CommandLineFormat), commandLine)) {
    throw CommandLineFormatException();
  }

  if (hasConfigServiceFlag() && ((int)m_foundKeys.size() > (optionSpecified(DONT_ELEVATE) ? 2 : 1))) {
    throw CommandLineFormatException();
  }

  if ( ( hasConfigAppFlag()  && ! hasPortableFlag() && m_foundKeys.size() > 1  ) ||
       ( hasConfigAppFlag()  &&  hasPortableFlag()  && m_foundKeys.size() > 2 ) ) {
    throw CommandLineFormatException();
  }

  bool hasPassFile = hasPasswordFile();
  if (hasPassFile) {
    optionSpecified(PASSWORD_FILE, &m_passwordFile);
  }

  if (hasKillAllFlag() && hasReloadFlag()) {
    throw CommandLineFormatException();
  }

  if (hasConnectFlag()) {
    optionSpecified(CONNECT, &m_connectHostName);
  }

  if(hasSetVncPortAndPrimaryPasswdFlag()) {
      setVncPortAndPrimaryPassword();
  }

  if ((hasControlServiceFlag() || hasControlAppFlag()) && (isSlave()) && (m_foundKeys.size() > 2)) {
    throw CommandLineFormatException();
  }

  bool hasNotSlaveControl = (hasControlServiceFlag() || hasControlAppFlag()) && !isSlave();
  if ((hasNotSlaveControl && !hasPassFile && m_foundKeys.size() > 2) ||
      (hasNotSlaveControl && hasPassFile && m_foundKeys.size() != 3)) {
    throw CommandLineFormatException();
  }

  if(hasSetVncPortFlag() && ! hasSetVncPasswordFlag()) {
      setVncPort();
  }

  if(! hasSetVncPortFlag() && ( hasSetVncPasswordFlag() || hasSetControlPasswordFlag()) ) {
      setVncOrControlPassword();
  }

  if (m_foundKeys.size() == 0) {
    throw CommandLineFormatException();
  }
}