summaryrefslogtreecommitdiff
path: root/src/FeatureConfig.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-04-27 05:55:02 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-04-27 05:55:02 +0000
commitb74e27ff923ca4cc02fc0586a9cf08bd3d2e7705 (patch)
tree5ff05dd056d636758e47ae6528b38a16b1d3e4c5 /src/FeatureConfig.cc
parent393830739199a8da33df1922b547397eeeb486d4 (diff)
2008-04-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Reorganized version information so that it can be displayed in a standard terminal screen without scrolling. Removed http, ftp from Configuration section, because they are always enabled. * src/FeatureConfig.cc * src/FeatureConfig.h * src/main.cc * src/messageDigest.cc * src/messageDigest.h * src/version_usage.cc * test/FeatureConfigTest.cc
Diffstat (limited to 'src/FeatureConfig.cc')
-rw-r--r--src/FeatureConfig.cc126
1 files changed, 80 insertions, 46 deletions
diff --git a/src/FeatureConfig.cc b/src/FeatureConfig.cc
index 8c71c5a6..36dcff68 100644
--- a/src/FeatureConfig.cc
+++ b/src/FeatureConfig.cc
@@ -33,76 +33,110 @@
*/
/* copyright --> */
#include "FeatureConfig.h"
+#include "array_fun.h"
+#include "Util.h"
+#include <numeric>
namespace aria2 {
-FeatureConfig* FeatureConfig::featureConfig = 0;
+SharedHandle<FeatureConfig> FeatureConfig::_featureConfig;
-#define FEATURE_HTTP "http"
-#define FEATURE_HTTPS "https"
-#define FEATURE_FTP "ftp"
-#define FEATURE_BITTORRENT "bittorrent"
-#define FEATURE_METALINK "metalink"
-#define FEATURE_MESSAGE_DIGEST "message digest"
-#define FEATURE_ASYNC_DNS "async dns"
+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");
-FeatureConfig::FeatureConfig() {
- static PortMap::value_type portArray[] = {
- PortMap::value_type("http", 80),
- PortMap::value_type("https", 443),
- PortMap::value_type("ftp", 21),
- };
- size_t portArraySize = sizeof(portArray)/sizeof(PortMap::value_type);
- defaultPorts.insert(&portArray[0],
- &portArray[portArraySize]);
-
- static FeatureMap::value_type featureArray[] = {
- FeatureMap::value_type(FEATURE_HTTP, true),
- FeatureMap::value_type(FEATURE_HTTPS,
#ifdef ENABLE_SSL
- true
+# define HTTPS_ENABLED true
#else
- false
+# define HTTPS_ENABLED false
#endif // ENABLE_SSL
- ),
- FeatureMap::value_type(FEATURE_FTP, true),
- FeatureMap::value_type(FEATURE_BITTORRENT,
+
#ifdef ENABLE_BITTORRENT
- true
+# define BITTORRENT_ENABLED true
#else
- false
+# define BITTORRENT_ENABLED false
#endif // ENABLE_BITTORRENT
- ),
- FeatureMap::value_type(FEATURE_METALINK,
+
#ifdef ENABLE_METALINK
- true
+# define METALINK_ENABLED true
#else
- false
+# define METALINK_ENABLED false
#endif // ENABLE_METALINK
- ),
- FeatureMap::value_type(FEATURE_MESSAGE_DIGEST,
+
#ifdef ENABLE_MESSAGE_DIGEST
- true
+# define MESSAGE_DIGEST_ENABLED true
#else
- false
+# define MESSAGE_DIGEST_ENABLED false
#endif // ENABLE_MESSAGE_DIGEST
- ),
- FeatureMap::value_type(FEATURE_ASYNC_DNS,
+
#ifdef ENABLE_ASYNC_DNS
- true
+# define ASYNC_DNS_ENABLED true
#else
- false
+# define ASYNC_DNS_ENABLED false
#endif // ENABLE_ASYNC_DNS
- ),
+
+FeatureConfig::FeatureConfig() {
+ _defaultPorts.insert(PortMap::value_type("http", 80));
+ _defaultPorts.insert(PortMap::value_type("https", 443));
+ _defaultPorts.insert(PortMap::value_type("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)
};
- size_t featureArraySize = sizeof(featureArray)/sizeof(FeatureMap::value_type);
- supportedFeatures.insert(&featureArray[0],
- &featureArray[featureArraySize]);
+ _features.insert(&featureArray[0], &featureArray[arrayLength(featureArray)]);
+}
- for(size_t i = 0; i < featureArraySize; i++) {
- features.push_back(featureArray[i].first);
+SharedHandle<FeatureConfig> 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;
+ }
+}
+
+class AccFeature {
+public:
+ std::string operator()(std::string line, const FeatureMap::value_type& v)
+ {
+ if(v.second) {
+ line += v.first+", ";
+ }
+ return line;
+ }
+};
+
+std::string FeatureConfig::featureSummary() const
+{
+ return Util::trim
+ (std::accumulate(_features.begin(), _features.end(), std::string(),
+ AccFeature()), ", ");
}
} // namespace aria2