コード例 #1
0
ファイル: utils-test.c プロジェクト: Elbandi/transmission
static int
test_base64 (void)
{
  int len;
  char *in, *out;

  /* base64 */
  out = tr_base64_encode ("YOYO!", -1, &len);
  check_streq ("WU9ZTyE=", out);
  check_int_eq (8, len);
  in = tr_base64_decode (out, -1, &len);
  check_streq ("YOYO!", in);
  check_int_eq (5, len);
  tr_free (in);
  tr_free (out);
  out = tr_base64_encode (NULL, 0, &len);
  check (out == NULL);
  check_int_eq (0, len);

  return 0;
}
コード例 #2
0
ファイル: upnp.c プロジェクト: AllardJ/Tomato
void
tr_upnpClose (tr_upnp * handle)
{
    assert (!handle->isMapped);
    assert ((handle->state == TR_UPNP_IDLE)
          || (handle->state == TR_UPNP_ERR)
          || (handle->state == TR_UPNP_DISCOVER));

    if (handle->hasDiscovered)
        FreeUPNPUrls (&handle->urls);
    tr_free (handle);
}
コード例 #3
0
ファイル: file-test.c プロジェクト: Prodito/Torrentor
static bool
create_hardlink (const char * dst_path, const char * src_path)
{
#ifndef _WIN32

  return link (src_path, dst_path) != -1;

#else

  wchar_t * wide_src_path = tr_win32_utf8_to_native (src_path, -1);
  wchar_t * wide_dst_path = tr_win32_utf8_to_native (dst_path, -1);

  bool ret = CreateHardLinkW (wide_dst_path, wide_src_path, NULL);

  tr_free (wide_dst_path);
  tr_free (wide_src_path);

  return ret;

#endif
}
コード例 #4
0
ファイル: resume.c プロジェクト: dazwiafl/transmission
/* TODO: resume peers6 */
static void
savePeers( tr_benc *          dict,
           const tr_torrent * tor )
{
    tr_pex *  pex = NULL;
    const int count = tr_peerMgrGetPeers( tor->session->peerMgr,
                                          tor->info.hash, &pex );

    if( count > 0 )
        tr_bencDictAddRaw( dict, KEY_PEERS, pex, sizeof( tr_pex ) * count );
    tr_free( pex );
}
コード例 #5
0
ファイル: webseed.c プロジェクト: HumbleRepose/transmission
static void
webseed_free( struct tr_webseed * w )
{
    tr_torrent * tor = tr_torrentFindFromId( w->session, w->torrent_id );
    const tr_info * inf = tr_torrentInfo( tor );
    tr_file_index_t i;

    for( i=0; i<inf->fileCount; ++i )
        tr_free( w->file_urls[i] );
    tr_free( w->file_urls );

    /* webseed destruct */
    event_free( w->timer );
    tr_bandwidthDestruct( &w->bandwidth );
    tr_free( w->base_url );

    /* parent class destruct */
    tr_peerDestruct( tor, &w->parent );

    tr_free( w );
}
コード例 #6
0
ファイル: ptrarray.c プロジェクト: miracle2k/transmission
void
tr_ptrArrayDestruct( tr_ptrArray * p, PtrArrayForeachFunc func )
{
    assert( p );
    assert( p->items || !p->n_items );

    if( func )
        tr_ptrArrayForeach( p, func );

    tr_free( p->items );

    memset( p, ~0, sizeof( tr_ptrArray ) );
}
コード例 #7
0
ファイル: platform.c プロジェクト: dreamcat4/transmission
static ThreadFuncReturnType
ThreadFunc( void * _t )
{
    tr_thread * t = _t;

    t->func( t->arg );

    tr_free( t );
#ifdef WIN32
    _endthreadex( 0 );
    return 0;
#endif
}
コード例 #8
0
void
libttest_session_close (tr_session * session)
{
  char * sandbox;

  sandbox = tr_strdup (tr_sessionGetConfigDir (session));
  tr_sessionClose (session);
  tr_logFreeQueue (tr_logGetQueue ());
  session = NULL;

  libtest_sandbox_destroy (sandbox);
  tr_free (sandbox);
}
コード例 #9
0
static tr_bool
getfile( char ** setme, const char * root, tr_benc * path )
{
    tr_bool success = FALSE;

    if( tr_bencIsList( path ) )
    {
        int i;
        char * tmp;
        const int n = tr_bencListSize( path );
        struct evbuffer * buf = evbuffer_new( );

        evbuffer_add( buf, root, strlen( root ) );
        for( i = 0; i < n; ++i )
        {
            const char * str;
            if( tr_bencGetStr( tr_bencListChild( path, i ), &str ) )
            {
                evbuffer_add( buf, TR_PATH_DELIMITER_STR, 1 );
                evbuffer_add( buf, str, strlen( str ) );
            }
        }

        tmp = evbuffer_free_to_str( buf );
        *setme = tr_utf8clean( tmp, -1 );
        tr_free( tmp );
        /* fprintf( stderr, "[%s]\n", *setme ); */
        success = TRUE;
    }

    if( ( *setme != NULL ) && path_is_suspicious( *setme ) )
    {
        tr_free( *setme );
        *setme = NULL;
        success = FALSE;
    }

    return success;
}
コード例 #10
0
ファイル: torrent-ctor.c プロジェクト: dreamcat4/transmission
void
tr_ctorSetFilesWanted( tr_ctor                * ctor,
                       const tr_file_index_t  * files,
                       tr_file_index_t          fileCount,
                       tr_bool                  wanted )
{
    tr_file_index_t ** myfiles = wanted ? &ctor->want : &ctor->notWant;
    tr_file_index_t * mycount = wanted ? &ctor->wantSize : &ctor->notWantSize;

    tr_free( *myfiles );
    *myfiles = tr_memdup( files, sizeof(tr_file_index_t)*fileCount );
    *mycount = fileCount;
}
コード例 #11
0
ファイル: cache.c プロジェクト: marltu/transmission
static int
flushContiguous( tr_cache * cache, int pos, int n )
{
    int i;
    int err = 0;
    uint8_t * buf = tr_new( uint8_t, n * MAX_BLOCK_SIZE );
    uint8_t * walk = buf;
    struct cache_block ** blocks = (struct cache_block**) tr_ptrArrayBase( &cache->blocks );

    struct cache_block * b = blocks[pos];
    tr_torrent * tor             = b->tor;
    const tr_piece_index_t piece = b->piece;
    const uint32_t offset        = b->offset;

//fprintf( stderr, "flushing %d contiguous blocks [%d-%d) from cache to disk\n", n, pos, n+pos );

    for( i=pos; i<pos+n; ++i ) {
        b = blocks[i];
        memcpy( walk, b->buf, b->length );
        walk += b->length;
        tr_free( b->buf );
        tr_free( b );
    }
    tr_ptrArrayErase( &cache->blocks, pos, pos+n );

#if 0
    tr_tordbg( tor, "Writing to disk piece %d, offset %d, len %d", (int)piece, (int)offset, (int)(walk-buf) );
    tr_ndbg( MY_NAME, "Removing %d blocks from cache, rank: %d - %d left", n, rank, tr_ptrArraySize(&cache->blocks) );
    fprintf( stderr, "%s - Writing to disk piece %d, offset %d, len %d\n", tr_torrentName(tor), (int)piece, (int)offset, (int)(walk-buf) );
    fprintf( stderr, "%s - Removing %d blocks from cache; %d left\n", MY_NAME, n, tr_ptrArraySize(&cache->blocks) );
#endif

    err = tr_ioWrite( tor, piece, offset, walk-buf, buf );
    tr_free( buf );

    ++cache->disk_writes;
    cache->disk_write_bytes += walk-buf;
    return err;
}
コード例 #12
0
ファイル: inout.c プロジェクト: dazwiafl/transmission
/* returns 0 on success, or an errno on failure */
static int
readOrWriteBytes( const tr_torrent * tor,
                  int                ioMode,
                  tr_file_index_t    fileIndex,
                  uint64_t           fileOffset,
                  void *             buf,
                  size_t             buflen )
{
    const tr_info * info = &tor->info;
    const tr_file * file = &info->files[fileIndex];

    typedef size_t ( *iofunc )( int, void *, size_t );
    iofunc          func = ioMode ==
                           TR_IO_READ ? (iofunc)read : (iofunc)write;
    char          * path;
    struct stat     sb;
    int             fd = -1;
    int             err;
    int             fileExists;

    assert( tor->downloadDir && *tor->downloadDir );
    assert( fileIndex < info->fileCount );
    assert( !file->length || ( fileOffset < file->length ) );
    assert( fileOffset + buflen <= file->length );

    path = tr_buildPath( tor->downloadDir, file->name, NULL );
    fileExists = !stat( path, &sb );
    tr_free( path );

    if( !file->length )
        return 0;

    if( ( ioMode == TR_IO_READ ) && !fileExists ) /* does file exist? */
        err = errno;
    else if( ( fd = tr_fdFileCheckout ( tor->downloadDir, file->name, ioMode == TR_IO_WRITE, !file->dnd, file->length ) ) < 0 )
        err = errno;
    else if( tr_lseek( fd, (int64_t)fileOffset, SEEK_SET ) == -1 )
        err = errno;
    else if( func( fd, buf, buflen ) != buflen )
        err = errno;
    else
        err = 0;

    if( ( !err ) && ( !fileExists ) && ( ioMode == TR_IO_WRITE ) )
        tr_statsFileCreated( tor->session );

    if( fd >= 0 )
        tr_fdFileReturn( fd );

    return err;
}
コード例 #13
0
static int
test_numbers (void)
{
  int i;
  int count;
  int * numbers;

  numbers = tr_parseNumberRange ("1-10,13,16-19", TR_BAD_SIZE, &count);
  check_int_eq (15, count);
  check_int_eq (1, numbers[0]);
  check_int_eq (6, numbers[5]);
  check_int_eq (10, numbers[9]);
  check_int_eq (13, numbers[10]);
  check_int_eq (16, numbers[11]);
  check_int_eq (19, numbers[14]);
  tr_free (numbers);

  numbers = tr_parseNumberRange ("1-5,3-7,2-6", TR_BAD_SIZE, &count);
  check (count == 7);
  check (numbers != NULL);
  for (i=0; i<count; ++i)
    check_int_eq (i+1, numbers[i]);
  tr_free (numbers);

  numbers = tr_parseNumberRange ("1-Hello", TR_BAD_SIZE, &count);
  check_int_eq (0, count);
  check (numbers == NULL);

  numbers = tr_parseNumberRange ("1-", TR_BAD_SIZE, &count);
  check_int_eq (0, count);
  check (numbers == NULL);

  numbers = tr_parseNumberRange ("Hello", TR_BAD_SIZE, &count);
  check_int_eq (0, count);
  check (numbers == NULL);

  return 0;
}
コード例 #14
0
ファイル: daemon.c プロジェクト: jaseg/transmission
static void
onFileAdded (tr_session * session, const char * dir, const char * file)
{
    char * filename = tr_buildPath (dir, file, NULL);
    tr_ctor * ctor = tr_ctorNew (session);
    int err = tr_ctorSetMetainfoFromFile (ctor, filename);

    if (!err)
    {
        tr_torrentNew (ctor, &err, NULL);

        if (err == TR_PARSE_ERR)
            tr_logAddError ("Error parsing .torrent file \"%s\"", file);
        else
        {
            bool trash = false;
            int test = tr_ctorGetDeleteSource (ctor, &trash);

            tr_logAddInfo ("Parsing .torrent file successful \"%s\"", file);

            if (!test && trash)
            {
                tr_logAddInfo ("Deleting input .torrent file \"%s\"", file);
                if (tr_remove (filename))
                    tr_logAddError ("Error deleting .torrent file: %s", tr_strerror (errno));
            }
            else
            {
                char * new_filename = tr_strdup_printf ("%s.added", filename);
                tr_rename (filename, new_filename);
                tr_free (new_filename);
            }
        }
    }

    tr_ctorFree (ctor);
    tr_free (filename);
}
コード例 #15
0
ファイル: file-test.c プロジェクト: Prodito/Torrentor
static bool
path_contains_no_symlinks (const char * path)
{
  const char * p = path;

  while (*p != '\0')
    {
      tr_sys_path_info info;
      char * pathPart;
      const char * slashPos = strchr (p, '/');

#ifdef _WIN32

      const char * backslashPos = strchr (p, '\\');
      if (slashPos == NULL || (backslashPos != NULL && backslashPos < slashPos))
        slashPos = backslashPos;

#endif

      if (slashPos == NULL)
        slashPos = p + strlen (p) - 1;

      pathPart = tr_strndup (path, slashPos - path + 1);

      if (!tr_sys_path_get_info (pathPart, TR_SYS_PATH_NO_FOLLOW, &info, NULL) ||
          (info.type != TR_SYS_PATH_IS_FILE && info.type != TR_SYS_PATH_IS_DIRECTORY))
        {
          tr_free (pathPart);
          return false;
        }

      tr_free (pathPart);

      p = slashPos + 1;
    }

  return true;
}
コード例 #16
0
ファイル: rename-test.c プロジェクト: xzcvczx/transmission
static bool testFileExistsAndConsistsOfThisString(tr_torrent const* tor, tr_file_index_t fileIndex, char const* str)
{
    char* path;
    size_t const str_len = strlen(str);
    bool success = false;

    path = tr_torrentFindFile(tor, fileIndex);

    if (path != NULL)
    {
        TR_ASSERT(tr_sys_path_exists(path, NULL));

        size_t contents_len;
        uint8_t* contents = tr_loadFile(path, &contents_len, NULL);

        success = contents != NULL && str_len == contents_len && memcmp(contents, str, contents_len) == 0;

        tr_free(contents);
        tr_free(path);
    }

    return success;
}
コード例 #17
0
ファイル: fastresume.c プロジェクト: fangang190/canary
static uint8_t*
loadResumeFile( const tr_torrent * tor,
                size_t *           len )
{
    uint8_t *    ret = NULL;
    const char * cacheDir = tr_getResumeDir( tor->session );
    const char * hash = tor->info.hashString;

    if( !ret && tor->session->tag )
    {
        char * path = tr_strdup_printf( "%s" TR_PATH_DELIMITER_STR "%s-%s", cacheDir, hash, tor->session->tag );
        ret = tr_loadFile( path, len );
        tr_free( path );
    }
    if( !ret )
    {
        char * path = tr_buildPath( cacheDir, hash, NULL );
        ret = tr_loadFile( path, len );
        tr_free( path );
    }

    return ret;
}
コード例 #18
0
bool tr_sha1_final(tr_sha1_ctx_t handle, uint8_t* hash)
{
    bool ret = true;

    if (hash != NULL)
    {
        TR_ASSERT(handle != NULL);

        ret = check_result(API(ShaFinal)(handle, hash));
    }

    tr_free(handle);
    return ret;
}
コード例 #19
0
ファイル: resume.c プロジェクト: HumbleRepose/transmission
static void
bitfieldToBenc( const tr_bitfield * b, tr_benc * benc )
{
    if( tr_bitfieldHasAll( b ) )
        tr_bencInitStr( benc, "all", 3 );
    else if( tr_bitfieldHasNone( b ) )
        tr_bencInitStr( benc, "none", 4 );
    else {
        size_t byte_count = 0;
        uint8_t * raw = tr_bitfieldGetRaw( b, &byte_count );
        tr_bencInitRaw( benc, raw, byte_count );
        tr_free( raw );
    }
}
コード例 #20
0
ファイル: resume.c プロジェクト: xzcvczx/transmission
static void savePeers(tr_variant* dict, tr_torrent const* tor)
{
    int count;
    tr_pex* pex;

    count = tr_peerMgrGetPeers((tr_torrent*)tor, &pex, TR_AF_INET, TR_PEERS_INTERESTING, MAX_REMEMBERED_PEERS);

    if (count > 0)
    {
        tr_variantDictAddRaw(dict, TR_KEY_peers2, pex, sizeof(tr_pex) * count);
    }

    tr_free(pex);

    count = tr_peerMgrGetPeers((tr_torrent*)tor, &pex, TR_AF_INET6, TR_PEERS_INTERESTING, MAX_REMEMBERED_PEERS);

    if (count > 0)
    {
        tr_variantDictAddRaw(dict, TR_KEY_peers2_6, pex, sizeof(tr_pex) * count);
    }

    tr_free(pex);
}
コード例 #21
0
ファイル: blocklist.c プロジェクト: Mikayex/transmission
static void blocklistLoad(tr_blocklistFile* b)
{
    tr_sys_file_t fd;
    uint64_t byteCount;
    tr_sys_path_info info;
    char* base;
    tr_error* error = NULL;
    char const* err_fmt = _("Couldn't read \"%1$s\": %2$s");

    blocklistClose(b);

    if (!tr_sys_path_get_info(b->filename, 0, &info, NULL))
    {
        return;
    }

    byteCount = info.size;

    if (byteCount == 0)
    {
        return;
    }

    fd = tr_sys_file_open(b->filename, TR_SYS_FILE_READ, 0, &error);

    if (fd == TR_BAD_SYS_FILE)
    {
        tr_logAddError(err_fmt, b->filename, error->message);
        tr_error_free(error);
        return;
    }

    b->rules = tr_sys_file_map_for_reading(fd, 0, byteCount, &error);

    if (b->rules == NULL)
    {
        tr_logAddError(err_fmt, b->filename, error->message);
        tr_sys_file_close(fd, NULL);
        tr_error_free(error);
        return;
    }

    b->fd = fd;
    b->byteCount = byteCount;
    b->ruleCount = byteCount / sizeof(struct tr_ipv4_range);

    base = tr_sys_path_basename(b->filename, NULL);
    tr_logAddInfo(_("Blocklist \"%s\" contains %zu entries"), base, b->ruleCount);
    tr_free(base);
}
コード例 #22
0
ファイル: fdlimit.c プロジェクト: dazwiafl/transmission
void
tr_fdClose( void )
{
    int i = 0;

    for( i = 0; i < TR_MAX_OPEN_FILES; ++i )
        if( fileIsOpen( &gFd->open[i] ) )
            TrCloseFile( i );

    tr_lockFree( gFd->lock );

    tr_free( gFd );
    gFd = NULL;
}
コード例 #23
0
ファイル: stats.c プロジェクト: dmkc/transmission
static void
loadCumulativeStats( const tr_session * session,
                     tr_session_stats * setme )
{
    tr_benc top;
    char * filename;
    bool loaded = false;

    filename = getFilename( session );
    loaded = !tr_bencLoadFile( &top, TR_FMT_JSON, filename );
    tr_free( filename );

    if( !loaded )
    {
        filename = getOldFilename( session );
        loaded = !tr_bencLoadFile( &top, TR_FMT_BENC, filename );
        tr_free( filename );
    }

    if( loaded )
    {
        int64_t i;

        if( tr_bencDictFindInt( &top, "downloaded-bytes", &i ) )
            setme->downloadedBytes = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "files-added", &i ) )
            setme->filesAdded = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "seconds-active", &i ) )
            setme->secondsActive = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "session-count", &i ) )
            setme->sessionCount = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "uploaded-bytes", &i ) )
            setme->uploadedBytes = (uint64_t) i;

        tr_bencFree( &top );
    }
}
コード例 #24
0
ファイル: web.c プロジェクト: Longinus00/transmission
static CURL *
createEasy( tr_session * s, struct tr_web_task * task )
{
    const tr_address * addr;
    CURL * e = curl_easy_init( );
    const long verbose = getenv( "TR_CURL_VERBOSE" ) != NULL;

    if( !task->range && s->isProxyEnabled ) {
        const long proxyType = getCurlProxyType( s->proxyType );
        curl_easy_setopt( e, CURLOPT_PROXY, s->proxy );
        curl_easy_setopt( e, CURLOPT_PROXYAUTH, CURLAUTH_ANY );
        curl_easy_setopt( e, CURLOPT_PROXYPORT, s->proxyPort );
        curl_easy_setopt( e, CURLOPT_PROXYTYPE, proxyType );
    }

    if( !task->range && s->isProxyAuthEnabled ) {
        char * str = tr_strdup_printf( "%s:%s", s->proxyUsername,
                                                s->proxyPassword );
        curl_easy_setopt( e, CURLOPT_PROXYUSERPWD, str );
        tr_free( str );
    }

    curl_easy_setopt( e, CURLOPT_AUTOREFERER, 1L );
    curl_easy_setopt( e, CURLOPT_ENCODING, "gzip;q=1.0, deflate, identity" );
    curl_easy_setopt( e, CURLOPT_FOLLOWLOCATION, 1L );
    curl_easy_setopt( e, CURLOPT_MAXREDIRS, -1L );
    curl_easy_setopt( e, CURLOPT_NOSIGNAL, 1L );
    curl_easy_setopt( e, CURLOPT_PRIVATE, task );
#ifdef USE_LIBCURL_SOCKOPT
    curl_easy_setopt( e, CURLOPT_SOCKOPTFUNCTION, sockoptfunction );
    curl_easy_setopt( e, CURLOPT_SOCKOPTDATA, task );
#endif
    curl_easy_setopt( e, CURLOPT_SSL_VERIFYHOST, 0L );
    curl_easy_setopt( e, CURLOPT_SSL_VERIFYPEER, 0L );
    curl_easy_setopt( e, CURLOPT_TIMEOUT, getTimeoutFromURL( task->url ) );
    curl_easy_setopt( e, CURLOPT_URL, task->url );
    curl_easy_setopt( e, CURLOPT_USERAGENT, TR_NAME "/" SHORT_VERSION_STRING );
    curl_easy_setopt( e, CURLOPT_VERBOSE, verbose );
    curl_easy_setopt( e, CURLOPT_WRITEDATA, task );
    curl_easy_setopt( e, CURLOPT_WRITEFUNCTION, writeFunc );

    if(( addr = tr_sessionGetPublicAddress( s, TR_AF_INET )))
        curl_easy_setopt( e, CURLOPT_INTERFACE, tr_ntop_non_ts( addr ) );

    if( task->range )
        curl_easy_setopt( e, CURLOPT_RANGE, task->range );

    return e;
}
コード例 #25
0
ファイル: session.c プロジェクト: liesen/transmission-horn
void
tr_sessionGetSettings( tr_session * s, struct tr_benc * d )
{
    int i, n=0;
    char * freeme[16];

    assert( tr_bencIsDict( d ) );

    tr_bencDictReserve( d, 30 );
    tr_bencDictAddInt( d, TR_PREFS_KEY_BLOCKLIST_ENABLED,        tr_blocklistIsEnabled( s ) );
    tr_bencDictAddStr( d, TR_PREFS_KEY_DOWNLOAD_DIR,             s->downloadDir );
    tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED,                   tr_sessionGetSpeedLimit( s, TR_DOWN ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_DSPEED_ENABLED,           tr_sessionIsSpeedLimitEnabled( s, TR_DOWN ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_ENCRYPTION,               s->encryptionMode );
    tr_bencDictAddInt( d, TR_PREFS_KEY_LAZY_BITFIELD,            s->useLazyBitfield );
    tr_bencDictAddInt( d, TR_PREFS_KEY_MSGLEVEL,                 tr_getMessageLevel( ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_OPEN_FILE_LIMIT,          s->openFileLimit );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL,        tr_sessionGetPeerLimit( s ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_LIMIT_TORRENT,       s->peerLimitPerTorrent );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT,                tr_sessionGetPeerPort( s ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT_RANDOM_ENABLED, s->isPortRandom );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW,     s->randomPortLow );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH,    s->randomPortHigh );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_SOCKET_TOS,          s->peerSocketTOS );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PEX_ENABLED,              s->isPexEnabled );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PORT_FORWARDING,          tr_sessionIsPortForwardingEnabled( s ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PREALLOCATION,            s->preallocationMode );
    tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY,                    s->proxy );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_AUTH_ENABLED,       s->isProxyAuthEnabled );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_ENABLED,            s->isProxyEnabled );
    tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY_PASSWORD,           s->proxyPassword );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_PORT,               s->proxyPort );
    tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_TYPE,               s->proxyType );
    tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY_USERNAME,           s->proxyUsername );
    tr_bencDictAddDouble( d, TR_PREFS_KEY_RATIO,                 s->desiredRatio );
    tr_bencDictAddInt( d, TR_PREFS_KEY_RATIO_ENABLED,            s->isRatioLimited );
    tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_AUTH_REQUIRED,        tr_sessionIsRPCPasswordEnabled( s ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_ENABLED,              tr_sessionIsRPCEnabled( s ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_PORT,                 tr_sessionGetRPCPort( s ) );
    tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_USERNAME,             freeme[n++] = tr_sessionGetRPCUsername( s ) );
    tr_bencDictAddStr( d, TR_PREFS_KEY_RPC_WHITELIST,            freeme[n++] = tr_sessionGetRPCWhitelist( s ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_RPC_WHITELIST_ENABLED,    tr_sessionGetRPCWhitelistEnabled( s ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED,                   tr_sessionGetSpeedLimit( s, TR_UP ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_ENABLED,           tr_sessionIsSpeedLimitEnabled( s, TR_UP ) );
    tr_bencDictAddInt( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, s->uploadSlotsPerTorrent );

    for( i=0; i<n; ++i )
        tr_free( freeme[i] );
}
コード例 #26
0
ファイル: media_stm.c プロジェクト: dulton/nampu
static __inline__ void
__clear_stm(stm_info *stm)
{
	int32_t fileds;
	stm_into_pri *f;

	for (fileds = 0; fileds < stm->fields; ++fileds)
	{
		f = &stm->pri_fields[fileds];
		if (f->data)
		{
			tr_free(f->data, f->size);
		}
	}
}
コード例 #27
0
static int
test_quickfindFirst (void)
{
  size_t i;
  const size_t k = 10;
  const size_t n = 100;
  const size_t n_trials = 1000;
  int * buf = tr_new (int, n);

  for (i=0; i<n_trials; ++i)
    check_int_eq (0, test_quickFindFirst_Iteration (k, n, buf, 100));

  tr_free (buf);
  return 0;
}
コード例 #28
0
ファイル: stats.c プロジェクト: cfpp2p/Transmission-basin
static void
loadCumulativeStats (const tr_session * session, tr_session_stats * setme)
{
  tr_variant top;
  char * filename;
  bool loaded = false;

  filename = getFilename (session);
  loaded = !tr_variantFromFile (&top, TR_VARIANT_FMT_JSON, filename);
  tr_free (filename);

  if (!loaded)
    {
      filename = getOldFilename (session);
      loaded = !tr_variantFromFile (&top, TR_VARIANT_FMT_BENC, filename);
      tr_free (filename);
    }

  if (loaded)
    {
      int64_t i;

      if (tr_variantDictFindInt (&top, TR_KEY_downloaded_bytes, &i))
        setme->downloadedBytes = (uint64_t) i;
      if (tr_variantDictFindInt (&top, TR_KEY_files_added, &i))
        setme->filesAdded = (uint64_t) i;
      if (tr_variantDictFindInt (&top, TR_KEY_seconds_active, &i))
        setme->secondsActive = (uint64_t) i;
      if (tr_variantDictFindInt (&top, TR_KEY_session_count, &i))
        setme->sessionCount = (uint64_t) i;
      if (tr_variantDictFindInt (&top, TR_KEY_uploaded_bytes, &i))
        setme->uploadedBytes = (uint64_t) i;

      tr_variantFree (&top);
    }
}
コード例 #29
0
char*
tr_metainfoGetBasename( const tr_info * inf )
{
    char *ret, *pch, *name;

    name = tr_strdup( inf->name );
    for( pch=name; pch && *pch; ++pch )
        if( *pch == '/' )
            *pch = '_';

    ret = tr_strdup_printf( "%s.%16.16s", name, inf->hashString );

    tr_free( name );
    return ret;
}
コード例 #30
0
ファイル: fastresume.c プロジェクト: fangang190/canary
static uint64_t
parseDownloadDir( tr_torrent *    tor,
                  const uint8_t * buf,
                  uint32_t        len )
{
    uint64_t ret = 0;

    if( buf && *buf && len )
    {
        tr_free( tor->downloadDir );
        tor->downloadDir = tr_strndup( (char*)buf, len );
        ret = TR_FR_DOWNLOAD_DIR;
    }

    return ret;
}