From: Michael R Sweet Date: Fri, 4 Apr 2025 15:26:37 +0000 (-0400) Subject: Fix copy/paste error in Avahi cupsDNSSDBrowseNew code. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=833021c8c5f06d8aa6c257032bfeaf18fd72cb97;p=thirdparty%2Fcups.git Fix copy/paste error in Avahi cupsDNSSDBrowseNew code. Use cupsGetClock API in ippfind to measure time, and timeout if nothing comes in after 2.5 seconds in "forever" mode. --- diff --git a/cups/dnssd.c b/cups/dnssd.c index 87e5bf8cd3..51030ded44 100644 --- a/cups/dnssd.c +++ b/cups/dnssd.c @@ -491,9 +491,9 @@ cupsDNSSDBrowseNew( subtype = (const char *)cupsArrayGetElement(tarray, i); if (subtype) - snprintf(typename, sizeof(typename), "%s._sub.%s.local", subtype, base); + snprintf(typename, sizeof(typename), "%s._sub.%s", subtype, base); else - snprintf(typename, sizeof(typename), "%s.local", base); + cupsCopyString(typename, base, sizeof(typename)); 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) { @@ -3009,7 +3009,7 @@ avahi_resolve_cb( 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); - if (!resolver) + if (!resolver || event != AVAHI_RESOLVER_FOUND) return; (void)resolver; diff --git a/tools/ippfind.c b/tools/ippfind.c index a2f2012e42..4778bb8c1e 100644 --- a/tools/ippfind.c +++ b/tools/ippfind.c @@ -116,9 +116,10 @@ typedef struct ippfind_srv_s // Service information static cups_dnssd_t *dnssd; // DNS-SD context static int address_family = AF_UNSPEC; // Address family for LIST -static int bonjour_error = 0; // Error browsing/resolving? +static bool bonjour_error = false; // Error browsing/resolving? static double bonjour_timeout = 1.0; // Timeout in seconds static int ipp_version = 20; // IPP version for LIST +static double last_update = 0.0; // Last update time // @@ -130,7 +131,6 @@ static int compare_services(ippfind_srv_t *a, ippfind_srv_t *b, void *data); static int eval_expr(ippfind_srv_t *service, ippfind_expr_t *expressions); static int exec_program(ippfind_srv_t *service, int num_args, char **args); 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); -static double get_time(void); static int list_service(ippfind_srv_t *service); static ippfind_expr_t *new_expr(ippfind_op_t op, bool invert, const char *value, const char *regex, char **args); 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, int num_txt, cups_option_t *txt); @@ -1064,11 +1064,11 @@ main(int argc, // I - Number of command-line args // Process browse/resolve requests... if (bonjour_timeout > 1.0) - endtime = get_time() + bonjour_timeout; + endtime = cupsGetClock() + bonjour_timeout; else - endtime = get_time() + 300.0; + endtime = cupsGetClock() + 300.0; - while (get_time() < endtime) + while (cupsGetClock() < endtime) { // Process any services that we have found... int j, // Looping var @@ -1122,7 +1122,7 @@ main(int argc, // I - Number of command-line args if (getenv("IPPFIND_DEBUG")) fprintf(stderr, "STATUS processed=%u, resolved=%u, count=%u\n", (unsigned)processed, (unsigned)resolved, (unsigned)count); - if (processed > 0 && processed == cupsArrayGetCount(services.services) && bonjour_timeout <= 1.0) + if (processed > 0 && (processed == cupsArrayGetCount(services.services) || (cupsGetClock() - last_update) >= 2.5) && bonjour_timeout <= 1.0) break; // Give the browsers/resolvers some time... @@ -1152,6 +1152,9 @@ browse_callback( { ippfind_srv_t *service; // Service + + last_update = cupsGetClock(); + if (getenv("IPPFIND_DEBUG")) fprintf(stderr, "B flags=0x%04X, if_index=%u, serviceName=\"%s\", regtype=\"%s\", replyDomain=\"%s\"\n", flags, if_index, serviceName, regtype, replyDomain); @@ -1592,31 +1595,6 @@ get_service(ippfind_srvs_t *services, // I - Service array } -// -// 'get_time()' - Get the current time-of-day in seconds. -// - -static double -get_time(void) -{ -#ifdef _WIN32 - struct _timeb curtime; // Current Windows time - - _ftime(&curtime); - - return (curtime.time + 0.001 * curtime.millitm); - -#else - struct timeval curtime; // Current UNIX time - - if (gettimeofday(&curtime, NULL)) - return (0.0); - else - return (curtime.tv_sec + 0.000001 * curtime.tv_usec); -#endif // _WIN32 -} - - // // 'list_service()' - List the contents of a service. // @@ -1897,6 +1875,8 @@ resolve_callback( char *value; // Pointer into value + last_update = cupsGetClock(); + if (getenv("IPPFIND_DEBUG")) fprintf(stderr, "R flags=0x%04X, if_index=%u, fullName=\"%s\", hostTarget=\"%s\", port=%u, num_txt=%d, txt=%p\n", flags, if_index, fullName, hostTarget, port, num_txt, (void *)txt); @@ -1907,7 +1887,7 @@ resolve_callback( // Only process "add" data... if (flags & CUPS_DNSSD_FLAGS_ERROR) { - bonjour_error = 1; + bonjour_error = true; return; }