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-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;
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 bool default_set = false;
00067
00068 sbuild::keyfile kconfig;
00069
00070 while (std::getline(stream, line))
00071 {
00072 linecount++;
00073
00074 if (line[0] == '#')
00075 {
00076
00077 }
00078 else if (line.length() == 0)
00079 {
00080
00081 }
00082 else
00083 {
00084 static const char *whitespace = " \t";
00085
00086
00087 std::string::size_type cstart = line.find_first_not_of(whitespace);
00088 std::string::size_type cend = line.find_first_of(whitespace, cstart);
00089
00090
00091 std::string::size_type lstart = line.find_first_not_of(whitespace,
00092 cend);
00093 std::string::size_type lend = line.find_first_of(whitespace, lstart);
00094
00095
00096 std::string::size_type pstart = line.find_first_not_of(whitespace,
00097 lend);
00098 std::string::size_type pend = line.find_first_of(whitespace, pstart);
00099
00100
00101 std::string::size_type tstart = line.find_first_not_of(whitespace,
00102 pend);
00103 if (cstart == std::string::npos ||
00104 tstart != std::string::npos)
00105 throw keyfile::error(linecount, keyfile::INVALID_LINE, line);
00106
00107 std::string chroot_name = line.substr(cstart, cend - cstart);
00108
00109 std::string location;
00110 if (lstart != std::string::npos)
00111 location = line.substr(lstart, lend - lstart);
00112
00113 std::string personality;
00114 if (pstart != std::string::npos)
00115 personality = line.substr(pstart, pend - pstart);
00116
00117
00118 if (kconfig.has_group(chroot_name))
00119 throw keyfile::error(linecount, keyfile::DUPLICATE_GROUP,
00120 chroot_name);
00121 else
00122 kconfig.set_group(chroot_name, "", linecount);
00123
00124 kconfig.set_value(chroot_name, "type", "plain", "", linecount);
00125
00126
00127 format fmt(_("%1% chroot (dchroot compatibility)"));
00128 fmt % chroot_name;
00129
00130 kconfig.set_value(chroot_name, "description", fmt, "", linecount);
00131
00132 if (lstart != std::string::npos)
00133 kconfig.set_value(chroot_name, "location", location, "", linecount);
00134
00135 if (pstart != std::string::npos)
00136 kconfig.set_value(chroot_name, "personality", personality, "", linecount);
00137
00138 if (chroot_name == "default")
00139 default_set = true;
00140
00141
00142 if (!default_set)
00143 {
00144 sbuild::string_list aliases;
00145 aliases.push_back("default");
00146 kconfig.set_list_value(chroot_name, "aliases",
00147 aliases.begin(), aliases.end(),
00148 "", linecount);
00149 default_set = true;
00150 }
00151
00152 }
00153 }
00154
00155 load_keyfile(kconfig, active);
00156 }