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::keyfile;
00037 using boost::format;
00038 using namespace dchroot;
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;
00060
00061 size_t linecount = 0;
00062 std::string line;
00063 std::string chroot_name;
00064 std::string chroot_location;
00065 bool default_set = false;
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
00095 std::string::size_type pstart = line.find_first_not_of(whitespace,
00096 lend);
00097 std::string::size_type pend = line.find_first_of(whitespace, pstart);
00098
00099
00100 std::string::size_type tstart = line.find_first_not_of(whitespace,
00101 pend);
00102 if (cstart == std::string::npos ||
00103 tstart != std::string::npos)
00104 throw keyfile::error(linecount, keyfile::INVALID_LINE, line);
00105
00106 std::string chroot_name = line.substr(cstart, cend - cstart);
00107
00108 std::string location;
00109 if (lstart != std::string::npos)
00110 location = line.substr(lstart, lend - lstart);
00111
00112 std::string personality;
00113 if (pstart != std::string::npos)
00114 personality = line.substr(pstart, pend - pstart);
00115
00116
00117 if (kconfig.has_group(chroot_name))
00118 throw keyfile::error(linecount, keyfile::DUPLICATE_GROUP,
00119 chroot_name);
00120 else
00121 kconfig.set_group(chroot_name, "", linecount);
00122
00123 kconfig.set_value(chroot_name, "type", "plain", "", linecount);
00124
00125
00126 format fmt(_("%1% chroot (dchroot compatibility)"));
00127 fmt % chroot_name;
00128
00129 kconfig.set_value(chroot_name, "description", fmt, "", linecount);
00130
00131 if (lstart != std::string::npos)
00132 kconfig.set_value(chroot_name, "location", location, "", linecount);
00133
00134 if (pstart != std::string::npos)
00135 kconfig.set_value(chroot_name, "personality", personality, "", linecount);
00136
00137 if (chroot_name == "default")
00138 default_set = true;
00139
00140
00141 if (!default_set)
00142 {
00143 sbuild::string_list aliases;
00144 aliases.push_back("default");
00145 kconfig.set_list_value(chroot_name, "aliases",
00146 aliases.begin(), aliases.end(),
00147 "", linecount);
00148 default_set = true;
00149 }
00150
00151 }
00152 }
00153
00154 load_keyfile(kconfig, active);
00155 }