00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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;
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
00076 }
00077 else if (line.length() == 0)
00078 {
00079
00080 }
00081 else
00082 {
00083 static const char *whitespace = " \t:;,";
00084
00085
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
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
00104 sbuild::string_list users;
00105 if (lend != std::string::npos)
00106 users = sbuild::split_string(line.substr(lend), whitespace);
00107
00108
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
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 }