Skip to content

Commit 49fa530

Browse files
committed
Add server::embedded_pages type, setup macros, and config passthru.
1 parent 2a90e1d commit 49fa530

File tree

21 files changed

+419
-43
lines changed

21 files changed

+419
-43
lines changed

Makefile.am

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ console_bn_SOURCES = \
133133
console/localize.hpp \
134134
console/main.cpp \
135135
console/stack_trace.cpp \
136-
console/stack_trace.hpp
136+
console/stack_trace.hpp \
137+
console/embedded/embedded.hpp \
138+
console/embedded/web_css.cpp \
139+
console/embedded/web_ecma.cpp \
140+
console/embedded/web_font.cpp \
141+
console/embedded/web_html.cpp \
142+
console/embedded/web_icon.cpp
137143

138144
endif WITH_CONSOLE
139145

builds/cmake/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,13 @@ if (with-console)
391391
"../../console/localize.hpp"
392392
"../../console/main.cpp"
393393
"../../console/stack_trace.cpp"
394-
"../../console/stack_trace.hpp" )
394+
"../../console/stack_trace.hpp"
395+
"../../console/embedded/embedded.hpp"
396+
"../../console/embedded/web_css.cpp"
397+
"../../console/embedded/web_ecma.cpp"
398+
"../../console/embedded/web_font.cpp"
399+
"../../console/embedded/web_html.cpp"
400+
"../../console/embedded/web_icon.cpp" )
395401

396402
# bn project specific include directories.
397403
#------------------------------------------------------------------------------

builds/msvc/vs2022/bn/bn.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@
118118
<Import Project="$(ProjectDir)$(ProjectName).props" />
119119
</ImportGroup>
120120
<ItemGroup>
121+
<ClCompile Include="..\..\..\..\console\embedded\web_css.cpp" />
122+
<ClCompile Include="..\..\..\..\console\embedded\web_ecma.cpp" />
123+
<ClCompile Include="..\..\..\..\console\embedded\web_font.cpp" />
124+
<ClCompile Include="..\..\..\..\console\embedded\web_html.cpp" />
125+
<ClCompile Include="..\..\..\..\console\embedded\web_icon.cpp" />
121126
<ClCompile Include="..\..\..\..\console\executor.cpp" />
122127
<ClCompile Include="..\..\..\..\console\executor_commands.cpp" />
123128
<ClCompile Include="..\..\..\..\console\executor_dumps.cpp" />
@@ -133,6 +138,7 @@
133138
<ClCompile Include="..\..\..\..\console\stack_trace.cpp" />
134139
</ItemGroup>
135140
<ItemGroup>
141+
<ClInclude Include="..\..\..\..\console\embedded\embedded.hpp" />
136142
<ClInclude Include="..\..\..\..\console\executor.hpp" />
137143
<ClInclude Include="..\..\..\..\console\localize.hpp" />
138144
<ClInclude Include="..\..\..\..\console\stack_trace.hpp" />

builds/msvc/vs2022/bn/bn.vcxproj.filters

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,31 @@
88
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
99
<ItemGroup>
1010
<Filter Include="resource">
11-
<UniqueIdentifier>{D3404804-C83F-46CE-0000-000000000001}</UniqueIdentifier>
11+
<UniqueIdentifier>{D3404804-C83F-46CE-0000-000000000002}</UniqueIdentifier>
1212
</Filter>
1313
<Filter Include="src">
1414
<UniqueIdentifier>{D3404804-C83F-46CE-0000-000000000000}</UniqueIdentifier>
1515
</Filter>
16+
<Filter Include="src\embedded">
17+
<UniqueIdentifier>{D3404804-C83F-46CE-0000-000000000001}</UniqueIdentifier>
18+
</Filter>
1619
</ItemGroup>
1720
<ItemGroup>
21+
<ClCompile Include="..\..\..\..\console\embedded\web_css.cpp">
22+
<Filter>src\embedded</Filter>
23+
</ClCompile>
24+
<ClCompile Include="..\..\..\..\console\embedded\web_ecma.cpp">
25+
<Filter>src\embedded</Filter>
26+
</ClCompile>
27+
<ClCompile Include="..\..\..\..\console\embedded\web_font.cpp">
28+
<Filter>src\embedded</Filter>
29+
</ClCompile>
30+
<ClCompile Include="..\..\..\..\console\embedded\web_html.cpp">
31+
<Filter>src\embedded</Filter>
32+
</ClCompile>
33+
<ClCompile Include="..\..\..\..\console\embedded\web_icon.cpp">
34+
<Filter>src\embedded</Filter>
35+
</ClCompile>
1836
<ClCompile Include="..\..\..\..\console\executor.cpp">
1937
<Filter>src</Filter>
2038
</ClCompile>
@@ -56,6 +74,9 @@
5674
</ClCompile>
5775
</ItemGroup>
5876
<ItemGroup>
77+
<ClInclude Include="..\..\..\..\console\embedded\embedded.hpp">
78+
<Filter>src\embedded</Filter>
79+
</ClInclude>
5980
<ClInclude Include="..\..\..\..\console\executor.hpp">
6081
<Filter>src</Filter>
6182
</ClInclude>

console/embedded/embedded.hpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#ifndef LIBBITCOIN_BN_EMBEDDED_HPP
20+
#define LIBBITCOIN_BN_EMBEDDED_HPP
21+
22+
#include "../executor.hpp"
23+
24+
#include <memory>
25+
#include <bitcoin/system.hpp>
26+
27+
#define DECLARE_EMBEDDED_PAGE(page) \
28+
system::data_slice page() const NOEXCEPT override
29+
30+
#define DECLARE_EMBEDDED_PAGES(container) \
31+
struct container : public embedded_pages \
32+
{ \
33+
DECLARE_EMBEDDED_PAGE(page); \
34+
DECLARE_EMBEDDED_PAGE(style); \
35+
DECLARE_EMBEDDED_PAGE(script); \
36+
DECLARE_EMBEDDED_PAGE(font); \
37+
DECLARE_EMBEDDED_PAGE(icon); \
38+
}
39+
40+
namespace libbitcoin {
41+
namespace server {
42+
43+
DECLARE_EMBEDDED_PAGES(web_pages);
44+
DECLARE_EMBEDDED_PAGES(explore_pages);
45+
46+
} // namespace server
47+
} // namespace libbitcoin
48+
49+
#define DEFINE_EMBEDDED_PAGE(container, type, name, ...) \
50+
system::data_slice container::name() const NOEXCEPT \
51+
{ \
52+
static constexpr type _##name##_[] = __VA_ARGS__; \
53+
static const system::data_slice out \
54+
{ \
55+
std::addressof(_##name##_[zero]), \
56+
std::next(std::addressof(_##name##_[zero]), \
57+
literal_length(_##name##_)) \
58+
}; \
59+
return out; \
60+
}
61+
62+
#endif

console/embedded/web_css.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include "../embedded/embedded.hpp"
20+
21+
namespace libbitcoin {
22+
namespace server {
23+
24+
// Simple test css for embedded page, links in font.
25+
DEFINE_EMBEDDED_PAGE(web_pages, char, style,
26+
R"(@font-face
27+
{
28+
font-family: 'Boston';
29+
src: url('boston.ttf');
30+
})")
31+
32+
DEFINE_EMBEDDED_PAGE(explore_pages, char, page, "")
33+
DEFINE_EMBEDDED_PAGE(explore_pages, char, style, "")
34+
DEFINE_EMBEDDED_PAGE(explore_pages, char, script, "")
35+
DEFINE_EMBEDDED_PAGE(explore_pages, char, font, "")
36+
DEFINE_EMBEDDED_PAGE(explore_pages, char, icon, "")
37+
38+
} // namespace server
39+
} // namespace libbitcoin

console/embedded/web_ecma.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include "../embedded/embedded.hpp"
20+
21+
namespace libbitcoin {
22+
namespace server {
23+
24+
// Simple test script for embedded page.
25+
DEFINE_EMBEDDED_PAGE(web_pages, char, script,
26+
R"(document.addEventListener('DOMContentLoaded', function()
27+
{
28+
console.log('ping');
29+
});)")
30+
31+
} // namespace server
32+
} // namespace libbitcoin

console/embedded/web_font.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include "../embedded/embedded.hpp"
20+
21+
namespace libbitcoin {
22+
namespace server {
23+
24+
DEFINE_EMBEDDED_PAGE(web_pages, uint8_t, font,
25+
{
26+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
27+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
28+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
34+
})
35+
36+
} // namespace server
37+
} // namespace libbitcoin

console/embedded/web_html.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include "../embedded/embedded.hpp"
20+
21+
namespace libbitcoin {
22+
namespace server {
23+
24+
// Simple test html for embedded page, links in css and page icon.
25+
DEFINE_EMBEDDED_PAGE(web_pages, char, page,
26+
R"(<html>
27+
<head>
28+
<title>Libbitcoin Server</title>
29+
<meta charset="utf-8">
30+
<meta name="description" content="libbitcoin admin site">
31+
<link rel="stylesheet" href="style.css"/>
32+
<link rel="icon" href="icon.png" type="image/png"/>
33+
<link rel="preload" href="boston.ttf" as="font" type="font/woff2">
34+
</head>
35+
<body>
36+
<p>Hello world!</p>
37+
</body>
38+
</html>)")
39+
40+
} // namespace server
41+
} // namespace libbitcoin

console/embedded/web_icon.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include "../embedded/embedded.hpp"
20+
21+
namespace libbitcoin {
22+
namespace server {
23+
24+
DEFINE_EMBEDDED_PAGE(web_pages, uint8_t, icon,
25+
{
26+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
27+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
28+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
34+
})
35+
36+
} // namespace server
37+
} // namespace libbitcoin

0 commit comments

Comments
 (0)