* Fixed a buffer overflow when writting to the output buffer. This

would in some rare occasions cause memory to be corrupted. leading to
a crash.

* Added option for setting the http proxy and proccess's umask.

* Save the total uploaded for downloads between sessions.

* Moved from sigc++ to my own lightweight slot class for the task
scheduler. This saves some 5-600kb when compiled with debugging
symbols, 1-200kb without.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@605 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-12-05 07:59:29 +00:00
parent 32a3619cd8
commit ba7d61b532
15 changed files with 250 additions and 23 deletions
+1 -1
View File
@@ -60,7 +60,7 @@ Control::Control() :
m_inputStdin->slot_pressed(sigc::mem_fun(m_input, &input::Manager::pressed));
m_taskShutdown.set_iterator(taskScheduler.end());
m_taskShutdown.set_slot(sigc::mem_fun(*this, &Control::receive_shutdown));
m_taskShutdown.set_slot(rak::mem_fn(this, &Control::receive_shutdown));
}
Control::~Control() {
+5
View File
@@ -132,6 +132,11 @@ CurlGet::set_user_agent(const char* s) {
curl_easy_setopt(m_handle, CURLOPT_USERAGENT, s);
}
void
CurlGet::set_http_proxy(const char* s) {
curl_easy_setopt(m_handle, CURLOPT_PROXY, s);
}
void
CurlGet::perform(CURLMsg* msg) {
if (msg->msg != CURLMSG_DONE)
+1
View File
@@ -67,6 +67,7 @@ class CurlGet : public torrent::Http {
double size_total();
void set_user_agent(const char* s);
void set_http_proxy(const char* s);
protected:
CURL* handle() { return m_handle; }
+5 -1
View File
@@ -103,7 +103,11 @@ CurlStack::fdset(fd_set* readfds, fd_set* writefds, fd_set* exceptfds) {
void
CurlStack::add_get(CurlGet* get) {
get->set_user_agent(m_userAgent.c_str());
if (!m_userAgent.empty())
get->set_user_agent(m_userAgent.c_str());
if (!m_httpProxy.empty())
get->set_http_proxy(m_httpProxy.c_str());
CURLMcode code;
+4
View File
@@ -68,6 +68,9 @@ class CurlStack {
const std::string& user_agent() const { return m_userAgent; }
void set_user_agent(const std::string& s) { m_userAgent = s; }
const std::string& http_proxy() const { return m_httpProxy; }
void set_http_proxy(const std::string& s) { m_httpProxy = s; }
static void global_init();
static void global_cleanup();
@@ -85,6 +88,7 @@ class CurlStack {
CurlGetList m_getList;
std::string m_userAgent;
std::string m_httpProxy;
};
}
+2 -2
View File
@@ -61,10 +61,10 @@ DownloadFactory::DownloadFactory(const std::string& uri, Manager* m) :
m_start(false) {
m_taskLoad.set_iterator(taskScheduler.end());
m_taskLoad.set_slot(sigc::mem_fun(*this, &DownloadFactory::receive_load));
m_taskLoad.set_slot(rak::mem_fn(this, &DownloadFactory::receive_load));
m_taskCommit.set_iterator(taskScheduler.end());
m_taskCommit.set_slot(sigc::mem_fun(*this, &DownloadFactory::receive_commit));
m_taskCommit.set_slot(rak::mem_fn(this, &DownloadFactory::receive_commit));
}
DownloadFactory::~DownloadFactory() {
+1 -1
View File
@@ -51,7 +51,7 @@ Window::Window(Canvas* c, bool d, int h) :
m_minHeight(h) {
m_taskUpdate.set_iterator(displayScheduler.end());
m_taskUpdate.set_slot(sigc::mem_fun(*this, &Window::redraw));
m_taskUpdate.set_slot(rak::mem_fn(this, &Window::redraw));
}
Window::~Window() {
+4
View File
@@ -136,6 +136,8 @@ initialize_option_handler(Control* c, OptionHandler* optionHandler) {
optionHandler->insert("max_open_files", new OptionHandlerInt(c, &apply_max_open_files));
optionHandler->insert("max_open_sockets", new OptionHandlerInt(c, &apply_max_open_sockets));
optionHandler->insert("umask", new OptionHandlerOctal(c, &apply_umask));
optionHandler->insert("connection_leech", new OptionHandlerString(c, &apply_connection_leech));
optionHandler->insert("connection_seed", new OptionHandlerString(c, &apply_connection_seed));
@@ -143,6 +145,8 @@ initialize_option_handler(Control* c, OptionHandler* optionHandler) {
optionHandler->insert("encoding_list", new OptionHandlerString(c, &apply_encoding_list));
optionHandler->insert("tracker_dump", new OptionHandlerString(c, &apply_tracker_dump));
optionHandler->insert("use_udp_trackers", new OptionHandlerString(c, &apply_use_udp_trackers));
optionHandler->insert("http_proxy", new OptionHandlerString(c, &apply_http_proxy));
}
void
+24 -2
View File
@@ -37,9 +37,11 @@
#include "config.h"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <torrent/exceptions.h>
#include <torrent/torrent.h>
#include <netinet/in.h>
#include "core/manager.h"
#include "ui/root.h"
@@ -55,7 +57,17 @@ OptionHandlerInt::process(const std::string& key, const std::string& arg) {
int a;
if (std::sscanf(arg.c_str(), "%i", &a) != 1)
throw torrent::input_error("Invalid argument for \"" + key + "\": \"" + arg + "\"");
throw torrent::input_error("Invalid argument for \"" + key + "\": \"" + arg + "\", must be an integer.");
m_apply(m_control, a);
}
void
OptionHandlerOctal::process(const std::string& key, const std::string& arg) {
int a;
if (std::sscanf(arg.c_str(), "%o", &a) != 1)
throw torrent::input_error("Invalid argument for \"" + key + "\": \"" + arg + "\", must be an octal.");
m_apply(m_control, a);
}
@@ -110,6 +122,11 @@ apply_global_upload_rate(Control* m, int arg) {
m->ui()->set_up_throttle(arg);
}
void
apply_umask(Control* m, int arg) {
umask(arg);
}
void
apply_hash_read_ahead(Control* m, int arg) {
torrent::set_hash_read_ahead(arg << 20);
@@ -185,6 +202,11 @@ apply_check_hash(Control* m, const std::string& arg) {
m->core()->set_check_hash(false);
}
void
apply_http_proxy(Control* m, const std::string& arg) {
m->core()->get_poll_manager()->get_http_stack()->set_http_proxy(arg);
}
void
apply_session_directory(Control* m, const std::string& arg) {
m->core()->get_download_store().use(arg);
+18
View File
@@ -59,6 +59,8 @@ void apply_connection_seed(Control* m, const std::string& arg);
void apply_global_download_rate(Control* m, int arg);
void apply_global_upload_rate(Control* m, int arg);
void apply_umask(Control* m, int arg);
void apply_hash_read_ahead(Control* m, int arg);
void apply_hash_interval(Control* m, int arg);
void apply_hash_max_tries(Control* m, int arg);
@@ -73,6 +75,8 @@ void apply_tracker_dump(Control* m, const std::string& arg);
void apply_use_udp_trackers(Control* m, const std::string& arg);
void apply_check_hash(Control* m, const std::string& arg);
void apply_http_proxy(Control* m, const std::string& arg);
void apply_session_directory(Control* m, const std::string& arg);
void apply_encoding_list(Control* m, const std::string& arg);
@@ -90,6 +94,20 @@ private:
Apply m_apply;
};
class OptionHandlerOctal : public OptionHandlerBase {
public:
typedef void (*Apply)(Control*, int);
OptionHandlerOctal(Control* c, Apply a) :
m_control(c), m_apply(a) {}
virtual void process(const std::string& key, const std::string& arg);
private:
Control* m_control;
Apply m_apply;
};
class OptionHandlerString : public OptionHandlerBase {
public:
typedef void (*Apply)(Control*, const std::string&);
+1 -1
View File
@@ -86,7 +86,7 @@ DownloadList::DownloadList(Control* c) :
m_windowLog = new WLog(&m_control->core()->get_log_important());
m_taskUpdate.set_iterator(taskScheduler.end());
m_taskUpdate.set_slot(sigc::mem_fun(*this, &DownloadList::task_update)),
m_taskUpdate.set_slot(rak::mem_fn(this, &DownloadList::task_update)),
setup_keys();
setup_input();
+3 -3
View File
@@ -39,7 +39,7 @@
#include <list>
#include <rak/timer.h>
#include <sigc++/slot.h>
#include <rak/functional_fun.h>
namespace utils {
@@ -47,10 +47,10 @@ namespace utils {
class TaskItem {
public:
typedef sigc::slot<void> Slot;
typedef rak::function<void> Slot;
typedef std::list<std::pair<rak::timer, TaskItem*> >::iterator iterator;
TaskItem(Slot s = Slot()) : m_slot(s) {}
TaskItem() {}
Slot& get_slot() { return m_slot; }
void set_slot(Slot s) { m_slot = s; }