aboutsummaryrefslogtreecommitdiffstats
path: root/src/server_lds.c
diff options
context:
space:
mode:
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);