]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_avahi.c
Merge remote-tracking branch 'remotes/origin/branch-netatalk-2-1'
[netatalk.git] / etc / afpd / afp_avahi.c
index fc3627116be216f301ec713f3ce29cedb72bb3a9..dbd0cf2e75fd266f8e328b6df485ad4986a7ff29 100644 (file)
@@ -48,6 +48,7 @@ static void register_stuff(void) {
     DSI *dsi;
     char name[MAXINSTANCENAMELEN+1];
     AvahiStringList *strlist = NULL;
+    AvahiStringList *strlist2 = NULL;
     char tmpname[256];
 
     assert(ctx->client);
@@ -94,19 +95,31 @@ static void register_stuff(void) {
 
             dsi = (DSI *)config->obj.handle;
             port = getip_port((struct sockaddr *)&dsi->server);
-            
-            if (convert_string(config->obj.options.unixcharset, CH_UTF8,
-                               config->obj.options.server ? config->obj.options.server : config->obj.options.hostname, -1,
-                               name, MAXINSTANCENAMELEN) <= 0) {
-                LOG ( log_error, logtype_afpd, "Could not set Zeroconf instance name");
+
+            if (convert_string(config->obj.options.unixcharset,
+                               CH_UTF8,
+                               config->obj.options.server ?
+                               config->obj.options.server :
+                               config->obj.options.hostname,
+                               -1,
+                               name,
+                               MAXINSTANCENAMELEN) <= 0) {
+                LOG(log_error, logtype_afpd, "Could not set Zeroconf instance name");
+                goto fail;
+            }
+            if ((dsi->bonjourname = strdup(name)) == NULL) {
+                LOG(log_error, logtype_afpd, "Could not set Zeroconf instance name");
                 goto fail;
+
             }
+            LOG(log_info, logtype_afpd, "Registering server '%s' with with Bonjour",
+                dsi->bonjourname);
 
             if (avahi_entry_group_add_service(ctx->group,
                                               AVAHI_IF_UNSPEC,
                                               AVAHI_PROTO_UNSPEC,
                                               0,
-                                              name,
+                                              dsi->bonjourname,
                                               AFP_DNS_SERVICE_TYPE,
                                               NULL,
                                               NULL,
@@ -121,7 +134,7 @@ static void register_stuff(void) {
                                                           AVAHI_IF_UNSPEC,
                                                           AVAHI_PROTO_UNSPEC,
                                                           0,
-                                                          name,
+                                                          dsi->bonjourname,
                                                           ADISK_SERVICE_TYPE,
                                                           NULL,
                                                           NULL,
@@ -131,6 +144,25 @@ static void register_stuff(void) {
                     avahi_strerror(avahi_client_errno(ctx->client)));
                 goto fail;
             }  /* if */
+
+            if (config->obj.options.mimicmodel) {
+                strlist2 = avahi_string_list_add_printf(strlist2, "model=%s", config->obj.options.mimicmodel);
+                if (avahi_entry_group_add_service_strlst(ctx->group,
+                                                         AVAHI_IF_UNSPEC,
+                                                         AVAHI_PROTO_UNSPEC,
+                                                         0,
+                                                         dsi->bonjourname,
+                                                         DEV_INFO_SERVICE_TYPE,
+                                                         NULL,
+                                                         NULL,
+                                                         0,
+                                                         strlist2) < 0) {
+                    LOG(log_error, logtype_afpd, "Failed to add service: %s",
+                        avahi_strerror(avahi_client_errno(ctx->client)));
+                    goto fail;
+                }
+            } /* if (config->obj.options.mimicmodel) */
+
         }      /* for config*/
 
         if (avahi_entry_group_commit(ctx->group) < 0) {
@@ -250,7 +282,7 @@ static void client_callback(AvahiClient *client,
  * neccessary config setting.
  */
 void av_zeroconf_setup(const AFPConfig *configs) {
-    int error, ret;
+    int error;
 
     /* initialize the struct that holds our config settings. */
     if (ctx) {
@@ -291,8 +323,6 @@ fail:
  * This function finally runs the loop impl.
  */
 int av_zeroconf_run(void) {
-    int ret;
-
     /* Finally, start the event loop thread */
     if (avahi_threaded_poll_start(ctx->threaded_poll) < 0) {
         LOG(log_error, logtype_afpd, "Failed to create thread: %s",