Changeset 6697


Ignore:
Timestamp:
Sep 3, 2008, 7:59:09 PM (13 years ago)
Author:
charles
Message:

#1209: shttpd crash when setting port to one already in use

File:
1 edited

Legend:

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

    r6645 r6697  
    3939struct tr_rpc_server
    4040{
     41    unsigned int isEnabled          : 1;
     42    unsigned int isPasswordEnabled  : 1;
    4143    int port;
    4244    time_t lastRequestTime;
     
    4446    tr_handle * session;
    4547    struct event timer;
    46     int isPasswordEnabled;
    4748    char * username;
    4849    char * password;
     
    409410        argv[argc] = NULL; /* shttpd_init() wants it null-terminated */
    410411
    411         server->ctx = shttpd_init( argc, argv );
    412         shttpd_register_uri( server->ctx, "/transmission/rpc", handle_rpc, server );
    413         shttpd_register_uri( server->ctx, "/transmission/upload", handle_upload, server );
    414         shttpd_register_uri( server->ctx, "/", handle_root, server );
    415 
    416         evtimer_set( &server->timer, rpcPulse, server );
    417         evtimer_add( &server->timer, &tv );
     412        if(( server->ctx = shttpd_init( argc, argv )))
     413        {
     414            shttpd_register_uri( server->ctx, "/transmission/rpc", handle_rpc, server );
     415            shttpd_register_uri( server->ctx, "/transmission/upload", handle_upload, server );
     416            shttpd_register_uri( server->ctx, "/", handle_root, server );
     417
     418            evtimer_set( &server->timer, rpcPulse, server );
     419            evtimer_add( &server->timer, &tv );
     420        }
    418421
    419422        for( i=0; i<argc; ++i )
     
    440443tr_rpcSetEnabled( tr_rpc_server * server, int isEnabled )
    441444{
    442     if( !isEnabled && server->ctx )
     445    server->isEnabled = isEnabled != 0;
     446
     447    if( !isEnabled )
    443448        stopServer( server );
    444 
    445     if( isEnabled && !server->ctx )
     449    else
    446450        startServer( server );
    447451}
     
    460464        server->port = port;
    461465
    462         if( server->ctx )
     466        if( server->isEnabled )
    463467        {
    464468            stopServer( server );
     
    594598    if( !err )
    595599    {
    596         const int isRunning = server->ctx != NULL;
    597 
    598         if( isRunning )
     600        const int isEnabled = server->isEnabled;
     601
     602        if( isEnabled )
    599603            stopServer( server );
    600604
     
    603607        dbgmsg( "setting our ACL to [%s]", server->acl );
    604608
    605         if( isRunning )
     609        if( isEnabled )
    606610            startServer( server );
    607611    }
     
    625629                   const char           * username )
    626630{
    627     const int isRunning = server->ctx != NULL;
    628 
    629     if( isRunning )
     631    const int isEnabled = server->isEnabled;
     632
     633    if( isEnabled )
    630634        stopServer( server );
    631635
     
    634638    dbgmsg( "setting our Username to [%s]", server->username );
    635639
    636     if( isRunning )
     640    if( isEnabled )
    637641        startServer( server );
    638642}
     
    648652                   const char           * password )
    649653{
    650     const int isRunning = server->ctx != NULL;
    651 
    652     if( isRunning )
     654    const int isEnabled = server->isEnabled;
     655
     656    if( isEnabled )
    653657        stopServer( server );
    654658
     
    657661    dbgmsg( "setting our Password to [%s]", server->password );
    658662
    659     if( isRunning )
     663    if( isEnabled )
    660664        startServer( server );
    661665}
     
    671675                          int              isEnabled )
    672676{
    673     const int isRunning = server->ctx != NULL;
    674 
    675     if( isRunning )
     677    const int wasEnabled = server->isEnabled;
     678
     679    if( wasEnabled )
    676680        stopServer( server );
    677681
     
    679683    dbgmsg( "setting 'password enabled' to %d", isEnabled );
    680684
    681     if( isRunning )
     685    if( isEnabled )
    682686        startServer( server );
    683687}
     
    732736    s->username = tr_strdup( username );
    733737    s->password = tr_strdup( password );
    734     s->isPasswordEnabled = isPasswordEnabled;
     738    s->isPasswordEnabled = isPasswordEnabled != 0;
     739    s->isEnabled = isEnabled != 0;
    735740   
    736741    if( isEnabled )
Note: See TracChangeset for help on using the changeset viewer.