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>
52 #elif defined(HAVE_AVAHI)
53 # include <avahi-client/client.h>
54 # include <avahi-client/lookup.h>
55 # include <avahi-common/simple-watch.h>
56 # include <avahi-common/domain.h>
57 # include <avahi-common/error.h>
58 # include <avahi-common/malloc.h>
59 # define kDNSServiceMaxDomainName AVAHI_DOMAIN_NAME_MAX
60 #endif /* HAVE_DNSSD */
62 extern char **environ
; /* Process environment variables */
69 typedef enum ippfind_exit_e
/* Exit codes */
71 IPPFIND_EXIT_TRUE
= 0, /* OK and result is true */
72 IPPFIND_EXIT_FALSE
, /* OK but result is false*/
73 IPPFIND_EXIT_BONJOUR
, /* Browse/resolve failure */
74 IPPFIND_EXIT_SYNTAX
, /* Bad option or syntax error */
75 IPPFIND_EXIT_MEMORY
/* Out of memory */
78 typedef enum ippfind_op_e
/* Operations for expressions */
80 /* "Evaluation" operations */
81 IPPFIND_OP_NONE
, /* No operation */
82 IPPFIND_OP_AND
, /* Logical AND of all children */
83 IPPFIND_OP_OR
, /* Logical OR of all children */
84 IPPFIND_OP_TRUE
, /* Always true */
85 IPPFIND_OP_FALSE
, /* Always false */
86 IPPFIND_OP_IS_LOCAL
, /* Is a local service */
87 IPPFIND_OP_IS_REMOTE
, /* Is a remote service */
88 IPPFIND_OP_DOMAIN_REGEX
, /* Domain matches regular expression */
89 IPPFIND_OP_NAME_REGEX
, /* Name matches regular expression */
90 IPPFIND_OP_HOST_REGEX
, /* Hostname matches regular expression */
91 IPPFIND_OP_PORT_RANGE
, /* Port matches range */
92 IPPFIND_OP_PATH_REGEX
, /* Path matches regular expression */
93 IPPFIND_OP_TXT_EXISTS
, /* TXT record key exists */
94 IPPFIND_OP_TXT_REGEX
, /* TXT record key matches regular expression */
95 IPPFIND_OP_URI_REGEX
, /* URI matches regular expression */
97 /* "Output" operations */
98 IPPFIND_OP_EXEC
, /* Execute when true */
99 IPPFIND_OP_LIST
, /* List when true */
100 IPPFIND_OP_PRINT_NAME
, /* Print URI when true */
101 IPPFIND_OP_PRINT_URI
, /* Print name when true */
102 IPPFIND_OP_QUIET
/* No output when true */
105 typedef struct ippfind_expr_s
/* Expression */
107 struct ippfind_expr_s
108 *prev
, /* Previous expression */
109 *next
, /* Next expression */
110 *parent
, /* Parent expressions */
111 *child
; /* Child expressions */
112 ippfind_op_t op
; /* Operation code (see above) */
113 int invert
; /* Invert the result */
114 char *key
; /* TXT record key */
115 regex_t re
; /* Regular expression for matching */
116 int range
[2]; /* Port number range */
117 int num_args
; /* Number of arguments for exec */
118 char **args
; /* Arguments for exec */
121 typedef struct ippfind_srv_s
/* Service information */
124 DNSServiceRef ref
; /* Service reference for query */
125 #elif defined(HAVE_AVAHI)
126 AvahiServiceResolver
*ref
; /* Resolver */
127 #endif /* HAVE_DNSSD */
128 char *name
, /* Service name */
129 *domain
, /* Domain name */
130 *regtype
, /* Registration type */
131 *fullName
, /* Full name */
132 *host
, /* Hostname */
133 *resource
, /* Resource path */
135 int num_txt
; /* Number of TXT record keys */
136 cups_option_t
*txt
; /* TXT record keys */
137 int port
, /* Port number */
138 is_local
, /* Is a local service? */
139 is_processed
, /* Did we process the service? */
140 is_resolved
; /* Got the resolve data? */
149 static DNSServiceRef dnssd_ref
; /* Master service reference */
150 #elif defined(HAVE_AVAHI)
151 static AvahiClient
*avahi_client
= NULL
;/* Client information */
152 static int avahi_got_data
= 0; /* Got data from poll? */
153 static AvahiSimplePoll
*avahi_poll
= NULL
;
154 /* Poll information */
155 #endif /* HAVE_DNSSD */
157 static int address_family
= AF_UNSPEC
;
158 /* Address family for LIST */
159 static int bonjour_error
= 0; /* Error browsing/resolving? */
160 static double bonjour_timeout
= 1.0; /* Timeout in seconds */
161 static int ipp_version
= 20; /* IPP version for LIST */
169 static void browse_callback(DNSServiceRef sdRef
,
170 DNSServiceFlags flags
,
171 uint32_t interfaceIndex
,
172 DNSServiceErrorType errorCode
,
173 const char *serviceName
,
175 const char *replyDomain
, void *context
)
176 __attribute__((nonnull(1,5,6,7,8)));
177 static void browse_local_callback(DNSServiceRef sdRef
,
178 DNSServiceFlags flags
,
179 uint32_t interfaceIndex
,
180 DNSServiceErrorType errorCode
,
181 const char *serviceName
,
183 const char *replyDomain
,
185 __attribute__((nonnull(1,5,6,7,8)));
186 #elif defined(HAVE_AVAHI)
187 static void browse_callback(AvahiServiceBrowser
*browser
,
188 AvahiIfIndex interface
,
189 AvahiProtocol protocol
,
190 AvahiBrowserEvent event
,
191 const char *serviceName
,
193 const char *replyDomain
,
194 AvahiLookupResultFlags flags
,
196 static void client_callback(AvahiClient
*client
,
197 AvahiClientState state
,
199 #endif /* HAVE_AVAHI */
201 static int compare_services(ippfind_srv_t
*a
, ippfind_srv_t
*b
);
202 static const char *dnssd_error_string(int error
);
203 static int eval_expr(ippfind_srv_t
*service
,
204 ippfind_expr_t
*expressions
);
205 static int exec_program(ippfind_srv_t
*service
, int num_args
,
207 static ippfind_srv_t
*get_service(cups_array_t
*services
,
208 const char *serviceName
,
210 const char *replyDomain
)
211 __attribute__((nonnull(1,2,3,4)));
212 static double get_time(void);
213 static int list_service(ippfind_srv_t
*service
);
214 static ippfind_expr_t
*new_expr(ippfind_op_t op
, int invert
,
215 const char *value
, const char *regex
,
218 static void resolve_callback(DNSServiceRef sdRef
,
219 DNSServiceFlags flags
,
220 uint32_t interfaceIndex
,
221 DNSServiceErrorType errorCode
,
222 const char *fullName
,
223 const char *hostTarget
, uint16_t port
,
225 const unsigned char *txtRecord
,
227 __attribute__((nonnull(1,5,6,9, 10)));
228 #elif defined(HAVE_AVAHI)
229 static int poll_callback(struct pollfd
*pollfds
,
230 unsigned int num_pollfds
, int timeout
,
232 static void resolve_callback(AvahiServiceResolver
*res
,
233 AvahiIfIndex interface
,
234 AvahiProtocol protocol
,
235 AvahiBrowserEvent event
,
236 const char *serviceName
,
238 const char *replyDomain
,
239 const char *host_name
,
241 AvahiStringList
*txt
,
242 AvahiLookupResultFlags flags
,
244 #endif /* HAVE_DNSSD */
245 static void set_service_uri(ippfind_srv_t
*service
);
246 static void show_usage(void) __attribute__((noreturn
));
247 static void show_version(void) __attribute__((noreturn
));
251 * 'main()' - Browse for printers.
254 int /* O - Exit status */
255 main(int argc
, /* I - Number of command-line args */
256 char *argv
[]) /* I - Command-line arguments */
258 int i
, /* Looping var */
259 have_output
= 0,/* Have output expression */
260 status
= IPPFIND_EXIT_TRUE
;
262 const char *opt
, /* Option character */
263 *search
; /* Current browse/resolve string */
264 cups_array_t
*searches
; /* Things to browse/resolve */
265 cups_array_t
*services
; /* Service array */
266 ippfind_srv_t
*service
; /* Current service */
267 ippfind_expr_t
*expressions
= NULL
,
268 /* Expression tree */
269 *temp
= NULL
, /* New expression */
270 *parent
= NULL
, /* Parent expression */
271 *current
= NULL
,/* Current expression */
272 *parens
[100]; /* Markers for parenthesis */
273 int num_parens
= 0; /* Number of parenthesis */
274 ippfind_op_t logic
= IPPFIND_OP_AND
;
275 /* Logic for next expression */
276 int invert
= 0; /* Invert expression? */
277 int err
; /* DNS-SD error */
279 fd_set sinput
; /* Input set for select() */
280 struct timeval stimeout
; /* Timeout for select() */
281 #endif /* HAVE_DNSSD */
282 double endtime
; /* End time */
283 static const char * const ops
[] = /* Node operation names */
309 * Initialize the locale...
312 _cupsSetLocale(argv
);
315 * Create arrays to track services and things we want to browse/resolve...
318 searches
= cupsArrayNew(NULL
, NULL
);
319 services
= cupsArrayNew((cups_array_func_t
)compare_services
, NULL
);
322 * Parse command-line...
325 for (i
= 1; i
< argc
; i
++)
327 if (argv
[i
][0] == '-')
329 if (argv
[i
][1] == '-')
332 * Parse --option options...
335 if (!strcmp(argv
[i
], "--and"))
337 if (logic
== IPPFIND_OP_OR
)
339 _cupsLangPuts(stderr
, _("ippfind: Cannot use --and after --or."));
345 _cupsLangPuts(stderr
,
346 _("ippfind: Missing expression before \"--and\"."));
352 else if (!strcmp(argv
[i
], "--domain"))
357 _cupsLangPrintf(stderr
,
358 _("ippfind: Missing regular expression after %s."),
363 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
, argv
[i
],
365 return (IPPFIND_EXIT_MEMORY
);
367 else if (!strcmp(argv
[i
], "--exec"))
372 _cupsLangPrintf(stderr
, _("ippfind: Expected program after %s."),
377 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
379 return (IPPFIND_EXIT_MEMORY
);
382 if (!strcmp(argv
[i
], ";"))
389 _cupsLangPrintf(stderr
, _("ippfind: Expected semi-colon after %s."),
396 else if (!strcmp(argv
[i
], "--false"))
398 if ((temp
= new_expr(IPPFIND_OP_FALSE
, invert
, NULL
, NULL
,
400 return (IPPFIND_EXIT_MEMORY
);
402 else if (!strcmp(argv
[i
], "--help"))
406 else if (!strcmp(argv
[i
], "--host"))
411 _cupsLangPrintf(stderr
,
412 _("ippfind: Missing regular expression after %s."),
417 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
, argv
[i
],
419 return (IPPFIND_EXIT_MEMORY
);
421 else if (!strcmp(argv
[i
], "--ls"))
423 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
425 return (IPPFIND_EXIT_MEMORY
);
429 else if (!strcmp(argv
[i
], "--local"))
431 if ((temp
= new_expr(IPPFIND_OP_IS_LOCAL
, invert
, NULL
, NULL
,
433 return (IPPFIND_EXIT_MEMORY
);
435 else if (!strcmp(argv
[i
], "--name"))
440 _cupsLangPrintf(stderr
,
441 _("ippfind: Missing regular expression after %s."),
446 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
, argv
[i
],
448 return (IPPFIND_EXIT_MEMORY
);
450 else if (!strcmp(argv
[i
], "--not"))
454 else if (!strcmp(argv
[i
], "--or"))
458 _cupsLangPuts(stderr
,
459 _("ippfind: Missing expression before \"--or\"."));
463 logic
= IPPFIND_OP_OR
;
465 if (parent
&& parent
->op
== IPPFIND_OP_OR
)
468 * Already setup to do "foo --or bar --or baz"...
473 else if (!current
->prev
&& parent
)
476 * Change parent node into an OR node...
479 parent
->op
= IPPFIND_OP_OR
;
482 else if (!current
->prev
)
485 * Need to group "current" in a new OR node...
488 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
490 return (IPPFIND_EXIT_MEMORY
);
492 temp
->parent
= parent
;
493 temp
->child
= current
;
494 current
->parent
= temp
;
497 parent
->child
= temp
;
507 * Need to group previous expressions in an AND node, and then
508 * put that in an OR node...
511 if ((temp
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
513 return (IPPFIND_EXIT_MEMORY
);
515 while (current
->prev
)
517 current
->parent
= temp
;
518 current
= current
->prev
;
521 current
->parent
= temp
;
522 temp
->child
= current
;
525 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
527 return (IPPFIND_EXIT_MEMORY
);
529 temp
->parent
= parent
;
530 current
->parent
= temp
;
533 parent
->child
= temp
;
541 else if (!strcmp(argv
[i
], "--path"))
546 _cupsLangPrintf(stderr
,
547 _("ippfind: Missing regular expression after %s."),
552 if ((temp
= new_expr(IPPFIND_OP_PATH_REGEX
, invert
, NULL
, argv
[i
],
554 return (IPPFIND_EXIT_MEMORY
);
556 else if (!strcmp(argv
[i
], "--port"))
561 _cupsLangPrintf(stderr
,
562 _("ippfind: Expected port range after %s."),
567 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
], NULL
,
569 return (IPPFIND_EXIT_MEMORY
);
571 else if (!strcmp(argv
[i
], "--print"))
573 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
575 return (IPPFIND_EXIT_MEMORY
);
579 else if (!strcmp(argv
[i
], "--print-name"))
581 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
583 return (IPPFIND_EXIT_MEMORY
);
587 else if (!strcmp(argv
[i
], "--quiet"))
589 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
591 return (IPPFIND_EXIT_MEMORY
);
595 else if (!strcmp(argv
[i
], "--remote"))
597 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
599 return (IPPFIND_EXIT_MEMORY
);
601 else if (!strcmp(argv
[i
], "--true"))
603 if ((temp
= new_expr(IPPFIND_OP_TRUE
, invert
, NULL
, argv
[i
],
605 return (IPPFIND_EXIT_MEMORY
);
607 else if (!strcmp(argv
[i
], "--txt"))
612 _cupsLangPrintf(stderr
, _("ippfind: Expected key name after %s."),
617 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
], NULL
,
619 return (IPPFIND_EXIT_MEMORY
);
621 else if (!strncmp(argv
[i
], "--txt-", 5))
623 const char *key
= argv
[i
] + 5;/* TXT key */
628 _cupsLangPrintf(stderr
,
629 _("ippfind: Missing regular expression after %s."),
634 if ((temp
= new_expr(IPPFIND_OP_TXT_REGEX
, invert
, key
, argv
[i
],
636 return (IPPFIND_EXIT_MEMORY
);
638 else if (!strcmp(argv
[i
], "--uri"))
643 _cupsLangPrintf(stderr
,
644 _("ippfind: Missing regular expression after %s."),
649 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
, argv
[i
],
651 return (IPPFIND_EXIT_MEMORY
);
653 else if (!strcmp(argv
[i
], "--version"))
659 _cupsLangPrintf(stderr
, _("%s: Unknown option \"%s\"."),
667 * Add new expression...
670 if (logic
== IPPFIND_OP_AND
&&
671 current
&& current
->prev
&&
672 parent
&& parent
->op
!= IPPFIND_OP_AND
)
675 * Need to re-group "current" in a new AND node...
678 ippfind_expr_t
*tempand
; /* Temporary AND node */
680 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
682 return (IPPFIND_EXIT_MEMORY
);
685 * Replace "current" with new AND node at the end of this list...
688 current
->prev
->next
= tempand
;
689 tempand
->prev
= current
->prev
;
690 tempand
->parent
= parent
;
693 * Add "current to the new AND node...
696 tempand
->child
= current
;
697 current
->parent
= tempand
;
698 current
->prev
= NULL
;
703 * Add the new node at current level...
706 temp
->parent
= parent
;
707 temp
->prev
= current
;
710 current
->next
= temp
;
712 parent
->child
= temp
;
718 logic
= IPPFIND_OP_AND
;
728 for (opt
= argv
[i
] + 1; *opt
; opt
++)
733 address_family
= AF_INET
;
737 address_family
= AF_INET6
;
744 _cupsLangPrintf(stderr
,
745 _("ippfind: Expected port range after %s."),
750 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
],
751 NULL
, NULL
)) == NULL
)
752 return (IPPFIND_EXIT_MEMORY
);
759 _cupsLangPrintf(stderr
,
760 _("%s: Missing timeout for \"-T\"."),
765 bonjour_timeout
= atof(argv
[i
]);
772 _cupsLangPrintf(stderr
,
773 _("%s: Missing version for \"-V\"."),
779 if (!strcmp(argv
[i
], "1.1"))
781 else if (!strcmp(argv
[i
], "2.0"))
783 else if (!strcmp(argv
[i
], "2.1"))
785 else if (!strcmp(argv
[i
], "2.2"))
789 _cupsLangPrintf(stderr
, _("%s: Bad version %s for \"-V\"."),
799 _cupsLangPrintf(stderr
,
800 _("ippfind: Missing regular expression after "
805 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
,
806 argv
[i
], NULL
)) == NULL
)
807 return (IPPFIND_EXIT_MEMORY
);
814 _cupsLangPrintf(stderr
,
815 _("ippfind: Missing regular expression after "
820 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
,
821 argv
[i
], NULL
)) == NULL
)
822 return (IPPFIND_EXIT_MEMORY
);
826 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
828 return (IPPFIND_EXIT_MEMORY
);
837 _cupsLangPrintf(stderr
,
838 _("ippfind: Missing regular expression after "
843 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
,
844 argv
[i
], NULL
)) == NULL
)
845 return (IPPFIND_EXIT_MEMORY
);
849 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
851 return (IPPFIND_EXIT_MEMORY
);
857 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
859 return (IPPFIND_EXIT_MEMORY
);
865 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
867 return (IPPFIND_EXIT_MEMORY
);
871 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
873 return (IPPFIND_EXIT_MEMORY
);
882 _cupsLangPrintf(stderr
,
883 _("ippfind: Missing key name after %s."),
888 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
],
889 NULL
, NULL
)) == NULL
)
890 return (IPPFIND_EXIT_MEMORY
);
897 _cupsLangPrintf(stderr
,
898 _("ippfind: Missing regular expression after "
903 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
,
904 argv
[i
], NULL
)) == NULL
)
905 return (IPPFIND_EXIT_MEMORY
);
912 _cupsLangPrintf(stderr
,
913 _("ippfind: Missing program after %s."),
918 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
920 return (IPPFIND_EXIT_MEMORY
);
923 if (!strcmp(argv
[i
], ";"))
930 _cupsLangPrintf(stderr
,
931 _("ippfind: Missing semi-colon after %s."),
940 _cupsLangPrintf(stderr
, _("%s: Unknown option \"-%c\"."),
949 * Add new expression...
952 if (logic
== IPPFIND_OP_AND
&&
953 current
&& current
->prev
&&
954 parent
&& parent
->op
!= IPPFIND_OP_AND
)
957 * Need to re-group "current" in a new AND node...
960 ippfind_expr_t
*tempand
; /* Temporary AND node */
962 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
964 return (IPPFIND_EXIT_MEMORY
);
967 * Replace "current" with new AND node at the end of this list...
970 current
->prev
->next
= tempand
;
971 tempand
->prev
= current
->prev
;
972 tempand
->parent
= parent
;
975 * Add "current to the new AND node...
978 tempand
->child
= current
;
979 current
->parent
= tempand
;
980 current
->prev
= NULL
;
985 * Add the new node at current level...
988 temp
->parent
= parent
;
989 temp
->prev
= current
;
992 current
->next
= temp
;
994 parent
->child
= temp
;
1000 logic
= IPPFIND_OP_AND
;
1006 else if (!strcmp(argv
[i
], "("))
1008 if (num_parens
>= 100)
1010 _cupsLangPuts(stderr
, _("ippfind: Too many parenthesis."));
1014 if ((temp
= new_expr(IPPFIND_OP_AND
, invert
, NULL
, NULL
, NULL
)) == NULL
)
1015 return (IPPFIND_EXIT_MEMORY
);
1017 parens
[num_parens
++] = temp
;
1021 temp
->parent
= current
->parent
;
1022 current
->next
= temp
;
1023 temp
->prev
= current
;
1031 logic
= IPPFIND_OP_AND
;
1033 else if (!strcmp(argv
[i
], ")"))
1035 if (num_parens
<= 0)
1037 _cupsLangPuts(stderr
, _("ippfind: Missing open parenthesis."));
1041 current
= parens
[--num_parens
];
1042 parent
= current
->parent
;
1044 logic
= IPPFIND_OP_AND
;
1046 else if (!strcmp(argv
[i
], "!"))
1053 * _regtype._tcp[,subtype][.domain]
1057 * service-name[._regtype._tcp[.domain]]
1060 cupsArrayAdd(searches
, argv
[i
]);
1066 _cupsLangPuts(stderr
, _("ippfind: Missing close parenthesis."));
1073 * Add an implicit --print-uri to the end...
1076 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, 0, NULL
, NULL
, NULL
)) == NULL
)
1077 return (IPPFIND_EXIT_MEMORY
);
1081 while (current
->parent
)
1082 current
= current
->parent
;
1084 current
->next
= temp
;
1085 temp
->prev
= current
;
1091 if (cupsArrayCount(searches
) == 0)
1094 * Add an implicit browse for IPP printers ("_ipp._tcp")...
1097 cupsArrayAdd(searches
, "_ipp._tcp");
1100 if (getenv("IPPFIND_DEBUG"))
1102 int indent
= 4; /* Indentation */
1104 puts("Expression tree:");
1105 current
= expressions
;
1109 * Print the current node...
1112 printf("%*s%s%s\n", indent
, "", current
->invert
? "!" : "",
1116 * Advance to the next node...
1121 current
= current
->child
;
1124 else if (current
->next
)
1125 current
= current
->next
;
1126 else if (current
->parent
)
1128 while (current
->parent
)
1131 current
= current
->parent
;
1136 current
= current
->next
;
1142 puts("\nSearch items:");
1143 for (search
= (const char *)cupsArrayFirst(searches
);
1145 search
= (const char *)cupsArrayNext(searches
))
1146 printf(" %s\n", search
);
1150 * Start up browsing/resolving...
1154 if ((err
= DNSServiceCreateConnection(&dnssd_ref
)) != kDNSServiceErr_NoError
)
1156 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1157 dnssd_error_string(err
));
1158 return (IPPFIND_EXIT_BONJOUR
);
1161 #elif defined(HAVE_AVAHI)
1162 if ((avahi_poll
= avahi_simple_poll_new()) == NULL
)
1164 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1166 return (IPPFIND_EXIT_BONJOUR
);
1169 avahi_simple_poll_set_func(avahi_poll
, poll_callback
, NULL
);
1171 avahi_client
= avahi_client_new(avahi_simple_poll_get(avahi_poll
),
1172 0, client_callback
, avahi_poll
, &err
);
1175 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1176 dnssd_error_string(err
));
1177 return (IPPFIND_EXIT_BONJOUR
);
1179 #endif /* HAVE_DNSSD */
1181 for (search
= (const char *)cupsArrayFirst(searches
);
1183 search
= (const char *)cupsArrayNext(searches
))
1185 char buf
[1024], /* Full name string */
1186 *name
= NULL
, /* Service instance name */
1187 *regtype
, /* Registration type */
1188 *domain
; /* Domain, if any */
1190 strlcpy(buf
, search
, sizeof(buf
));
1195 else if ((regtype
= strstr(buf
, "._")) != NULL
)
1203 regtype
= "_ipp._tcp";
1206 for (domain
= regtype
; *domain
; domain
++)
1207 if (*domain
== '.' && domain
[1] != '_')
1219 * Resolve the given service instance name, regtype, and domain...
1225 service
= get_service(services
, name
, regtype
, domain
);
1228 service
->ref
= dnssd_ref
;
1229 err
= DNSServiceResolve(&(service
->ref
),
1230 kDNSServiceFlagsShareConnection
, 0, name
,
1231 regtype
, domain
, resolve_callback
,
1234 #elif defined(HAVE_AVAHI)
1235 service
->ref
= avahi_service_resolver_new(avahi_client
, AVAHI_IF_UNSPEC
,
1236 AVAHI_PROTO_UNSPEC
, name
,
1238 AVAHI_PROTO_UNSPEC
, 0,
1239 resolve_callback
, service
);
1243 err
= avahi_client_get_error(avahi_client
);
1244 #endif /* HAVE_DNSSD */
1249 * Browse for services of the given type...
1253 DNSServiceRef ref
; /* Browse reference */
1256 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
, 0, regtype
,
1257 domain
, browse_callback
, services
);
1262 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
,
1263 kDNSServiceInterfaceIndexLocalOnly
, regtype
,
1264 domain
, browse_local_callback
, services
);
1267 #elif defined(HAVE_AVAHI)
1268 if (avahi_service_browser_new(avahi_client
, AVAHI_IF_UNSPEC
,
1269 AVAHI_PROTO_UNSPEC
, regtype
, domain
, 0,
1270 browse_callback
, services
))
1273 err
= avahi_client_get_errno(avahi_client
);
1274 #endif /* HAVE_DNSSD */
1279 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
1280 dnssd_error_string(err
));
1283 printf("name=\"%s\"\n", name
);
1285 printf("regtype=\"%s\"\n", regtype
);
1288 printf("domain=\"%s\"\n", domain
);
1290 return (IPPFIND_EXIT_BONJOUR
);
1295 * Process browse/resolve requests...
1298 if (bonjour_timeout
> 1.0)
1299 endtime
= get_time() + bonjour_timeout
;
1301 endtime
= get_time() + 300.0;
1303 while (get_time() < endtime
)
1305 int process
= 0; /* Process services? */
1308 int fd
= DNSServiceRefSockFD(dnssd_ref
);
1309 /* File descriptor for DNS-SD */
1312 FD_SET(fd
, &sinput
);
1314 stimeout
.tv_sec
= 0;
1315 stimeout
.tv_usec
= 500000;
1317 if (select(fd
+ 1, &sinput
, NULL
, NULL
, &stimeout
) < 0)
1320 if (FD_ISSET(fd
, &sinput
))
1323 * Process responses...
1326 DNSServiceProcessResult(dnssd_ref
);
1331 * Time to process services...
1337 #elif defined(HAVE_AVAHI)
1340 if (avahi_simple_poll_iterate(avahi_poll
, 500) > 0)
1343 * We've been told to exit the loop. Perhaps the connection to
1347 return (IPPFIND_EXIT_BONJOUR
);
1350 if (!avahi_got_data
)
1353 * Time to process services...
1358 #endif /* HAVE_DNSSD */
1363 * Process any services that we have found...
1366 int active
= 0, /* Number of active resolves */
1367 resolved
= 0, /* Number of resolved services */
1368 processed
= 0; /* Number of processed services */
1370 for (service
= (ippfind_srv_t
*)cupsArrayFirst(services
);
1372 service
= (ippfind_srv_t
*)cupsArrayNext(services
))
1374 if (service
->is_processed
)
1377 if (service
->is_resolved
)
1380 if (!service
->ref
&& !service
->is_resolved
)
1383 * Found a service, now resolve it (but limit to 50 active resolves...)
1389 service
->ref
= dnssd_ref
;
1390 err
= DNSServiceResolve(&(service
->ref
),
1391 kDNSServiceFlagsShareConnection
, 0,
1392 service
->name
, service
->regtype
,
1393 service
->domain
, resolve_callback
,
1396 #elif defined(HAVE_AVAHI)
1397 service
->ref
= avahi_service_resolver_new(avahi_client
,
1403 AVAHI_PROTO_UNSPEC
, 0,
1409 err
= avahi_client_get_errno(avahi_client
);
1410 #endif /* HAVE_DNSSD */
1414 _cupsLangPrintf(stderr
,
1415 _("ippfind: Unable to browse or resolve: %s"),
1416 dnssd_error_string(err
));
1417 return (IPPFIND_EXIT_BONJOUR
);
1423 else if (service
->is_resolved
&& !service
->is_processed
)
1426 * Resolved, not process this service against the expressions...
1432 DNSServiceRefDeallocate(service
->ref
);
1434 avahi_record_browser_free(service
->ref
);
1435 #endif /* HAVE_DNSSD */
1437 service
->ref
= NULL
;
1440 if (!eval_expr(service
, expressions
))
1441 status
= IPPFIND_EXIT_FALSE
;
1443 service
->is_processed
= 1;
1445 else if (service
->ref
)
1450 * If we have processed all services we have discovered, then we are done.
1453 if (processed
== cupsArrayCount(services
) && bonjour_timeout
<= 1.0)
1459 return (IPPFIND_EXIT_BONJOUR
);
1467 * 'browse_callback()' - Browse devices.
1472 DNSServiceRef sdRef
, /* I - Service reference */
1473 DNSServiceFlags flags
, /* I - Option flags */
1474 uint32_t interfaceIndex
, /* I - Interface number */
1475 DNSServiceErrorType errorCode
, /* I - Error, if any */
1476 const char *serviceName
, /* I - Name of service/device */
1477 const char *regtype
, /* I - Type of service */
1478 const char *replyDomain
, /* I - Service domain */
1479 void *context
) /* I - Services array */
1482 * Only process "add" data...
1485 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1492 get_service((cups_array_t
*)context
, serviceName
, regtype
, replyDomain
);
1497 * 'browse_local_callback()' - Browse local devices.
1501 browse_local_callback(
1502 DNSServiceRef sdRef
, /* I - Service reference */
1503 DNSServiceFlags flags
, /* I - Option flags */
1504 uint32_t interfaceIndex
, /* I - Interface number */
1505 DNSServiceErrorType errorCode
, /* I - Error, if any */
1506 const char *serviceName
, /* I - Name of service/device */
1507 const char *regtype
, /* I - Type of service */
1508 const char *replyDomain
, /* I - Service domain */
1509 void *context
) /* I - Services array */
1511 ippfind_srv_t
*service
; /* Service */
1515 * Only process "add" data...
1518 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1525 service
= get_service((cups_array_t
*)context
, serviceName
, regtype
,
1527 service
->is_local
= 1;
1529 #endif /* HAVE_DNSSD */
1534 * 'browse_callback()' - Browse devices.
1539 AvahiServiceBrowser
*browser
, /* I - Browser */
1540 AvahiIfIndex interface
, /* I - Interface index (unused) */
1541 AvahiProtocol protocol
, /* I - Network protocol (unused) */
1542 AvahiBrowserEvent event
, /* I - What happened */
1543 const char *name
, /* I - Service name */
1544 const char *type
, /* I - Registration type */
1545 const char *domain
, /* I - Domain */
1546 AvahiLookupResultFlags flags
, /* I - Flags */
1547 void *context
) /* I - Services array */
1549 AvahiClient
*client
= avahi_service_browser_get_client(browser
);
1550 /* Client information */
1551 ippfind_srv_t
*service
; /* Service information */
1560 case AVAHI_BROWSER_FAILURE
:
1561 fprintf(stderr
, "DEBUG: browse_callback: %s\n",
1562 avahi_strerror(avahi_client_errno(client
)));
1564 avahi_simple_poll_quit(avahi_poll
);
1567 case AVAHI_BROWSER_NEW
:
1569 * This object is new on the network. Create a device entry for it if
1570 * it doesn't yet exist.
1573 service
= get_service((cups_array_t
*)context
, name
, type
, domain
);
1575 if (flags
& AVAHI_LOOKUP_RESULT_LOCAL
)
1576 service
->is_local
= 1;
1579 case AVAHI_BROWSER_REMOVE
:
1580 case AVAHI_BROWSER_ALL_FOR_NOW
:
1581 case AVAHI_BROWSER_CACHE_EXHAUSTED
:
1588 * 'client_callback()' - Avahi client callback function.
1593 AvahiClient
*client
, /* I - Client information (unused) */
1594 AvahiClientState state
, /* I - Current state */
1595 void *context
) /* I - User data (unused) */
1601 * If the connection drops, quit.
1604 if (state
== AVAHI_CLIENT_FAILURE
)
1606 fputs("DEBUG: Avahi connection failed.\n", stderr
);
1608 avahi_simple_poll_quit(avahi_poll
);
1611 #endif /* HAVE_AVAHI */
1615 * 'compare_services()' - Compare two devices.
1618 static int /* O - Result of comparison */
1619 compare_services(ippfind_srv_t
*a
, /* I - First device */
1620 ippfind_srv_t
*b
) /* I - Second device */
1622 return (strcmp(a
->name
, b
->name
));
1627 * 'dnssd_error_string()' - Return an error string for an error code.
1630 static const char * /* O - Error message */
1631 dnssd_error_string(int error
) /* I - Error number */
1636 case kDNSServiceErr_NoError
:
1640 case kDNSServiceErr_Unknown
:
1641 return ("Unknown error.");
1643 case kDNSServiceErr_NoSuchName
:
1644 return ("Service not found.");
1646 case kDNSServiceErr_NoMemory
:
1647 return ("Out of memory.");
1649 case kDNSServiceErr_BadParam
:
1650 return ("Bad parameter.");
1652 case kDNSServiceErr_BadReference
:
1653 return ("Bad service reference.");
1655 case kDNSServiceErr_BadState
:
1656 return ("Bad state.");
1658 case kDNSServiceErr_BadFlags
:
1659 return ("Bad flags.");
1661 case kDNSServiceErr_Unsupported
:
1662 return ("Unsupported.");
1664 case kDNSServiceErr_NotInitialized
:
1665 return ("Not initialized.");
1667 case kDNSServiceErr_AlreadyRegistered
:
1668 return ("Already registered.");
1670 case kDNSServiceErr_NameConflict
:
1671 return ("Name conflict.");
1673 case kDNSServiceErr_Invalid
:
1674 return ("Invalid name.");
1676 case kDNSServiceErr_Firewall
:
1677 return ("Firewall prevents registration.");
1679 case kDNSServiceErr_Incompatible
:
1680 return ("Client library incompatible.");
1682 case kDNSServiceErr_BadInterfaceIndex
:
1683 return ("Bad interface index.");
1685 case kDNSServiceErr_Refused
:
1686 return ("Server prevents registration.");
1688 case kDNSServiceErr_NoSuchRecord
:
1689 return ("Record not found.");
1691 case kDNSServiceErr_NoAuth
:
1692 return ("Authentication required.");
1694 case kDNSServiceErr_NoSuchKey
:
1695 return ("Encryption key not found.");
1697 case kDNSServiceErr_NATTraversal
:
1698 return ("Unable to traverse NAT boundary.");
1700 case kDNSServiceErr_DoubleNAT
:
1701 return ("Unable to traverse double-NAT boundary.");
1703 case kDNSServiceErr_BadTime
:
1704 return ("Bad system time.");
1706 case kDNSServiceErr_BadSig
:
1707 return ("Bad signature.");
1709 case kDNSServiceErr_BadKey
:
1710 return ("Bad encryption key.");
1712 case kDNSServiceErr_Transient
:
1713 return ("Transient error occurred - please try again.");
1715 case kDNSServiceErr_ServiceNotRunning
:
1716 return ("Server not running.");
1718 case kDNSServiceErr_NATPortMappingUnsupported
:
1719 return ("NAT doesn't support NAT-PMP or UPnP.");
1721 case kDNSServiceErr_NATPortMappingDisabled
:
1722 return ("NAT supports NAT-PNP or UPnP but it is disabled.");
1724 case kDNSServiceErr_NoRouter
:
1725 return ("No Internet/default router configured.");
1727 case kDNSServiceErr_PollingMode
:
1728 return ("Service polling mode error.");
1730 case kDNSServiceErr_Timeout
:
1731 return ("Service timeout.");
1734 # elif defined(HAVE_AVAHI)
1735 return (avahi_strerror(error
));
1736 # endif /* HAVE_DNSSD */
1741 * 'eval_expr()' - Evaluate the expressions against the specified service.
1743 * Returns 1 for true and 0 for false.
1746 static int /* O - Result of evaluation */
1747 eval_expr(ippfind_srv_t
*service
, /* I - Service */
1748 ippfind_expr_t
*expressions
) /* I - Expressions */
1750 int logic
, /* Logical operation */
1751 result
; /* Result of current expression */
1752 ippfind_expr_t
*expression
; /* Current expression */
1753 const char *val
; /* TXT value */
1756 * Loop through the expressions...
1759 if (expressions
&& expressions
->parent
)
1760 logic
= expressions
->parent
->op
;
1762 logic
= IPPFIND_OP_AND
;
1764 for (expression
= expressions
; expression
; expression
= expression
->next
)
1766 switch (expression
->op
)
1769 case IPPFIND_OP_AND
:
1770 case IPPFIND_OP_OR
:
1771 if (expression
->child
)
1772 result
= eval_expr(service
, expression
->child
);
1774 result
= expression
->op
== IPPFIND_OP_AND
;
1776 case IPPFIND_OP_TRUE
:
1779 case IPPFIND_OP_FALSE
:
1782 case IPPFIND_OP_IS_LOCAL
:
1783 result
= service
->is_local
;
1785 case IPPFIND_OP_IS_REMOTE
:
1786 result
= !service
->is_local
;
1788 case IPPFIND_OP_DOMAIN_REGEX
:
1789 result
= !regexec(&(expression
->re
), service
->domain
, 0, NULL
, 0);
1791 case IPPFIND_OP_NAME_REGEX
:
1792 result
= !regexec(&(expression
->re
), service
->name
, 0, NULL
, 0);
1794 case IPPFIND_OP_HOST_REGEX
:
1795 result
= !regexec(&(expression
->re
), service
->host
, 0, NULL
, 0);
1797 case IPPFIND_OP_PORT_RANGE
:
1798 result
= service
->port
>= expression
->range
[0] &&
1799 service
->port
<= expression
->range
[1];
1801 case IPPFIND_OP_PATH_REGEX
:
1802 result
= !regexec(&(expression
->re
), service
->resource
, 0, NULL
, 0);
1804 case IPPFIND_OP_TXT_EXISTS
:
1805 result
= cupsGetOption(expression
->key
, service
->num_txt
,
1806 service
->txt
) != NULL
;
1808 case IPPFIND_OP_TXT_REGEX
:
1809 val
= cupsGetOption(expression
->key
, service
->num_txt
,
1812 result
= !regexec(&(expression
->re
), val
, 0, NULL
, 0);
1816 case IPPFIND_OP_URI_REGEX
:
1817 result
= !regexec(&(expression
->re
), service
->uri
, 0, NULL
, 0);
1819 case IPPFIND_OP_EXEC
:
1820 result
= exec_program(service
, expression
->num_args
,
1823 case IPPFIND_OP_LIST
:
1824 result
= list_service(service
);
1826 case IPPFIND_OP_PRINT_NAME
:
1827 _cupsLangPuts(stdout
, service
->name
);
1830 case IPPFIND_OP_PRINT_URI
:
1831 _cupsLangPuts(stdout
, service
->uri
);
1834 case IPPFIND_OP_QUIET
:
1839 if (expression
->invert
)
1842 if (logic
== IPPFIND_OP_AND
&& !result
)
1844 else if (logic
== IPPFIND_OP_OR
&& result
)
1848 return (logic
== IPPFIND_OP_AND
);
1853 * 'exec_program()' - Execute a program for a service.
1856 static int /* O - 1 if program terminated
1857 successfully, 0 otherwise. */
1858 exec_program(ippfind_srv_t
*service
, /* I - Service */
1859 int num_args
, /* I - Number of command-line args */
1860 char **args
) /* I - Command-line arguments */
1862 char **myargv
, /* Command-line arguments */
1863 **myenvp
, /* Environment variables */
1864 *ptr
, /* Pointer into variable */
1865 domain
[1024], /* IPPFIND_SERVICE_DOMAIN */
1866 hostname
[1024], /* IPPFIND_SERVICE_HOSTNAME */
1867 name
[256], /* IPPFIND_SERVICE_NAME */
1868 port
[32], /* IPPFIND_SERVICE_PORT */
1869 regtype
[256], /* IPPFIND_SERVICE_REGTYPE */
1870 scheme
[128], /* IPPFIND_SERVICE_SCHEME */
1871 uri
[1024], /* IPPFIND_SERVICE_URI */
1872 txt
[100][256]; /* IPPFIND_TXT_foo */
1873 int i
, /* Looping var */
1874 myenvc
, /* Number of environment variables */
1875 status
; /* Exit status of program */
1877 char program
[1024]; /* Program to execute */
1878 int pid
; /* Process ID */
1883 * Environment variables...
1886 snprintf(domain
, sizeof(domain
), "IPPFIND_SERVICE_DOMAIN=%s",
1888 snprintf(hostname
, sizeof(hostname
), "IPPFIND_SERVICE_HOSTNAME=%s",
1890 snprintf(name
, sizeof(name
), "IPPFIND_SERVICE_NAME=%s", service
->name
);
1891 snprintf(port
, sizeof(port
), "IPPFIND_SERVICE_PORT=%d", service
->port
);
1892 snprintf(regtype
, sizeof(regtype
), "IPPFIND_SERVICE_REGTYPE=%s",
1894 snprintf(scheme
, sizeof(scheme
), "IPPFIND_SERVICE_SCHEME=%s",
1895 !strncmp(service
->regtype
, "_http._tcp", 10) ? "http" :
1896 !strncmp(service
->regtype
, "_https._tcp", 11) ? "https" :
1897 !strncmp(service
->regtype
, "_ipp._tcp", 9) ? "ipp" :
1898 !strncmp(service
->regtype
, "_ipps._tcp", 10) ? "ipps" : "lpd");
1899 snprintf(uri
, sizeof(uri
), "IPPFIND_SERVICE_URI=%s", service
->uri
);
1900 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1902 snprintf(txt
[i
], sizeof(txt
[i
]), "IPPFIND_TXT_%s=%s", service
->txt
[i
].name
,
1903 service
->txt
[i
].value
);
1904 for (ptr
= txt
[i
] + 12; *ptr
&& *ptr
!= '='; ptr
++)
1905 *ptr
= _cups_toupper(*ptr
);
1908 for (i
= 0, myenvc
= 7 + service
->num_txt
; environ
[i
]; i
++)
1909 if (strncmp(environ
[i
], "IPPFIND_", 8))
1912 if ((myenvp
= calloc(sizeof(char *), myenvc
+ 1)) == NULL
)
1914 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1915 exit(IPPFIND_EXIT_MEMORY
);
1918 for (i
= 0, myenvc
= 0; environ
[i
]; i
++)
1919 if (strncmp(environ
[i
], "IPPFIND_", 8))
1920 myenvp
[myenvc
++] = environ
[i
];
1922 myenvp
[myenvc
++] = domain
;
1923 myenvp
[myenvc
++] = hostname
;
1924 myenvp
[myenvc
++] = name
;
1925 myenvp
[myenvc
++] = port
;
1926 myenvp
[myenvc
++] = regtype
;
1927 myenvp
[myenvc
++] = scheme
;
1928 myenvp
[myenvc
++] = uri
;
1930 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1931 myenvp
[myenvc
++] = txt
[i
];
1934 * Allocate and copy command-line arguments...
1937 if ((myargv
= calloc(sizeof(char *), num_args
+ 1)) == NULL
)
1939 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1940 exit(IPPFIND_EXIT_MEMORY
);
1943 for (i
= 0; i
< num_args
; i
++)
1945 if (strchr(args
[i
], '{'))
1947 char temp
[2048], /* Temporary string */
1948 *tptr
, /* Pointer into temporary string */
1949 keyword
[256], /* {keyword} */
1950 *kptr
; /* Pointer into keyword */
1952 for (ptr
= args
[i
], tptr
= temp
; *ptr
; ptr
++)
1957 * Do a {var} substitution...
1960 for (kptr
= keyword
, ptr
++; *ptr
&& *ptr
!= '}'; ptr
++)
1961 if (kptr
< (keyword
+ sizeof(keyword
) - 1))
1966 _cupsLangPuts(stderr
,
1967 _("ippfind: Missing close brace in substitution."));
1968 exit(IPPFIND_EXIT_SYNTAX
);
1972 if (!keyword
[0] || !strcmp(keyword
, "service_uri"))
1973 strlcpy(tptr
, service
->uri
, sizeof(temp
) - (tptr
- temp
));
1974 else if (!strcmp(keyword
, "service_domain"))
1975 strlcpy(tptr
, service
->domain
, sizeof(temp
) - (tptr
- temp
));
1976 else if (!strcmp(keyword
, "service_hostname"))
1977 strlcpy(tptr
, service
->host
, sizeof(temp
) - (tptr
- temp
));
1978 else if (!strcmp(keyword
, "service_name"))
1979 strlcpy(tptr
, service
->name
, sizeof(temp
) - (tptr
- temp
));
1980 else if (!strcmp(keyword
, "service_path"))
1981 strlcpy(tptr
, service
->resource
, sizeof(temp
) - (tptr
- temp
));
1982 else if (!strcmp(keyword
, "service_port"))
1983 strlcpy(tptr
, port
+ 20, sizeof(temp
) - (tptr
- temp
));
1984 else if (!strcmp(keyword
, "service_scheme"))
1985 strlcpy(tptr
, scheme
+ 22, sizeof(temp
) - (tptr
- temp
));
1986 else if (!strncmp(keyword
, "txt_", 4))
1988 if ((ptr
= (char *)cupsGetOption(keyword
+ 4, service
->num_txt
,
1989 service
->txt
)) != NULL
)
1990 strlcpy(tptr
, strdup(ptr
), sizeof(temp
) - (tptr
- temp
));
1996 _cupsLangPrintf(stderr
, _("ippfind: Unknown variable \"{%s}\"."),
1998 exit(IPPFIND_EXIT_SYNTAX
);
2001 tptr
+= strlen(tptr
);
2003 else if (tptr
< (temp
+ sizeof(temp
) - 1))
2008 myargv
[i
] = strdup(temp
);
2011 myargv
[i
] = strdup(args
[i
]);
2015 status
= _spawnvpe(_P_WAIT
, args
[0], myargv
, myenvp
);
2019 * Execute the program...
2022 if (strchr(args
[0], '/') && !access(args
[0], X_OK
))
2023 strlcpy(program
, args
[0], sizeof(program
));
2024 else if (!cupsFileFind(args
[0], getenv("PATH"), 1, program
, sizeof(program
)))
2026 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2027 args
[0], strerror(ENOENT
));
2028 exit(IPPFIND_EXIT_SYNTAX
);
2031 if (getenv("IPPFIND_DEBUG"))
2033 printf("\nProgram:\n %s\n", program
);
2034 puts("\nArguments:");
2035 for (i
= 0; i
< num_args
; i
++)
2036 printf(" %s\n", myargv
[i
]);
2037 puts("\nEnvironment:");
2038 for (i
= 0; i
< myenvc
; i
++)
2039 printf(" %s\n", myenvp
[i
]);
2042 if ((pid
= fork()) == 0)
2045 * Child comes here...
2048 execve(program
, myargv
, myenvp
);
2053 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2054 args
[0], strerror(errno
));
2055 exit(IPPFIND_EXIT_SYNTAX
);
2060 * Wait for it to complete...
2063 while (wait(&status
) != pid
)
2072 for (i
= 0; i
< num_args
; i
++)
2076 * Return whether the program succeeded or crashed...
2079 return (status
== 0);
2084 * 'get_service()' - Create or update a device.
2087 static ippfind_srv_t
* /* O - Service */
2088 get_service(cups_array_t
*services
, /* I - Service array */
2089 const char *serviceName
, /* I - Name of service/device */
2090 const char *regtype
, /* I - Type of service */
2091 const char *replyDomain
) /* I - Service domain */
2093 ippfind_srv_t key
, /* Search key */
2094 *service
; /* Service */
2095 char fullName
[kDNSServiceMaxDomainName
];
2096 /* Full name for query */
2100 * See if this is a new device...
2103 key
.name
= (char *)serviceName
;
2104 key
.regtype
= (char *)regtype
;
2106 for (service
= cupsArrayFind(services
, &key
);
2108 service
= cupsArrayNext(services
))
2109 if (_cups_strcasecmp(service
->name
, key
.name
))
2111 else if (!strcmp(service
->regtype
, key
.regtype
))
2115 * Yes, add the service...
2118 service
= calloc(sizeof(ippfind_srv_t
), 1);
2119 service
->name
= strdup(serviceName
);
2120 service
->domain
= strdup(replyDomain
);
2121 service
->regtype
= strdup(regtype
);
2123 cupsArrayAdd(services
, service
);
2126 * Set the "full name" of this service, which is used for queries and
2131 DNSServiceConstructFullName(fullName
, serviceName
, regtype
, replyDomain
);
2132 #else /* HAVE_AVAHI */
2133 avahi_service_name_join(fullName
, kDNSServiceMaxDomainName
, serviceName
,
2134 regtype
, replyDomain
);
2135 #endif /* HAVE_DNSSD */
2137 service
->fullName
= strdup(fullName
);
2144 * 'get_time()' - Get the current time-of-day in seconds.
2151 struct _timeb curtime
; /* Current Windows time */
2155 return (curtime
.time
+ 0.001 * curtime
.millitm
);
2158 struct timeval curtime
; /* Current UNIX time */
2160 if (gettimeofday(&curtime
, NULL
))
2163 return (curtime
.tv_sec
+ 0.000001 * curtime
.tv_usec
);
2169 * 'list_service()' - List the contents of a service.
2172 static int /* O - 1 if successful, 0 otherwise */
2173 list_service(ippfind_srv_t
*service
) /* I - Service */
2175 http_addrlist_t
*addrlist
; /* Address(es) of service */
2176 char port
[10]; /* Port number of service */
2179 snprintf(port
, sizeof(port
), "%d", service
->port
);
2181 if ((addrlist
= httpAddrGetList(service
->host
, address_family
, port
)) == NULL
)
2183 _cupsLangPrintf(stdout
, "%s unreachable", service
->uri
);
2187 if (!strncmp(service
->regtype
, "_ipp._tcp", 9) ||
2188 !strncmp(service
->regtype
, "_ipps._tcp", 10))
2194 http_t
*http
; /* HTTP connection */
2195 ipp_t
*request
, /* IPP request */
2196 *response
; /* IPP response */
2197 ipp_attribute_t
*attr
; /* IPP attribute */
2198 int i
, /* Looping var */
2199 count
, /* Number of values */
2200 version
, /* IPP version */
2201 paccepting
; /* printer-is-accepting-jobs value */
2202 ipp_pstate_t pstate
; /* printer-state value */
2203 char preasons
[1024], /* Comma-delimited printer-state-reasons */
2204 *ptr
, /* Pointer into reasons */
2205 *end
; /* End of reasons buffer */
2206 static const char * const rattrs
[] =/* Requested attributes */
2208 "printer-is-accepting-jobs",
2210 "printer-state-reasons"
2214 * Connect to the printer...
2217 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2218 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2219 HTTP_ENCRYPTION_ALWAYS
:
2220 HTTP_ENCRYPTION_IF_REQUESTED
,
2223 httpAddrFreeList(addrlist
);
2227 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2232 * Get the current printer state...
2236 version
= ipp_version
;
2240 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
2241 ippSetVersion(request
, version
/ 10, version
% 10);
2242 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
2244 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
2245 "requesting-user-name", NULL
, cupsUser());
2246 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
2247 "requested-attributes",
2248 (int)(sizeof(rattrs
) / sizeof(rattrs
[0])), NULL
, rattrs
);
2250 response
= cupsDoRequest(http
, request
, service
->resource
);
2252 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
&& version
> 11)
2255 while (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
&& version
> 11);
2261 if (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
)
2263 _cupsLangPrintf(stdout
, "%s: unavailable", service
->uri
);
2267 if ((attr
= ippFindAttribute(response
, "printer-state",
2268 IPP_TAG_ENUM
)) != NULL
)
2269 pstate
= ippGetInteger(attr
, 0);
2271 pstate
= IPP_PSTATE_STOPPED
;
2273 if ((attr
= ippFindAttribute(response
, "printer-is-accepting-jobs",
2274 IPP_TAG_BOOLEAN
)) != NULL
)
2275 paccepting
= ippGetBoolean(attr
, 0);
2279 if ((attr
= ippFindAttribute(response
, "printer-state-reasons",
2280 IPP_TAG_KEYWORD
)) != NULL
)
2282 strlcpy(preasons
, ippGetString(attr
, 0, NULL
), sizeof(preasons
));
2284 for (i
= 1, count
= ippGetCount(attr
), ptr
= preasons
+ strlen(preasons
),
2285 end
= preasons
+ sizeof(preasons
) - 1;
2286 i
< count
&& ptr
< end
;
2287 i
++, ptr
+= strlen(ptr
))
2290 strlcpy(ptr
, ippGetString(attr
, i
, NULL
), end
- ptr
+ 1);
2294 strlcpy(preasons
, "none", sizeof(preasons
));
2296 ippDelete(response
);
2299 _cupsLangPrintf(stdout
, "%s %s %s %s", service
->uri
,
2300 ippEnumString("printer-state", pstate
),
2301 paccepting
? "accepting-jobs" : "not-accepting-jobs",
2304 else if (!strncmp(service
->regtype
, "_http._tcp", 10) ||
2305 !strncmp(service
->regtype
, "_https._tcp", 11))
2308 * HTTP/HTTPS web page
2311 http_t
*http
; /* HTTP connection */
2312 http_status_t status
; /* HEAD status */
2316 * Connect to the web server...
2319 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2320 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2321 HTTP_ENCRYPTION_ALWAYS
:
2322 HTTP_ENCRYPTION_IF_REQUESTED
,
2325 httpAddrFreeList(addrlist
);
2329 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2333 if (httpGet(http
, service
->resource
))
2335 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2341 status
= httpUpdate(http
);
2343 while (status
== HTTP_STATUS_CONTINUE
);
2348 if (status
>= HTTP_STATUS_BAD_REQUEST
)
2350 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2354 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2356 else if (!strncmp(service
->regtype
, "_printer._tcp", 13))
2362 int sock
; /* Socket */
2365 if (!httpAddrConnect(addrlist
, &sock
))
2367 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2368 httpAddrFreeList(addrlist
);
2372 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2373 httpAddrFreeList(addrlist
);
2383 _cupsLangPrintf(stdout
, "%s unsupported", service
->uri
);
2384 httpAddrFreeList(addrlist
);
2393 * 'new_expr()' - Create a new expression.
2396 static ippfind_expr_t
* /* O - New expression */
2397 new_expr(ippfind_op_t op
, /* I - Operation */
2398 int invert
, /* I - Invert result? */
2399 const char *value
, /* I - TXT key or port range */
2400 const char *regex
, /* I - Regular expression */
2401 char **args
) /* I - Pointer to argument strings */
2403 ippfind_expr_t
*temp
; /* New expression */
2406 if ((temp
= calloc(1, sizeof(ippfind_expr_t
))) == NULL
)
2410 temp
->invert
= invert
;
2412 if (op
== IPPFIND_OP_TXT_EXISTS
|| op
== IPPFIND_OP_TXT_REGEX
)
2413 temp
->key
= (char *)value
;
2414 else if (op
== IPPFIND_OP_PORT_RANGE
)
2417 * Pull port number range of the form "number", "-number" (0-number),
2418 * "number-" (number-65535), and "number-number".
2423 temp
->range
[1] = atoi(value
+ 1);
2425 else if (strchr(value
, '-'))
2427 if (sscanf(value
, "%d-%d", temp
->range
, temp
->range
+ 1) == 1)
2428 temp
->range
[1] = 65535;
2432 temp
->range
[0] = temp
->range
[1] = atoi(value
);
2438 int err
= regcomp(&(temp
->re
), regex
, REG_NOSUB
| REG_ICASE
| REG_EXTENDED
);
2442 char message
[256]; /* Error message */
2444 regerror(err
, &(temp
->re
), message
, sizeof(message
));
2445 _cupsLangPrintf(stderr
, _("ippfind: Bad regular expression: %s"),
2447 exit(IPPFIND_EXIT_SYNTAX
);
2453 int num_args
; /* Number of arguments */
2455 for (num_args
= 1; args
[num_args
]; num_args
++)
2456 if (!strcmp(args
[num_args
], ";"))
2459 temp
->num_args
= num_args
;
2460 temp
->args
= malloc(num_args
* sizeof(char *));
2461 memcpy(temp
->args
, args
, num_args
* sizeof(char *));
2470 * 'poll_callback()' - Wait for input on the specified file descriptors.
2472 * Note: This function is needed because avahi_simple_poll_iterate is broken
2473 * and always uses a timeout of 0 (!) milliseconds.
2474 * (Avahi Ticket #364)
2477 static int /* O - Number of file descriptors matching */
2479 struct pollfd
*pollfds
, /* I - File descriptors */
2480 unsigned int num_pollfds
, /* I - Number of file descriptors */
2481 int timeout
, /* I - Timeout in milliseconds (unused) */
2482 void *context
) /* I - User data (unused) */
2484 int val
; /* Return value */
2490 val
= poll(pollfds
, num_pollfds
, 500);
2497 #endif /* HAVE_AVAHI */
2501 * 'resolve_callback()' - Process resolve data.
2507 DNSServiceRef sdRef
, /* I - Service reference */
2508 DNSServiceFlags flags
, /* I - Data flags */
2509 uint32_t interfaceIndex
, /* I - Interface */
2510 DNSServiceErrorType errorCode
, /* I - Error, if any */
2511 const char *fullName
, /* I - Full service name */
2512 const char *hostTarget
, /* I - Hostname */
2513 uint16_t port
, /* I - Port number (network byte order) */
2514 uint16_t txtLen
, /* I - Length of TXT record data */
2515 const unsigned char *txtRecord
, /* I - TXT record data */
2516 void *context
) /* I - Service */
2518 char key
[256], /* TXT key value */
2519 *value
; /* Value from TXT record */
2520 const unsigned char *txtEnd
; /* End of TXT record */
2521 uint8_t valueLen
; /* Length of value */
2522 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2527 * Only process "add" data...
2530 if (errorCode
!= kDNSServiceErr_NoError
)
2532 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
2533 dnssd_error_string(errorCode
));
2538 service
->is_resolved
= 1;
2539 service
->host
= strdup(hostTarget
);
2540 service
->port
= ntohs(port
);
2543 * Loop through the TXT key/value pairs and add them to an array...
2546 for (txtEnd
= txtRecord
+ txtLen
; txtRecord
< txtEnd
; txtRecord
+= valueLen
)
2549 * Ignore bogus strings...
2552 valueLen
= *txtRecord
++;
2554 memcpy(key
, txtRecord
, valueLen
);
2555 key
[valueLen
] = '\0';
2557 if ((value
= strchr(key
, '=')) == NULL
)
2563 * Add to array of TXT values...
2566 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2570 set_service_uri(service
);
2574 #elif defined(HAVE_AVAHI)
2577 AvahiServiceResolver
*resolver
, /* I - Resolver */
2578 AvahiIfIndex interface
, /* I - Interface */
2579 AvahiProtocol protocol
, /* I - Address protocol */
2580 AvahiBrowserEvent event
, /* I - Event */
2581 const char *serviceName
,/* I - Service name */
2582 const char *regtype
, /* I - Registration type */
2583 const char *replyDomain
,/* I - Domain name */
2584 const char *hostTarget
, /* I - FQDN */
2585 uint16_t port
, /* I - Port number */
2586 AvahiStringList
*txt
, /* I - TXT records */
2587 AvahiLookupResultFlags flags
, /* I - Lookup flags */
2588 void *context
) /* I - Service */
2590 char uri
[1024]; /* URI */
2591 key
[256], /* TXT key */
2592 *value
; /* TXT value */
2593 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2595 AvahiStringList
*current
; /* Current TXT key/value pair */
2598 if (event
!= AVAHI_RESOLVER_FOUND
)
2602 avahi_service_resolver_free(resolver
);
2603 avahi_simple_poll_quit(uribuf
->poll
);
2607 service
->is_resolved
= 1;
2608 service
->host
= strdup(hostTarget
);
2609 service
->port
= ntohs(port
);
2612 * Loop through the TXT key/value pairs and add them to an array...
2615 for (current
= txt
; current
; current
= current
->next
)
2618 * Ignore bogus strings...
2621 if (current
->size
> (sizeof(key
) - 1))
2624 memcpy(key
, current
->text
, current
->size
);
2625 key
[current
->size
] = '\0';
2627 if ((value
= strchr(key
, '=')) == NULL
)
2633 * Add to array of TXT values...
2636 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2640 set_service_uri(service
);
2642 #endif /* HAVE_DNSSD */
2646 * 'set_service_uri()' - Set the URI of the service.
2650 set_service_uri(ippfind_srv_t
*service
) /* I - Service */
2652 char uri
[1024]; /* URI */
2653 const char *path
, /* Resource path */
2654 *scheme
; /* URI scheme */
2657 if (!strncmp(service
->regtype
, "_http.", 6))
2660 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2662 else if (!strncmp(service
->regtype
, "_https.", 7))
2665 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2667 else if (!strncmp(service
->regtype
, "_ipp.", 5))
2670 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2672 else if (!strncmp(service
->regtype
, "_ipps.", 6))
2675 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2677 else if (!strncmp(service
->regtype
, "_printer.", 9))
2680 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2685 if (!path
|| !*path
)
2690 service
->resource
= strdup(path
);
2694 snprintf(uri
, sizeof(uri
), "/%s", path
);
2695 service
->resource
= strdup(uri
);
2698 httpAssembleURI(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), scheme
, NULL
,
2699 service
->host
, service
->port
, service
->resource
);
2700 service
->uri
= strdup(uri
);
2705 * 'show_usage()' - Show program usage.
2711 _cupsLangPuts(stderr
, _("Usage: ippfind [options] regtype[,subtype]"
2712 "[.domain.] ... [expression]\n"
2713 " ippfind [options] name[.regtype[.domain.]] "
2714 "... [expression]\n"
2716 " ippfind --version"));
2717 _cupsLangPuts(stderr
, "");
2718 _cupsLangPuts(stderr
, _("Options:"));
2719 _cupsLangPuts(stderr
, _(" -4 Connect using IPv4."));
2720 _cupsLangPuts(stderr
, _(" -6 Connect using IPv6."));
2721 _cupsLangPuts(stderr
, _(" -T seconds Set the browse timeout in "
2723 _cupsLangPuts(stderr
, _(" -V version Set default IPP "
2725 _cupsLangPuts(stderr
, _(" --help Show this help."));
2726 _cupsLangPuts(stderr
, _(" --version Show program version."));
2727 _cupsLangPuts(stderr
, "");
2728 _cupsLangPuts(stderr
, _("Expressions:"));
2729 _cupsLangPuts(stderr
, _(" -P number[-number] Match port to number or range."));
2730 _cupsLangPuts(stderr
, _(" -d regex Match domain to regular expression."));
2731 _cupsLangPuts(stderr
, _(" -h regex Match hostname to regular expression."));
2732 _cupsLangPuts(stderr
, _(" -l List attributes."));
2733 _cupsLangPuts(stderr
, _(" -n regex Match service name to regular expression."));
2734 _cupsLangPuts(stderr
, _(" -p Print URI if true."));
2735 _cupsLangPuts(stderr
, _(" -q Quietly report match via exit code."));
2736 _cupsLangPuts(stderr
, _(" -r True if service is remote."));
2737 _cupsLangPuts(stderr
, _(" -s Print service name if true."));
2738 _cupsLangPuts(stderr
, _(" -t key True if the TXT record contains the key."));
2739 _cupsLangPuts(stderr
, _(" -u regex Match URI to regular expression."));
2740 _cupsLangPuts(stderr
, _(" -x utility [argument ...] ;\n"
2741 " Execute program if true."));
2742 _cupsLangPuts(stderr
, _(" --domain regex Match domain to regular expression."));
2743 _cupsLangPuts(stderr
, _(" --exec utility [argument ...] ;\n"
2744 " Execute program if true."));
2745 _cupsLangPuts(stderr
, _(" --host regex Match hostname to regular expression."));
2746 _cupsLangPuts(stderr
, _(" --ls List attributes."));
2747 _cupsLangPuts(stderr
, _(" --local True if service is local."));
2748 _cupsLangPuts(stderr
, _(" --name regex Match service name to regular expression."));
2749 _cupsLangPuts(stderr
, _(" --path regex Match resource path to regular expression."));
2750 _cupsLangPuts(stderr
, _(" --port number[-number] Match port to number or range."));
2751 _cupsLangPuts(stderr
, _(" --print Print URI if true."));
2752 _cupsLangPuts(stderr
, _(" --print-name Print service name if true."));
2753 _cupsLangPuts(stderr
, _(" --quiet Quietly report match via exit code."));
2754 _cupsLangPuts(stderr
, _(" --remote True if service is remote."));
2755 _cupsLangPuts(stderr
, _(" --txt key True if the TXT record contains the key."));
2756 _cupsLangPuts(stderr
, _(" --txt-* regex Match TXT record key to regular expression."));
2757 _cupsLangPuts(stderr
, _(" --uri regex Match URI to regular expression."));
2758 _cupsLangPuts(stderr
, "");
2759 _cupsLangPuts(stderr
, _("Modifiers:"));
2760 _cupsLangPuts(stderr
, _(" ( expressions ) Group expressions."));
2761 _cupsLangPuts(stderr
, _(" ! expression Unary NOT of expression."));
2762 _cupsLangPuts(stderr
, _(" --not expression Unary NOT of expression."));
2763 _cupsLangPuts(stderr
, _(" --false Always false."));
2764 _cupsLangPuts(stderr
, _(" --true Always true."));
2765 _cupsLangPuts(stderr
, _(" expression expression Logical AND."));
2766 _cupsLangPuts(stderr
, _(" expression --and expression\n"
2768 _cupsLangPuts(stderr
, _(" expression --or expression\n"
2770 _cupsLangPuts(stderr
, "");
2771 _cupsLangPuts(stderr
, _("Substitutions:"));
2772 _cupsLangPuts(stderr
, _(" {} URI"));
2773 _cupsLangPuts(stderr
, _(" {service_domain} Domain name"));
2774 _cupsLangPuts(stderr
, _(" {service_hostname} Fully-qualified domain name"));
2775 _cupsLangPuts(stderr
, _(" {service_name} Service instance name"));
2776 _cupsLangPuts(stderr
, _(" {service_port} Port number"));
2777 _cupsLangPuts(stderr
, _(" {service_regtype} DNS-SD registration type"));
2778 _cupsLangPuts(stderr
, _(" {service_scheme} URI scheme"));
2779 _cupsLangPuts(stderr
, _(" {service_uri} URI"));
2780 _cupsLangPuts(stderr
, _(" {txt_*} Value of TXT record key"));
2781 _cupsLangPuts(stderr
, "");
2782 _cupsLangPuts(stderr
, _("Environment Variables:"));
2783 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_DOMAIN Domain name"));
2784 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_HOSTNAME\n"
2785 " Fully-qualified domain name"));
2786 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_NAME Service instance name"));
2787 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_PORT Port number"));
2788 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_REGTYPE DNS-SD registration type"));
2789 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_SCHEME URI scheme"));
2790 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_URI URI"));
2791 _cupsLangPuts(stderr
, _(" IPPFIND_TXT_* Value of TXT record key"));
2793 exit(IPPFIND_EXIT_TRUE
);
2798 * 'show_version()' - Show program version.
2804 _cupsLangPuts(stderr
, CUPS_SVERSION
);
2806 exit(IPPFIND_EXIT_TRUE
);