4 * DNS-SD discovery backend for the Common UNIX Printing System (CUPS).
6 * Copyright 2008-2009 by Apple Inc.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * "LICENSE" which should have been included with this file. If this
12 * file is missing or damaged, see the license at "http://www.cups.org/".
14 * This file is subject to the Apple OS-Developed Software exception.
18 * main() - Browse for printers.
19 * browse_callback() - Browse devices.
20 * browse_local_callback() - Browse local devices.
21 * compare_devices() - Compare two devices.
22 * exec_backend() - Execute the backend that corresponds to the
23 * resolved service name.
24 * get_device() - Create or update a device.
25 * query_callback() - Process query data.
26 * sigterm_handler() - Handle termination signals...
27 * unquote() - Unquote a name string.
31 * Include necessary headers.
34 #include "backend-private.h"
35 #include <cups/array.h>
45 CUPS_DEVICE_PRINTER
= 0, /* lpd://... */
46 CUPS_DEVICE_IPP
, /* ipp://... */
47 CUPS_DEVICE_FAX_IPP
, /* ipp://... */
48 CUPS_DEVICE_PDL_DATASTREAM
, /* socket://... */
49 CUPS_DEVICE_RIOUSBPRINT
/* riousbprint://... */
55 DNSServiceRef ref
; /* Service reference for resolve */
56 char *name
, /* Service name */
57 *domain
, /* Domain name */
58 *fullName
, /* Full name */
59 *make_and_model
, /* Make and model from TXT record */
60 *device_id
; /* 1284 device ID from TXT record */
61 cups_devtype_t type
; /* Device registration type */
62 int priority
, /* Priority associated with type */
63 cups_shared
, /* CUPS shared printer? */
64 sent
; /* Did we list the device? */
72 static int job_canceled
= 0;
73 /* Set to 1 on SIGTERM */
80 static void browse_callback(DNSServiceRef sdRef
,
81 DNSServiceFlags flags
,
82 uint32_t interfaceIndex
,
83 DNSServiceErrorType errorCode
,
84 const char *serviceName
,
86 const char *replyDomain
, void *context
);
87 static void browse_local_callback(DNSServiceRef sdRef
,
88 DNSServiceFlags flags
,
89 uint32_t interfaceIndex
,
90 DNSServiceErrorType errorCode
,
91 const char *serviceName
,
93 const char *replyDomain
,
95 static int compare_devices(cups_device_t
*a
, cups_device_t
*b
);
96 static void exec_backend(char **argv
);
97 static cups_device_t
*get_device(cups_array_t
*devices
,
98 const char *serviceName
,
100 const char *replyDomain
);
101 static void query_callback(DNSServiceRef sdRef
,
102 DNSServiceFlags flags
,
103 uint32_t interfaceIndex
,
104 DNSServiceErrorType errorCode
,
105 const char *fullName
, uint16_t rrtype
,
106 uint16_t rrclass
, uint16_t rdlen
,
107 const void *rdata
, uint32_t ttl
,
109 static void sigterm_handler(int sig
);
110 static void unquote(char *dst
, const char *src
, size_t dstsize
);
114 * 'main()' - Browse for printers.
117 int /* O - Exit status */
118 main(int argc
, /* I - Number of command-line args */
119 char *argv
[]) /* I - Command-line arguments */
121 const char *name
; /* Backend name */
122 DNSServiceRef main_ref
, /* Main service reference */
123 fax_ipp_ref
, /* IPP fax service reference */
124 ipp_ref
, /* IPP service reference */
125 ipp_tls_ref
, /* IPP w/TLS service reference */
126 local_fax_ipp_ref
, /* Local IPP fax service reference */
127 local_ipp_ref
, /* Local IPP service reference */
128 local_ipp_tls_ref
, /* Local IPP w/TLS service reference */
129 local_printer_ref
, /* Local LPD service reference */
130 pdl_datastream_ref
, /* AppSocket service reference */
131 printer_ref
, /* LPD service reference */
132 riousbprint_ref
; /* Remote IO service reference */
133 int fd
; /* Main file descriptor */
134 fd_set input
; /* Input set for select() */
135 struct timeval timeout
; /* Timeout for select() */
136 cups_array_t
*devices
; /* Device array */
137 cups_device_t
*device
; /* Current device */
138 char uriName
[1024]; /* Unquoted fullName for URI */
139 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
140 struct sigaction action
; /* Actions for POSIX signals */
141 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
145 * Don't buffer stderr, and catch SIGTERM...
148 setbuf(stderr
, NULL
);
150 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
151 sigset(SIGTERM
, sigterm_handler
);
152 #elif defined(HAVE_SIGACTION)
153 memset(&action
, 0, sizeof(action
));
155 sigemptyset(&action
.sa_mask
);
156 action
.sa_handler
= SIG_IGN
;
157 sigaction(SIGTERM
, &action
, sigterm_handler
);
159 signal(SIGTERM
, sigterm_handler
);
160 #endif /* HAVE_SIGSET */
163 * Check command-line...
170 fprintf(stderr
, "Usage: %s job user title copies options [filename(s)]\n",
176 * Only do discovery when run as "dnssd"...
179 if ((name
= strrchr(argv
[0], '/')) != NULL
)
184 if (strcmp(name
, "dnssd"))
188 * Create an array to track devices...
191 devices
= cupsArrayNew((cups_array_func_t
)compare_devices
, NULL
);
194 * Browse for different kinds of printers...
197 if (DNSServiceCreateConnection(&main_ref
) != kDNSServiceErr_NoError
)
199 perror("ERROR: Unable to create service connection");
203 fd
= DNSServiceRefSockFD(main_ref
);
205 fax_ipp_ref
= main_ref
;
206 DNSServiceBrowse(&fax_ipp_ref
, kDNSServiceFlagsShareConnection
, 0,
207 "_fax-ipp._tcp", NULL
, browse_callback
, devices
);
210 DNSServiceBrowse(&ipp_ref
, kDNSServiceFlagsShareConnection
, 0,
211 "_ipp._tcp", NULL
, browse_callback
, devices
);
213 ipp_tls_ref
= main_ref
;
214 DNSServiceBrowse(&ipp_tls_ref
, kDNSServiceFlagsShareConnection
, 0,
215 "_ipp-tls._tcp", NULL
, browse_callback
, devices
);
217 local_fax_ipp_ref
= main_ref
;
218 DNSServiceBrowse(&local_fax_ipp_ref
, kDNSServiceFlagsShareConnection
,
219 kDNSServiceInterfaceIndexLocalOnly
,
220 "_fax-ipp._tcp", NULL
, browse_local_callback
, devices
);
222 local_ipp_ref
= main_ref
;
223 DNSServiceBrowse(&local_ipp_ref
, kDNSServiceFlagsShareConnection
,
224 kDNSServiceInterfaceIndexLocalOnly
,
225 "_ipp._tcp", NULL
, browse_local_callback
, devices
);
227 local_ipp_tls_ref
= main_ref
;
228 DNSServiceBrowse(&local_ipp_tls_ref
, kDNSServiceFlagsShareConnection
,
229 kDNSServiceInterfaceIndexLocalOnly
,
230 "_ipp-tls._tcp", NULL
, browse_local_callback
, devices
);
232 local_printer_ref
= main_ref
;
233 DNSServiceBrowse(&local_printer_ref
, kDNSServiceFlagsShareConnection
,
234 kDNSServiceInterfaceIndexLocalOnly
,
235 "_printer._tcp", NULL
, browse_local_callback
, devices
);
237 pdl_datastream_ref
= main_ref
;
238 DNSServiceBrowse(&pdl_datastream_ref
, kDNSServiceFlagsShareConnection
, 0,
239 "_pdl-datastream._tcp", NULL
, browse_callback
, devices
);
241 printer_ref
= main_ref
;
242 DNSServiceBrowse(&printer_ref
, kDNSServiceFlagsShareConnection
, 0,
243 "_printer._tcp", NULL
, browse_callback
, devices
);
245 riousbprint_ref
= main_ref
;
246 DNSServiceBrowse(&riousbprint_ref
, kDNSServiceFlagsShareConnection
, 0,
247 "_riousbprint._tcp", NULL
, browse_callback
, devices
);
250 * Loop until we are killed...
253 while (!job_canceled
)
261 if (select(fd
+ 1, &input
, NULL
, NULL
, &timeout
) < 0)
264 if (FD_ISSET(fd
, &input
))
267 * Process results of our browsing...
270 DNSServiceProcessResult(main_ref
);
275 * Announce any devices we've found...
278 DNSServiceErrorType status
; /* DNS query status */
279 cups_device_t
*best
; /* Best matching device */
280 char device_uri
[1024]; /* Device URI */
281 int count
; /* Number of queries */
284 for (device
= (cups_device_t
*)cupsArrayFirst(devices
),
285 best
= NULL
, count
= 0;
287 device
= (cups_device_t
*)cupsArrayNext(devices
))
288 if (!device
->ref
&& !device
->sent
)
291 * Found the device, now get the TXT record(s) for it...
296 device
->ref
= main_ref
;
298 fprintf(stderr
, "DEBUG: Querying \"%s\"...\n", device
->fullName
);
300 status
= DNSServiceQueryRecord(&(device
->ref
),
301 kDNSServiceFlagsShareConnection
,
304 kDNSServiceClass_IN
, query_callback
,
306 if (status
!= kDNSServiceErr_NoError
)
308 fputs("ERROR: Unable to query for TXT records!\n", stderr
);
309 fprintf(stderr
, "DEBUG: DNSServiceQueryRecord returned %d\n",
316 else if (!device
->sent
)
319 * Got the TXT records, now report the device...
322 DNSServiceRefDeallocate(device
->ref
);
327 else if (strcasecmp(best
->name
, device
->name
) ||
328 strcasecmp(best
->domain
, device
->domain
))
330 unquote(uriName
, best
->fullName
, sizeof(uriName
));
332 httpAssembleURI(HTTP_URI_CODING_ALL
, device_uri
, sizeof(device_uri
),
333 "dnssd", NULL
, uriName
, 0,
334 best
->cups_shared
? "/cups" : "/");
336 cupsBackendReport("network", device_uri
, best
->make_and_model
,
337 best
->name
, best
->device_id
, NULL
);
341 else if (best
->priority
> device
->priority
||
342 (best
->priority
== device
->priority
&&
343 best
->type
< device
->type
))
354 unquote(uriName
, best
->fullName
, sizeof(uriName
));
356 httpAssembleURI(HTTP_URI_CODING_ALL
, device_uri
, sizeof(device_uri
),
357 "dnssd", NULL
, uriName
, 0,
358 best
->cups_shared
? "/cups" : "/");
360 cupsBackendReport("network", device_uri
, best
->make_and_model
,
361 best
->name
, best
->device_id
, NULL
);
367 return (CUPS_BACKEND_OK
);
372 * 'browse_callback()' - Browse devices.
377 DNSServiceRef sdRef
, /* I - Service reference */
378 DNSServiceFlags flags
, /* I - Option flags */
379 uint32_t interfaceIndex
, /* I - Interface number */
380 DNSServiceErrorType errorCode
, /* I - Error, if any */
381 const char *serviceName
, /* I - Name of service/device */
382 const char *regtype
, /* I - Type of service */
383 const char *replyDomain
, /* I - Service domain */
384 void *context
) /* I - Devices array */
386 fprintf(stderr
, "DEBUG2: browse_callback(sdRef=%p, flags=%x, "
387 "interfaceIndex=%d, errorCode=%d, serviceName=\"%s\", "
388 "regtype=\"%s\", replyDomain=\"%s\", context=%p)\n",
389 sdRef
, flags
, interfaceIndex
, errorCode
,
390 serviceName
? serviceName
: "(null)",
391 regtype
? regtype
: "(null)",
392 replyDomain
? replyDomain
: "(null)",
396 * Only process "add" data...
399 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
406 get_device((cups_array_t
*)context
, serviceName
, regtype
, replyDomain
);
411 * 'browse_local_callback()' - Browse local devices.
415 browse_local_callback(
416 DNSServiceRef sdRef
, /* I - Service reference */
417 DNSServiceFlags flags
, /* I - Option flags */
418 uint32_t interfaceIndex
, /* I - Interface number */
419 DNSServiceErrorType errorCode
, /* I - Error, if any */
420 const char *serviceName
, /* I - Name of service/device */
421 const char *regtype
, /* I - Type of service */
422 const char *replyDomain
, /* I - Service domain */
423 void *context
) /* I - Devices array */
425 cups_device_t
*device
; /* Device */
428 fprintf(stderr
, "DEBUG2: browse_local_callback(sdRef=%p, flags=%x, "
429 "interfaceIndex=%d, errorCode=%d, serviceName=\"%s\", "
430 "regtype=\"%s\", replyDomain=\"%s\", context=%p)\n",
431 sdRef
, flags
, interfaceIndex
, errorCode
,
432 serviceName
? serviceName
: "(null)",
433 regtype
? regtype
: "(null)",
434 replyDomain
? replyDomain
: "(null)",
438 * Only process "add" data...
441 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
448 device
= get_device((cups_array_t
*)context
, serviceName
, regtype
,
452 * Hide locally-registered devices...
455 fprintf(stderr
, "DEBUG: Hiding local printer \"%s\"...\n",
462 * 'compare_devices()' - Compare two devices.
465 static int /* O - Result of comparison */
466 compare_devices(cups_device_t
*a
, /* I - First device */
467 cups_device_t
*b
) /* I - Second device */
469 return (strcmp(a
->name
, b
->name
));
474 * 'exec_backend()' - Execute the backend that corresponds to the
475 * resolved service name.
479 exec_backend(char **argv
) /* I - Command-line arguments */
481 const char *resolved_uri
, /* Resolved device URI */
482 *cups_serverbin
; /* Location of programs */
483 char scheme
[1024], /* Scheme from URI */
484 *ptr
, /* Pointer into scheme */
485 filename
[1024]; /* Backend filename */
489 * Resolve the device URI...
492 if ((resolved_uri
= cupsBackendDeviceURI(argv
)) == NULL
)
495 exit(CUPS_BACKEND_OK
);
497 exit(CUPS_BACKEND_FAILED
);
501 * Extract the scheme from the URI...
504 strlcpy(scheme
, resolved_uri
, sizeof(scheme
));
505 if ((ptr
= strchr(scheme
, ':')) != NULL
)
509 * Get the filename of the backend...
512 if ((cups_serverbin
= getenv("CUPS_SERVERBIN")) == NULL
)
513 cups_serverbin
= CUPS_SERVERBIN
;
515 snprintf(filename
, sizeof(filename
), "%s/backend/%s", cups_serverbin
, scheme
);
518 * Overwrite the device URI and run the new backend...
521 setenv("DEVICE_URI", resolved_uri
, 1);
523 argv
[0] = (char *)resolved_uri
;
525 fprintf(stderr
, "DEBUG: Executing backend \"%s\"...\n", filename
);
527 execv(filename
, argv
);
529 fprintf(stderr
, "ERROR: Unable to execute backend \"%s\": %s\n", filename
,
531 exit(CUPS_BACKEND_STOP
);
536 * 'get_device()' - Create or update a device.
539 static cups_device_t
* /* O - Device */
540 get_device(cups_array_t
*devices
, /* I - Device array */
541 const char *serviceName
, /* I - Name of service/device */
542 const char *regtype
, /* I - Type of service */
543 const char *replyDomain
) /* I - Service domain */
545 cups_device_t key
, /* Search key */
546 *device
; /* Device */
547 char fullName
[kDNSServiceMaxDomainName
];
548 /* Full name for query */
552 * See if this is a new device...
555 key
.name
= (char *)serviceName
;
557 if (!strcmp(regtype
, "_ipp._tcp.") ||
558 !strcmp(regtype
, "_ipp-tls._tcp."))
559 key
.type
= CUPS_DEVICE_IPP
;
560 else if (!strcmp(regtype
, "_fax-ipp._tcp."))
561 key
.type
= CUPS_DEVICE_FAX_IPP
;
562 else if (!strcmp(regtype
, "_printer._tcp."))
563 key
.type
= CUPS_DEVICE_PRINTER
;
564 else if (!strcmp(regtype
, "_pdl-datastream._tcp."))
565 key
.type
= CUPS_DEVICE_PDL_DATASTREAM
;
567 key
.type
= CUPS_DEVICE_RIOUSBPRINT
;
569 for (device
= cupsArrayFind(devices
, &key
);
571 device
= cupsArrayNext(devices
))
572 if (strcasecmp(device
->name
, key
.name
))
574 else if (device
->type
== key
.type
)
576 if (!strcasecmp(device
->domain
, "local.") &&
577 strcasecmp(device
->domain
, replyDomain
))
580 * Update the .local listing to use the "global" domain name instead.
581 * The backend will try local lookups first, then the global domain name.
584 free(device
->domain
);
585 device
->domain
= strdup(replyDomain
);
587 DNSServiceConstructFullName(fullName
, device
->name
, regtype
,
589 free(device
->fullName
);
590 device
->fullName
= strdup(fullName
);
597 * Yes, add the device...
600 fprintf(stderr
, "DEBUG: Found \"%s.%s%s\"...\n", serviceName
, regtype
,
603 device
= calloc(sizeof(cups_device_t
), 1);
604 device
->name
= strdup(serviceName
);
605 device
->domain
= strdup(replyDomain
);
606 device
->type
= key
.type
;
607 device
->priority
= 50;
609 cupsArrayAdd(devices
, device
);
612 * Set the "full name" of this service, which is used for queries...
615 DNSServiceConstructFullName(fullName
, serviceName
, regtype
, replyDomain
);
616 device
->fullName
= strdup(fullName
);
623 * 'query_callback()' - Process query data.
628 DNSServiceRef sdRef
, /* I - Service reference */
629 DNSServiceFlags flags
, /* I - Data flags */
630 uint32_t interfaceIndex
, /* I - Interface */
631 DNSServiceErrorType errorCode
, /* I - Error, if any */
632 const char *fullName
, /* I - Full service name */
633 uint16_t rrtype
, /* I - Record type */
634 uint16_t rrclass
, /* I - Record class */
635 uint16_t rdlen
, /* I - Length of record data */
636 const void *rdata
, /* I - Record data */
637 uint32_t ttl
, /* I - Time-to-live */
638 void *context
) /* I - Devices array */
640 cups_array_t
*devices
; /* Device array */
641 char name
[1024], /* Service name */
642 *ptr
; /* Pointer into string */
643 cups_device_t dkey
, /* Search key */
644 *device
; /* Device */
647 fprintf(stderr
, "DEBUG2: query_callback(sdRef=%p, flags=%x, "
648 "interfaceIndex=%d, errorCode=%d, fullName=\"%s\", "
649 "rrtype=%u, rrclass=%u, rdlen=%u, rdata=%p, ttl=%u, "
651 sdRef
, flags
, interfaceIndex
, errorCode
,
652 fullName
? fullName
: "(null)", rrtype
, rrclass
, rdlen
, rdata
, ttl
,
656 * Only process "add" data...
659 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
663 * Lookup the service in the devices array.
666 devices
= (cups_array_t
*)context
;
669 unquote(name
, fullName
, sizeof(name
));
671 if ((dkey
.domain
= strstr(name
, "._tcp.")) != NULL
)
674 dkey
.domain
= (char *)"local.";
676 if ((ptr
= strstr(name
, "._")) != NULL
)
679 if (strstr(fullName
, "_ipp._tcp.") ||
680 strstr(fullName
, "_ipp-tls._tcp."))
681 dkey
.type
= CUPS_DEVICE_IPP
;
682 else if (strstr(fullName
, "_fax-ipp._tcp."))
683 dkey
.type
= CUPS_DEVICE_FAX_IPP
;
684 else if (strstr(fullName
, "_printer._tcp."))
685 dkey
.type
= CUPS_DEVICE_PRINTER
;
686 else if (strstr(fullName
, "_pdl-datastream._tcp."))
687 dkey
.type
= CUPS_DEVICE_PDL_DATASTREAM
;
689 dkey
.type
= CUPS_DEVICE_RIOUSBPRINT
;
691 for (device
= cupsArrayFind(devices
, &dkey
);
693 device
= cupsArrayNext(devices
))
695 if (strcasecmp(device
->name
, dkey
.name
) ||
696 strcasecmp(device
->domain
, dkey
.domain
))
701 else if (device
->type
== dkey
.type
)
704 * Found it, pull out the priority and make and model from the TXT
705 * record and save it...
708 const uint8_t *data
, /* Pointer into data */
709 *datanext
, /* Next key/value pair */
710 *dataend
; /* End of entire TXT record */
711 uint8_t datalen
; /* Length of current key/value pair */
712 char key
[256], /* Key string */
713 value
[256], /* Value string */
715 /* Manufacturer and model */
716 model
[256], /* Model */
717 device_id
[2048];/* 1284 device ID */
721 make_and_model
[0] = '\0';
723 strcpy(model
, "Unknown");
725 for (data
= rdata
, dataend
= data
+ rdlen
;
730 * Read a key/value pair starting with an 8-bit length. Since the
731 * length is 8 bits and the size of the key/value buffers is 256, we
732 * don't need to check for overflow...
737 if (!datalen
|| (data
+ datalen
) >= dataend
)
740 datanext
= data
+ datalen
;
742 for (ptr
= key
; data
< datanext
&& *data
!= '='; data
++)
746 if (data
< datanext
&& *data
== '=')
751 memcpy(value
, data
, datanext
- data
);
752 value
[datanext
- data
] = '\0';
757 if (!strncasecmp(key
, "usb_", 4))
760 * Add USB device ID information...
763 ptr
= device_id
+ strlen(device_id
);
764 snprintf(ptr
, sizeof(device_id
) - (ptr
- device_id
), "%s:%s;",
768 if (!strcasecmp(key
, "usb_MFG") || !strcasecmp(key
, "usb_MANU") ||
769 !strcasecmp(key
, "usb_MANUFACTURER"))
770 strcpy(make_and_model
, value
);
771 else if (!strcasecmp(key
, "usb_MDL") || !strcasecmp(key
, "usb_MODEL"))
772 strcpy(model
, value
);
773 else if (!strcasecmp(key
, "product") && !strstr(value
, "Ghostscript"))
778 * Strip parenthesis...
781 if ((ptr
= value
+ strlen(value
) - 1) > value
&& *ptr
== ')')
784 strcpy(model
, value
+ 1);
787 strcpy(model
, value
);
789 else if (!strcasecmp(key
, "ty"))
791 strcpy(model
, value
);
793 if ((ptr
= strchr(model
, ',')) != NULL
)
796 else if (!strcasecmp(key
, "priority"))
797 device
->priority
= atoi(value
);
798 else if ((device
->type
== CUPS_DEVICE_IPP
||
799 device
->type
== CUPS_DEVICE_PRINTER
) &&
800 !strcasecmp(key
, "printer-type"))
803 * This is a CUPS printer!
806 device
->cups_shared
= 1;
808 if (device
->type
== CUPS_DEVICE_PRINTER
)
813 if (device
->device_id
)
814 free(device
->device_id
);
816 if (!device_id
[0] && strcmp(model
, "Unknown"))
818 if (make_and_model
[0])
819 snprintf(device_id
, sizeof(device_id
), "MFG:%s;MDL:%s;",
820 make_and_model
, model
);
821 else if (!strncasecmp(model
, "designjet ", 10))
822 snprintf(device_id
, sizeof(device_id
), "MFG:HP;MDL:%s", model
+ 10);
823 else if (!strncasecmp(model
, "stylus ", 7))
824 snprintf(device_id
, sizeof(device_id
), "MFG:EPSON;MDL:%s", model
+ 7);
825 else if ((ptr
= strchr(model
, ' ')) != NULL
)
828 * Assume the first word is the make...
831 memcpy(make_and_model
, model
, ptr
- model
);
832 make_and_model
[ptr
- model
] = '\0';
834 snprintf(device_id
, sizeof(device_id
), "MFG:%s;MDL:%s",
835 make_and_model
, ptr
+ 1);
840 device
->device_id
= strdup(device_id
);
842 device
->device_id
= NULL
;
844 if (device
->make_and_model
)
845 free(device
->make_and_model
);
847 if (make_and_model
[0])
849 strlcat(make_and_model
, " ", sizeof(make_and_model
));
850 strlcat(make_and_model
, model
, sizeof(make_and_model
));
852 device
->make_and_model
= strdup(make_and_model
);
855 device
->make_and_model
= strdup(model
);
861 fprintf(stderr
, "DEBUG: Ignoring TXT record for \"%s\"...\n", fullName
);
866 * 'sigterm_handler()' - Handle termination signals...
870 sigterm_handler(int sig
) /* I - Signal number (unused) */
877 * 'unquote()' - Unquote a name string.
881 unquote(char *dst
, /* I - Destination buffer */
882 const char *src
, /* I - Source string */
883 size_t dstsize
) /* I - Size of destination buffer */
885 char *dstend
= dst
+ dstsize
- 1; /* End of destination buffer */
888 while (*src
&& dst
< dstend
)
893 if (isdigit(src
[0] & 255) && isdigit(src
[1] & 255) &&
894 isdigit(src
[2] & 255))
896 *dst
++ = ((((src
[0] - '0') * 10) + src
[1] - '0') * 10) + src
[2] - '0';