]>
Commit | Line | Data |
---|---|---|
5e7672ff RG |
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 | #pragma once | |
23 | ||
24 | #include "dnsdist.hh" | |
25 | ||
26 | extern "C" { | |
0ed8f0fa | 27 | #include "dnsdist-lua-ffi-interface.h" |
5e7672ff RG |
28 | } |
29 | ||
30 | // dnsdist_ffi_dnsquestion_t is a lightuserdata | |
31 | template<> | |
32 | struct LuaContext::Pusher<dnsdist_ffi_dnsquestion_t*> { | |
33 | static const int minSize = 1; | |
34 | static const int maxSize = 1; | |
35 | ||
36 | static PushedObject push(lua_State* state, dnsdist_ffi_dnsquestion_t* ptr) noexcept { | |
37 | lua_pushlightuserdata(state, ptr); | |
38 | return PushedObject{state, 1}; | |
39 | } | |
40 | }; | |
41 | ||
42 | struct dnsdist_ffi_dnsquestion_t | |
43 | { | |
44 | dnsdist_ffi_dnsquestion_t(DNSQuestion* dq_): dq(dq_) | |
45 | { | |
46 | } | |
47 | ||
48 | DNSQuestion* dq{nullptr}; | |
a291bc0d RG |
49 | std::vector<dnsdist_ffi_ednsoption_t> ednsOptionsVect; |
50 | std::vector<dnsdist_ffi_http_header_t> httpHeadersVect; | |
51 | std::vector<dnsdist_ffi_tag_t> tagsVect; | |
5e7672ff | 52 | std::unordered_map<std::string, std::string> httpHeaders; |
0ed8f0fa | 53 | std::string trailingData; |
45a661ed | 54 | ComboAddress maskedRemote; |
5e7672ff RG |
55 | boost::optional<std::string> result{boost::none}; |
56 | boost::optional<std::string> httpPath{boost::none}; | |
57 | boost::optional<std::string> httpQueryString{boost::none}; | |
58 | boost::optional<std::string> httpHost{boost::none}; | |
59 | boost::optional<std::string> httpScheme{boost::none}; | |
60 | }; | |
0ed8f0fa | 61 | |
be05aa91 RG |
62 | // dnsdist_ffi_server_t is a lightuserdata |
63 | template<> | |
64 | struct LuaContext::Pusher<dnsdist_ffi_server_t*> { | |
65 | static const int minSize = 1; | |
66 | static const int maxSize = 1; | |
67 | ||
68 | static PushedObject push(lua_State* state, dnsdist_ffi_server_t* ptr) noexcept { | |
69 | lua_pushlightuserdata(state, ptr); | |
70 | return PushedObject{state, 1}; | |
71 | } | |
72 | }; | |
73 | ||
74 | struct dnsdist_ffi_server_t | |
75 | { | |
76 | dnsdist_ffi_server_t(const std::shared_ptr<DownstreamState>& server_): server(server_) | |
77 | { | |
78 | } | |
79 | ||
80 | const std::shared_ptr<DownstreamState>& server; | |
81 | }; | |
82 | ||
83 | // dnsdist_ffi_servers_list_t is a lightuserdata | |
84 | template<> | |
85 | struct LuaContext::Pusher<dnsdist_ffi_servers_list_t*> { | |
86 | static const int minSize = 1; | |
87 | static const int maxSize = 1; | |
88 | ||
89 | static PushedObject push(lua_State* state, dnsdist_ffi_servers_list_t* ptr) noexcept { | |
90 | lua_pushlightuserdata(state, ptr); | |
91 | return PushedObject{state, 1}; | |
92 | } | |
93 | }; | |
94 | ||
95 | struct dnsdist_ffi_servers_list_t | |
96 | { | |
cc958b79 | 97 | dnsdist_ffi_servers_list_t(const ServerPolicy::NumberedServerVector& servers_): servers(servers_) |
be05aa91 RG |
98 | { |
99 | ffiServers.reserve(servers.size()); | |
100 | for (const auto& server: servers) { | |
101 | ffiServers.push_back(dnsdist_ffi_server_t(server.second)); | |
102 | } | |
103 | } | |
104 | ||
105 | std::vector<dnsdist_ffi_server_t> ffiServers; | |
cc958b79 | 106 | const ServerPolicy::NumberedServerVector& servers; |
be05aa91 RG |
107 | }; |
108 | ||
0ed8f0fa | 109 | const std::string& getLuaFFIWrappers(); |