A new user interface for you! Read more...

File xrdp-avahi.diff of Package xrdp

diff --git a/configure.ac b/configure.ac
index 788c8a0..228deca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7,6 +7,7 @@ AM_INIT_AUTOMAKE([1.6 foreign])
 AC_PROG_CC
 AC_C_CONST
 AC_PROG_LIBTOOL
+PKG_CHECK_MODULES(AVAHI, avahi-client >= 0.6.4)
 AC_ARG_ENABLE(nopam, AS_HELP_STRING([--enable-nopam],
               [Build no PAM support (default: no)]),
               [nopam=true], [nopam=false])
diff --git a/xrdp/Makefile.am b/xrdp/Makefile.am
index 32dd412..8a5dd67 100644
--- a/xrdp/Makefile.am
+++ b/xrdp/Makefile.am
@@ -1,6 +1,7 @@
 INCLUDES = \
   -I$(top_srcdir)/common \
-  -I$(top_srcdir)/libxrdp
+  -I$(top_srcdir)/libxrdp \
+  $(AVAHI_CFLAGS)
 
 sbin_PROGRAMS = \
   xrdp
@@ -18,11 +19,13 @@ xrdp_SOURCES = \
   xrdp_painter.c \
   xrdp_process.c \
   xrdp_region.c \
-  xrdp_wm.c
+  xrdp_wm.c \
+  xrdp_avahi.c
 
 xrdp_LDADD = \
   $(top_srcdir)/common/libcommon.la \
-  $(top_srcdir)/libxrdp/libxrdp.la
+  $(top_srcdir)/libxrdp/libxrdp.la \
+  $(AVAHI_LIBS)
 
 xrdpsysconfdir=$(sysconfdir)/xrdp
 
diff --git a/xrdp/xrdp.h b/xrdp/xrdp.h
index 94e6ed5..3520285 100644
--- a/xrdp/xrdp.h
+++ b/xrdp/xrdp.h
@@ -153,6 +149,8 @@ xrdp_listen_create(void);
 void APP_CC
 xrdp_listen_delete(struct xrdp_listen* self);
 int APP_CC
+xrdp_listen_get_port(char* port, int port_bytes);
+int APP_CC
 xrdp_listen_main_loop(struct xrdp_listen* self);
 
 /* xrdp_region.c */
@@ -399,3 +397,9 @@ server_get_channel_id(struct xrdp_mod* mod, char* name);
 int DEFAULT_CC
 server_send_to_channel(struct xrdp_mod* mod, int channel_id,
                        char* data, int data_len);
+
+/* xrdp_avahi.c */
+int APP_CC
+xrdp_avahi_init(void);
+void APP_CC
+xrdp_avahi_fini(void);
diff --git a/xrdp/xrdp_avahi.c b/xrdp/xrdp_avahi.c
new file mode 100644
index 0000000..e98ab6d
--- /dev/null
+++ b/xrdp/xrdp_avahi.c
@@ -0,0 +1,112 @@
+/*
+   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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+   xrdp: A Remote Desktop Protocol server.
+   Copyright (C) Novell, Inc. 2008
+
+   avahi integration
+
+*/
+
+#include "xrdp.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <avahi-client/client.h>
+#include <avahi-client/publish.h>
+#include <avahi-common/thread-watch.h>
+
+static AvahiClient       *client = NULL;
+static AvahiThreadedPoll *threaded_poll = NULL;
+static AvahiEntryGroup   *avahi_group = NULL;
+
+static const char *_service_name = "RDP service on %s";
+
+static void
+avahi_client_callback (AvahiClient      *c,
+		       AvahiClientState state,
+		       void             *userdata)
+{
+    switch (state) {
+    case AVAHI_CLIENT_S_RUNNING:
+	avahi_group = avahi_entry_group_new (c, 0, 0);
+	if (avahi_group)
+	{
+	    char hname[512];
+	    char name[576];
+	    char port[8];
+
+	    if (gethostname (hname, sizeof (hname)))
+		break;
+
+	    sprintf (name, _service_name, hname);
+
+	    xrdp_listen_get_port (port, sizeof (port));
+
+	    avahi_entry_group_add_service (avahi_group,
+					   AVAHI_IF_UNSPEC,
+					   AVAHI_PROTO_UNSPEC,
+					   0, 
+					   name,
+					   "_rdp._tcp",
+					   0,
+					   0,
+					   atoi (port),
+					   NULL);
+
+	    avahi_entry_group_commit (avahi_group);
+	}
+	break;
+    case AVAHI_CLIENT_FAILURE:
+    case AVAHI_CLIENT_S_COLLISION:
+    case AVAHI_CLIENT_CONNECTING:
+	break;
+    case AVAHI_CLIENT_S_REGISTERING:
+	if (avahi_group)
+	    avahi_entry_group_reset (avahi_group);
+    default:
+	break;
+    }
+}
+
+int APP_CC
+xrdp_avahi_init (void)
+{
+    if (!(threaded_poll = avahi_threaded_poll_new ()))
+	return 1;
+
+    if (!(client = avahi_client_new (avahi_threaded_poll_get (threaded_poll),
+				    0, 
+				    avahi_client_callback,
+				    NULL,
+				    NULL)))
+       return 1;
+
+   if (avahi_threaded_poll_start (threaded_poll) < 0)
+       return 1;
+
+   return 0;
+}
+
+void APP_CC
+xrdp_avahi_fini (void)
+{
+    avahi_threaded_poll_stop (threaded_poll);
+    if (avahi_group)
+	avahi_entry_group_free (avahi_group);
+    avahi_client_free (client);
+    avahi_threaded_poll_free (threaded_poll);
+}
diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c
index 4526d14..75311a9 100644
--- a/xrdp/xrdp_listen.c
+++ b/xrdp/xrdp_listen.c
@@ -105,7 +105,7 @@ xrdp_process_run(void* in_val)
 }
 
 /*****************************************************************************/
-static int
+int
 xrdp_listen_get_port(char* port, int port_bytes)
 {
   int fd;