Coverage Report

Created: 2026-08-31 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/propertysetter.cpp
Line
Count
Source
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
#include <log4cxx/config/propertysetter.h>
19
#include <log4cxx/helpers/loglog.h>
20
#include <log4cxx/helpers/optionconverter.h>
21
#include <log4cxx/spi/optionhandler.h>
22
#include <log4cxx/helpers/properties.h>
23
#include <log4cxx/helpers/stringhelper.h>
24
#include <log4cxx/appender.h>
25
26
27
using namespace LOG4CXX_NS;
28
using namespace LOG4CXX_NS::helpers;
29
using namespace LOG4CXX_NS::spi;
30
using namespace LOG4CXX_NS::config;
31
32
0
PropertySetter::PropertySetter(const helpers::ObjectPtr& obj1) : obj(obj1)
33
0
{
34
0
}
35
36
void PropertySetter::setProperties(const helpers::ObjectPtr& obj, helpers::Properties& properties, const LogString& prefix)
37
0
{
38
0
  PropertySetter(obj).setProperties(properties, prefix);
39
0
}
40
41
42
void PropertySetter::setProperties(helpers::Properties& properties, const LogString& prefix)
43
0
{
44
0
  size_t len = prefix.length();
45
46
0
  for (auto key : properties.propertyNames())
47
0
  {
48
    // handle only properties that start with the desired prefix.
49
0
    if (key.find(prefix) == 0)
50
0
    {
51
      // ignore key if it contains dots after the prefix
52
0
      if (key.find(0x2E /* '.' */, len + 1) != LogString::npos)
53
0
      {
54
0
        continue;
55
0
      }
56
57
0
      LogString value = OptionConverter::findAndSubst(key, properties);
58
0
      key = key.substr(len);
59
60
0
      if (key == LOG4CXX_STR("layout")
61
0
        && obj != 0
62
0
        && obj->instanceof(Appender::getStaticClass()))
63
0
      {
64
0
        continue;
65
0
      }
66
67
0
      setProperty(key, value);
68
0
    }
69
0
  }
70
71
0
  activate();
72
0
}
73
74
void PropertySetter::setProperty(const LogString& option, const LogString& value)
75
0
{
76
0
  if (value.empty())
77
0
  {
78
0
    return;
79
0
  }
80
81
0
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
82
0
  {
83
0
    if (LogLog::isDebugEnabled())
84
0
    {
85
      // Do not echo secret-bearing option values (e.g. the ODBCAppender
86
      // "Password", SMTPAppender "SMTPPassword" or DBAppender
87
      // "DriverParams" options) into diagnostic output: internal debug
88
      // output routinely flows into console/log pipelines with weaker
89
      // access control than the configuration file itself.
90
0
      LogString lowerOption(StringHelper::toLowerCase(option));
91
0
      bool sensitive =
92
0
        lowerOption.find(LOG4CXX_STR("password")) != LogString::npos ||
93
0
        lowerOption.find(LOG4CXX_STR("driverparams")) != LogString::npos;
94
0
      LogLog::debug(LOG4CXX_STR("Setting option name=[") +
95
0
        option + LOG4CXX_STR("], value=[") +
96
0
        (sensitive ? LogString(LOG4CXX_STR("****")) : value) +
97
0
        LOG4CXX_STR("]"));
98
0
    }
99
0
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
100
0
    handler->setOption(option, value);
101
0
  }
102
0
}
103
104
void PropertySetter::activate()
105
0
{
106
0
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
107
0
  {
108
0
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
109
0
    handler->activateOptions();
110
0
  }
111
0
}
112
113
#if LOG4CXX_ABI_VERSION <= 15
114
void PropertySetter::setProperties(const helpers::ObjectPtr& obj,
115
  helpers::Properties& properties,
116
  const LogString& prefix,
117
  Pool&)
118
0
{
119
0
  PropertySetter(obj).setProperties(properties, prefix);
120
0
}
121
122
123
void PropertySetter::setProperties(helpers::Properties& properties,
124
  const LogString& prefix,
125
  Pool&)
126
0
{
127
0
  setProperties(properties, prefix);
128
0
}
129
130
void PropertySetter::setProperty(const LogString& option,
131
  const LogString& value,
132
  Pool&)
133
0
{
134
0
  setProperty(option, value);
135
0
}
136
137
void PropertySetter::activate(Pool& p)
138
0
{
139
0
  activate();
140
0
}
141
#endif