From 7648a256d97abda40edbdc0d7bf59edd0a09fb95 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Tue, 17 Feb 2026 23:52:06 +0100 Subject: Extract createServer and parseAuthConfig, simplify programs Rename createSecureServer to createServer and add an unsecure path (UA_ServerConfig_setMinimal) when certPath is NULL, eliminating the if/else server creation blocks in server_lds.c and server_register.c. Add parseAuthConfig() to common.c to replace four near-identical authMode parsing blocks across the three programs. Restructure server_register.c error handling with goto cleanup, removing ~20 duplicated cleanup sequences. Rename the CMake library target from DiscoveryCommon to common. --- src/client.c | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) (limited to 'src/client.c') diff --git a/src/client.c b/src/client.c index 8234963..f03a337 100644 --- a/src/client.c +++ b/src/client.c @@ -233,38 +233,11 @@ main (int argc, char **argv) const char *username = NULL, *password = NULL; - if (op == OP_READ_TIME) + if (op == OP_READ_TIME + && parseAuthConfig (&cfg, "Client", NULL, &username, &password) != 0) { - const char *authMode = configRequire (&cfg, "authMode", "Client"); - if (!authMode) - { - configFree (&cfg); - return EXIT_FAILURE; - } - - if (strcmp (authMode, "anonymous") == 0) - { - /* No credentials needed. */ - } - else if (strcmp (authMode, "user") == 0) - { - username = configRequire (&cfg, "username", "Client"); - password = configRequire (&cfg, "password", "Client"); - if (!username || !password) - { - configFree (&cfg); - return EXIT_FAILURE; - } - } - else - { - UA_LOG_FATAL (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, - "Unknown auth mode: %s " - "(expected 'anonymous' or 'user')", - authMode); - configFree (&cfg); - return EXIT_FAILURE; - } + configFree (&cfg); + return EXIT_FAILURE; } /* ---- Trust store ---- */ -- cgit v1.2.3