Coverage Report

Created: 2026-06-09 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open62541_15/src/server/ua_server_config.c
Line
Count
Source
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
 *
5
 *    Copyright 2019 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
6
 *    Copyright 2019 (c) HMS Industrial Networks AB (Author: Jonas Green)
7
 */
8
9
#include <open62541/server.h>
10
11
#include "ua_server_internal.h"
12
13
void
14
10.2k
UA_ServerConfig_clear(UA_ServerConfig *config) {
15
10.2k
    if(!config)
16
0
        return;
17
18
    /* Server Description */
19
10.2k
    UA_BuildInfo_clear(&config->buildInfo);
20
10.2k
    UA_ApplicationDescription_clear(&config->applicationDescription);
21
10.2k
#ifdef UA_ENABLE_DISCOVERY_MULTICAST
22
10.2k
    UA_MdnsDiscoveryConfiguration_clear(&config->mdnsConfig);
23
10.2k
#ifdef UA_ENABLE_DISCOVERY_MULTICAST_MDNSD
24
10.2k
    UA_String_clear(&config->mdnsInterfaceIP);
25
# if !defined(UA_HAS_GETIFADDR)
26
    if (config->mdnsIpAddressListSize) {
27
        UA_free(config->mdnsIpAddressList);
28
    }
29
# endif
30
10.2k
#endif
31
10.2k
#endif
32
33
    /* Stop and delete the EventLoop */
34
10.2k
    UA_EventLoop *el = config->eventLoop;
35
10.2k
    if(el && !config->externalEventLoop) {
36
10.2k
        if(el->state != UA_EVENTLOOPSTATE_FRESH &&
37
10.2k
           el->state != UA_EVENTLOOPSTATE_STOPPED) {
38
9.69k
            el->stop(el);
39
17.8k
            while(el->state != UA_EVENTLOOPSTATE_STOPPED) {
40
8.16k
                el->run(el, 100);
41
8.16k
            }
42
9.69k
        }
43
10.2k
        el->free(el);
44
10.2k
        config->eventLoop = NULL;
45
10.2k
    }
46
47
    /* Networking */
48
10.2k
    UA_Array_delete(config->serverUrls, config->serverUrlsSize,
49
10.2k
                    &UA_TYPES[UA_TYPES_STRING]);
50
10.2k
    config->serverUrls = NULL;
51
10.2k
    config->serverUrlsSize = 0;
52
53
    /* Security Policies */
54
20.4k
    for(size_t i = 0; i < config->securityPoliciesSize; ++i) {
55
10.2k
        UA_SecurityPolicy *policy = &config->securityPolicies[i];
56
10.2k
        policy->clear(policy);
57
10.2k
    }
58
10.2k
    UA_free(config->securityPolicies);
59
10.2k
    config->securityPolicies = NULL;
60
10.2k
    config->securityPoliciesSize = 0;
61
62
20.4k
    for(size_t i = 0; i < config->endpointsSize; ++i)
63
10.2k
        UA_EndpointDescription_clear(&config->endpoints[i]);
64
65
10.2k
    UA_free(config->endpoints);
66
10.2k
    config->endpoints = NULL;
67
10.2k
    config->endpointsSize = 0;
68
69
    /* Nodestore */
70
10.2k
    if(config->nodestore) {
71
10.2k
        config->nodestore->free(config->nodestore);
72
10.2k
        config->nodestore = NULL;
73
10.2k
    }
74
75
    /* Certificate Validation */
76
10.2k
    if(config->secureChannelPKI.clear)
77
10.2k
        config->secureChannelPKI.clear(&config->secureChannelPKI);
78
10.2k
    if(config->sessionPKI.clear)
79
10.2k
        config->sessionPKI.clear(&config->sessionPKI);
80
81
    /* Access Control */
82
10.2k
    if(config->accessControl.clear)
83
10.2k
        config->accessControl.clear(&config->accessControl);
84
85
    /* Historical data */
86
10.2k
#ifdef UA_ENABLE_HISTORIZING
87
10.2k
    if(config->historyDatabase.clear)
88
0
        config->historyDatabase.clear(&config->historyDatabase);
89
10.2k
#endif
90
91
10.2k
#ifdef UA_ENABLE_PUBSUB
92
10.2k
    if(config->pubSubConfig.securityPolicies != NULL) {
93
0
        for(size_t i = 0; i < config->pubSubConfig.securityPoliciesSize; i++) {
94
0
            config->pubSubConfig.securityPolicies[i].clear(&config->pubSubConfig.securityPolicies[i]);
95
0
        }
96
0
        UA_free(config->pubSubConfig.securityPolicies);
97
0
        config->pubSubConfig.securityPolicies = NULL;
98
0
        config->pubSubConfig.securityPoliciesSize = 0;
99
0
    }
100
10.2k
#endif /* UA_ENABLE_PUBSUB */
101
102
    /* Logger */
103
10.2k
    if(config->logging != NULL && config->logging->clear != NULL)
104
10.2k
        config->logging->clear(config->logging);
105
10.2k
    config->logging = NULL;
106
107
    /* Custom Data Types */
108
10.2k
    UA_cleanupDataTypeWithCustom(config->customDataTypes);
109
    config->customDataTypes = NULL;
110
10.2k
}