Skip to content

Commit 3d5e693

Browse files
committed
Fix a new bug in cupsDNSSDBrowseNew with Avahi (copy/paste error)
Use the cupsGetClock API in ippfind to keep track of the running time, and timeout after 2.5 seconds of no messages.
1 parent 35362af commit 3d5e693

3 files changed

Lines changed: 15 additions & 34 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ Changes in libcups
44
libcups v3.0.0 (YYYY-MM-DD)
55
---------------------------
66

7+
- Updated `ippfind` to use `cupsGetClock` API.
78
- Fixed return values of `ippDateToTime` when the timezone isn't GMT.
89
- Fixed a potential timing issue with `cupsEnumDests`.
10+
- Fixed a bug in the Avahi implementation of `cupsDNSSDBrowseNew`.
911

1012

1113
libcups v3.0rc4 (2025-03-18)

cups/dnssd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ cupsDNSSDBrowseNew(
491491
subtype = (const char *)cupsArrayGetElement(tarray, i);
492492

493493
if (subtype)
494-
snprintf(typename, sizeof(typename), "%s._sub.%s.local", subtype, base);
494+
snprintf(typename, sizeof(typename), "%s._sub.%s", subtype, base);
495495
else
496-
snprintf(typename, sizeof(typename), "%s.local", base);
496+
cupsCopyString(typename, base, sizeof(typename));
497497

498498
if ((browse->browsers[browse->num_browsers] = avahi_service_browser_new(dnssd->client, avahi_if_index(if_index), AVAHI_PROTO_UNSPEC, typename, domain, /*flags*/0, (AvahiServiceBrowserCallback)avahi_browse_cb, browse)) != NULL)
499499
{
@@ -3009,7 +3009,7 @@ avahi_resolve_cb(
30093009

30103010
DEBUG_printf("3avahi_resolve_cb(resolver=%p, if_index=%d, protocol=%d, event=%s, name=\"%s\", type=\"%s\", domain=\"%s\", host=\"%s\", address=%p, port=%u, txtrec=%p, flags=%u, resolve=%p)", (void *)resolver, if_index, protocol, avahi_events[event], name, type, domain, host, (void *)address, (unsigned)port, (void *)txtrec, (unsigned)flags, (void *)resolve);
30113011

3012-
if (!resolver)
3012+
if (!resolver || event != AVAHI_RESOLVER_FOUND)
30133013
return;
30143014

30153015
(void)resolver;

tools/ippfind.c

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// commands such as IPP and Bonjour conformance tests. This tool is
44
// inspired by the UNIX "find" command, thus its name.
55
//
6-
// Copyright © 2021-2023 by OpenPrinting.
6+
// Copyright © 2021-2025 by OpenPrinting.
77
// Copyright © 2020 by the IEEE-ISTO Printer Working Group
88
// Copyright © 2008-2018 by Apple Inc.
99
//
@@ -118,6 +118,7 @@ static int address_family = AF_UNSPEC;
118118
static bool bonjour_error = false; // Error browsing/resolving?
119119
static double bonjour_timeout = 1.0; // Timeout in seconds
120120
static int ipp_version = 20; // IPP version for LIST
121+
static double last_update = 0.0; // Last update time
121122

122123

123124
//
@@ -129,7 +130,6 @@ static int compare_services(ippfind_srv_t *a, ippfind_srv_t *b);
129130
static int eval_expr(ippfind_srv_t *service, ippfind_expr_t *expressions);
130131
static int exec_program(ippfind_srv_t *service, size_t num_args, char **args);
131132
static ippfind_srv_t *get_service(ippfind_srvs_t *services, const char *serviceName, const char *regtype, const char *replyDomain) _CUPS_NONNULL(1,2,3,4);
132-
static double get_time(void);
133133
static int list_service(ippfind_srv_t *service);
134134
static ippfind_expr_t *new_expr(ippfind_op_t op, bool invert, const char *value, const char *regex, char **args);
135135
static void resolve_callback(cups_dnssd_resolve_t *resolve, void *context, cups_dnssd_flags_t flags, uint32_t if_index, const char *fullName, const char *hostTarget, uint16_t port, size_t num_txt, cups_option_t *txt);
@@ -962,11 +962,11 @@ main(int argc, // I - Number of command-line args
962962

963963
// Process browse/resolve requests...
964964
if (bonjour_timeout > 1.0)
965-
endtime = get_time() + bonjour_timeout;
965+
endtime = cupsGetClock() + bonjour_timeout;
966966
else
967-
endtime = get_time() + 300.0;
967+
endtime = cupsGetClock() + 300.0;
968968

969-
while (get_time() < endtime)
969+
while (cupsGetClock() < endtime)
970970
{
971971
// Process any services that we have found...
972972
size_t j, // Looping var
@@ -1022,7 +1022,7 @@ main(int argc, // I - Number of command-line args
10221022
if (getenv("IPPFIND_DEBUG"))
10231023
fprintf(stderr, "STATUS processed=%u, resolved=%u, count=%u\n", (unsigned)processed, (unsigned)resolved, (unsigned)count);
10241024

1025-
if (processed > 0 && processed == cupsArrayGetCount(services.services) && bonjour_timeout <= 1.0)
1025+
if (processed > 0 && (processed == cupsArrayGetCount(services.services) || (cupsGetClock() - last_update) >= 2.5) && bonjour_timeout <= 1.0)
10261026
break;
10271027

10281028
// Give the browsers/resolvers some time...
@@ -1053,6 +1053,8 @@ browse_callback(
10531053
ippfind_srv_t *service; // Service
10541054

10551055

1056+
last_update = cupsGetClock();
1057+
10561058
if (getenv("IPPFIND_DEBUG"))
10571059
fprintf(stderr, "B flags=0x%04X, if_index=%u, serviceName=\"%s\", regtype=\"%s\", replyDomain=\"%s\"\n", flags, if_index, serviceName, regtype, replyDomain);
10581060

@@ -1505,31 +1507,6 @@ get_service(ippfind_srvs_t *services, // I - Service array
15051507
}
15061508

15071509

1508-
//
1509-
// 'get_time()' - Get the current time-of-day in seconds.
1510-
//
1511-
1512-
static double
1513-
get_time(void)
1514-
{
1515-
#ifdef _WIN32
1516-
struct _timeb curtime; // Current Windows time
1517-
1518-
_ftime(&curtime);
1519-
1520-
return (curtime.time + 0.001 * curtime.millitm);
1521-
1522-
#else
1523-
struct timeval curtime; // Current UNIX time
1524-
1525-
if (gettimeofday(&curtime, NULL))
1526-
return (0.0);
1527-
else
1528-
return (curtime.tv_sec + 0.000001 * curtime.tv_usec);
1529-
#endif // _WIN32
1530-
}
1531-
1532-
15331510
//
15341511
// 'list_service()' - List the contents of a service.
15351512
//
@@ -1809,6 +1786,8 @@ resolve_callback(
18091786
char *value; // Pointer into value
18101787

18111788

1789+
last_update = cupsGetClock();
1790+
18121791
if (getenv("IPPFIND_DEBUG"))
18131792
fprintf(stderr, "R flags=0x%04X, if_index=%u, fullName=\"%s\", hostTarget=\"%s\", port=%u, num_txt=%u, txt=%p\n", flags, if_index, fullName, hostTarget, port, (unsigned)num_txt, txt);
18141793

0 commit comments

Comments
 (0)