Changeset 5 for trunk

Show
Ignore:
Timestamp:
31.01.2005 13:43:23 (4 years ago)
Author:
m
Message:

- Fixed Bug #3222

Location:
trunk/File/Bittorrent
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/File/Bittorrent/Decode.php

    r4 r5  
    2020* Encode data in Bittorrent format 
    2121* 
    22 * Based on  
     22* Based on 
    2323*   Original Python implementation by Petru Paler <petru@paler.net> 
    2424*   PHP translation by Gerard Krijgsman <webmaster@animesuki.com> 
     
    6565    */ 
    6666    var $name = ''; 
    67      
     67 
    6868    /** 
    6969    * @var string   Filename of the torrent 
    7070    */ 
    7171    var $filename = ''; 
    72      
     72 
    7373    /** 
    7474    * @var string   Comment 
    7575    */ 
    7676    var $comment = ''; 
    77      
     77 
    7878    /** 
    7979    * @var int   Creation date as unix timestamp 
    8080    */ 
    8181    var $date = 0; 
    82      
     82 
    8383    /** 
    8484    * @var array    Files in the torrent 
    8585    */ 
    8686    var $files = array(); 
    87      
     87 
    8888    /** 
    8989    * @var int      Size of of the full torrent (after download) 
    9090    */ 
    9191    var $size = 0; 
    92      
     92 
    9393    /** 
    9494    * @var string   Signature of the software which created the torrent 
    9595    */ 
    9696    var $created_by = ''; 
    97     
     97 
    9898    /** 
    9999    * @var string    tracker (the tracker the torrent has been received from) 
     
    105105    */ 
    106106    var $announce_list = array(); 
    107      
     107 
    108108    /** 
    109109    * @var string   Source string 
     
    111111    */ 
    112112    var $_source = ''; 
    113      
     113 
    114114    /** 
    115115    * @var int      Current position of the string 
     
    117117    */ 
    118118    var $_position = 0; 
    119      
     119 
    120120    /** 
    121121    * Decode a Bencoded string 
     
    130130        return $this->_bdecode(); 
    131131    } 
    132      
     132 
    133133    /** 
    134134    * Decode .torrent file and accumulate information 
    135135    * 
    136     * @param string    Filename         
     136    * @param string    Filename 
    137137    * @return mixed    Returns an arrayon success or false on error 
    138138    */ 
     
    144144            return false; 
    145145        } 
    146          
     146 
    147147        // Reset public attributes 
    148148        $this->name          = ''; 
     
    157157        $this->_position     = 0; 
    158158 
    159         // Decode .torrent   
     159        // Decode .torrent 
    160160        $this->_source = file_get_contents($file); 
    161161        $decoded = $this->_bdecode(); 
    162          
     162 
    163163        // Pull information form decoded data 
    164164        $this->filename = basename($file); 
     
    177177            $this->created_by = $decoded['created by']; 
    178178        } 
    179         // There is sometimes an array listing all files  
     179        // There is sometimes an array listing all files 
    180180        // in the torrent with their individual filesize 
    181181        if (isset($decoded['info']['files']) and is_array($decoded['info']['files'])) { 
     
    207207            } 
    208208        } 
    209          
     209 
    210210        // Currently, I'm not sure how to determine an error 
    211211        // Just try to fetch the info from the decoded data 
     
    223223        ); 
    224224    } 
    225      
     225 
    226226    /** 
    227227    * Decode a BEncoded String 
     
    250250        } 
    251251    } 
    252      
     252 
    253253    /** 
    254254    * Decode a BEncoded dictionary 
     
    282282    * @access private 
    283283    * @return string 
    284     */                 
     284    */ 
    285285    function _decode_string() 
    286286    { 
     
    293293        // Move Pointer after string 
    294294        $this->_position = $pos_colon + $str_length + 1; 
     295        $return = utf8_decode($return); 
    295296        return $return; 
    296297    } 
    297      
     298 
    298299    /** 
    299300    * Decode a BEncoded integer 
     
    305306    * @access private 
    306307    * @return int 
    307     */                 
     308    */ 
    308309    function _decode_int() 
    309310    { 
     
    326327    * @access private 
    327328    * @return array 
    328     */                 
     329    */ 
    329330    function _decode_list() 
    330331    { 
     
    342343    * 
    343344    * @access private 
    344     * @return string            
     345    * @return string 
    345346    */ 
    346347    function _getChar() 
  • trunk/File/Bittorrent/Encode.php

    r4 r5  
    2020* Encode data in Bittorrent format 
    2121* 
    22 * Based on  
     22* Based on 
    2323*   Original Python implementation by Petru Paler <petru@paler.net> 
    2424*   PHP translation by Gerard Krijgsman <webmaster@animesuki.com> 
     
    5858    * @param mixed    Variable to encode 
    5959    * @return string 
    60     */                 
     60    */ 
    6161    function encode($mixed) 
    6262    { 
     
    7575        } 
    7676    } 
    77      
     77 
    7878    /** 
    7979    * BEncodes a string 
     
    8888    function encode_string($str) 
    8989    { 
     90        $str = utf8_encode($str); 
    9091        return sprintf('%d:%s', strlen($str), $str); 
    9192    } 
    92      
     93 
    9394    /** 
    9495    * BEncodes a integer 
     
    105106        return sprintf('i%de', $int); 
    106107    } 
    107      
     108 
    108109    /** 
    109110    * BEncodes an array 
     
    120121    * list of strings ["Monduna", "Bit", "Torrents"] would bEncode to 
    121122    * l7:Monduna3:Bit8:Torrentse. The list [1, "Monduna", 3, ["Sub", "List"]] 
    122     * would bEncode to li1e7:Mondunai3el3:Sub4:Listee  
     123    * would bEncode to li1e7:Mondunai3el3:Sub4:Listee 
    123124    * 
    124125    * @param array 
     
    127128    function encode_array($array) 
    128129    { 
     130        // Sort array 
     131        asort($array, SORT_STRING); 
    129132        // Check for strings in the keys 
    130133        $isList = true;