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