bool ApplicationHttpServer::parsePhase2 (ProgramOptions& options) {
  if (options.has("server.require-keep-alive")) {
    _requireKeepAlive= true;
  }

  for (vector<string>::const_iterator i = _httpPorts.begin();  i != _httpPorts.end();  ++i) {
    addPort(*i);
  }

  return true;
}
bool ApplicationHttpsServer::parsePhase2 (ProgramOptions& options) {

  // check keep alive
  if (options.has("server.secure-require-keep-alive")) {
    _requireKeepAlive= true;
  }


  // add ports
  for (vector<string>::const_iterator i = _httpsPorts.begin();  i != _httpsPorts.end();  ++i) {
    addPort(*i);
  }


  // create the ssl context (if possible)
  bool ok = createSslContext();

  if (! ok) {
    return false;
  }

  // and return
  return true;
}
示例#3
0
static void ParseProgramOptions (int argc, char* argv[]) {
  string level = "info";

  ProgramOptionsDescription description("STANDARD options");

  ProgramOptionsDescription hidden("HIDDEN options");

  hidden
    ("colors", "activate color support")
    ("no-pretty-print", "disable pretty printting")          
    ("auto-complete", "enable auto completion, use no-auto-complete to disable")
  ;

  description
    ("help,h", "help message")
    ("quite,s", "no banner")
    ("log.level,l", &level,  "log level")
    ("server", &ServerAddressPort, "server address and port")
    ("startup.directory", &StartupPath, "startup paths containing the Ruby files; multiple directories can be separated by cola")
    ("startup.modules-path", &StartupModules, "one or more directories separated by cola")
    ("pager", &OutputPager, "output pager")
    ("use-pager", "use pager")
    ("pretty-print", "pretty print values")          
    ("no-colors", "deactivate color support")
    ("no-auto-complete", "disable auto completion")
    // ("unit-tests", &UnitTests, "do not start as shell, run unit tests instead")
    (hidden, true)
  ;

  ProgramOptions options;

  if (! options.parse(description, argc, argv)) {
    cerr << options.lastError() << "\n";
    exit(EXIT_FAILURE);
  }

  // check for help
  set<string> help = options.needHelp("help");

  if (! help.empty()) {
    cout << description.usage(help) << endl;
    exit(EXIT_SUCCESS);
  }

  // set the logging
  TRI_SetLogLevelLogging(level.c_str());
  TRI_CreateLogAppenderFile("-");

  // set colors
  if (options.has("colors")) {
    NoColors = false;
  }

  if (options.has("no-colors")) {
    NoColors = true;
  }

  if (options.has("auto-complete")) {
    NoAutoComplete = false;
  }

  if (options.has("no-auto-complete")) {
    NoAutoComplete = true;
  }

  if (options.has("pretty-print")) {
    PrettyPrint = true;
  }

  if (options.has("no-pretty-print")) {
    PrettyPrint = false;
  }

  if (options.has("use-pager")) {
    UsePager = true;
  }

  if (options.has("quite")) {
    Quite = true;
  }
}
示例#4
0
void ArangoClient::parse (ProgramOptions& options,
                          ProgramOptionsDescription& description,
                          string const& example,
                          int argc,
                          char* argv[],
                          string const& initFilename) {
  // if options are invalid, exit directly
  if (! options.parse(description, argc, argv)) {
    LOG_FATAL_AND_EXIT("%s", options.lastError().c_str());
  }

  // setup the logging
  TRI_SetLogLevelLogging(_logLevel.c_str());
  TRI_CreateLogAppenderFile("-", 0, TRI_LOG_SEVERITY_UNKNOWN, false);
  TRI_SetLineNumberLogging(false);
  TRI_SetThreadIdentifierLogging(false);

  // parse config file
  string configFile = "";
  bool allowLocal = false;

  if (! _configFile.empty()) {
    if (StringUtils::tolower(_configFile) == string("none")) {
      LOG_DEBUG("using no init file at all");
    }
    else {
      configFile = _configFile;
    }
  }

  else {
    char* d = TRI_LocateConfigDirectory();

    if (d != 0) {
      string sysDir = string(d) + initFilename;
      TRI_FreeString(TRI_CORE_MEM_ZONE, d);

      if (FileUtils::exists(sysDir)) {
        configFile = sysDir;
        allowLocal = true;
      }
      else {
        LOG_DEBUG("no system init file '%s'", sysDir.c_str());
      }
    }
  }

  if (! configFile.empty()) {
    if (allowLocal) {
      string localConfigFile = configFile + ".local";

      if (FileUtils::exists(localConfigFile)) {
        LOG_DEBUG("using init override file '%s'", localConfigFile.c_str());

        if (! options.parse(description, localConfigFile)) {
          LOG_FATAL_AND_EXIT("cannot parse config file '%s': %s", localConfigFile.c_str(), options.lastError().c_str());
        }
      }
    }

    LOG_DEBUG("using init file '%s'", configFile.c_str());

    if (! options.parse(description, configFile)) {
      LOG_FATAL_AND_EXIT("cannot parse config file '%s': %s", configFile.c_str(), options.lastError().c_str());
    }
  }

  // configuration is parsed and valid if we got to this point
  
  // check for --help
  set<string> help = options.needHelp("help");

  if (! help.empty()) {
    if (! example.empty()) {
      cout << "USAGE: " << argv[0] << " " << example << endl << endl;
    }
    cout << description.usage(help) << endl;

    // --help always returns success
    TRI_EXIT_FUNCTION(EXIT_SUCCESS, NULL);
  }


  // set temp path
  if (options.has("temp-path")) {
    TRI_SetUserTempPath((char*) _tempPath.c_str());
  }

  if (options.has("server.username")) {
    // if a username is specified explicitly, assume authentication is desired
    _disableAuthentication = false;
  }

  // check if have a password
  _hasPassword = options.has("server.password") 
              || _disableAuthentication
              || options.has("jslint") 
              || options.has("javascript.unit-tests");

  // set colors
  if (options.has("colors")) {
    _noColors = false;
  }

  if (options.has("no-colors")) {
    _noColors = true;
  }

  // set auto-completion
  if (options.has("auto-complete")) {
    _noAutoComplete = false;
  }

  if (options.has("no-auto-complete")) {
    _noAutoComplete = true;
  }

  // set pretty print
  if (options.has("pretty-print")) {
    _prettyPrint = true;
  }

  if (options.has("no-pretty-print")) {
    _prettyPrint = false;
  }

  // set pager
  if (options.has("use-pager")) {
    _usePager = true;
  }

  // set quiet
  if (options.has("quiet")) {
    _quiet = true;
  }

  // .............................................................................
  // server options
  // .............................................................................

  if (_serverOptions) {

    // check connection args
    if (_connectTimeout <= 0) {
      LOG_FATAL_AND_EXIT("invalid value for --server.connect-timeout, must be positive");
    }

    if (_requestTimeout <= 0) {
      LOG_FATAL_AND_EXIT("invalid value for --server.request-timeout, must be positive");
    }

    // must specify a user name
    if (_username.size() == 0) {
      LOG_FATAL_AND_EXIT("no value specified for --server.username");
    }

    // no password given on command-line
    if (! _hasPassword) {
      usleep(10 * 1000);
      printContinuous("Please specify a password: "******"");
    }
  }
}
示例#5
0
void ArangoClient::parse (ProgramOptions& options,
                          ProgramOptionsDescription& description,
                          int argc,
                          char* argv[],
                          string const& initFilename) {
  if (! options.parse(description, argc, argv)) {
    LOGGER_FATAL_AND_EXIT(options.lastError());
  }

  // check for help
  set<string> help = options.needHelp("help");

  if (! help.empty()) {
    cout << description.usage(help) << endl;
    TRI_EXIT_FUNCTION(EXIT_SUCCESS, NULL);
  }

  // setup the logging
  TRI_SetLogLevelLogging(_logLevel.c_str());
  TRI_CreateLogAppenderFile("-", 0, TRI_LOG_SEVERITY_UNKNOWN, false);
  TRI_SetLineNumberLogging(false);
  TRI_SetThreadIdentifierLogging(false);

  // parse config file
  string configFile = "";

  if (! _configFile.empty()) {
    if (StringUtils::tolower(_configFile) == string("none")) {
      LOGGER_DEBUG("using no init file at all");
    }
    else {
      configFile = _configFile;
    }
  }


#ifdef _SYSCONFDIR_
  else {
    // use packaged config file from etc/relative
    string sysDir = string(_SYSCONFDIR_);
    string systemConfigFile = initFilename;

    if (! sysDir.empty()) {
      if (sysDir[sysDir.size() - 1] != TRI_DIR_SEPARATOR_CHAR) {
        sysDir += TRI_DIR_SEPARATOR_CHAR + systemConfigFile;
      }
      else {
        sysDir += systemConfigFile;
      }

      if (FileUtils::exists(sysDir)) {
        configFile = sysDir;
      }
      else {
        LOGGER_DEBUG("no system init file '" << sysDir << "'");
      }
    }
  }
#endif

  if (! configFile.empty()) {
    LOGGER_DEBUG("using init file '" << configFile << "'");

    if (! options.parse(description, configFile)) {
      LOGGER_FATAL_AND_EXIT("cannot parse config file '" << configFile << "': " << options.lastError());
    }
  }

  // set temp path
  if (options.has("temp-path")) {
    TRI_SetUserTempPath((char*) _tempPath.c_str());
  }

  // check if have a password
  _hasPassword = options.has("server.password") 
              || _disableAuthentication
              || options.has("jslint") 
              || options.has("javascript.unit-tests");

  // set colors
  if (options.has("colors")) {
    _noColors = false;
  }

  if (options.has("no-colors")) {
    _noColors = true;
  }

  // set auto-completion
  if (options.has("auto-complete")) {
    _noAutoComplete = false;
  }

  if (options.has("no-auto-complete")) {
    _noAutoComplete = true;
  }

  // set pretty print
  if (options.has("pretty-print")) {
    _prettyPrint = true;
  }

  if (options.has("no-pretty-print")) {
    _prettyPrint = false;
  }

  // set pager
  if (options.has("use-pager")) {
    _usePager = true;
  }

  // set quiet
  if (options.has("quiet")) {
    _quiet = true;
  }

  // .............................................................................
  // server options
  // .............................................................................

  if (_serverOptions) {

    // check connection args
    if (_connectTimeout <= 0) {
      LOGGER_FATAL_AND_EXIT("invalid value for --server.connect-timeout, must be positive");
    }

    if (_requestTimeout <= 0) {
      LOGGER_FATAL_AND_EXIT("invalid value for --server.request-timeout, must be positive");
    }

    // must specify a user name
    if (_username.size() == 0) {
      LOGGER_FATAL_AND_EXIT("no value specified for --server.username");
    }

    // no password given on command-line
    if (! _hasPassword) {
      usleep(10 * 1000);
      printContinuous("Please specify a password: "******"");
    }
  }
}
示例#6
0
void ArangoClient::parse (ProgramOptions& options,
                          ProgramOptionsDescription& description, 
                          int argc,
                          char* argv[],
                          string const& initFilename) {
  if (! options.parse(description, argc, argv)) {
    cerr << options.lastError() << "\n";
    exit(EXIT_FAILURE);
  }

  // check for help
  set<string> help = options.needHelp("help");

  if (! help.empty()) {
    cout << description.usage(help) << endl;
    exit(EXIT_SUCCESS);
  }

  // setup the logging
  TRI_SetLogLevelLogging(_logLevel.c_str());
  TRI_CreateLogAppenderFile("-");
  TRI_SetLineNumberLogging(false);
  TRI_SetThreadIdentifierLogging(false);

  // parse config file
  string configFile = "";

  if (! _configFile.empty()) {
    if (StringUtils::tolower(_configFile) == string("none")) {
      LOGGER_INFO << "using no init file at all";
    }
    else {
      configFile = _configFile;
    }
  }

#ifdef _SYSCONFDIR_

  else {
    string sysDir = string(_SYSCONFDIR_);
    string systemConfigFile = initFilename;

    if (! sysDir.empty()) {
      if (sysDir[sysDir.size() - 1] != '/') {
        sysDir += "/" + systemConfigFile;
      }
      else {
        sysDir += systemConfigFile;
      }

      if (FileUtils::exists(sysDir)) {
        configFile = sysDir;
      }
      else {
        LOGGER_DEBUG << "no system init file '" << sysDir << "'";
      }
    }
  }
  
#endif

  if (! configFile.empty()) {
    LOGGER_DEBUG << "using init file '" << configFile << "'";

    if (! options.parse(description, configFile)) {
      cout << "cannot parse config file '" << configFile << "': " << options.lastError() << endl;
      exit(EXIT_FAILURE);
    }
  }

  // check if have a password
  _hasPassword = options.has("server.password") || options.has("server.disable-authentication");

  // set colors
  if (options.has("colors")) {
    _noColors = false;
  }

  if (options.has("no-colors")) {
    _noColors = true;
  }

  // set auto-completion
  if (options.has("auto-complete")) {
    _noAutoComplete = false;
  }

  if (options.has("no-auto-complete")) {
    _noAutoComplete = true;
  }

  // set pretty print
  if (options.has("pretty-print")) {
    _prettyPrint = true;
  }

  if (options.has("no-pretty-print")) {
    _prettyPrint = false;
  }

  // set pager
  if (options.has("use-pager")) {
    _usePager = true;
  }

  // set quiet
  if (options.has("quiet")) {
    _quiet = true;
  }

  // .............................................................................
  // server options
  // .............................................................................

  if (_serverOptions) {

    // check connection args
    if (_connectTimeout <= 0) {
      cerr << "invalid value for --server.connect-timeout, must be positive" << endl;
      exit(EXIT_FAILURE);
    }

    if (_requestTimeout <= 0) {
      cerr << "invalid value for --server.request-timeout, must be positive" << endl;
      exit(EXIT_FAILURE);
    }
  
    // must specify a user name
    if (_username.size() == 0) {
      cerr << "no value specified for --server.username" << endl;
      exit(EXIT_FAILURE);
    }

    // no password given on command-line
    if (! _hasPassword) {
      cout << "Please specify a password: " << flush;

      // now prompt for it
#ifdef TRI_HAVE_TERMIOS_H
      TRI_SetStdinVisibility(false);
      getline(cin, _password);

      TRI_SetStdinVisibility(true);
#else
      getline(cin, _password);
#endif
    }
  }
}