Don't return hidden option from DownloadHandle::getOption and getGlobalOption

pull/92/head
Tatsuhiro Tsujikawa 2013-05-17 23:06:34 +09:00
parent 45506573a8
commit c688f51f2e
2 changed files with 16 additions and 3 deletions

View File

@ -481,7 +481,12 @@ const std::string& getGlobalOption(Session* session, const std::string& name)
{
const SharedHandle<DownloadEngine>& e =
session->context->reqinfo->getDownloadEngine();
return e->getOption()->get(option::k2p(name));
const Pref* pref = option::k2p(name);
if(OptionParser::getInstance()->find(pref)) {
return e->getOption()->get(pref);
} else {
return A2STR::NIL;
}
}
KeyVals getGlobalOptions(Session* session)
@ -776,7 +781,12 @@ struct RequestGroupDH : public DownloadHandle {
}
virtual const std::string& getOption(const std::string& name)
{
return group->getOption()->get(option::k2p(name));
const Pref* pref = option::k2p(name);
if(OptionParser::getInstance()->find(pref)) {
return group->getOption()->get(pref);
} else {
return A2STR::NIL;
}
}
virtual KeyVals getOptions()
{

View File

@ -179,6 +179,8 @@ void Aria2ApiTest::testChangeOption()
CPPUNIT_ASSERT(std::find(retopts.begin(), retopts.end(),
KeyVals::value_type("dir", "mydownload"))
!= retopts.end());
// Don't return hidden option
CPPUNIT_ASSERT(hd->getOption(PREF_STARTUP_IDLE_TIME->k).empty());
deleteDownloadHandle(hd);
// failure with null gid
CPPUNIT_ASSERT_EQUAL(-1, changeOption(session_, (A2Gid)0, options));
@ -205,7 +207,8 @@ void Aria2ApiTest::testChangeGlobalOption()
CPPUNIT_ASSERT_EQUAL(0, changeGlobalOption(session_, options));
CPPUNIT_ASSERT_EQUAL(std::string("none"),
getGlobalOption(session_, PREF_FILE_ALLOCATION->k));
// Don't return hidden option
CPPUNIT_ASSERT(getGlobalOption(session_, PREF_STARTUP_IDLE_TIME->k).empty());
// failure with bad option value
options.clear();
options.push_back(KeyVals::value_type(PREF_FILE_ALLOCATION->k, "foo"));