Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for reading YAML files #22

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- run: sudo apt install libyaml-cpp-dev asciidoctor libsystemd-dev
- run: sudo apt install asciidoctor libsystemd-dev
- run: pip install meson ninja pytest
- run: meson setup build
- run: meson test -C build -v
Expand Down
9 changes: 3 additions & 6 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ endif::[]

* https://mesonbuild.com/[Meson], at least version 0.46.0.
* https://ninja-build.org/[Ninja], at least version 1.5.
* https://github.com/jbeder/yaml-cpp[yaml-cpp], at least version 0.5.0
Requirement will be removed in *ip2unix* version 3, since the YAML rule file
format is deprecated.
* {cpp} compiler supporting {cpp}17 (https://gcc.gnu.org/[GNU G++] version 7.0
onwards).
* https://www.python.org/[Python] 3, at least version 3.6 is needed for running
Expand Down Expand Up @@ -223,7 +220,7 @@ To install the required dependencies:

[source,sh-session]
---------------------------------------------------------------------
$ sudo apt install meson g++ libyaml-cpp-dev pkg-config
$ sudo apt install meson g++
---------------------------------------------------------------------

If you want to have the manpage:
Expand All @@ -246,7 +243,7 @@ To install the required dependencies:

[source,sh-session]
---------------------------------------------------------------------
$ sudo yum install meson gcc-c++ yaml-cpp-devel
$ sudo yum install meson gcc-c++
---------------------------------------------------------------------

If you want to have the manpage:
Expand All @@ -269,7 +266,7 @@ To install the required dependencies:

[source,sh-session]
---------------------------------------------------------------------
$ sudo pacman -S yaml-cpp meson gcc pkg-config
$ sudo pacman -S meson gcc
---------------------------------------------------------------------

If you want to have the manpage:
Expand Down
3 changes: 1 addition & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ pkgs.stdenv.mkDerivation rec {
};

nativeBuildInputs = [
pkgs.meson pkgs.ninja pkgs.pkgconfig pkgs.asciidoc pkgs.libxslt.bin
pkgs.meson pkgs.ninja pkgs.asciidoc pkgs.libxslt.bin
pkgs.docbook_xml_dtd_45 pkgs.docbook_xsl pkgs.libxml2.bin pkgs.docbook5
pkgs.python3Packages.pytest pkgs.python3Packages.pytest-timeout
pkgs.systemd
];
buildInputs = [ pkgs.libyamlcpp ];

doCheck = true;

Expand Down
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ lib_cflags = []
lib_ldflags = []

deps = [
dependency('yaml-cpp', version: '>=0.5.0'),
cc.find_library('dl')
]

Expand Down
3 changes: 1 addition & 2 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ let

mesonFlags = [ "-Dtest-timeout=3600" ] ++ attrs.mesonFlags or [];

nativeBuildInputs = [ pkgs.meson pkgs.ninja pkgs.pkgconfig ]
nativeBuildInputs = [ pkgs.meson pkgs.ninja ]
++ attrs.nativeBuildInputs or [];
buildInputs = [ pkgs.libyamlcpp ] ++ attrs.buildInputs or [];

doCheck = attrs.doCheck or true;

Expand Down
70 changes: 3 additions & 67 deletions src/ip2unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,7 @@ static void print_version(void)
stdout);
}

static void warn_deprecated_rules_file_long_opt(void)
{
fputs("The use of the --rules-file option is deprecated and the option"
" will be removed in ip2unix version 3.0. Furthermore, YAML will no"
" longer be supported for rule specification and the new --file"
" option simply takes a file with a list of newline-separated rules"
" as specified via the -r/--rule option.", stderr);
}

static void warn_deprecated_yaml_data(void)
{
fputs("The use of -F/--rules-data option is deprecated and it will be"
" removed in ip2unix version 3. Please use the -r/--rule option"
" instead.\n", stderr);
}

static void warn_deprecated_yaml_file(std::string &filename)
{
fprintf(stderr, "The rule file '%s' contains YAML data, which will no"
" longer be supported in ip2unix version 3. Please use a list of"
" newline-separated rules as specified via the -r/--rule option.",
filename.c_str());
}

static bool push_rule_args_from_file(std::string &filename,
static bool push_rule_args_from_file(std::string filename,
std::vector<std::string> &rule_args)
{
std::ifstream input(filename);
Expand Down Expand Up @@ -164,10 +140,6 @@ int main(int argc, char *argv[])
bool show_rules = false;
unsigned int verbosity = 0;

// TODO: Remove in version 3.0.
bool show_warn_deprecated_rules_file_long_opt = false;
bool show_warn_deprecated_yaml_data = false;

static struct option lopts[] = {
{"help", no_argument, nullptr, 'h'},
{"version", no_argument, nullptr, 'V'},
Expand All @@ -176,19 +148,14 @@ int main(int argc, char *argv[])
{"rule", required_argument, nullptr, 'r'},
{"file", required_argument, nullptr, 'f'},
{"verbose", no_argument, nullptr, 'v'},

// TODO: Remove in version 3.0.
{"rules-file", required_argument, nullptr, 'y'},
{"rules-data", required_argument, nullptr, 'F'},

{nullptr, 0, nullptr, 0}
};

std::optional<std::string> rulefile = std::nullopt;
std::optional<std::string> ruledata = std::nullopt;
std::vector<std::string> rule_args;

while ((c = getopt_long(argc, argv, "+hcpr:f:F:v",
while ((c = getopt_long(argc, argv, "+hcpr:f:v",
lopts, nullptr)) != -1) {
switch (c) {
case 'h':
Expand All @@ -211,28 +178,11 @@ int main(int argc, char *argv[])
rule_args.push_back(optarg);
break;

case 'y':
show_warn_deprecated_rules_file_long_opt = true;
/* fallthrough */
case 'f':
rulefile = std::string(optarg);
if (is_yaml_rule_file(*rulefile))
warn_deprecated_yaml_file(*rulefile);
else if (push_rule_args_from_file(*rulefile, rule_args))
// XXX: This is to make sure that when we use the new rule
// file format we can use multiple -f options.
// TODO: Remove this in version 3.0 when dropping YAML
// support.
rulefile = std::nullopt;
else
if (!push_rule_args_from_file(std::string(optarg), rule_args))
return EXIT_FAILURE;
break;

case 'F':
show_warn_deprecated_yaml_data = true;
ruledata = std::string(optarg);
break;

case 'v':
verbosity++;
break;
Expand All @@ -244,12 +194,6 @@ int main(int argc, char *argv[])
}
}

// TODO: Remove in version 3.0.
if (show_warn_deprecated_rules_file_long_opt)
warn_deprecated_rules_file_long_opt();
if (show_warn_deprecated_yaml_data)
warn_deprecated_yaml_data();

if (!rule_args.empty() && (rulefile || ruledata)) {
fprintf(stderr, "%s: Can't specify both direct rules and a rule"
" file.\n\n", self);
Expand All @@ -275,14 +219,6 @@ int main(int argc, char *argv[])
else
return EXIT_FAILURE;
}
} else if (rulefile) {
auto result = parse_rules(rulefile.value(), true);
if (!result) return EXIT_FAILURE;
rules = result.value();
} else if (ruledata) {
auto result = parse_rules(ruledata.value(), false);
if (!result) return EXIT_FAILURE;
rules = result.value();
} else {
fprintf(stderr, "%s: You need to either specify a rule file with '-f'"
" or directly specify rules via '-r'.\n\n", self);
Expand Down
5 changes: 0 additions & 5 deletions src/preload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ static void init_rules(void)
LOG(FATAL) << "Unable to decode __IP2UNIX_RULES: " << *err;
_exit(EXIT_FAILURE);
}
} else if ((rule_source = getenv("IP2UNIX_RULE_FILE")) != nullptr) {
std::cerr << "The use of the IP2UNIX_RULE_FILE environment"
" variable is deprecated and will be removed in"
" ip2unix version 3.0." << std::endl;
rules = parse_rules(std::string(rule_source), true);
} else {
LOG(FATAL) << "Unable to find __IP2UNIX_RULES!";
_exit(EXIT_FAILURE);
Expand Down
2 changes: 0 additions & 2 deletions src/rules.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ struct Rule {
bool ignore = false;
};

bool is_yaml_rule_file(std::string);
std::optional<std::vector<Rule>> parse_rules(std::string, bool);
std::optional<Rule> parse_rule_arg(size_t, const std::string&);
void print_rules(std::vector<Rule>&, std::ostream&);

Expand Down