~singpolyma/biboumi

ref: b60cbda4f93bb83e36b29f5cba975b94b833663d biboumi/src/main.cpp -rw-r--r-- 1.3 KiB
b60cbda4 — Florent Le Coz Read the served hostname from the config file 9 years ago
                                                                                
ccebe901 Florent Le Coz
f0d9273d Florent Le Coz
bf7b05ef Florent Le Coz
f0d9273d Florent Le Coz
bf7b05ef Florent Le Coz
b60cbda4 Florent Le Coz
f0d9273d Florent Le Coz
64c1b28c Florent Le Coz
f0d9273d Florent Le Coz
b60cbda4 Florent Le Coz
f0d9273d Florent Le Coz
b60cbda4 Florent Le Coz
f0d9273d Florent Le Coz
b60cbda4 Florent Le Coz
f0d9273d Florent Le Coz
b60cbda4 Florent Le Coz
ccebe901 Florent Le Coz
b60cbda4 Florent Le Coz
f0d9273d Florent Le Coz
ccebe901 Florent Le Coz
64c1b28c Florent Le Coz
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
#include <xmpp/xmpp_component.hpp>
#include <network/poller.hpp>
#include <config/config.hpp>

#include <iostream>
#include <memory>

/**
 * Provide an helpful message to help the user write a minimal working
 * configuration file.
 */
int config_help(const std::string& missing_option)
{
  if (!missing_option.empty())
    std::cerr << "Error: empty value for option " << missing_option << "." << std::endl;
  std::cerr <<
    "Please provide a configuration file filled like this:\n\n"
    "hostname=irc.example.com\npassword=S3CR3T"
            << std::endl;
  return 1;
}

int main(int ac, char** av)
{
  if (ac > 1)
    Config::filename = av[1];
  Config::file_must_exist = true;
  std::cerr << "Using configuration file: " << Config::filename << std::endl;

  std::string password;
  try { // The file must exist
    password = Config::get("password", "");
  }
  catch (const std::ios::failure& e) {
    return config_help("");
  }
  const std::string hostname = Config::get("hostname", "");
  if (password.empty())
    return config_help("hostname");
  if (hostname.empty())
    return config_help("password");
  std::shared_ptr<XmppComponent> xmpp_component =
    std::make_shared<XmppComponent>(hostname, password);

  Poller p;
  p.add_socket_handler(xmpp_component);
  xmpp_component->start();
  while (p.poll())
    ;
  return 0;
}