After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 159874 - Patch to publish vino server throught zeroconf
Patch to publish vino server throught zeroconf
Status: RESOLVED FIXED
Product: vino
Classification: Applications
Component: Server
unspecified
Other Linux
: High enhancement
: ---
Assigned To: Vino Maintainer(s)
Vino Maintainer(s)
: 316663 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2004-11-29 17:24 UTC by Sebastien Estienne
Modified: 2006-01-13 12:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
the patch modify configure.in server/makefile.am and vino-server.c (2.78 KB, patch)
2004-11-29 17:25 UTC, Sebastien Estienne
none Details | Review
vino-zeroconf.c (2.79 KB, text/plain)
2004-11-29 17:26 UTC, Sebastien Estienne
  Details
vino-zeroconf.h (1.03 KB, text/plain)
2004-11-29 17:27 UTC, Sebastien Estienne
  Details
Patch against vino 2.12.1 to add zeroconf support using avahi (9.89 KB, patch)
2005-09-23 21:55 UTC, Sebastien Estienne
none Details | Review
some fix to use g_malloc instead of malloc (9.85 KB, patch)
2005-09-24 00:32 UTC, Sebastien Estienne
needs-work Details | Review
patch the configure.in file to add avahi support (disable by default) (754 bytes, patch)
2005-10-01 00:54 UTC, Sebastien Estienne
none Details | Review
patch vino-server.c vino-http.c Makefile.am to add mdns support (3.50 KB, patch)
2005-10-01 00:55 UTC, Sebastien Estienne
none Details | Review
vino-mdns.c (4.71 KB, text/plain)
2005-10-01 00:56 UTC, Sebastien Estienne
  Details
vino-mdns.h (1.07 KB, text/plain)
2005-10-01 00:56 UTC, Sebastien Estienne
  Details
Patch to add zeroconf support using avahi's api 0.6.x (10.99 KB, patch)
2006-01-08 14:36 UTC, Sebastien Estienne
needs-work Details | Review
New patch implementing vincent recommendations (11.64 KB, patch)
2006-01-08 18:57 UTC, Sebastien Estienne
none Details | Review
new version of the patch (11.67 KB, patch)
2006-01-08 20:17 UTC, Sebastien Estienne
none Details | Review

Description Sebastien Estienne 2004-11-29 17:24:10 UTC
Patch to publish vino server throught zeroconf
Comment 1 Sebastien Estienne 2004-11-29 17:25:54 UTC
Created attachment 34279 [details] [review]
the patch modify configure.in server/makefile.am and vino-server.c
Comment 2 Sebastien Estienne 2004-11-29 17:26:37 UTC
Created attachment 34280 [details]
vino-zeroconf.c
Comment 3 Sebastien Estienne 2004-11-29 17:27:18 UTC
Created attachment 34281 [details]
vino-zeroconf.h
Comment 4 Sebastien Estienne 2005-08-24 00:39:21 UTC
if you are interested i can port this patch to avahi zeroconf instead of Howl,
but only if there is some interest as this patch is sitting there for almost 1 year.
Comment 5 Sebastien Estienne 2005-09-23 21:55:54 UTC
Created attachment 52576 [details] [review]
Patch against vino 2.12.1 to add zeroconf support using avahi
Comment 6 Sebastien Estienne 2005-09-24 00:32:34 UTC
Created attachment 52581 [details] [review]
some fix to use g_malloc instead of malloc
Comment 7 Mark McLoughlin 2005-09-30 16:07:47 UTC
*** Bug 316663 has been marked as a duplicate of this bug. ***
Comment 8 Mark McLoughlin 2005-09-30 16:50:08 UTC
Sorry for taking so long to even look at this. Some suggestions

 - Rename the files to vino-mdns.[ch] and use mdns everywhere instead of
   zeroconf. Isn't "zeroconf" trademarked now ? MDNS more accurately
   describe what the code does, anyway

 - The rest of the code in vino/server goes to great pains to use the
   same coding style. I'd appreciate it if you could use that style
   too

 - Should be off by default in configure.in

 - I'd make the API as simple as:

     void vino_mdns_init     (void);
     void vino_mdns_shutdown (void);

   and maintain any state in static variables global to vino-mdns.[ch]

   Looks like the global variables might be:

     static AvahiClient     *mdns_client = NULL;
     static AvahiEntryGroup *mdns_group = NULL;
     static GPtrArray       *mdns_ports = NULL;

   (You'd use mdns_ports with code like:

      g_ptr_array_add (mdns_ports, GUINT_TO_POINTER (port_number));
   )

   There's no need to keep the service name as part of the global state,
   you can just create that when adding the service

 - You'd then just have 

     void vino_mdns_add_port    (int port);
     void vino_mdns_remove_port (int port);

 - The ZC_RFB define should be in vino-mdns.c as its not part of the API
   for the module

 - Ditto for all the avahi headers - they should only be included in the
   C file when we don't have the zc_vino struct

 - The use of goto in create_services() is fairly gratuitous - just return, no
   need for the variable to hold the return code even.

 - Use g_new0 (zc_vino, 1) instead of g_malloc()

 - You need to free the AvahiGLibPoll after creating the client

 - I don't see why you free everything when the client goes into DISCONNECTED
   state. Isn't there a danger that the code will attempt to free it again
   later?

 - You seem to be missing the vino-util.[ch] to add the new dprintf() module
   code

Thanks
Comment 9 Sebastien Estienne 2005-10-01 00:54:08 UTC
Created attachment 52893 [details] [review]
patch the configure.in file to add avahi support (disable by default)
Comment 10 Sebastien Estienne 2005-10-01 00:55:07 UTC
Created attachment 52894 [details] [review]
patch vino-server.c vino-http.c Makefile.am to add mdns support
Comment 11 Sebastien Estienne 2005-10-01 00:56:02 UTC
Created attachment 52895 [details]
vino-mdns.c
Comment 12 Sebastien Estienne 2005-10-01 00:56:28 UTC
Created attachment 52896 [details]
vino-mdns.h
Comment 13 Sebastien Estienne 2005-10-01 01:03:33 UTC
Fixed most of the issues that you reported.

Added support to publish the built-in http server (if compiled in)

the vino-mdns API is like this:
void vino_mdns_add_service (char *type, int port);
void vino_mdns_start       (void);
void vino_mdns_stop        (void);

- vino_mdns_add_service create a hash table of service to publish (service type,
port number
- vino_mdns_start start publishing the services defined in the hash table
- vino_mdns_stop stops publishing the services and clean everything

I tryed to improve to coding style to match the one of vino.

Don't know what to do about freeing AvahiGLibPoll, and what to do in case of
DISCONNECT, i'll try to ask other avahi developpers.

thanx for your suggestions
Comment 14 Sebastien Estienne 2005-10-19 14:02:56 UTC
Any thing that i should modify to make this code enter cvs?
Comment 15 Sebastien Estienne 2005-12-21 00:10:39 UTC
hello, any comment on the last version of the patch?
Comment 16 Sebastien Estienne 2006-01-08 14:35:20 UTC
Following is a patch supporting avahi's Api 0.6.X (the definitive one)

please review and comment, the patch is against vino CVS
Comment 17 Sebastien Estienne 2006-01-08 14:36:37 UTC
Created attachment 56967 [details] [review]
Patch to add zeroconf support using avahi's api 0.6.x
Comment 18 Vincent Untz 2006-01-08 17:08:49 UTC
Comment on attachment 56967 [details] [review]
Patch to add zeroconf support using avahi's api 0.6.x

Some comments:

>+#ifdef VINO_ENABLE_MDNS
>+  vino_mdns_add_service("_http._tcp", http_port);
>+#endif
>+

You forgot a space:
+  vino_mdns_add_service ("_http._tcp", http_port);
It happens in some other places too ;-)

>+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;

Are the three latest cases useful? Or maybe you should add:
  default:
    g_assert_not_reached();
  after them.

>+static void 
>+client_callback(AvahiClient *c, AvahiClientState state, void * userdata) 
>+{
>+  g_assert(c);
>+
>+  switch(state)
>+    {
>+    case  AVAHI_CLIENT_S_RUNNING:
>+      create_services(c, userdata);

Isn't userdata always NULL? Do create_services() really need this second argument?

>+      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;

Are the two latest cases useful? Or maybe you should add:
  default:
    g_assert_not_reached();
  after them.

>+}
>+
>+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));
>+}

It looks like calling this is useless after vino_mdns_start() has been called. Am I right? Shouldn't this be possible?

Also, I agree with Mark that a vino_mdns_remove_service() could be useful (although I'm not sure it would be used now, since I don't know vino's code).

>+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 ());

Translators won't like this ;-) (I have no better proposition).

>+  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();
>+    }  

Don't use &error if you won't use it (and free it).

Also, it shouldn't be possible to call vino_mdns_start() when it's already started, or it shouldn't do anything.

>+void
>+vino_mdns_stop (void)
>+{
>+  g_free(mdns_name);
>+  if (mdns_group)
>+    avahi_entry_group_free(mdns_group);

You can add:
  mdns_group = NULL;

>+  if (mdns_client)
>+    avahi_client_free(mdns_client);

Same for mdns_client.

>+  if (mdns_services)
>+    g_hash_table_destroy(mdns_services);

Same for mdns_services.
Comment 19 Sebastien Estienne 2006-01-08 18:57:14 UTC
Created attachment 56980 [details] [review]
New patch implementing vincent recommendations
Comment 20 Sebastien Estienne 2006-01-08 19:00:39 UTC
I implemented your recommendations, i just didn't change the stuff about vino_mdns_remove_service as i think it's not usefull yet, as there is no reason to  publish only vnc and not http.

In my opinion it's publish vnc+http or don't publish anything, in this use case vino_mdns_start/stop() is enought.
Comment 21 Sebastien Estienne 2006-01-08 20:17:09 UTC
Created attachment 56982 [details] [review]
new version of the patch
Comment 22 Sebastien Estienne 2006-01-08 20:19:42 UTC
this part in vino-server.c:
#ifdef VINO_ENABLE_MDNS
  vino_mdns_stop ();
#endif /* VINO_ENABLE_MDNS */

could be move before #ifdef VINO_ENABLE_HTTP_SERVER
so the service would be unpublished before the http server is stopped.
Comment 23 Mark McLoughlin 2006-01-13 12:11:09 UTC
Thanks guys - I've finally got around to looking at this again, re-worked it a bit and committed.

I've only given it basic testing, so if you could bang on it a bit more, that would be great.

2006-01-13  Mark McLoughlin  <mark@skynet.ie>

        Add support for publishing over mDNS. Based on patch from very
        patient Sebastien Estienne <sebastien.estienne@gmail.com> in
        bug #159874

        * configure.in: add --enable-avahi

        * server/Makefile.am: add vino-mdns.[ch] and build against
        avahi if enabled

        * server/vino-mdns.[ch]:
        (vino_mdns_add_service),
        (vino_mdns_start),
        (vino_mdns_stop): add internal publishing API.

        * server/vino-main.c: (main): start and stop the mDNS support
        before and after entering the mainloop.

        * server/vino-server.c: (vino_server_init_from_screen): advertise
        the rfb service

        * server/vino-http.c: (vino_http_create_listening_socket): advertise
        the http service

        * server/vino-util.[ch]: (vino_setup_debug_flags): add mdns
        debugging flag