sbuild-chroot-config.h

00001 /* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software: you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation, either version 3 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>.
00016  *
00017  *********************************************************************/
00018 
00019 #ifndef SBUILD_CHROOT_CONFIG_H
00020 #define SBUILD_CHROOT_CONFIG_H
00021 
00022 #include <sbuild/sbuild-chroot.h>
00023 #include <sbuild/sbuild-custom-error.h>
00024 
00025 #include <map>
00026 #include <ostream>
00027 #include <vector>
00028 #include <string>
00029 
00030 namespace sbuild
00031 {
00032 
00042  class chroot_config
00043   {
00044   public:
00046     typedef std::vector<chroot::ptr> chroot_list;
00048     typedef std::map<std::string, std::string> string_map;
00050     typedef std::map<std::string, chroot::ptr> chroot_map;
00052     typedef std::map<std::string, chroot_map> chroot_namespace_map;
00053 
00055     static const std::string namespace_separator;
00056 
00058     enum error_code
00059       {
00060         ALIAS_EXIST,       
00061         CHROOT_NOTFOUND,   
00062         CHROOTS_NOTFOUND,  
00063         CHROOT_EXIST,      
00064         FILE_NOTREG,       
00065         FILE_OPEN,         
00066         FILE_OWNER,        
00067         FILE_PERMS,        
00068         NAME_INVALID,      
00069         NAMESPACE_NOTFOUND 
00070       };
00071 
00073     typedef custom_error<error_code> error;
00074 
00076     typedef std::shared_ptr<chroot_config> ptr;
00077 
00079     chroot_config ();
00080 
00089     chroot_config (std::string const& chroot_namespace,
00090                    std::string const& file);
00091 
00093     virtual ~chroot_config ();
00094 
00104     void
00105     add (std::string const& chroot_namespace,
00106          std::string const& location);
00107 
00108   private:
00117     void
00118     add_config_file (std::string const& chroot_namespace,
00119                      std::string const& file);
00120 
00129     void
00130     add_config_directory (std::string const& chroot_namespace,
00131                           std::string const& dir);
00132 
00133   protected:
00145     void
00146     add (std::string const& chroot_namespace,
00147          chroot::ptr&       chroot,
00148          keyfile const&     kconfig);
00149 
00150   public:
00158     chroot_list
00159     get_chroots (std::string const& chroot_namespace) const;
00160 
00161   protected:
00169     chroot_map&
00170     find_namespace (std::string const& chroot_namespace);
00171 
00179     chroot_map const&
00180     find_namespace (std::string const& chroot_namespace) const;
00181 
00182   public:
00190     static void
00191     get_namespace(std::string const& name,
00192                   std::string&       chroot_namespace,
00193                   std::string&       chroot_name);
00194 
00202     const chroot::ptr
00203     find_chroot (std::string const& name) const;
00204 
00213     const chroot::ptr
00214     find_chroot (std::string const& namespace_hint,
00215                  std::string const& name) const;
00216 
00224     const sbuild::chroot::ptr
00225     find_chroot_in_namespace (std::string const& chroot_namespace,
00226                               std::string const& name) const;
00227 
00236     const chroot::ptr
00237     find_alias (std::string const& namespace_hint,
00238                 std::string const& name) const;
00239 
00248     std::string
00249     lookup_alias (std::string const& namespace_hint,
00250                   std::string const& name) const;
00251 
00260     string_list
00261     get_chroot_list (std::string const& chroot_namespace) const;
00262 
00271     string_list
00272     get_alias_list (std::string const& chroot_namespace) const;
00273 
00280     void
00281     print_chroot_list_simple (std::ostream& stream) const;
00282 
00295     chroot_map
00296     validate_chroots (std::string const& namespace_hint,
00297                       string_list const& chroots) const;
00298 
00299   private:
00309     void
00310     load_data (std::string const& chroot_namespace,
00311                std::string const& file);
00312 
00313   protected:
00322     virtual void
00323     parse_data (std::string const& chroot_namespace,
00324                 std::istream& stream);
00325 
00334     virtual void
00335     load_keyfile (std::string const& chroot_namespace,
00336                   keyfile& kconfig);
00337 
00339     chroot_namespace_map namespaces;
00341     string_map aliases;
00342   };
00343 
00344 }
00345 
00346 #endif /* SBUILD_CHROOT_CONFIG_H */
00347 
00348 /*
00349  * Local Variables:
00350  * mode:C++
00351  * End:
00352  */