Coverage Report

Created: 2026-07-16 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open62541_15/arch/common/eventloop_common.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 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
41.6k
                                const UA_KeyValueMap *map) {
15
130k
    for(size_t i = 0; i < restrictionsSize; i++) {
16
88.8k
        const UA_KeyValueRestriction *r = &restrictions[i];
17
88.8k
        const UA_Variant *val = UA_KeyValueMap_get(map, r->name);
18
19
        /* Value not present but required? */
20
88.8k
        if(!val) {
21
84.4k
            if(r->required) {
22
0
                UA_LOG_WARNING(logger, UA_LOGCATEGORY_EVENTLOOP,
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
84.4k
            continue;
28
84.4k
        }
29
30
        /* Type matches */
31
4.45k
        if(val->type != r->type) {
32
0
            UA_LOG_WARNING(logger, UA_LOGCATEGORY_EVENTLOOP,
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
4.45k
        UA_Boolean scalar = UA_Variant_isScalar(val);
40
4.45k
        if(scalar && !r->scalar) {
41
0
            UA_LOG_WARNING(logger, UA_LOGCATEGORY_EVENTLOOP,
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
4.45k
        if(!scalar && !r->array) {
47
0
            UA_LOG_WARNING(logger, UA_LOGCATEGORY_EVENTLOOP,
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
4.45k
    }
53
54
41.6k
    return UA_STATUSCODE_GOOD;
55
41.6k
}
56
57
UA_StatusCode
58
UA_EventLoopCommon_allocStaticBuffer(UA_KeyValueMap *params,
59
                                     UA_QualifiedName name,
60
                                     UA_UInt32 defaultSize,
61
30.8k
                                     UA_ByteString *buf) {
62
30.8k
    UA_StatusCode res = UA_STATUSCODE_GOOD;
63
30.8k
    UA_UInt32 bufSize = defaultSize;
64
30.8k
    const UA_UInt32 *configBufSize = (const UA_UInt32 *)
65
30.8k
        UA_KeyValueMap_getScalar(params, name, &UA_TYPES[UA_TYPES_UINT32]);
66
30.8k
    if(configBufSize)
67
0
        bufSize = *configBufSize;
68
30.8k
    else
69
        /* Write the resolved default back into the params so the
70
         * SecureChannel constraint logic in ua_server_binary.c caps the
71
         * channel to the actual static-buffer size. */
72
30.8k
        res = UA_KeyValueMap_setScalar(params, name, &bufSize,
73
30.8k
                                       &UA_TYPES[UA_TYPES_UINT32]);
74
30.8k
    if(buf->length != bufSize) {
75
30.8k
        UA_ByteString_clear(buf);
76
30.8k
        res |= UA_ByteString_allocBuffer(buf, bufSize);
77
30.8k
    }
78
30.8k
    return res;
79
30.8k
}