Skip to content

Commit

Permalink
Prevent hostname regeneration if we are set for localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
zdohnal committed Mar 15, 2024
1 parent f39ba2c commit a58282b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
16 changes: 9 additions & 7 deletions pappl/dnssd.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

static void dns_sd_printer_callback(cups_dnssd_service_t *service, pappl_printer_t *printer, cups_dnssd_flags_t flags);
static void dns_sd_system_callback(cups_dnssd_service_t *service, pappl_system_t *system, cups_dnssd_flags_t flags);
static bool dns_sd_is_loopback(const char *name);


//
Expand Down Expand Up @@ -57,7 +56,7 @@ _papplPrinterRegisterDNSSDNoLock(

papplLogPrinter(printer, PAPPL_LOGLEVEL_DEBUG, "Registering DNS-SD name '%s' on '%s'", printer->dns_sd_name, printer->system->hostname);

if_index = dns_sd_is_loopback(system->hostname) ? CUPS_DNSSD_IF_INDEX_LOCAL : CUPS_DNSSD_IF_INDEX_ANY;
if_index = _papplDNSSDIsLoopback(system->hostname) ? CUPS_DNSSD_IF_INDEX_LOCAL : CUPS_DNSSD_IF_INDEX_ANY;

// Get attributes and values for the TXT record...
color_supported = ippFindAttribute(printer->driver_attrs, "color-supported", IPP_TAG_BOOLEAN);
Expand Down Expand Up @@ -304,7 +303,7 @@ _papplSystemRegisterDNSSDNoLock(

papplLog(system, PAPPL_LOGLEVEL_DEBUG, "Registering DNS-SD name '%s' on '%s'", system->dns_sd_name, system->hostname);

if_index = dns_sd_is_loopback(system->hostname) ? CUPS_DNSSD_IF_INDEX_LOCAL : CUPS_DNSSD_IF_INDEX_ANY;
if_index = _papplDNSSDIsLoopback(system->hostname) ? CUPS_DNSSD_IF_INDEX_LOCAL : CUPS_DNSSD_IF_INDEX_ANY;

// Rename the service as needed...
if (system->dns_sd_collision)
Expand Down Expand Up @@ -464,13 +463,16 @@ dns_sd_system_callback(


//
// 'dns_sd_is_loopback()' - Find out whether the string means
// localhost
// '_papplDNSSDIsLoopback()' - Find out whether the string means
// localhost
//

static bool
dns_sd_is_loopback(const char *name)
bool
_papplDNSSDIsLoopback(const char *name)
{
if (!name)
return (false);

if (!strcasecmp(name, "localhost"))
return (true);
else if (!strcmp(name, "127.0.0.1"))
Expand Down
2 changes: 2 additions & 0 deletions pappl/printer-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ struct _pappl_printer_s // Printer data
//
// Functions...
//
//
extern bool _papplDNSSDIsLoopback(const char *name) _PAPPL_PRIVATE;

extern bool _papplPrinterAddRawListeners(pappl_printer_t *printer) _PAPPL_PRIVATE;
extern void *_papplPrinterRunRaw(pappl_printer_t *printer) _PAPPL_PRIVATE;
Expand Down
2 changes: 1 addition & 1 deletion pappl/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ papplSystemRun(pappl_system_t *system) // I - System
bool force_dns_sd = system->dns_sd_host_changes != dns_sd_host_changes;
// Force re-registration?

if (force_dns_sd)
if (!_papplDNSSDIsLoopback(system->hostname) && force_dns_sd)
_papplSystemSetHostNameNoLock(system, NULL);

if (system->dns_sd_collision || force_dns_sd)
Expand Down

0 comments on commit a58282b

Please sign in to comment.