/* 

                          Firewall Builder

                 Copyright (C) 2000 Vadim Kurland

  Author:  Vadim Kurland     vadim@vk.crocodile.org

  $Id: Rule.hh,v 1.20 2002/05/10 07:11:54 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 __RULE_HH_FLAG__
#define __RULE_HH_FLAG__

#include <fwbuilder/Group.hh>

namespace libfwbuilder
{

    class FWOptions;

    class RuleElementSrc;
    class RuleElementDst;
    class RuleElementSrv;
    class RuleElementOSrc;
    class RuleElementODst;
    class RuleElementOSrv;
    class RuleElementTSrc;
    class RuleElementTDst;
    class RuleElementTSrv;
    class RuleElementInterval;

class Rule : public Group 
{
    public:

    Rule();
    Rule(const FWObject *root);

    DECLARE_FWOBJECT_SUBTYPE(Rule);

    void setPosition(int n);
    int  getPosition() const;

    void disable();
    void enable();
    bool isDisabled();

    virtual bool isEmpty();

    virtual FWOptions* getOptionsObject();
};

class PolicyRule : public Rule 
{
    public:

    PolicyRule();
    PolicyRule(const FWObject *root);
    virtual void fromXML(xmlNodePtr parent) throw(FWException);
    virtual xmlNodePtr toXML      (xmlNodePtr parent) throw(FWException);

    DECLARE_FWOBJECT_SUBTYPE(PolicyRule);
    virtual FWOptions* getOptionsObject();
    virtual bool isEmpty();

    libfwbuilder::RuleElementSrc*  getSrc() const;
    libfwbuilder::RuleElementDst*  getDst() const;
    libfwbuilder::RuleElementSrv*  getSrv() const;
    libfwbuilder::RuleElementInterval* getWhen() const;

    typedef enum { Unknown, Accept, Reject, Deny, Scrub, Return, Skip, Continue } Action;

    Action getAction() const;
    void   setAction(Action act);
    std::string getActionAsString() const;
    void   setAction(const std::string& act);

    typedef enum { Undefined, Inbound, Outbound, Both } Direction;

    Direction getDirection() const;
    void   setDirection(Direction dir);
    std::string getDirectionAsString() const;
    void   setDirection(const std::string& dir);

    bool   getLogging() const;
    void   setLogging(bool flag);

};

class NATRule : public Rule 
{
    public:

    typedef enum { Unknown, NONAT, SNAT, Masq, DNAT, SNetnat, DNetnat, Redirect , Return , Skip , Continue }  NATRuleTypes;



    NATRule();
    NATRule(const FWObject *root);
    virtual void fromXML(xmlNodePtr parent) throw(FWException);
    virtual xmlNodePtr toXML      (xmlNodePtr parent) throw(FWException);

    DECLARE_FWOBJECT_SUBTYPE(NATRule);
    virtual FWOptions* getOptionsObject();
    virtual bool isEmpty();

    libfwbuilder::RuleElementOSrc* getOSrc() const;
    libfwbuilder::RuleElementODst* getODst() const;
    libfwbuilder::RuleElementOSrv* getOSrv() const;
    libfwbuilder::RuleElementTSrc* getTSrc() const;
    libfwbuilder::RuleElementTDst* getTDst() const;
    libfwbuilder::RuleElementTSrv* getTSrv() const;
    libfwbuilder::RuleElementInterval* getWhen() const;

    NATRuleTypes getRuleType() const;
    void         setRuleType(NATRuleTypes rt);
    std::string  getRuleTypeAsString() const;
    void         setRuleType(const std::string &rt);
};

}

#endif //__RULE_HH_FLAG__
