Changeset 8149


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

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

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/Makefile.am

    r7087 r8149  
    2424    $(LIBCURL_LIBS) \
    2525    $(ZLIB_LIBS) \
     26    $(AVAHI_LIBS) \
    2627    $(OPENSSL_LIBS) \
    2728    $(PTHREAD_LIBS) \
  • trunk/configure.ac

    r8142 r8149  
    253253fi
    254254
     255PKG_CHECK_MODULES([AVAHI],
     256                  [avahi-client],
     257                  [have_avahi=yes],
     258                  [have_avahi=no])
     259AC_ARG_ENABLE([avahi],
     260              AS_HELP_STRING([--enable-avahi],[enable mDNS advertising for the web interface]),,
     261              [enable_avahi=yes])
     262use_avahi=no
     263if test "x$enable_avahi" = "xyes" ; then
     264    if test "x$have_avahi" = "xyes"; then
     265        use_avahi=yes
     266        AC_DEFINE([HAVE_AVAHI], 1)
     267    fi
     268fi
     269
    255270AC_ARG_ENABLE([nls],
    256271              AS_HELP_STRING([--enable-nls],[enable native language support]),,
     
    376391          ... dbus-glib support:    ${use_dbus_glib}
    377392          ... libnotify support:    ${use_libnotify}
     393          ... avahi support:        ${use_avahi}
    378394        Build OS X client:          ${build_mac}
    379395
  • trunk/daemon/Makefile.am

    r7979 r8149  
    2626    $(LIBCURL_LIBS) \
    2727    $(ZLIB_LIBS) \
     28    $(AVAHI_LIBS) \
    2829    $(OPENSSL_LIBS) \
    2930    $(PTHREAD_LIBS) -lm
  • trunk/gtk/Makefile.am

    r8097 r8149  
    110110    $(LIBCURL_LIBS) \
    111111    $(ZLIB_LIBS) \
     112    $(AVAHI_LIBS) \
    112113    $(PTHREAD_LIBS) -lm
    113114
  • trunk/libtransmission/Makefile.am

    r7705 r8149  
    88    $(OPENSSL_CFLAGS) \
    99    $(PTHREAD_CFLAGS) \
     10    $(AVAHI_CFLAGS)   \
    1011    $(ZLIB_CFLAGS)
    1112
     
    129130    $(OPENSSL_LIBS) \
    130131    $(PTHREAD_LIBS) \
     132    $(AVAHI_LIBS) \
    131133    $(ZLIB_LIBS) \
    132134    -lm
  • 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.