* Added 'get_pid', 'get/set_name' and 'cat' command.

* SocketFd::open_local() should use SOCK_STREAM, not SOCK_DGRAM.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@959 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-08-20 01:38:38 +00:00
parent 5ec7790aa9
commit ded9e12ff1
7 changed files with 56 additions and 2 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ namespace rpc {
// By using a static array we avoid allocating the variables on the
// heap. This should reduce memory use and improve cache locality.
#define COMMAND_SLOTS_SIZE 100
#define COMMAND_SLOTS_SIZE 150
#define COMMAND_VARIABLES_SIZE 100
#define COMMAND_DOWNLOAD_SLOTS_SIZE 100
#define COMMAND_FILE_SLOTS_SIZE 20
+4
View File
@@ -40,6 +40,7 @@
#include <functional>
#include <unistd.h>
#include <rak/path.h>
#include <sys/types.h>
#include <torrent/torrent.h>
#include <torrent/chunk_manager.h>
@@ -102,6 +103,9 @@ initialize_command_local() {
ADD_VARIABLE_C_STRING("library_version", torrent::version());
ADD_COMMAND_VOID("get_hostname", rak::ptr_fun(&apply_get_hostname));
ADD_COMMAND_VOID("get_pid", rak::ptr_fun(&getpid));
ADD_VARIABLE_STRING("name", "");
ADD_VARIABLE_VALUE("max_file_size", -1);
ADD_VARIABLE_VALUE("split_file_size", -1);
+9
View File
@@ -116,6 +116,14 @@ apply_print(const torrent::Object& rawArgs) {
return torrent::Object();
}
torrent::Object
apply_cat(const torrent::Object& rawArgs) {
std::string result;
rpc::print_object_std(&result, &rawArgs, 0);
return result;
}
void
initialize_command_ui() {
ADD_VARIABLE_STRING("key_layout", "qwerty");
@@ -133,4 +141,5 @@ initialize_command_ui() {
// ADD_COMMAND_LIST("view_sort_current", rak::bind_ptr_fn(&apply_view_filter, &core::ViewManager::set_sort_current));
ADD_COMMAND_LIST("print", rak::ptr_fn(&apply_print));
ADD_COMMAND_LIST("cat", rak::ptr_fn(&apply_cat));
}
+3
View File
@@ -166,6 +166,9 @@ main(int argc, char** argv) {
initialize_commands();
rpc::parse_command_multiple(
// "set_name = $cat={$get_hostname=,:,$get_pid=}\n"
"set_name = \"$cat=$get_hostname=,:,$get_pid=\"\n"
// Currently not doing any sorting on main.
"view_add = main\n"
"view_add = default\n"
+37
View File
@@ -389,4 +389,41 @@ print_object(char* first, char* last, const torrent::Object* src, int flags) {
}
}
void
print_object_std(std::string* dest, const torrent::Object* src, int flags) {
switch (src->type()) {
case torrent::Object::TYPE_STRING:
{
const std::string& str = src->as_string();
if ((flags & print_expand_tilde) && *str.c_str() == '~')
*dest += rak::path_expand(str);
else
*dest += str;
return;
}
case torrent::Object::TYPE_VALUE:
{
char buffer[64];
snprintf(buffer, 64, "%lli", src->as_value());
*dest += buffer;
return;
}
case torrent::Object::TYPE_LIST:
for (torrent::Object::list_type::const_iterator itr = src->as_list().begin(), itrEnd = src->as_list().end(); itr != itrEnd; itr++) {
print_object_std(dest, &*itr, flags);
// Don't expand tilde after the first element in the list.
flags &= ~print_expand_tilde;
}
return;
default:
throw torrent::input_error("Invalid type.");
}
}
}
+1
View File
@@ -91,6 +91,7 @@ convert_to_single_argument(const torrent::Object& args) {
static const int print_expand_tilde = 0x1;
char* print_object(char* first, char* last, const torrent::Object* src, int flags);
void print_object_std(std::string* dest, const torrent::Object* src, int flags);
}
+1 -1
View File
@@ -140,7 +140,7 @@ SocketFd::open_datagram() {
bool
SocketFd::open_local() {
return (m_fd = socket(PF_LOCAL, SOCK_DGRAM, 0)) != -1;
return (m_fd = socket(PF_LOCAL, SOCK_STREAM, 0)) != -1;
}
void