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#include "apps/http/model/servers.h"
21#include "express/middleware/StaticMiddleware.h"
22#include "net/config/ConfigSection.hpp"
23
24#ifndef DOXYGEN_SHOULD_SKIP_THIS
25
26#include "log/Logger.h"
27
28#endif /* DOXYGEN_SHOULD_SKIP_THIS */
29
30using namespace express;
31
32int main(int argc, char* argv[]) {
33 using WebApp = apps::http::STREAM::WebApp;
34 using SocketAddress = WebApp::SocketAddress;
35
36 const WebApp webApp(apps::http::STREAM::getWebApp("httpserver"));
37
38 net::config::ConfigSection configWeb = net::config::ConfigSection(&webApp.getConfig(), "www", "Web behavior of httpserver");
39 CLI::Option* htmlRoot = configWeb.addOption("--html-root", "HTML root directory", "path", "");
40 configWeb.required(htmlRoot);
41 WebApp::init(argc, argv);
42
43 webApp.use(express::middleware::StaticMiddleware(htmlRoot->as<std::string>()));
44
45#if (STREAM_TYPE == TLS)
46 // std::map<std::string, std::map<std::string, std::any>> sniCerts = {
47 // {"snodec.home.vchrist.at", {{"Cert", certChainFile}, {"CertKey", keyFile}, {"Password", password}, {"CaFile",
48 // caFile}}},
49 // {"www.vchrist.at", {{"Cert", certChainFile}, {"CertKey", keyFile}, {"Password", password}, {"CaFile", caFile}}}};
50
51 // webApp.addSniCerts(sniCerts);
52 // webApp.forceSni();
53#endif
54 webApp.listen(
55 [instanceName = webApp.getConfig().getInstanceName()](const SocketAddress& socketAddress, const core::socket::State& state) {
56 switch (state) {
57 case core::socket::State::OK:
58 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
59 break;
60 case core::socket::State::DISABLED:
61 VLOG(1) << instanceName << ": disabled";
62 break;
63 case core::socket::State::ERROR:
64 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
65 break;
66 case core::socket::State::FATAL:
67 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
68 break;
69 }
70 });
71
72 return WebApp::start();
73}
74
75/*
76#if (NET_TYPE == IN) // in
77#if (STREAM_TYPE == LEGACY)
78 webApp.listen(8080, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
79#elif (STREAM_TYPE == TLS)
80 webApp.listen(8088, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
81#endif
82#elif (NET_TYPE == IN6) // in6
83#if (STREAM_TYPE == LEGACY)
84 webApp.listen(8080, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
85#elif (STREAM_TYPE == TLS)
86 webApp.listen(8088, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
87#endif
88#elif (NET_TYPE == L2) //
89 // ATLAS: 10:3D:1C:AC:BA:9C
90 // TITAN: A4:B1:C1:2C:82:37
91 // USB: 44:01:BB:A3:63:32
92
93 // webApp.listen("A4:B1:C1:2C:82:37", 0x1023, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) ->
94void { // titan webApp.listen("10:3D:1C:AC:BA:9C", 0x1023, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State&
95state) { // titan #elif (NET_TYPE == RC) // rf
96 // webApp.listen("A4:B1:C1:2C:82:37", 1, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
97// titan webApp.listen("10:3D:1C:AC:BA:9C", 1, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
98// titan #elif (NET_TYPE == UN) // un webApp.listen("/tmp/testme", 5, [](const WebApp::SocketAddress& socketAddress, const
99core::socket::State& state)
100{ // titan #endif if (errnum != 0) { PLOG(FATAL) << "listen"; } else { VLOG(1) << "snode.c listening on " <<
101socketAddress.toString();
102 }
103
104#ifdef NET_TYPE
105 });
106#endif
107*/
int main(int argc, char *argv[])