Skip to content

Commit 23bc8ac

Browse files
committed
Fix DNS-SD callbacks on Windows (Issue #1528)
1 parent 002cedc commit 23bc8ac

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

cups/dnssd.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,9 @@ cupsDNSSDBrowseNew(
548548
// 'cupsDNSSDCopyComputerName()' - Copy the current human-readable name for the system.
549549
//
550550
// This function copies the current human-readable name ("My Computer") to the
551-
// provided buffer. The "dnssd" parameter is a DNS-SD context created with
552-
// @link cupsDNSSDNew@. The "buffer" parameter points to a character array of
553-
// at least 128 bytes and the "bufsize" parameter specifies the actual size of
551+
// provided buffer. The "dnssd" argument is a DNS-SD context created with
552+
// @link cupsDNSSDNew@. The "buffer" argument points to a character array of
553+
// at least 128 bytes and the "bufsize" argument specifies the actual size of
554554
// the array.
555555
//
556556

@@ -618,9 +618,9 @@ cupsDNSSDCopyComputerName(
618618
// 'cupsDNSSDCopyHostName()' - Copy the current mDNS hostname for the system.
619619
//
620620
// This function copies the current mDNS hostname ("hostname.local") to the
621-
// provided buffer. The "dnssd" parameter is a DNS-SD context created with
622-
// @link cupsDNSSDNew@. The "buffer" parameter points to a character array of
623-
// at least 70 bytes and the "bufsize" parameter specifies the actual size of
621+
// provided buffer. The "dnssd" argument is a DNS-SD context created with
622+
// @link cupsDNSSDNew@. The "buffer" argument points to a character array of
623+
// at least 70 bytes and the "bufsize" argument specifies the actual size of
624624
// the array.
625625
//
626626

@@ -960,7 +960,7 @@ cupsDNSSDQueryGetContext(
960960
// 'cupsDNSSDQueryNew()' - Create a new query request.
961961
//
962962
// This function creates a new DNS-SD query request for the specified full
963-
// service name and DNS record type. The "fullname" parameter specifies the
963+
// service name and DNS record type. The "fullname" argument specifies the
964964
// full DNS name of the service (instance name, type, and domain) being queried.
965965
// Responses to the query are reported using the required query callback
966966
// function with the "flags" argument set to `CUPS_DNSSD_FLAGS_NONE` on success
@@ -1472,6 +1472,14 @@ cupsDNSSDServiceAdd(
14721472
char fullname[256]; // Full service instance name
14731473
cups_array_t *tarray; // Types array
14741474

1475+
if (port == 0)
1476+
{
1477+
// Windows DNS-SD support doesn't allow for so-called "flagship naming",
1478+
// just ignore services on port 0 for now...
1479+
// TODO: Report bug to Microsoft about lack of support for services on port 0.
1480+
return (true);
1481+
}
1482+
14751483
if ((tarray = cupsArrayNewStrings(types, ',')) == NULL)
14761484
{
14771485
report_error(service->dnssd, "Unable to create types array: %s", strerror(errno));
@@ -1537,7 +1545,7 @@ cupsDNSSDServiceAdd(
15371545

15381546
if ((srv->req.pServiceInstance = DnsServiceConstructInstance(srv->fullname, srv->hostname, /*pIp4*/NULL, /*pIp6*/NULL, port, 0, 0, (DWORD)num_txt, keys, values)) == NULL)
15391547
{
1540-
report_error(service->dnssd, "Unable to allocate memory for '%s'.", fullname);
1548+
report_error(service->dnssd, "Unable to allocate memory for '%s' for host '%s', port %d.", fullname, host ? host : service->dnssd->hostname, port);
15411549
ret = false;
15421550
cupsArrayDelete(tarray);
15431551
goto done;
@@ -2466,8 +2474,8 @@ mdns_to_cups(
24662474
static void
24672475
win32_browse_cb(
24682476
DWORD status, // I - Status
2469-
PVOID context, // I - Browser
2470-
PDNS_RECORD records) // I - Record list
2477+
PVOID context, // I - Browser
2478+
PDNS_RECORD records) // I - Record list
24712479
{
24722480
cups_dnssd_browse_t *browse = (cups_dnssd_browse_t *)context;
24732481
PDNS_RECORD record; // Current DNS record
@@ -2487,7 +2495,7 @@ win32_browse_cb(
24872495
}
24882496
}
24892497

2490-
(browse->cb)(browse, browse->cb_data, status == ERROR_SUCCESS ? CUPS_DNSSD_FLAGS_NONE : CUPS_DNSSD_FLAGS_ERROR, /*if_index*/0, name, type, domain);
2498+
(browse->cb)(browse, browse->cb_data, status == ERROR_SUCCESS ? CUPS_DNSSD_FLAGS_ADD : CUPS_DNSSD_FLAGS_ERROR, /*if_index*/0, name, type, domain);
24912499

24922500
DnsRecordListFree(records, DnsFreeRecordList);
24932501
}
@@ -2515,7 +2523,7 @@ win32_query_cb(
25152523
PDNS_RECORD record; // Current DNS record
25162524

25172525
for (record = result->pQueryRecords; record; record = record->pNext)
2518-
(query->cb)(query, query->cb_data, CUPS_DNSSD_FLAGS_NONE, /*if_index*/0, fullname, record->wType, &record->Data, record->wDataLength);
2526+
(query->cb)(query, query->cb_data, CUPS_DNSSD_FLAGS_ADD, /*if_index*/0, fullname, record->wType, &record->Data, record->wDataLength);
25192527

25202528
DnsRecordListFree(result->pQueryRecords, DnsFreeRecordList);
25212529
}
@@ -2557,7 +2565,7 @@ win32_resolve_cb(
25572565
num_txt = cupsAddOption(txtname, txtvalue, num_txt, &txt);
25582566
}
25592567

2560-
(resolve->cb)(resolve, resolve->cb_data, CUPS_DNSSD_FLAGS_NONE, instance->dwInterfaceIndex, fullname, hostname, instance->wPort, num_txt, txt);
2568+
(resolve->cb)(resolve, resolve->cb_data, CUPS_DNSSD_FLAGS_ADD, instance->dwInterfaceIndex, fullname, hostname, instance->wPort, num_txt, txt);
25612569

25622570
cupsFreeOptions(num_txt, txt);
25632571
}
@@ -2581,7 +2589,7 @@ win32_service_cb(
25812589
cups_dnssd_service_t *service = (cups_dnssd_service_t *)context;
25822590
// Service
25832591

2584-
(service->cb)(service, service->cb_data, status == ERROR_SUCCESS ? CUPS_DNSSD_FLAGS_NONE : CUPS_DNSSD_FLAGS_ERROR);
2592+
(service->cb)(service, service->cb_data, status == ERROR_SUCCESS ? CUPS_DNSSD_FLAGS_ADD : CUPS_DNSSD_FLAGS_ERROR);
25852593

25862594
if (instance)
25872595
DnsServiceFreeInstance(instance);

0 commit comments

Comments
 (0)