dchroot-dsa-chroot-config.cc

Go to the documentation of this file.
00001 /* Copyright © 2005-2006  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::keyfile;
00037 using boost::format;
00038 using namespace dchroot_dsa;
00039 
00040 chroot_config::chroot_config ():
00041   sbuild::chroot_config()
00042 {
00043 }
00044 
00045 chroot_config::chroot_config (std::string const& file,
00046                               bool               active):
00047   sbuild::chroot_config(file, active)
00048 {
00049 }
00050 
00051 chroot_config::~chroot_config ()
00052 {
00053 }
00054 
00055 void
00056 chroot_config::parse_data (std::istream& stream,
00057                            bool          active)
00058 {
00059   active = false; // dchroot does not support sessions.
00060 
00061   size_t linecount = 0;
00062   std::string line;
00063   std::string chroot_name;
00064   std::string chroot_location;
00065 
00066   sbuild::keyfile kconfig;
00067 
00068   while (std::getline(stream, line))
00069     {
00070       linecount++;
00071 
00072       if (line[0] == '#')
00073         {
00074           // Comment line; do nothing.
00075         }
00076       else if (line.length() == 0)
00077         {
00078           // Empty line; do nothing.
00079         }
00080       else // Item
00081         {
00082           static const char *whitespace = " \t:;,";
00083 
00084           // Get chroot name
00085           std::string::size_type cstart = line.find_first_not_of(whitespace);
00086           std::string::size_type cend = line.find_first_of(whitespace, cstart);
00087 
00088           // Get chroot location
00089           std::string::size_type lstart = line.find_first_not_of(whitespace,
00090                                                                  cend);
00091           std::string::size_type lend = line.find_first_of(whitespace, lstart);
00092 
00093           if (cstart == std::string::npos)
00094             throw keyfile::error(linecount, keyfile::INVALID_LINE, line);
00095 
00096           std::string chroot_name = line.substr(cstart, cend - cstart);
00097 
00098           std::string location;
00099           if (lstart != std::string::npos)
00100             location = line.substr(lstart, lend - lstart);
00101 
00102           // DSA dchroot parses valid users.
00103           sbuild::string_list users;
00104           if (lend != std::string::npos)
00105             users = sbuild::split_string(line.substr(lend), whitespace);
00106 
00107           // Add details to keyfile.
00108           if (kconfig.has_group(chroot_name))
00109             throw keyfile::error(linecount, keyfile::DUPLICATE_GROUP,
00110                                  chroot_name);
00111           else
00112             kconfig.set_group(chroot_name, "", linecount);
00113 
00114           kconfig.set_value(chroot_name, "type", "plain", "", linecount);
00115 
00116           // TRANSLATORS: %1% = chroot name
00117           format fmt(_("%1% chroot (dchroot-dsa compatibility)"));
00118           fmt % chroot_name;
00119 
00120           kconfig.set_value(chroot_name, "description", fmt, "", linecount);
00121 
00122           if (lstart != std::string::npos)
00123             kconfig.set_value(chroot_name, "location", location, "", linecount);
00124 
00125           kconfig.set_list_value(chroot_name, "users",
00126                                  users.begin(), users.end(),
00127                                  "", linecount);
00128         }
00129     }
00130 
00131   load_keyfile(kconfig, active);
00132 }

Generated on Sat Jan 27 16:11:02 2007 for schroot by  doxygen 1.5.1