int tr_ctorSetMetainfo( tr_ctor * ctor, const uint8_t * metainfo, size_t len ) { int err; clearMetainfo( ctor ); err = tr_bencLoad( metainfo, len, &ctor->metainfo, NULL ); ctor->isSet_metainfo = !err; return err; }
int tr_ctorSetMetainfo (tr_ctor * ctor, const uint8_t * metainfo, size_t len) { int err; clearMetainfo (ctor); err = tr_variantFromBenc (&ctor->metainfo, metainfo, len); ctor->isSet_metainfo = !err; return err; }
int tr_ctorSetMetainfoFromFile( tr_ctor * ctor, const char * filename ) { uint8_t * metainfo; size_t len; int err; metainfo = tr_loadFile( filename, &len ); if( metainfo && len ) err = tr_ctorSetMetainfo( ctor, metainfo, len ); else { clearMetainfo( ctor ); err = 1; } setSourceFile( ctor, filename ); /* if no `name' field was set, then set it from the filename */ if( ctor->isSet_metainfo ) { tr_benc * info; if( tr_bencDictFindDict( &ctor->metainfo, "info", &info ) ) { const char * name; if( !tr_bencDictFindStr( info, "name.utf-8", &name ) ) if( !tr_bencDictFindStr( info, "name", &name ) ) name = NULL; if( !name || !*name ) { char * base = tr_basename( filename ); tr_bencDictAddStr( info, "name", base ); tr_free( base ); } } } tr_free( metainfo ); return err; }