Skip to content
database.hh 2.01 KiB
Newer Older
Seblu's avatar
Seblu committed
/*
  This file is part of SLS.
Seblu's avatar
Seblu committed
  Copyright (C) 2008 Sebastien LUTTRINGER <contact@seblu.net>
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  SLS is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
Seblu's avatar
Seblu committed
  the Free Software Foundation; version 2 of the License.
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  SLS is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  You should have received a copy of the GNU General Public License
  along with SLS; if not, write to the Free Software
Seblu's avatar
Seblu committed
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Seblu's avatar
Seblu committed
*/
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
#ifndef DATABASE_HH
# define DATABASE_HH
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
# include <list>
Seblu's avatar
Seblu committed
# include <sqlite3.h>
# include "sls.hh"
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
// -----------------------------------------------------------------------------
// Classes
// -----------------------------------------------------------------------------

// Host

struct Host {
  string login;
  string pass;
  string ipv4;
  int level;
};

typedef std::list<Host> Hosts;

// Group

struct Group {
  string name;
  Hosts hosts;
};

typedef std::list<Group> Groups;

// User
struct User {
  string login;
  string pass;
  int level;
  bool priv;
};
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
typedef std::list<User> Users;

// Script

struct Script {
  string name;
  string path;
  int level;
};

typedef std::list<Script> Scripts;

// Alias

struct Alias {
  string name;
  string val;
};

typedef std::list<Alias> Aliases;


// Data container
Seblu's avatar
Seblu committed
class Database {
Seblu's avatar
Seblu committed
public:
  Database();

  void open(const string &path);
Seblu's avatar
Seblu committed
  bool opened() const;
Seblu's avatar
Seblu committed
  void close();

protected:
  void load_hosts_();
  void load_groups_();
  void load_users_();
  void load_scripts_();
  void load_aliases_();

  void save_hosts_();
  void save_groups_();
  void save_users_();
  void save_scripts_();
  void save_aliases_();

  void exec(const string &sql);

private:
  sqlite3 *db_;

  Hosts hosts_;
  Groups groups_;
  Users users_;
  Scripts scripts_;
  Aliases aliases_;
Seblu's avatar
Seblu committed
};

#endif