infoconv: new program

This commit is contained in:
Junxiao Shi committed 2020-06-02 20:47:18 -04:00
1 parent 5ef83615b5
commit 7f8bc18ea4
6 files changed
+207 -133

No files matched your search

+1
View File
@@ -1 +1,2 @@
infoconv
infoedit
+9 -4
View File
@@ -1,10 +1,15 @@
all: infoedit
all: infoconv infoedit
infoconv: infoconv.cpp
$(CXX) -o infoconv -std=c++11 infoconv.cpp
infoedit: infoedit.hpp infoedit.cpp
g++ -o infoedit -std=c++11 infoedit.cpp -lboost_program_options
$(CXX) -o infoedit -std=c++11 infoedit.cpp -lboost_program_options
install: infoedit
cp infoedit /usr/local/bin/infoedit
install: infoconv infoedit
install /usr/local/bin/infoconv infoconv
install /usr/local/bin/infoedit infoedit
uninstall:
rm /usr/local/bin/infoconv
rm /usr/local/bin/infoedit
+4 -129
View File
@@ -1,131 +1,6 @@
A tool used to edit NFD configuration files
===========================================
# Command Line Tools for Boost INFO Format
This tool is majorly developed for use in NFD integration tests. However, it can also used to
edit any INFO-formatted files.
This repository contains programs for working with [Boost INFO](https://www.boost.org/doc/libs/1_73_0/doc/html/property_tree/parsers.html#property_tree.parsers.info_parser) file format, as defined in Boost Property Tree library.
Each invocation of `infoedit` tool performs exactly one edit and the file is modified in place.
To perform multiple edits, `infoedit` tool should be invoked multiple times on the same file.
## Usage ##
infoedit [-f file] [-s|d|a|r path] [-v value]
OPTIONS:
* `-f file`: specifies a file to edit
* `-s path`: specifies a property-tree path to modify
* `-p path`: specifies a property-tree path to add (duplicates can be added)
* `-v value`: used with -s path or -p path, sets the value at the path
* `-d path`: deletes all subtrees matching the path
* `-a path`: adds a subtree at the path; the subtree is read from stdin
* `-r path`: replaces a subtree at the path; equivalent to -d path followed by -a path
## Sample commands for NFD ##
./infoedit -f nfd.conf -s general.user -v ndn.user
./infoedit -f nfd.conf -s tables.strategy_choice./site -v /localhost/nfd/strategy/broadcast
./infoedit -f nfd.conf -d tables.strategy_choice./
./infoedit -f nfd.conf -d authorizations
./infoedit -f nfd.conf -a rib.localhost_security <<<EOT
trust-anchor
{
type any
}
EOT
### nfd.conf used in above sample ###
; comment1
general ; comment2
{
user user ; comment3
group group
}
tables
{
strategy_choice
{
/ /localhost/nfd/strategy/best-route
/site /localhost/nfd/strategy/broadcast
}
}
authorizations
{
authorize
{
certfile file1.cert
}
authorize
{
certfile file2.cert
}
}
### nfd.conf after carrying out all commands in above sample ###
general
{
user ndn.user
group group
}
tables
{
strategy_choice
{
/site /localhost/nfd/strategy/broadcast
}
}
rib
{
localhost_security
{
trust-anchor
{
type any
}
}
}
## Sample commands for NLSR ##
./infoedit -f nlsr.conf -d security.cert-to-publish
./infoedit -f nlsr.conf -p security.cert-to-publish -v security/root.cert
./infoedit -f nlsr.conf -p security.cert-to-publish -v security/site.cert
./infoedit -f nlsr.conf -p security.cert-to-publish -v security/operator.cert
./infoedit -f nlsr.conf -p security.cert-to-publish -v security/router.cert
### nlsr.conf used in above sample ###
...
security
{
...
; cert-to-publish "root.cert"
; cert-to-publish "site.cert"
; cert-to-publish "operator.cert"
cert-to-publish "router.cert"
}
### nlsr.conf after carrying out all commands in above sample ###
...
security
{
...
cert-to-publish security/root.cert
cert-to-publish security/site.cert
cert-to-publish security/operator.cert
cert-to-publish security/router.cert
}
* [infoconv](infoconv.md) converts between INFO and JSON formats.
* [infoedit](infoedit.md) programmatically edits an INFO file.
+50
View File
@@ -0,0 +1,50 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <iostream>
namespace pt = boost::property_tree;
static void
usage()
{
std::cerr << "USAGE\n"
" infoconv info2json < config.info > config.json\n"
" infoconv json2info < config.info > config.info\n";
}
static void
info2json()
{
pt::ptree tree;
pt::info_parser::read_info(std::cin, tree);
pt::json_parser::write_json(std::cout, tree);
}
static void
json2info()
{
pt::ptree tree;
pt::json_parser::read_json(std::cin, tree);
pt::info_parser::write_info(std::cout, tree);
}
int
main(int argc, char** argv)
{
if (argc != 2) {
usage();
return 2;
}
std::string action(argv[1]);
if (action == "info2json") {
info2json();
}
else if (action == "json2info") {
json2info();
}
else {
usage();
return 2;
}
}
+11
View File
@@ -0,0 +1,11 @@
# infoconv: Convert between INFO and JSON
**infoconv** program allows converting between Boost INFO and JSON formats.
One use case is to allow processing INFO files with JSON tools such as [jq](https://stedolan.github.io/jq/).
Usage:
```
infoconv info2json < config.info > config.json
infoconv json2info < config.json > config.info
```
+132
View File
@@ -0,0 +1,132 @@
# A tool used to edit NFD configuration files
This tool is majorly developed for use in NFD integration tests. However, it can also used to
edit any INFO-formatted files.
Each invocation of `infoedit` tool performs exactly one edit and the file is modified in place.
To perform multiple edits, `infoedit` tool should be invoked multiple times on the same file.
## Usage
infoedit [-f file] [-s|d|a|r path] [-v value]
OPTIONS:
* `-f file`: specifies a file to edit
* `-s path`: specifies a property-tree path to modify
* `-p path`: specifies a property-tree path to add (duplicates can be added)
* `-v value`: used with -s path or -p path, sets the value at the path
* `-d path`: deletes all subtrees matching the path
* `-a path`: adds a subtree at the path; the subtree is read from stdin
* `-r path`: replaces a subtree at the path; equivalent to -d path followed by -a path
## Sample commands for NFD
./infoedit -f nfd.conf -s general.user -v ndn.user
./infoedit -f nfd.conf -s tables.strategy_choice./site -v /localhost/nfd/strategy/broadcast
./infoedit -f nfd.conf -d tables.strategy_choice./
./infoedit -f nfd.conf -d authorizations
./infoedit -f nfd.conf -a rib.localhost_security <<<EOT
trust-anchor
{
type any
}
EOT
### nfd.conf used in above sample
; comment1
general ; comment2
{
user user ; comment3
group group
}
tables
{
strategy_choice
{
/ /localhost/nfd/strategy/best-route
/site /localhost/nfd/strategy/broadcast
}
}
authorizations
{
authorize
{
certfile file1.cert
}
authorize
{
certfile file2.cert
}
}
### nfd.conf after carrying out all commands in above sample
general
{
user ndn.user
group group
}
tables
{
strategy_choice
{
/site /localhost/nfd/strategy/broadcast
}
}
rib
{
localhost_security
{
trust-anchor
{
type any
}
}
}
## Sample commands for NLSR
./infoedit -f nlsr.conf -d security.cert-to-publish
./infoedit -f nlsr.conf -p security.cert-to-publish -v security/root.cert
./infoedit -f nlsr.conf -p security.cert-to-publish -v security/site.cert
./infoedit -f nlsr.conf -p security.cert-to-publish -v security/operator.cert
./infoedit -f nlsr.conf -p security.cert-to-publish -v security/router.cert
### nlsr.conf used in above sample
...
security
{
...
; cert-to-publish "root.cert"
; cert-to-publish "site.cert"
; cert-to-publish "operator.cert"
cert-to-publish "router.cert"
}
### nlsr.conf after carrying out all commands in above sample
...
security
{
...
cert-to-publish security/root.cert
cert-to-publish security/site.cert
cert-to-publish security/operator.cert
cert-to-publish security/router.cert
}
###