]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_avahi.c
sigquit
[netatalk.git] / etc / afpd / afp_avahi.c
index e763a0cfb7034185dc226d06f7455573b5d5cfae..a06c7be4237209e35faa9a4bee6f16da6ff01d00 100644 (file)
@@ -46,7 +46,7 @@ static void register_stuff(void) {
     const AFPConfig *config;
     const struct vol *volume;
     DSI *dsi;
-    const char *name;
+    char name[MAXINSTANCENAMELEN+1];
     AvahiStringList *strlist = NULL;
     char tmpname[256];
 
@@ -69,8 +69,10 @@ static void register_stuff(void) {
                
         for (volume = getvolumes(); volume; volume = volume->v_next) {
 
-            if (convert_string(CH_UCS2, CH_UTF8_MAC, volume->v_name, -1, tmpname, 255) <= 0)
+            if (convert_string(CH_UCS2, CH_UTF8_MAC, volume->v_name, -1, tmpname, 255) <= 0) {
+                LOG ( log_error, logtype_afpd, "Could not set Zeroconf volume name for TimeMachine");
                 goto fail;
+            }
 
             if (volume->v_flags & AFPVOL_TM) {
                 if (volume->v_uuid) {
@@ -91,15 +93,32 @@ static void register_stuff(void) {
         for (config = ctx->configs; config; config = config->next) {
 
             dsi = (DSI *)config->obj.handle;
-            name = config->obj.options.server ?
-                config->obj.options.server : config->obj.options.hostname;
             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");
+                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,
@@ -114,8 +133,8 @@ static void register_stuff(void) {
                                                           AVAHI_IF_UNSPEC,
                                                           AVAHI_PROTO_UNSPEC,
                                                           0,
-                                                          name,
-                                                          "_adisk._tcp",
+                                                          dsi->bonjourname,
+                                                          ADISK_SERVICE_TYPE,
                                                           NULL,
                                                           NULL,
                                                           9, /* discard */
@@ -243,7 +262,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) {
@@ -284,8 +303,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",