• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

daemon/src/Configuration.cpp

Go to the documentation of this file.
00001 #include "config.h"
00002 #include "Configuration.h"
00003 #include "net/DiscoveryAnnouncement.h"
00004 #include "net/DiscoveryAnnouncement.h"
00005 #include "core/Node.h"
00006 
00007 #include <ibrdtn/utils/Utils.h>
00008 #include <ibrdtn/utils/Clock.h>
00009 
00010 #include <ibrcommon/net/vinterface.h>
00011 #include <ibrcommon/Logger.h>
00012 
00013 #include <getopt.h>
00014 
00015 #ifdef __DEVELOPMENT_ASSERTIONS__
00016 #include <cassert>
00017 #endif
00018 
00019 using namespace dtn::net;
00020 using namespace dtn::core;
00021 using namespace dtn::utils;
00022 using namespace ibrcommon;
00023 
00024 namespace dtn
00025 {
00026         namespace daemon
00027         {
00028                 Configuration::NetConfig::NetConfig(std::string n, NetType t, const std::string &u, bool d)
00029                  : name(n), type(t), url(u), port(0), discovery(d)
00030                 {
00031                 }
00032 
00033                 Configuration::NetConfig::NetConfig(std::string n, NetType t, const ibrcommon::vinterface &i, int p, bool d)
00034                  : name(n), type(t), interface(i), port(p), discovery(d)
00035                 {
00036                 }
00037 
00038                 Configuration::NetConfig::NetConfig(std::string n, NetType t, const ibrcommon::vaddress &a, int p, bool d)
00039                  : name(n), type(t), interface(), address(a), port(p), discovery(d)
00040                 {
00041                 }
00042 
00043                 Configuration::NetConfig::NetConfig(std::string n, NetType t, int p, bool d)
00044                  : name(n), type(t), interface(), port(p), discovery(d)
00045                 {
00046                 }
00047 
00048                 Configuration::NetConfig::~NetConfig()
00049                 {
00050                 }
00051 
00052                 std::string Configuration::version()
00053                 {
00054                         std::stringstream ss;
00055                         ss << PACKAGE_VERSION;
00056                 #ifdef SVN_REVISION
00057                         ss << " (build " << SVN_REVISION << ")";
00058                 #endif
00059 
00060                         return ss.str();
00061                 }
00062 
00063                 Configuration::Configuration()
00064                  : _filename("config.ini"), _doapi(true)
00065                 {
00066                 }
00067 
00068                 Configuration::~Configuration()
00069                 {}
00070 
00071                 Configuration::Discovery::Discovery()
00072                  : _enabled(true), _timeout(5) {};
00073 
00074                 Configuration::Statistic::Statistic() {};
00075 
00076                 Configuration::Debug::Debug()
00077                  : _enabled(false), _quiet(false), _level(0) {};
00078 
00079                 Configuration::Logger::Logger()
00080                  : _quiet(false), _options(0), _timestamps(false) {};
00081 
00082                 Configuration::Network::Network()
00083                  : _routing("default"), _forwarding(true), _tcp_nodelay(true), _tcp_chunksize(1024), _default_net("lo"), _use_default_net(false) {};
00084 
00085                 Configuration::Security::Security()
00086                  : _enabled(false)
00087                 {};
00088 
00089                 Configuration::Daemon::Daemon()
00090                  : _daemonize(false), _kill(false)
00091                 {
00092                 };
00093 
00094                 Configuration::Discovery::~Discovery() {};
00095                 Configuration::Statistic::~Statistic() {};
00096                 Configuration::Debug::~Debug() {};
00097                 Configuration::Logger::~Logger() {};
00098                 Configuration::Network::~Network() {};
00099                 Configuration::Daemon::~Daemon() {};
00100 
00101                 const Configuration::Discovery& Configuration::getDiscovery() const
00102                 {
00103                         return _disco;
00104                 }
00105 
00106                 const Configuration::Statistic& Configuration::getStatistic() const
00107                 {
00108                         return _stats;
00109                 }
00110 
00111                 const Configuration::Debug& Configuration::getDebug() const
00112                 {
00113                         return _debug;
00114                 }
00115 
00116                 const Configuration::Logger& Configuration::getLogger() const
00117                 {
00118                         return _logger;
00119                 }
00120 
00121                 const Configuration::Network& Configuration::getNetwork() const
00122                 {
00123                         return _network;
00124                 }
00125 
00126                 const Configuration::Security& Configuration::getSecurity() const
00127                 {
00128                         return _security;
00129                 }
00130 
00131                 const Configuration::Daemon& Configuration::getDaemon() const
00132                 {
00133                         return _daemon;
00134                 }
00135 
00136                 Configuration& Configuration::getInstance()
00137                 {
00138                         static Configuration conf;
00139                         return conf;
00140                 }
00141 
00142                 void Configuration::params(int argc, char *argv[])
00143                 {
00144                         int c;
00145                         int doapi = _doapi;
00146                         int disco = _disco._enabled;
00147                         int badclock = dtn::utils::Clock::badclock;
00148                         int timestamp = _logger._timestamps;
00149 
00150                         while (1)
00151                         {
00152                                 static struct option long_options[] =
00153                                 {
00154                                                 /* These options set a flag. */
00155                                                 {"noapi", no_argument, &doapi, 0},
00156                                                 {"nodiscovery", no_argument, &disco, 0},
00157                                                 {"badclock", no_argument, &badclock, 1},
00158                                                 {"timestamp", no_argument, &timestamp, 1},
00159 
00160                                                 /* These options don't set a flag. We distinguish them by their indices. */
00161                                                 {"help", no_argument, 0, 'h'},
00162 #ifdef HAVE_LIBDAEMON
00163                                                 {"daemon", no_argument, 0, 'D'},
00164                                                 {"kill", no_argument, 0, 'k'},
00165                                                 {"pidfile", required_argument, 0, 'p'},
00166 #endif
00167 
00168                                                 {"quiet", no_argument, 0, 'q'},
00169                                                 {"version", no_argument, 0, 'v'},
00170                                                 {"interface", required_argument, 0, 'i'},
00171                                                 {"configuration", required_argument, 0, 'c'},
00172                                                 {"debug", required_argument, 0, 'd'},
00173                                                 {0, 0, 0, 0}
00174                                 };
00175 
00176                                 /* getopt_long stores the option index here. */
00177                                 int option_index = 0;
00178 
00179 #ifdef HAVE_LIBDAEMON
00180                                 c = getopt_long (argc, argv, "qhDkp:vi:c:d:",
00181                                                 long_options, &option_index);
00182 #else
00183                                 c = getopt_long (argc, argv, "qhvi:c:d:",
00184                                                 long_options, &option_index);
00185 #endif
00186 
00187                                 /* Detect the end of the options. */
00188                                 if (c == -1)
00189                                         break;
00190 
00191                                 switch (c)
00192                                 {
00193                                 case 0:
00194                                         /* If this option set a flag, do nothing else now. */
00195                                         if (long_options[option_index].flag != 0)
00196                                                 break;
00197                                         printf ("option %s", long_options[option_index].name);
00198                                         if (optarg)
00199                                                 printf (" with arg %s", optarg);
00200                                         printf ("\n");
00201                                         break;
00202 
00203                                 case 'h':
00204                                         std::cout << "IBR-DTN version: " << version() << std::endl;
00205                                         std::cout << "Syntax: dtnd [options]"  << std::endl;
00206                                         std::cout << " -h|--help       display this text" << std::endl;
00207                                         std::cout << " -c <file>       set a configuration file" << std::endl;
00208 #ifdef HAVE_LIBDAEMON
00209                                         std::cout << " -D              daemonize the process" << std::endl;
00210                                         std::cout << " -k              stop the running daemon" << std::endl;
00211                                         std::cout << " -p <file>       store the pid in this pidfile" << std::endl;
00212 #endif
00213                                         std::cout << " -i <interface>  interface to bind on (e.g. eth0)" << std::endl;
00214                                         std::cout << " -d <level>      enable debugging and set a verbose level" << std::endl;
00215                                         std::cout << " -q              enables the quiet mode (no logging to the console)" << std::endl;
00216                                         std::cout << " --noapi         disable API module" << std::endl;
00217                                         std::cout << " --nodiscovery   disable discovery module" << std::endl;
00218                                         std::cout << " --badclock      assume a bad clock on the system (use AgeBlock)" << std::endl;
00219                                         std::cout << " --timestamp     enables timestamps for logging instead of datetime values" << std::endl;
00220                                         exit(0);
00221                                         break;
00222 
00223                                 case 'v':
00224                                         std::cout << "IBR-DTN version: " << version() << std::endl;
00225                                         exit(0);
00226                                         break;
00227 
00228                                 case 'q':
00229                                         _debug._quiet = true;
00230                                         break;
00231 
00232                                 case 'c':
00233                                         _filename = optarg;
00234                                         break;
00235 
00236                                 case 'i':
00237                                         _network._default_net = ibrcommon::vinterface(optarg);
00238                                         _network._use_default_net = true;
00239                                         break;
00240 
00241                                 case 'd':
00242                                         _debug._enabled = true;
00243                                         _debug._level = atoi(optarg);
00244                                         break;
00245 
00246                                 case 'D':
00247                                         _daemon._daemonize = true;
00248                                         _debug._quiet = true;
00249                                         break;
00250 
00251                                 case 'k':
00252                                         _daemon._daemonize = true;
00253                                         _daemon._kill = true;
00254                                         break;
00255 
00256                                 case 'p':
00257                                         _daemon._pidfile = std::string(optarg);
00258                                         break;
00259 
00260                                 case '?':
00261                                         /* getopt_long already printed an error message. */
00262                                         break;
00263 
00264                                 default:
00265                                         abort ();
00266                                 }
00267                         }
00268 
00269                         _doapi = doapi;
00270                         _disco._enabled = disco;
00271                         dtn::utils::Clock::badclock = badclock;
00272                         _logger._timestamps = timestamp;
00273                 }
00274 
00275                 void Configuration::load()
00276                 {
00277                         load(_filename);
00278                 }
00279 
00280                 void Configuration::load(string filename)
00281                 {
00282                         try {
00283                                 // load main configuration
00284                                 _conf = ibrcommon::ConfigFile(filename);
00285                                 _filename = filename;
00286 
00287                                 IBRCOMMON_LOGGER(info) << "Configuration: " << filename << IBRCOMMON_LOGGER_ENDL;
00288                         } catch (const ibrcommon::ConfigFile::file_not_found&) {
00289                                 IBRCOMMON_LOGGER(info) << "Using default settings. Call with --help for options." << IBRCOMMON_LOGGER_ENDL;
00290                                 _conf = ConfigFile();
00291                         }
00292 
00293                         // load all configuration extensions
00294                         _disco.load(_conf);
00295                         _stats.load(_conf);
00296                         _debug.load(_conf);
00297                         _logger.load(_conf);
00298                         _network.load(_conf);
00299                         _security.load(_conf);
00300                 }
00301 
00302                 void Configuration::Discovery::load(const ibrcommon::ConfigFile &conf)
00303                 {
00304                         _timeout = conf.read<unsigned int>("discovery_timeout", 5);
00305                 }
00306 
00307                 void Configuration::Statistic::load(const ibrcommon::ConfigFile&)
00308                 {
00309                 }
00310 
00311                 void Configuration::Logger::load(const ibrcommon::ConfigFile&)
00312                 {
00313                 }
00314 
00315                 void Configuration::Debug::load(const ibrcommon::ConfigFile&)
00316                 {
00317                 }
00318 
00319                 void Configuration::Daemon::load(const ibrcommon::ConfigFile&)
00320                 {
00321                 }
00322 
00323                 bool Configuration::Debug::quiet() const
00324                 {
00325                         return _quiet;
00326                 }
00327 
00328                 bool Configuration::Debug::enabled() const
00329                 {
00330                         return _enabled;
00331                 }
00332 
00333                 int Configuration::Debug::level() const
00334                 {
00335                         return _level;
00336                 }
00337 
00338                 string Configuration::getNodename()
00339                 {
00340                         try {
00341                                 return _conf.read<string>("local_uri");
00342                         } catch (const ibrcommon::ConfigFile::key_not_found&) {
00343                                 char *hostname_array = new char[64];
00344                                 if ( gethostname(hostname_array, 64) != 0 )
00345                                 {
00346                                         // error
00347                                         delete[] hostname_array;
00348                                         return "local";
00349                                 }
00350 
00351                                 string hostname(hostname_array);
00352                                 delete[] hostname_array;
00353 
00354                                 stringstream ss;
00355                                 ss << "dtn://" << hostname;
00356                                 ss >> hostname;
00357 
00358                                 return hostname;
00359                         }
00360                 }
00361 
00362                 const std::list<Configuration::NetConfig>& Configuration::Network::getInterfaces() const
00363                 {
00364                         return _interfaces;
00365                 }
00366 
00367                 const ibrcommon::vaddress Configuration::Discovery::address() const throw (ParameterNotFoundException)
00368                 {
00369                         try {
00370                                 return ibrcommon::vaddress( ibrcommon::vaddress::VADDRESS_INET,
00371                                                 Configuration::getInstance()._conf.read<string>("discovery_address"));
00372                         } catch (const ConfigFile::key_not_found&) {
00373                                 throw ParameterNotFoundException();
00374                         }
00375                 }
00376 
00377                 int Configuration::Discovery::port() const
00378                 {
00379                         return Configuration::getInstance()._conf.read<int>("discovery_port", 4551);
00380                 }
00381 
00382                 unsigned int Configuration::Discovery::timeout() const
00383                 {
00384                         return _timeout;
00385                 }
00386 
00387                 Configuration::NetConfig Configuration::getAPIInterface()
00388                 {
00389                         return Configuration::NetConfig("local", Configuration::NetConfig::NETWORK_TCP, ibrcommon::vinterface("lo"), 4550);
00390                 }
00391 
00392                 ibrcommon::File Configuration::getAPISocket()
00393                 {
00394                         try {
00395                                 return ibrcommon::File(_conf.read<std::string>("api_socket"));
00396                         } catch (const ConfigFile::key_not_found&) {
00397                                 throw ParameterNotSetException();
00398                         }
00399                 }
00400 
00401                 std::string Configuration::getStorage() const
00402                 {
00403                         return _conf.read<std::string>("storage", "default");
00404                 }
00405 
00406                 void Configuration::Network::load(const ibrcommon::ConfigFile &conf)
00407                 {
00411                         _static_routes.clear();
00412 
00413                         string key = "route1";
00414                         unsigned int keynumber = 1;
00415 
00416                         while (conf.keyExists( key ))
00417                         {
00418                                 vector<string> route = dtn::utils::Utils::tokenize(" ", conf.read<string>(key, "dtn:none dtn:none"));
00419                                 _static_routes.push_back( dtn::routing::StaticRoutingExtension::StaticRoute( route.front(), route.back() ) );
00420 
00421                                 keynumber++;
00422                                 stringstream ss; ss << "route" << keynumber; ss >> key;
00423                         }
00424 
00428                         // read the node count
00429                         int count = 1;
00430 
00431                         // initial prefix
00432                         std::string prefix = "static1_";
00433 
00434                         while ( conf.keyExists(prefix + "uri") )
00435                         {
00436                                 Node n(Node::NODE_PERMANENT);
00437 
00438                                 n.setAddress( conf.read<std::string>(prefix + "address", "127.0.0.1") );
00439                                 n.setPort( conf.read<unsigned int>(prefix + "port", 4556) );
00440                                 n.setURI( conf.read<std::string>(prefix + "uri", "dtn:none") );
00441                                 n.setConnectImmediately( conf.read<std::string>(prefix + "immediately", "no") == "yes" );
00442 
00443                                 std::string protocol = conf.read<std::string>(prefix + "proto", "tcp");
00444                                 if (protocol == "tcp") n.setProtocol(Node::CONN_TCPIP);
00445                                 if (protocol == "udp") n.setProtocol(Node::CONN_UDPIP);
00446                                 if (protocol == "zigbee") n.setProtocol(Node::CONN_ZIGBEE);
00447                                 if (protocol == "bluetooth") n.setProtocol(Node::CONN_BLUETOOTH);
00448                                 if (protocol == "http") n.setProtocol(Node::CONN_HTTP);
00449 
00450                                 count++;
00451 
00452                                 std::stringstream prefix_stream;
00453                                 prefix_stream << "static" << count << "_";
00454                                 prefix = prefix_stream.str();
00455 
00456                                 _nodes.push_back(n);
00457                         }
00458 
00462                         _routing = conf.read<string>("routing", "default");
00463 
00467                         _forwarding = (conf.read<std::string>("routing_forwarding", "yes") == "yes");
00468 
00472                         _interfaces.clear();
00473 
00474                         if (_use_default_net)
00475                         {
00476                                 _interfaces.push_back( Configuration::NetConfig("default", Configuration::NetConfig::NETWORK_TCP, _default_net, 4556) );
00477                         }
00478                         else try
00479                         {
00480                                 vector<string> nets = dtn::utils::Utils::tokenize(" ", conf.read<string>("net_interfaces") );
00481                                 for (vector<string>::const_iterator iter = nets.begin(); iter != nets.end(); iter++)
00482                                 {
00483                                         std::string netname = (*iter);
00484 
00485                                         std::string key_type = "net_" + netname + "_type";
00486                                         std::string key_port = "net_" + netname + "_port";
00487                                         std::string key_interface = "net_" + netname + "_interface";
00488                                         std::string key_address = "net_" + netname + "_address";
00489                                         std::string key_discovery = "net_" + netname + "_discovery";
00490 
00491                                         std::string type_name = conf.read<string>(key_type, "tcp");
00492                                         Configuration::NetConfig::NetType type = Configuration::NetConfig::NETWORK_UNKNOWN;
00493 
00494                                         if (type_name == "tcp") type = Configuration::NetConfig::NETWORK_TCP;
00495                                         if (type_name == "udp") type = Configuration::NetConfig::NETWORK_UDP;
00496                                         if (type_name == "http") type = Configuration::NetConfig::NETWORK_HTTP;
00497                                         if (type_name == "lowpan") type = Configuration::NetConfig::NETWORK_LOWPAN;
00498 
00499                                         switch (type)
00500                                         {
00501                                                 case Configuration::NetConfig::NETWORK_HTTP:
00502                                                 {
00503                                                         Configuration::NetConfig::NetConfig nc(netname, type,
00504                                                                         conf.read<std::string>(key_address, "http://localhost/"),
00505                                                                         conf.read<std::string>(key_discovery, "yes") == "no");
00506 
00507                                                         _interfaces.push_back(nc);
00508                                                         break;
00509                                                 }
00510 
00511                                                 default:
00512                                                 {
00513                                                         int port = conf.read<int>(key_port, 4556);
00514                                                         bool discovery = (conf.read<std::string>(key_discovery, "yes") == "yes");
00515 
00516                                                         try {
00517                                                                 ibrcommon::vinterface interface(conf.read<std::string>(key_interface));
00518                                                                 Configuration::NetConfig::NetConfig nc(netname, type, interface, port, discovery);
00519                                                                 _interfaces.push_back(nc);
00520                                                         } catch (const ConfigFile::key_not_found&) {
00521                                                                 ibrcommon::vaddress addr;
00522                                                                 Configuration::NetConfig::NetConfig nc(netname, type, addr, port, discovery);
00523                                                                 _interfaces.push_back(nc);
00524                                                         }
00525 
00526                                                         break;
00527                                                 }
00528                                         }
00529                                 }
00530                         } catch (const ConfigFile::key_not_found&) {
00531                                 // stop the one network is not found.
00532                         }
00533 
00537                         _tcp_nodelay = (conf.read<std::string>("tcp_nodelay", "yes") == "yes");
00538                         _tcp_chunksize = conf.read<unsigned int>("tcp_chunksize", 1024);
00539                 }
00540 
00541                 const list<dtn::routing::StaticRoutingExtension::StaticRoute>& Configuration::Network::getStaticRoutes() const
00542                 {
00543                         return _static_routes;
00544                 }
00545 
00546                 const std::list<Node>& Configuration::Network::getStaticNodes() const
00547                 {
00548                         return _nodes;
00549                 }
00550 
00551                 int Configuration::getTimezone()
00552                 {
00553                         return _conf.read<int>( "timezone", 0 );
00554                 }
00555 
00556                 ibrcommon::File Configuration::getPath(string name)
00557                 {
00558                         stringstream ss;
00559                         ss << name << "_path";
00560                         string key; ss >> key;
00561 
00562                         try {
00563                                 return ibrcommon::File(_conf.read<string>(key));
00564                         } catch (const ConfigFile::key_not_found&) {
00565                                 throw ParameterNotSetException();
00566                         }
00567                 }
00568 
00569                 unsigned int Configuration::getUID()
00570                 {
00571                         try {
00572                                 return _conf.read<unsigned int>("user");
00573                         } catch (const ConfigFile::key_not_found&) {
00574                                 throw ParameterNotSetException();
00575                         }
00576                 }
00577 
00578                 unsigned int Configuration::getGID()
00579                 {
00580                         try {
00581                                 return _conf.read<unsigned int>("group");
00582                         } catch (const ConfigFile::key_not_found&) {
00583                                 throw ParameterNotSetException();
00584                         }
00585                 }
00586 
00587 
00588                 bool Configuration::Discovery::enabled() const
00589                 {
00590                         return _enabled;
00591                 }
00592 
00593                 bool Configuration::Discovery::announce() const
00594                 {
00595                         return (Configuration::getInstance()._conf.read<int>("discovery_announce", 1) == 1);
00596                 }
00597 
00598                 bool Configuration::Discovery::shortbeacon() const
00599                 {
00600                         return (Configuration::getInstance()._conf.read<int>("discovery_short", 0) == 1);
00601                 }
00602 
00603                 char Configuration::Discovery::version() const
00604                 {
00605                         return Configuration::getInstance()._conf.read<int>("discovery_version", 2);
00606                 }
00607 
00608                 bool Configuration::doAPI()
00609                 {
00610                         return _doapi;
00611                 }
00612 
00613                 string Configuration::getNotifyCommand()
00614                 {
00615                         try {
00616                                 return _conf.read<string>("notify_cmd");
00617                         } catch (const ConfigFile::key_not_found&) {
00618                                 throw ParameterNotSetException();
00619                         }
00620                 }
00621 
00622                 Configuration::RoutingExtension Configuration::Network::getRoutingExtension() const
00623                 {
00624                         if ( _routing == "epidemic" ) return EPIDEMIC_ROUTING;
00625                         if ( _routing == "flooding" ) return FLOOD_ROUTING;
00626                         return DEFAULT_ROUTING;
00627                 }
00628 
00629 
00630                 bool Configuration::Network::doForwarding() const
00631                 {
00632                         return _forwarding;
00633                 }
00634 
00635                 bool Configuration::Network::getTCPOptionNoDelay() const
00636                 {
00637                         return _tcp_nodelay;
00638                 }
00639 
00640                 size_t Configuration::Network::getTCPChunkSize() const
00641                 {
00642                         return _tcp_chunksize;
00643                 }
00644 
00645                 bool Configuration::Statistic::enabled() const
00646                 {
00647                         return Configuration::getInstance()._conf.keyExists("statistic_type");
00648                 }
00649 
00650                 ibrcommon::File Configuration::Statistic::logfile() const throw (ParameterNotSetException)
00651                 {
00652                         try {
00653                                 return ibrcommon::File(Configuration::getInstance()._conf.read<std::string>("statistic_file"));
00654                         } catch (const ConfigFile::key_not_found&) {
00655                                 throw ParameterNotSetException();
00656                         }
00657                 }
00658 
00659                 std::string Configuration::Statistic::type() const
00660                 {
00661                         return Configuration::getInstance()._conf.read<std::string>("statistic_type", "stdout");
00662                 }
00663 
00664                 unsigned int Configuration::Statistic::interval() const
00665                 {
00666                         return Configuration::getInstance()._conf.read<unsigned int>("statistic_interval", 300);
00667                 }
00668 
00669                 std::string Configuration::Statistic::address() const
00670                 {
00671                         return Configuration::getInstance()._conf.read<std::string>("statistic_address", "127.0.0.1");
00672                 }
00673 
00674                 unsigned int Configuration::Statistic::port() const
00675                 {
00676                         return Configuration::getInstance()._conf.read<unsigned int>("statistic_port", 1234);
00677                 }
00678 
00679                 size_t Configuration::getLimit(std::string suffix)
00680                 {
00681                         std::string unparsed = _conf.read<std::string>("limit_" + suffix, "0");
00682 
00683                         std::stringstream ss(unparsed);
00684 
00685                         float value; ss >> value;
00686                         char multiplier = 0; ss >> multiplier;
00687 
00688                         switch (multiplier)
00689                         {
00690                         default:
00691                                 return (size_t)value;
00692                                 break;
00693 
00694                         case 'G':
00695                                 return (size_t)(value * 1000000000);
00696                                 break;
00697 
00698                         case 'M':
00699                                 return (size_t)(value * 1000000);
00700                                 break;
00701 
00702                         case 'K':
00703                                 return (size_t)(value * 1000);
00704                                 break;
00705                         }
00706 
00707                         return 0;
00708                 }
00709 
00710                 void Configuration::Security::load(const ibrcommon::ConfigFile &conf)
00711                 {
00712 #ifdef WITH_BUNDLE_SECURITY
00713                         // enable security if the security path is set
00714                         try {
00715                                 _path = conf.read<std::string>("security_path");
00716 
00717                                 if (!_path.exists())
00718                                 {
00719                                         ibrcommon::File::createDirectory(_path);
00720                                 }
00721 
00722                                 _enabled = true;
00723                         } catch (const ibrcommon::ConfigFile::key_not_found&) {
00724                                 return;
00725                         }
00726 
00727                         // load level
00728                         _level = Level(conf.read<int>("security_level", 0));
00729 
00730                         // load CA file
00731                         try {
00732                                 _ca = conf.read<std::string>("security_ca");
00733 
00734                                 if (!_ca.exists())
00735                                 {
00736                                         IBRCOMMON_LOGGER(warning) << "CA file " << _ca.getPath() << " does not exists!" << IBRCOMMON_LOGGER_ENDL;
00737                                 }
00738                         } catch (const ibrcommon::ConfigFile::key_not_found&) {
00739                         }
00740 
00741                         // load KEY file
00742                         try {
00743                                 _ca = conf.read<std::string>("security_key");
00744 
00745                                 if (!_ca.exists())
00746                                 {
00747                                         IBRCOMMON_LOGGER(warning) << "KEY file " << _ca.getPath() << " does not exists!" << IBRCOMMON_LOGGER_ENDL;
00748                                 }
00749                         } catch (const ibrcommon::ConfigFile::key_not_found&) {
00750                         }
00751 
00752                         // load KEY file
00753                         try {
00754                                 _bab_default_key = conf.read<std::string>("security_bab_default_key");
00755 
00756                                 if (!_bab_default_key.exists())
00757                                 {
00758                                         IBRCOMMON_LOGGER(warning) << "KEY file " << _bab_default_key.getPath() << " does not exists!" << IBRCOMMON_LOGGER_ENDL;
00759                                 }
00760                         } catch (const ibrcommon::ConfigFile::key_not_found&) {
00761                         }
00762 #endif
00763                 };
00764 
00765                 Configuration::Security::~Security() {};
00766 
00767                 bool Configuration::Security::enabled() const
00768                 {
00769                         return _enabled;
00770                 }
00771 
00772 #ifdef WITH_BUNDLE_SECURITY
00773                 const ibrcommon::File& Configuration::Security::getPath() const
00774                 {
00775                         return _path;
00776                 }
00777 
00778                 const ibrcommon::File& Configuration::Security::getCA() const
00779                 {
00780                         return _ca;
00781                 }
00782 
00783                 const ibrcommon::File& Configuration::Security::getKey() const
00784                 {
00785                         return _key;
00786                 }
00787 
00788                 Configuration::Security::Level Configuration::Security::getLevel() const
00789                 {
00790                         return _level;
00791                 }
00792 
00793                 const ibrcommon::File& Configuration::Security::getBABDefaultKey() const
00794                 {
00795                         return _bab_default_key;
00796                 }
00797 #endif
00798 
00799                 bool Configuration::Logger::quiet() const
00800                 {
00801                         return _quiet;
00802                 }
00803 
00804                 bool Configuration::Logger::display_timestamps() const
00805                 {
00806                         return _timestamps;
00807                 }
00808 
00809                 unsigned int Configuration::Logger::options() const
00810                 {
00811                         return _options;
00812                 }
00813 
00814                 std::ostream& Configuration::Logger::output() const
00815                 {
00816                         return std::cout;
00817                 }
00818 
00819                 bool Configuration::Daemon::daemonize() const
00820                 {
00821                         return _daemonize;
00822                 }
00823 
00824                 bool Configuration::Daemon::kill_daemon() const
00825                 {
00826                         return _kill;
00827                 }
00828 
00829                 const ibrcommon::File& Configuration::Daemon::getPidFile() const
00830                 {
00831                         if (_pidfile == ibrcommon::File()) throw ParameterNotSetException();
00832                         return _pidfile;
00833                 }
00834         }
00835 }

Generated on Wed Mar 30 2011 11:11:49 for IBR-DTNSuite by  doxygen 1.7.1