hello,

i've update the patch to support last avahi api:
http://bugzilla.gnome.org/show_bug.cgi?id=159874

if you want to test or review the patch, follow the following instructions:

export CVSROOT=:pserver:[EMAIL PROTECTED]:/cvs/gnome
cvs login
cvs co vino
cd vino/
cat /PathToThePatch/vino-avahi-0.6.patch | patch -p0
./autogen.sh
./configure --sysconfdir=/etc --prefix=/usr --enable-avahi
--enable-debug=yes --enable-http-server=yes
make
./server/vino-server

This patch publish the vnc server and the http frontend to access the
vnc java applet if available.

I didn't handle very well disconnection from avahi (eg when you
restart avahi while vino-server is running), i'll improve this.

--
Sebastien Estienne
diff -urN vino.orig/configure.in vino/configure.in
--- vino.orig/configure.in	2005-10-27 20:13:08.000000000 +0200
+++ vino/configure.in	2006-01-08 14:38:47.000000000 +0100
@@ -214,6 +214,32 @@
 dnl End of libvncserver stuff
 dnl
 
+dnl
+dnl   Check for Avahi
+dnl
+AC_ARG_ENABLE(avahi,
+        AS_HELP_STRING([--enable-avahi],[Enable use of avahi]),
+        [case "${enableval}" in
+                yes) VINO_ENABLE_MDNS=yes ;;
+                no)  VINO_ENABLE_MDNS=no ;;
+                *) AC_MSG_ERROR(bad value ${enableval} for --enable-avahi) ;;
+        esac],
+        [VINO_ENABLE_MDNS=no])
+
+if test "x$VINO_ENABLE_MDNS" = "xyes" ; then
+    PKG_CHECK_MODULES(AVAHI, [ avahi-client >= 0.6  avahi-glib >= 0.6 ])
+    AVAHI_CFLAGS="$AVAHI_CFLAGS -DVINO_ENABLE_MDNS"
+    AC_SUBST(AVAHI_CFLAGS)
+    AC_SUBST(AVAHI_LIBS)
+fi
+AM_CONDITIONAL(VINO_ENABLE_MDNS, test "x$VINO_ENABLE_MDNS" = "xyes")
+
+dnl
+dnl End of Avahi stuff
+dnl
+
+
+
 
 dnl --enable-debug=(yes|minimum|no)
 AC_ARG_ENABLE(debug, [  --enable-debug=[no/yes] turn on debugging [default=no]],,enable_debug=minimum)
diff -urN vino.orig/server/Makefile.am vino/server/Makefile.am
--- vino.orig/server/Makefile.am	2005-05-20 11:39:48.000000000 +0200
+++ vino/server/Makefile.am	2006-01-08 14:36:21.000000000 +0100
@@ -7,6 +7,7 @@
 	$(VINO_SERVER_CFLAGS) \
 	$(VINO_DEBUG_CFLAGS) \
 	$(VINO_HTTP_CFLAGS) \
+	$(AVAHI_CFLAGS) \
 	$(LIBGNUTLS_CFLAGS) \
 	$(LIBGCRYPT_CFLAGS) \
 	$(WARN_CFLAGS) \
@@ -24,6 +25,7 @@
 	$(LIBGCRYPT_LIBS) \
 	$(X_LIBS) $(XTEST_LIBS) $(XSHM_LIBS) $(XDAMAGE_LIBS) \
 	$(top_builddir)/server/libvncserver/libvncserver.la \
+	$(AVAHI_LIBS) \
 	$(NULL)
 
 if HTTP_SERVER
@@ -33,6 +35,13 @@
 	$(NULL)
 endif
 
+if VINO_ENABLE_MDNS
+VINO_MDNS_SRC = \
+	vino-mdns.c \
+	vino-mdns.h \
+	$(NULL)
+endif
+
 vino_server_SOURCES = \
 	vino-cursor.c \
 	vino-cursor.h \
@@ -53,6 +62,7 @@
 	vino-server.h \
 	vino-shell.c \
 	vino-shell.h \
+	$(VINO_MDNS_SRC) \
 	vino-util.c \
 	vino-util.h \
 	$(VINO_HTTP_SRC) \
diff -urN vino.orig/server/vino-http.c vino/server/vino-http.c
--- vino.orig/server/vino-http.c	2004-02-05 09:54:57.000000000 +0100
+++ vino/server/vino-http.c	2006-01-08 14:36:21.000000000 +0100
@@ -33,6 +33,10 @@
 #include <netinet/in.h>
 #include <libgnomeui/gnome-icon-theme.h>
 
+#ifdef VINO_ENABLE_MDNS
+#include "vino-mdns.h"
+#endif
+
 #include "vino-util.h"
 
 #define VINO_CLIENT_HTML_FILE "vino-client.html"
@@ -663,6 +667,10 @@
 
   dprintf (HTTP, "Listening for HTTP requests on port %d\n", http_port);
 
+#ifdef VINO_ENABLE_MDNS
+  vino_mdns_add_service("_http._tcp", http_port);
+#endif
+
   http->priv->http_port  = http_port;
   http->priv->socket     = sock;
   http->priv->io_channel = g_io_channel_unix_new (http->priv->socket);
diff -urN vino.orig/server/vino-mdns.c vino/server/vino-mdns.c
--- vino.orig/server/vino-mdns.c	1970-01-01 01:00:00.000000000 +0100
+++ vino/server/vino-mdns.c	2006-01-08 15:13:59.000000000 +0100
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2005 Ethium, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ *      Sebastien Estienne <[EMAIL PROTECTED]>
+ *
+ */
+
+#include <config.h>
+
+#include "vino-mdns.h" 
+#include "vino-util.h"
+
+#include <avahi-client/client.h>
+#include <avahi-client/publish.h>
+#include <avahi-common/alternative.h>
+#include <avahi-common/error.h>
+#include <avahi-glib/glib-watch.h>
+#include <avahi-glib/glib-malloc.h>
+
+
+static AvahiClient     *mdns_client = NULL;
+static AvahiEntryGroup *mdns_group = NULL;
+static GHashTable      *mdns_services = NULL;
+char                   *mdns_name = NULL; 
+
+static int create_services(AvahiClient *c, void *userdata);
+
+static void 
+entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) 
+{
+  char *new_name;
+
+  g_assert(g == mdns_group);
+  
+  switch(state)
+    {
+    case AVAHI_ENTRY_GROUP_ESTABLISHED:
+      dprintf (MDNS, "Avahi: Service '%s' successfully established.\n", mdns_name);
+      break;
+    case AVAHI_ENTRY_GROUP_COLLISION:
+
+      new_name = avahi_alternative_service_name(mdns_name);
+      avahi_free(mdns_name);
+      mdns_name = new_name;
+
+      dprintf (MDNS, "Avahi: Service name collision, renaming service to '%s'\n", mdns_name);
+
+      create_services(avahi_entry_group_get_client(g), NULL);
+      break;
+    case AVAHI_ENTRY_GROUP_FAILURE:
+    case AVAHI_ENTRY_GROUP_UNCOMMITED:
+    case AVAHI_ENTRY_GROUP_REGISTERING:
+      break;
+    }
+}
+
+static void
+entry_group_add_service(gpointer key, gpointer hvalue, gpointer user_data)
+{
+  int   ret;
+  char *type = (char *)key;
+  int   port = GPOINTER_TO_INT (hvalue);
+
+  if ((ret = avahi_entry_group_add_service_strlst(mdns_group, 
+						  AVAHI_IF_UNSPEC, 
+						  AVAHI_PROTO_UNSPEC, 
+						  0,
+						  mdns_name, 
+						  type, 
+						  NULL, 
+						  NULL, 
+						  port, 
+						  NULL)) < 0) 
+    dprintf (MDNS, "Avahi: Failed to add %s on port %d : %s\n", type, port, avahi_strerror(ret));
+}
+
+static int
+create_services(AvahiClient *c, void *userdata) 
+{
+  int ret = 0;
+
+  g_assert(c);
+  
+  if (!mdns_group) 
+    {
+      if (!(mdns_group = avahi_entry_group_new(c, entry_group_callback, userdata))) 
+	{
+	  dprintf (MDNS, "Avahi: avahi_entry_group_new() failed: %s\n", avahi_strerror(avahi_client_errno(c)));
+	  return ret;
+	}
+    }
+    
+  dprintf (MDNS, "Avahi: Adding service '%s'\n", mdns_name);
+
+  g_hash_table_foreach(mdns_services, entry_group_add_service, NULL);
+
+  if ((ret = avahi_entry_group_commit(mdns_group)) < 0) 
+    {
+      dprintf (MDNS, "Avahi: Failed to commit entry_group: %s\n", avahi_strerror(ret));
+      return ret;
+    }
+  
+  return ret;
+}
+
+static void 
+client_callback(AvahiClient *c, AvahiClientState state, void * userdata) 
+{
+  g_assert(c);
+
+  switch(state)
+    {
+    case  AVAHI_CLIENT_S_RUNNING:
+      create_services(c, userdata);
+      break;
+    case AVAHI_CLIENT_S_COLLISION:
+      if (mdns_group)
+	avahi_entry_group_reset(mdns_group);
+      break;
+      /* FIXME handle disconnection better */
+    case AVAHI_CLIENT_FAILURE:
+      dprintf (MDNS, "Connection with Avahi daemon terminated.\n");
+      break;
+    case AVAHI_CLIENT_CONNECTING:
+    case AVAHI_CLIENT_S_REGISTERING:
+      break;
+    }
+}
+
+void 
+vino_mdns_add_service (char *type, int port)
+{
+  if (mdns_services == NULL)
+    mdns_services = g_hash_table_new (g_str_hash, g_str_equal);
+  g_hash_table_insert (mdns_services, type, GINT_TO_POINTER (port));
+}
+
+void
+vino_mdns_start ()
+{
+  int              error;
+  const AvahiPoll *poll_api;
+  AvahiGLibPoll   *glib_poll;
+
+  mdns_name = g_strdup_printf (_("%s's remote desktop"), g_get_user_name ());
+
+  avahi_set_allocator(avahi_glib_allocator());
+
+  glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
+  poll_api = avahi_glib_poll_get (glib_poll);
+  
+  if (!(mdns_client = avahi_client_new(poll_api, 0, client_callback, NULL, &error)))
+    {
+      dprintf (MDNS, "Avahi daemon may not be running.\n");
+      vino_mdns_stop();
+    }  
+}
+
+void
+vino_mdns_stop (void)
+{
+  g_free(mdns_name);
+  if (mdns_group)
+    avahi_entry_group_free(mdns_group);
+  if (mdns_client)
+    avahi_client_free(mdns_client);
+  if (mdns_services)
+    g_hash_table_destroy(mdns_services);
+}
diff -urN vino.orig/server/vino-mdns.h vino/server/vino-mdns.h
--- vino.orig/server/vino-mdns.h	1970-01-01 01:00:00.000000000 +0100
+++ vino/server/vino-mdns.h	2006-01-08 15:04:34.000000000 +0100
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2005 Ethium, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ *      Sebastien Estienne <[EMAIL PROTECTED]>
+ *
+ */
+
+#ifndef __VINO_MDNS_H__
+#define __VINO_MDNS_H__
+
+#include "vino-server.h"
+
+G_BEGIN_DECLS
+
+void vino_mdns_add_service (char *type, int port);
+void vino_mdns_start       (void);
+void vino_mdns_stop        (void);
+
+G_END_DECLS
+
+#endif /* __VINO_MDNS_H__ */
diff -urN vino.orig/server/vino-server.c vino/server/vino-server.c
--- vino.orig/server/vino-server.c	2005-05-19 16:43:28.000000000 +0200
+++ vino/server/vino-server.c	2006-01-08 14:36:21.000000000 +0100
@@ -29,6 +29,9 @@
 #ifdef VINO_ENABLE_HTTP_SERVER
 #include "vino-http.h"
 #endif
+#ifdef VINO_ENABLE_MDNS
+#include "vino-mdns.h"
+#endif
 #include "vino-input.h"
 #include "vino-cursor.h"
 #include "vino-prompt.h"
@@ -696,6 +699,11 @@
 #ifdef VINO_ENABLE_HTTP_SERVER
   server->priv->http = vino_http_get (rfb_screen->rfbPort);
 #endif
+
+#ifdef VINO_ENABLE_MDNS
+  vino_mdns_add_service("_rfb._tcp", rfb_screen->rfbPort);
+  vino_mdns_start();
+#endif
 }
 
 static void
@@ -713,6 +721,10 @@
   server->priv->http = NULL;
 #endif /* VINO_ENABLE_HTTP_SERVER */
 
+#ifdef VINO_ENABLE_MDNS
+  vino_mdns_stop ();
+#endif /* VINO_ENABLE_MDNS */
+
   if (server->priv->io_watch)
     g_source_remove (server->priv->io_watch);
   server->priv->io_watch = 0;
diff -urN vino.orig/server/vino-util.c vino/server/vino-util.c
--- vino.orig/server/vino-util.c	2004-07-12 14:17:52.000000000 +0200
+++ vino/server/vino-util.c	2006-01-08 14:36:21.000000000 +0100
@@ -42,6 +42,9 @@
 #ifdef HAVE_GNUTLS
       { "tls",     VINO_DEBUG_TLS },
 #endif
+#ifdef VINO_ENABLE_MDNS
+      { "mdns",     VINO_DEBUG_MDNS },
+#endif
       { "prompt",  VINO_DEBUG_PROMPT },
       { "http",    VINO_DEBUG_HTTP}
     };
diff -urN vino.orig/server/vino-util.h vino/server/vino-util.h
--- vino.orig/server/vino-util.h	2004-07-12 14:17:52.000000000 +0200
+++ vino/server/vino-util.h	2006-01-08 14:36:21.000000000 +0100
@@ -45,8 +45,11 @@
 #ifdef HAVE_GNUTLS
   VINO_DEBUG_TLS     = 1 << 4,
 #endif
-  VINO_DEBUG_PROMPT  = 1 << 5,
-  VINO_DEBUG_HTTP    = 1 << 6
+#ifdef VINO_ENABLE_MDNS
+  VINO_DEBUG_MDNS    = 1 << 5,
+#endif
+  VINO_DEBUG_PROMPT  = 1 << 6,
+  VINO_DEBUG_HTTP    = 1 << 7
 } VinoDebugFlags;
 
 #ifdef G_ENABLE_DEBUG


_______________________________________________
avahi mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/avahi

Reply via email to