* Allow certain commands, like schedule and on_* to take unquoted

multi-arg commands. So "on_start = link1,create_link=tied,,.started"
now works again.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@879 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-03-27 15:45:18 +00:00
parent ee6eae6c84
commit 3bd0d6fb27
3 changed files with 78 additions and 10 deletions
+69 -4
View File
@@ -184,17 +184,82 @@ convert_list_to_string(const torrent::Object& src) {
if (!src.is_list())
throw torrent::internal_error("convert_list_to_string(...) !src->is_list().");
return convert_list_to_string(src.as_list().begin(), src.as_list().end());
}
std::string
convert_list_to_string(torrent::Object::list_type::const_iterator first,
torrent::Object::list_type::const_iterator last) {
std::string dest;
for (torrent::Object::list_type::const_iterator itr = src.as_list().begin(), last = src.as_list().end(); itr != last; itr++) {
if (!itr->is_string())
while (first != last) {
if (!first->is_string())
throw torrent::input_error("Could not convert non-string list element to string.");
// Meh.
if (!dest.empty())
dest += ",";
dest += ",\"";
else
dest += '"';
dest += itr->as_string();
std::string::size_type quoteItr = dest.size();
dest += first->as_string();
// Finding a quote inside the string should be relatively rare, so
// use something that is fast in the general case and ignore the
// cost of the unusual one.
while (quoteItr != dest.size()) {
if (dest[quoteItr] == '"' || dest[quoteItr] == '\\')
dest.insert(quoteItr++, 1, '\\');
quoteItr++;
}
dest += '"';
first++;
}
return dest;
}
std::string
convert_list_to_command(torrent::Object::list_type::const_iterator first,
torrent::Object::list_type::const_iterator last) {
if (first == last)
throw torrent::input_error("Too few arguments.");
std::string dest = (first++)->as_string();
std::string::size_type quoteItr = dest.find('=');
if (quoteItr == std::string::npos)
throw torrent::input_error("Could not find '=' in command.");
// We should only escape backslash, not quote here as the string
// will start with the command name which isn't quoted.
while ((quoteItr = dest.find('\\', quoteItr + 1)) != std::string::npos)
dest.insert(quoteItr++, 1, '\\');
while (first != last) {
if (!first->is_string())
throw torrent::input_error("Could not convert non-string list element to string.");
dest += ",\"";
std::string::size_type quoteItr = dest.size();
dest += first->as_string();
// Finding a quote inside the string should be relatively rare, so
// use something that is fast in the general case and ignore the
// cost of the unusual one.
while (quoteItr != dest.size()) {
if (dest[quoteItr] == '"' || dest[quoteItr] == '\\')
dest.insert(quoteItr++, 1, '\\');
quoteItr++;
}
dest += '"';
first++;
}
return dest;
+3
View File
@@ -61,6 +61,9 @@ const char* parse_list(const char* first, const char* last, torrent::Object* des
const char* parse_whole_list(const char* first, const char* last, torrent::Object* dest);
std::string convert_list_to_string(const torrent::Object& src);
std::string convert_list_to_string(torrent::Object::list_type::const_iterator first, torrent::Object::list_type::const_iterator last);
std::string convert_list_to_command(torrent::Object::list_type::const_iterator first, torrent::Object::list_type::const_iterator last);
int64_t convert_to_value(const torrent::Object& src, int base = 0, int unit = 1);
}