Ignore:
Timestamp:
Jan 13, 2009, 4:35:06 PM (13 years ago)
Author:
charles
Message:

(trunk libT) Clean up RPC server initialization (wereHamster)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/rpc-server.c

    r7658 r7706  
    709709tr_rpc_server *
    710710tr_rpcInit( tr_session  * session,
    711             tr_bool       isEnabled,
    712             tr_port       port,
    713             tr_bool       isWhitelistEnabled,
    714             const char  * whitelist,
    715             tr_bool       isPasswordEnabled,
    716             const char  * username,
    717             const char  * password )
     711            tr_benc * settings )
    718712{
    719713    tr_rpc_server * s;
     714    tr_bool found;
     715    int64_t i;
     716    const char *str;
    720717
    721718    s = tr_new0( tr_rpc_server, 1 );
    722719    s->session = session;
    723     s->port = port;
    724     s->username = tr_strdup( username );
    725     s->password = tr_strdup( password );
    726     s->isWhitelistEnabled = isWhitelistEnabled;
    727     s->isPasswordEnabled = isPasswordEnabled;
    728     s->isEnabled = isEnabled != 0;
    729     tr_rpcSetWhitelist( s, whitelist ? whitelist : "127.0.0.1" );
     720
     721    found = tr_bencDictFindInt( settings, TR_PREFS_KEY_RPC_ENABLED, &i );
     722    assert( found );
     723    s->isEnabled = i != 0;
     724
     725    found = tr_bencDictFindInt( settings, TR_PREFS_KEY_RPC_PORT, &i );
     726    assert( found );
     727    s->port = i;
     728
     729    found = tr_bencDictFindInt( settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, &i );
     730    assert( found );
     731    s->isWhitelistEnabled = i != 0;
     732
     733    found = tr_bencDictFindInt( settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &i );
     734    assert( found );
     735    s->isPasswordEnabled = i != 0;
     736
     737    found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_WHITELIST, &str );
     738    assert( found );
     739    tr_rpcSetWhitelist( s, str ? str : "127.0.0.1" );
     740
     741    found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_USERNAME, &str );
     742    assert( found );
     743    s->username = tr_strdup( str );
     744
     745    found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_PASSWORD, &str );
     746    assert( found );
     747    s->password = tr_strdup( str );
    730748
    731749#ifdef HAVE_ZLIB
     
    736754#endif
    737755
    738     if( isEnabled )
     756    if( s->isEnabled )
     757    {
     758        tr_ninf( MY_NAME, _( "Serving RPC and Web requests on port %d" ), (int) s->port );
    739759        tr_runInEventThread( session, startServer, s );
    740760
    741     if( isEnabled )
    742     {
    743         tr_ninf( MY_NAME, _( "Serving RPC and Web requests on port %d" ), (int)port );
    744 
    745         if( isWhitelistEnabled )
     761        if( s->isWhitelistEnabled )
    746762            tr_ninf( MY_NAME, _( "Whitelist enabled" ) );
    747763
    748         if( isPasswordEnabled )
     764        if( s->isPasswordEnabled )
    749765            tr_ninf( MY_NAME, _( "Password required" ) );
    750766    }
Note: See TracChangeset for help on using the changeset viewer.