From 87b3f060923132d74b83a8298a9a1e813b0255f5 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Sun, 22 Nov 2020 01:49:20 +0100 Subject: [PATCH] Add configs for toml in controller --- src/config.c | 7 +-- src/handlers/http.c | 2 +- src/logger.c | 8 +++- tests/emgauwa-controller-testing.conf | 66 +++++++++++++++++++++++++++ tests/emgauwa-controller-testing.ini | 65 -------------------------- tests/run_tests.sh | 5 +- 6 files changed, 79 insertions(+), 74 deletions(-) create mode 100644 tests/emgauwa-controller-testing.conf delete mode 100644 tests/emgauwa-controller-testing.ini diff --git a/src/config.c b/src/config.c index 7ce9df7..8eaebdf 100644 --- a/src/config.c +++ b/src/config.c @@ -9,11 +9,6 @@ config_t *global_config; - -#define CONFINI_IS_KEY(SECTION, KEY) \ - (ini_array_match(SECTION, disp->append_to, '.', disp->format) && \ - ini_string_match_ii(KEY, disp->data, disp->format)) - static int config_load_log_level(config_t *config, char *value) { @@ -211,6 +206,8 @@ config_init() global_config->user = NULL; global_config->group = NULL; + global_config->include = NULL; + config_load_string(&global_config->content_dir, "."); config_load_string(&global_config->not_found_file, "404.html"); config_load_string(&global_config->not_found_file_type, "text/html"); diff --git a/src/handlers/http.c b/src/handlers/http.c index 65fa69f..b72db52 100644 --- a/src/handlers/http.c +++ b/src/handlers/http.c @@ -81,7 +81,7 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm) response.content = NULL; response.alloced_content = false; - M_RESPONSE_MSG(LOGGER_WARNING, &response, 500, "server did not create a response"); + M_RESPONSE_MSG(LOGGER_NONE, &response, 500, "server did not create a response"); if(!endpoint) { diff --git a/src/logger.c b/src/logger.c index 0553238..8ba8af2 100644 --- a/src/logger.c +++ b/src/logger.c @@ -65,7 +65,13 @@ logger_log(int level, const char *filename, int line, const char *func, const ch strftime(timestamp_str, 32, "%Y-%m-%d %H:%M:%S", localtime(&rawtime)); size_t timestamp_len = strlen(timestamp_str); - char *buffer = malloc(sizeof(char) * (128 + strlen(msg) + timestamp_len)); + size_t buffer_size = 128; + buffer_size += timestamp_len; + buffer_size += strlen(filename); + buffer_size += strlen(func); + buffer_size += strlen(msg); + + char *buffer = malloc(sizeof(char) * (buffer_size)); sprintf(buffer, "%s %s[%5s] %s:%d:%s " COLOR_NONE "%s", timestamp_str, color, level_str, filename, line, func, msg); // start arg va_list and find log_len diff --git a/tests/emgauwa-controller-testing.conf b/tests/emgauwa-controller-testing.conf new file mode 100644 index 0000000..5b541e4 --- /dev/null +++ b/tests/emgauwa-controller-testing.conf @@ -0,0 +1,66 @@ +[controller] +database = "emgauwa-controller.sqlite" + +mqtt-host = "127.0.0.1" + +[ports] +# 4422 for testing; 4421 for dev-env; 4420 for testing-env; 4419 for prod-env +discovery = 4422 +# 1886 for testing; 1885 for dev-env; 1884 for testing-env; 1883 for prod-env +mqtt = 1886 + +[logging] +level = "debug" +file = "stdout" + +[[relays]] +driver = "piface" +pin = 0 +inverted = 0 + +[[relays]] +driver = "piface" +pin = 1 +inverted = 0 + +[[relays]] +driver = "gpio" +pin = 5 +inverted = 1 + +[[relays]] +driver = "gpio" +pin = 4 +inverted = 1 + +[[relays]] +driver = "gpio" +pin = 3 +inverted = 1 + +[[relays]] +driver = "gpio" +pin = 2 +inverted = 1 + +[[relays]] +driver = "gpio" +pin = 1 +inverted = 1 +pulse-duration = 3 + +[[relays]] +driver = "gpio" +pin = 0 +inverted = 1 +pulse-duration = 3 + +[[relays]] +driver = "gpio" +pin = 16 +inverted = 1 + +[[relays]] +driver = "gpio" +pin = 15 +inverted = 1 diff --git a/tests/emgauwa-controller-testing.ini b/tests/emgauwa-controller-testing.ini deleted file mode 100644 index d3577f6..0000000 --- a/tests/emgauwa-controller-testing.ini +++ /dev/null @@ -1,65 +0,0 @@ -[controller] -name = new emgauwa device - -: 4422 for testing; 4421 for dev-env; 4420 for testing-env; 4419 for prod-env -discovery-port = 4422 -: 1886 for testing; 1885 for dev-env; 1884 for testing-env; 1883 for prod-env -mqtt-port = 1886 -mqtt-host = localhost - -relay-count = 10 -database = controller.sqlite -log-level = debug -log-file = stdout - -[relay-0] -driver = piface -pin = 0 -inverted = 0 - -[relay-1] -driver = piface -pin = 1 -inverted = 0 - -[relay-2] -driver = gpio -pin = 5 -inverted = 1 - -[relay-3] -driver = gpio -pin = 4 -inverted = 1 - -[relay-4] -driver = gpio -pin = 3 -inverted = 1 - -[relay-5] -driver = gpio -pin = 2 -inverted = 1 - -[relay-6] -driver = gpio -pin = 1 -inverted = 1 -pulse-duration = 3 - -[relay-7] -driver = gpio -pin = 0 -inverted = 1 -pulse-duration = 3 - -[relay-8] -driver = gpio -pin = 16 -inverted = 1 - -[relay-9] -driver = gpio -pin = 15 -inverted = 1 diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 2150f05..7216b2b 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -15,7 +15,8 @@ then mkdir -p controller cd controller - git pull >/dev/null || git clone --quiet ssh://git@git.serguzim.me:3022/emgauwa/controller.git . || exit + echo "Trying to pull or clone controller" + git clone --quiet ssh://git@git.serguzim.me:3022/emgauwa/controller.git . >/dev/null 2>&1 || git pull >/dev/null || exit git checkout dev >/dev/null 2>&1 git checkout $target_branch >/dev/null 2>&1 @@ -32,7 +33,7 @@ fi echo "Emgauwa controller: $($EMGAUWA_CONTROLLER_EXE --version)" -$EMGAUWA_CONTROLLER_EXE start -c $source_dir/emgauwa-controller-testing.ini >$working_dir/controller.log 2>&1 & +$EMGAUWA_CONTROLLER_EXE -c $source_dir/emgauwa-controller-testing.conf >$working_dir/controller.log 2>&1 & controller_id=$! cd $working_dir