1
#pragma once
2

            
3
#include "envoy/thread_local/thread_local.h"
4

            
5
#include "source/common/common/matchers.h"
6
#include "source/extensions/filters/common/lua/lua.h"
7

            
8
namespace Envoy {
9
namespace Extensions {
10
namespace StringMatcher {
11
namespace Lua {
12

            
13
// This class should not be used directly. It is exposed here for use in tests.
14
// Correct use requires use of a thread local slot.
15
class LuaStringMatcher : public Matchers::StringMatcher, public ThreadLocal::ThreadLocalObject {
16
public:
17
  LuaStringMatcher(const std::string& code);
18

            
19
  // ThreadLocal::ThreadLocalObject
20
9
  ~LuaStringMatcher() override = default;
21

            
22
  // To avoid hiding other implementations of match.
23
  using Matchers::StringMatcher::match;
24

            
25
  // Matchers::StringMatcher
26
  bool match(absl::string_view value) const override;
27

            
28
private:
29
  CSmartPtr<lua_State, lua_close> state_;
30
  int matcher_func_ref_{LUA_NOREF};
31
};
32

            
33
class LuaStringMatcherFactory : public Matchers::StringMatcherExtensionFactory {
34
public:
35
  Matchers::StringMatcherPtr
36
  createStringMatcher(const Protobuf::Message& config,
37
                      Server::Configuration::CommonFactoryContext& context) override;
38
7
  std::string name() const override { return "envoy.string_matcher.lua"; }
39
  ProtobufTypes::MessagePtr createEmptyConfigProto() override;
40
};
41

            
42
} // namespace Lua
43
} // namespace StringMatcher
44
} // namespace Extensions
45
} // namespace Envoy