dchroot-dsa-chroot-config.cc

Go to the documentation of this file.
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 2 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, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00016  * MA  02111-1307  USA
00017  *
00018  *********************************************************************/
00019 
00020 #include <config.h>
00021 
00022 #include <sbuild/sbuild-chroot-plain.h>
00023 #include <sbuild/sbuild-log.h>
00024 #include <sbuild/sbuild-parse-error.h>
00025 
00026 #include "dchroot-dsa-chroot-config.h"
00027 
00028 #include <cerrno>
00029 #include <cstdlib>
00030 #include <cstring>
00031 #include <iostream>
00032 
00033 #include <boost/format.hpp>
00034 
00035 using std::endl;
00036 using sbuild::_;
00037 using sbuild::keyfile;
00038 using boost::format;
00039 using namespace dchroot_dsa;
00040 
00041 chroot_config::chroot_config ():
00042   sbuild::chroot_config()
00043 {
00044 }
00045 
00046 chroot_config::chroot_config (std::string const& file,
00047                               bool               active):
00048   sbuild::chroot_config(file, active)
00049 {
00050 }
00051 
00052 chroot_config::~chroot_config ()
00053 {
00054 }
00055 
00056 void
00057 chroot_config::parse_data (std::istream& stream,
00058                            bool          active)
00059 {
00060   active = false; // dchroot does not support sessions.
00061 
00062   size_t linecount = 0;
00063   std::string line;
00064   std::string chroot_name;
00065   std::string chroot_location;
00066 
00067   sbuild::keyfile kconfig;
00068 
00069   while (std::getline(stream, line))
00070     {
00071       linecount++;
00072 
00073       if (line[0] == '#')
00074         {
00075           // Comment line; do nothing.
00076         }
00077       else if (line.length() == 0)
00078         {
00079           // Empty line; do nothing.
00080         }
00081       else // Item
00082         {
00083           static const char *whitespace = " \t:;,";
00084 
00085           // Get chroot name
00086           std::string::size_type cstart = line.find_first_not_of(whitespace);
00087           std::string::size_type cend = line.find_first_of(whitespace, cstart);
00088 
00089           // Get chroot location
00090           std::string::size_type lstart = line.find_first_not_of(whitespace,
00091                                                                  cend);
00092           std::string::size_type lend = line.find_first_of(whitespace, lstart);
00093 
00094           if (cstart == std::string::npos)
00095             throw keyfile::error(linecount, keyfile::INVALID_LINE, line);
00096 
00097           std::string chroot_name = line.substr(cstart, cend - cstart);
00098 
00099           std::string location;
00100           if (lstart != std::string::npos)
00101             location = line.substr(lstart, lend - lstart);
00102 
00103           // DSA dchroot parses valid users.
00104           sbuild::string_list users;
00105           if (lend != std::string::npos)
00106             users = sbuild::split_string(line.substr(lend), whitespace);
00107 
00108           // Add details to keyfile.
00109           if (kconfig.has_group(chroot_name))
00110             throw keyfile::error(linecount, keyfile::DUPLICATE_GROUP,
00111                                  chroot_name);
00112           else
00113             kconfig.set_group(chroot_name, "", linecount);
00114 
00115           kconfig.set_value(chroot_name, "type", "plain", "", linecount);
00116 
00117           // TRANSLATORS: %1% = chroot name
00118           format fmt(_("%1% chroot (dchroot-dsa compatibility)"));
00119           fmt % chroot_name;
00120 
00121           kconfig.set_value(chroot_name, "description", fmt, "", linecount);
00122 
00123           if (lstart != std::string::npos)
00124             kconfig.set_value(chroot_name, "location", location, "", linecount);
00125 
00126           kconfig.set_list_value(chroot_name, "users",
00127                                  users.begin(), users.end(),
00128                                  "", linecount);
00129         }
00130     }
00131 
00132   load_keyfile(kconfig, active);
00133 }

Generated on Sun Jul 8 21:23:54 2007 for schroot by  doxygen 1.5.2