4 * Utility to find IPP printers via Bonjour/DNS-SD and optionally run
5 * commands such as IPP and Bonjour conformance tests. This tool is
6 * inspired by the UNIX "find" command, thus its name.
8 * Copyright 2008-2014 by Apple Inc.
10 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * file is missing or damaged, see the license at "http://www.cups.org/".
16 * This file is subject to the Apple OS-Developed Software exception.
20 * Include necessary headers.
23 #define _CUPS_NO_DEPRECATED
24 #include <cups/cups-private.h>
27 # include <sys/timeb.h>
29 # include <sys/wait.h>
34 #elif defined(HAVE_AVAHI)
35 # include <avahi-client/client.h>
36 # include <avahi-client/lookup.h>
37 # include <avahi-common/simple-watch.h>
38 # include <avahi-common/domain.h>
39 # include <avahi-common/error.h>
40 # include <avahi-common/malloc.h>
41 # define kDNSServiceMaxDomainName AVAHI_DOMAIN_NAME_MAX
42 #endif /* HAVE_DNSSD */
45 extern char **environ
; /* Process environment variables */
53 typedef enum ippfind_exit_e
/* Exit codes */
55 IPPFIND_EXIT_TRUE
= 0, /* OK and result is true */
56 IPPFIND_EXIT_FALSE
, /* OK but result is false*/
57 IPPFIND_EXIT_BONJOUR
, /* Browse/resolve failure */
58 IPPFIND_EXIT_SYNTAX
, /* Bad option or syntax error */
59 IPPFIND_EXIT_MEMORY
/* Out of memory */
62 typedef enum ippfind_op_e
/* Operations for expressions */
64 /* "Evaluation" operations */
65 IPPFIND_OP_NONE
, /* No operation */
66 IPPFIND_OP_AND
, /* Logical AND of all children */
67 IPPFIND_OP_OR
, /* Logical OR of all children */
68 IPPFIND_OP_TRUE
, /* Always true */
69 IPPFIND_OP_FALSE
, /* Always false */
70 IPPFIND_OP_IS_LOCAL
, /* Is a local service */
71 IPPFIND_OP_IS_REMOTE
, /* Is a remote service */
72 IPPFIND_OP_DOMAIN_REGEX
, /* Domain matches regular expression */
73 IPPFIND_OP_NAME_REGEX
, /* Name matches regular expression */
74 IPPFIND_OP_HOST_REGEX
, /* Hostname matches regular expression */
75 IPPFIND_OP_PORT_RANGE
, /* Port matches range */
76 IPPFIND_OP_PATH_REGEX
, /* Path matches regular expression */
77 IPPFIND_OP_TXT_EXISTS
, /* TXT record key exists */
78 IPPFIND_OP_TXT_REGEX
, /* TXT record key matches regular expression */
79 IPPFIND_OP_URI_REGEX
, /* URI matches regular expression */
81 /* "Output" operations */
82 IPPFIND_OP_EXEC
, /* Execute when true */
83 IPPFIND_OP_LIST
, /* List when true */
84 IPPFIND_OP_PRINT_NAME
, /* Print URI when true */
85 IPPFIND_OP_PRINT_URI
, /* Print name when true */
86 IPPFIND_OP_QUIET
/* No output when true */
89 typedef struct ippfind_expr_s
/* Expression */
92 *prev
, /* Previous expression */
93 *next
, /* Next expression */
94 *parent
, /* Parent expressions */
95 *child
; /* Child expressions */
96 ippfind_op_t op
; /* Operation code (see above) */
97 int invert
; /* Invert the result */
98 char *key
; /* TXT record key */
99 regex_t re
; /* Regular expression for matching */
100 int range
[2]; /* Port number range */
101 int num_args
; /* Number of arguments for exec */
102 char **args
; /* Arguments for exec */
105 typedef struct ippfind_srv_s
/* Service information */
108 DNSServiceRef ref
; /* Service reference for query */
109 #elif defined(HAVE_AVAHI)
110 AvahiServiceResolver
*ref
; /* Resolver */
111 #endif /* HAVE_DNSSD */
112 char *name
, /* Service name */
113 *domain
, /* Domain name */
114 *regtype
, /* Registration type */
115 *fullName
, /* Full name */
116 *host
, /* Hostname */
117 *resource
, /* Resource path */
119 int num_txt
; /* Number of TXT record keys */
120 cups_option_t
*txt
; /* TXT record keys */
121 int port
, /* Port number */
122 is_local
, /* Is a local service? */
123 is_processed
, /* Did we process the service? */
124 is_resolved
; /* Got the resolve data? */
133 static DNSServiceRef dnssd_ref
; /* Master service reference */
134 #elif defined(HAVE_AVAHI)
135 static AvahiClient
*avahi_client
= NULL
;/* Client information */
136 static int avahi_got_data
= 0; /* Got data from poll? */
137 static AvahiSimplePoll
*avahi_poll
= NULL
;
138 /* Poll information */
139 #endif /* HAVE_DNSSD */
141 static int address_family
= AF_UNSPEC
;
142 /* Address family for LIST */
143 static int bonjour_error
= 0; /* Error browsing/resolving? */
144 static double bonjour_timeout
= 1.0; /* Timeout in seconds */
145 static int ipp_version
= 20; /* IPP version for LIST */
153 static void DNSSD_API
browse_callback(DNSServiceRef sdRef
,
154 DNSServiceFlags flags
,
155 uint32_t interfaceIndex
,
156 DNSServiceErrorType errorCode
,
157 const char *serviceName
,
159 const char *replyDomain
, void *context
)
160 __attribute__((nonnull(1,5,6,7,8)));
161 static void DNSSD_API
browse_local_callback(DNSServiceRef sdRef
,
162 DNSServiceFlags flags
,
163 uint32_t interfaceIndex
,
164 DNSServiceErrorType errorCode
,
165 const char *serviceName
,
167 const char *replyDomain
,
169 __attribute__((nonnull(1,5,6,7,8)));
170 #elif defined(HAVE_AVAHI)
171 static void browse_callback(AvahiServiceBrowser
*browser
,
172 AvahiIfIndex interface
,
173 AvahiProtocol protocol
,
174 AvahiBrowserEvent event
,
175 const char *serviceName
,
177 const char *replyDomain
,
178 AvahiLookupResultFlags flags
,
180 static void client_callback(AvahiClient
*client
,
181 AvahiClientState state
,
183 #endif /* HAVE_AVAHI */
185 static int compare_services(ippfind_srv_t
*a
, ippfind_srv_t
*b
);
186 static const char *dnssd_error_string(int error
);
187 static int eval_expr(ippfind_srv_t
*service
,
188 ippfind_expr_t
*expressions
);
189 static int exec_program(ippfind_srv_t
*service
, int num_args
,
191 static ippfind_srv_t
*get_service(cups_array_t
*services
,
192 const char *serviceName
,
194 const char *replyDomain
)
195 __attribute__((nonnull(1,2,3,4)));
196 static double get_time(void);
197 static int list_service(ippfind_srv_t
*service
);
198 static ippfind_expr_t
*new_expr(ippfind_op_t op
, int invert
,
199 const char *value
, const char *regex
,
202 static void DNSSD_API
resolve_callback(DNSServiceRef sdRef
,
203 DNSServiceFlags flags
,
204 uint32_t interfaceIndex
,
205 DNSServiceErrorType errorCode
,
206 const char *fullName
,
207 const char *hostTarget
, uint16_t port
,
209 const unsigned char *txtRecord
,
211 __attribute__((nonnull(1,5,6,9, 10)));
212 #elif defined(HAVE_AVAHI)
213 static int poll_callback(struct pollfd
*pollfds
,
214 unsigned int num_pollfds
, int timeout
,
216 static void resolve_callback(AvahiServiceResolver
*res
,
217 AvahiIfIndex interface
,
218 AvahiProtocol protocol
,
219 AvahiResolverEvent event
,
220 const char *serviceName
,
222 const char *replyDomain
,
223 const char *host_name
,
224 const AvahiAddress
*address
,
226 AvahiStringList
*txt
,
227 AvahiLookupResultFlags flags
,
229 #endif /* HAVE_DNSSD */
230 static void set_service_uri(ippfind_srv_t
*service
);
231 static void show_usage(void) __attribute__((noreturn
));
232 static void show_version(void) __attribute__((noreturn
));
236 * 'main()' - Browse for printers.
239 int /* O - Exit status */
240 main(int argc
, /* I - Number of command-line args */
241 char *argv
[]) /* I - Command-line arguments */
243 int i
, /* Looping var */
244 have_output
= 0,/* Have output expression */
245 status
= IPPFIND_EXIT_TRUE
;
247 const char *opt
, /* Option character */
248 *search
; /* Current browse/resolve string */
249 cups_array_t
*searches
; /* Things to browse/resolve */
250 cups_array_t
*services
; /* Service array */
251 ippfind_srv_t
*service
; /* Current service */
252 ippfind_expr_t
*expressions
= NULL
,
253 /* Expression tree */
254 *temp
= NULL
, /* New expression */
255 *parent
= NULL
, /* Parent expression */
256 *current
= NULL
,/* Current expression */
257 *parens
[100]; /* Markers for parenthesis */
258 int num_parens
= 0; /* Number of parenthesis */
259 ippfind_op_t logic
= IPPFIND_OP_AND
;
260 /* Logic for next expression */
261 int invert
= 0; /* Invert expression? */
262 int err
; /* DNS-SD error */
264 fd_set sinput
; /* Input set for select() */
265 struct timeval stimeout
; /* Timeout for select() */
266 #endif /* HAVE_DNSSD */
267 double endtime
; /* End time */
268 static const char * const ops
[] = /* Node operation names */
294 * Initialize the locale...
297 _cupsSetLocale(argv
);
300 * Create arrays to track services and things we want to browse/resolve...
303 searches
= cupsArrayNew(NULL
, NULL
);
304 services
= cupsArrayNew((cups_array_func_t
)compare_services
, NULL
);
307 * Parse command-line...
310 for (i
= 1; i
< argc
; i
++)
312 if (argv
[i
][0] == '-')
314 if (argv
[i
][1] == '-')
317 * Parse --option options...
320 if (!strcmp(argv
[i
], "--and"))
322 if (logic
== IPPFIND_OP_OR
)
324 _cupsLangPuts(stderr
, _("ippfind: Cannot use --and after --or."));
330 _cupsLangPuts(stderr
,
331 _("ippfind: Missing expression before \"--and\"."));
337 else if (!strcmp(argv
[i
], "--domain"))
342 _cupsLangPrintf(stderr
,
343 _("ippfind: Missing regular expression after %s."),
348 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
, argv
[i
],
350 return (IPPFIND_EXIT_MEMORY
);
352 else if (!strcmp(argv
[i
], "--exec"))
357 _cupsLangPrintf(stderr
, _("ippfind: Expected program after %s."),
362 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
364 return (IPPFIND_EXIT_MEMORY
);
367 if (!strcmp(argv
[i
], ";"))
374 _cupsLangPrintf(stderr
, _("ippfind: Expected semi-colon after %s."),
381 else if (!strcmp(argv
[i
], "--false"))
383 if ((temp
= new_expr(IPPFIND_OP_FALSE
, invert
, NULL
, NULL
,
385 return (IPPFIND_EXIT_MEMORY
);
387 else if (!strcmp(argv
[i
], "--help"))
391 else if (!strcmp(argv
[i
], "--host"))
396 _cupsLangPrintf(stderr
,
397 _("ippfind: Missing regular expression after %s."),
402 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
, argv
[i
],
404 return (IPPFIND_EXIT_MEMORY
);
406 else if (!strcmp(argv
[i
], "--ls"))
408 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
410 return (IPPFIND_EXIT_MEMORY
);
414 else if (!strcmp(argv
[i
], "--local"))
416 if ((temp
= new_expr(IPPFIND_OP_IS_LOCAL
, invert
, NULL
, NULL
,
418 return (IPPFIND_EXIT_MEMORY
);
420 else if (!strcmp(argv
[i
], "--name"))
425 _cupsLangPrintf(stderr
,
426 _("ippfind: Missing regular expression after %s."),
431 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
, argv
[i
],
433 return (IPPFIND_EXIT_MEMORY
);
435 else if (!strcmp(argv
[i
], "--not"))
439 else if (!strcmp(argv
[i
], "--or"))
443 _cupsLangPuts(stderr
,
444 _("ippfind: Missing expression before \"--or\"."));
448 logic
= IPPFIND_OP_OR
;
450 if (parent
&& parent
->op
== IPPFIND_OP_OR
)
453 * Already setup to do "foo --or bar --or baz"...
458 else if (!current
->prev
&& parent
)
461 * Change parent node into an OR node...
464 parent
->op
= IPPFIND_OP_OR
;
467 else if (!current
->prev
)
470 * Need to group "current" in a new OR node...
473 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
475 return (IPPFIND_EXIT_MEMORY
);
477 temp
->parent
= parent
;
478 temp
->child
= current
;
479 current
->parent
= temp
;
482 parent
->child
= temp
;
492 * Need to group previous expressions in an AND node, and then
493 * put that in an OR node...
496 if ((temp
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
498 return (IPPFIND_EXIT_MEMORY
);
500 while (current
->prev
)
502 current
->parent
= temp
;
503 current
= current
->prev
;
506 current
->parent
= temp
;
507 temp
->child
= current
;
510 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
512 return (IPPFIND_EXIT_MEMORY
);
514 temp
->parent
= parent
;
515 current
->parent
= temp
;
518 parent
->child
= temp
;
526 else if (!strcmp(argv
[i
], "--path"))
531 _cupsLangPrintf(stderr
,
532 _("ippfind: Missing regular expression after %s."),
537 if ((temp
= new_expr(IPPFIND_OP_PATH_REGEX
, invert
, NULL
, argv
[i
],
539 return (IPPFIND_EXIT_MEMORY
);
541 else if (!strcmp(argv
[i
], "--port"))
546 _cupsLangPrintf(stderr
,
547 _("ippfind: Expected port range after %s."),
552 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
], NULL
,
554 return (IPPFIND_EXIT_MEMORY
);
556 else if (!strcmp(argv
[i
], "--print"))
558 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
560 return (IPPFIND_EXIT_MEMORY
);
564 else if (!strcmp(argv
[i
], "--print-name"))
566 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
568 return (IPPFIND_EXIT_MEMORY
);
572 else if (!strcmp(argv
[i
], "--quiet"))
574 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
576 return (IPPFIND_EXIT_MEMORY
);
580 else if (!strcmp(argv
[i
], "--remote"))
582 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
584 return (IPPFIND_EXIT_MEMORY
);
586 else if (!strcmp(argv
[i
], "--true"))
588 if ((temp
= new_expr(IPPFIND_OP_TRUE
, invert
, NULL
, argv
[i
],
590 return (IPPFIND_EXIT_MEMORY
);
592 else if (!strcmp(argv
[i
], "--txt"))
597 _cupsLangPrintf(stderr
, _("ippfind: Expected key name after %s."),
602 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
], NULL
,
604 return (IPPFIND_EXIT_MEMORY
);
606 else if (!strncmp(argv
[i
], "--txt-", 5))
608 const char *key
= argv
[i
] + 5;/* TXT key */
613 _cupsLangPrintf(stderr
,
614 _("ippfind: Missing regular expression after %s."),
619 if ((temp
= new_expr(IPPFIND_OP_TXT_REGEX
, invert
, key
, argv
[i
],
621 return (IPPFIND_EXIT_MEMORY
);
623 else if (!strcmp(argv
[i
], "--uri"))
628 _cupsLangPrintf(stderr
,
629 _("ippfind: Missing regular expression after %s."),
634 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
, argv
[i
],
636 return (IPPFIND_EXIT_MEMORY
);
638 else if (!strcmp(argv
[i
], "--version"))
644 _cupsLangPrintf(stderr
, _("%s: Unknown option \"%s\"."),
652 * Add new expression...
655 if (logic
== IPPFIND_OP_AND
&&
656 current
&& current
->prev
&&
657 parent
&& parent
->op
!= IPPFIND_OP_AND
)
660 * Need to re-group "current" in a new AND node...
663 ippfind_expr_t
*tempand
; /* Temporary AND node */
665 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
667 return (IPPFIND_EXIT_MEMORY
);
670 * Replace "current" with new AND node at the end of this list...
673 current
->prev
->next
= tempand
;
674 tempand
->prev
= current
->prev
;
675 tempand
->parent
= parent
;
678 * Add "current to the new AND node...
681 tempand
->child
= current
;
682 current
->parent
= tempand
;
683 current
->prev
= NULL
;
688 * Add the new node at current level...
691 temp
->parent
= parent
;
692 temp
->prev
= current
;
695 current
->next
= temp
;
697 parent
->child
= temp
;
703 logic
= IPPFIND_OP_AND
;
713 for (opt
= argv
[i
] + 1; *opt
; opt
++)
718 address_family
= AF_INET
;
722 address_family
= AF_INET6
;
729 _cupsLangPrintf(stderr
,
730 _("ippfind: Expected port range after %s."),
735 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
],
736 NULL
, NULL
)) == NULL
)
737 return (IPPFIND_EXIT_MEMORY
);
744 _cupsLangPrintf(stderr
,
745 _("%s: Missing timeout for \"-T\"."),
750 bonjour_timeout
= atof(argv
[i
]);
757 _cupsLangPrintf(stderr
,
758 _("%s: Missing version for \"-V\"."),
763 if (!strcmp(argv
[i
], "1.1"))
765 else if (!strcmp(argv
[i
], "2.0"))
767 else if (!strcmp(argv
[i
], "2.1"))
769 else if (!strcmp(argv
[i
], "2.2"))
773 _cupsLangPrintf(stderr
, _("%s: Bad version %s for \"-V\"."),
783 _cupsLangPrintf(stderr
,
784 _("ippfind: Missing regular expression after "
789 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
,
790 argv
[i
], NULL
)) == NULL
)
791 return (IPPFIND_EXIT_MEMORY
);
798 _cupsLangPrintf(stderr
,
799 _("ippfind: Missing regular expression after "
804 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
,
805 argv
[i
], NULL
)) == NULL
)
806 return (IPPFIND_EXIT_MEMORY
);
810 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
812 return (IPPFIND_EXIT_MEMORY
);
821 _cupsLangPrintf(stderr
,
822 _("ippfind: Missing regular expression after "
827 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
,
828 argv
[i
], NULL
)) == NULL
)
829 return (IPPFIND_EXIT_MEMORY
);
833 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
835 return (IPPFIND_EXIT_MEMORY
);
841 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
843 return (IPPFIND_EXIT_MEMORY
);
849 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
851 return (IPPFIND_EXIT_MEMORY
);
855 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
857 return (IPPFIND_EXIT_MEMORY
);
866 _cupsLangPrintf(stderr
,
867 _("ippfind: Missing key name after %s."),
872 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
],
873 NULL
, NULL
)) == NULL
)
874 return (IPPFIND_EXIT_MEMORY
);
881 _cupsLangPrintf(stderr
,
882 _("ippfind: Missing regular expression after "
887 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
,
888 argv
[i
], NULL
)) == NULL
)
889 return (IPPFIND_EXIT_MEMORY
);
896 _cupsLangPrintf(stderr
,
897 _("ippfind: Missing program after %s."),
902 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
904 return (IPPFIND_EXIT_MEMORY
);
907 if (!strcmp(argv
[i
], ";"))
914 _cupsLangPrintf(stderr
,
915 _("ippfind: Missing semi-colon after %s."),
924 _cupsLangPrintf(stderr
, _("%s: Unknown option \"-%c\"."),
932 * Add new expression...
935 if (logic
== IPPFIND_OP_AND
&&
936 current
&& current
->prev
&&
937 parent
&& parent
->op
!= IPPFIND_OP_AND
)
940 * Need to re-group "current" in a new AND node...
943 ippfind_expr_t
*tempand
; /* Temporary AND node */
945 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
947 return (IPPFIND_EXIT_MEMORY
);
950 * Replace "current" with new AND node at the end of this list...
953 current
->prev
->next
= tempand
;
954 tempand
->prev
= current
->prev
;
955 tempand
->parent
= parent
;
958 * Add "current to the new AND node...
961 tempand
->child
= current
;
962 current
->parent
= tempand
;
963 current
->prev
= NULL
;
968 * Add the new node at current level...
971 temp
->parent
= parent
;
972 temp
->prev
= current
;
975 current
->next
= temp
;
977 parent
->child
= temp
;
983 logic
= IPPFIND_OP_AND
;
989 else if (!strcmp(argv
[i
], "("))
991 if (num_parens
>= 100)
993 _cupsLangPuts(stderr
, _("ippfind: Too many parenthesis."));
997 if ((temp
= new_expr(IPPFIND_OP_AND
, invert
, NULL
, NULL
, NULL
)) == NULL
)
998 return (IPPFIND_EXIT_MEMORY
);
1000 parens
[num_parens
++] = temp
;
1004 temp
->parent
= current
->parent
;
1005 current
->next
= temp
;
1006 temp
->prev
= current
;
1014 logic
= IPPFIND_OP_AND
;
1016 else if (!strcmp(argv
[i
], ")"))
1018 if (num_parens
<= 0)
1020 _cupsLangPuts(stderr
, _("ippfind: Missing open parenthesis."));
1024 current
= parens
[--num_parens
];
1025 parent
= current
->parent
;
1027 logic
= IPPFIND_OP_AND
;
1029 else if (!strcmp(argv
[i
], "!"))
1036 * _regtype._tcp[,subtype][.domain]
1040 * service-name[._regtype._tcp[.domain]]
1043 cupsArrayAdd(searches
, argv
[i
]);
1049 _cupsLangPuts(stderr
, _("ippfind: Missing close parenthesis."));
1056 * Add an implicit --print-uri to the end...
1059 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, 0, NULL
, NULL
, NULL
)) == NULL
)
1060 return (IPPFIND_EXIT_MEMORY
);
1064 while (current
->parent
)
1065 current
= current
->parent
;
1067 current
->next
= temp
;
1068 temp
->prev
= current
;
1074 if (cupsArrayCount(searches
) == 0)
1077 * Add an implicit browse for IPP printers ("_ipp._tcp")...
1080 cupsArrayAdd(searches
, "_ipp._tcp");
1083 if (getenv("IPPFIND_DEBUG"))
1085 int indent
= 4; /* Indentation */
1087 puts("Expression tree:");
1088 current
= expressions
;
1092 * Print the current node...
1095 printf("%*s%s%s\n", indent
, "", current
->invert
? "!" : "",
1099 * Advance to the next node...
1104 current
= current
->child
;
1107 else if (current
->next
)
1108 current
= current
->next
;
1109 else if (current
->parent
)
1111 while (current
->parent
)
1114 current
= current
->parent
;
1119 current
= current
->next
;
1125 puts("\nSearch items:");
1126 for (search
= (const char *)cupsArrayFirst(searches
);
1128 search
= (const char *)cupsArrayNext(searches
))
1129 printf(" %s\n", search
);
1133 * Start up browsing/resolving...
1137 if ((err
= DNSServiceCreateConnection(&dnssd_ref
)) != kDNSServiceErr_NoError
)
1139 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1140 dnssd_error_string(err
));
1141 return (IPPFIND_EXIT_BONJOUR
);
1144 #elif defined(HAVE_AVAHI)
1145 if ((avahi_poll
= avahi_simple_poll_new()) == NULL
)
1147 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1149 return (IPPFIND_EXIT_BONJOUR
);
1152 avahi_simple_poll_set_func(avahi_poll
, poll_callback
, NULL
);
1154 avahi_client
= avahi_client_new(avahi_simple_poll_get(avahi_poll
),
1155 0, client_callback
, avahi_poll
, &err
);
1158 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1159 dnssd_error_string(err
));
1160 return (IPPFIND_EXIT_BONJOUR
);
1162 #endif /* HAVE_DNSSD */
1164 for (search
= (const char *)cupsArrayFirst(searches
);
1166 search
= (const char *)cupsArrayNext(searches
))
1168 char buf
[1024], /* Full name string */
1169 *name
= NULL
, /* Service instance name */
1170 *regtype
, /* Registration type */
1171 *domain
; /* Domain, if any */
1173 strlcpy(buf
, search
, sizeof(buf
));
1178 else if ((regtype
= strstr(buf
, "._")) != NULL
)
1186 regtype
= "_ipp._tcp";
1189 for (domain
= regtype
; *domain
; domain
++)
1190 if (*domain
== '.' && domain
[1] != '_')
1202 * Resolve the given service instance name, regtype, and domain...
1208 service
= get_service(services
, name
, regtype
, domain
);
1211 service
->ref
= dnssd_ref
;
1212 err
= DNSServiceResolve(&(service
->ref
),
1213 kDNSServiceFlagsShareConnection
, 0, name
,
1214 regtype
, domain
, resolve_callback
,
1217 #elif defined(HAVE_AVAHI)
1218 service
->ref
= avahi_service_resolver_new(avahi_client
, AVAHI_IF_UNSPEC
,
1219 AVAHI_PROTO_UNSPEC
, name
,
1221 AVAHI_PROTO_UNSPEC
, 0,
1222 resolve_callback
, service
);
1226 err
= avahi_client_errno(avahi_client
);
1227 #endif /* HAVE_DNSSD */
1232 * Browse for services of the given type...
1236 DNSServiceRef ref
; /* Browse reference */
1239 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
, 0, regtype
,
1240 domain
, browse_callback
, services
);
1245 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
,
1246 kDNSServiceInterfaceIndexLocalOnly
, regtype
,
1247 domain
, browse_local_callback
, services
);
1250 #elif defined(HAVE_AVAHI)
1251 if (avahi_service_browser_new(avahi_client
, AVAHI_IF_UNSPEC
,
1252 AVAHI_PROTO_UNSPEC
, regtype
, domain
, 0,
1253 browse_callback
, services
))
1256 err
= avahi_client_errno(avahi_client
);
1257 #endif /* HAVE_DNSSD */
1262 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
1263 dnssd_error_string(err
));
1266 printf("name=\"%s\"\n", name
);
1268 printf("regtype=\"%s\"\n", regtype
);
1271 printf("domain=\"%s\"\n", domain
);
1273 return (IPPFIND_EXIT_BONJOUR
);
1278 * Process browse/resolve requests...
1281 if (bonjour_timeout
> 1.0)
1282 endtime
= get_time() + bonjour_timeout
;
1284 endtime
= get_time() + 300.0;
1286 while (get_time() < endtime
)
1288 int process
= 0; /* Process services? */
1291 int fd
= DNSServiceRefSockFD(dnssd_ref
);
1292 /* File descriptor for DNS-SD */
1295 FD_SET(fd
, &sinput
);
1297 stimeout
.tv_sec
= 0;
1298 stimeout
.tv_usec
= 500000;
1300 if (select(fd
+ 1, &sinput
, NULL
, NULL
, &stimeout
) < 0)
1303 if (FD_ISSET(fd
, &sinput
))
1306 * Process responses...
1309 DNSServiceProcessResult(dnssd_ref
);
1314 * Time to process services...
1320 #elif defined(HAVE_AVAHI)
1323 if (avahi_simple_poll_iterate(avahi_poll
, 500) > 0)
1326 * We've been told to exit the loop. Perhaps the connection to
1330 return (IPPFIND_EXIT_BONJOUR
);
1333 if (!avahi_got_data
)
1336 * Time to process services...
1341 #endif /* HAVE_DNSSD */
1346 * Process any services that we have found...
1349 int active
= 0, /* Number of active resolves */
1350 resolved
= 0, /* Number of resolved services */
1351 processed
= 0; /* Number of processed services */
1353 for (service
= (ippfind_srv_t
*)cupsArrayFirst(services
);
1355 service
= (ippfind_srv_t
*)cupsArrayNext(services
))
1357 if (service
->is_processed
)
1360 if (service
->is_resolved
)
1363 if (!service
->ref
&& !service
->is_resolved
)
1366 * Found a service, now resolve it (but limit to 50 active resolves...)
1372 service
->ref
= dnssd_ref
;
1373 err
= DNSServiceResolve(&(service
->ref
),
1374 kDNSServiceFlagsShareConnection
, 0,
1375 service
->name
, service
->regtype
,
1376 service
->domain
, resolve_callback
,
1379 #elif defined(HAVE_AVAHI)
1380 service
->ref
= avahi_service_resolver_new(avahi_client
,
1386 AVAHI_PROTO_UNSPEC
, 0,
1392 err
= avahi_client_errno(avahi_client
);
1393 #endif /* HAVE_DNSSD */
1397 _cupsLangPrintf(stderr
,
1398 _("ippfind: Unable to browse or resolve: %s"),
1399 dnssd_error_string(err
));
1400 return (IPPFIND_EXIT_BONJOUR
);
1406 else if (service
->is_resolved
&& !service
->is_processed
)
1409 * Resolved, not process this service against the expressions...
1415 DNSServiceRefDeallocate(service
->ref
);
1417 avahi_service_resolver_free(service
->ref
);
1418 #endif /* HAVE_DNSSD */
1420 service
->ref
= NULL
;
1423 if (!eval_expr(service
, expressions
))
1424 status
= IPPFIND_EXIT_FALSE
;
1426 service
->is_processed
= 1;
1428 else if (service
->ref
)
1433 * If we have processed all services we have discovered, then we are done.
1436 if (processed
== cupsArrayCount(services
) && bonjour_timeout
<= 1.0)
1442 return (IPPFIND_EXIT_BONJOUR
);
1450 * 'browse_callback()' - Browse devices.
1453 static void DNSSD_API
1455 DNSServiceRef sdRef
, /* I - Service reference */
1456 DNSServiceFlags flags
, /* I - Option flags */
1457 uint32_t interfaceIndex
, /* I - Interface number */
1458 DNSServiceErrorType errorCode
, /* I - Error, if any */
1459 const char *serviceName
, /* I - Name of service/device */
1460 const char *regtype
, /* I - Type of service */
1461 const char *replyDomain
, /* I - Service domain */
1462 void *context
) /* I - Services array */
1465 * Only process "add" data...
1469 (void)interfaceIndex
;
1471 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1478 get_service((cups_array_t
*)context
, serviceName
, regtype
, replyDomain
);
1483 * 'browse_local_callback()' - Browse local devices.
1486 static void DNSSD_API
1487 browse_local_callback(
1488 DNSServiceRef sdRef
, /* I - Service reference */
1489 DNSServiceFlags flags
, /* I - Option flags */
1490 uint32_t interfaceIndex
, /* I - Interface number */
1491 DNSServiceErrorType errorCode
, /* I - Error, if any */
1492 const char *serviceName
, /* I - Name of service/device */
1493 const char *regtype
, /* I - Type of service */
1494 const char *replyDomain
, /* I - Service domain */
1495 void *context
) /* I - Services array */
1497 ippfind_srv_t
*service
; /* Service */
1501 * Only process "add" data...
1505 (void)interfaceIndex
;
1507 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1514 service
= get_service((cups_array_t
*)context
, serviceName
, regtype
,
1516 service
->is_local
= 1;
1518 #endif /* HAVE_DNSSD */
1523 * 'browse_callback()' - Browse devices.
1528 AvahiServiceBrowser
*browser
, /* I - Browser */
1529 AvahiIfIndex interface
, /* I - Interface index (unused) */
1530 AvahiProtocol protocol
, /* I - Network protocol (unused) */
1531 AvahiBrowserEvent event
, /* I - What happened */
1532 const char *name
, /* I - Service name */
1533 const char *type
, /* I - Registration type */
1534 const char *domain
, /* I - Domain */
1535 AvahiLookupResultFlags flags
, /* I - Flags */
1536 void *context
) /* I - Services array */
1538 AvahiClient
*client
= avahi_service_browser_get_client(browser
);
1539 /* Client information */
1540 ippfind_srv_t
*service
; /* Service information */
1549 case AVAHI_BROWSER_FAILURE
:
1550 fprintf(stderr
, "DEBUG: browse_callback: %s\n",
1551 avahi_strerror(avahi_client_errno(client
)));
1553 avahi_simple_poll_quit(avahi_poll
);
1556 case AVAHI_BROWSER_NEW
:
1558 * This object is new on the network. Create a device entry for it if
1559 * it doesn't yet exist.
1562 service
= get_service((cups_array_t
*)context
, name
, type
, domain
);
1564 if (flags
& AVAHI_LOOKUP_RESULT_LOCAL
)
1565 service
->is_local
= 1;
1568 case AVAHI_BROWSER_REMOVE
:
1569 case AVAHI_BROWSER_ALL_FOR_NOW
:
1570 case AVAHI_BROWSER_CACHE_EXHAUSTED
:
1577 * 'client_callback()' - Avahi client callback function.
1582 AvahiClient
*client
, /* I - Client information (unused) */
1583 AvahiClientState state
, /* I - Current state */
1584 void *context
) /* I - User data (unused) */
1590 * If the connection drops, quit.
1593 if (state
== AVAHI_CLIENT_FAILURE
)
1595 fputs("DEBUG: Avahi connection failed.\n", stderr
);
1597 avahi_simple_poll_quit(avahi_poll
);
1600 #endif /* HAVE_AVAHI */
1604 * 'compare_services()' - Compare two devices.
1607 static int /* O - Result of comparison */
1608 compare_services(ippfind_srv_t
*a
, /* I - First device */
1609 ippfind_srv_t
*b
) /* I - Second device */
1611 return (strcmp(a
->name
, b
->name
));
1616 * 'dnssd_error_string()' - Return an error string for an error code.
1619 static const char * /* O - Error message */
1620 dnssd_error_string(int error
) /* I - Error number */
1625 case kDNSServiceErr_NoError
:
1629 case kDNSServiceErr_Unknown
:
1630 return ("Unknown error.");
1632 case kDNSServiceErr_NoSuchName
:
1633 return ("Service not found.");
1635 case kDNSServiceErr_NoMemory
:
1636 return ("Out of memory.");
1638 case kDNSServiceErr_BadParam
:
1639 return ("Bad parameter.");
1641 case kDNSServiceErr_BadReference
:
1642 return ("Bad service reference.");
1644 case kDNSServiceErr_BadState
:
1645 return ("Bad state.");
1647 case kDNSServiceErr_BadFlags
:
1648 return ("Bad flags.");
1650 case kDNSServiceErr_Unsupported
:
1651 return ("Unsupported.");
1653 case kDNSServiceErr_NotInitialized
:
1654 return ("Not initialized.");
1656 case kDNSServiceErr_AlreadyRegistered
:
1657 return ("Already registered.");
1659 case kDNSServiceErr_NameConflict
:
1660 return ("Name conflict.");
1662 case kDNSServiceErr_Invalid
:
1663 return ("Invalid name.");
1665 case kDNSServiceErr_Firewall
:
1666 return ("Firewall prevents registration.");
1668 case kDNSServiceErr_Incompatible
:
1669 return ("Client library incompatible.");
1671 case kDNSServiceErr_BadInterfaceIndex
:
1672 return ("Bad interface index.");
1674 case kDNSServiceErr_Refused
:
1675 return ("Server prevents registration.");
1677 case kDNSServiceErr_NoSuchRecord
:
1678 return ("Record not found.");
1680 case kDNSServiceErr_NoAuth
:
1681 return ("Authentication required.");
1683 case kDNSServiceErr_NoSuchKey
:
1684 return ("Encryption key not found.");
1686 case kDNSServiceErr_NATTraversal
:
1687 return ("Unable to traverse NAT boundary.");
1689 case kDNSServiceErr_DoubleNAT
:
1690 return ("Unable to traverse double-NAT boundary.");
1692 case kDNSServiceErr_BadTime
:
1693 return ("Bad system time.");
1695 case kDNSServiceErr_BadSig
:
1696 return ("Bad signature.");
1698 case kDNSServiceErr_BadKey
:
1699 return ("Bad encryption key.");
1701 case kDNSServiceErr_Transient
:
1702 return ("Transient error occurred - please try again.");
1704 case kDNSServiceErr_ServiceNotRunning
:
1705 return ("Server not running.");
1707 case kDNSServiceErr_NATPortMappingUnsupported
:
1708 return ("NAT doesn't support NAT-PMP or UPnP.");
1710 case kDNSServiceErr_NATPortMappingDisabled
:
1711 return ("NAT supports NAT-PNP or UPnP but it is disabled.");
1713 case kDNSServiceErr_NoRouter
:
1714 return ("No Internet/default router configured.");
1716 case kDNSServiceErr_PollingMode
:
1717 return ("Service polling mode error.");
1720 case kDNSServiceErr_Timeout
:
1721 return ("Service timeout.");
1725 # elif defined(HAVE_AVAHI)
1726 return (avahi_strerror(error
));
1727 # endif /* HAVE_DNSSD */
1732 * 'eval_expr()' - Evaluate the expressions against the specified service.
1734 * Returns 1 for true and 0 for false.
1737 static int /* O - Result of evaluation */
1738 eval_expr(ippfind_srv_t
*service
, /* I - Service */
1739 ippfind_expr_t
*expressions
) /* I - Expressions */
1741 int logic
, /* Logical operation */
1742 result
; /* Result of current expression */
1743 ippfind_expr_t
*expression
; /* Current expression */
1744 const char *val
; /* TXT value */
1747 * Loop through the expressions...
1750 if (expressions
&& expressions
->parent
)
1751 logic
= expressions
->parent
->op
;
1753 logic
= IPPFIND_OP_AND
;
1755 for (expression
= expressions
; expression
; expression
= expression
->next
)
1757 switch (expression
->op
)
1760 case IPPFIND_OP_AND
:
1761 case IPPFIND_OP_OR
:
1762 if (expression
->child
)
1763 result
= eval_expr(service
, expression
->child
);
1765 result
= expression
->op
== IPPFIND_OP_AND
;
1767 case IPPFIND_OP_TRUE
:
1770 case IPPFIND_OP_FALSE
:
1773 case IPPFIND_OP_IS_LOCAL
:
1774 result
= service
->is_local
;
1776 case IPPFIND_OP_IS_REMOTE
:
1777 result
= !service
->is_local
;
1779 case IPPFIND_OP_DOMAIN_REGEX
:
1780 result
= !regexec(&(expression
->re
), service
->domain
, 0, NULL
, 0);
1782 case IPPFIND_OP_NAME_REGEX
:
1783 result
= !regexec(&(expression
->re
), service
->name
, 0, NULL
, 0);
1785 case IPPFIND_OP_HOST_REGEX
:
1786 result
= !regexec(&(expression
->re
), service
->host
, 0, NULL
, 0);
1788 case IPPFIND_OP_PORT_RANGE
:
1789 result
= service
->port
>= expression
->range
[0] &&
1790 service
->port
<= expression
->range
[1];
1792 case IPPFIND_OP_PATH_REGEX
:
1793 result
= !regexec(&(expression
->re
), service
->resource
, 0, NULL
, 0);
1795 case IPPFIND_OP_TXT_EXISTS
:
1796 result
= cupsGetOption(expression
->key
, service
->num_txt
,
1797 service
->txt
) != NULL
;
1799 case IPPFIND_OP_TXT_REGEX
:
1800 val
= cupsGetOption(expression
->key
, service
->num_txt
,
1803 result
= !regexec(&(expression
->re
), val
, 0, NULL
, 0);
1807 case IPPFIND_OP_URI_REGEX
:
1808 result
= !regexec(&(expression
->re
), service
->uri
, 0, NULL
, 0);
1810 case IPPFIND_OP_EXEC
:
1811 result
= exec_program(service
, expression
->num_args
,
1814 case IPPFIND_OP_LIST
:
1815 result
= list_service(service
);
1817 case IPPFIND_OP_PRINT_NAME
:
1818 _cupsLangPuts(stdout
, service
->name
);
1821 case IPPFIND_OP_PRINT_URI
:
1822 _cupsLangPuts(stdout
, service
->uri
);
1825 case IPPFIND_OP_QUIET
:
1830 if (expression
->invert
)
1833 if (logic
== IPPFIND_OP_AND
&& !result
)
1835 else if (logic
== IPPFIND_OP_OR
&& result
)
1839 return (logic
== IPPFIND_OP_AND
);
1844 * 'exec_program()' - Execute a program for a service.
1847 static int /* O - 1 if program terminated
1848 successfully, 0 otherwise. */
1849 exec_program(ippfind_srv_t
*service
, /* I - Service */
1850 int num_args
, /* I - Number of command-line args */
1851 char **args
) /* I - Command-line arguments */
1853 char **myargv
, /* Command-line arguments */
1854 **myenvp
, /* Environment variables */
1855 *ptr
, /* Pointer into variable */
1856 domain
[1024], /* IPPFIND_SERVICE_DOMAIN */
1857 hostname
[1024], /* IPPFIND_SERVICE_HOSTNAME */
1858 name
[256], /* IPPFIND_SERVICE_NAME */
1859 port
[32], /* IPPFIND_SERVICE_PORT */
1860 regtype
[256], /* IPPFIND_SERVICE_REGTYPE */
1861 scheme
[128], /* IPPFIND_SERVICE_SCHEME */
1862 uri
[1024], /* IPPFIND_SERVICE_URI */
1863 txt
[100][256]; /* IPPFIND_TXT_foo */
1864 int i
, /* Looping var */
1865 myenvc
, /* Number of environment variables */
1866 status
; /* Exit status of program */
1868 char program
[1024]; /* Program to execute */
1869 int pid
; /* Process ID */
1874 * Environment variables...
1877 snprintf(domain
, sizeof(domain
), "IPPFIND_SERVICE_DOMAIN=%s",
1879 snprintf(hostname
, sizeof(hostname
), "IPPFIND_SERVICE_HOSTNAME=%s",
1881 snprintf(name
, sizeof(name
), "IPPFIND_SERVICE_NAME=%s", service
->name
);
1882 snprintf(port
, sizeof(port
), "IPPFIND_SERVICE_PORT=%d", service
->port
);
1883 snprintf(regtype
, sizeof(regtype
), "IPPFIND_SERVICE_REGTYPE=%s",
1885 snprintf(scheme
, sizeof(scheme
), "IPPFIND_SERVICE_SCHEME=%s",
1886 !strncmp(service
->regtype
, "_http._tcp", 10) ? "http" :
1887 !strncmp(service
->regtype
, "_https._tcp", 11) ? "https" :
1888 !strncmp(service
->regtype
, "_ipp._tcp", 9) ? "ipp" :
1889 !strncmp(service
->regtype
, "_ipps._tcp", 10) ? "ipps" : "lpd");
1890 snprintf(uri
, sizeof(uri
), "IPPFIND_SERVICE_URI=%s", service
->uri
);
1891 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1893 snprintf(txt
[i
], sizeof(txt
[i
]), "IPPFIND_TXT_%s=%s", service
->txt
[i
].name
,
1894 service
->txt
[i
].value
);
1895 for (ptr
= txt
[i
] + 12; *ptr
&& *ptr
!= '='; ptr
++)
1896 *ptr
= (char)_cups_toupper(*ptr
);
1899 for (i
= 0, myenvc
= 7 + service
->num_txt
; environ
[i
]; i
++)
1900 if (strncmp(environ
[i
], "IPPFIND_", 8))
1903 if ((myenvp
= calloc(sizeof(char *), (size_t)(myenvc
+ 1))) == NULL
)
1905 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1906 exit(IPPFIND_EXIT_MEMORY
);
1909 for (i
= 0, myenvc
= 0; environ
[i
]; i
++)
1910 if (strncmp(environ
[i
], "IPPFIND_", 8))
1911 myenvp
[myenvc
++] = environ
[i
];
1913 myenvp
[myenvc
++] = domain
;
1914 myenvp
[myenvc
++] = hostname
;
1915 myenvp
[myenvc
++] = name
;
1916 myenvp
[myenvc
++] = port
;
1917 myenvp
[myenvc
++] = regtype
;
1918 myenvp
[myenvc
++] = scheme
;
1919 myenvp
[myenvc
++] = uri
;
1921 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1922 myenvp
[myenvc
++] = txt
[i
];
1925 * Allocate and copy command-line arguments...
1928 if ((myargv
= calloc(sizeof(char *), (size_t)(num_args
+ 1))) == NULL
)
1930 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1931 exit(IPPFIND_EXIT_MEMORY
);
1934 for (i
= 0; i
< num_args
; i
++)
1936 if (strchr(args
[i
], '{'))
1938 char temp
[2048], /* Temporary string */
1939 *tptr
, /* Pointer into temporary string */
1940 keyword
[256], /* {keyword} */
1941 *kptr
; /* Pointer into keyword */
1943 for (ptr
= args
[i
], tptr
= temp
; *ptr
; ptr
++)
1948 * Do a {var} substitution...
1951 for (kptr
= keyword
, ptr
++; *ptr
&& *ptr
!= '}'; ptr
++)
1952 if (kptr
< (keyword
+ sizeof(keyword
) - 1))
1957 _cupsLangPuts(stderr
,
1958 _("ippfind: Missing close brace in substitution."));
1959 exit(IPPFIND_EXIT_SYNTAX
);
1963 if (!keyword
[0] || !strcmp(keyword
, "service_uri"))
1964 strlcpy(tptr
, service
->uri
, sizeof(temp
) - (size_t)(tptr
- temp
));
1965 else if (!strcmp(keyword
, "service_domain"))
1966 strlcpy(tptr
, service
->domain
, sizeof(temp
) - (size_t)(tptr
- temp
));
1967 else if (!strcmp(keyword
, "service_hostname"))
1968 strlcpy(tptr
, service
->host
, sizeof(temp
) - (size_t)(tptr
- temp
));
1969 else if (!strcmp(keyword
, "service_name"))
1970 strlcpy(tptr
, service
->name
, sizeof(temp
) - (size_t)(tptr
- temp
));
1971 else if (!strcmp(keyword
, "service_path"))
1972 strlcpy(tptr
, service
->resource
, sizeof(temp
) - (size_t)(tptr
- temp
));
1973 else if (!strcmp(keyword
, "service_port"))
1974 strlcpy(tptr
, port
+ 20, sizeof(temp
) - (size_t)(tptr
- temp
));
1975 else if (!strcmp(keyword
, "service_scheme"))
1976 strlcpy(tptr
, scheme
+ 22, sizeof(temp
) - (size_t)(tptr
- temp
));
1977 else if (!strncmp(keyword
, "txt_", 4))
1979 if ((ptr
= (char *)cupsGetOption(keyword
+ 4, service
->num_txt
,
1980 service
->txt
)) != NULL
)
1981 strlcpy(tptr
, strdup(ptr
), sizeof(temp
) - (size_t)(tptr
- temp
));
1987 _cupsLangPrintf(stderr
, _("ippfind: Unknown variable \"{%s}\"."),
1989 exit(IPPFIND_EXIT_SYNTAX
);
1992 tptr
+= strlen(tptr
);
1994 else if (tptr
< (temp
+ sizeof(temp
) - 1))
1999 myargv
[i
] = strdup(temp
);
2002 myargv
[i
] = strdup(args
[i
]);
2006 status
= _spawnvpe(_P_WAIT
, args
[0], myargv
, myenvp
);
2010 * Execute the program...
2013 if (strchr(args
[0], '/') && !access(args
[0], X_OK
))
2014 strlcpy(program
, args
[0], sizeof(program
));
2015 else if (!cupsFileFind(args
[0], getenv("PATH"), 1, program
, sizeof(program
)))
2017 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2018 args
[0], strerror(ENOENT
));
2019 exit(IPPFIND_EXIT_SYNTAX
);
2022 if (getenv("IPPFIND_DEBUG"))
2024 printf("\nProgram:\n %s\n", program
);
2025 puts("\nArguments:");
2026 for (i
= 0; i
< num_args
; i
++)
2027 printf(" %s\n", myargv
[i
]);
2028 puts("\nEnvironment:");
2029 for (i
= 0; i
< myenvc
; i
++)
2030 printf(" %s\n", myenvp
[i
]);
2033 if ((pid
= fork()) == 0)
2036 * Child comes here...
2039 execve(program
, myargv
, myenvp
);
2044 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2045 args
[0], strerror(errno
));
2046 exit(IPPFIND_EXIT_SYNTAX
);
2051 * Wait for it to complete...
2054 while (wait(&status
) != pid
)
2063 for (i
= 0; i
< num_args
; i
++)
2070 * Return whether the program succeeded or crashed...
2073 return (status
== 0);
2078 * 'get_service()' - Create or update a device.
2081 static ippfind_srv_t
* /* O - Service */
2082 get_service(cups_array_t
*services
, /* I - Service array */
2083 const char *serviceName
, /* I - Name of service/device */
2084 const char *regtype
, /* I - Type of service */
2085 const char *replyDomain
) /* I - Service domain */
2087 ippfind_srv_t key
, /* Search key */
2088 *service
; /* Service */
2089 char fullName
[kDNSServiceMaxDomainName
];
2090 /* Full name for query */
2094 * See if this is a new device...
2097 key
.name
= (char *)serviceName
;
2098 key
.regtype
= (char *)regtype
;
2100 for (service
= cupsArrayFind(services
, &key
);
2102 service
= cupsArrayNext(services
))
2103 if (_cups_strcasecmp(service
->name
, key
.name
))
2105 else if (!strcmp(service
->regtype
, key
.regtype
))
2109 * Yes, add the service...
2112 service
= calloc(sizeof(ippfind_srv_t
), 1);
2113 service
->name
= strdup(serviceName
);
2114 service
->domain
= strdup(replyDomain
);
2115 service
->regtype
= strdup(regtype
);
2117 cupsArrayAdd(services
, service
);
2120 * Set the "full name" of this service, which is used for queries and
2125 DNSServiceConstructFullName(fullName
, serviceName
, regtype
, replyDomain
);
2126 #else /* HAVE_AVAHI */
2127 avahi_service_name_join(fullName
, kDNSServiceMaxDomainName
, serviceName
,
2128 regtype
, replyDomain
);
2129 #endif /* HAVE_DNSSD */
2131 service
->fullName
= strdup(fullName
);
2138 * 'get_time()' - Get the current time-of-day in seconds.
2145 struct _timeb curtime
; /* Current Windows time */
2149 return (curtime
.time
+ 0.001 * curtime
.millitm
);
2152 struct timeval curtime
; /* Current UNIX time */
2154 if (gettimeofday(&curtime
, NULL
))
2157 return (curtime
.tv_sec
+ 0.000001 * curtime
.tv_usec
);
2163 * 'list_service()' - List the contents of a service.
2166 static int /* O - 1 if successful, 0 otherwise */
2167 list_service(ippfind_srv_t
*service
) /* I - Service */
2169 http_addrlist_t
*addrlist
; /* Address(es) of service */
2170 char port
[10]; /* Port number of service */
2173 snprintf(port
, sizeof(port
), "%d", service
->port
);
2175 if ((addrlist
= httpAddrGetList(service
->host
, address_family
, port
)) == NULL
)
2177 _cupsLangPrintf(stdout
, "%s unreachable", service
->uri
);
2181 if (!strncmp(service
->regtype
, "_ipp._tcp", 9) ||
2182 !strncmp(service
->regtype
, "_ipps._tcp", 10))
2188 http_t
*http
; /* HTTP connection */
2189 ipp_t
*request
, /* IPP request */
2190 *response
; /* IPP response */
2191 ipp_attribute_t
*attr
; /* IPP attribute */
2192 int i
, /* Looping var */
2193 count
, /* Number of values */
2194 version
, /* IPP version */
2195 paccepting
; /* printer-is-accepting-jobs value */
2196 ipp_pstate_t pstate
; /* printer-state value */
2197 char preasons
[1024], /* Comma-delimited printer-state-reasons */
2198 *ptr
, /* Pointer into reasons */
2199 *end
; /* End of reasons buffer */
2200 static const char * const rattrs
[] =/* Requested attributes */
2202 "printer-is-accepting-jobs",
2204 "printer-state-reasons"
2208 * Connect to the printer...
2211 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2212 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2213 HTTP_ENCRYPTION_ALWAYS
:
2214 HTTP_ENCRYPTION_IF_REQUESTED
,
2217 httpAddrFreeList(addrlist
);
2221 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2226 * Get the current printer state...
2230 version
= ipp_version
;
2234 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
2235 ippSetVersion(request
, version
/ 10, version
% 10);
2236 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
2238 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
2239 "requesting-user-name", NULL
, cupsUser());
2240 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
2241 "requested-attributes",
2242 (int)(sizeof(rattrs
) / sizeof(rattrs
[0])), NULL
, rattrs
);
2244 response
= cupsDoRequest(http
, request
, service
->resource
);
2246 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
&& version
> 11)
2249 while (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
&& version
> 11);
2255 if (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
)
2257 _cupsLangPrintf(stdout
, "%s: unavailable", service
->uri
);
2261 if ((attr
= ippFindAttribute(response
, "printer-state",
2262 IPP_TAG_ENUM
)) != NULL
)
2263 pstate
= (ipp_pstate_t
)ippGetInteger(attr
, 0);
2265 pstate
= IPP_PSTATE_STOPPED
;
2267 if ((attr
= ippFindAttribute(response
, "printer-is-accepting-jobs",
2268 IPP_TAG_BOOLEAN
)) != NULL
)
2269 paccepting
= ippGetBoolean(attr
, 0);
2273 if ((attr
= ippFindAttribute(response
, "printer-state-reasons",
2274 IPP_TAG_KEYWORD
)) != NULL
)
2276 strlcpy(preasons
, ippGetString(attr
, 0, NULL
), sizeof(preasons
));
2278 for (i
= 1, count
= ippGetCount(attr
), ptr
= preasons
+ strlen(preasons
),
2279 end
= preasons
+ sizeof(preasons
) - 1;
2280 i
< count
&& ptr
< end
;
2281 i
++, ptr
+= strlen(ptr
))
2284 strlcpy(ptr
, ippGetString(attr
, i
, NULL
), end
- ptr
+ 1);
2288 strlcpy(preasons
, "none", sizeof(preasons
));
2290 ippDelete(response
);
2293 _cupsLangPrintf(stdout
, "%s %s %s %s", service
->uri
,
2294 ippEnumString("printer-state", pstate
),
2295 paccepting
? "accepting-jobs" : "not-accepting-jobs",
2298 else if (!strncmp(service
->regtype
, "_http._tcp", 10) ||
2299 !strncmp(service
->regtype
, "_https._tcp", 11))
2302 * HTTP/HTTPS web page
2305 http_t
*http
; /* HTTP connection */
2306 http_status_t status
; /* HEAD status */
2310 * Connect to the web server...
2313 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2314 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2315 HTTP_ENCRYPTION_ALWAYS
:
2316 HTTP_ENCRYPTION_IF_REQUESTED
,
2319 httpAddrFreeList(addrlist
);
2323 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2327 if (httpGet(http
, service
->resource
))
2329 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2335 status
= httpUpdate(http
);
2337 while (status
== HTTP_STATUS_CONTINUE
);
2342 if (status
>= HTTP_STATUS_BAD_REQUEST
)
2344 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2348 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2350 else if (!strncmp(service
->regtype
, "_printer._tcp", 13))
2356 int sock
; /* Socket */
2359 if (!httpAddrConnect(addrlist
, &sock
))
2361 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2362 httpAddrFreeList(addrlist
);
2366 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2367 httpAddrFreeList(addrlist
);
2369 httpAddrClose(NULL
, sock
);
2373 _cupsLangPrintf(stdout
, "%s unsupported", service
->uri
);
2374 httpAddrFreeList(addrlist
);
2383 * 'new_expr()' - Create a new expression.
2386 static ippfind_expr_t
* /* O - New expression */
2387 new_expr(ippfind_op_t op
, /* I - Operation */
2388 int invert
, /* I - Invert result? */
2389 const char *value
, /* I - TXT key or port range */
2390 const char *regex
, /* I - Regular expression */
2391 char **args
) /* I - Pointer to argument strings */
2393 ippfind_expr_t
*temp
; /* New expression */
2396 if ((temp
= calloc(1, sizeof(ippfind_expr_t
))) == NULL
)
2400 temp
->invert
= invert
;
2402 if (op
== IPPFIND_OP_TXT_EXISTS
|| op
== IPPFIND_OP_TXT_REGEX
)
2403 temp
->key
= (char *)value
;
2404 else if (op
== IPPFIND_OP_PORT_RANGE
)
2407 * Pull port number range of the form "number", "-number" (0-number),
2408 * "number-" (number-65535), and "number-number".
2413 temp
->range
[1] = atoi(value
+ 1);
2415 else if (strchr(value
, '-'))
2417 if (sscanf(value
, "%d-%d", temp
->range
, temp
->range
+ 1) == 1)
2418 temp
->range
[1] = 65535;
2422 temp
->range
[0] = temp
->range
[1] = atoi(value
);
2428 int err
= regcomp(&(temp
->re
), regex
, REG_NOSUB
| REG_ICASE
| REG_EXTENDED
);
2432 char message
[256]; /* Error message */
2434 regerror(err
, &(temp
->re
), message
, sizeof(message
));
2435 _cupsLangPrintf(stderr
, _("ippfind: Bad regular expression: %s"),
2437 exit(IPPFIND_EXIT_SYNTAX
);
2443 int num_args
; /* Number of arguments */
2445 for (num_args
= 1; args
[num_args
]; num_args
++)
2446 if (!strcmp(args
[num_args
], ";"))
2449 temp
->num_args
= num_args
;
2450 temp
->args
= malloc((size_t)num_args
* sizeof(char *));
2451 memcpy(temp
->args
, args
, (size_t)num_args
* sizeof(char *));
2460 * 'poll_callback()' - Wait for input on the specified file descriptors.
2462 * Note: This function is needed because avahi_simple_poll_iterate is broken
2463 * and always uses a timeout of 0 (!) milliseconds.
2464 * (Avahi Ticket #364)
2467 static int /* O - Number of file descriptors matching */
2469 struct pollfd
*pollfds
, /* I - File descriptors */
2470 unsigned int num_pollfds
, /* I - Number of file descriptors */
2471 int timeout
, /* I - Timeout in milliseconds (unused) */
2472 void *context
) /* I - User data (unused) */
2474 int val
; /* Return value */
2480 val
= poll(pollfds
, num_pollfds
, 500);
2487 #endif /* HAVE_AVAHI */
2491 * 'resolve_callback()' - Process resolve data.
2495 static void DNSSD_API
2497 DNSServiceRef sdRef
, /* I - Service reference */
2498 DNSServiceFlags flags
, /* I - Data flags */
2499 uint32_t interfaceIndex
, /* I - Interface */
2500 DNSServiceErrorType errorCode
, /* I - Error, if any */
2501 const char *fullName
, /* I - Full service name */
2502 const char *hostTarget
, /* I - Hostname */
2503 uint16_t port
, /* I - Port number (network byte order) */
2504 uint16_t txtLen
, /* I - Length of TXT record data */
2505 const unsigned char *txtRecord
, /* I - TXT record data */
2506 void *context
) /* I - Service */
2508 char key
[256], /* TXT key value */
2509 *value
; /* Value from TXT record */
2510 const unsigned char *txtEnd
; /* End of TXT record */
2511 uint8_t valueLen
; /* Length of value */
2512 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2517 * Only process "add" data...
2522 (void)interfaceIndex
;
2525 if (errorCode
!= kDNSServiceErr_NoError
)
2527 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
2528 dnssd_error_string(errorCode
));
2533 service
->is_resolved
= 1;
2534 service
->host
= strdup(hostTarget
);
2535 service
->port
= ntohs(port
);
2538 * Loop through the TXT key/value pairs and add them to an array...
2541 for (txtEnd
= txtRecord
+ txtLen
; txtRecord
< txtEnd
; txtRecord
+= valueLen
)
2544 * Ignore bogus strings...
2547 valueLen
= *txtRecord
++;
2549 memcpy(key
, txtRecord
, valueLen
);
2550 key
[valueLen
] = '\0';
2552 if ((value
= strchr(key
, '=')) == NULL
)
2558 * Add to array of TXT values...
2561 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2565 set_service_uri(service
);
2569 #elif defined(HAVE_AVAHI)
2572 AvahiServiceResolver
*resolver
, /* I - Resolver */
2573 AvahiIfIndex interface
, /* I - Interface */
2574 AvahiProtocol protocol
, /* I - Address protocol */
2575 AvahiResolverEvent event
, /* I - Event */
2576 const char *serviceName
,/* I - Service name */
2577 const char *regtype
, /* I - Registration type */
2578 const char *replyDomain
,/* I - Domain name */
2579 const char *hostTarget
, /* I - FQDN */
2580 const AvahiAddress
*address
, /* I - Address */
2581 uint16_t port
, /* I - Port number */
2582 AvahiStringList
*txt
, /* I - TXT records */
2583 AvahiLookupResultFlags flags
, /* I - Lookup flags */
2584 void *context
) /* I - Service */
2586 char key
[256], /* TXT key */
2587 *value
; /* TXT value */
2588 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2590 AvahiStringList
*current
; /* Current TXT key/value pair */
2595 if (event
!= AVAHI_RESOLVER_FOUND
)
2599 avahi_service_resolver_free(resolver
);
2600 avahi_simple_poll_quit(avahi_poll
);
2604 service
->is_resolved
= 1;
2605 service
->host
= strdup(hostTarget
);
2606 service
->port
= port
;
2609 * Loop through the TXT key/value pairs and add them to an array...
2612 for (current
= txt
; current
; current
= current
->next
)
2615 * Ignore bogus strings...
2618 if (current
->size
> (sizeof(key
) - 1))
2621 memcpy(key
, current
->text
, current
->size
);
2622 key
[current
->size
] = '\0';
2624 if ((value
= strchr(key
, '=')) == NULL
)
2630 * Add to array of TXT values...
2633 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2637 set_service_uri(service
);
2639 #endif /* HAVE_DNSSD */
2643 * 'set_service_uri()' - Set the URI of the service.
2647 set_service_uri(ippfind_srv_t
*service
) /* I - Service */
2649 char uri
[1024]; /* URI */
2650 const char *path
, /* Resource path */
2651 *scheme
; /* URI scheme */
2654 if (!strncmp(service
->regtype
, "_http.", 6))
2657 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2659 else if (!strncmp(service
->regtype
, "_https.", 7))
2662 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2664 else if (!strncmp(service
->regtype
, "_ipp.", 5))
2667 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2669 else if (!strncmp(service
->regtype
, "_ipps.", 6))
2672 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2674 else if (!strncmp(service
->regtype
, "_printer.", 9))
2677 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2682 if (!path
|| !*path
)
2687 service
->resource
= strdup(path
);
2691 snprintf(uri
, sizeof(uri
), "/%s", path
);
2692 service
->resource
= strdup(uri
);
2695 httpAssembleURI(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), scheme
, NULL
,
2696 service
->host
, service
->port
, service
->resource
);
2697 service
->uri
= strdup(uri
);
2702 * 'show_usage()' - Show program usage.
2708 _cupsLangPuts(stderr
, _("Usage: ippfind [options] regtype[,subtype]"
2709 "[.domain.] ... [expression]\n"
2710 " ippfind [options] name[.regtype[.domain.]] "
2711 "... [expression]\n"
2713 " ippfind --version"));
2714 _cupsLangPuts(stderr
, "");
2715 _cupsLangPuts(stderr
, _("Options:"));
2716 _cupsLangPuts(stderr
, _(" -4 Connect using IPv4."));
2717 _cupsLangPuts(stderr
, _(" -6 Connect using IPv6."));
2718 _cupsLangPuts(stderr
, _(" -T seconds Set the browse timeout in "
2720 _cupsLangPuts(stderr
, _(" -V version Set default IPP "
2722 _cupsLangPuts(stderr
, _(" --help Show this help."));
2723 _cupsLangPuts(stderr
, _(" --version Show program version."));
2724 _cupsLangPuts(stderr
, "");
2725 _cupsLangPuts(stderr
, _("Expressions:"));
2726 _cupsLangPuts(stderr
, _(" -P number[-number] Match port to number or range."));
2727 _cupsLangPuts(stderr
, _(" -d regex Match domain to regular expression."));
2728 _cupsLangPuts(stderr
, _(" -h regex Match hostname to regular expression."));
2729 _cupsLangPuts(stderr
, _(" -l List attributes."));
2730 _cupsLangPuts(stderr
, _(" -n regex Match service name to regular expression."));
2731 _cupsLangPuts(stderr
, _(" -p Print URI if true."));
2732 _cupsLangPuts(stderr
, _(" -q Quietly report match via exit code."));
2733 _cupsLangPuts(stderr
, _(" -r True if service is remote."));
2734 _cupsLangPuts(stderr
, _(" -s Print service name if true."));
2735 _cupsLangPuts(stderr
, _(" -t key True if the TXT record contains the key."));
2736 _cupsLangPuts(stderr
, _(" -u regex Match URI to regular expression."));
2737 _cupsLangPuts(stderr
, _(" -x utility [argument ...] ;\n"
2738 " Execute program if true."));
2739 _cupsLangPuts(stderr
, _(" --domain regex Match domain to regular expression."));
2740 _cupsLangPuts(stderr
, _(" --exec utility [argument ...] ;\n"
2741 " Execute program if true."));
2742 _cupsLangPuts(stderr
, _(" --host regex Match hostname to regular expression."));
2743 _cupsLangPuts(stderr
, _(" --ls List attributes."));
2744 _cupsLangPuts(stderr
, _(" --local True if service is local."));
2745 _cupsLangPuts(stderr
, _(" --name regex Match service name to regular expression."));
2746 _cupsLangPuts(stderr
, _(" --path regex Match resource path to regular expression."));
2747 _cupsLangPuts(stderr
, _(" --port number[-number] Match port to number or range."));
2748 _cupsLangPuts(stderr
, _(" --print Print URI if true."));
2749 _cupsLangPuts(stderr
, _(" --print-name Print service name if true."));
2750 _cupsLangPuts(stderr
, _(" --quiet Quietly report match via exit code."));
2751 _cupsLangPuts(stderr
, _(" --remote True if service is remote."));
2752 _cupsLangPuts(stderr
, _(" --txt key True if the TXT record contains the key."));
2753 _cupsLangPuts(stderr
, _(" --txt-* regex Match TXT record key to regular expression."));
2754 _cupsLangPuts(stderr
, _(" --uri regex Match URI to regular expression."));
2755 _cupsLangPuts(stderr
, "");
2756 _cupsLangPuts(stderr
, _("Modifiers:"));
2757 _cupsLangPuts(stderr
, _(" ( expressions ) Group expressions."));
2758 _cupsLangPuts(stderr
, _(" ! expression Unary NOT of expression."));
2759 _cupsLangPuts(stderr
, _(" --not expression Unary NOT of expression."));
2760 _cupsLangPuts(stderr
, _(" --false Always false."));
2761 _cupsLangPuts(stderr
, _(" --true Always true."));
2762 _cupsLangPuts(stderr
, _(" expression expression Logical AND."));
2763 _cupsLangPuts(stderr
, _(" expression --and expression\n"
2765 _cupsLangPuts(stderr
, _(" expression --or expression\n"
2767 _cupsLangPuts(stderr
, "");
2768 _cupsLangPuts(stderr
, _("Substitutions:"));
2769 _cupsLangPuts(stderr
, _(" {} URI"));
2770 _cupsLangPuts(stderr
, _(" {service_domain} Domain name"));
2771 _cupsLangPuts(stderr
, _(" {service_hostname} Fully-qualified domain name"));
2772 _cupsLangPuts(stderr
, _(" {service_name} Service instance name"));
2773 _cupsLangPuts(stderr
, _(" {service_port} Port number"));
2774 _cupsLangPuts(stderr
, _(" {service_regtype} DNS-SD registration type"));
2775 _cupsLangPuts(stderr
, _(" {service_scheme} URI scheme"));
2776 _cupsLangPuts(stderr
, _(" {service_uri} URI"));
2777 _cupsLangPuts(stderr
, _(" {txt_*} Value of TXT record key"));
2778 _cupsLangPuts(stderr
, "");
2779 _cupsLangPuts(stderr
, _("Environment Variables:"));
2780 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_DOMAIN Domain name"));
2781 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_HOSTNAME\n"
2782 " Fully-qualified domain name"));
2783 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_NAME Service instance name"));
2784 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_PORT Port number"));
2785 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_REGTYPE DNS-SD registration type"));
2786 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_SCHEME URI scheme"));
2787 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_URI URI"));
2788 _cupsLangPuts(stderr
, _(" IPPFIND_TXT_* Value of TXT record key"));
2790 exit(IPPFIND_EXIT_TRUE
);
2795 * 'show_version()' - Show program version.
2801 _cupsLangPuts(stderr
, CUPS_SVERSION
);
2803 exit(IPPFIND_EXIT_TRUE
);