Changeset 7706


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

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

Location:
trunk/libtransmission
Files:
3 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    }
  • trunk/libtransmission/rpc-server.h

    r7658 r7706  
    2121
    2222tr_rpc_server * tr_rpcInit( tr_session  * session,
    23                             tr_bool       isEnabled,
    24                             tr_port       port,
    25                             tr_bool       isWhitelistEnabled,
    26                             const char  * whitelist,
    27                             tr_bool       isPasswordEnabled,
    28                             const char  * username,
    29                             const char  * password );
     23                            tr_benc  * settings );
    3024
    3125void            tr_rpcClose( tr_rpc_server ** freeme );
  • trunk/libtransmission/session.c

    r7658 r7706  
    370370    tr_session * session;
    371371    char * filename;
    372     int64_t rpc_enabled, whitelist_enabled, rpc_auth_enabled, rpc_port;
    373     const char * whitelist = NULL, *rpc_passwd = NULL, *rpc_username = NULL;
    374372
    375373    assert( tr_bencIsDict( clientSettings ) );
     
    528526
    529527    session->web = tr_webInit( session );
    530     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_ENABLED, &rpc_enabled )
    531          && tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_PORT, &rpc_port )
    532          && tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, &whitelist_enabled )
    533          && tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &rpc_auth_enabled )
    534          && tr_bencDictFindStr( &settings, TR_PREFS_KEY_RPC_WHITELIST, &whitelist )
    535          && tr_bencDictFindStr( &settings, TR_PREFS_KEY_RPC_USERNAME, &rpc_username )
    536          && tr_bencDictFindStr( &settings, TR_PREFS_KEY_RPC_PASSWORD, &rpc_passwd );
    537     assert( found );
    538     session->rpcServer = tr_rpcInit( session, rpc_enabled, rpc_port, whitelist_enabled, whitelist,
    539                                      rpc_auth_enabled, rpc_username, rpc_passwd );
     528    session->rpcServer = tr_rpcInit( session, &settings );
    540529
    541530    metainfoLookupRescan( session );
Note: See TracChangeset for help on using the changeset viewer.