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         CHROOT_EXIST,      
00063         FILE_NOTREG,       
00064         FILE_OPEN,         
00065         FILE_OWNER,        
00066         FILE_PERMS,        
00067         NAME_INVALID,      
00068         NAMESPACE_NOTFOUND 
00069       };
00070 
00072     typedef custom_error<error_code> error;
00073 
00075     typedef std::tr1::shared_ptr<chroot_config> ptr;
00076 
00078     chroot_config ();
00079 
00088     chroot_config (std::string const& chroot_namespace,
00089                    std::string const& file);
00090 
00092     virtual ~chroot_config ();
00093 
00103     void
00104     add (std::string const& chroot_namespace,
00105          std::string const& location);
00106 
00107   private:
00116     void
00117     add_config_file (std::string const& chroot_namespace,
00118                      std::string const& file);
00119 
00128     void
00129     add_config_directory (std::string const& chroot_namespace,
00130                           std::string const& dir);
00131 
00132   protected:
00144     void
00145     add (std::string const& chroot_namespace,
00146          chroot::ptr&       chroot,
00147          keyfile const&     kconfig);
00148 
00149   public:
00157     chroot_list
00158     get_chroots (std::string const& chroot_namespace) const;
00159 
00160   protected:
00168     chroot_map&
00169     find_namespace (std::string const& chroot_namespace);
00170 
00178     chroot_map const&
00179     find_namespace (std::string const& chroot_namespace) const;
00180 
00181   public:
00189     const chroot::ptr
00190     find_chroot (std::string const& name) const;
00191 
00200     const chroot::ptr
00201     find_chroot (std::string const& namespace_hint,
00202                  std::string const& name) const;
00203 
00211     const sbuild::chroot::ptr
00212     find_chroot_in_namespace (std::string const& chroot_namespace,
00213                               std::string const& name) const;
00214 
00223     const chroot::ptr
00224     find_alias (std::string const& namespace_hint,
00225                 std::string const& name) const;
00226 
00235     std::string
00236     lookup_alias (std::string const& namespace_hint,
00237                   std::string const& name) const;
00238 
00247     string_list
00248     get_chroot_list (std::string const& chroot_namespace) const;
00249 
00258     string_list
00259     get_alias_list (std::string const& chroot_namespace) const;
00260 
00269     void
00270     print_chroot_list (string_list const& chroots,
00271                        std::ostream& stream) const;
00272 
00279     void
00280     print_chroot_list_simple (std::ostream& stream) const;
00281 
00289     void
00290     print_chroot_info (string_list const& chroots,
00291                        std::ostream&      stream) const;
00292 
00300     void
00301     print_chroot_location (string_list const& chroots,
00302                            std::ostream&      stream) const;
00303 
00311     void
00312     print_chroot_config (string_list const& chroots,
00313                          std::ostream&      stream) const;
00314 
00327     string_list
00328     validate_chroots (std::string const& namespace_hint,
00329                       string_list&       chroots) const;
00330 
00331   private:
00341     void
00342     load_data (std::string const& chroot_namespace,
00343                std::string const& file);
00344 
00345   protected:
00354     virtual void
00355     parse_data (std::string const& chroot_namespace,
00356                 std::istream& stream);
00357 
00366     virtual void
00367     load_keyfile (std::string const& chroot_namespace,
00368                   keyfile& kconfig);
00369 
00371     chroot_namespace_map namespaces;
00373     string_map aliases;
00374   };
00375 
00376 }
00377 
00378 #endif /* SBUILD_CHROOT_CONFIG_H */
00379 
00380 /*
00381  * Local Variables:
00382  * mode:C++
00383  * End:
00384  */

Generated on Tue Jan 18 21:48:56 2011 for sbuild by  doxygen 1.5.6