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

Import libconf/nutconf features #2283

Closed
wants to merge 128 commits into from

Conversation

jimklimov
Copy link
Member

@jimklimov jimklimov commented Jan 27, 2024

This codebase lingered in side branches of NUT since 2013, and used in forked projects, providing a neat C++ parser of NUT configuration files as a library and a front-end CLI tool to read, write and "understand" them. It was further used in an automated installer for NUT packages on some platforms (to be ported later).

This PR brings back the initial coding effort from the libconf branch (cherry-picked over NUT v2.6.5 because there was a lot of noise, and modernized with a series of tag merges), as well as further clean-ups done in the FTY branch and recently in PR #2275.

Part of the aim of this PR is to integrate the feature separately from many others that evolved in the forks, with minimal intrusion into the generally used NUT codebase up till now. It should also help iterate build nuances for the many platforms now covered by NUT CI, so that these recipes succeed everywhere (cursorily looking, POSIX-like headers available on Windows can be problematic).

At this moment, while the tool would be likely usable for the config syntax of 2013 vintage, it would need further updates for evolution since NUT v2.6.5 for both common options (master/primary, USB matching, etc.) and for various new driver toggles. Probably the augeas lens file evolution would help in the next steps.

Note that this PR does not actually enable builds of the codebase by default (support of C++11, optionally CPPUNIT), but only on some select CI agents that claim the ability. A more general support (notably MinGW implementation or pruning) would be the focus of a follow-up PR.

EmilienKia and others added 30 commits January 27, 2024 17:46
Just parse tokens.
Rename NutConfParser in NutParser.
Implement the abstract class NutConfParser based on NutParser for configuration file parsing.
Remove old C sample code.
Add stubs for the default configuration file parser.
Basic implementation will follow.
Add UT for GenericConfiguration (validate GenericConfigParser and all the stack).
Fix some errors found with UT.
Test pending.
A bug is pending: IPv6 format must be in quoted string because of ':'.
Add parsing option to NutParser.
Add a first option OPTION_IGNORE_COLON to parse ':' as a normal character and not as token.
Use it to allow parsing "::1" IPv6-like as string without having to quote them (upsd.conf).
nut::NutMemory (memory-based stream)
nut::NutFile (file-stream)
nut::NutSocket with nut::NutSocket::Address (UNIX domain, IPv4, IPv6)
Basic unit tests plus a few minor changes and updates to the code
General serialisers implemented
Several TBDs and TODOs left for review
tbc...
Getters/setters for all UPS config. attributes added
The getters/setters need further checking for type correctness
Generic support for the above implemented in GenericConfiguration class
The special serialiser is needed because of the [upsmon]::upsmon
directive (which doesn't use the standard = key/ value separator).
Also, serialisation of section entry value list was fixed (so that
multiple entries are produced rather than a list of values).
All existing NUT configuration classes now implement
Serialisable interface (parseFrom and writeTo methods).
Note that the parseFrom implementations are very naive
(they simply read whole source stream to memory and call
existing parseFromString method).  That's enough for now,
however, in future the parsres should directly use NutStream
interface.
UTs with focus on basic configuration settings and serialisation
were added for nut.conf, upsmon.conf, upsd.conf ups.conf and upsd.users.
Note that the tests are not exhaustive; they only parse configuration
files samples, change a few randomly selected parameters, serialise
the result back and check it.
A non-complete implementation of NUT IPC support module.
Certain functions are just outlined, for now.
Deals with signal handling and execution of external commands.
I commit this partial implementation because I'll be on holiday
for certain amount of time and it's IMO better to have the code
comitted.
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…od arg name

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…hods

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ns" (weak-vtables)

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov jimklimov added feature nut-scanner nutconf NUT configuration library and tool labels Jan 27, 2024
jimklimov and others added 2 commits January 28, 2024 19:18
…tors with clang++ to not worry about "(static) const something" variables

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ns in parallel testing

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov jimklimov marked this pull request as draft January 29, 2024 19:14
@jimklimov
Copy link
Member Author

jimklimov commented Jan 29, 2024

Superseded by #2290 which (eventually) gets this codebase buildable without warnings. It becomes too tedious to keep applying same hotfixes for a warning here and there on systems whose agents claim support for nutconf vs. just all of them suitable ones based on basic prerequisites, for little benefit (when that PR is ready, it gets merged pulling this one in anyway).

@jimklimov
Copy link
Member Author

Effectively merged via #2290

@jimklimov jimklimov closed this Feb 15, 2024
@jimklimov jimklimov deleted the libconf-nutconf branch February 15, 2024 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature nut-scanner nutconf NUT configuration library and tool
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants