Changeset 10774
- Timestamp:
- Jun 16, 2010, 3:05:23 AM (13 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/metainfo.c
r10502 r10774 403 403 tr_info * inf, 404 404 tr_bool * hasInfoDict, 405 int * infoDictOffset,406 405 int * infoDictLength, 407 406 const tr_benc * meta_in ) … … 461 460 if( infoDictLength != NULL ) 462 461 *infoDictLength = len; 463 464 if( infoDictOffset != NULL )465 {466 int mlen = 0;467 char * mstr = tr_bencToStr( meta_in, TR_FMT_BENC, &mlen );468 const char * offset = tr_memmem( mstr, mlen, bstr, len );469 if( offset != NULL )470 *infoDictOffset = offset - mstr;471 tr_free( mstr );472 if( offset == NULL )473 return "info";474 }475 462 476 463 tr_free( bstr ); … … 564 551 tr_info * inf, 565 552 tr_bool * hasInfoDict, 566 int * infoDictOffset,567 553 int * infoDictLength ) 568 554 { … … 570 556 inf, 571 557 hasInfoDict, 572 infoDictOffset,573 558 infoDictLength, 574 559 meta_in ); -
trunk/libtransmission/metainfo.h
r10502 r10774 26 26 tr_info * setmeInfo, 27 27 tr_bool * setmeHasInfoDict, 28 int * setmeInfoDictOffset,29 28 int * setmeInfoDictLength ); 30 29 -
trunk/libtransmission/torrent-magnet.c
r10641 r10774 96 96 } 97 97 98 static int 99 findInfoDictOffset( const tr_torrent * tor ) 100 { 101 size_t fileLen; 102 uint8_t * fileContents; 103 int offset = 0; 104 105 /* load the file, and find the info dict's offset inside the file */ 106 if(( fileContents = tr_loadFile( tor->info.torrent, &fileLen ))) 107 { 108 tr_benc top; 109 110 if( !tr_bencParse( fileContents, fileContents + fileLen, &top, NULL ) ) 111 { 112 tr_benc * infoDict; 113 114 if( tr_bencDictFindDict( &top, "info", &infoDict ) ) 115 { 116 int infoLen; 117 char * infoContents = tr_bencToStr( infoDict, TR_FMT_BENC, &infoLen ); 118 const uint8_t * i = (const uint8_t*) tr_memmem( (char*)fileContents, fileLen, infoContents, infoLen ); 119 offset = i == NULL ? i - fileContents : 0; 120 tr_free( infoContents ); 121 } 122 123 tr_bencFree( &top ); 124 } 125 126 tr_free( fileContents ); 127 } 128 129 return offset; 130 } 131 132 static void 133 ensureInfoDictOffsetIsCached( tr_torrent * tor ) 134 { 135 assert( tr_torrentHasMetadata( tor ) ); 136 137 if( !tor->infoDictOffsetIsCached ) 138 { 139 tor->infoDictOffset = findInfoDictOffset( tor ); 140 tor->infoDictOffsetIsCached = TRUE; 141 } 142 } 143 98 144 void* 99 tr_torrentGetMetadataPiece( consttr_torrent * tor, int piece, int * len )145 tr_torrentGetMetadataPiece( tr_torrent * tor, int piece, int * len ) 100 146 { 101 147 char * ret = NULL; … … 105 151 assert( len != NULL ); 106 152 107 if( tor->infoDictLength > 0 ) 108 { 109 FILE * fp = fopen( tor->info.torrent, "rb" ); 153 if( tr_torrentHasMetadata( tor ) ) 154 { 155 FILE * fp; 156 157 ensureInfoDictOffsetIsCached( tor ); 158 159 assert( tor->infoDictLength > 0 ); 160 assert( tor->infoDictOffset >= 0 ); 161 162 fp = fopen( tor->info.torrent, "rb" ); 110 163 if( fp != NULL ) 111 164 { … … 209 262 tr_bencMergeDicts( tr_bencDictAddDict( &newMetainfo, "info", 0 ), &infoDict ); 210 263 211 success = tr_metainfoParse( tor->session, &newMetainfo, &tor->info, 212 &hasInfo, &tor->infoDictOffset, &tor->infoDictLength ); 264 success = tr_metainfoParse( tor->session, &newMetainfo, &tor->info, &hasInfo, &tor->infoDictLength ); 213 265 214 266 assert( hasInfo ); -
trunk/libtransmission/torrent-magnet.h
r9868 r10774 26 26 }; 27 27 28 void* tr_torrentGetMetadataPiece( consttr_torrent * tor, int piece, int * len );28 void* tr_torrentGetMetadataPiece( tr_torrent * tor, int piece, int * len ); 29 29 30 30 void tr_torrentSetMetadataPiece( tr_torrent * tor, int piece, const void * data, int len ); -
trunk/libtransmission/torrent.c
r10736 r10774 738 738 static tr_parse_result 739 739 torrentParseImpl( const tr_ctor * ctor, tr_info * setmeInfo, 740 tr_bool * setmeHasInfo, int * dict Offset, int * dictLength )740 tr_bool * setmeHasInfo, int * dictLength ) 741 741 { 742 742 int doFree; … … 756 756 757 757 didParse = tr_metainfoParse( session, metainfo, setmeInfo, 758 &hasInfo, dict Offset, dictLength );758 &hasInfo, dictLength ); 759 759 doFree = didParse && ( setmeInfo == &tmp ); 760 760 … … 780 780 tr_torrentParse( const tr_ctor * ctor, tr_info * setmeInfo ) 781 781 { 782 return torrentParseImpl( ctor, setmeInfo, NULL, NULL , NULL);782 return torrentParseImpl( ctor, setmeInfo, NULL, NULL ); 783 783 } 784 784 … … 786 786 tr_torrentNew( const tr_ctor * ctor, int * setmeError ) 787 787 { 788 int off,len;788 int len; 789 789 tr_bool hasInfo; 790 790 tr_info tmpInfo; … … 795 795 assert( tr_isSession( tr_ctorGetSession( ctor ) ) ); 796 796 797 r = torrentParseImpl( ctor, &tmpInfo, &hasInfo, & off, &len );797 r = torrentParseImpl( ctor, &tmpInfo, &hasInfo, &len ); 798 798 if( r == TR_PARSE_OK ) 799 799 { … … 801 801 tor->info = tmpInfo; 802 802 if( hasInfo ) 803 {804 tor->infoDictOffset = off;805 803 tor->infoDictLength = len; 806 }807 804 torrentInit( tor, ctor ); 808 805 } … … 2196 2193 memset( &tmpInfo, 0, sizeof( tr_info ) ); 2197 2194 if( tr_metainfoParse( tor->session, &metainfo, &tmpInfo, 2198 &hasInfo, &tor->infoDict Offset, &tor->infoDictLength ) )2195 &hasInfo, &tor->infoDictLength ) ) 2199 2196 { 2200 2197 /* it's good, so keep these new trackers and free the old ones */ -
trunk/libtransmission/torrent.h
r10664 r10774 166 166 char * incompleteDir; 167 167 168 /* Length, in bytes, of the "info" dict in the .torrent file */168 /* Length, in bytes, of the "info" dict in the .torrent file. */ 169 169 int infoDictLength; 170 170 171 /* Offset, in bytes, of the beginning of the "info" dict in the .torrent file */ 171 /* Offset, in bytes, of the beginning of the "info" dict in the .torrent file. 172 * 173 * Used by the torrent-magnet code for serving metainfo to peers. 174 * This field is lazy-generated and might not be initialized yet. */ 172 175 int infoDictOffset; 173 176 … … 232 235 tr_bool startAfterVerify; 233 236 tr_bool isDirty; 237 238 tr_bool infoDictOffsetIsCached; 234 239 235 240 uint16_t maxConnectedPeers;
Note: See TracChangeset
for help on using the changeset viewer.