Commit 7c2e640b authored by Seblu's avatar Seblu
Browse files

Ajout du parsing des fichiers de conf

parent c58ee421
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
Max command line size = 512
Max conf file line size = 2048
+0 −2
Original line number Diff line number Diff line
@@ -2,5 +2,3 @@ IMPROVMENTS:
remove static magic MAX_LINE_SIZE in sscanf

BUG:
SLDaemon::binpath() ne recupere pas le bon nom pour le binaire en cours d'execution
RELOAD return bad address during execl

sld/examples/conffile

0 → 100644
+6 −0
Original line number Diff line number Diff line
host=trinity
pass=sex
server=localhost
port=18136
scriptdir=examples/scripts/
verbose=1
+4 −0
Original line number Diff line number Diff line
#!/bin/bash

echo "Hello World !"
+55 −9
Original line number Diff line number Diff line
@@ -28,11 +28,6 @@ SLDaemon &SLDaemon::Instance() {
  return *instance_;
}

SLDaemon::Options::Options() {
  this->port = 0;
  this->verbose = 3;
}

void SLDaemon::usage(const char *argv0) const {
  std::cerr << "usage: "
	    << argv0
@@ -116,10 +111,42 @@ SLDaemon::Options *SLDaemon::getoptions(int argc, char *argv[]) const {
}

SLDaemon::Options *SLDaemon::getoptions(const string file) const {
  if (file == "")
    throw Error(ERR_BADPARAM, "Conf file not implemented");
  throw Error(ERR_BADPARAM, "Conf file not implemented");
  ifstream fs;
  char line[MAX_CONF_LINE_SIZE];
  int i=0;
  char name[11], value[MAX_CONF_LINE_SIZE - 10 + 1];
  SLDaemon::Options o;

  fs.open(file.c_str(), ifstream::in);

  if (!fs.is_open())
    return 0;

  while (fs.good()) {
    fs.getline(line, MAX_CONF_LINE_SIZE);
    if (fs.eof())
      break;
    sscanf(line, "%10[^=]=%2039s\n", name, value); //TODO: fix magic number

    if (!strcasecmp(name, "host"))
      o.login = value;
    else if (!strcasecmp(name, "pass"))
      o.pass = value;
    else if (!strcasecmp(name, "server"))
      o.server = value;
    else if (!strcasecmp(name, "port"))
      o.port = atoi(value);
    else if (!strcasecmp(name, "scriptdir"))
      o.scriptdir = value;
    else if (!strcasecmp(name, "verbose"))
      o.verbose = atoi(value);
    else
      std::cerr << "Invalid line " << i << ": " << line;
  }

  fs.close();

  return new SLDaemon::Options(o);
}

void SLDaemon::applyoptions(const Options *opt) {
@@ -711,6 +738,25 @@ string SLDaemon::md5(const string &file) const {
  return string(digest);
}

//******************************************************************************
// Class Options functions
//******************************************************************************

SLDaemon::Options::Options() {
  this->port = 0;
  this->verbose = 3;
}

void SLDaemon::Options::print() {
  std::cout << "server: " << server << std::endl;
  std::cout << "port: " << port << std::endl;
  std::cout << "host login: " << login << std::endl;
  std::cout << "host pass: " << pass << std::endl;
  std::cout << "script directory: " << scriptdir << std::endl;
  std::cout << "configuration file: " << conffile << std::endl;
  std::cout << "verbose level: " << verbose << std::endl;
}

//******************************************************************************
// Class Job functions
//******************************************************************************
Loading