• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 19741624072

27 Nov 2025 03:45PM UTC coverage: 73.086% (+0.02%) from 73.065%
19741624072

Pull #16570

github

web-flow
Merge 08a2cdb1d into f94a3f63f
Pull Request #16570: rec: rewrite all unwrap calls in web.rs

38523 of 63408 branches covered (60.75%)

Branch coverage included in aggregate %.

128044 of 164496 relevant lines covered (77.84%)

6531485.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.0
/pdns/dnsdistdist/dnsdist-lua-bindings-kvs.cc
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22
#include "dnsdist.hh"
23
#include "dnsdist-kvs.hh"
24
#include "dnsdist-lua.hh"
25

26
void setupLuaBindingsKVS([[maybe_unused]] LuaContext& luaCtx, [[maybe_unused]] bool client)
27
{
818✔
28
#ifdef HAVE_LMDB
818✔
29
  luaCtx.writeFunction("newLMDBKVStore", [client](const std::string& fname, const std::string& dbName, boost::optional<bool> noLock) {
818✔
30
    if (client) {
6!
31
      return std::shared_ptr<KeyValueStore>(nullptr);
32
    }
33
    return std::shared_ptr<KeyValueStore>(new LMDBKVStore(fname, dbName, noLock ? *noLock : false));
6!
34
  });
6✔
35
#endif /* HAVE_LMDB */
818✔
36

37
#ifdef HAVE_CDB
818✔
38
  luaCtx.writeFunction("newCDBKVStore", [client](const std::string& fname, time_t refreshDelay) {
818✔
39
    if (client) {
4!
40
      return std::shared_ptr<KeyValueStore>(nullptr);
41
    }
42
    return std::shared_ptr<KeyValueStore>(new CDBKVStore(fname, refreshDelay));
4✔
43
  });
4✔
44
#endif /* HAVE_CDB */
818✔
45

46
#if defined(HAVE_LMDB) || defined(HAVE_CDB)
818✔
47
  /* Key Value Store objects */
48
  luaCtx.writeFunction("KeyValueLookupKeySourceIP", [](boost::optional<uint8_t> v4Mask, boost::optional<uint8_t> v6Mask, boost::optional<bool> includePort) {
818✔
49
    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeySourceIP(v4Mask ? *v4Mask : 32, v6Mask ? *v6Mask : 128, includePort ? *includePort : false));
16✔
50
  });
16✔
51
  luaCtx.writeFunction("KeyValueLookupKeyQName", [](boost::optional<bool> wireFormat) {
818✔
52
    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeyQName(wireFormat ? *wireFormat : true));
10✔
53
  });
10✔
54
  luaCtx.writeFunction("KeyValueLookupKeySuffix", [](boost::optional<size_t> minLabels, boost::optional<bool> wireFormat) {
818✔
55
    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeySuffix(minLabels ? *minLabels : 0, wireFormat ? *wireFormat : true));
6!
56
  });
6✔
57
  luaCtx.writeFunction("KeyValueLookupKeyTag", [](const std::string& tag) {
818✔
58
    return std::shared_ptr<KeyValueLookupKey>(new KeyValueLookupKeyTag(tag));
6✔
59
  });
6✔
60

61
  luaCtx.registerFunction<std::string(std::shared_ptr<KeyValueStore>::*)(const boost::variant<ComboAddress, DNSName, std::string>, boost::optional<bool> wireFormat)>("lookup", [](std::shared_ptr<KeyValueStore>& kvs, const boost::variant<ComboAddress, DNSName, std::string> keyVar, boost::optional<bool> wireFormat) {
818✔
62
    std::string result;
6✔
63
    if (!kvs) {
6!
64
      return result;
65
    }
66

67
    if (keyVar.type() == typeid(ComboAddress)) {
6!
68
      const auto ca = boost::get<ComboAddress>(&keyVar);
69
      KeyValueLookupKeySourceIP lookup(32, 128, false);
70
      for (const auto& key : lookup.getKeys(*ca)) {
×
71
        if (kvs->getValue(key, result)) {
×
72
          return result;
73
        }
74
      }
75
    }
76
    else if (keyVar.type() == typeid(DNSName)) {
6!
77
      const DNSName* dn = boost::get<DNSName>(&keyVar);
78
      KeyValueLookupKeyQName lookup(wireFormat ? *wireFormat : true);
×
79
      for (const auto& key : lookup.getKeys(*dn)) {
×
80
        if (kvs->getValue(key, result)) {
×
81
          return result;
82
        }
83
      }
84
    }
85
    else if (keyVar.type() == typeid(std::string)) {
6!
86
      const std::string* keyStr = boost::get<std::string>(&keyVar);
6✔
87
      kvs->getValue(*keyStr, result);
6✔
88
    }
6✔
89

90
    return result;
6✔
91
  });
6✔
92

93
  luaCtx.registerFunction<std::string(std::shared_ptr<KeyValueStore>::*)(const DNSName&, boost::optional<size_t> minLabels, boost::optional<bool> wireFormat)>("lookupSuffix", [](std::shared_ptr<KeyValueStore>& kvs, const DNSName& dn, boost::optional<size_t> minLabels, boost::optional<bool> wireFormat) {
818✔
94
    std::string result;
6✔
95
    if (!kvs) {
6!
96
      return result;
97
    }
98

99
    KeyValueLookupKeySuffix lookup(minLabels ? *minLabels : 0, wireFormat ? *wireFormat : true);
6!
100
    for (const auto& key : lookup.getKeys(dn)) {
6✔
101
      if (kvs->getValue(key, result)) {
6!
102
        return result;
103
      }
104
    }
6✔
105

106
    return result;
6✔
107
  });
6✔
108

109
  luaCtx.registerFunction<bool(std::shared_ptr<KeyValueStore>::*)()>("reload", [](std::shared_ptr<KeyValueStore>& kvs) {
818✔
110
    if (!kvs) {
7!
111
      return false;
112
    }
113

114
    return kvs->reload();
7✔
115
  });
7✔
116
#endif /* defined(HAVE_LMDB) || defined(HAVE_CDB) */
818✔
117
}
818✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc