When I tried to install the new release files, it shut down my site completely giving the following error

Fatal error: Call to undefined function: bt_message() in /var/www/vhosts/mysite.co.uk/subdomains/torrent/httpdocs/bt_common.inc on line 373

I had to delete the whole bittorent module folder to get my site back up again

Comments

bradfordcp’s picture

Assigned: Unassigned » bradfordcp

I am verifying the issue now. Where you trying to access a specific page or are all pages unavailable?

bradfordcp’s picture

I just performed a clean drupal installation and installed the bittorrent module without any issue. Everything appears to be working normally. Could you please provide more information?

droople’s picture

Title: errors during installlation » errors during installlation: fixed

in the bt_common.inc file on line 275

there is a typo of "foreach($bparsed as & $key => $value)"

should be changed to

"foreach($bparsed as $key => $value)"

bradfordcp’s picture

Line 275 in bt_common.inc should read:
"foreach($bparsed as $key => &$value) {"
That is copied directly from the CVS (it is also the same in my working copy). The '&' is in place so $value is a reference and can be changed within the foreach loop.

From the documentation at php.net:

As of PHP 5, you can easily modify array's elements by preceding $value with &. This will assign reference instead of copying the value.

$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
    $value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
bradfordcp’s picture

After doing more research I noticed announce.php calls bt_message() at line 373 as your error states. I am wondering if all of the correct files were moved into the root of the drupal installation. That is the only thing that comes to mind.

droople’s picture

Title: errors during installlation: fixed » leaving the "&" in line 275 gives this error
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /var/www/vhosts/mysite.co.uk/subdomains/torrent/httpdocs/bt_common.inc on line 275

once I change it (remove the "&" sign, the error disappears and all looks well

bradfordcp’s picture

That is because the function is no longer doing as it was intended. Could you please paste the entire function here (with the &) so that I may verify it.

droople’s picture

Title: leaving the "&" in line 275 gives this error » bt_common.inc line 256 to 293
**
 * Strips the unnescessary values from the bdecode() result.
 * 
 * @param $bparsed
 *   The array of data returned by bdecode()
 * @return The modified structure without the 'value' field. Example:
 *    array(
 *      'announce' => 'announce url',
 *      'creation date' => 'creation date',
 *      'info' => array(
 *        'files' => 'files list',
 *      'name' => 'torrent name',
 *        'piece length' => 'length of each piece',
 *        'pieces' => 'The piece hashes',
 *      ),
 *    )
 */
function strip_excess($bparsed) {
  if (is_array($bparsed)) {
    foreach($bparsed as $key => $value) {
      if (is_array($value)) {
        if (array_key_exists('value', $value)) {
          $value = strip_excess($value['value']);
        }
        else {
          $value = strip_excess($value);
        }
      }
    }
  }
  
  if (is_array($bparsed) && array_key_exists('value', $bparsed)) {
    return $bparsed['value'];
  }
  else {
    return $bparsed;
  }
}
bradfordcp’s picture

Everything looks correct except the '&' before '$value', it should read '&$value'. If this is not in place the torrent structure will not be to spec. Most notably the information hash will be off and the structure returned will not be re-encoded appropriately. Something else that comes to mind is what version of PHP are you using. The ability to reference within a foreach loop is only in PHP 5.

droople’s picture

Title: bt_common.inc line 256 to 293 » PhP version 4.4.2-1buld1

Could this be the problem?

Sorry for all the trouble then

bradfordcp’s picture

Status: Active » Closed (fixed)

Yes, this is the problem. PHP 5 is required to use the '&' before $value in the foreach statement. I might rewrite this later, but for now it looks like PHP 5 is required for my module.