xorp

conf_tree.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/rtrmgr/conf_tree.hh,v 1.36 2008/10/02 21:58:22 bms Exp $
00021 
00022 #ifndef __RTRMGR_CONF_TREE_HH__
00023 #define __RTRMGR_CONF_TREE_HH__
00024 
00025 
00026 
00027 
00028 
00029 
00030 #include "libproto/config_node_id.hh"
00031 
00032 #include "conf_tree_node.hh"
00033 #include "rtrmgr_error.hh"
00034 #include "xorp_client.hh"
00035 
00036 
00037 class TemplateTree;
00038 class CommandTree;
00039 class ConfTemplate;
00040 
00041 class ConfPathSegment {
00042 public:
00043     ConfPathSegment(const string& segname, int type,
00044             const ConfigNodeId& node_id)
00045     : _segname(segname), _type(type), _node_id(node_id) {}
00046 #ifdef XORP_USE_USTL
00047     ConfPathSegment() { }
00048 #endif
00049     const string& segname() const { return _segname; }
00050     int type() const { return _type; }
00051     const ConfigNodeId& node_id() const { return _node_id; }
00052 
00053 private:
00054     string      _segname;
00055     int         _type;
00056     ConfigNodeId    _node_id;
00057 };
00058 
00059 class ConfigTree {
00060 public:
00061     ConfigTree(TemplateTree *tt, bool verbose);
00062     virtual ~ConfigTree();
00063 
00064 #if 0
00065     ConfigTree& operator=(const ConfigTree& orig_tree);
00066 #endif
00067     bool parse(const string& configuration, const string& config_file,
00068            string& error_msg);
00069     void push_path();
00070     void extend_path(const string& segment, int type,
00071              const ConfigNodeId& node_id);
00072     void pop_path();
00073     void add_node(const string& nodename, int type,
00074           const ConfigNodeId& node_id) 
00075     throw (ParseError);
00076     virtual ConfigTreeNode* create_node(const string& segment, 
00077                     const string& path,
00078                     const TemplateTreeNode* ttn, 
00079                     ConfigTreeNode* parent_node, 
00080                     const ConfigNodeId& node_id,
00081                     uid_t user_id, bool verbose) = 0;
00082     virtual ConfigTree* create_tree(TemplateTree *tt, bool verbose) = 0;
00083     void terminal_value(const string& value,
00084             int type, 
00085             ConfigOperator op) throw (ParseError);
00086     list<ConfPathSegment> path_as_segments() const;
00087     const TemplateTreeNode* 
00088         find_template(const list<string>& path_segments) const;
00089     const TemplateTreeNode* 
00090         find_template_by_type(const list<ConfPathSegment>& path_segments) 
00091     const;
00092     virtual ConfigTreeNode& root_node() = 0;
00093     virtual const ConfigTreeNode& const_root_node() const = 0;
00094     ConfigTreeNode* find_node(const list<string>& path);
00095     const ConfigTreeNode* find_const_node(const list<string>& path) const;
00096     ConfigTreeNode* find_config_module(const string& module_name);
00097     string show_subtree(bool show_top, const list<string>& path_segments, 
00098             bool numbered, bool suppress_default_values) const;
00099     string show_tree(bool numbered) const;
00100     string show_unannotated_tree(bool numbered) const;
00101     string tree_str() const;
00102 
00103     bool apply_deltas(uid_t user_id, const string& deltas, 
00104               bool provisional_change, bool preserve_node_id,
00105               string& response);
00106     bool apply_deletions(uid_t user_id, const string& deletions, 
00107              bool provisional_change, string& response);
00108 
00109     void retain_different_nodes(const ConfigTree& them,
00110                 bool retain_changed_values);
00111     void retain_deletion_nodes(const ConfigTree& them,
00112                    bool retain_value_changed);
00113     void retain_common_nodes(const ConfigTree& them);
00114     void add_default_children();
00115 
00116     void expand_varname_to_matchlist(const string& varname, 
00117                          list<string>& matches) const;
00118 
00119 protected:
00120     string path_as_string(const list<string>& path_segments) const;
00121     string current_path_as_string() const;
00122     const ConfigTreeNode* find_config_node(const list<string>& path_segments) const;
00123 
00124     string      _config_file;
00125     TemplateTree*   _template_tree;
00126     //ConfigTreeNode    _root_node;
00127     ConfigTreeNode* _current_node;
00128     list<ConfPathSegment>   _path_segments;
00129     list<size_t>    _segment_lengths;
00130     bool        _verbose;
00131 };
00132 
00133 #endif // __RTRMGR_CONF_TREE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations