#endif /* __APPLE__ */
#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
+# define _CUPS_DNSSD_GET_DESTS 250 /* Milliseconds for cupsGetDests */
# define _CUPS_DNSSD_MAXTIME 50 /* Milliseconds for maximum quantum of time */
#endif /* HAVE_DNSSD || HAVE_AVAHI */
main_fd = DNSServiceRefSockFD(data.main_ref);
ipp_ref = data.main_ref;
- DNSServiceBrowse(&ipp_ref, kDNSServiceFlagsShareConnection, 0,
- "_ipp._tcp", NULL,
- (DNSServiceBrowseReply)cups_dnssd_browse_cb, &data);
+ if (DNSServiceBrowse(&ipp_ref, kDNSServiceFlagsShareConnection, 0, "_ipp._tcp", NULL, (DNSServiceBrowseReply)cups_dnssd_browse_cb, &data) != kDNSServiceErr_NoError)
+ {
+ DEBUG_puts("1cupsEnumDests: Unable to create IPP browser, returning 0.");
+ DNSServiceRefDeallocate(data.main_ref);
+ return (0);
+ }
local_ipp_ref = data.main_ref;
- DNSServiceBrowse(&local_ipp_ref, kDNSServiceFlagsShareConnection,
- kDNSServiceInterfaceIndexLocalOnly,
- "_ipp._tcp", NULL,
- (DNSServiceBrowseReply)cups_dnssd_local_cb, &data);
+ if (DNSServiceBrowse(&local_ipp_ref, kDNSServiceFlagsShareConnection, kDNSServiceInterfaceIndexLocalOnly, "_ipp._tcp", NULL, (DNSServiceBrowseReply)cups_dnssd_local_cb, &data) != kDNSServiceErr_NoError)
+ {
+ DEBUG_puts("1cupsEnumDests: Unable to create local IPP browser, returning 0.");
+ DNSServiceRefDeallocate(data.main_ref);
+ return (0);
+ }
# ifdef HAVE_SSL
ipps_ref = data.main_ref;
- DNSServiceBrowse(&ipps_ref, kDNSServiceFlagsShareConnection, 0,
- "_ipps._tcp", NULL,
- (DNSServiceBrowseReply)cups_dnssd_browse_cb, &data);
+ if (DNSServiceBrowse(&ipps_ref, kDNSServiceFlagsShareConnection, 0, "_ipps._tcp", NULL, (DNSServiceBrowseReply)cups_dnssd_browse_cb, &data) != kDNSServiceErr_NoError)
+ {
+ DEBUG_puts("1cupsEnumDests: Unable to create IPPS browser, returning 0.");
+ DNSServiceRefDeallocate(data.main_ref);
+ return (0);
+ }
local_ipps_ref = data.main_ref;
- DNSServiceBrowse(&local_ipps_ref, kDNSServiceFlagsShareConnection,
- kDNSServiceInterfaceIndexLocalOnly,
- "_ipps._tcp", NULL,
- (DNSServiceBrowseReply)cups_dnssd_local_cb, &data);
+ if (DNSServiceBrowse(&local_ipps_ref, kDNSServiceFlagsShareConnection, kDNSServiceInterfaceIndexLocalOnly, "_ipps._tcp", NULL, (DNSServiceBrowseReply)cups_dnssd_local_cb, &data) != kDNSServiceErr_NoError)
+ {
+ DEBUG_puts("1cupsEnumDests: Unable to create local IPPS browser, returning 0.");
+ DNSServiceRefDeallocate(data.main_ref);
+ return (0);
+ }
# endif /* HAVE_SSL */
# else /* HAVE_AVAHI */
}
data.browsers = 1;
- ipp_ref = avahi_service_browser_new(data.client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipp._tcp", NULL, 0, cups_dnssd_browse_cb, &data);
+ if ((ipp_ref = avahi_service_browser_new(data.client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipp._tcp", NULL, 0, cups_dnssd_browse_cb, &data)) == NULL)
+ {
+ DEBUG_puts("1cupsEnumDests: Unable to create Avahi IPP browser, returning 0.");
+
+ avahi_client_free(data.client);
+ avahi_simple_poll_free(data.simple_poll);
+ return (0);
+ }
# ifdef HAVE_SSL
data.browsers ++;
- ipps_ref = avahi_service_browser_new(data.client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipps._tcp", NULL, 0, cups_dnssd_browse_cb, &data);
+ if ((ipps_ref = avahi_service_browser_new(data.client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipps._tcp", NULL, 0, cups_dnssd_browse_cb, &data)) == NULL)
+ {
+ DEBUG_puts("1cupsEnumDests: Unable to create Avahi IPPS browser, returning 0.");
+
+ avahi_service_browser_free(ipp_ref);
+ avahi_client_free(data.client);
+ avahi_simple_poll_free(data.simple_poll);
+ return (0);
+ }
# endif /* HAVE_SSL */
# endif /* HAVE_DNSSD */
if (nfds > 0)
DNSServiceProcessResult(data.main_ref);
+ else if (nfds < 0 && errno != EINTR && errno != EAGAIN)
+ break;
# else /* HAVE_AVAHI */
data.got_data = 0;
data.num_dests = 0;
data.dests = NULL;
- cupsEnumDests(0, 250, NULL, 0, 0, (cups_dest_cb_t)cups_get_cb, &data);
+ cupsEnumDests(0, _CUPS_DNSSD_GET_DESTS, NULL, 0, 0, (cups_dest_cb_t)cups_get_cb, &data);
/*
* Make a copy of the "real" queues for a later sanity check...
/*
* CUPS API test program for CUPS.
*
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2017 by Apple Inc.
* Copyright 2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
cups_dest_t *dests, /* Destinations */
*dest, /* Current destination */
*named_dest; /* Current named destination */
- const char *ppdfile; /* PPD file */
+ const char *dest_name, /* Destination name */
+ *dval, /* Destination value */
+ *ppdfile; /* PPD file */
ppd_file_t *ppd; /* PPD file data */
int num_jobs; /* Number of jobs for queue */
cups_job_t *jobs; /* Jobs for queue */
* cupsGetDest(printer)
*/
- printf("cupsGetDest(\"%s\"): ", dests[num_dests / 2].name);
+ for (i = 0, dest_name = NULL; i < num_dests; i ++)
+ {
+ if ((dval = cupsGetOption("printer-is-temporary", dests[i].num_options, dest[i].options)) != NULL && !strcmp(dval, "false"))
+ {
+ dest_name = dests[i].name;
+ break;
+ }
+ }
+
+ printf("cupsGetDest(\"%s\"): ", dest_name ? dest_name : "(null)");
fflush(stdout);
- if ((dest = cupsGetDest(dests[num_dests / 2].name, NULL, num_dests,
- dests)) == NULL)
+ if ((dest = cupsGetDest(dest_name, NULL, num_dests, dests)) == NULL)
{
puts("FAIL");
return (1);
dest->instance ? dest->instance : "(null)");
fflush(stdout);
- if ((named_dest = cupsGetNamedDest(NULL, dest->name,
- dest->instance)) == NULL ||
+ if ((named_dest = cupsGetNamedDest(NULL, dest->name, dest->instance)) == NULL ||
!dests_equal(dest, named_dest))
{
if (named_dest)
fputs("cupsPrintFile: ", stdout);
fflush(stdout);
- if (cupsPrintFile(dest->name, "../data/testprint", "Test Page",
+ if (cupsPrintFile(dest->name, "../test/testfile.pdf", "Test Page",
dest->num_options, dest->options) <= 0)
{
printf("FAIL (%s)\n", cupsLastErrorString());
* cupsGetPPD(printer)
*/
- fputs("cupsGetPPD(): ", stdout);
+ fputs("cupsGetPPD: ", stdout);
fflush(stdout);
if ((ppdfile = cupsGetPPD(dest->name)) == NULL)
* ppdOpenFile()
*/
- fputs("ppdOpenFile(): ", stdout);
+ fputs("ppdOpenFile: ", stdout);
fflush(stdout);
if ((ppd = ppdOpenFile(ppdfile)) == NULL)
{
int i; /* Looping var */
cups_option_t *aoption; /* Current option */
+ cups_option_t *boption; /* Current option */
const char *bval; /* Option value */
if (!a || !b)
return;
- puts(" Item cupsGetDest cupsGetNamedDest");
- puts(" -------------------- -------------------- --------------------");
+ puts(" Item cupsGetDest cupsGetNamedDest");
+ puts(" -------------------- ------------------------ ------------------------");
if (_cups_strcasecmp(a->name, b->name))
- printf(" name %-20.20s %-20.20s\n", a->name, b->name);
+ printf(" name %-24.24s %-24.24s\n", a->name, b->name);
if ((a->instance && !b->instance) ||
(!a->instance && b->instance) ||
(a->instance && _cups_strcasecmp(a->instance, b->instance)))
- printf(" instance %-20.20s %-20.20s\n",
+ printf(" instance %-24.24s %-24.24s\n",
a->instance ? a->instance : "(null)",
b->instance ? b->instance : "(null)");
if (a->num_options != b->num_options)
- printf(" num_options %-20d %-20d\n", a->num_options,
+ printf(" num_options %-24d %-24d\n", a->num_options,
b->num_options);
for (i = a->num_options, aoption = a->options; i > 0; i --, aoption ++)
if ((bval = cupsGetOption(aoption->name, b->num_options,
b->options)) == NULL ||
strcmp(aoption->value, bval))
- printf(" %-20.20s %-20.20s %-20.20s\n", aoption->name,
+ printf(" %-20.20s %-24.24s %-24.24s\n", aoption->name,
aoption->value, bval ? bval : "(null)");
+
+ for (i = b->num_options, boption = b->options; i > 0; i --, boption ++)
+ if (!cupsGetOption(boption->name, a->num_options, a->options))
+ printf(" %-20.20s %-24.24s %-24.24s\n", boption->name,
+ boption->value, "(null)");
}