Coverage Report

Created: 2025-12-14 06:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open62541/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
525
UA_ServerConfig_clear(UA_ServerConfig *config) {
15
525
    if(!config)
16
0
        return;
17
18
    /* Server Description */
19
525
    UA_BuildInfo_clear(&config->buildInfo);
20
525
    UA_ApplicationDescription_clear(&config->applicationDescription);
21
525
#ifdef UA_ENABLE_DISCOVERY_MULTICAST
22
525
    UA_MdnsDiscoveryConfiguration_clear(&config->mdnsConfig);
23
525
#ifdef UA_ENABLE_DISCOVERY_MULTICAST_MDNSD
24
525
    UA_String_clear(&config->mdnsInterfaceIP);
25
# if !defined(UA_HAS_GETIFADDR)
26
    if (config->mdnsIpAddressListSize) {
27
        UA_free(config->mdnsIpAddressList);
28
    }
29
# endif
30
525
#endif
31
525
#endif
32
33
    /* Stop and delete the EventLoop */
34
525
    UA_EventLoop *el = config->eventLoop;
35
525
    if(el && !config->externalEventLoop) {
36
525
        if(el->state != UA_EVENTLOOPSTATE_FRESH &&
37
525
           el->state != UA_EVENTLOOPSTATE_STOPPED) {
38
249
            el->stop(el);
39
498
            while(el->state != UA_EVENTLOOPSTATE_STOPPED) {
40
249
                el->run(el, 100);
41
249
            }
42
249
        }
43
525
        el->free(el);
44
525
        config->eventLoop = NULL;
45
525
    }
46
47
    /* Networking */
48
525
    UA_Array_delete(config->serverUrls, config->serverUrlsSize,
49
525
                    &UA_TYPES[UA_TYPES_STRING]);
50
525
    config->serverUrls = NULL;
51
525
    config->serverUrlsSize = 0;
52
53
    /* Security Policies */
54
1.05k
    for(size_t i = 0; i < config->securityPoliciesSize; ++i) {
55
525
        UA_SecurityPolicy *policy = &config->securityPolicies[i];
56
525
        policy->clear(policy);
57
525
    }
58
525
    UA_free(config->securityPolicies);
59
525
    config->securityPolicies = NULL;
60
525
    config->securityPoliciesSize = 0;
61
62
1.05k
    for(size_t i = 0; i < config->endpointsSize; ++i)
63
525
        UA_EndpointDescription_clear(&config->endpoints[i]);
64
65
525
    UA_free(config->endpoints);
66
525
    config->endpoints = NULL;
67
525
    config->endpointsSize = 0;
68
69
    /* Nodestore */
70
525
    if(config->nodestore) {
71
525
        config->nodestore->free(config->nodestore);
72
525
        config->nodestore = NULL;
73
525
    }
74
75
    /* Certificate Validation */
76
525
    if(config->secureChannelPKI.clear)
77
525
        config->secureChannelPKI.clear(&config->secureChannelPKI);
78
525
    if(config->sessionPKI.clear)
79
525
        config->sessionPKI.clear(&config->sessionPKI);
80
81
    /* Access Control */
82
525
    if(config->accessControl.clear)
83
525
        config->accessControl.clear(&config->accessControl);
84
85
    /* Historical data */
86
525
#ifdef UA_ENABLE_HISTORIZING
87
525
    if(config->historyDatabase.clear)
88
0
        config->historyDatabase.clear(&config->historyDatabase);
89
525
#endif
90
91
525
#ifdef UA_ENABLE_PUBSUB
92
525
    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
525
#endif /* UA_ENABLE_PUBSUB */
101
102
    /* Logger */
103
525
    if(config->logging != NULL && config->logging->clear != NULL)
104
525
        config->logging->clear(config->logging);
105
525
    config->logging = NULL;
106
107
    /* Custom Data Types */
108
525
    UA_cleanupDataTypeWithCustom(config->customDataTypes);
109
    config->customDataTypes = NULL;
110
525
}