summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/RpcMethodImpl.cc65
-rw-r--r--src/RpcMethodImpl.h2
-rw-r--r--src/aria2api.cc50
-rw-r--r--src/includes/aria2/aria2.h49
4 files changed, 135 insertions, 31 deletions
diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc
index 1142c445..dcf1c84d 100644
--- a/src/RpcMethodImpl.cc
+++ b/src/RpcMethodImpl.cc
@@ -1112,37 +1112,7 @@ SharedHandle<ValueBase> ChangeGlobalOptionRpcMethod::process
Option option;
gatherChangeableGlobalOption(&option, optsParam);
- e->getOption()->merge(option);
-
- if(option.defined(PREF_MAX_OVERALL_DOWNLOAD_LIMIT)) {
- e->getRequestGroupMan()->setMaxOverallDownloadSpeedLimit
- (option.getAsInt(PREF_MAX_OVERALL_DOWNLOAD_LIMIT));
- }
- if(option.defined(PREF_MAX_OVERALL_UPLOAD_LIMIT)) {
- e->getRequestGroupMan()->setMaxOverallUploadSpeedLimit
- (option.getAsInt(PREF_MAX_OVERALL_UPLOAD_LIMIT));
- }
- if(option.defined(PREF_MAX_CONCURRENT_DOWNLOADS)) {
- e->getRequestGroupMan()->setMaxSimultaneousDownloads
- (option.getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS));
- e->getRequestGroupMan()->requestQueueCheck();
- }
- if(option.defined(PREF_MAX_DOWNLOAD_RESULT)) {
- e->getRequestGroupMan()->setMaxDownloadResult
- (option.getAsInt(PREF_MAX_DOWNLOAD_RESULT));
- }
- if(option.defined(PREF_LOG_LEVEL)) {
- LogFactory::setLogLevel(option.get(PREF_LOG_LEVEL));
- }
- if(option.defined(PREF_LOG)) {
- LogFactory::setLogFile(option.get(PREF_LOG));
- try {
- LogFactory::reconfigure();
- } catch(RecoverableException& e) {
- // TODO no exception handling
- }
- }
-
+ changeGlobalOption(option, e);
return VLB_OK;
}
@@ -1542,4 +1512,37 @@ void changeOption
#endif // ENABLE_BITTORRENT
}
+void changeGlobalOption(const Option& option, DownloadEngine* e)
+{
+ e->getOption()->merge(option);
+ if(option.defined(PREF_MAX_OVERALL_DOWNLOAD_LIMIT)) {
+ e->getRequestGroupMan()->setMaxOverallDownloadSpeedLimit
+ (option.getAsInt(PREF_MAX_OVERALL_DOWNLOAD_LIMIT));
+ }
+ if(option.defined(PREF_MAX_OVERALL_UPLOAD_LIMIT)) {
+ e->getRequestGroupMan()->setMaxOverallUploadSpeedLimit
+ (option.getAsInt(PREF_MAX_OVERALL_UPLOAD_LIMIT));
+ }
+ if(option.defined(PREF_MAX_CONCURRENT_DOWNLOADS)) {
+ e->getRequestGroupMan()->setMaxSimultaneousDownloads
+ (option.getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS));
+ e->getRequestGroupMan()->requestQueueCheck();
+ }
+ if(option.defined(PREF_MAX_DOWNLOAD_RESULT)) {
+ e->getRequestGroupMan()->setMaxDownloadResult
+ (option.getAsInt(PREF_MAX_DOWNLOAD_RESULT));
+ }
+ if(option.defined(PREF_LOG_LEVEL)) {
+ LogFactory::setLogLevel(option.get(PREF_LOG_LEVEL));
+ }
+ if(option.defined(PREF_LOG)) {
+ LogFactory::setLogFile(option.get(PREF_LOG));
+ try {
+ LogFactory::reconfigure();
+ } catch(RecoverableException& e) {
+ // TODO no exception handling
+ }
+ }
+}
+
} // namespace aria2
diff --git a/src/RpcMethodImpl.h b/src/RpcMethodImpl.h
index b1b254b5..72baf438 100644
--- a/src/RpcMethodImpl.h
+++ b/src/RpcMethodImpl.h
@@ -613,6 +613,8 @@ void changeOption
const Option& option,
DownloadEngine* e);
+void changeGlobalOption(const Option& option, DownloadEngine* e);
+
} // namespace aria2
#endif // D_RPC_METHOD_IMPL_H
diff --git a/src/aria2api.cc b/src/aria2api.cc
index 069bb12a..c7504941 100644
--- a/src/aria2api.cc
+++ b/src/aria2api.cc
@@ -247,6 +247,17 @@ void apiGatherChangeableOptionForReserved
} // namespace
namespace {
+void apiGatherChangeableGlobalOption
+(Option* option, const KeyVals& options,
+ const SharedHandle<OptionParser>& optionParser)
+{
+ apiGatherOption(options.begin(), options.end(),
+ std::mem_fun(&OptionHandler::getChangeGlobalOption),
+ option, optionParser);
+}
+} // namespace
+
+namespace {
void addRequestGroup(const SharedHandle<RequestGroup>& group,
const SharedHandle<DownloadEngine>& e,
int position)
@@ -466,6 +477,45 @@ int changeOption(Session* session, const A2Gid& gid, const KeyVals& options)
}
}
+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));
+}
+
+KeyVals getGlobalOptions(Session* session)
+{
+ const SharedHandle<DownloadEngine>& e =
+ session->context->reqinfo->getDownloadEngine();
+ const SharedHandle<OptionParser>& optionParser = OptionParser::getInstance();
+ const Option* option = e->getOption();
+ KeyVals options;
+ for(size_t i = 1, len = option::countOption(); i < len; ++i) {
+ const Pref* pref = option::i2p(i);
+ if(option->defined(pref) && optionParser->find(pref)) {
+ options.push_back(KeyVals::value_type(pref->k, option->get(pref)));
+ }
+ }
+ return options;
+}
+
+int changeGlobalOption(Session* session, const KeyVals& options)
+{
+ const SharedHandle<DownloadEngine>& e =
+ session->context->reqinfo->getDownloadEngine();
+ Option option;
+ try {
+ apiGatherChangeableGlobalOption(&option, options,
+ OptionParser::getInstance());
+ } catch(RecoverableException& err) {
+ A2_LOG_INFO_EX(EX_EXCEPTION_CAUGHT, err);
+ return -1;
+ }
+ changeGlobalOption(option, e.get());
+ return 0;
+}
+
std::vector<A2Gid> getActiveDownload(Session* session)
{
const SharedHandle<DownloadEngine>& e =
diff --git a/src/includes/aria2/aria2.h b/src/includes/aria2/aria2.h
index c1a4b637..7328d2c0 100644
--- a/src/includes/aria2/aria2.h
+++ b/src/includes/aria2/aria2.h
@@ -437,6 +437,55 @@ int unpauseDownload(Session* session, const A2Gid& gid);
int changeOption(Session* session, const A2Gid& gid, const KeyVals& options);
/**
+ * @function
+ *
+ * Returns global option denoted by the |name|. If such option is not
+ * available, returns empty string.
+ */
+const std::string& getGlobalOption(Session* session, const std::string& name);
+
+/**
+ * @function
+ *
+ * Returns global options. Note that this function does not return
+ * options which have no default value and have not been set by
+ * :func:`sessionNew()`, configuration files or API functions.
+ */
+KeyVals getGlobalOptions(Session* session);
+
+/**
+ * @function
+ *
+ * Apply global options in the |options| dynamically. The following
+ * options are available:
+ *
+ * * :option:`download-result <--download-result>`
+ * * :option:`log <-l>`
+ * * :option:`log-level <--log-level>`
+ * * :option:`max-concurrent-downloads <-j>`
+ * * :option:`max-download-result <--max-download-result>`
+ * * :option:`max-overall-download-limit <--max-overall-download-limit>`
+ * * :option:`max-overall-upload-limit <--max-overall-upload-limit>`
+ * * :option:`save-cookies <--save-cookies>`
+ * * :option:`save-session <--save-session>`
+ * * :option:`server-stat-of <--server-stat-of>`
+ *
+ * In addition to them, options listed in :ref:`input-file` subsection
+ * are available, except for following options:
+ * :option:`checksum <--checksum>`,
+ * :option:`index-out <-O>`,
+ * :option:`out <-o>`,
+ * :option:`pause <--pause>` and
+ * :option:`select-file <--select-file>`.
+ *
+ * The options which are not applicable or unknown, they are just
+ * ignored.
+ *
+ * This function returns 0 if it succeeds, or negative error code.
+ */
+int changeGlobalOption(Session* session, const KeyVals& options);
+
+/**
* @enum
*
* Constants how to re-position a download.