SNode.C
Loading...
Searching...
No Matches
httpserverclientcert.cpp
Go to the documentation of this file.
1/*
2 * SNode.C - A Slim Toolkit for Network Communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by 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 Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#include "apps/http/model/servers.h"
43#include "express/middleware/StaticMiddleware.h"
44#include "net/config/ConfigSection.hpp"
45
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
47
48#include "log/Logger.h"
49
50#endif /* DOXYGEN_SHOULD_SKIP_THIS */
51
52using namespace express;
53
54int main(int argc, char* argv[]) {
55 using WebApp = apps::http::STREAM::WebApp;
56 using SocketAddress = WebApp::SocketAddress;
57
58 const WebApp webApp(apps::http::STREAM::getWebApp("httpserver"));
59
60 net::config::ConfigSection configWeb = net::config::ConfigSection(&webApp.getConfig(), "www", "Web behavior of httpserver");
61 CLI::Option* htmlRoot = configWeb.addOption("--html-root", "HTML root directory", "path", "");
62 configWeb.required(htmlRoot);
63 WebApp::init(argc, argv);
64
65 webApp.use(express::middleware::StaticMiddleware(htmlRoot->as<std::string>()));
66
67#if (STREAM_TYPE == TLS)
68 // std::map<std::string, std::map<std::string, std::any>> sniCerts = {
69 // {"snodec.home.vchrist.at", {{"Cert", certChainFile}, {"CertKey", keyFile}, {"Password", password}, {"CaFile",
70 // caFile}}},
71 // {"www.vchrist.at", {{"Cert", certChainFile}, {"CertKey", keyFile}, {"Password", password}, {"CaFile", caFile}}}};
72
73 // webApp.addSniCerts(sniCerts);
74 // webApp.forceSni();
75#endif
76 webApp.listen(
77 [instanceName = webApp.getConfig().getInstanceName()](const SocketAddress& socketAddress, const core::socket::State& state) {
78 switch (state) {
79 case core::socket::State::OK:
80 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
81 break;
82 case core::socket::State::DISABLED:
83 VLOG(1) << instanceName << ": disabled";
84 break;
85 case core::socket::State::ERROR:
86 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
87 break;
88 case core::socket::State::FATAL:
89 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
90 break;
91 }
92 });
93
94 return WebApp::start();
95}
96
97/*
98#if (NET_TYPE == IN) // in
99#if (STREAM_TYPE == LEGACY)
100 webApp.listen(8080, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
101#elif (STREAM_TYPE == TLS)
102 webApp.listen(8088, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
103#endif
104#elif (NET_TYPE == IN6) // in6
105#if (STREAM_TYPE == LEGACY)
106 webApp.listen(8080, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
107#elif (STREAM_TYPE == TLS)
108 webApp.listen(8088, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
109#endif
110#elif (NET_TYPE == L2) //
111 // ATLAS: 10:3D:1C:AC:BA:9C
112 // TITAN: A4:B1:C1:2C:82:37
113 // USB: 44:01:BB:A3:63:32
114
115 // webApp.listen("A4:B1:C1:2C:82:37", 0x1023, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) ->
116void { // titan webApp.listen("10:3D:1C:AC:BA:9C", 0x1023, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State&
117state) { // titan #elif (NET_TYPE == RC) // rf
118 // webApp.listen("A4:B1:C1:2C:82:37", 1, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
119// titan webApp.listen("10:3D:1C:AC:BA:9C", 1, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
120// titan #elif (NET_TYPE == UN) // un webApp.listen("/tmp/testme", 5, [](const WebApp::SocketAddress& socketAddress, const
121core::socket::State& state)
122{ // titan #endif if (errnum != 0) { PLOG(FATAL) << "listen"; } else { VLOG(1) << "snode.c listening on " <<
123socketAddress.toString();
124 }
125
126#ifdef NET_TYPE
127 });
128#endif
129*/
int main(int argc, char *argv[])