summaryrefslogtreecommitdiffhomepage
path: root/webserver.cpp
blob: c49751ee40b3514b7ff6a8fa450e5c47fab67fde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "config.h"
#include "server.h"
#include "plugin.h"

#include <exception>
#include <iostream>
#include <string>

using namespace std::string_literals;

void usage()
{
 std::cout << "usage: webserver [-c <configuration-filename>]" << std::endl;
}

void initlocale() {
 if (setenv("LC_ALL", "UTF-8", 1)) {
  exit(1);
 }
}

int main(int argc, char* argv[])
{
 //initlocale(); // TODO: breaks plugins

 std::string config_filename;

 if (!(argc == 1 || argc == 3)) {
  usage();
  return 1;
 }

 if (argc == 3) {
  if (argv[1] != "-c"s) {
   usage();
   return 1;
  }

  config_filename = argv[2];
 }

 try {
  Config config{config_filename};
  
  PluginLoader plugin_loader(config);
  plugin_loader.load_plugins();

  if (!plugin_loader.validate_config())
   throw std::runtime_error("Config validation error.");

  return run_server(config, plugin_loader.get_plugins());
 } catch (const std::exception& ex) {
  std::cout << "Error: " << ex.what() << std::endl;
  return 1;
 }
}