Coverage Report

Created: 2025-07-01 07:01

/src/open62541/arch/common/eventloop_common.c
Line
Count
Source (jump to first uncovered line)
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 2022 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
6
 */
7
8
#include "eventloop_common.h"
9
10
UA_StatusCode
11
UA_KeyValueRestriction_validate(const UA_Logger *logger, const char *logprefix,
12
                                const UA_KeyValueRestriction *restrictions,
13
                                size_t restrictionsSize,
14
675
                                const UA_KeyValueMap *map) {
15
2.02k
    for(size_t i = 0; i < restrictionsSize; i++) {
16
1.35k
        const UA_KeyValueRestriction *r = &restrictions[i];
17
1.35k
        const UA_Variant *val = UA_KeyValueMap_get(map, r->name);
18
19
        /* Value not present but required? */
20
1.35k
        if(!val) {
21
1.35k
            if(r->required) {
22
0
                UA_LOG_WARNING(logger, UA_LOGCATEGORY_USERLAND,
23
0
                               "%s\t| Parameter %.*s required but not defined",
24
0
                               logprefix, (int)r->name.name.length, (char*)r->name.name.data);
25
0
                return UA_STATUSCODE_BADINTERNALERROR;
26
0
            }
27
1.35k
            continue;
28
1.35k
        }
29
30
        /* Type matches */
31
0
        if(val->type != r->type) {
32
0
            UA_LOG_WARNING(logger, UA_LOGCATEGORY_USERLAND,
33
0
                           "%s\t| Parameter %.*s has the wrong type",
34
0
                           logprefix, (int)r->name.name.length, (char*)r->name.name.data);
35
0
            return UA_STATUSCODE_BADINTERNALERROR;
36
0
        }
37
38
        /* Scalar / array is allowed */
39
0
        UA_Boolean scalar = UA_Variant_isScalar(val);
40
0
        if(scalar && !r->scalar) {
41
0
            UA_LOG_WARNING(logger, UA_LOGCATEGORY_USERLAND,
42
0
                           "%s\t| Parameter %.*s must not be scalar",
43
0
                           logprefix, (int)r->name.name.length, (char*)r->name.name.data);
44
0
            return UA_STATUSCODE_BADINTERNALERROR;
45
0
        }
46
0
        if(!scalar && !r->array) {
47
0
            UA_LOG_WARNING(logger, UA_LOGCATEGORY_USERLAND,
48
0
                           "%s\t| Parameter %.*s must not be an array",
49
0
                           logprefix, (int)r->name.name.length, (char*)r->name.name.data);
50
0
            return UA_STATUSCODE_BADCONNECTIONREJECTED;
51
0
        }
52
0
    }
53
54
675
    return UA_STATUSCODE_GOOD;
55
675
}