/* */ #include "FeatureConfig.h" #include "array_fun.h" #include "Util.h" #include "Request.h" #include namespace aria2 { SharedHandle FeatureConfig::_featureConfig; const std::string FeatureConfig::FEATURE_HTTPS("HTTPS"); const std::string FeatureConfig::FEATURE_BITTORRENT("BitTorrent"); const std::string FeatureConfig::FEATURE_METALINK("Metalink"); const std::string FeatureConfig::FEATURE_MESSAGE_DIGEST("Message Digest"); const std::string FeatureConfig::FEATURE_ASYNC_DNS("Async DNS"); #ifdef ENABLE_SSL # define HTTPS_ENABLED true #else # define HTTPS_ENABLED false #endif // ENABLE_SSL #ifdef ENABLE_BITTORRENT # define BITTORRENT_ENABLED true #else # define BITTORRENT_ENABLED false #endif // ENABLE_BITTORRENT #ifdef ENABLE_METALINK # define METALINK_ENABLED true #else # define METALINK_ENABLED false #endif // ENABLE_METALINK #ifdef ENABLE_MESSAGE_DIGEST # define MESSAGE_DIGEST_ENABLED true #else # define MESSAGE_DIGEST_ENABLED false #endif // ENABLE_MESSAGE_DIGEST #ifdef ENABLE_ASYNC_DNS # define ASYNC_DNS_ENABLED true #else # define ASYNC_DNS_ENABLED false #endif // ENABLE_ASYNC_DNS FeatureConfig::FeatureConfig() { _defaultPorts.insert(PortMap::value_type(Request::PROTO_HTTP, 80)); _defaultPorts.insert(PortMap::value_type(Request::PROTO_HTTPS, 443)); _defaultPorts.insert(PortMap::value_type(Request::PROTO_FTP, 21)); FeatureMap::value_type featureArray[] = { FeatureMap::value_type(FEATURE_HTTPS, HTTPS_ENABLED), FeatureMap::value_type(FEATURE_BITTORRENT, BITTORRENT_ENABLED), FeatureMap::value_type(FEATURE_METALINK, METALINK_ENABLED), FeatureMap::value_type(FEATURE_MESSAGE_DIGEST, MESSAGE_DIGEST_ENABLED), FeatureMap::value_type(FEATURE_ASYNC_DNS, ASYNC_DNS_ENABLED) }; _features.insert(&featureArray[0], &featureArray[arrayLength(featureArray)]); } SharedHandle FeatureConfig::getInstance() { if(_featureConfig.isNull()) { _featureConfig.reset(new FeatureConfig()); } return _featureConfig; } uint16_t FeatureConfig::getDefaultPort(const std::string& protocol) const { PortMap::const_iterator itr = _defaultPorts.find(protocol); if(itr == _defaultPorts.end()) { return 0; } else { return itr->second; } } bool FeatureConfig::isSupported(const std::string& feature) const { FeatureMap::const_iterator itr = _features.find(feature); if(itr == _features.end()) { return false; } else { return itr->second; } } std::string FeatureConfig::featureSummary() const { std::string s; for(FeatureMap::const_iterator i = _features.begin(); i != _features.end(); ++i) { if((*i).second) { s += (*i).first+", "; } } return Util::trim(s, ", "); } } // namespace aria2