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-2013 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 * main() - Browse for printers.
21 * browse_callback() - Browse devices.
22 * browse_local_callback() - Browse local devices.
23 * browse_callback() - Browse devices.
24 * client_callback() - Avahi client callback function.
25 * compare_services() - Compare two devices.
26 * dnssd_error_string() - Return an error string for an error code.
27 * eval_expr() - Evaluate the expressions against the specified
29 * exec_program() - Execute a program for a service.
30 * get_service() - Create or update a device.
31 * get_time() - Get the current time-of-day in seconds.
32 * list_service() - List the contents of a service.
33 * new_expr() - Create a new expression.
34 * poll_callback() - Wait for input on the specified file
36 * resolve_callback() - Process resolve data.
37 * set_service_uri() - Set the URI of the service.
38 * show_usage() - Show program usage.
39 * show_version() - Show program version.
43 * Include necessary headers.
46 #define _CUPS_NO_DEPRECATED
47 #include <cups/cups-private.h>
50 # include <sys/timeb.h>
52 # include <sys/wait.h>
57 #elif defined(HAVE_AVAHI)
58 # include <avahi-client/client.h>
59 # include <avahi-client/lookup.h>
60 # include <avahi-common/simple-watch.h>
61 # include <avahi-common/domain.h>
62 # include <avahi-common/error.h>
63 # include <avahi-common/malloc.h>
64 # define kDNSServiceMaxDomainName AVAHI_DOMAIN_NAME_MAX
65 #endif /* HAVE_DNSSD */
68 extern char **environ
; /* Process environment variables */
76 typedef enum ippfind_exit_e
/* Exit codes */
78 IPPFIND_EXIT_TRUE
= 0, /* OK and result is true */
79 IPPFIND_EXIT_FALSE
, /* OK but result is false*/
80 IPPFIND_EXIT_BONJOUR
, /* Browse/resolve failure */
81 IPPFIND_EXIT_SYNTAX
, /* Bad option or syntax error */
82 IPPFIND_EXIT_MEMORY
/* Out of memory */
85 typedef enum ippfind_op_e
/* Operations for expressions */
87 /* "Evaluation" operations */
88 IPPFIND_OP_NONE
, /* No operation */
89 IPPFIND_OP_AND
, /* Logical AND of all children */
90 IPPFIND_OP_OR
, /* Logical OR of all children */
91 IPPFIND_OP_TRUE
, /* Always true */
92 IPPFIND_OP_FALSE
, /* Always false */
93 IPPFIND_OP_IS_LOCAL
, /* Is a local service */
94 IPPFIND_OP_IS_REMOTE
, /* Is a remote service */
95 IPPFIND_OP_DOMAIN_REGEX
, /* Domain matches regular expression */
96 IPPFIND_OP_NAME_REGEX
, /* Name matches regular expression */
97 IPPFIND_OP_HOST_REGEX
, /* Hostname matches regular expression */
98 IPPFIND_OP_PORT_RANGE
, /* Port matches range */
99 IPPFIND_OP_PATH_REGEX
, /* Path matches regular expression */
100 IPPFIND_OP_TXT_EXISTS
, /* TXT record key exists */
101 IPPFIND_OP_TXT_REGEX
, /* TXT record key matches regular expression */
102 IPPFIND_OP_URI_REGEX
, /* URI matches regular expression */
104 /* "Output" operations */
105 IPPFIND_OP_EXEC
, /* Execute when true */
106 IPPFIND_OP_LIST
, /* List when true */
107 IPPFIND_OP_PRINT_NAME
, /* Print URI when true */
108 IPPFIND_OP_PRINT_URI
, /* Print name when true */
109 IPPFIND_OP_QUIET
/* No output when true */
112 typedef struct ippfind_expr_s
/* Expression */
114 struct ippfind_expr_s
115 *prev
, /* Previous expression */
116 *next
, /* Next expression */
117 *parent
, /* Parent expressions */
118 *child
; /* Child expressions */
119 ippfind_op_t op
; /* Operation code (see above) */
120 int invert
; /* Invert the result */
121 char *key
; /* TXT record key */
122 regex_t re
; /* Regular expression for matching */
123 int range
[2]; /* Port number range */
124 int num_args
; /* Number of arguments for exec */
125 char **args
; /* Arguments for exec */
128 typedef struct ippfind_srv_s
/* Service information */
131 DNSServiceRef ref
; /* Service reference for query */
132 #elif defined(HAVE_AVAHI)
133 AvahiServiceResolver
*ref
; /* Resolver */
134 #endif /* HAVE_DNSSD */
135 char *name
, /* Service name */
136 *domain
, /* Domain name */
137 *regtype
, /* Registration type */
138 *fullName
, /* Full name */
139 *host
, /* Hostname */
140 *resource
, /* Resource path */
142 int num_txt
; /* Number of TXT record keys */
143 cups_option_t
*txt
; /* TXT record keys */
144 int port
, /* Port number */
145 is_local
, /* Is a local service? */
146 is_processed
, /* Did we process the service? */
147 is_resolved
; /* Got the resolve data? */
156 static DNSServiceRef dnssd_ref
; /* Master service reference */
157 #elif defined(HAVE_AVAHI)
158 static AvahiClient
*avahi_client
= NULL
;/* Client information */
159 static int avahi_got_data
= 0; /* Got data from poll? */
160 static AvahiSimplePoll
*avahi_poll
= NULL
;
161 /* Poll information */
162 #endif /* HAVE_DNSSD */
164 static int address_family
= AF_UNSPEC
;
165 /* Address family for LIST */
166 static int bonjour_error
= 0; /* Error browsing/resolving? */
167 static double bonjour_timeout
= 1.0; /* Timeout in seconds */
168 static int ipp_version
= 20; /* IPP version for LIST */
176 static void DNSSD_API
browse_callback(DNSServiceRef sdRef
,
177 DNSServiceFlags flags
,
178 uint32_t interfaceIndex
,
179 DNSServiceErrorType errorCode
,
180 const char *serviceName
,
182 const char *replyDomain
, void *context
)
183 __attribute__((nonnull(1,5,6,7,8)));
184 static void DNSSD_API
browse_local_callback(DNSServiceRef sdRef
,
185 DNSServiceFlags flags
,
186 uint32_t interfaceIndex
,
187 DNSServiceErrorType errorCode
,
188 const char *serviceName
,
190 const char *replyDomain
,
192 __attribute__((nonnull(1,5,6,7,8)));
193 #elif defined(HAVE_AVAHI)
194 static void browse_callback(AvahiServiceBrowser
*browser
,
195 AvahiIfIndex interface
,
196 AvahiProtocol protocol
,
197 AvahiBrowserEvent event
,
198 const char *serviceName
,
200 const char *replyDomain
,
201 AvahiLookupResultFlags flags
,
203 static void client_callback(AvahiClient
*client
,
204 AvahiClientState state
,
206 #endif /* HAVE_AVAHI */
208 static int compare_services(ippfind_srv_t
*a
, ippfind_srv_t
*b
);
209 static const char *dnssd_error_string(int error
);
210 static int eval_expr(ippfind_srv_t
*service
,
211 ippfind_expr_t
*expressions
);
212 static int exec_program(ippfind_srv_t
*service
, int num_args
,
214 static ippfind_srv_t
*get_service(cups_array_t
*services
,
215 const char *serviceName
,
217 const char *replyDomain
)
218 __attribute__((nonnull(1,2,3,4)));
219 static double get_time(void);
220 static int list_service(ippfind_srv_t
*service
);
221 static ippfind_expr_t
*new_expr(ippfind_op_t op
, int invert
,
222 const char *value
, const char *regex
,
225 static void DNSSD_API
resolve_callback(DNSServiceRef sdRef
,
226 DNSServiceFlags flags
,
227 uint32_t interfaceIndex
,
228 DNSServiceErrorType errorCode
,
229 const char *fullName
,
230 const char *hostTarget
, uint16_t port
,
232 const unsigned char *txtRecord
,
234 __attribute__((nonnull(1,5,6,9, 10)));
235 #elif defined(HAVE_AVAHI)
236 static int poll_callback(struct pollfd
*pollfds
,
237 unsigned int num_pollfds
, int timeout
,
239 static void resolve_callback(AvahiServiceResolver
*res
,
240 AvahiIfIndex interface
,
241 AvahiProtocol protocol
,
242 AvahiResolverEvent event
,
243 const char *serviceName
,
245 const char *replyDomain
,
246 const char *host_name
,
247 const AvahiAddress
*address
,
249 AvahiStringList
*txt
,
250 AvahiLookupResultFlags flags
,
252 #endif /* HAVE_DNSSD */
253 static void set_service_uri(ippfind_srv_t
*service
);
254 static void show_usage(void) __attribute__((noreturn
));
255 static void show_version(void) __attribute__((noreturn
));
259 * 'main()' - Browse for printers.
262 int /* O - Exit status */
263 main(int argc
, /* I - Number of command-line args */
264 char *argv
[]) /* I - Command-line arguments */
266 int i
, /* Looping var */
267 have_output
= 0,/* Have output expression */
268 status
= IPPFIND_EXIT_TRUE
;
270 const char *opt
, /* Option character */
271 *search
; /* Current browse/resolve string */
272 cups_array_t
*searches
; /* Things to browse/resolve */
273 cups_array_t
*services
; /* Service array */
274 ippfind_srv_t
*service
; /* Current service */
275 ippfind_expr_t
*expressions
= NULL
,
276 /* Expression tree */
277 *temp
= NULL
, /* New expression */
278 *parent
= NULL
, /* Parent expression */
279 *current
= NULL
,/* Current expression */
280 *parens
[100]; /* Markers for parenthesis */
281 int num_parens
= 0; /* Number of parenthesis */
282 ippfind_op_t logic
= IPPFIND_OP_AND
;
283 /* Logic for next expression */
284 int invert
= 0; /* Invert expression? */
285 int err
; /* DNS-SD error */
287 fd_set sinput
; /* Input set for select() */
288 struct timeval stimeout
; /* Timeout for select() */
289 #endif /* HAVE_DNSSD */
290 double endtime
; /* End time */
291 static const char * const ops
[] = /* Node operation names */
317 * Initialize the locale...
320 _cupsSetLocale(argv
);
323 * Create arrays to track services and things we want to browse/resolve...
326 searches
= cupsArrayNew(NULL
, NULL
);
327 services
= cupsArrayNew((cups_array_func_t
)compare_services
, NULL
);
330 * Parse command-line...
333 for (i
= 1; i
< argc
; i
++)
335 if (argv
[i
][0] == '-')
337 if (argv
[i
][1] == '-')
340 * Parse --option options...
343 if (!strcmp(argv
[i
], "--and"))
345 if (logic
== IPPFIND_OP_OR
)
347 _cupsLangPuts(stderr
, _("ippfind: Cannot use --and after --or."));
353 _cupsLangPuts(stderr
,
354 _("ippfind: Missing expression before \"--and\"."));
360 else if (!strcmp(argv
[i
], "--domain"))
365 _cupsLangPrintf(stderr
,
366 _("ippfind: Missing regular expression after %s."),
371 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
, argv
[i
],
373 return (IPPFIND_EXIT_MEMORY
);
375 else if (!strcmp(argv
[i
], "--exec"))
380 _cupsLangPrintf(stderr
, _("ippfind: Expected program after %s."),
385 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
387 return (IPPFIND_EXIT_MEMORY
);
390 if (!strcmp(argv
[i
], ";"))
397 _cupsLangPrintf(stderr
, _("ippfind: Expected semi-colon after %s."),
404 else if (!strcmp(argv
[i
], "--false"))
406 if ((temp
= new_expr(IPPFIND_OP_FALSE
, invert
, NULL
, NULL
,
408 return (IPPFIND_EXIT_MEMORY
);
410 else if (!strcmp(argv
[i
], "--help"))
414 else if (!strcmp(argv
[i
], "--host"))
419 _cupsLangPrintf(stderr
,
420 _("ippfind: Missing regular expression after %s."),
425 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
, argv
[i
],
427 return (IPPFIND_EXIT_MEMORY
);
429 else if (!strcmp(argv
[i
], "--ls"))
431 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
433 return (IPPFIND_EXIT_MEMORY
);
437 else if (!strcmp(argv
[i
], "--local"))
439 if ((temp
= new_expr(IPPFIND_OP_IS_LOCAL
, invert
, NULL
, NULL
,
441 return (IPPFIND_EXIT_MEMORY
);
443 else if (!strcmp(argv
[i
], "--name"))
448 _cupsLangPrintf(stderr
,
449 _("ippfind: Missing regular expression after %s."),
454 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
, argv
[i
],
456 return (IPPFIND_EXIT_MEMORY
);
458 else if (!strcmp(argv
[i
], "--not"))
462 else if (!strcmp(argv
[i
], "--or"))
466 _cupsLangPuts(stderr
,
467 _("ippfind: Missing expression before \"--or\"."));
471 logic
= IPPFIND_OP_OR
;
473 if (parent
&& parent
->op
== IPPFIND_OP_OR
)
476 * Already setup to do "foo --or bar --or baz"...
481 else if (!current
->prev
&& parent
)
484 * Change parent node into an OR node...
487 parent
->op
= IPPFIND_OP_OR
;
490 else if (!current
->prev
)
493 * Need to group "current" in a new OR node...
496 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
498 return (IPPFIND_EXIT_MEMORY
);
500 temp
->parent
= parent
;
501 temp
->child
= current
;
502 current
->parent
= temp
;
505 parent
->child
= temp
;
515 * Need to group previous expressions in an AND node, and then
516 * put that in an OR node...
519 if ((temp
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
521 return (IPPFIND_EXIT_MEMORY
);
523 while (current
->prev
)
525 current
->parent
= temp
;
526 current
= current
->prev
;
529 current
->parent
= temp
;
530 temp
->child
= current
;
533 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
535 return (IPPFIND_EXIT_MEMORY
);
537 temp
->parent
= parent
;
538 current
->parent
= temp
;
541 parent
->child
= temp
;
549 else if (!strcmp(argv
[i
], "--path"))
554 _cupsLangPrintf(stderr
,
555 _("ippfind: Missing regular expression after %s."),
560 if ((temp
= new_expr(IPPFIND_OP_PATH_REGEX
, invert
, NULL
, argv
[i
],
562 return (IPPFIND_EXIT_MEMORY
);
564 else if (!strcmp(argv
[i
], "--port"))
569 _cupsLangPrintf(stderr
,
570 _("ippfind: Expected port range after %s."),
575 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
], NULL
,
577 return (IPPFIND_EXIT_MEMORY
);
579 else if (!strcmp(argv
[i
], "--print"))
581 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
583 return (IPPFIND_EXIT_MEMORY
);
587 else if (!strcmp(argv
[i
], "--print-name"))
589 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
591 return (IPPFIND_EXIT_MEMORY
);
595 else if (!strcmp(argv
[i
], "--quiet"))
597 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
599 return (IPPFIND_EXIT_MEMORY
);
603 else if (!strcmp(argv
[i
], "--remote"))
605 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
607 return (IPPFIND_EXIT_MEMORY
);
609 else if (!strcmp(argv
[i
], "--true"))
611 if ((temp
= new_expr(IPPFIND_OP_TRUE
, invert
, NULL
, argv
[i
],
613 return (IPPFIND_EXIT_MEMORY
);
615 else if (!strcmp(argv
[i
], "--txt"))
620 _cupsLangPrintf(stderr
, _("ippfind: Expected key name after %s."),
625 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
], NULL
,
627 return (IPPFIND_EXIT_MEMORY
);
629 else if (!strncmp(argv
[i
], "--txt-", 5))
631 const char *key
= argv
[i
] + 5;/* TXT key */
636 _cupsLangPrintf(stderr
,
637 _("ippfind: Missing regular expression after %s."),
642 if ((temp
= new_expr(IPPFIND_OP_TXT_REGEX
, invert
, key
, argv
[i
],
644 return (IPPFIND_EXIT_MEMORY
);
646 else if (!strcmp(argv
[i
], "--uri"))
651 _cupsLangPrintf(stderr
,
652 _("ippfind: Missing regular expression after %s."),
657 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
, argv
[i
],
659 return (IPPFIND_EXIT_MEMORY
);
661 else if (!strcmp(argv
[i
], "--version"))
667 _cupsLangPrintf(stderr
, _("%s: Unknown option \"%s\"."),
675 * Add new expression...
678 if (logic
== IPPFIND_OP_AND
&&
679 current
&& current
->prev
&&
680 parent
&& parent
->op
!= IPPFIND_OP_AND
)
683 * Need to re-group "current" in a new AND node...
686 ippfind_expr_t
*tempand
; /* Temporary AND node */
688 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
690 return (IPPFIND_EXIT_MEMORY
);
693 * Replace "current" with new AND node at the end of this list...
696 current
->prev
->next
= tempand
;
697 tempand
->prev
= current
->prev
;
698 tempand
->parent
= parent
;
701 * Add "current to the new AND node...
704 tempand
->child
= current
;
705 current
->parent
= tempand
;
706 current
->prev
= NULL
;
711 * Add the new node at current level...
714 temp
->parent
= parent
;
715 temp
->prev
= current
;
718 current
->next
= temp
;
720 parent
->child
= temp
;
726 logic
= IPPFIND_OP_AND
;
736 for (opt
= argv
[i
] + 1; *opt
; opt
++)
741 address_family
= AF_INET
;
745 address_family
= AF_INET6
;
752 _cupsLangPrintf(stderr
,
753 _("ippfind: Expected port range after %s."),
758 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
],
759 NULL
, NULL
)) == NULL
)
760 return (IPPFIND_EXIT_MEMORY
);
767 _cupsLangPrintf(stderr
,
768 _("%s: Missing timeout for \"-T\"."),
773 bonjour_timeout
= atof(argv
[i
]);
780 _cupsLangPrintf(stderr
,
781 _("%s: Missing version for \"-V\"."),
787 if (!strcmp(argv
[i
], "1.1"))
789 else if (!strcmp(argv
[i
], "2.0"))
791 else if (!strcmp(argv
[i
], "2.1"))
793 else if (!strcmp(argv
[i
], "2.2"))
797 _cupsLangPrintf(stderr
, _("%s: Bad version %s for \"-V\"."),
807 _cupsLangPrintf(stderr
,
808 _("ippfind: Missing regular expression after "
813 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
,
814 argv
[i
], NULL
)) == NULL
)
815 return (IPPFIND_EXIT_MEMORY
);
822 _cupsLangPrintf(stderr
,
823 _("ippfind: Missing regular expression after "
828 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
,
829 argv
[i
], NULL
)) == NULL
)
830 return (IPPFIND_EXIT_MEMORY
);
834 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
836 return (IPPFIND_EXIT_MEMORY
);
845 _cupsLangPrintf(stderr
,
846 _("ippfind: Missing regular expression after "
851 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
,
852 argv
[i
], NULL
)) == NULL
)
853 return (IPPFIND_EXIT_MEMORY
);
857 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
859 return (IPPFIND_EXIT_MEMORY
);
865 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
867 return (IPPFIND_EXIT_MEMORY
);
873 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
875 return (IPPFIND_EXIT_MEMORY
);
879 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
881 return (IPPFIND_EXIT_MEMORY
);
890 _cupsLangPrintf(stderr
,
891 _("ippfind: Missing key name after %s."),
896 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
],
897 NULL
, NULL
)) == NULL
)
898 return (IPPFIND_EXIT_MEMORY
);
905 _cupsLangPrintf(stderr
,
906 _("ippfind: Missing regular expression after "
911 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
,
912 argv
[i
], NULL
)) == NULL
)
913 return (IPPFIND_EXIT_MEMORY
);
920 _cupsLangPrintf(stderr
,
921 _("ippfind: Missing program after %s."),
926 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
928 return (IPPFIND_EXIT_MEMORY
);
931 if (!strcmp(argv
[i
], ";"))
938 _cupsLangPrintf(stderr
,
939 _("ippfind: Missing semi-colon after %s."),
948 _cupsLangPrintf(stderr
, _("%s: Unknown option \"-%c\"."),
957 * Add new expression...
960 if (logic
== IPPFIND_OP_AND
&&
961 current
&& current
->prev
&&
962 parent
&& parent
->op
!= IPPFIND_OP_AND
)
965 * Need to re-group "current" in a new AND node...
968 ippfind_expr_t
*tempand
; /* Temporary AND node */
970 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
972 return (IPPFIND_EXIT_MEMORY
);
975 * Replace "current" with new AND node at the end of this list...
978 current
->prev
->next
= tempand
;
979 tempand
->prev
= current
->prev
;
980 tempand
->parent
= parent
;
983 * Add "current to the new AND node...
986 tempand
->child
= current
;
987 current
->parent
= tempand
;
988 current
->prev
= NULL
;
993 * Add the new node at current level...
996 temp
->parent
= parent
;
997 temp
->prev
= current
;
1000 current
->next
= temp
;
1002 parent
->child
= temp
;
1008 logic
= IPPFIND_OP_AND
;
1014 else if (!strcmp(argv
[i
], "("))
1016 if (num_parens
>= 100)
1018 _cupsLangPuts(stderr
, _("ippfind: Too many parenthesis."));
1022 if ((temp
= new_expr(IPPFIND_OP_AND
, invert
, NULL
, NULL
, NULL
)) == NULL
)
1023 return (IPPFIND_EXIT_MEMORY
);
1025 parens
[num_parens
++] = temp
;
1029 temp
->parent
= current
->parent
;
1030 current
->next
= temp
;
1031 temp
->prev
= current
;
1039 logic
= IPPFIND_OP_AND
;
1041 else if (!strcmp(argv
[i
], ")"))
1043 if (num_parens
<= 0)
1045 _cupsLangPuts(stderr
, _("ippfind: Missing open parenthesis."));
1049 current
= parens
[--num_parens
];
1050 parent
= current
->parent
;
1052 logic
= IPPFIND_OP_AND
;
1054 else if (!strcmp(argv
[i
], "!"))
1061 * _regtype._tcp[,subtype][.domain]
1065 * service-name[._regtype._tcp[.domain]]
1068 cupsArrayAdd(searches
, argv
[i
]);
1074 _cupsLangPuts(stderr
, _("ippfind: Missing close parenthesis."));
1081 * Add an implicit --print-uri to the end...
1084 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, 0, NULL
, NULL
, NULL
)) == NULL
)
1085 return (IPPFIND_EXIT_MEMORY
);
1089 while (current
->parent
)
1090 current
= current
->parent
;
1092 current
->next
= temp
;
1093 temp
->prev
= current
;
1099 if (cupsArrayCount(searches
) == 0)
1102 * Add an implicit browse for IPP printers ("_ipp._tcp")...
1105 cupsArrayAdd(searches
, "_ipp._tcp");
1108 if (getenv("IPPFIND_DEBUG"))
1110 int indent
= 4; /* Indentation */
1112 puts("Expression tree:");
1113 current
= expressions
;
1117 * Print the current node...
1120 printf("%*s%s%s\n", indent
, "", current
->invert
? "!" : "",
1124 * Advance to the next node...
1129 current
= current
->child
;
1132 else if (current
->next
)
1133 current
= current
->next
;
1134 else if (current
->parent
)
1136 while (current
->parent
)
1139 current
= current
->parent
;
1144 current
= current
->next
;
1150 puts("\nSearch items:");
1151 for (search
= (const char *)cupsArrayFirst(searches
);
1153 search
= (const char *)cupsArrayNext(searches
))
1154 printf(" %s\n", search
);
1158 * Start up browsing/resolving...
1162 if ((err
= DNSServiceCreateConnection(&dnssd_ref
)) != kDNSServiceErr_NoError
)
1164 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1165 dnssd_error_string(err
));
1166 return (IPPFIND_EXIT_BONJOUR
);
1169 #elif defined(HAVE_AVAHI)
1170 if ((avahi_poll
= avahi_simple_poll_new()) == NULL
)
1172 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1174 return (IPPFIND_EXIT_BONJOUR
);
1177 avahi_simple_poll_set_func(avahi_poll
, poll_callback
, NULL
);
1179 avahi_client
= avahi_client_new(avahi_simple_poll_get(avahi_poll
),
1180 0, client_callback
, avahi_poll
, &err
);
1183 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1184 dnssd_error_string(err
));
1185 return (IPPFIND_EXIT_BONJOUR
);
1187 #endif /* HAVE_DNSSD */
1189 for (search
= (const char *)cupsArrayFirst(searches
);
1191 search
= (const char *)cupsArrayNext(searches
))
1193 char buf
[1024], /* Full name string */
1194 *name
= NULL
, /* Service instance name */
1195 *regtype
, /* Registration type */
1196 *domain
; /* Domain, if any */
1198 strlcpy(buf
, search
, sizeof(buf
));
1203 else if ((regtype
= strstr(buf
, "._")) != NULL
)
1211 regtype
= "_ipp._tcp";
1214 for (domain
= regtype
; *domain
; domain
++)
1215 if (*domain
== '.' && domain
[1] != '_')
1227 * Resolve the given service instance name, regtype, and domain...
1233 service
= get_service(services
, name
, regtype
, domain
);
1236 service
->ref
= dnssd_ref
;
1237 err
= DNSServiceResolve(&(service
->ref
),
1238 kDNSServiceFlagsShareConnection
, 0, name
,
1239 regtype
, domain
, resolve_callback
,
1242 #elif defined(HAVE_AVAHI)
1243 service
->ref
= avahi_service_resolver_new(avahi_client
, AVAHI_IF_UNSPEC
,
1244 AVAHI_PROTO_UNSPEC
, name
,
1246 AVAHI_PROTO_UNSPEC
, 0,
1247 resolve_callback
, service
);
1251 err
= avahi_client_errno(avahi_client
);
1252 #endif /* HAVE_DNSSD */
1257 * Browse for services of the given type...
1261 DNSServiceRef ref
; /* Browse reference */
1264 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
, 0, regtype
,
1265 domain
, browse_callback
, services
);
1270 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
,
1271 kDNSServiceInterfaceIndexLocalOnly
, regtype
,
1272 domain
, browse_local_callback
, services
);
1275 #elif defined(HAVE_AVAHI)
1276 if (avahi_service_browser_new(avahi_client
, AVAHI_IF_UNSPEC
,
1277 AVAHI_PROTO_UNSPEC
, regtype
, domain
, 0,
1278 browse_callback
, services
))
1281 err
= avahi_client_errno(avahi_client
);
1282 #endif /* HAVE_DNSSD */
1287 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
1288 dnssd_error_string(err
));
1291 printf("name=\"%s\"\n", name
);
1293 printf("regtype=\"%s\"\n", regtype
);
1296 printf("domain=\"%s\"\n", domain
);
1298 return (IPPFIND_EXIT_BONJOUR
);
1303 * Process browse/resolve requests...
1306 if (bonjour_timeout
> 1.0)
1307 endtime
= get_time() + bonjour_timeout
;
1309 endtime
= get_time() + 300.0;
1311 while (get_time() < endtime
)
1313 int process
= 0; /* Process services? */
1316 int fd
= DNSServiceRefSockFD(dnssd_ref
);
1317 /* File descriptor for DNS-SD */
1320 FD_SET(fd
, &sinput
);
1322 stimeout
.tv_sec
= 0;
1323 stimeout
.tv_usec
= 500000;
1325 if (select(fd
+ 1, &sinput
, NULL
, NULL
, &stimeout
) < 0)
1328 if (FD_ISSET(fd
, &sinput
))
1331 * Process responses...
1334 DNSServiceProcessResult(dnssd_ref
);
1339 * Time to process services...
1345 #elif defined(HAVE_AVAHI)
1348 if (avahi_simple_poll_iterate(avahi_poll
, 500) > 0)
1351 * We've been told to exit the loop. Perhaps the connection to
1355 return (IPPFIND_EXIT_BONJOUR
);
1358 if (!avahi_got_data
)
1361 * Time to process services...
1366 #endif /* HAVE_DNSSD */
1371 * Process any services that we have found...
1374 int active
= 0, /* Number of active resolves */
1375 resolved
= 0, /* Number of resolved services */
1376 processed
= 0; /* Number of processed services */
1378 for (service
= (ippfind_srv_t
*)cupsArrayFirst(services
);
1380 service
= (ippfind_srv_t
*)cupsArrayNext(services
))
1382 if (service
->is_processed
)
1385 if (service
->is_resolved
)
1388 if (!service
->ref
&& !service
->is_resolved
)
1391 * Found a service, now resolve it (but limit to 50 active resolves...)
1397 service
->ref
= dnssd_ref
;
1398 err
= DNSServiceResolve(&(service
->ref
),
1399 kDNSServiceFlagsShareConnection
, 0,
1400 service
->name
, service
->regtype
,
1401 service
->domain
, resolve_callback
,
1404 #elif defined(HAVE_AVAHI)
1405 service
->ref
= avahi_service_resolver_new(avahi_client
,
1411 AVAHI_PROTO_UNSPEC
, 0,
1417 err
= avahi_client_errno(avahi_client
);
1418 #endif /* HAVE_DNSSD */
1422 _cupsLangPrintf(stderr
,
1423 _("ippfind: Unable to browse or resolve: %s"),
1424 dnssd_error_string(err
));
1425 return (IPPFIND_EXIT_BONJOUR
);
1431 else if (service
->is_resolved
&& !service
->is_processed
)
1434 * Resolved, not process this service against the expressions...
1440 DNSServiceRefDeallocate(service
->ref
);
1442 avahi_service_resolver_free(service
->ref
);
1443 #endif /* HAVE_DNSSD */
1445 service
->ref
= NULL
;
1448 if (!eval_expr(service
, expressions
))
1449 status
= IPPFIND_EXIT_FALSE
;
1451 service
->is_processed
= 1;
1453 else if (service
->ref
)
1458 * If we have processed all services we have discovered, then we are done.
1461 if (processed
== cupsArrayCount(services
) && bonjour_timeout
<= 1.0)
1467 return (IPPFIND_EXIT_BONJOUR
);
1475 * 'browse_callback()' - Browse devices.
1478 static void DNSSD_API
1480 DNSServiceRef sdRef
, /* I - Service reference */
1481 DNSServiceFlags flags
, /* I - Option flags */
1482 uint32_t interfaceIndex
, /* I - Interface number */
1483 DNSServiceErrorType errorCode
, /* I - Error, if any */
1484 const char *serviceName
, /* I - Name of service/device */
1485 const char *regtype
, /* I - Type of service */
1486 const char *replyDomain
, /* I - Service domain */
1487 void *context
) /* I - Services array */
1490 * Only process "add" data...
1493 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1500 get_service((cups_array_t
*)context
, serviceName
, regtype
, replyDomain
);
1505 * 'browse_local_callback()' - Browse local devices.
1508 static void DNSSD_API
1509 browse_local_callback(
1510 DNSServiceRef sdRef
, /* I - Service reference */
1511 DNSServiceFlags flags
, /* I - Option flags */
1512 uint32_t interfaceIndex
, /* I - Interface number */
1513 DNSServiceErrorType errorCode
, /* I - Error, if any */
1514 const char *serviceName
, /* I - Name of service/device */
1515 const char *regtype
, /* I - Type of service */
1516 const char *replyDomain
, /* I - Service domain */
1517 void *context
) /* I - Services array */
1519 ippfind_srv_t
*service
; /* Service */
1523 * Only process "add" data...
1526 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1533 service
= get_service((cups_array_t
*)context
, serviceName
, regtype
,
1535 service
->is_local
= 1;
1537 #endif /* HAVE_DNSSD */
1542 * 'browse_callback()' - Browse devices.
1547 AvahiServiceBrowser
*browser
, /* I - Browser */
1548 AvahiIfIndex interface
, /* I - Interface index (unused) */
1549 AvahiProtocol protocol
, /* I - Network protocol (unused) */
1550 AvahiBrowserEvent event
, /* I - What happened */
1551 const char *name
, /* I - Service name */
1552 const char *type
, /* I - Registration type */
1553 const char *domain
, /* I - Domain */
1554 AvahiLookupResultFlags flags
, /* I - Flags */
1555 void *context
) /* I - Services array */
1557 AvahiClient
*client
= avahi_service_browser_get_client(browser
);
1558 /* Client information */
1559 ippfind_srv_t
*service
; /* Service information */
1568 case AVAHI_BROWSER_FAILURE
:
1569 fprintf(stderr
, "DEBUG: browse_callback: %s\n",
1570 avahi_strerror(avahi_client_errno(client
)));
1572 avahi_simple_poll_quit(avahi_poll
);
1575 case AVAHI_BROWSER_NEW
:
1577 * This object is new on the network. Create a device entry for it if
1578 * it doesn't yet exist.
1581 service
= get_service((cups_array_t
*)context
, name
, type
, domain
);
1583 if (flags
& AVAHI_LOOKUP_RESULT_LOCAL
)
1584 service
->is_local
= 1;
1587 case AVAHI_BROWSER_REMOVE
:
1588 case AVAHI_BROWSER_ALL_FOR_NOW
:
1589 case AVAHI_BROWSER_CACHE_EXHAUSTED
:
1596 * 'client_callback()' - Avahi client callback function.
1601 AvahiClient
*client
, /* I - Client information (unused) */
1602 AvahiClientState state
, /* I - Current state */
1603 void *context
) /* I - User data (unused) */
1609 * If the connection drops, quit.
1612 if (state
== AVAHI_CLIENT_FAILURE
)
1614 fputs("DEBUG: Avahi connection failed.\n", stderr
);
1616 avahi_simple_poll_quit(avahi_poll
);
1619 #endif /* HAVE_AVAHI */
1623 * 'compare_services()' - Compare two devices.
1626 static int /* O - Result of comparison */
1627 compare_services(ippfind_srv_t
*a
, /* I - First device */
1628 ippfind_srv_t
*b
) /* I - Second device */
1630 return (strcmp(a
->name
, b
->name
));
1635 * 'dnssd_error_string()' - Return an error string for an error code.
1638 static const char * /* O - Error message */
1639 dnssd_error_string(int error
) /* I - Error number */
1644 case kDNSServiceErr_NoError
:
1648 case kDNSServiceErr_Unknown
:
1649 return ("Unknown error.");
1651 case kDNSServiceErr_NoSuchName
:
1652 return ("Service not found.");
1654 case kDNSServiceErr_NoMemory
:
1655 return ("Out of memory.");
1657 case kDNSServiceErr_BadParam
:
1658 return ("Bad parameter.");
1660 case kDNSServiceErr_BadReference
:
1661 return ("Bad service reference.");
1663 case kDNSServiceErr_BadState
:
1664 return ("Bad state.");
1666 case kDNSServiceErr_BadFlags
:
1667 return ("Bad flags.");
1669 case kDNSServiceErr_Unsupported
:
1670 return ("Unsupported.");
1672 case kDNSServiceErr_NotInitialized
:
1673 return ("Not initialized.");
1675 case kDNSServiceErr_AlreadyRegistered
:
1676 return ("Already registered.");
1678 case kDNSServiceErr_NameConflict
:
1679 return ("Name conflict.");
1681 case kDNSServiceErr_Invalid
:
1682 return ("Invalid name.");
1684 case kDNSServiceErr_Firewall
:
1685 return ("Firewall prevents registration.");
1687 case kDNSServiceErr_Incompatible
:
1688 return ("Client library incompatible.");
1690 case kDNSServiceErr_BadInterfaceIndex
:
1691 return ("Bad interface index.");
1693 case kDNSServiceErr_Refused
:
1694 return ("Server prevents registration.");
1696 case kDNSServiceErr_NoSuchRecord
:
1697 return ("Record not found.");
1699 case kDNSServiceErr_NoAuth
:
1700 return ("Authentication required.");
1702 case kDNSServiceErr_NoSuchKey
:
1703 return ("Encryption key not found.");
1705 case kDNSServiceErr_NATTraversal
:
1706 return ("Unable to traverse NAT boundary.");
1708 case kDNSServiceErr_DoubleNAT
:
1709 return ("Unable to traverse double-NAT boundary.");
1711 case kDNSServiceErr_BadTime
:
1712 return ("Bad system time.");
1714 case kDNSServiceErr_BadSig
:
1715 return ("Bad signature.");
1717 case kDNSServiceErr_BadKey
:
1718 return ("Bad encryption key.");
1720 case kDNSServiceErr_Transient
:
1721 return ("Transient error occurred - please try again.");
1723 case kDNSServiceErr_ServiceNotRunning
:
1724 return ("Server not running.");
1726 case kDNSServiceErr_NATPortMappingUnsupported
:
1727 return ("NAT doesn't support NAT-PMP or UPnP.");
1729 case kDNSServiceErr_NATPortMappingDisabled
:
1730 return ("NAT supports NAT-PNP or UPnP but it is disabled.");
1732 case kDNSServiceErr_NoRouter
:
1733 return ("No Internet/default router configured.");
1735 case kDNSServiceErr_PollingMode
:
1736 return ("Service polling mode error.");
1739 case kDNSServiceErr_Timeout
:
1740 return ("Service timeout.");
1744 # elif defined(HAVE_AVAHI)
1745 return (avahi_strerror(error
));
1746 # endif /* HAVE_DNSSD */
1751 * 'eval_expr()' - Evaluate the expressions against the specified service.
1753 * Returns 1 for true and 0 for false.
1756 static int /* O - Result of evaluation */
1757 eval_expr(ippfind_srv_t
*service
, /* I - Service */
1758 ippfind_expr_t
*expressions
) /* I - Expressions */
1760 int logic
, /* Logical operation */
1761 result
; /* Result of current expression */
1762 ippfind_expr_t
*expression
; /* Current expression */
1763 const char *val
; /* TXT value */
1766 * Loop through the expressions...
1769 if (expressions
&& expressions
->parent
)
1770 logic
= expressions
->parent
->op
;
1772 logic
= IPPFIND_OP_AND
;
1774 for (expression
= expressions
; expression
; expression
= expression
->next
)
1776 switch (expression
->op
)
1779 case IPPFIND_OP_AND
:
1780 case IPPFIND_OP_OR
:
1781 if (expression
->child
)
1782 result
= eval_expr(service
, expression
->child
);
1784 result
= expression
->op
== IPPFIND_OP_AND
;
1786 case IPPFIND_OP_TRUE
:
1789 case IPPFIND_OP_FALSE
:
1792 case IPPFIND_OP_IS_LOCAL
:
1793 result
= service
->is_local
;
1795 case IPPFIND_OP_IS_REMOTE
:
1796 result
= !service
->is_local
;
1798 case IPPFIND_OP_DOMAIN_REGEX
:
1799 result
= !regexec(&(expression
->re
), service
->domain
, 0, NULL
, 0);
1801 case IPPFIND_OP_NAME_REGEX
:
1802 result
= !regexec(&(expression
->re
), service
->name
, 0, NULL
, 0);
1804 case IPPFIND_OP_HOST_REGEX
:
1805 result
= !regexec(&(expression
->re
), service
->host
, 0, NULL
, 0);
1807 case IPPFIND_OP_PORT_RANGE
:
1808 result
= service
->port
>= expression
->range
[0] &&
1809 service
->port
<= expression
->range
[1];
1811 case IPPFIND_OP_PATH_REGEX
:
1812 result
= !regexec(&(expression
->re
), service
->resource
, 0, NULL
, 0);
1814 case IPPFIND_OP_TXT_EXISTS
:
1815 result
= cupsGetOption(expression
->key
, service
->num_txt
,
1816 service
->txt
) != NULL
;
1818 case IPPFIND_OP_TXT_REGEX
:
1819 val
= cupsGetOption(expression
->key
, service
->num_txt
,
1822 result
= !regexec(&(expression
->re
), val
, 0, NULL
, 0);
1826 case IPPFIND_OP_URI_REGEX
:
1827 result
= !regexec(&(expression
->re
), service
->uri
, 0, NULL
, 0);
1829 case IPPFIND_OP_EXEC
:
1830 result
= exec_program(service
, expression
->num_args
,
1833 case IPPFIND_OP_LIST
:
1834 result
= list_service(service
);
1836 case IPPFIND_OP_PRINT_NAME
:
1837 _cupsLangPuts(stdout
, service
->name
);
1840 case IPPFIND_OP_PRINT_URI
:
1841 _cupsLangPuts(stdout
, service
->uri
);
1844 case IPPFIND_OP_QUIET
:
1849 if (expression
->invert
)
1852 if (logic
== IPPFIND_OP_AND
&& !result
)
1854 else if (logic
== IPPFIND_OP_OR
&& result
)
1858 return (logic
== IPPFIND_OP_AND
);
1863 * 'exec_program()' - Execute a program for a service.
1866 static int /* O - 1 if program terminated
1867 successfully, 0 otherwise. */
1868 exec_program(ippfind_srv_t
*service
, /* I - Service */
1869 int num_args
, /* I - Number of command-line args */
1870 char **args
) /* I - Command-line arguments */
1872 char **myargv
, /* Command-line arguments */
1873 **myenvp
, /* Environment variables */
1874 *ptr
, /* Pointer into variable */
1875 domain
[1024], /* IPPFIND_SERVICE_DOMAIN */
1876 hostname
[1024], /* IPPFIND_SERVICE_HOSTNAME */
1877 name
[256], /* IPPFIND_SERVICE_NAME */
1878 port
[32], /* IPPFIND_SERVICE_PORT */
1879 regtype
[256], /* IPPFIND_SERVICE_REGTYPE */
1880 scheme
[128], /* IPPFIND_SERVICE_SCHEME */
1881 uri
[1024], /* IPPFIND_SERVICE_URI */
1882 txt
[100][256]; /* IPPFIND_TXT_foo */
1883 int i
, /* Looping var */
1884 myenvc
, /* Number of environment variables */
1885 status
; /* Exit status of program */
1887 char program
[1024]; /* Program to execute */
1888 int pid
; /* Process ID */
1893 * Environment variables...
1896 snprintf(domain
, sizeof(domain
), "IPPFIND_SERVICE_DOMAIN=%s",
1898 snprintf(hostname
, sizeof(hostname
), "IPPFIND_SERVICE_HOSTNAME=%s",
1900 snprintf(name
, sizeof(name
), "IPPFIND_SERVICE_NAME=%s", service
->name
);
1901 snprintf(port
, sizeof(port
), "IPPFIND_SERVICE_PORT=%d", service
->port
);
1902 snprintf(regtype
, sizeof(regtype
), "IPPFIND_SERVICE_REGTYPE=%s",
1904 snprintf(scheme
, sizeof(scheme
), "IPPFIND_SERVICE_SCHEME=%s",
1905 !strncmp(service
->regtype
, "_http._tcp", 10) ? "http" :
1906 !strncmp(service
->regtype
, "_https._tcp", 11) ? "https" :
1907 !strncmp(service
->regtype
, "_ipp._tcp", 9) ? "ipp" :
1908 !strncmp(service
->regtype
, "_ipps._tcp", 10) ? "ipps" : "lpd");
1909 snprintf(uri
, sizeof(uri
), "IPPFIND_SERVICE_URI=%s", service
->uri
);
1910 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1912 snprintf(txt
[i
], sizeof(txt
[i
]), "IPPFIND_TXT_%s=%s", service
->txt
[i
].name
,
1913 service
->txt
[i
].value
);
1914 for (ptr
= txt
[i
] + 12; *ptr
&& *ptr
!= '='; ptr
++)
1915 *ptr
= _cups_toupper(*ptr
);
1918 for (i
= 0, myenvc
= 7 + service
->num_txt
; environ
[i
]; i
++)
1919 if (strncmp(environ
[i
], "IPPFIND_", 8))
1922 if ((myenvp
= calloc(sizeof(char *), myenvc
+ 1)) == NULL
)
1924 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1925 exit(IPPFIND_EXIT_MEMORY
);
1928 for (i
= 0, myenvc
= 0; environ
[i
]; i
++)
1929 if (strncmp(environ
[i
], "IPPFIND_", 8))
1930 myenvp
[myenvc
++] = environ
[i
];
1932 myenvp
[myenvc
++] = domain
;
1933 myenvp
[myenvc
++] = hostname
;
1934 myenvp
[myenvc
++] = name
;
1935 myenvp
[myenvc
++] = port
;
1936 myenvp
[myenvc
++] = regtype
;
1937 myenvp
[myenvc
++] = scheme
;
1938 myenvp
[myenvc
++] = uri
;
1940 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1941 myenvp
[myenvc
++] = txt
[i
];
1944 * Allocate and copy command-line arguments...
1947 if ((myargv
= calloc(sizeof(char *), num_args
+ 1)) == NULL
)
1949 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1950 exit(IPPFIND_EXIT_MEMORY
);
1953 for (i
= 0; i
< num_args
; i
++)
1955 if (strchr(args
[i
], '{'))
1957 char temp
[2048], /* Temporary string */
1958 *tptr
, /* Pointer into temporary string */
1959 keyword
[256], /* {keyword} */
1960 *kptr
; /* Pointer into keyword */
1962 for (ptr
= args
[i
], tptr
= temp
; *ptr
; ptr
++)
1967 * Do a {var} substitution...
1970 for (kptr
= keyword
, ptr
++; *ptr
&& *ptr
!= '}'; ptr
++)
1971 if (kptr
< (keyword
+ sizeof(keyword
) - 1))
1976 _cupsLangPuts(stderr
,
1977 _("ippfind: Missing close brace in substitution."));
1978 exit(IPPFIND_EXIT_SYNTAX
);
1982 if (!keyword
[0] || !strcmp(keyword
, "service_uri"))
1983 strlcpy(tptr
, service
->uri
, sizeof(temp
) - (tptr
- temp
));
1984 else if (!strcmp(keyword
, "service_domain"))
1985 strlcpy(tptr
, service
->domain
, sizeof(temp
) - (tptr
- temp
));
1986 else if (!strcmp(keyword
, "service_hostname"))
1987 strlcpy(tptr
, service
->host
, sizeof(temp
) - (tptr
- temp
));
1988 else if (!strcmp(keyword
, "service_name"))
1989 strlcpy(tptr
, service
->name
, sizeof(temp
) - (tptr
- temp
));
1990 else if (!strcmp(keyword
, "service_path"))
1991 strlcpy(tptr
, service
->resource
, sizeof(temp
) - (tptr
- temp
));
1992 else if (!strcmp(keyword
, "service_port"))
1993 strlcpy(tptr
, port
+ 20, sizeof(temp
) - (tptr
- temp
));
1994 else if (!strcmp(keyword
, "service_scheme"))
1995 strlcpy(tptr
, scheme
+ 22, sizeof(temp
) - (tptr
- temp
));
1996 else if (!strncmp(keyword
, "txt_", 4))
1998 if ((ptr
= (char *)cupsGetOption(keyword
+ 4, service
->num_txt
,
1999 service
->txt
)) != NULL
)
2000 strlcpy(tptr
, strdup(ptr
), sizeof(temp
) - (tptr
- temp
));
2006 _cupsLangPrintf(stderr
, _("ippfind: Unknown variable \"{%s}\"."),
2008 exit(IPPFIND_EXIT_SYNTAX
);
2011 tptr
+= strlen(tptr
);
2013 else if (tptr
< (temp
+ sizeof(temp
) - 1))
2018 myargv
[i
] = strdup(temp
);
2021 myargv
[i
] = strdup(args
[i
]);
2025 status
= _spawnvpe(_P_WAIT
, args
[0], myargv
, myenvp
);
2029 * Execute the program...
2032 if (strchr(args
[0], '/') && !access(args
[0], X_OK
))
2033 strlcpy(program
, args
[0], sizeof(program
));
2034 else if (!cupsFileFind(args
[0], getenv("PATH"), 1, program
, sizeof(program
)))
2036 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2037 args
[0], strerror(ENOENT
));
2038 exit(IPPFIND_EXIT_SYNTAX
);
2041 if (getenv("IPPFIND_DEBUG"))
2043 printf("\nProgram:\n %s\n", program
);
2044 puts("\nArguments:");
2045 for (i
= 0; i
< num_args
; i
++)
2046 printf(" %s\n", myargv
[i
]);
2047 puts("\nEnvironment:");
2048 for (i
= 0; i
< myenvc
; i
++)
2049 printf(" %s\n", myenvp
[i
]);
2052 if ((pid
= fork()) == 0)
2055 * Child comes here...
2058 execve(program
, myargv
, myenvp
);
2063 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2064 args
[0], strerror(errno
));
2065 exit(IPPFIND_EXIT_SYNTAX
);
2070 * Wait for it to complete...
2073 while (wait(&status
) != pid
)
2082 for (i
= 0; i
< num_args
; i
++)
2089 * Return whether the program succeeded or crashed...
2092 return (status
== 0);
2097 * 'get_service()' - Create or update a device.
2100 static ippfind_srv_t
* /* O - Service */
2101 get_service(cups_array_t
*services
, /* I - Service array */
2102 const char *serviceName
, /* I - Name of service/device */
2103 const char *regtype
, /* I - Type of service */
2104 const char *replyDomain
) /* I - Service domain */
2106 ippfind_srv_t key
, /* Search key */
2107 *service
; /* Service */
2108 char fullName
[kDNSServiceMaxDomainName
];
2109 /* Full name for query */
2113 * See if this is a new device...
2116 key
.name
= (char *)serviceName
;
2117 key
.regtype
= (char *)regtype
;
2119 for (service
= cupsArrayFind(services
, &key
);
2121 service
= cupsArrayNext(services
))
2122 if (_cups_strcasecmp(service
->name
, key
.name
))
2124 else if (!strcmp(service
->regtype
, key
.regtype
))
2128 * Yes, add the service...
2131 service
= calloc(sizeof(ippfind_srv_t
), 1);
2132 service
->name
= strdup(serviceName
);
2133 service
->domain
= strdup(replyDomain
);
2134 service
->regtype
= strdup(regtype
);
2136 cupsArrayAdd(services
, service
);
2139 * Set the "full name" of this service, which is used for queries and
2144 DNSServiceConstructFullName(fullName
, serviceName
, regtype
, replyDomain
);
2145 #else /* HAVE_AVAHI */
2146 avahi_service_name_join(fullName
, kDNSServiceMaxDomainName
, serviceName
,
2147 regtype
, replyDomain
);
2148 #endif /* HAVE_DNSSD */
2150 service
->fullName
= strdup(fullName
);
2157 * 'get_time()' - Get the current time-of-day in seconds.
2164 struct _timeb curtime
; /* Current Windows time */
2168 return (curtime
.time
+ 0.001 * curtime
.millitm
);
2171 struct timeval curtime
; /* Current UNIX time */
2173 if (gettimeofday(&curtime
, NULL
))
2176 return (curtime
.tv_sec
+ 0.000001 * curtime
.tv_usec
);
2182 * 'list_service()' - List the contents of a service.
2185 static int /* O - 1 if successful, 0 otherwise */
2186 list_service(ippfind_srv_t
*service
) /* I - Service */
2188 http_addrlist_t
*addrlist
; /* Address(es) of service */
2189 char port
[10]; /* Port number of service */
2192 snprintf(port
, sizeof(port
), "%d", service
->port
);
2194 if ((addrlist
= httpAddrGetList(service
->host
, address_family
, port
)) == NULL
)
2196 _cupsLangPrintf(stdout
, "%s unreachable", service
->uri
);
2200 if (!strncmp(service
->regtype
, "_ipp._tcp", 9) ||
2201 !strncmp(service
->regtype
, "_ipps._tcp", 10))
2207 http_t
*http
; /* HTTP connection */
2208 ipp_t
*request
, /* IPP request */
2209 *response
; /* IPP response */
2210 ipp_attribute_t
*attr
; /* IPP attribute */
2211 int i
, /* Looping var */
2212 count
, /* Number of values */
2213 version
, /* IPP version */
2214 paccepting
; /* printer-is-accepting-jobs value */
2215 ipp_pstate_t pstate
; /* printer-state value */
2216 char preasons
[1024], /* Comma-delimited printer-state-reasons */
2217 *ptr
, /* Pointer into reasons */
2218 *end
; /* End of reasons buffer */
2219 static const char * const rattrs
[] =/* Requested attributes */
2221 "printer-is-accepting-jobs",
2223 "printer-state-reasons"
2227 * Connect to the printer...
2230 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2231 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2232 HTTP_ENCRYPTION_ALWAYS
:
2233 HTTP_ENCRYPTION_IF_REQUESTED
,
2236 httpAddrFreeList(addrlist
);
2240 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2245 * Get the current printer state...
2249 version
= ipp_version
;
2253 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
2254 ippSetVersion(request
, version
/ 10, version
% 10);
2255 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
2257 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
2258 "requesting-user-name", NULL
, cupsUser());
2259 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
2260 "requested-attributes",
2261 (int)(sizeof(rattrs
) / sizeof(rattrs
[0])), NULL
, rattrs
);
2263 response
= cupsDoRequest(http
, request
, service
->resource
);
2265 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
&& version
> 11)
2268 while (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
&& version
> 11);
2274 if (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
)
2276 _cupsLangPrintf(stdout
, "%s: unavailable", service
->uri
);
2280 if ((attr
= ippFindAttribute(response
, "printer-state",
2281 IPP_TAG_ENUM
)) != NULL
)
2282 pstate
= ippGetInteger(attr
, 0);
2284 pstate
= IPP_PSTATE_STOPPED
;
2286 if ((attr
= ippFindAttribute(response
, "printer-is-accepting-jobs",
2287 IPP_TAG_BOOLEAN
)) != NULL
)
2288 paccepting
= ippGetBoolean(attr
, 0);
2292 if ((attr
= ippFindAttribute(response
, "printer-state-reasons",
2293 IPP_TAG_KEYWORD
)) != NULL
)
2295 strlcpy(preasons
, ippGetString(attr
, 0, NULL
), sizeof(preasons
));
2297 for (i
= 1, count
= ippGetCount(attr
), ptr
= preasons
+ strlen(preasons
),
2298 end
= preasons
+ sizeof(preasons
) - 1;
2299 i
< count
&& ptr
< end
;
2300 i
++, ptr
+= strlen(ptr
))
2303 strlcpy(ptr
, ippGetString(attr
, i
, NULL
), end
- ptr
+ 1);
2307 strlcpy(preasons
, "none", sizeof(preasons
));
2309 ippDelete(response
);
2312 _cupsLangPrintf(stdout
, "%s %s %s %s", service
->uri
,
2313 ippEnumString("printer-state", pstate
),
2314 paccepting
? "accepting-jobs" : "not-accepting-jobs",
2317 else if (!strncmp(service
->regtype
, "_http._tcp", 10) ||
2318 !strncmp(service
->regtype
, "_https._tcp", 11))
2321 * HTTP/HTTPS web page
2324 http_t
*http
; /* HTTP connection */
2325 http_status_t status
; /* HEAD status */
2329 * Connect to the web server...
2332 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2333 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2334 HTTP_ENCRYPTION_ALWAYS
:
2335 HTTP_ENCRYPTION_IF_REQUESTED
,
2338 httpAddrFreeList(addrlist
);
2342 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2346 if (httpGet(http
, service
->resource
))
2348 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2354 status
= httpUpdate(http
);
2356 while (status
== HTTP_STATUS_CONTINUE
);
2361 if (status
>= HTTP_STATUS_BAD_REQUEST
)
2363 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2367 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2369 else if (!strncmp(service
->regtype
, "_printer._tcp", 13))
2375 int sock
; /* Socket */
2378 if (!httpAddrConnect(addrlist
, &sock
))
2380 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2381 httpAddrFreeList(addrlist
);
2385 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2386 httpAddrFreeList(addrlist
);
2388 httpAddrClose(NULL
, sock
);
2392 _cupsLangPrintf(stdout
, "%s unsupported", service
->uri
);
2393 httpAddrFreeList(addrlist
);
2402 * 'new_expr()' - Create a new expression.
2405 static ippfind_expr_t
* /* O - New expression */
2406 new_expr(ippfind_op_t op
, /* I - Operation */
2407 int invert
, /* I - Invert result? */
2408 const char *value
, /* I - TXT key or port range */
2409 const char *regex
, /* I - Regular expression */
2410 char **args
) /* I - Pointer to argument strings */
2412 ippfind_expr_t
*temp
; /* New expression */
2415 if ((temp
= calloc(1, sizeof(ippfind_expr_t
))) == NULL
)
2419 temp
->invert
= invert
;
2421 if (op
== IPPFIND_OP_TXT_EXISTS
|| op
== IPPFIND_OP_TXT_REGEX
)
2422 temp
->key
= (char *)value
;
2423 else if (op
== IPPFIND_OP_PORT_RANGE
)
2426 * Pull port number range of the form "number", "-number" (0-number),
2427 * "number-" (number-65535), and "number-number".
2432 temp
->range
[1] = atoi(value
+ 1);
2434 else if (strchr(value
, '-'))
2436 if (sscanf(value
, "%d-%d", temp
->range
, temp
->range
+ 1) == 1)
2437 temp
->range
[1] = 65535;
2441 temp
->range
[0] = temp
->range
[1] = atoi(value
);
2447 int err
= regcomp(&(temp
->re
), regex
, REG_NOSUB
| REG_ICASE
| REG_EXTENDED
);
2451 char message
[256]; /* Error message */
2453 regerror(err
, &(temp
->re
), message
, sizeof(message
));
2454 _cupsLangPrintf(stderr
, _("ippfind: Bad regular expression: %s"),
2456 exit(IPPFIND_EXIT_SYNTAX
);
2462 int num_args
; /* Number of arguments */
2464 for (num_args
= 1; args
[num_args
]; num_args
++)
2465 if (!strcmp(args
[num_args
], ";"))
2468 temp
->num_args
= num_args
;
2469 temp
->args
= malloc(num_args
* sizeof(char *));
2470 memcpy(temp
->args
, args
, num_args
* sizeof(char *));
2479 * 'poll_callback()' - Wait for input on the specified file descriptors.
2481 * Note: This function is needed because avahi_simple_poll_iterate is broken
2482 * and always uses a timeout of 0 (!) milliseconds.
2483 * (Avahi Ticket #364)
2486 static int /* O - Number of file descriptors matching */
2488 struct pollfd
*pollfds
, /* I - File descriptors */
2489 unsigned int num_pollfds
, /* I - Number of file descriptors */
2490 int timeout
, /* I - Timeout in milliseconds (unused) */
2491 void *context
) /* I - User data (unused) */
2493 int val
; /* Return value */
2499 val
= poll(pollfds
, num_pollfds
, 500);
2506 #endif /* HAVE_AVAHI */
2510 * 'resolve_callback()' - Process resolve data.
2514 static void DNSSD_API
2516 DNSServiceRef sdRef
, /* I - Service reference */
2517 DNSServiceFlags flags
, /* I - Data flags */
2518 uint32_t interfaceIndex
, /* I - Interface */
2519 DNSServiceErrorType errorCode
, /* I - Error, if any */
2520 const char *fullName
, /* I - Full service name */
2521 const char *hostTarget
, /* I - Hostname */
2522 uint16_t port
, /* I - Port number (network byte order) */
2523 uint16_t txtLen
, /* I - Length of TXT record data */
2524 const unsigned char *txtRecord
, /* I - TXT record data */
2525 void *context
) /* I - Service */
2527 char key
[256], /* TXT key value */
2528 *value
; /* Value from TXT record */
2529 const unsigned char *txtEnd
; /* End of TXT record */
2530 uint8_t valueLen
; /* Length of value */
2531 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2536 * Only process "add" data...
2539 if (errorCode
!= kDNSServiceErr_NoError
)
2541 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
2542 dnssd_error_string(errorCode
));
2547 service
->is_resolved
= 1;
2548 service
->host
= strdup(hostTarget
);
2549 service
->port
= ntohs(port
);
2552 * Loop through the TXT key/value pairs and add them to an array...
2555 for (txtEnd
= txtRecord
+ txtLen
; txtRecord
< txtEnd
; txtRecord
+= valueLen
)
2558 * Ignore bogus strings...
2561 valueLen
= *txtRecord
++;
2563 memcpy(key
, txtRecord
, valueLen
);
2564 key
[valueLen
] = '\0';
2566 if ((value
= strchr(key
, '=')) == NULL
)
2572 * Add to array of TXT values...
2575 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2579 set_service_uri(service
);
2583 #elif defined(HAVE_AVAHI)
2586 AvahiServiceResolver
*resolver
, /* I - Resolver */
2587 AvahiIfIndex interface
, /* I - Interface */
2588 AvahiProtocol protocol
, /* I - Address protocol */
2589 AvahiResolverEvent event
, /* I - Event */
2590 const char *serviceName
,/* I - Service name */
2591 const char *regtype
, /* I - Registration type */
2592 const char *replyDomain
,/* I - Domain name */
2593 const char *hostTarget
, /* I - FQDN */
2594 const AvahiAddress
*address
, /* I - Address */
2595 uint16_t port
, /* I - Port number */
2596 AvahiStringList
*txt
, /* I - TXT records */
2597 AvahiLookupResultFlags flags
, /* I - Lookup flags */
2598 void *context
) /* I - Service */
2600 char key
[256], /* TXT key */
2601 *value
; /* TXT value */
2602 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2604 AvahiStringList
*current
; /* Current TXT key/value pair */
2609 if (event
!= AVAHI_RESOLVER_FOUND
)
2613 avahi_service_resolver_free(resolver
);
2614 avahi_simple_poll_quit(avahi_poll
);
2618 service
->is_resolved
= 1;
2619 service
->host
= strdup(hostTarget
);
2620 service
->port
= port
;
2623 * Loop through the TXT key/value pairs and add them to an array...
2626 for (current
= txt
; current
; current
= current
->next
)
2629 * Ignore bogus strings...
2632 if (current
->size
> (sizeof(key
) - 1))
2635 memcpy(key
, current
->text
, current
->size
);
2636 key
[current
->size
] = '\0';
2638 if ((value
= strchr(key
, '=')) == NULL
)
2644 * Add to array of TXT values...
2647 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2651 set_service_uri(service
);
2653 #endif /* HAVE_DNSSD */
2657 * 'set_service_uri()' - Set the URI of the service.
2661 set_service_uri(ippfind_srv_t
*service
) /* I - Service */
2663 char uri
[1024]; /* URI */
2664 const char *path
, /* Resource path */
2665 *scheme
; /* URI scheme */
2668 if (!strncmp(service
->regtype
, "_http.", 6))
2671 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2673 else if (!strncmp(service
->regtype
, "_https.", 7))
2676 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2678 else if (!strncmp(service
->regtype
, "_ipp.", 5))
2681 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2683 else if (!strncmp(service
->regtype
, "_ipps.", 6))
2686 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2688 else if (!strncmp(service
->regtype
, "_printer.", 9))
2691 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2696 if (!path
|| !*path
)
2701 service
->resource
= strdup(path
);
2705 snprintf(uri
, sizeof(uri
), "/%s", path
);
2706 service
->resource
= strdup(uri
);
2709 httpAssembleURI(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), scheme
, NULL
,
2710 service
->host
, service
->port
, service
->resource
);
2711 service
->uri
= strdup(uri
);
2716 * 'show_usage()' - Show program usage.
2722 _cupsLangPuts(stderr
, _("Usage: ippfind [options] regtype[,subtype]"
2723 "[.domain.] ... [expression]\n"
2724 " ippfind [options] name[.regtype[.domain.]] "
2725 "... [expression]\n"
2727 " ippfind --version"));
2728 _cupsLangPuts(stderr
, "");
2729 _cupsLangPuts(stderr
, _("Options:"));
2730 _cupsLangPuts(stderr
, _(" -4 Connect using IPv4."));
2731 _cupsLangPuts(stderr
, _(" -6 Connect using IPv6."));
2732 _cupsLangPuts(stderr
, _(" -T seconds Set the browse timeout in "
2734 _cupsLangPuts(stderr
, _(" -V version Set default IPP "
2736 _cupsLangPuts(stderr
, _(" --help Show this help."));
2737 _cupsLangPuts(stderr
, _(" --version Show program version."));
2738 _cupsLangPuts(stderr
, "");
2739 _cupsLangPuts(stderr
, _("Expressions:"));
2740 _cupsLangPuts(stderr
, _(" -P number[-number] Match port to number or range."));
2741 _cupsLangPuts(stderr
, _(" -d regex Match domain to regular expression."));
2742 _cupsLangPuts(stderr
, _(" -h regex Match hostname to regular expression."));
2743 _cupsLangPuts(stderr
, _(" -l List attributes."));
2744 _cupsLangPuts(stderr
, _(" -n regex Match service name to regular expression."));
2745 _cupsLangPuts(stderr
, _(" -p Print URI if true."));
2746 _cupsLangPuts(stderr
, _(" -q Quietly report match via exit code."));
2747 _cupsLangPuts(stderr
, _(" -r True if service is remote."));
2748 _cupsLangPuts(stderr
, _(" -s Print service name if true."));
2749 _cupsLangPuts(stderr
, _(" -t key True if the TXT record contains the key."));
2750 _cupsLangPuts(stderr
, _(" -u regex Match URI to regular expression."));
2751 _cupsLangPuts(stderr
, _(" -x utility [argument ...] ;\n"
2752 " Execute program if true."));
2753 _cupsLangPuts(stderr
, _(" --domain regex Match domain to regular expression."));
2754 _cupsLangPuts(stderr
, _(" --exec utility [argument ...] ;\n"
2755 " Execute program if true."));
2756 _cupsLangPuts(stderr
, _(" --host regex Match hostname to regular expression."));
2757 _cupsLangPuts(stderr
, _(" --ls List attributes."));
2758 _cupsLangPuts(stderr
, _(" --local True if service is local."));
2759 _cupsLangPuts(stderr
, _(" --name regex Match service name to regular expression."));
2760 _cupsLangPuts(stderr
, _(" --path regex Match resource path to regular expression."));
2761 _cupsLangPuts(stderr
, _(" --port number[-number] Match port to number or range."));
2762 _cupsLangPuts(stderr
, _(" --print Print URI if true."));
2763 _cupsLangPuts(stderr
, _(" --print-name Print service name if true."));
2764 _cupsLangPuts(stderr
, _(" --quiet Quietly report match via exit code."));
2765 _cupsLangPuts(stderr
, _(" --remote True if service is remote."));
2766 _cupsLangPuts(stderr
, _(" --txt key True if the TXT record contains the key."));
2767 _cupsLangPuts(stderr
, _(" --txt-* regex Match TXT record key to regular expression."));
2768 _cupsLangPuts(stderr
, _(" --uri regex Match URI to regular expression."));
2769 _cupsLangPuts(stderr
, "");
2770 _cupsLangPuts(stderr
, _("Modifiers:"));
2771 _cupsLangPuts(stderr
, _(" ( expressions ) Group expressions."));
2772 _cupsLangPuts(stderr
, _(" ! expression Unary NOT of expression."));
2773 _cupsLangPuts(stderr
, _(" --not expression Unary NOT of expression."));
2774 _cupsLangPuts(stderr
, _(" --false Always false."));
2775 _cupsLangPuts(stderr
, _(" --true Always true."));
2776 _cupsLangPuts(stderr
, _(" expression expression Logical AND."));
2777 _cupsLangPuts(stderr
, _(" expression --and expression\n"
2779 _cupsLangPuts(stderr
, _(" expression --or expression\n"
2781 _cupsLangPuts(stderr
, "");
2782 _cupsLangPuts(stderr
, _("Substitutions:"));
2783 _cupsLangPuts(stderr
, _(" {} URI"));
2784 _cupsLangPuts(stderr
, _(" {service_domain} Domain name"));
2785 _cupsLangPuts(stderr
, _(" {service_hostname} Fully-qualified domain name"));
2786 _cupsLangPuts(stderr
, _(" {service_name} Service instance name"));
2787 _cupsLangPuts(stderr
, _(" {service_port} Port number"));
2788 _cupsLangPuts(stderr
, _(" {service_regtype} DNS-SD registration type"));
2789 _cupsLangPuts(stderr
, _(" {service_scheme} URI scheme"));
2790 _cupsLangPuts(stderr
, _(" {service_uri} URI"));
2791 _cupsLangPuts(stderr
, _(" {txt_*} Value of TXT record key"));
2792 _cupsLangPuts(stderr
, "");
2793 _cupsLangPuts(stderr
, _("Environment Variables:"));
2794 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_DOMAIN Domain name"));
2795 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_HOSTNAME\n"
2796 " Fully-qualified domain name"));
2797 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_NAME Service instance name"));
2798 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_PORT Port number"));
2799 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_REGTYPE DNS-SD registration type"));
2800 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_SCHEME URI scheme"));
2801 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_URI URI"));
2802 _cupsLangPuts(stderr
, _(" IPPFIND_TXT_* Value of TXT record key"));
2804 exit(IPPFIND_EXIT_TRUE
);
2809 * 'show_version()' - Show program version.
2815 _cupsLangPuts(stderr
, CUPS_SVERSION
);
2817 exit(IPPFIND_EXIT_TRUE
);