Show
Ignore:
Timestamp:
02/28/08 14:54:36 (4 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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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}