mirror of https://github.com/aria2/aria2
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.ccpull/1/head
parent
3938307391
commit
b74e27ff92
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
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
|
||||
|
||||
2008-04-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Masked user ID in log.
|
||||
|
|
|
@ -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");
|
||||
|
||||
#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() {
|
||||
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]);
|
||||
_defaultPorts.insert(PortMap::value_type("http", 80));
|
||||
_defaultPorts.insert(PortMap::value_type("https", 443));
|
||||
_defaultPorts.insert(PortMap::value_type("ftp", 21));
|
||||
|
||||
static FeatureMap::value_type featureArray[] = {
|
||||
FeatureMap::value_type(FEATURE_HTTP, true),
|
||||
FeatureMap::value_type(FEATURE_HTTPS,
|
||||
#ifdef ENABLE_SSL
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif // ENABLE_SSL
|
||||
),
|
||||
FeatureMap::value_type(FEATURE_FTP, true),
|
||||
FeatureMap::value_type(FEATURE_BITTORRENT,
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif // ENABLE_BITTORRENT
|
||||
),
|
||||
FeatureMap::value_type(FEATURE_METALINK,
|
||||
#ifdef ENABLE_METALINK
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif // ENABLE_METALINK
|
||||
),
|
||||
FeatureMap::value_type(FEATURE_MESSAGE_DIGEST,
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
),
|
||||
FeatureMap::value_type(FEATURE_ASYNC_DNS,
|
||||
#ifdef ENABLE_ASYNC_DNS
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif // ENABLE_ASYNC_DNS
|
||||
),
|
||||
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
|
||||
|
|
|
@ -36,9 +36,9 @@
|
|||
#define _D_FEATURE_CONFIG_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "SharedHandle.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <deque>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -47,63 +47,26 @@ typedef std::map<std::string, bool> FeatureMap;
|
|||
|
||||
class FeatureConfig {
|
||||
private:
|
||||
static FeatureConfig* featureConfig;
|
||||
static SharedHandle<FeatureConfig> _featureConfig;
|
||||
|
||||
PortMap defaultPorts;
|
||||
FeatureMap supportedFeatures;
|
||||
std::deque<std::string> features;
|
||||
PortMap _defaultPorts;
|
||||
FeatureMap _features;
|
||||
|
||||
FeatureConfig();
|
||||
~FeatureConfig() {}
|
||||
public:
|
||||
static FeatureConfig* getInstance() {
|
||||
if(!featureConfig) {
|
||||
featureConfig = new FeatureConfig();
|
||||
}
|
||||
return featureConfig;
|
||||
}
|
||||
static SharedHandle<FeatureConfig> getInstance();
|
||||
|
||||
static void release() {
|
||||
delete featureConfig;
|
||||
featureConfig = 0;
|
||||
}
|
||||
uint16_t getDefaultPort(const std::string& protocol) const;
|
||||
|
||||
uint16_t getDefaultPort(const std::string& protocol) const {
|
||||
PortMap::const_iterator itr = defaultPorts.find(protocol);
|
||||
if(itr == defaultPorts.end()) {
|
||||
return 0;
|
||||
} else {
|
||||
return itr->second;
|
||||
}
|
||||
}
|
||||
bool isSupported(const std::string& feature) const;
|
||||
|
||||
bool isSupported(const std::string& feature) const {
|
||||
FeatureMap::const_iterator itr = supportedFeatures.find(feature);
|
||||
if(itr == supportedFeatures.end()) {
|
||||
return false;
|
||||
} else {
|
||||
return itr->second;
|
||||
}
|
||||
}
|
||||
std::string featureSummary() const;
|
||||
|
||||
const std::deque<std::string>& getFeatures() const {
|
||||
return features;
|
||||
}
|
||||
|
||||
std::string getConfigurationSummary() const {
|
||||
std::string summary;
|
||||
for(std::deque<std::string>::const_iterator itr = features.begin();
|
||||
itr != features.end(); itr++) {
|
||||
summary += *itr;
|
||||
if(isSupported(*itr)) {
|
||||
summary += ": yes";
|
||||
} else {
|
||||
summary += ": no";
|
||||
}
|
||||
summary += "\n";
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
static const std::string FEATURE_HTTPS;
|
||||
static const std::string FEATURE_BITTORRENT;
|
||||
static const std::string FEATURE_METALINK;
|
||||
static const std::string FEATURE_MESSAGE_DIGEST;
|
||||
static const std::string FEATURE_ASYNC_DNS;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -434,7 +434,6 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
delete op;
|
||||
LogFactory::release();
|
||||
FeatureConfig::release();
|
||||
return exitStatus;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "messageDigest.h"
|
||||
#include "Util.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -64,4 +65,14 @@ std::string MessageDigestContext::digestFinal()
|
|||
return rawMDString;
|
||||
}
|
||||
|
||||
std::string MessageDigestContext::getSupportedAlgoString()
|
||||
{
|
||||
std::string algos;
|
||||
for(DigestAlgoMap::const_iterator itr = digestAlgos.begin();
|
||||
itr != digestAlgos.end(); ++itr) {
|
||||
algos += (*itr).first+", ";
|
||||
}
|
||||
return Util::trim(algos, ", ");
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -105,15 +105,7 @@ public:
|
|||
return (*itr).second;
|
||||
}
|
||||
|
||||
static std::string getSupportedAlgoString()
|
||||
{
|
||||
std::string algos;
|
||||
for(DigestAlgoMap::const_iterator itr = digestAlgos.begin();
|
||||
itr != digestAlgos.end(); ++itr) {
|
||||
algos += (*itr).first+" ";
|
||||
}
|
||||
return algos;
|
||||
}
|
||||
static std::string getSupportedAlgoString();
|
||||
|
||||
static size_t digestLength(const std::string& algostring)
|
||||
{
|
||||
|
|
|
@ -56,39 +56,17 @@ void showVersion() {
|
|||
<< "Copyright (C) 2006, 2008 Tatsuhiro Tsujikawa" << "\n"
|
||||
<< "\n"
|
||||
<<
|
||||
_("This program is free software; you can redistribute it and/or modify\n"
|
||||
"it under the terms of the GNU General Public License as published by\n"
|
||||
"the Free Software Foundation; either version 2 of the License, or\n"
|
||||
"(at your option) any later version.\n"
|
||||
"\n"
|
||||
"This program is distributed in the hope that it will be useful,\n"
|
||||
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
||||
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
||||
"GNU General Public License for more details.\n"
|
||||
"\n"
|
||||
"You should have received a copy of the GNU General Public License\n"
|
||||
"along with this program; if not, write to the Free Software\n"
|
||||
"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n")
|
||||
<< "\n"
|
||||
|
||||
<<
|
||||
"In addition, as a special exception, the copyright holders give\n"
|
||||
"permission to link the code of portions of this program with the\n"
|
||||
"OpenSSL library under certain conditions as described in each\n"
|
||||
"individual source file, and distribute linked combinations\n"
|
||||
"including the two.\n"
|
||||
"You must obey the GNU General Public License in all respects\n"
|
||||
"for all of the code used other than OpenSSL. If you modify\n"
|
||||
"file(s) with this exception, you may extend this exception to your\n"
|
||||
"version of the file(s), but you are not obligated to do so. If you\n"
|
||||
"do not wish to do so, delete this exception statement from your\n"
|
||||
"version. If you delete this exception statement from all source\n"
|
||||
"files in the program, then also delete it here.\n"
|
||||
<< "\n"
|
||||
<< "** Configuration **" << "\n"
|
||||
<< FeatureConfig::getInstance()->getConfigurationSummary()
|
||||
<< "Enabled Features: "
|
||||
<< FeatureConfig::getInstance()->featureSummary() << "\n"
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
<< "message digest algorithms: " << MessageDigestContext::getSupportedAlgoString() << "\n"
|
||||
<< "Hash Algorithms: "
|
||||
<< MessageDigestContext::getSupportedAlgoString() << "\n"
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
<< "\n"
|
||||
<< StringFormat(_("Report bugs to %s"), "<tujikawa at users dot sourceforge dot net>")
|
||||
|
|
|
@ -8,13 +8,13 @@ class FeatureConfigTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST_SUITE(FeatureConfigTest);
|
||||
CPPUNIT_TEST(testGetDefaultPort);
|
||||
CPPUNIT_TEST(testIsSupported);
|
||||
CPPUNIT_TEST(testGetConfigurationSummary);
|
||||
CPPUNIT_TEST(testFeatureSummary);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void testGetDefaultPort();
|
||||
void testIsSupported();
|
||||
void testGetConfigurationSummary();
|
||||
void testFeatureSummary();
|
||||
};
|
||||
|
||||
|
||||
|
@ -30,51 +30,48 @@ void FeatureConfigTest::testGetDefaultPort() {
|
|||
}
|
||||
|
||||
void FeatureConfigTest::testIsSupported() {
|
||||
CPPUNIT_ASSERT_EQUAL(true,
|
||||
FeatureConfig::getInstance()->isSupported("http"));
|
||||
#ifdef ENABLE_SSL
|
||||
CPPUNIT_ASSERT_EQUAL(true,
|
||||
FeatureConfig::getInstance()->isSupported("https"));
|
||||
FeatureConfig::getInstance()->isSupported
|
||||
(FeatureConfig::FEATURE_HTTPS));
|
||||
#else
|
||||
CPPUNIT_ASSERT_EQUAL(false,
|
||||
FeatureConfig::getInstance()->isSupported("https"));
|
||||
FeatureConfig::getInstance()->isSupported
|
||||
(FeatureConfig::FEATURE_HTTPS));
|
||||
#endif // ENABLE_SSL
|
||||
CPPUNIT_ASSERT_EQUAL(true,
|
||||
FeatureConfig::getInstance()->isSupported("ftp"));
|
||||
CPPUNIT_ASSERT_EQUAL(false,
|
||||
FeatureConfig::getInstance()->isSupported("ftps"));
|
||||
FeatureConfig::getInstance()->isSupported("FTPS"));
|
||||
}
|
||||
|
||||
void FeatureConfigTest::testGetConfigurationSummary() {
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http: yes\n")
|
||||
#ifdef ENABLE_SSL
|
||||
+"https: yes\n"
|
||||
#else
|
||||
+"https: no\n"
|
||||
#endif // ENABLE_SSL
|
||||
+"ftp: yes\n"
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
+"bittorrent: yes\n"
|
||||
#else
|
||||
+"bittorrent: no\n"
|
||||
#endif // ENABLE_BITTORRENT
|
||||
#ifdef ENABLE_METALINK
|
||||
+"metalink: yes\n"
|
||||
#else
|
||||
+"metalink: no\n"
|
||||
#endif // ENABLE_METALINK
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
+"message digest: yes\n"
|
||||
#else
|
||||
+"message digest: no\n"
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
void FeatureConfigTest::testFeatureSummary() {
|
||||
CPPUNIT_ASSERT_EQUAL(
|
||||
#ifdef ENABLE_ASYNC_DNS
|
||||
+"async dns: yes\n"
|
||||
std::string("Async DNS, ")
|
||||
#else
|
||||
+"async dns: no\n"
|
||||
std::string()
|
||||
#endif // ENABLE_ASYNC_DNS
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
+std::string("BitTorrent, ")
|
||||
#else
|
||||
+std::string()
|
||||
#endif // ENABLE_BITTORRENT
|
||||
#ifdef ENABLE_SSL
|
||||
+std::string("HTTPS, ")
|
||||
#else
|
||||
+std::string()
|
||||
#endif // ENABLE_SSL
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
+std::string("Message Digest, ")
|
||||
#else
|
||||
+std::string()
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
#ifdef ENABLE_METALINK
|
||||
+std::string("Metalink")
|
||||
#else
|
||||
+std::string()
|
||||
#endif // ENABLE_METALINK
|
||||
,
|
||||
FeatureConfig::getInstance()->getConfigurationSummary());
|
||||
FeatureConfig::getInstance()->featureSummary());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
Loading…
Reference in New Issue