Browse Source

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

Tatsuhiro Tsujikawa 12 years ago
parent
commit
c688f51f2e
2 changed files with 16 additions and 3 deletions
  1. 12 2
      src/aria2api.cc
  2. 4 1
      test/Aria2ApiTest.cc

+ 12 - 2
src/aria2api.cc

@@ -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()
   {

+ 4 - 1
test/Aria2ApiTest.cc

@@ -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"));