Ignore:
Timestamp:
Apr 5, 2009, 3:49:03 PM (12 years ago)
Author:
charles
Message:

(trunk) If avahi's zeroconf implementation is available, use it to advertise our web ui

File:
1 edited

Legend:

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

    r8108 r8149  
    2525#endif
    2626
     27#ifdef HAVE_AVAHI
     28 #include <avahi-common/simple-watch.h>
     29 #include <avahi-client/client.h>
     30 #include <avahi-client/publish.h>
     31#endif
     32
    2733#include <libevent/event.h>
    2834#include <libevent/evhttp.h>
     
    6268#ifdef HAVE_ZLIB
    6369    z_stream           stream;
     70#endif
     71#ifdef HAVE_AVAHI
     72    AvahiSimplePoll   *poll;
     73    AvahiClient       *client;
     74    AvahiEntryGroup   *group;
    6475#endif
    6576};
     
    520531}
    521532
     533#ifdef HAVE_AVAHI
     534static void
     535entry_group_callback( AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata )
     536{
     537        /* No-op */
     538}
     539
     540static void
     541client_callback( AvahiClient *c, AvahiClientState state, void * vserver )
     542{
     543        tr_rpc_server * server  = vserver;
     544
     545        if( state != AVAHI_CLIENT_S_RUNNING )
     546        {
     547                avahi_client_free( server->client );
     548                server->client = NULL;
     549                avahi_simple_poll_free( server->poll );
     550                server->poll = NULL;
     551                return;
     552        }
     553
     554        server->group = avahi_entry_group_new( c, entry_group_callback, NULL );
     555        avahi_entry_group_add_service( server->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
     556                                       0, "Transmission Web Interface", "_http._tcp", NULL, NULL, server->port,
     557                                       "path=/transmission/web", NULL );
     558        avahi_entry_group_commit( server->group );
     559}
     560#endif /* HAVE_AVAHI */
     561
    522562static void
    523563startServer( void * vserver )
     
    530570        evhttp_bind_socket( server->httpd, "0.0.0.0", server->port );
    531571        evhttp_set_gencb( server->httpd, handle_request, server );
     572
     573#ifdef HAVE_AVAHI
     574        server->poll = avahi_simple_poll_new();
     575        server->client = avahi_client_new( avahi_simple_poll_get( server->poll ), 0, client_callback, server, NULL );
     576#endif
    532577    }
    533578}
     
    540585        evhttp_free( server->httpd );
    541586        server->httpd = NULL;
     587
     588#ifdef HAVE_AVAHI
     589        avahi_client_free( server->client );
     590        server->client = NULL;
     591        avahi_entry_group_free( server->group );
     592        server->group = NULL;
     593        avahi_simple_poll_free( server->poll );
     594        server->poll = NULL;
     595#endif
    542596    }
    543597}
Note: See TracChangeset for help on using the changeset viewer.