Question

I want to write my own rTorrent WebUI and doing my first steps with xmlrpc. But somehow it's not really working...

This is the function I wrote for HTTP POST requests:

function request($method, $args) {
    $data = xmlrpc_encode_request($method, $args);
    $ch = curl_init('http://#####/RPC2/');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = xmlrpc_decode(curl_exec($ch));
    curl_close($ch);
    return $response;
}

Now get torrent-list...

$data['hash'] = request('download_list',null);
print_r($data);
Array
(
    [hash] => Array
        (
            [0] => 0CF0C7F75D18281AE7C65309F6B798CEB149BCB8
            [1] => 8CAA3ED5CB29999A6DA84739FDFF2D6B04489833
        )

)

...and request information for every torrent/hash (reference for possible methods).

foreach ($data['hash'] as $index => $hash) {
    echo   "d.get_name:       "; print_r(request('d.get_name',       $hash));
    echo "\nd.get_base_path:  "; print_r(request('d.get_base_path',  $hash));
    echo "\nd.get_hash:       "; print_r(request('d.get_hash',       $hash));
    echo "\nd.is_active:      "; print_r(request('d.is_active',      $hash));
    echo "\nd.get_down_total: "; print_r(request('d.get_down_total', $hash));
    echo "\nd.get_up_total:   "; print_r(request('d.get_up_total',   $hash));
    echo "\nd.get_size_bytes: "; print_r(request('d.get_size_bytes', $hash));
}

Information about torrents matching the hash should be shown, but only a few are working.

d.get_name:       [Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
d.get_base_path:  /data/rtorrent/complete/[Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
d.get_hash:       0CF0C7F75D18281AE7C65309F6B798CEB149BCB8
d.is_active:      
d.get_down_total: 
d.get_up_total:   
d.get_size_bytes: 

d.get_name:       [Anime-Koi] Tokyo Ravens - 03 [h264-720p][C997AD9B].mkv
d.get_base_path:  /data/rtorrent/complete/[Anime-Koi] Tokyo Ravens - 03 [h264-720p][C997AD9B].mkv
d.get_hash:       8CAA3ED5CB29999A6DA84739FDFF2D6B04489833
d.is_active:      
d.get_down_total: 
d.get_up_total:   
d.get_size_bytes: 

Multicall is possible to get everything in one request. But same here - doesn't work.

print_r(request("d.multicall",array(
    "main",
    "d.get_name=",
    "d.get_base_path=",
    "d.get_up_total=",
    "d.get_size_bytes=",
    "d.get_down_total=",
    "d.get_completed_chunks=",
    "d.get_connection_current=",
    "d.get_connection_leech=",
    "d.get_connection_seed=",
    "d.get_creation_date="
)));
Array
(
    [0] => Array
        (
            [0] => [Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
            [1] => /data/rtorrent/complete/[Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
            [2] => 
            [3] => 
            [4] => 
            [5] => 
            [6] => seed
            [7] => 
            [8] => 
            [9] => 
        )

    [1] => Array
        (
            [0] => [Anime-Koi] Tokyo Ravens - 03 [h264-720p][C997AD9B].mkv
            [1] => /data/rtorrent/complete/[Anime-Koi] Tokyo Ravens - 03 [h264-720p][C997AD9B].mkv
            [2] => 
            [3] => 
            [4] => 
            [5] => 
            [6] => seed
            [7] => 
            [8] => 
            [9] => 
        )
)

Howerer, global requests are working fine.

print_r(request('view_list',null));
Array
(
    [0] => main
    [1] => default
    [2] => name
    [3] => active
    [4] => started
    [5] => stopped
    [6] => complete
    [7] => incomplete
    [8] => hashing
    [9] => seeding
    [10] => leeching
)
print_r(request('system.listMethods',null));
Array
(
    [0] => system.listMethods
    [1] => system.methodExist
    [2] => system.methodHelp
    [...]
    [959] => view_sort_new
    [960] => xmlrpc_dialect
    [961] => xmlrpc_size_limit
)

A few example of the xml-request for the first torrent when added following in the request function:

echo "request for \"$method\"\n".htmlentities($data)."\nresult: ";
request for "d.get_name"

<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>d.get_name</methodName>
<params>
 <param>
  <value>
   <string>0CF0C7F75D18281AE7C65309F6B798CEB149BCB8</string>
  </value>
 </param>
</params>
</methodCall>

result: [Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
request for "d.get_base_path"

<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>d.get_base_path</methodName>
<params>
 <param>
  <value>
   <string>0CF0C7F75D18281AE7C65309F6B798CEB149BCB8</string>
  </value>
 </param>
</params>
</methodCall>

result: /data/rtorrent/complete/[Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
request for "d.get_down_total"

<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>d.get_down_total</methodName>
<params>
 <param>
  <value>
   <string>0CF0C7F75D18281AE7C65309F6B798CEB149BCB8</string>
  </value>
 </param>
</params>
</methodCall>

result: 
request for "d.get_size_bytes"

<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>d.get_size_bytes</methodName>
<params>
 <param>
  <value>
   <string>0CF0C7F75D18281AE7C65309F6B798CEB149BCB8</string>
  </value>
 </param>
</params>
</methodCall>

result: 

What am I doing wrong that only some requests return anything useful?

Was it helpful?

Solution

This is a bug within PHP-XMLRPC.

However you can replace your line:

$response = xmlrpc_decode(curl_exec($ch));

With:

$response = xmlrpc_decode(str_replace('i8>', 'i4>', curl_exec($ch)));

This should work as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top