mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-07 02:32:32 +00:00
* Fixed a bug that caused 'execute*' commands to fail when trying to run a program without any arguments.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1187 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+4
-4
@@ -54,7 +54,7 @@ namespace rpc {
|
||||
template <typename T> const torrent::Object
|
||||
command_base_call(command_base* rawCommand, target_type target, const torrent::Object& args) {
|
||||
if (!is_target_compatible<T>(target))
|
||||
throw torrent::input_error("Target of wrong type.");
|
||||
throw torrent::input_error("Target of wrong type to command.");
|
||||
|
||||
return command_base::_call<typename command_function<T>::type, T>(rawCommand, target, args);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ COMMAND_BASE_TEMPLATE_DEFINE(command_base_call);
|
||||
template <typename T> const torrent::Object
|
||||
command_base_call_value_base(command_base* rawCommand, target_type target, const torrent::Object& rawArgs, int base, int unit) {
|
||||
if (!is_target_compatible<T>(target))
|
||||
throw torrent::input_error("Target of wrong type.");
|
||||
throw torrent::input_error("Target of wrong type to command.");
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
@@ -96,7 +96,7 @@ COMMAND_BASE_TEMPLATE_DEFINE(command_base_call_value_kb);
|
||||
template <typename T> const torrent::Object
|
||||
command_base_call_string(command_base* rawCommand, target_type target, const torrent::Object& rawArgs) {
|
||||
if (!is_target_compatible<T>(target))
|
||||
throw torrent::input_error("Target of wrong type.");
|
||||
throw torrent::input_error("Target of wrong type to command.");
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
@@ -111,7 +111,7 @@ COMMAND_BASE_TEMPLATE_DEFINE(command_base_call_string);
|
||||
template <typename T> const torrent::Object
|
||||
command_base_call_list(command_base* rawCommand, target_type target, const torrent::Object& rawArgs) {
|
||||
if (!is_target_compatible<T>(target))
|
||||
throw torrent::input_error("Target of wrong type.");
|
||||
throw torrent::input_error("Target of wrong type to command.");
|
||||
|
||||
if (rawArgs.type() != torrent::Object::TYPE_LIST) {
|
||||
torrent::Object::list_type arg;
|
||||
|
||||
+27
-13
@@ -161,25 +161,39 @@ ExecFile::execute_object(const torrent::Object& rawArgs, int flags) {
|
||||
char valueBuffer[buffer_size];
|
||||
char* valueCurrent = valueBuffer;
|
||||
|
||||
const torrent::Object::list_type& args = rawArgs.as_list();
|
||||
if (rawArgs.is_list()) {
|
||||
const torrent::Object::list_type& args = rawArgs.as_list();
|
||||
|
||||
if (args.empty())
|
||||
throw torrent::input_error("Too few arguments.");
|
||||
if (args.empty())
|
||||
throw torrent::input_error("Too few arguments.");
|
||||
|
||||
for (torrent::Object::list_const_iterator itr = args.begin(), last = args.end(); itr != last; itr++, argsCurrent++) {
|
||||
if (argsCurrent == argsBuffer + max_args - 1)
|
||||
throw torrent::input_error("Too many arguments.");
|
||||
for (torrent::Object::list_const_iterator itr = args.begin(), last = args.end(); itr != last; itr++, argsCurrent++) {
|
||||
if (argsCurrent == argsBuffer + max_args - 1)
|
||||
throw torrent::input_error("Too many arguments.");
|
||||
|
||||
if (itr->is_string() && (!(flags & flag_expand_tilde) || *itr->as_string().c_str() != '~')) {
|
||||
*argsCurrent = const_cast<char*>(itr->as_string().c_str());
|
||||
if (itr->is_string() && (!(flags & flag_expand_tilde) || *itr->as_string().c_str() != '~')) {
|
||||
*argsCurrent = const_cast<char*>(itr->as_string().c_str());
|
||||
|
||||
} else {
|
||||
} else {
|
||||
*argsCurrent = valueCurrent;
|
||||
valueCurrent = print_object(valueCurrent, valueBuffer + buffer_size, &*itr, flags) + 1;
|
||||
|
||||
if (valueCurrent >= valueBuffer + buffer_size)
|
||||
throw torrent::input_error("Overflowed execute arg buffer.");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
const torrent::Object::string_type& args = rawArgs.as_string();
|
||||
|
||||
if ((flags & flag_expand_tilde) && args.c_str()[0] == '~') {
|
||||
*argsCurrent = valueCurrent;
|
||||
valueCurrent = print_object(valueCurrent, valueBuffer + buffer_size, &*itr, flags) + 1;
|
||||
valueCurrent = print_object(valueCurrent, valueBuffer + buffer_size, &rawArgs, flags) + 1;
|
||||
} else {
|
||||
*argsCurrent = const_cast<char*>(args.c_str());
|
||||
}
|
||||
|
||||
if (valueCurrent >= valueBuffer + buffer_size)
|
||||
throw torrent::input_error("Overflowed execute arg buffer.");
|
||||
}
|
||||
argsCurrent++;
|
||||
}
|
||||
|
||||
*argsCurrent = NULL;
|
||||
|
||||
Reference in New Issue
Block a user