* Added support for XMLRPC_TYPE_BASE64.

* Added 'load_raw*' commands for loading torrents directly from the
data passed through the first argument.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@964 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-08-24 12:30:29 +00:00
parent 85d14f0e96
commit c6a43429a2
7 changed files with 58 additions and 17 deletions
+4 -1
View File
@@ -349,7 +349,10 @@ initialize_command_events() {
ADD_COMMAND_LIST("load", rak::bind_ptr_fn(&apply_load, core::Manager::create_quiet | core::Manager::create_tied));
ADD_COMMAND_LIST("load_verbose", rak::bind_ptr_fn(&apply_load, core::Manager::create_tied));
ADD_COMMAND_LIST("load_start", rak::bind_ptr_fn(&apply_load, core::Manager::create_quiet | core::Manager::create_tied | core::Manager::create_start));
ADD_COMMAND_LIST("load_start_verbose", rak::bind_ptr_fn(&apply_load, core::Manager::create_tied | core::Manager::create_start));
ADD_COMMAND_LIST("load_start_verbose", rak::bind_ptr_fn(&apply_load, core::Manager::create_tied | core::Manager::create_start));
ADD_COMMAND_LIST("load_raw", rak::bind_ptr_fn(&apply_load, core::Manager::create_quiet | core::Manager::create_raw_data));
ADD_COMMAND_LIST("load_raw_verbose", rak::bind_ptr_fn(&apply_load, core::Manager::create_raw_data));
ADD_COMMAND_LIST("load_raw_start", rak::bind_ptr_fn(&apply_load, core::Manager::create_quiet | core::Manager::create_start | core::Manager::create_raw_data));
ADD_COMMAND_VALUE_UN("close_low_diskspace", std::ptr_fun(&apply_close_low_diskspace));
+14 -4
View File
@@ -61,13 +61,12 @@
namespace core {
DownloadFactory::DownloadFactory(const std::string& uri, Manager* m) :
DownloadFactory::DownloadFactory(Manager* m) :
m_manager(m),
m_stream(NULL),
m_commited(false),
m_loaded(false),
m_uri(uri),
m_session(false),
m_start(false),
m_printLog(true) {
@@ -90,10 +89,21 @@ DownloadFactory::~DownloadFactory() {
}
void
DownloadFactory::load() {
DownloadFactory::load(const std::string& uri) {
m_uri = uri;
priority_queue_insert(&taskScheduler, &m_taskLoad, cachedTime);
}
// This function must be called before DownloadFactory::commit().
void
DownloadFactory::load_raw_data(const std::string& input) {
if (m_stream)
throw torrent::internal_error("DownloadFactory::load*() called on an object with m_stream != NULL");
m_stream = new std::stringstream(input);
m_loaded = true;
}
void
DownloadFactory::commit() {
priority_queue_insert(&taskScheduler, &m_taskCommit, cachedTime);
@@ -102,7 +112,7 @@ DownloadFactory::commit() {
void
DownloadFactory::receive_load() {
if (m_stream)
throw torrent::internal_error("DownloadFactory::load() called on an object with m_stream != NULL");
throw torrent::internal_error("DownloadFactory::load*() called on an object with m_stream != NULL");
if (std::strncmp(m_uri.c_str(), "http://", 7) == 0 ||
std::strncmp(m_uri.c_str(), "https://", 8) == 0 ||
+3 -2
View File
@@ -58,13 +58,14 @@ public:
typedef std::vector<std::string> command_list_type;
// Do not destroy this object while it is in a HttpQueue.
DownloadFactory(const std::string& uri, Manager* m);
DownloadFactory(Manager* m);
~DownloadFactory();
// Calling of receive_load() is delayed so you can change whatever
// you want without fear of the slots being triggered as you call
// load() or commit().
void load();
void load(const std::string& uri);
void load_raw_data(const std::string& input);
void commit();
command_list_type& commands() { return m_commands; }
+12 -2
View File
@@ -397,7 +397,7 @@ Manager::receive_http_failed(std::string msg) {
void
Manager::try_create_download(const std::string& uri, int flags, const command_list_type& commands) {
// Adding download.
DownloadFactory* f = new DownloadFactory(uri, this);
DownloadFactory* f = new DownloadFactory(this);
f->variables()["tied_to_file"] = (int64_t)(bool)(flags & create_tied);
f->commands().insert(f->commands().end(), commands.begin(), commands.end());
@@ -405,7 +405,12 @@ Manager::try_create_download(const std::string& uri, int flags, const command_li
f->set_start(flags & create_start);
f->set_print_log(!(flags & create_quiet));
f->slot_finished(sigc::bind(sigc::ptr_fun(&rak::call_delete_func<core::DownloadFactory>), f));
f->load();
if (flags & create_raw_data)
f->load_raw_data(uri);
else
f->load(uri);
f->commit();
}
@@ -465,6 +470,11 @@ manager_equal_tied(const std::string& path, Download* download) {
void
Manager::try_create_download_expand(const std::string& uri, int flags, command_list_type commands) {
if (flags & create_raw_data) {
try_create_download(uri, flags, commands);
return;
}
std::vector<std::string> paths;
paths.reserve(256);
+4 -3
View File
@@ -99,9 +99,10 @@ public:
void handshake_log(const sockaddr* sa, int msg, int err, const torrent::HashString* hash);
static const int create_start = 0x1;
static const int create_tied = 0x2;
static const int create_quiet = 0x4;
static const int create_start = 0x1;
static const int create_tied = 0x2;
static const int create_quiet = 0x4;
static const int create_raw_data = 0x8;
typedef std::vector<std::string> command_list_type;
+4 -4
View File
@@ -103,12 +103,12 @@ load_session_torrents(Control* c) {
std::list<std::string> l = c->core()->download_store()->get_formated_entries().make_list();
for (std::list<std::string>::iterator first = l.begin(), last = l.end(); first != last; ++first) {
core::DownloadFactory* f = new core::DownloadFactory(*first, c->core());
core::DownloadFactory* f = new core::DownloadFactory(c->core());
// Replace with session torrent flag.
f->set_session(true);
f->slot_finished(sigc::bind(sigc::ptr_fun(&rak::call_delete_func<core::DownloadFactory>), f));
f->load();
f->load(*first);
f->commit();
}
}
@@ -117,12 +117,12 @@ void
load_arg_torrents(Control* c, char** first, char** last) {
//std::for_each(begin, end, std::bind1st(std::mem_fun(&core::Manager::insert), &c->get_core()));
for (; first != last; ++first) {
core::DownloadFactory* f = new core::DownloadFactory(*first, c->core());
core::DownloadFactory* f = new core::DownloadFactory(c->core());
// Replace with session torrent flag.
f->set_start(true);
f->slot_finished(sigc::bind(sigc::ptr_fun(&rak::call_delete_func<core::DownloadFactory>), f));
f->load();
f->load(*first);
f->commit();
}
}
+17 -1
View File
@@ -87,7 +87,23 @@ xmlrpc_to_object(xmlrpc_env* env, xmlrpc_value* value) {
return result;
}
// case XMLRPC_TYPE_BASE64:
case XMLRPC_TYPE_BASE64:
{
size_t valueSize;
const char* valueString;
xmlrpc_read_base64(env, value, &valueSize, (const unsigned char**)&valueString);
if (env->fault_occurred)
return torrent::Object();
torrent::Object result = torrent::Object(std::string(valueString, valueSize));
// Urgh, seriously?
::free((void*)valueString);
return result;
}
case XMLRPC_TYPE_ARRAY:
{
torrent::Object result(torrent::Object::TYPE_LIST);