/*
 * netconfig_conf.h:
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: netconfig_conf.h,v 1.1.1.1 2005/06/27 13:37:56 cm Exp $
 */

#ifndef __NCCONF_H
#define __NCCONF_H

#include <vdr/tools.h>
#include <netinet/in.h>

// constants
#define NC_CONFIG_FILE               "netconfig.conf"

class cNetconfigParameter : public cListObject {
  private:
    bool section, visible;
    char *p_key, *p_value;
  public:
    cNetconfigParameter(const char *key = NULL, const char *value = NULL, bool section = false, bool visible = false);
    ~cNetconfigParameter();
    const char *GetKey(void) { return p_key; };
    const char *SetKey(const char *key);
    const char *GetValue(void) { return p_value; };
    const char *SetValue(const char *value);
    bool isSection() { return section; };
    bool SetSection(bool set);
    bool isVisible() { return visible; };
    bool SetVisible(bool set);
};

class cNetconfigParameters : public cList<cNetconfigParameter> {
  public:
    cNetconfigParameters();
    ~cNetconfigParameters();
};

class cNetconfigInterface : public cListObject {
  private:
    in_addr_t addr;
    char mask, *p_key;
  public:
    cNetconfigInterface(char *key, in_addr_t address = 0, char mask = 0);
    ~cNetconfigInterface();
    in_addr_t GetAddr() { return addr; };
    in_addr_t SetAddr(in_addr_t addr);
    char GetMask() { return mask; };
    char SetMask(char mask);
    const char *GetKey(void) { return p_key; };
    const char *SetKey(const char *key);
};

class cNetconfigInterfaces : public cList<cNetconfigInterface> {
  public:
    cNetconfigInterfaces();
    ~cNetconfigInterfaces();
};

class cNetconfigConf {
  private:
    bool ok;
    char *p_hostname;
    char *p_domain;
    char *p_config;
    char *p_dhcpScript;
    in_addr_t gateway;
    in_addr_t nameserver;
    cNetconfigInterfaces oInterfaces;
    cNetconfigParameters oSambaParameters;
    char *ReadAllFromSocket(int fd, int &length);
    bool StoreConfig(const char *key, const char *value);
    bool ParseConfig(const char *key, const char *value);
    bool SetData(const char *key, const char *value);
    char *FixString(char *string);
    void Initialize(void);
  public:
    cNetconfigConf();
    ~cNetconfigConf();
    bool isOk(void) { return ok; };
    bool Load(void);
    bool Save(void);
    const char *GetDhcpScript(void) { return p_dhcpScript; };
    const char *SetDhcpScript(const char *script);
    const char *GetConfig(void) { return p_config; };
    const char *SetConfig(const char *config);
    const char *GetHostname(void) { return p_hostname; };
    const char *SetHostname(const char *name);
    const char *GetDomain(void) { return p_domain; };
    const char *SetDomain(const char *domain);
    in_addr_t GetGateway(void) { return gateway; };
    in_addr_t SetGateway(in_addr_t addr);
    in_addr_t GetNameserver(void) { return nameserver; };
    in_addr_t SetNameserver(in_addr_t addr);
    cNetconfigInterfaces *Interfaces();
    cNetconfigParameters *SambaParameters();
};

#endif
