Divided load_config_from_files into smaller ones.
[bpdyndnsd] / src / main.cpp
CommitLineData
b1be615b
BS
1/** @file
2 * @brief The main function.
3 *
4 *
5 *
6 * @copyright Intra2net AG
7 * @license GPLv2
8*/
4545a371
BS
9
10#ifdef HAVE_CONFIG_H
11#include <config.h>
12#endif
13
14#define VERSION 0
15#define REVISION 1
16#define RELEASE 0
17
18#include <iostream>
19#include <list>
20#include <string>
21
22#include <boost/foreach.hpp>
23
24#include "updater.cpp"
25#include "config.cpp"
26
27#include "service.cpp"
28
29#include "dhs.cpp"
30#include "ods.cpp"
31
32using namespace std;
33
85a0abf9
BS
34typedef boost::shared_ptr<Config> ConfigPtr;
35typedef boost::shared_ptr<Updater> UpdaterPtr;
36
4545a371 37/**
b1be615b
BS
38 * @brief The main part.
39 * @param argc Number of arguments
40 * @param argv Command line arguments
41 * @return 0 if all is fine.
4545a371
BS
42 */
43int main(int argc, char *argv[])
44{
98bd3874 45 // Initialize Config class and get the command line parameters
85a0abf9 46 ConfigPtr config(new Config);
4545a371
BS
47 int ret_val = config->parse_cmd_line(argc,argv);
48 if(ret_val == 1)
49 {
98bd3874 50 // usage
4545a371
BS
51 config->print_usage();
52 return 0;
53 }
54 else if(ret_val == 2)
55 {
98bd3874 56 // version
4545a371
BS
57 ostringstream version_string;
58 version_string << VERSION << "." << REVISION << "." << RELEASE;
59 config->print_version(version_string.str());
60 return 0;
61 }
62
1cf4e2b5 63 // Load the main config and the service files
98bd3874
BS
64 string config_path = "/home/bjoern/bpdyndnsd"; // TODO: standard config path should be /etc/bpdyndnsd if not specified other on command line
65 ret_val = config->load_config_from_files(config_path);
66 if(ret_val == 3)
67 {
1cf4e2b5 68 // unknown option
98bd3874 69 cout << "See manpage for config file structure." << endl;
1cf4e2b5 70 return 0;
98bd3874
BS
71 }
72 else if(ret_val == 4)
73 {
1cf4e2b5 74 // error opening
98bd3874
BS
75 return 0;
76 }
4545a371 77
98bd3874 78 // initialize Updater
85a0abf9 79 UpdaterPtr updater(new Updater(config));
4545a371
BS
80 updater->update_services();
81
4545a371
BS
82 return 0;
83}