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)
{
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;
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
//
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);
// 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
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...
{
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);
}
-//
-// '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.
//
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);
// Only process "add" data...
if (flags & CUPS_DNSSD_FLAGS_ERROR)
{
- bonjour_error = 1;
+ bonjour_error = true;
return;
}