Changeset 1040

Show
Ignore:
Timestamp:
02/28/08 19:54:36 (2 years ago)
Author:
rakshasa
Message:

* Added {get/set}_xmlrpc_size_limit to allow the user to specify
larger buffer size for handling direct loading of torrents through
xmlrpc.

* Allow file and tracker targets with the compact xmlrpc syntax,
e.g. "<infohash>:f<id>".

* Fixed an alignment bug in the DHT code.

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/libtorrent/src/dht/dht_node.cc

    r1013 r1040  
    4141#include "torrent/object.h" 
    4242 
     43// For SACompact... 
     44#include "download/download_info.h" 
     45 
    4346#include "dht_node.h" 
    4447 
     
    7477DhtNode::store_compact(char* buffer) const { 
    7578  HashString::cast_from(buffer)->assign(data()); 
    76   *(uint32_t*) (buffer+20) = address()->sa_inet()->address_n(); 
    77   *(uint16_t*) (buffer+24) = address()->sa_inet()->port_n(); 
    78   return buffer+26; 
     79 
     80  SocketAddressCompact sa(address()->sa_inet()); 
     81  std::memcpy(buffer + 20, sa.c_str(), 6); 
     82 
     83  return buffer + 26; 
    7984} 
    8085 
  • trunk/libtorrent/src/download/download_info.h

    r1004 r1040  
    3535//           3185 Skoppum, NORWAY 
    3636 
    37 #ifndef LIBTORRENT_TRACKER_INFO_H 
    38 #define LIBTORRENT_TRACKER_INFO_H 
     37#ifndef LIBTORRENT_DOWNLOAD_INFO_H 
     38#define LIBTORRENT_DOWNLOAD_INFO_H 
    3939 
    4040#include <list> 
     
    190190  SocketAddressCompact() {} 
    191191  SocketAddressCompact(uint32_t a, uint16_t p) : addr(a), port(p) {} 
     192  SocketAddressCompact(const rak::socket_address_inet* sa) : addr(sa->address_n()), port(sa->port_n()) {} 
    192193 
    193194  operator rak::socket_address () const { 
  • trunk/rtorrent/src/command_network.cc

    r1034 r1040  
    350350  ADD_COMMAND_STRING_UN("scgi_port",            rak::bind2nd(std::ptr_fun(&apply_scgi), 1)); 
    351351  ADD_COMMAND_STRING_UN("scgi_local",           rak::bind2nd(std::ptr_fun(&apply_scgi), 2)); 
    352   ADD_VARIABLE_BOOL("scgi_dont_route", false); 
     352  ADD_VARIABLE_BOOL    ("scgi_dont_route", false); 
    353353  ADD_COMMAND_STRING_UN("xmlrpc_dialect",       std::ptr_fun(&apply_xmlrpc_dialect)); 
     354  ADD_COMMAND_VALUE_TRI("xmlrpc_size_limit",    std::ptr_fun(&rpc::XmlRpc::set_size_limit), rak::ptr_fun(&rpc::XmlRpc::size_limit)); 
    354355 
    355356  ADD_COMMAND_VALUE_TRI("hash_read_ahead",      std::ptr_fun(&apply_hash_read_ahead), rak::ptr_fun(torrent::hash_read_ahead)); 
  • trunk/rtorrent/src/rpc/xmlrpc.cc

    r1039 r1040  
    134134rpc::target_type 
    135135xmlrpc_to_target(xmlrpc_env* env, xmlrpc_value* value) { 
     136  rpc::target_type target; 
     137 
    136138  switch (xmlrpc_value_type(value)) { 
    137139  case XMLRPC_TYPE_STRING: 
     
    142144      throw xmlrpc_error(env); 
    143145 
    144     if (std::strlen(str) == 40) { 
    145       core::Download* download = xmlrpc.get_slot_find_download()(str); 
    146       ::free((void*)str); 
    147  
    148       if (download == NULL) 
    149         throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Could not find info-hash."); 
    150  
    151       return rpc::make_target(download); 
    152  
    153     } else if (std::strlen(str) == 0) { 
     146    if (std::strlen(str) == 0) { 
     147      // When specifying void, we require a zero-length string. 
    154148      ::free((void*)str); 
    155149      return rpc::make_target(); 
     150 
     151    } else if (std::strlen(str) < 40) { 
     152      ::free((void*)str); 
     153      throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Unsupported target type found."); 
     154    } 
     155 
     156    core::Download* download = xmlrpc.get_slot_find_download()(str); 
     157 
     158    if (download == NULL) { 
     159      ::free((void*)str); 
     160      throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Could not find info-hash."); 
     161    } 
     162 
     163    if (std::strlen(str) == 40) { 
     164      ::free((void*)str); 
     165      return rpc::make_target(download); 
     166    } 
     167 
     168    if (std::strlen(str) < 42 || str[40] != ':') { 
     169      ::free((void*)str); 
     170      throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Unsupported target type found."); 
     171    } 
     172 
     173    // Files:    "<hash>:f<index>" 
     174    // Trackers: "<hash>:t<index>" 
     175 
     176    int index; 
     177    const char* end; 
     178 
     179    switch (str[41]) { 
     180    case 'f': 
     181      end = str + 42; 
     182      index = ::strtol(str + 42, (char**)&end, 0); 
     183 
     184      if (*str == '\0' || *end != '\0') 
     185        throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Invalid index."); 
     186 
     187      target = rpc::make_target(XmlRpc::call_file, xmlrpc.get_slot_find_file()(download, index)); 
     188      break; 
     189 
     190    case 't': 
     191      end = str + 42; 
     192      index = ::strtol(str + 42, (char**)&end, 0); 
     193 
     194      if (*str == '\0' || *end != '\0') 
     195        throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Invalid index."); 
     196 
     197      target = rpc::make_target(XmlRpc::call_file, xmlrpc.get_slot_find_tracker()(download, index)); 
     198      break; 
     199 
     200    default: 
     201      ::free((void*)str); 
     202      throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Unsupported target type found."); 
    156203    } 
    157204 
    158205    ::free((void*)str); 
    159     throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Unsupported target type found."); 
     206 
     207    // Check if the target pointer is NULL. 
     208    if (target.second == NULL) 
     209      throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Invalid index."); 
     210 
     211    return target; 
    160212 
    161213  default: 
     
    462514} 
    463515 
     516int64_t 
     517XmlRpc::size_limit() { 
     518  return xmlrpc_limit_get(XMLRPC_XML_SIZE_LIMIT_ID); 
     519} 
     520 
     521void 
     522XmlRpc::set_size_limit(uint64_t size) { 
     523  if (size >= (64 << 20)) 
     524    throw torrent::input_error("Invalid XMLRPC limit size."); 
     525 
     526  xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, size); 
     527} 
     528 
    464529#else 
    465530 
     
    472537bool XmlRpc::process(__UNUSED const char* inBuffer, __UNUSED uint32_t length, __UNUSED slot_write slotWrite) { return false; } 
    473538 
    474 #endif 
    475  
    476 } 
     539int64_t XmlRpc::size_limit() { return 0; } 
     540void    XmlRpc::set_size_limit(int64_t size) {} 
     541 
     542#endif 
     543 
     544} 
  • trunk/rtorrent/src/rpc/xmlrpc.h

    r970 r1040  
    9595  void                set_slot_find_tracker(slot_find_tracker::base_type* slot)   { m_slotFindTracker.set(slot); } 
    9696 
     97  static int64_t      size_limit(); 
     98  static void         set_size_limit(uint64_t size); 
     99 
    97100private: 
    98101  void*               m_env;