Divided load_config_from_files into smaller ones.
[bpdyndnsd] / src / main.cpp
1 /** @file
2  * @brief The main function.
3  *
4  *
5  *
6  * @copyright Intra2net AG
7  * @license GPLv2
8 */
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
32 using namespace std;
33
34 typedef boost::shared_ptr<Config> ConfigPtr;
35 typedef boost::shared_ptr<Updater> UpdaterPtr;
36
37 /**
38  * @brief The main part.
39  * @param argc Number of arguments
40  * @param argv Command line arguments
41  * @return 0 if all is fine.
42  */
43 int main(int argc, char *argv[])
44 {
45     // Initialize Config class and get the command line parameters
46     ConfigPtr config(new Config);
47     int ret_val = config->parse_cmd_line(argc,argv);
48     if(ret_val == 1)
49     {
50         // usage
51         config->print_usage();
52         return 0;
53     }
54     else if(ret_val == 2)
55     {
56         // version
57         ostringstream version_string;
58         version_string << VERSION << "." << REVISION << "." << RELEASE;
59         config->print_version(version_string.str());
60         return 0;
61     }
62
63     // Load the main config and the service files
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     {
68         // unknown option
69         cout << "See manpage for config file structure." << endl;
70         return 0;
71     }
72     else if(ret_val == 4)
73     {
74         // error opening
75         return 0;
76     }
77
78     // initialize Updater
79     UpdaterPtr updater(new Updater(config));
80     updater->update_services();
81
82     return 0;
83 }