1
0
mirror of https://github.com/fwbuilder/fwbuilder synced 2026-03-24 12:17:26 +01:00

* CompilerDriver.cpp (CompilerDriver::formSingleRuleCompileOutput):

fixes #1110: "when compiler detects fatal error and drops the rule
that caused it, the error does not appear in the single rule
compile output".
This commit is contained in:
Vadim Kurland 2010-01-20 02:54:15 +00:00
parent 76510d7f49
commit 264060a541
8 changed files with 62 additions and 42 deletions

View File

@ -316,7 +316,8 @@ QString CompilerDriver_iosacl::run(const std::string &cluster_id,
if (single_rule_compile_on)
{
return QString::fromUtf8((policy_script + routing_script).c_str());
return formSingleRuleCompileOutput(
QString::fromUtf8((policy_script + routing_script).c_str()));
}
QString script_buffer = assembleFwScript(

View File

@ -627,7 +627,9 @@ QString CompilerDriver_pix::run(const std::string &cluster_id,
if (single_rule_compile_on)
{
return QString::fromUtf8((policy_script + nat_script + routing_script).c_str());
return formSingleRuleCompileOutput(
QString::fromUtf8(
(policy_script + nat_script + routing_script).c_str()));
}
QFileInfo finfo(ofname);

View File

@ -1125,3 +1125,21 @@ bool CompilerDriver::isReachable(const Address* const client,
return false;
}
QString CompilerDriver::formSingleRuleCompileOutput(const QString &generated_code)
{
// in single rule compile mode just return the
// result. Note that we do not return all_errors because
// all compilers include errors and warnings with
// generated code for each rule. Two exceptions: 1)
// CompilerDriver errors need to be added on top, 2) if no
// output has been produced by the compiler, we have to
// show all_errors to the user because there could be an
// error message explaining this. Combined output of all
// compilers we assemble here may consist of a bunch of
// empty lines separated by LF. Need to account for that.
QString res = generated_code;
QString res2 = res.split("\n", QString::SkipEmptyParts).join("").replace(" ", "");
if (res2.isEmpty()) res = all_errors.join("\n");
return res;
}

View File

@ -212,6 +212,17 @@ public:
virtual bool prepare(const QStringList &args);
virtual void compile();
virtual QMap<QString,QString> compileSingleRule(const std::string &rule_id);
/*
* if compilers produced empty string for the generated code,
* this method checks if there were any errors and returns
* them. If compilers generated output, errors should be
* included in it because warning and error messages are
* usually attached to rules. Errors are taken from the
* all_errors member variable.
*/
QString formSingleRuleCompileOutput(const QString &generated_code);
};
};

View File

@ -400,25 +400,20 @@ QString CompilerDriver_ipt::run(const std::string &cluster_id,
all_errors.push_back(routing_compiler->getErrors("").c_str());
}
if (single_rule_compile_on)
{
// in single rule compile mode just return the result Note
// that we do not return all_errors because all compilers
// include errors and warnings with generated code for each
// rule. CompilerDriver errors, however, need to be added on
// top.
return
QString::fromUtf8(
(getErrors("") +
generated_script +
routing_compiler->getCompiledScript()).c_str());
}
if (haveErrorsAndWarnings())
{
all_errors.push_front(getErrors("").c_str());
}
if (single_rule_compile_on)
{
return formSingleRuleCompileOutput(
QString::fromUtf8(
(getErrors("") +
generated_script +
routing_compiler->getCompiledScript()).c_str()));
}
/*
* These store generated configuration internally, extract it later using

View File

@ -312,9 +312,8 @@ QString CompilerDriver_ipf::run(const std::string &cluster_id,
ostr << n.getCompiledScript();
}
return
//all_errors.join("\n").toStdString() +
QString::fromUtf8(ostr.str().c_str());
return formSingleRuleCompileOutput(
QString::fromUtf8(ostr.str().c_str()));
}
@ -340,12 +339,9 @@ QString CompilerDriver_ipf::run(const std::string &cluster_id,
if (c.haveErrorsAndWarnings())
{
all_errors.push_back(c.getErrors("").c_str());
if (!single_rule_compile_on)
{
ipf_str << "# Policy compiler errors and warnings:"
<< endl;
ipf_str << QString::fromUtf8(c.getErrors("# ").c_str());
}
ipf_str << "# Policy compiler errors and warnings:"
<< endl;
ipf_str << QString::fromUtf8(c.getErrors("# ").c_str());
}
ipf_str << QString::fromUtf8(c.getCompiledScript().c_str());
ipf_file.close();
@ -391,12 +387,9 @@ QString CompilerDriver_ipf::run(const std::string &cluster_id,
if (n.haveErrorsAndWarnings())
{
all_errors.push_back(n.getErrors("").c_str());
if (!single_rule_compile_on)
{
nat_str << "# NAT compiler errors and warnings:"
<< endl;
nat_str << QString::fromUtf8(n.getErrors("# ").c_str());
}
nat_str << "# NAT compiler errors and warnings:"
<< endl;
nat_str << QString::fromUtf8(n.getErrors("# ").c_str());
}
nat_str << QString::fromUtf8(n.getCompiledScript().c_str());
nat_file.close();

View File

@ -254,17 +254,14 @@ QString CompilerDriver_ipfw::run(const std::string &cluster_id,
if (!single_rule_compile_on)
c_str << "# ================ Rule set "
<< branch_name << endl;
if (c.haveErrorsAndWarnings())
{
all_errors.push_back(c.getErrors("").c_str());
// c_str << "# Policy compiler errors and warnings:"
// << endl;
// c_str << c.getErrors("# ");
}
c_str << c.getCompiledScript();
c_str << endl;
empty_output = false;
}
if (c.haveErrorsAndWarnings())
{
all_errors.push_back(c.getErrors("").c_str());
}
}
}
@ -293,7 +290,8 @@ QString CompilerDriver_ipfw::run(const std::string &cluster_id,
if (single_rule_compile_on)
{
return QString::fromUtf8(generated_script.c_str());
return formSingleRuleCompileOutput(
QString::fromUtf8(generated_script.c_str()));
}
PolicyCompiler_ipfw c(objdb, fw, false, oscnf.get());

View File

@ -385,7 +385,6 @@ QString CompilerDriver_pf::run(const std::string &cluster_id,
{
// store errors and warnings so they will appear on top
// of .fw file in addition to the .conf file
all_errors.push_back(n.getErrors("").c_str());
if (!single_rule_compile_on)
{
*(generated_scripts[ruleset_name])
@ -398,6 +397,8 @@ QString CompilerDriver_pf::run(const std::string &cluster_id,
*(generated_scripts[ruleset_name]) << endl;
}
all_errors.push_back(n.getErrors("").c_str());
conf_files[ruleset_name] = getConfFileName(
ruleset_name,
current_firewall_name.toUtf8().constData(),
@ -476,7 +477,6 @@ QString CompilerDriver_pf::run(const std::string &cluster_id,
{
if (c.haveErrorsAndWarnings())
{
all_errors.push_back(c.getErrors("").c_str());
if (!single_rule_compile_on)
{
*(generated_scripts[ruleset_name])
@ -489,6 +489,8 @@ QString CompilerDriver_pf::run(const std::string &cluster_id,
*(generated_scripts[ruleset_name]) << endl;
}
all_errors.push_back(c.getErrors("").c_str());
conf_files[ruleset_name] = getConfFileName(
ruleset_name,
current_firewall_name.toUtf8().constData(),
@ -527,7 +529,7 @@ QString CompilerDriver_pf::run(const std::string &cluster_id,
table_factories.clear();
generated_scripts.clear();
return buffer;
return formSingleRuleCompileOutput(buffer);
}
/*