char* value_str = NULL;
size_t str_length = 0;
- if (strlen(config_stream) <= 0) {
+ if (strlen(config_stream) <= 0)
return;
- }
cfg_opt_t opts[] = {
CFG_STR("username", "", CFGF_NONE),
CFG_STR("scanner_url", "", CFGF_NONE),
- CFG_INT("heartbeat_seconds", 2, CFGF_NONE),
+ CFG_INT("heartbeat_seconds", 0, CFGF_NONE),
CFG_END()
};
config->heartbeat = cfg_getint(cfg, "heartbeat_seconds");
+ if (config->heartbeat < 2)
+ config->heartbeat = 2;
+
cfg_free(cfg);
cfg = NULL;
}
\ No newline at end of file
#include "kds_s2000w_config.h"
#include "kds_s2000w_heartbeat.h"
-program_config heartbeat_config;
+extern program_config p_config;
pthread_t pwait;
void* _wait_thread(void *args)
{
- sleep(heartbeat_config.heartbeat);
+ sleep(p_config.heartbeat);
return NULL;
}
-void _load_config()
-{
- if (heartbeat_config.heartbeat != 0)
- return;
-
- const char* config_file = CONFIG_FILE;
- char* config_stream = read_config_file(config_file);
- if (config_stream == NULL)
- return;
-
- load_config(&heartbeat_config, config_stream);
-}
-
void join_thread()
{
pthread_join(pwait, NULL);
void wait_a_second()
{
- _load_config();
pthread_create(&pwait, NULL, _wait_thread, NULL);
}
\ No newline at end of file
scanner_url = "https://scanner.example.com"
username = "muster"
-heartbeat_seconds = 2
\ No newline at end of file
+# Scanner heart beat is by default 2 seconds before check next scan status,
+# heartbeat_seconds = 2
\ No newline at end of file
assert_int_equal(config->heartbeat, 5);
+ free(config->scanner_url);
+ config->scanner_url = NULL;
+ free(config->username);
+ config->username = NULL;
+ free(config);
+ config = NULL;
+}
+
+void kds_s200w_config_default_heartbeat_zero_set_default()
+{
+ const char* input_stream = "heartbeat_seconds = 0\n";
+
+ program_config* config = malloc(sizeof(program_config));
+ load_config(config, input_stream);
+
+ assert_int_equal(config->heartbeat, 2);
+
free(config->scanner_url);
config->scanner_url = NULL;
free(config->username);
void kds_s2000w_config_read_empty_config();
void kds_s200w_config_default_heartbeat();
void kds_s200w_config_default_heartbeat_five_seconds();
+void kds_s200w_config_default_heartbeat_zero_set_default();
#endif
\ No newline at end of file
cmocka_unit_test(kds_s2000w_config_multiple_parameters),
cmocka_unit_test(kds_s2000w_config_read_empty_config),
cmocka_unit_test(kds_s200w_config_default_heartbeat),
- cmocka_unit_test(kds_s200w_config_default_heartbeat_five_seconds)
+ cmocka_unit_test(kds_s200w_config_default_heartbeat_five_seconds),
+ cmocka_unit_test(kds_s200w_config_default_heartbeat_zero_set_default)
};
return cmocka_run_group_tests(read_config, NULL, NULL);