/** * Add the "private" flag to the torrent * * @return true if a change was required */ public function make_private() { if (empty($this->Dec)) { return false; } if ($this->is_private()) { return false; } $this->Dec['info']['private'] = Int64::make(1); ksort($this->Dec['info']); return true; }
/** * Internal decoding function that does the actual job * * @return decoded data with a suitable structure */ private function _bdec() { switch ($this->Data[$this->Pos]) { case 'i': $this->Pos++; $Value = substr($this->Data, $this->Pos, strpos($this->Data, 'e', $this->Pos) - $this->Pos); if (!ctype_digit($Value) && !($Value[0] == '-' && ctype_digit(substr($Value, 1)))) { return $this->error(); } $this->Pos += strlen($Value) + 1; return Int64::make($Value); case 'l': $Value = array(); $this->Pos++; while ($this->Data[$this->Pos] != 'e') { if ($this->Pos >= $this->Length) { return $this->error(); } $Value[] = $this->_bdec(); } $this->Pos++; return $Value; case 'd': $Value = array(); $this->Pos++; while ($this->Data[$this->Pos] != 'e') { $Length = substr($this->Data, $this->Pos, strpos($this->Data, ':', $this->Pos) - $this->Pos); if (!ctype_digit($Length)) { return $this->error(); } $this->Pos += strlen($Length) + $Length + 1; $Key = substr($this->Data, $this->Pos - $Length, $Length); if ($this->Pos >= $this->Length) { return $this->error(); } $Value[$Key] = $this->_bdec(); } $this->Pos++; // Use boolean true to keep track of empty dictionaries return empty($Value) ? true : $Value; default: $Length = substr($this->Data, $this->Pos, strpos($this->Data, ':', $this->Pos) - $this->Pos); if (!ctype_digit($Length)) { return $this->error(); // Even if the string is likely to be decoded correctly without this check, it's malformed } $this->Pos += strlen($Length) + $Length + 1; return substr($this->Data, $this->Pos - $Length, $Length); } }