Skip to content

Commit 833021c

Browse files
committed
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.
1 parent f8a7b0b commit 833021c

2 files changed

Lines changed: 15 additions & 35 deletions

File tree

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: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ typedef struct ippfind_srv_s // Service information
116116
static cups_dnssd_t *dnssd; // DNS-SD context
117117
static int address_family = AF_UNSPEC;
118118
// Address family for LIST
119-
static int bonjour_error = 0; // Error browsing/resolving?
119+
static bool bonjour_error = false; // Error browsing/resolving?
120120
static double bonjour_timeout = 1.0; // Timeout in seconds
121121
static int ipp_version = 20; // IPP version for LIST
122+
static double last_update = 0.0; // Last update time
122123

123124

124125
//
@@ -130,7 +131,6 @@ static int compare_services(ippfind_srv_t *a, ippfind_srv_t *b, void *data);
130131
static int eval_expr(ippfind_srv_t *service, ippfind_expr_t *expressions);
131132
static int exec_program(ippfind_srv_t *service, int num_args, char **args);
132133
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);
133-
static double get_time(void);
134134
static int list_service(ippfind_srv_t *service);
135135
static ippfind_expr_t *new_expr(ippfind_op_t op, bool invert, const char *value, const char *regex, char **args);
136136
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
10641064

10651065
// Process browse/resolve requests...
10661066
if (bonjour_timeout > 1.0)
1067-
endtime = get_time() + bonjour_timeout;
1067+
endtime = cupsGetClock() + bonjour_timeout;
10681068
else
1069-
endtime = get_time() + 300.0;
1069+
endtime = cupsGetClock() + 300.0;
10701070

1071-
while (get_time() < endtime)
1071+
while (cupsGetClock() < endtime)
10721072
{
10731073
// Process any services that we have found...
10741074
int j, // Looping var
@@ -1122,7 +1122,7 @@ main(int argc, // I - Number of command-line args
11221122
if (getenv("IPPFIND_DEBUG"))
11231123
fprintf(stderr, "STATUS processed=%u, resolved=%u, count=%u\n", (unsigned)processed, (unsigned)resolved, (unsigned)count);
11241124

1125-
if (processed > 0 && processed == cupsArrayGetCount(services.services) && bonjour_timeout <= 1.0)
1125+
if (processed > 0 && (processed == cupsArrayGetCount(services.services) || (cupsGetClock() - last_update) >= 2.5) && bonjour_timeout <= 1.0)
11261126
break;
11271127

11281128
// Give the browsers/resolvers some time...
@@ -1152,6 +1152,9 @@ browse_callback(
11521152
{
11531153
ippfind_srv_t *service; // Service
11541154

1155+
1156+
last_update = cupsGetClock();
1157+
11551158
if (getenv("IPPFIND_DEBUG"))
11561159
fprintf(stderr, "B flags=0x%04X, if_index=%u, serviceName=\"%s\", regtype=\"%s\", replyDomain=\"%s\"\n", flags, if_index, serviceName, regtype, replyDomain);
11571160

@@ -1592,31 +1595,6 @@ get_service(ippfind_srvs_t *services, // I - Service array
15921595
}
15931596

15941597

1595-
//
1596-
// 'get_time()' - Get the current time-of-day in seconds.
1597-
//
1598-
1599-
static double
1600-
get_time(void)
1601-
{
1602-
#ifdef _WIN32
1603-
struct _timeb curtime; // Current Windows time
1604-
1605-
_ftime(&curtime);
1606-
1607-
return (curtime.time + 0.001 * curtime.millitm);
1608-
1609-
#else
1610-
struct timeval curtime; // Current UNIX time
1611-
1612-
if (gettimeofday(&curtime, NULL))
1613-
return (0.0);
1614-
else
1615-
return (curtime.tv_sec + 0.000001 * curtime.tv_usec);
1616-
#endif // _WIN32
1617-
}
1618-
1619-
16201598
//
16211599
// 'list_service()' - List the contents of a service.
16221600
//
@@ -1897,6 +1875,8 @@ resolve_callback(
18971875
char *value; // Pointer into value
18981876

18991877

1878+
last_update = cupsGetClock();
1879+
19001880
if (getenv("IPPFIND_DEBUG"))
19011881
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);
19021882

@@ -1907,7 +1887,7 @@ resolve_callback(
19071887
// Only process "add" data...
19081888
if (flags & CUPS_DNSSD_FLAGS_ERROR)
19091889
{
1910-
bonjour_error = 1;
1890+
bonjour_error = true;
19111891
return;
19121892
}
19131893

0 commit comments

Comments
 (0)