2006-02-17 13:35:04 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-02-17 13:35:04 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-09-21 15:31:24 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
2006-02-17 13:35:04 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "Option.h"
|
2006-08-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/Option.h
(getAsBool): New function.
* src/Option.cc
(prefs.h): Included.
(defined): 0-length value is now recognized as undefined.
(getAsInt): Rewritten.
(getAsLLInt): Rewritten.
(getAsBool): New function.
* src/FeatureConfig.h: Rewritten.
* src/FeatureConfig.cc: Rewritten.
* src/prefs.h
(PREF_STDOUT_LOG): New definition.
(PREF_LOG): New definition.
(PREF_DIR): New definition.
(PREF_OUT): New definition.
(PREF_SPLIT): New definition.
(PREF_DAEMON): New definition.
(PREF_REFERER): New definition.
(PREF_TORRENT_FILE): New definition.
(PREF_LISTEN_PORT): New definition.
(PREF_METALINK_FILE): New definition.
(PREF_METALINK_VERSION): New definition.
(PREF_METALINK_LANGUAGE): New definition.
(PREF_METALINK_OS): New definition.
(PREF_METALINK_SERVERS): New definition.
* src/main.cc
(main): Following command-line parameters are now put into
Option
class: stdoutLog, logfile, dir, ufilename, split, daemonMode,
referer, torrentFile, metalinkFile, listenPort, metalinkVersion,
metalinkLanguage, metalinkOs, metalinkServers
To fix the bug that aria2 can not handle http response header
properly.
* src/HttpHeader.cc
(put): Made name lowercased.
(defined): Made name lowercased.
(getFirst): Made name lowercased.
(get): Made name lowercased.
(getFirstAsInt): Rewritten.
(getFirstAsLLInt): Rewritten.
2006-08-03 12:36:02 +00:00
|
|
|
#include "prefs.h"
|
2008-05-13 14:15:23 +00:00
|
|
|
#include "A2STR.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <cstdlib>
|
2008-05-18 10:14:53 +00:00
|
|
|
#include <cstring>
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
2006-02-17 13:35:04 +00:00
|
|
|
|
|
|
|
Option::Option() {}
|
|
|
|
|
|
|
|
Option::~Option() {}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void Option::put(const std::string& name, const std::string& value) {
|
2006-02-17 13:35:04 +00:00
|
|
|
table[name] = value;
|
|
|
|
}
|
|
|
|
|
2008-12-04 13:05:05 +00:00
|
|
|
bool Option::defined(const std::string& name) const
|
|
|
|
{
|
2006-02-17 13:35:04 +00:00
|
|
|
return table.count(name) == 1;
|
|
|
|
}
|
|
|
|
|
2008-12-04 13:05:05 +00:00
|
|
|
bool Option::blank(const std::string& name) const
|
|
|
|
{
|
|
|
|
std::map<std::string, std::string>::const_iterator i = table.find(name);
|
|
|
|
return i == table.end() || (*i).second.empty();
|
|
|
|
}
|
|
|
|
|
2008-05-18 10:14:53 +00:00
|
|
|
const std::string& Option::get(const std::string& name) const {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::map<std::string, std::string>::const_iterator itr = table.find(name);
|
2006-02-17 13:35:04 +00:00
|
|
|
if(itr == table.end()) {
|
2008-05-13 14:15:23 +00:00
|
|
|
return A2STR::NIL;
|
2006-02-17 13:35:04 +00:00
|
|
|
} else {
|
|
|
|
return (*itr).second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
int32_t Option::getAsInt(const std::string& name) const {
|
2008-05-18 10:14:53 +00:00
|
|
|
const std::string& value = get(name);
|
2008-05-13 14:15:23 +00:00
|
|
|
if(value.empty()) {
|
2006-02-17 13:35:04 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
2008-05-18 10:14:53 +00:00
|
|
|
return strtol(value.c_str(), 0, 10);
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-22 11:18:47 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
int64_t Option::getAsLLInt(const std::string& name) const {
|
2008-05-18 10:14:53 +00:00
|
|
|
const std::string& value = get(name);
|
2008-05-13 14:15:23 +00:00
|
|
|
if(value.empty()) {
|
2006-02-22 11:18:47 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
2008-05-18 10:14:53 +00:00
|
|
|
return strtoll(value.c_str(), 0, 10);
|
2006-08-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/Option.h
(getAsBool): New function.
* src/Option.cc
(prefs.h): Included.
(defined): 0-length value is now recognized as undefined.
(getAsInt): Rewritten.
(getAsLLInt): Rewritten.
(getAsBool): New function.
* src/FeatureConfig.h: Rewritten.
* src/FeatureConfig.cc: Rewritten.
* src/prefs.h
(PREF_STDOUT_LOG): New definition.
(PREF_LOG): New definition.
(PREF_DIR): New definition.
(PREF_OUT): New definition.
(PREF_SPLIT): New definition.
(PREF_DAEMON): New definition.
(PREF_REFERER): New definition.
(PREF_TORRENT_FILE): New definition.
(PREF_LISTEN_PORT): New definition.
(PREF_METALINK_FILE): New definition.
(PREF_METALINK_VERSION): New definition.
(PREF_METALINK_LANGUAGE): New definition.
(PREF_METALINK_OS): New definition.
(PREF_METALINK_SERVERS): New definition.
* src/main.cc
(main): Following command-line parameters are now put into
Option
class: stdoutLog, logfile, dir, ufilename, split, daemonMode,
referer, torrentFile, metalinkFile, listenPort, metalinkVersion,
metalinkLanguage, metalinkOs, metalinkServers
To fix the bug that aria2 can not handle http response header
properly.
* src/HttpHeader.cc
(put): Made name lowercased.
(defined): Made name lowercased.
(getFirst): Made name lowercased.
(get): Made name lowercased.
(getFirstAsInt): Rewritten.
(getFirstAsLLInt): Rewritten.
2006-08-03 12:36:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
bool Option::getAsBool(const std::string& name) const {
|
2008-05-19 10:25:38 +00:00
|
|
|
return get(name) == V_TRUE;
|
2006-02-22 11:18:47 +00:00
|
|
|
}
|
2006-08-27 12:49:17 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
double Option::getAsDouble(const std::string& name) const {
|
2008-05-18 10:14:53 +00:00
|
|
|
const std::string& value = get(name);
|
2008-05-13 14:15:23 +00:00
|
|
|
if(value.empty()) {
|
2006-08-27 12:49:17 +00:00
|
|
|
return 0.0;
|
|
|
|
} else {
|
|
|
|
return strtod(value.c_str(), 0);
|
|
|
|
}
|
|
|
|
}
|
2007-03-26 12:16:57 +00:00
|
|
|
|
|
|
|
void Option::clear()
|
|
|
|
{
|
|
|
|
table.clear();
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|