19 #include <zypp-core/base/UserRequestException> 20 #include <zypp-core/parser/ParseException> 26 #undef ZYPP_BASE_LOGGER_LOGGROUP 27 #define ZYPP_BASE_LOGGER_LOGGROUP "parser::susetags" 42 Pathname sanitize( Pathname path_r )
44 Pathname ret = path_r.absolutename();
45 if ( path_r.relativeDotDot() ) {
48 pWAR(
"Hostile location:", path_r,
"=>", ret );
53 std::string sanitizeEntry( Pathname path_r )
58 if ( path_r.relativeDotDot() ) {
61 pWAR(
"Hostile location:", path_r,
"=>",
"discard data entry" );
65 std::string ret = path_r.asString();
66 if ( ret.size() <= 1 )
69 ret = ret.substr( 1 );
71 ret = ret.substr( 2 );
106 bool setFileCheckSum( std::map<std::string, CheckSum> & map_r,
const std::string & value )
const 109 std::vector<std::string> words;
110 if (
str::split( value, std::back_inserter( words ) ) == 3 )
112 std::string pathstr = sanitizeEntry( words[2] );
113 if ( not pathstr.empty() )
114 map_r[std::move(pathstr)] =
CheckSum( words[0], words[1] );
162 _pimpl->repoindex().descrdir =
"suse/setup/descr";
163 _pimpl->repoindex().datadir =
"suse";
174 if (
_pimpl->hasRepoIndex() )
180 MIL <<
"[Content]" << endl;
200 const std::string & msg_r,
201 const std::string & line_r )
const 204 _pimpl->_inputname.c_str(),
218 MIL <<
"Start parsing content repoindex" << input_r << endl;
221 std::ostringstream s;
222 s <<
"Can't read bad stream: " << input_r;
230 if ( ! ticks.
toMin() )
234 for( ; line; line.
next() )
237 std::string value( *line );
240 if ( key.empty() || *key.c_str() ==
'#' )
246 std::string modifier;
248 if ( pos != std::string::npos )
250 modifier = key.substr( pos+1 );
257 else if ( key ==
"DESCRDIR" )
259 _pimpl->repoindex().descrdir = sanitize( value );
261 else if ( key ==
"DATADIR" )
263 _pimpl->repoindex().datadir = sanitize( value );
265 else if ( key ==
"KEY" )
267 if (
_pimpl->setFileCheckSum(
_pimpl->repoindex().signingKeys, value ) )
272 else if ( key ==
"META" )
274 if (
_pimpl->setFileCheckSum(
_pimpl->repoindex().metaFileChecksums, value ) )
279 else if ( key ==
"HASH" )
281 if (
_pimpl->setFileCheckSum(
_pimpl->repoindex().mediaFileChecksums, value ) )
292 if ( ! ticks.
set( input_r.
stream().tellg() ) )
299 if ( ! ticks.
toMax() )
303 MIL <<
"Done parsing " << input_r << endl;
ProgressData makeProgressData(const InputStream &input_r)
relates: ProgressData Setup from InputStream.
std::string errPrefix(unsigned lineNo_r, const std::string &msg_r=std::string(), const std::string &line_r="-") const
Prefix exception message with line information.
void sendTo(const ReceiverFnc &fnc_r)
Set ReceiverFnc.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
bool next()
Advance to next line.
ContentFileReader implementation.
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
unsigned lineNo() const
Return the current line number.
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
bool toMax()
Set counter value to current max value (unless no range).
static bool warning(const std::string &msg_r, const UserData &userData_r=UserData())
send warning text
Simple lineparser: Traverse each line in a file.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
bool setFileCheckSum(std::map< std::string, CheckSum > &map_r, const std::string &value) const
virtual void userRequestedAbort(unsigned lineNo_r)
Called when user(callback) request to abort.
bool toMin()
Set counter value to current min value.
RepoIndex_Ptr handoutRepoIndex()
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \, const Trim trim_r=NO_TRIM)
Split line_r into words.
std::string stripFirstWord(std::string &line, const bool ltrim_first)
RepoIndexConsumer _repoIndexConsumer
Maintain [min,max] and counter (value) for progress counting.
std::string sconcat(Args &&... args)
Concat words as string.
virtual void beginParse()
Called when start parsing.
ContentFileReader()
Default ctor.
bool hasRepoIndex() const
virtual void endParse()
Called when the parse is done.
bool set(value_type val_r)
Set new counter value.
virtual ~ContentFileReader()
Dtor.
Easy-to use interface to the ZYPP dependency resolver.
virtual void parse(const InputStream &imput_r, const ProgressData::ReceiverFnc &fnc_r=ProgressData::ReceiverFnc())
Parse the stream.