]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
refactor config load
authorBastian Dehn <hhaalo@arcor.de>
Tue, 5 May 2026 17:13:55 +0000 (19:13 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 5 May 2026 17:13:55 +0000 (19:13 +0200)
src/kds_s2000w_config.c
tests/kds_s2000w_read_config_tests.c

index af89bc7a1503364983a9f014644e8fde825db0a1..b0d741fd911cf6727ad7a42b9db5fe17af8211f6 100644 (file)
@@ -18,22 +18,6 @@ program_config_t* _kds_s2000w_config_init()
 
        config->scanner_url = NULL;
        config->username = NULL;
-
-       config->scanner_url = malloc(sizeof(char));
-       if (config->scanner_url == NULL) {
-               kds_s2000w_config_free(config);
-               config = NULL;
-               return NULL;
-       }
-
-       config->username = malloc(sizeof(char));
-       if (config->username == NULL) {
-               kds_s2000w_config_free(config);
-               config = NULL;
-               return NULL;
-       }
-       *config->scanner_url = '\0';
-       *config->username = '\0';
        config->log_level = 0;
        config->heartbeat = 1;
        config->ssl_verify = 0;
@@ -84,16 +68,13 @@ char* kds_s2000w_config_read(const char* filename)
 
 program_config_t* kds_s2000w_config_load(const char* config_string)
 {
+       if (config_string == NULL)
+               return NULL;
+
        program_config_t* config = _kds_s2000w_config_init();
        if (config == NULL)
                return NULL;
 
-       if (config_string == NULL)
-               return config;
-
-       if (strlen(config_string) == 0)
-               return config;
-
        cfg_opt_t opts[] = {
                CFG_STR(SCANNER_URL, "", CFGF_NONE),
                CFG_STR(USERNAME, "", CFGF_NONE),
index 940f62d46f651dfce12d9ffbdb2d7fbbf7500e29..54de828fc4d9e5031ff0182fdd5df2cf72625225 100644 (file)
@@ -30,14 +30,7 @@ void kds_s2000w_config_null_test()
 {
        program_config_t* config = kds_s2000w_config_load(NULL);
 
-       assert_non_null(config);
-       assert_string_equal(config->scanner_url, "");
-       assert_string_equal(config->username, "");
-       assert_int_equal(config->heartbeat, 1);
-       assert_int_equal(config->ssl_verify, 0);
-
-       kds_s2000w_config_free(config);
-       config = NULL;
+       assert_null(config);
 }
 
 void kds_s2000w_config_read_empty_config_test()
@@ -141,7 +134,7 @@ void kds_s2000w_config_profile_test()
 
 void kds_s2000w_config_load_no_mem_test()
 {
-       for (int16_t i = 0; i < 5; i++) {
+       for (int16_t i = 0; i < 3; i++) {
                _kds_s2000w_config_load_no_mem(i);
        }
 }