Coverage Report

Created: 2025-10-10 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opendnp3/cpp/lib/src/app/APDULogging.cpp
Line
Count
Source
1
/*
2
 * Copyright 2013-2022 Step Function I/O, LLC
3
 *
4
 * Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
5
 * LLC (https://stepfunc.io) under one or more contributor license agreements.
6
 * See the NOTICE file distributed with this work for additional information
7
 * regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
8
 * this file to you under the Apache License, Version 2.0 (the "License"); you
9
 * may not use this file except in compliance with the License. You may obtain
10
 * a copy of the License at:
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
#include "APDULogging.h"
22
23
#include "app/parsing/APDUHeaderParser.h"
24
#include "app/parsing/APDUParser.h"
25
#include "logging/LogMacros.h"
26
27
namespace opendnp3
28
{
29
namespace logging
30
{
31
32
    void LogHeader(Logger& logger, const LogLevel& flags, const APDUHeader& header)
33
0
    {
34
0
        FORMAT_LOG_BLOCK(logger, flags, "FIR: %i FIN: %i CON: %i UNS: %i SEQ: %i FUNC: %s", header.control.FIR,
35
0
                         header.control.FIN, header.control.CON, header.control.UNS, header.control.SEQ,
36
0
                         FunctionCodeSpec::to_human_string(header.function));
37
0
    }
38
39
    void LogHeader(Logger& logger, const LogLevel& flags, const APDUResponseHeader& header)
40
5.81k
    {
41
5.81k
        FORMAT_LOG_BLOCK(logger, flags, "FIR: %i FIN: %i CON: %i UNS: %i SEQ: %i FUNC: %s IIN: [0x%02x, 0x%02x]",
42
5.81k
                         header.control.FIR, header.control.FIN, header.control.CON, header.control.UNS,
43
5.81k
                         header.control.SEQ, FunctionCodeSpec::to_human_string(header.function), header.IIN.LSB,
44
5.81k
                         header.IIN.MSB);
45
5.81k
    }
46
47
    void ParseAndLogRequestTx(Logger& logger, const ser4cpp::rseq_t& apdu)
48
5.81k
    {
49
5.81k
        FORMAT_HEX_BLOCK(logger, flags::APP_HEX_TX, apdu, 18, 18);
50
51
5.81k
        if (logger.is_enabled(flags::APP_HEADER_TX))
52
0
        {
53
0
            const auto result = APDUHeaderParser::ParseRequest(apdu, &logger);
54
0
            if (result.success)
55
0
            {
56
0
                LogHeader(logger, flags::APP_HEADER_TX, result.header);
57
58
0
                if (logger.is_enabled(flags::APP_OBJECT_TX))
59
0
                {
60
0
                    auto expectsContents = result.header.function != FunctionCode::READ;
61
0
                    APDUParser::ParseAndLogAll(result.objects, &logger,
62
0
                                               ParserSettings::Create(expectsContents, flags::APP_OBJECT_TX));
63
0
                }
64
0
            }
65
0
        }
66
5.81k
    }
67
68
    void ParseAndLogResponseTx(Logger& logger, const ser4cpp::rseq_t& apdu)
69
0
    {
70
0
        FORMAT_HEX_BLOCK(logger, flags::APP_HEX_TX, apdu, 18, 18);
71
72
0
        if (logger.is_enabled(flags::APP_HEADER_TX))
73
0
        {
74
0
            const auto result = APDUHeaderParser::ParseResponse(apdu, &logger);
75
0
            if (result.success)
76
0
            {
77
0
                LogHeader(logger, flags::APP_HEADER_TX, result.header);
78
79
0
                if (logger.is_enabled(flags::APP_OBJECT_TX))
80
0
                {
81
0
                    APDUParser::ParseAndLogAll(result.objects, &logger,
82
0
                                               ParserSettings::Create(true, flags::APP_OBJECT_TX));
83
0
                }
84
0
            }
85
0
        }
86
0
    }
87
88
} // namespace logging
89
} // namespace opendnp3