/* 

                          Firewall Builder

                 Copyright (C) 2006 NetCitadel, LLC

  Author:  Vadim Kurland <vadim@fwbuilder.org>

  $Id: MultiAddress.h,v 1.4 2006/09/10 22:40:37 vkurland Exp $

  This program is free software which we release under the GNU General Public
  License. You may redistribute and/or modify this program under the terms
  of that license as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This program 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.
 
  To get a copy of the GNU General Public License, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/


#ifndef __GEN_MULTIADDRESS_HH_FLAG__
#define __GEN_MULTIADDRESS_HH_FLAG__

#include <fwbuilder/FWObject.h>
#include <fwbuilder/Address.h>
#include <fwbuilder/ObjectGroup.h>
#include <vector>



namespace libfwbuilder
{

class MultiAddress : public ObjectGroup
{
    private:
    // the name of the source XML attribute
    // (e.g. 'file' for address tables and 'dnsrec' for DNSName)
    std::string source_attribute_name;

      
    public:
    virtual void fromXML(xmlNodePtr parent) throw(FWException);

    DECLARE_FWOBJECT_SUBTYPE(MultiAddress);

    MultiAddress();
    MultiAddress(const FWObject *root,bool prepopulate);
    void registerSourceAttributeName(const std::string &an);

    std::string getSourceName() const;
    void setSourceName(const std::string &s);

    virtual void loadFromSource() throw(FWException);

    bool isCompileTime() const;
    bool isRunTime() const;
    void setCompileTime(const bool b);
    void setRunTime(const bool b); 

    virtual bool validateChild(FWObject *o);

    virtual xmlNodePtr toXML(xmlNodePtr xml_parent_node) throw(FWException);

};

/*
 * compilers assume that object that appear in Src, Dst, OSrc, ODst
 * are inherited from class Address and use this in many
 * places. MultiAddress is derived from ObjectGroup to simplify
 * processing in compile-time mode, which creates lots of problems
 * with it when it is configured in run-time mode. To simplify things,
 * we'll use class MultiAddressRunTime which is derived from
 * Address. We'll replace MultiAddress objects with run-time mode with
 * objects of this class in a special rule processor
 *
 * Objects of this class are never stored in the data file and do not
 * appear in DTD; they are only used in compilers.
 */
class MultiAddressRunTime : public Address
{
    std::string subst_type_name;
    std::string source_name;
    bool        run_time;

public:

    DECLARE_FWOBJECT_SUBTYPE(MultiAddressRunTime);

    MultiAddressRunTime();
    MultiAddressRunTime(MultiAddress *maddr);

    std::string getSourceName() const { return source_name; }
    std::string getSubstitutionTypeName() const { return subst_type_name; }

    bool isCompileTime() const { return !run_time; }
    bool isRunTime() const { return run_time; }
};

}


#endif

