Remove JSON library dependency.

This commit is contained in:
Jacob Windle 2019-12-16 14:45:02 -05:00
parent 7418c743fe
commit 7f78683035
2 changed files with 2 additions and 15 deletions

View File

@ -1,7 +1,3 @@
project(HostBlocker)
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONC REQUIRED json-c)
add_executable(hb main.c)
target_link_libraries(hb ${JSONC_LIBS})
target_include_directories(hb PUBLIC ${JSONC_INCLUDE_DIRS})
add_executable(hb main.c)

11
main.c
View File

@ -6,8 +6,6 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <json_tokener.h>
// Macro for status checks.
#define ONFAILED(status, fn) if(status > fn)
@ -25,7 +23,6 @@ const char *CONFIG;
// The current hardcoded location of the hosts file.
static const char *HOSTFILE = "/etc/hosts";
// Our configuration
struct json_object *config;
/**
* SIGINT handler, cleans up resources on Ctrl-C
@ -36,7 +33,6 @@ void int_handler(int signal) {
fprintf(stderr, "SIGINT received, cleaning up...\n");
// This should be the final decrement to the config object.
json_object_put(config);
}
void replacehost(char *oldhost, char *newhost);
@ -101,11 +97,7 @@ void showHosts()
*/
int read_config_file() {
// increment the refcount for tmp.
struct json_object *tmp = json_object_get(config);
/** Utilize the JSON parsing library json-c to parse configuration */
json_object_object_foreach(tmp, key, val) {
fprintf(stderr,"Key: %s\nValue:%s\n\n", key, val);
}
}
/**
@ -184,7 +176,6 @@ int main(int argc, char **argv)
showHosts();
}
else if (strcmp(argv[i], "-config") == 0) {
config = json_tokener_parse(argv[++i]);
CONFIG = argv[i];
}