- for (volume = getvolumes(); volume; volume = volume->v_next) {
-
- if (convert_string(CH_UCS2, CH_UTF8_MAC, volume->v_name, -1, tmpname, 255) <= 0)
- goto fail;
-
- if ((volume->v_flags & AFPVOL_TM) && volume->v_uuid) {
- LOG(log_info, logtype_afpd, "Registering volume '%s' with UUID: '%s' for TimeMachine",
- volume->v_localname, volume->v_uuid);
- strlist = avahi_string_list_add_printf(strlist, "dk%u=adVN=%s,adVF=0xa1,adVU=%s",
- i++, tmpname, volume->v_uuid);
- }
- }
-
- /* AFP server */
- 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 (avahi_entry_group_add_service(ctx->group,
- AVAHI_IF_UNSPEC,
- AVAHI_PROTO_UNSPEC,
- 0,
- name,
- AFP_DNS_SERVICE_TYPE,
- NULL,
- NULL,
- port,
- NULL) < 0) {
- LOG(log_error, logtype_afpd, "Failed to add service: %s",
- avahi_strerror(avahi_client_errno(ctx->client)));
- goto fail;
- }
-
- if (avahi_entry_group_add_service_strlst(ctx->group,
- AVAHI_IF_UNSPEC,
- AVAHI_PROTO_UNSPEC,
- 0,
- name,
- "_adisk._tcp",
- NULL,
- NULL,
- 311, /* serveradmin, peaked from os x 10.6 server */
- strlist) < 0) {
- LOG(log_error, logtype_afpd, "Failed to add service: %s",
- avahi_strerror(avahi_client_errno(ctx->client)));
- goto fail;
- } /* if */
- } /* for config*/
-
- if (avahi_entry_group_commit(ctx->group) < 0) {
- LOG(log_error, logtype_afpd, "Failed to commit entry group: %s",
- avahi_strerror(avahi_client_errno(ctx->client)));
- goto fail;
- }
-
- } /* if avahi_entry_group_is_empty*/
-
- return;
+ for (volume = getvolumes(); volume; volume = volume->v_next) {
+
+ 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) {
+ LOG(log_info, logtype_afpd, "Registering volume '%s' with UUID: '%s' for TimeMachine",
+ volume->v_localname, volume->v_uuid);
+ strlist = avahi_string_list_add_printf(strlist, "dk%u=adVN=%s,adVF=0xa1,adVU=%s",
+ i++, tmpname, volume->v_uuid);
+ } else {
+ LOG(log_warning, logtype_afpd, "Registering volume '%s' for TimeMachine. But UUID is invalid.",
+ volume->v_localname);
+ strlist = avahi_string_list_add_printf(strlist, "dk%u=adVN=%s,adVF=0xa1",
+ i++, tmpname);
+ }
+ }
+ }
+
+ /* AFP server */
+ for (config = ctx->configs; config; config = config->next) {
+
+ dsi = (DSI *)config->obj.dsi;
+ 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 Bonjour",
+ dsi->bonjourname);
+
+ if (avahi_entry_group_add_service(ctx->group,
+ AVAHI_IF_UNSPEC,
+ AVAHI_PROTO_UNSPEC,
+ 0,
+ dsi->bonjourname,
+ AFP_DNS_SERVICE_TYPE,
+ NULL,
+ NULL,
+ port,
+ NULL) < 0) {
+ LOG(log_error, logtype_afpd, "Failed to add service: %s",
+ avahi_strerror(avahi_client_errno(ctx->client)));
+ goto fail;
+ }
+
+ if (i && avahi_entry_group_add_service_strlst(ctx->group,
+ AVAHI_IF_UNSPEC,
+ AVAHI_PROTO_UNSPEC,
+ 0,
+ dsi->bonjourname,
+ ADISK_SERVICE_TYPE,
+ NULL,
+ NULL,
+ 9, /* discard */
+ strlist) < 0) {
+ LOG(log_error, logtype_afpd, "Failed to add service: %s",
+ 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) {
+ LOG(log_error, logtype_afpd, "Failed to commit entry group: %s",
+ avahi_strerror(avahi_client_errno(ctx->client)));
+ goto fail;
+ }
+
+ } /* if avahi_entry_group_is_empty*/
+
+ return;