aboutsummaryrefslogtreecommitdiffstats
path: root/src/server_lds.c
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-02-17 23:52:06 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-02-17 23:52:06 +0100
commit7648a256d97abda40edbdc0d7bf59edd0a09fb95 (patch)
treea86d829f85f4a3d8038741c299d9409cb2272686 /src/server_lds.c
parentb2002d96f495dcb3bd2f5a738ec1615034ca876f (diff)
downloadBobinkCOpcUa-7648a256d97abda40edbdc0d7bf59edd0a09fb95.tar.gz
BobinkCOpcUa-7648a256d97abda40edbdc0d7bf59edd0a09fb95.zip
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.
Diffstat (limited to 'src/server_lds.c')
-rw-r--r--src/server_lds.c70
1 files changed, 15 insertions, 55 deletions
diff --git a/src/server_lds.c b/src/server_lds.c
index e3407d5..0a1bf89 100644
--- a/src/server_lds.c
+++ b/src/server_lds.c
@@ -16,11 +16,9 @@
#include <open62541/plugin/accesscontrol_default.h>
#include <open62541/plugin/log_stdout.h>
#include <open62541/server.h>
-#include <open62541/server_config_default.h>
#include <signal.h>
#include <stdlib.h>
-#include <string.h>
UA_Boolean running = true;
@@ -63,9 +61,8 @@ main (int argc, char *argv[])
const char *applicationUri
= configRequire (&cfg, "applicationUri", "ServerLDS");
int cleanupTimeout = configRequireInt (&cfg, "cleanupTimeout", "ServerLDS");
- const char *authMode = configRequire (&cfg, "authMode", "ServerLDS");
- if (!applicationUri || !authMode || port < 0 || cleanupTimeout < 0)
+ if (!applicationUri || port < 0 || cleanupTimeout < 0)
{
configFree (&cfg);
return EXIT_FAILURE;
@@ -102,67 +99,30 @@ main (int argc, char *argv[])
UA_Boolean allowAnonymous;
const char *username = NULL, *password = NULL;
-
- if (strcmp (authMode, "anonymous") == 0)
- {
- allowAnonymous = true;
- }
- else if (strcmp (authMode, "user") == 0)
- {
- allowAnonymous = false;
- username = configRequire (&cfg, "username", "ServerLDS");
- password = configRequire (&cfg, "password", "ServerLDS");
- if (!username || !password)
- {
- configFree (&cfg);
- return EXIT_FAILURE;
- }
- }
- else
+ if (parseAuthConfig (&cfg, "ServerLDS", &allowAnonymous, &username,
+ &password)
+ != 0)
{
- UA_LOG_FATAL (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
- "Unknown auth mode: %s "
- "(expected 'anonymous' or 'user')",
- authMode);
configFree (&cfg);
return EXIT_FAILURE;
}
char **trustPaths = NULL;
size_t trustSize = 0;
- UA_StatusCode retval;
- UA_Server *server;
-
- if (secure)
+ if (secure && loadTrustStore (trustStore, &trustPaths, &trustSize) != 0)
{
- if (loadTrustStore (trustStore, &trustPaths, &trustSize) != 0)
- {
- configFree (&cfg);
- return EXIT_FAILURE;
- }
- server = createSecureServer ((UA_UInt16)port, applicationUri, certPath,
- keyPath, trustPaths, trustSize, &retval);
- if (!server)
- {
- freeTrustStore (trustPaths, trustSize);
- configFree (&cfg);
- return EXIT_FAILURE;
- }
+ configFree (&cfg);
+ return EXIT_FAILURE;
}
- else
+
+ UA_StatusCode retval;
+ UA_Server *server = createServer ((UA_UInt16)port, applicationUri, certPath,
+ keyPath, trustPaths, trustSize, &retval);
+ if (!server)
{
- server = UA_Server_new ();
- UA_ServerConfig *config = UA_Server_getConfig (server);
- retval = UA_ServerConfig_setMinimal (config, (UA_UInt16)port, NULL);
- if (retval != UA_STATUSCODE_GOOD)
- {
- UA_Server_delete (server);
- configFree (&cfg);
- return EXIT_FAILURE;
- }
- UA_String_clear (&config->applicationDescription.applicationUri);
- config->applicationDescription.applicationUri
- = UA_String_fromChars (applicationUri);
+ freeTrustStore (trustPaths, trustSize);
+ configFree (&cfg);
+ return EXIT_FAILURE;
}
UA_ServerConfig *serverConfig = UA_Server_getConfig (server);