Refactor
This commit is contained in:
parent
0706cd144b
commit
6992624b19
|
@ -0,0 +1,5 @@
|
|||
claugeas - Augeas Wrapper
|
||||
|
||||
Library that facilitates C# and other language bindings.
|
||||
This is a necessary library for the Augeas C# bindings.
|
||||
|
10
README.md
10
README.md
|
@ -1,10 +0,0 @@
|
|||
# clAugeas
|
||||
|
||||
Lbrary of functions for editing of relevant files to manage development environments.
|
||||
|
||||
## TODO :
|
||||
- Possibility to create a collection of sites for the development environment (dev, quality and production) each site can be of the following types:
|
||||
1) static with SSL
|
||||
2) reverse Proxy to existing service (systemd) with SSL.
|
||||
- The domain must be valid
|
||||
- The IP must be valid.
|
83
main.cpp
83
main.cpp
|
@ -8,62 +8,86 @@ inline bool path_exists (const std::string& name) {
|
|||
return (stat (name.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
CLAPI void testSource(const augSettings settings) {
|
||||
int r;
|
||||
struct augeas *aug;
|
||||
char *s;
|
||||
CLAPI void* initAug(augSettings settings, int flags) {
|
||||
|
||||
aug = aug_init(settings.root, settings.loadPath, AUG_NO_STDINC | AUG_NO_LOAD);
|
||||
if(!path_exists(std::string(settings.root))) {
|
||||
std::cout << "error: root path is invalid." << settings.root << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
r = aug_load_file(aug, "/etc/hosts");
|
||||
r = aug_source(aug, "/files/etc/hosts/1/ipaddr", nullptr);
|
||||
|
||||
std::cout << "The value read from node: " << s << std::endl;
|
||||
|
||||
aug_close(aug);
|
||||
return aug_init(settings.root, settings.loadPath, flags);
|
||||
}
|
||||
// This prints the actual file
|
||||
CLAPI void printPreview(const augSettings settings, const char* matchPath, const char* filePath) {
|
||||
struct augeas *aug;
|
||||
|
||||
CLAPI void closeAug(void* aug) {
|
||||
aug_close((augeas*)aug);
|
||||
}
|
||||
|
||||
// Wrapper of aug_preview
|
||||
CLAPI void printPreview(augeas* aug, const char* matchPath, const char* filePath) {
|
||||
|
||||
if(aug == nullptr) {
|
||||
std::cout << "error: augeas is not initialized." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
int r;
|
||||
char *s;
|
||||
char *etc_hosts_fn = nullptr;
|
||||
FILE *hosts_fp = nullptr;
|
||||
char *hosts_txt = nullptr;
|
||||
|
||||
aug = aug_init(settings.root, settings.loadPath, AUG_NO_STDINC | AUG_NO_LOAD);
|
||||
|
||||
r = aug_load_file(aug,filePath);
|
||||
|
||||
r = aug_load_file(aug, filePath);
|
||||
r = aug_preview(aug, matchPath, &s);
|
||||
if(r != 0) {
|
||||
std::cout << "Error loading file." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
r = aug_preview(aug,matchPath,&s);
|
||||
|
||||
if(r != 0) {
|
||||
std::cout << "Failure previewing." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << s << std::endl;
|
||||
|
||||
free(hosts_txt);
|
||||
free(s);
|
||||
aug_close(aug);
|
||||
}
|
||||
|
||||
|
||||
// Print tree of the matchPath
|
||||
CLAPI void printAugTree(
|
||||
const augSettings settings,
|
||||
augeas *aug,
|
||||
const char* matchPath,
|
||||
const char* filePath
|
||||
) {
|
||||
struct augeas *aug;
|
||||
|
||||
if(aug == nullptr) {
|
||||
std::cout << "error: augeas is not initialized." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
int r;
|
||||
|
||||
FILE *out = tmpfile();
|
||||
|
||||
aug = aug_init(settings.root, settings.loadPath, AUG_NO_STDINC | AUG_NO_LOAD);
|
||||
|
||||
if(!path_exists(std::string(settings.root))) {
|
||||
std::cout << "ERROR Path is invalid: " << settings.root << std::endl;
|
||||
}
|
||||
std::cout << settings.root<< std::endl;
|
||||
std::cout << settings.loadPath<< std::endl;
|
||||
|
||||
r = aug_load_file(aug, filePath);
|
||||
|
||||
if(r != 0) {
|
||||
std::cout << "error: can't load file." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
r = aug_print(aug, out,matchPath);
|
||||
|
||||
if(r != 0) {
|
||||
std::cout << "error: aug_print failure." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::map <std::string, std::string> stdBindList;
|
||||
std::map <std::string ,std::string>::iterator pos;
|
||||
|
||||
|
@ -99,7 +123,6 @@ CLAPI void printAugTree(
|
|||
std::cout << "Key: " << pos->first << ";" << " Value: " << pos->second << std::endl;
|
||||
}
|
||||
|
||||
aug_close(aug);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
9
main.h
9
main.h
|
@ -13,12 +13,15 @@
|
|||
|
||||
extern "C" {
|
||||
|
||||
CLAPI void printPreview (augSettings settings,
|
||||
CLAPI void* initAug (augSettings settings, int flags);
|
||||
|
||||
CLAPI void printPreview (augeas* aug,
|
||||
const char* matchPath,
|
||||
const char* filePath);
|
||||
|
||||
|
||||
CLAPI void printAugTree (augSettings settings,
|
||||
CLAPI void printAugTree (augeas* aug,
|
||||
const char* matchPath,
|
||||
const char* filePath);
|
||||
|
||||
CLAPI void closeAug (void* aug);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue