NAWA  0.8
Web Application Framework for C++
nawarun.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2019-2021 Tobias Flaig.
8  *
9  * This file is part of nawa.
10  *
11  * nawa is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License,
13  * version 3, as published by the Free Software Foundation.
14  *
15  * nawa is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with nawa. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef NAWA_NAWARUN_H
25 #define NAWA_NAWARUN_H
26 
27 #include <memory>
28 #include <nawa/internal/fwdecl.h>
29 #include <optional>
30 #include <string>
31 #include <tuple>
32 #include <unistd.h>
33 #include <vector>
34 
35 namespace nawarun {
36  using PrivilegeDowngradeData = std::tuple<uid_t, gid_t, std::vector<gid_t>>;
37 
38  struct Parameters {
39  using ConfigOptionId = std::pair<std::string, std::string>;
40  using ConfigOverride = std::pair<ConfigOptionId, std::string>;
41  std::optional<std::string> configFile;
42  std::vector<ConfigOverride> configOverrides;
43  };
44 
45  // Types of functions that need to be accessed from NAWA applications
46  using init_t = int(nawa::AppInit&);
54  unsigned int getConcurrency(nawa::Config const& config);
55 
62  std::pair<init_t*, std::shared_ptr<nawa::HandleRequestFunctionWrapper>> loadAppFunctions(nawa::Config const& config);
63 
68  void reload(int signum);
69 
77  std::optional<PrivilegeDowngradeData> preparePrivilegeDowngrade(nawa::Config const& config);
78 
83  void replaceLogger(nawa::Log const& log);
84 
92  Parameters parseCommandLine(int argc, char** argv);
93 
99  int run(Parameters const& parameters);
100 }// namespace nawarun
101 
102 #endif//NAWA_NAWARUN_H
Definition: Log.h:38
Forward declarations.
std::vector< ConfigOverride > configOverrides
Definition: nawarun.h:42
Parameters parseCommandLine(int argc, char **argv)
Definition: nawarun.cpp:340
std::optional< std::string > configFile
Definition: nawarun.h:41
std::pair< ConfigOptionId, std::string > ConfigOverride
Definition: nawarun.h:40
int(nawa::Connection &) handleRequest_t
Definition: nawarun.h:47
void reload(int signum)
Definition: nawarun.cpp:229
int(nawa::AppInit &) init_t
Definition: nawarun.h:46
unsigned int getConcurrency(nawa::Config const &config)
Definition: nawarun.cpp:184
int run(Parameters const &parameters)
Definition: nawarun.cpp:392
std::optional< PrivilegeDowngradeData > preparePrivilegeDowngrade(nawa::Config const &config)
Definition: nawarun.cpp:287
std::pair< init_t *, std::shared_ptr< nawa::HandleRequestFunctionWrapper > > loadAppFunctions(nawa::Config const &config)
Definition: nawarun.cpp:200
void replaceLogger(nawa::Log const &log)
Definition: nawarun.cpp:329
std::pair< std::string, std::string > ConfigOptionId
Definition: nawarun.h:39
std::tuple< uid_t, gid_t, std::vector< gid_t > > PrivilegeDowngradeData
Definition: nawarun.h:36