Changeset 5183
- Timestamp:
- Mar 2, 2008, 7:42:45 PM (14 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bencode.c
r5127 r5183 96 96 begin = buf + 1; 97 97 end = memchr( begin, 'e', (bufend-buf)-1 ); 98 if( end == NULL ) 98 if( end == NULL ) { 99 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 99 100 return TR_ERROR; 101 } 100 102 101 103 errno = 0; 102 104 val = strtoll( begin, &endptr, 10 ); 103 if( errno || ( endptr != end ) ) /* incomplete parse */ 105 if( errno || ( endptr != end ) ) { /* incomplete parse */ 106 fprintf( stderr, "Unable to parse int [%*.*s]\n", (int)(end-begin), (int)(end-begin), (const char*)begin ); 107 if( errno ) 108 fprintf( stderr, "errno is %d (%s)\n", errno, strerror(errno) ); 109 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 104 110 err = TR_ERROR; 105 else if( val && *(const char*)begin=='0' ) /* no leading zeroes! */ 111 } 112 else if( val && *(const char*)begin=='0' ) { /* no leading zeroes! */ 113 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 106 114 err = TR_ERROR; 115 } 107 116 else { 108 117 *setme_end = end + 1; … … 138 147 139 148 end = memchr( buf, ':', bufend-buf ); 140 if( end == NULL ) 149 if( end == NULL ) { 150 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 141 151 return TR_ERROR; 152 } 142 153 143 154 errno = 0; 144 155 len = strtoul( (const char*)buf, &endptr, 10 ); 145 if( errno || endptr!=end ) 156 if( errno || endptr!=end ) { 157 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 146 158 return TR_ERROR; 147 148 if( (const uint8_t*)end + 1 + len > bufend ) 159 } 160 161 if( (const uint8_t*)end + 1 + len > bufend ) { 162 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 149 163 return TR_ERROR; 164 } 150 165 151 166 *setme_end = end + 1 + len; … … 318 333 tr_bencLoad( const void * buf_in, 319 334 int buflen, 320 tr_benc * setme_benc,335 tr_benc * setme_benc, 321 336 char ** setme_end ) 322 337 { … … 324 339 const uint8_t * end; 325 340 const int ret = tr_bencParse( buf, buf+buflen, setme_benc, &end ); 341 fprintf( stderr, "tried to parse len %d\n", buflen ); 326 342 if( !ret && setme_end ) 327 343 *setme_end = (char*) end; 344 fprintf( stderr, "tr_bencLoad returning %d\n", ret ); 328 345 return ret; 329 346 } -
trunk/libtransmission/makemeta.c
r5127 r5183 205 205 totalRemain = b->totalSize; 206 206 fp = fopen( b->files[fileIndex].filename, "rb" ); 207 if( !fp ) { 208 tr_err( "Unable to open \"%s\": %s", b->files[fileIndex].filename, tr_strerror( errno ) ); 209 tr_free( ret ); 210 b->failed = 1; 211 return NULL; 212 } 207 213 while ( totalRemain ) 208 214 { … … 228 234 if( ++fileIndex < b->fileCount ) { 229 235 fp = fopen( b->files[fileIndex].filename, "rb" ); 236 if( !fp ) { 237 tr_err( "Unable to open \"%s\": %s", b->files[fileIndex].filename, tr_strerror( errno ) ); 238 tr_free( ret ); 239 b->failed = 1; 240 return NULL; 241 } 230 242 } 231 243 } … … 346 358 tr_bencInitInt( val, builder->pieceSize ); 347 359 348 pch = getHashInfo( builder ); 349 val = tr_bencDictAdd( dict, "pieces" ); 350 tr_bencInitStr( val, pch, SHA_DIGEST_LENGTH * builder->pieceCount, 0 ); 360 if( ( pch = getHashInfo( builder ) ) ) { 361 val = tr_bencDictAdd( dict, "pieces" ); 362 tr_bencInitStr( val, pch, SHA_DIGEST_LENGTH * builder->pieceCount, 0 ); 363 } 351 364 352 365 val = tr_bencDictAdd( dict, "private" ); … … 386 399 387 400 /* save the file */ 388 if ( !builder-> abortFlag ) {401 if ( !builder->failed && !builder->abortFlag ) { 389 402 size_t nmemb; 390 403 char * pch = tr_bencSave( &top, &n ); -
trunk/libtransmission/metainfo.c
r5127 r5183 55 55 56 56 success = parseURL( url, host, &port, &path ); 57 58 if( success ) { 57 if( !success ) 58 tr_err( "Can't parse URL \"%s\"", url ); 59 else { 59 60 *setme_host = tr_strdup( host ); 60 61 *setme_port = port; … … 177 178 char buf[4096]; 178 179 180 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 179 181 /* info_hash: urlencoded 20-byte SHA1 hash of the value of the info key 180 182 * from the Metainfo file. Note that the value will be a bencoded … … 186 188 tr_sha1( inf->hash, str, len, NULL ); 187 189 tr_free( str ); 190 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 188 191 } 189 192 else 190 193 { 191 194 tr_err( "info dictionary not found!" ); 192 return TR_EINVALID; 193 } 194 195 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 196 return TR_EINVALID; 197 } 198 199 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 195 200 tr_sha1_to_hex( inf->hashString, inf->hash ); 196 201 savedname( inf->torrent, sizeof( inf->torrent ), inf->hashString, tag ); 202 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 197 203 198 204 /* comment */ … … 201 207 if( val && val->type == TYPE_STR ) 202 208 strlcat_utf8( buf, val->val.s.s, sizeof( buf ), 0 ); 209 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 203 210 tr_free( inf->comment ); 204 211 inf->comment = tr_strdup( buf ); 205 212 213 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 206 214 /* creator */ 207 215 memset( buf, '\0', sizeof( buf ) ); … … 209 217 if( val && val->type == TYPE_STR ) 210 218 strlcat_utf8( buf, val->val.s.s, sizeof( buf ), 0 ); 219 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 211 220 tr_free( inf->creator ); 212 221 inf->creator = tr_strdup( buf ); … … 215 224 inf->dateCreated = 0; 216 225 val = tr_bencDictFind( meta, "creation date" ); 226 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 217 227 if( NULL != val && TYPE_INT == val->type ) 218 228 { 229 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 219 230 inf->dateCreated = val->val.i; 220 231 } … … 223 234 val = tr_bencDictFind( beInfo, "private" ); 224 235 val2 = tr_bencDictFind( meta, "private" ); 236 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 225 237 if( ( NULL != val && ( TYPE_INT != val->type || 0 != val->val.i ) ) || 226 238 ( NULL != val2 && ( TYPE_INT != val2->type || 0 != val2->val.i ) ) ) 227 239 { 240 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 228 241 inf->isPrivate = 1; 229 242 } … … 231 244 /* Piece length */ 232 245 val = tr_bencDictFind( beInfo, "piece length" ); 246 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 233 247 if( NULL == val || TYPE_INT != val->type ) 234 248 { 249 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 235 250 tr_err( "%s \"piece length\" entry", ( val ? "Invalid" : "Missing" ) ); 236 251 goto fail; 237 252 } 253 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 238 254 inf->pieceSize = val->val.i; 239 255 240 256 /* Hashes */ 241 257 val = tr_bencDictFind( beInfo, "pieces" ); 258 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 242 259 if( NULL == val || TYPE_STR != val->type ) 243 260 { 261 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 244 262 tr_err( "%s \"pieces\" entry", ( val ? "Invalid" : "Missing" ) ); 245 263 goto fail; 246 264 } 265 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 247 266 if( val->val.s.i % SHA_DIGEST_LENGTH ) 248 267 { 268 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 249 269 tr_err( "Invalid \"piece\" string (size is %d)", val->val.s.i ); 250 270 goto fail; 251 271 } 272 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 252 273 inf->pieceCount = val->val.s.i / SHA_DIGEST_LENGTH; 253 274 … … 261 282 /* get file or top directory name */ 262 283 val = tr_bencDictFindFirst( beInfo, "name.utf-8", "name", NULL ); 284 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 263 285 if( parseFiles( inf, tr_bencDictFindFirst( beInfo, 264 286 "name.utf-8", "name", NULL ), … … 266 288 tr_bencDictFind( beInfo, "length" ) ) ) 267 289 { 290 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 268 291 goto fail; 269 292 } 293 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 270 294 271 295 if( !inf->fileCount ) 272 296 { 297 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 273 298 tr_err( "Torrent has no files." ); 274 299 goto fail; 275 300 } 301 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 276 302 277 303 if( !inf->totalSize ) 278 304 { 305 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 279 306 tr_err( "Torrent is zero bytes long." ); 280 307 goto fail; 281 308 } 309 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 282 310 283 311 /* TODO add more tests so we don't crash on weird files */ 284 312 313 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 285 314 if( (uint64_t) inf->pieceCount != 286 315 ( inf->totalSize + inf->pieceSize - 1 ) / inf->pieceSize ) 287 316 { 317 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 288 318 tr_err( "Size of hashes and files don't match" ); 289 319 goto fail; 290 320 } 291 321 322 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 292 323 /* get announce or announce-list */ 293 324 if( getannounce( inf, meta ) ) 294 325 { 326 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 295 327 goto fail; 296 328 } 297 329 330 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 298 331 return TR_OK; 299 332 333 fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); 300 334 fail: 301 335 tr_metainfoFree( inf ); … … 500 534 501 535 if( tr_httpParseUrl( pch, -1, &address, &port, &announce ) ) 502 {503 tr_err( "Invalid announce URL (%s)", val->val.s.s );504 536 return TR_EINVALID; 505 } 537 506 538 sublist = calloc( 1, sizeof( sublist[0] ) ); 507 539 sublist[0].address = address; -
trunk/libtransmission/torrent.c
r5155 r5183 419 419 memset( setmeInfo, 0, sizeof( tr_info ) ); 420 420 421 if( !err && tr_ctorGetMetainfo( ctor, &metainfo ) ) 421 if( !err && tr_ctorGetMetainfo( ctor, &metainfo ) ) { 422 fprintf( stderr, "%s:%d can't get metainfo\n", __FILE__, __LINE__ ); 422 423 return TR_EINVALID; 424 } 423 425 424 426 err = tr_metainfoParse( setmeInfo, metainfo, handle->tag ); 427 fprintf( stderr, "%s:%d err %d\n", __FILE__, __LINE__, err ); 425 428 doFree = !err && ( setmeInfo == &tmp ); 426 429 427 430 if( !err && hashExists( handle, setmeInfo->hash ) ) { 428 431 err = TR_EDUPLICATE; 432 fprintf( stderr, "%s:%d err %d\n", __FILE__, __LINE__, err ); 429 433 doFree = 1; 430 434 } … … 433 437 tr_metainfoFree( setmeInfo ); 434 438 439 fprintf( stderr, "%s:%d err %d\n", __FILE__, __LINE__, err ); 435 440 return err; 436 441 } … … 446 451 447 452 err = tr_torrentParse( handle, ctor, &tmpInfo ); 453 fprintf( stderr, "%s:%d, err %d\n", __FILE__, __LINE__, err ); 448 454 if( !err ) { 449 455 tor = tr_new0( tr_torrent, 1 ); 450 456 tor->info = tmpInfo; 451 457 torrentRealInit( handle, tor, ctor ); 458 fprintf( stderr, "%s:%d, tor %p\n", __FILE__, __LINE__, tor ); 452 459 } else if( setmeError ) { 460 fprintf( stderr, "err is %d\n", err ); 453 461 *setmeError = err; 454 462 } 455 463 464 fprintf( stderr, "returning torrent %p\n", tor ); 456 465 return tor; 457 466 }
Note: See TracChangeset
for help on using the changeset viewer.