2 * "$Id: ippfind.c 12639 2015-05-19 02:36:30Z msweet $"
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-2015 by Apple Inc.
10 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * file is missing or damaged, see the license at "http://www.cups.org/".
16 * This file is subject to the Apple OS-Developed Software exception.
20 * Include necessary headers.
23 #define _CUPS_NO_DEPRECATED
24 #include <cups/cups-private.h>
27 # include <sys/timeb.h>
29 # include <sys/wait.h>
34 #elif defined(HAVE_AVAHI)
35 # include <avahi-client/client.h>
36 # include <avahi-client/lookup.h>
37 # include <avahi-common/simple-watch.h>
38 # include <avahi-common/domain.h>
39 # include <avahi-common/error.h>
40 # include <avahi-common/malloc.h>
41 # define kDNSServiceMaxDomainName AVAHI_DOMAIN_NAME_MAX
42 #endif /* HAVE_DNSSD */
45 extern char **environ
; /* Process environment variables */
53 typedef enum ippfind_exit_e
/* Exit codes */
55 IPPFIND_EXIT_TRUE
= 0, /* OK and result is true */
56 IPPFIND_EXIT_FALSE
, /* OK but result is false*/
57 IPPFIND_EXIT_BONJOUR
, /* Browse/resolve failure */
58 IPPFIND_EXIT_SYNTAX
, /* Bad option or syntax error */
59 IPPFIND_EXIT_MEMORY
/* Out of memory */
62 typedef enum ippfind_op_e
/* Operations for expressions */
64 /* "Evaluation" operations */
65 IPPFIND_OP_NONE
, /* No operation */
66 IPPFIND_OP_AND
, /* Logical AND of all children */
67 IPPFIND_OP_OR
, /* Logical OR of all children */
68 IPPFIND_OP_TRUE
, /* Always true */
69 IPPFIND_OP_FALSE
, /* Always false */
70 IPPFIND_OP_IS_LOCAL
, /* Is a local service */
71 IPPFIND_OP_IS_REMOTE
, /* Is a remote service */
72 IPPFIND_OP_DOMAIN_REGEX
, /* Domain matches regular expression */
73 IPPFIND_OP_NAME_REGEX
, /* Name matches regular expression */
74 IPPFIND_OP_HOST_REGEX
, /* Hostname matches regular expression */
75 IPPFIND_OP_PORT_RANGE
, /* Port matches range */
76 IPPFIND_OP_PATH_REGEX
, /* Path matches regular expression */
77 IPPFIND_OP_TXT_EXISTS
, /* TXT record key exists */
78 IPPFIND_OP_TXT_REGEX
, /* TXT record key matches regular expression */
79 IPPFIND_OP_URI_REGEX
, /* URI matches regular expression */
81 /* "Output" operations */
82 IPPFIND_OP_EXEC
, /* Execute when true */
83 IPPFIND_OP_LIST
, /* List when true */
84 IPPFIND_OP_PRINT_NAME
, /* Print URI when true */
85 IPPFIND_OP_PRINT_URI
, /* Print name when true */
86 IPPFIND_OP_QUIET
/* No output when true */
89 typedef struct ippfind_expr_s
/* Expression */
92 *prev
, /* Previous expression */
93 *next
, /* Next expression */
94 *parent
, /* Parent expressions */
95 *child
; /* Child expressions */
96 ippfind_op_t op
; /* Operation code (see above) */
97 int invert
; /* Invert the result */
98 char *key
; /* TXT record key */
99 regex_t re
; /* Regular expression for matching */
100 int range
[2]; /* Port number range */
101 int num_args
; /* Number of arguments for exec */
102 char **args
; /* Arguments for exec */
105 typedef struct ippfind_srv_s
/* Service information */
108 DNSServiceRef ref
; /* Service reference for query */
109 #elif defined(HAVE_AVAHI)
110 AvahiServiceResolver
*ref
; /* Resolver */
111 #endif /* HAVE_DNSSD */
112 char *name
, /* Service name */
113 *domain
, /* Domain name */
114 *regtype
, /* Registration type */
115 *fullName
, /* Full name */
116 *host
, /* Hostname */
117 *resource
, /* Resource path */
119 int num_txt
; /* Number of TXT record keys */
120 cups_option_t
*txt
; /* TXT record keys */
121 int port
, /* Port number */
122 is_local
, /* Is a local service? */
123 is_processed
, /* Did we process the service? */
124 is_resolved
; /* Got the resolve data? */
133 static DNSServiceRef dnssd_ref
; /* Master service reference */
134 #elif defined(HAVE_AVAHI)
135 static AvahiClient
*avahi_client
= NULL
;/* Client information */
136 static int avahi_got_data
= 0; /* Got data from poll? */
137 static AvahiSimplePoll
*avahi_poll
= NULL
;
138 /* Poll information */
139 #endif /* HAVE_DNSSD */
141 static int address_family
= AF_UNSPEC
;
142 /* Address family for LIST */
143 static int bonjour_error
= 0; /* Error browsing/resolving? */
144 static double bonjour_timeout
= 1.0; /* Timeout in seconds */
145 static int ipp_version
= 20; /* IPP version for LIST */
153 static void DNSSD_API
browse_callback(DNSServiceRef sdRef
,
154 DNSServiceFlags flags
,
155 uint32_t interfaceIndex
,
156 DNSServiceErrorType errorCode
,
157 const char *serviceName
,
159 const char *replyDomain
, void *context
)
160 __attribute__((nonnull(1,5,6,7,8)));
161 static void DNSSD_API
browse_local_callback(DNSServiceRef sdRef
,
162 DNSServiceFlags flags
,
163 uint32_t interfaceIndex
,
164 DNSServiceErrorType errorCode
,
165 const char *serviceName
,
167 const char *replyDomain
,
169 __attribute__((nonnull(1,5,6,7,8)));
170 #elif defined(HAVE_AVAHI)
171 static void browse_callback(AvahiServiceBrowser
*browser
,
172 AvahiIfIndex interface
,
173 AvahiProtocol protocol
,
174 AvahiBrowserEvent event
,
175 const char *serviceName
,
177 const char *replyDomain
,
178 AvahiLookupResultFlags flags
,
180 static void client_callback(AvahiClient
*client
,
181 AvahiClientState state
,
183 #endif /* HAVE_AVAHI */
185 static int compare_services(ippfind_srv_t
*a
, ippfind_srv_t
*b
);
186 static const char *dnssd_error_string(int error
);
187 static int eval_expr(ippfind_srv_t
*service
,
188 ippfind_expr_t
*expressions
);
189 static int exec_program(ippfind_srv_t
*service
, int num_args
,
191 static ippfind_srv_t
*get_service(cups_array_t
*services
,
192 const char *serviceName
,
194 const char *replyDomain
)
195 __attribute__((nonnull(1,2,3,4)));
196 static double get_time(void);
197 static int list_service(ippfind_srv_t
*service
);
198 static ippfind_expr_t
*new_expr(ippfind_op_t op
, int invert
,
199 const char *value
, const char *regex
,
202 static void DNSSD_API
resolve_callback(DNSServiceRef sdRef
,
203 DNSServiceFlags flags
,
204 uint32_t interfaceIndex
,
205 DNSServiceErrorType errorCode
,
206 const char *fullName
,
207 const char *hostTarget
, uint16_t port
,
209 const unsigned char *txtRecord
,
211 __attribute__((nonnull(1,5,6,9, 10)));
212 #elif defined(HAVE_AVAHI)
213 static int poll_callback(struct pollfd
*pollfds
,
214 unsigned int num_pollfds
, int timeout
,
216 static void resolve_callback(AvahiServiceResolver
*res
,
217 AvahiIfIndex interface
,
218 AvahiProtocol protocol
,
219 AvahiResolverEvent event
,
220 const char *serviceName
,
222 const char *replyDomain
,
223 const char *host_name
,
224 const AvahiAddress
*address
,
226 AvahiStringList
*txt
,
227 AvahiLookupResultFlags flags
,
229 #endif /* HAVE_DNSSD */
230 static void set_service_uri(ippfind_srv_t
*service
);
231 static void show_usage(void) __attribute__((noreturn
));
232 static void show_version(void) __attribute__((noreturn
));
236 * 'main()' - Browse for printers.
239 int /* O - Exit status */
240 main(int argc
, /* I - Number of command-line args */
241 char *argv
[]) /* I - Command-line arguments */
243 int i
, /* Looping var */
244 have_output
= 0,/* Have output expression */
245 status
= IPPFIND_EXIT_FALSE
;
247 const char *opt
, /* Option character */
248 *search
; /* Current browse/resolve string */
249 cups_array_t
*searches
; /* Things to browse/resolve */
250 cups_array_t
*services
; /* Service array */
251 ippfind_srv_t
*service
; /* Current service */
252 ippfind_expr_t
*expressions
= NULL
,
253 /* Expression tree */
254 *temp
= NULL
, /* New expression */
255 *parent
= NULL
, /* Parent expression */
256 *current
= NULL
,/* Current expression */
257 *parens
[100]; /* Markers for parenthesis */
258 int num_parens
= 0; /* Number of parenthesis */
259 ippfind_op_t logic
= IPPFIND_OP_AND
;
260 /* Logic for next expression */
261 int invert
= 0; /* Invert expression? */
262 int err
; /* DNS-SD error */
264 fd_set sinput
; /* Input set for select() */
265 struct timeval stimeout
; /* Timeout for select() */
266 #endif /* HAVE_DNSSD */
267 double endtime
; /* End time */
268 static const char * const ops
[] = /* Node operation names */
294 * Initialize the locale...
297 _cupsSetLocale(argv
);
300 * Create arrays to track services and things we want to browse/resolve...
303 searches
= cupsArrayNew(NULL
, NULL
);
304 services
= cupsArrayNew((cups_array_func_t
)compare_services
, NULL
);
307 * Parse command-line...
310 if (getenv("IPPFIND_DEBUG"))
311 for (i
= 1; i
< argc
; i
++)
312 fprintf(stderr
, "argv[%d]=\"%s\"\n", i
, argv
[i
]);
314 for (i
= 1; i
< argc
; i
++)
316 if (argv
[i
][0] == '-')
318 if (argv
[i
][1] == '-')
321 * Parse --option options...
324 if (!strcmp(argv
[i
], "--and"))
326 if (logic
== IPPFIND_OP_OR
)
328 _cupsLangPuts(stderr
, _("ippfind: Cannot use --and after --or."));
334 _cupsLangPuts(stderr
,
335 _("ippfind: Missing expression before \"--and\"."));
341 else if (!strcmp(argv
[i
], "--domain"))
346 _cupsLangPrintf(stderr
,
347 _("ippfind: Missing regular expression after %s."),
352 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
, argv
[i
],
354 return (IPPFIND_EXIT_MEMORY
);
356 else if (!strcmp(argv
[i
], "--exec"))
361 _cupsLangPrintf(stderr
, _("ippfind: Expected program after %s."),
366 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
368 return (IPPFIND_EXIT_MEMORY
);
371 if (!strcmp(argv
[i
], ";"))
378 _cupsLangPrintf(stderr
, _("ippfind: Expected semi-colon after %s."),
385 else if (!strcmp(argv
[i
], "--false"))
387 if ((temp
= new_expr(IPPFIND_OP_FALSE
, invert
, NULL
, NULL
,
389 return (IPPFIND_EXIT_MEMORY
);
391 else if (!strcmp(argv
[i
], "--help"))
395 else if (!strcmp(argv
[i
], "--host"))
400 _cupsLangPrintf(stderr
,
401 _("ippfind: Missing regular expression after %s."),
406 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
, argv
[i
],
408 return (IPPFIND_EXIT_MEMORY
);
410 else if (!strcmp(argv
[i
], "--ls"))
412 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
414 return (IPPFIND_EXIT_MEMORY
);
418 else if (!strcmp(argv
[i
], "--local"))
420 if ((temp
= new_expr(IPPFIND_OP_IS_LOCAL
, invert
, NULL
, NULL
,
422 return (IPPFIND_EXIT_MEMORY
);
424 else if (!strcmp(argv
[i
], "--name"))
429 _cupsLangPrintf(stderr
,
430 _("ippfind: Missing regular expression after %s."),
435 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
, argv
[i
],
437 return (IPPFIND_EXIT_MEMORY
);
439 else if (!strcmp(argv
[i
], "--not"))
443 else if (!strcmp(argv
[i
], "--or"))
447 _cupsLangPuts(stderr
,
448 _("ippfind: Missing expression before \"--or\"."));
452 logic
= IPPFIND_OP_OR
;
454 if (parent
&& parent
->op
== IPPFIND_OP_OR
)
457 * Already setup to do "foo --or bar --or baz"...
462 else if (!current
->prev
&& parent
)
465 * Change parent node into an OR node...
468 parent
->op
= IPPFIND_OP_OR
;
471 else if (!current
->prev
)
474 * Need to group "current" in a new OR node...
477 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
479 return (IPPFIND_EXIT_MEMORY
);
481 temp
->parent
= parent
;
482 temp
->child
= current
;
483 current
->parent
= temp
;
486 parent
->child
= temp
;
496 * Need to group previous expressions in an AND node, and then
497 * put that in an OR node...
500 if ((temp
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
502 return (IPPFIND_EXIT_MEMORY
);
504 while (current
->prev
)
506 current
->parent
= temp
;
507 current
= current
->prev
;
510 current
->parent
= temp
;
511 temp
->child
= current
;
514 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
516 return (IPPFIND_EXIT_MEMORY
);
518 temp
->parent
= parent
;
519 current
->parent
= temp
;
522 parent
->child
= temp
;
530 else if (!strcmp(argv
[i
], "--path"))
535 _cupsLangPrintf(stderr
,
536 _("ippfind: Missing regular expression after %s."),
541 if ((temp
= new_expr(IPPFIND_OP_PATH_REGEX
, invert
, NULL
, argv
[i
],
543 return (IPPFIND_EXIT_MEMORY
);
545 else if (!strcmp(argv
[i
], "--port"))
550 _cupsLangPrintf(stderr
,
551 _("ippfind: Expected port range after %s."),
556 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
], NULL
,
558 return (IPPFIND_EXIT_MEMORY
);
560 else if (!strcmp(argv
[i
], "--print"))
562 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
564 return (IPPFIND_EXIT_MEMORY
);
568 else if (!strcmp(argv
[i
], "--print-name"))
570 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
572 return (IPPFIND_EXIT_MEMORY
);
576 else if (!strcmp(argv
[i
], "--quiet"))
578 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
580 return (IPPFIND_EXIT_MEMORY
);
584 else if (!strcmp(argv
[i
], "--remote"))
586 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
588 return (IPPFIND_EXIT_MEMORY
);
590 else if (!strcmp(argv
[i
], "--true"))
592 if ((temp
= new_expr(IPPFIND_OP_TRUE
, invert
, NULL
, argv
[i
],
594 return (IPPFIND_EXIT_MEMORY
);
596 else if (!strcmp(argv
[i
], "--txt"))
601 _cupsLangPrintf(stderr
, _("ippfind: Expected key name after %s."),
606 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
], NULL
,
608 return (IPPFIND_EXIT_MEMORY
);
610 else if (!strncmp(argv
[i
], "--txt-", 6))
612 const char *key
= argv
[i
] + 6;/* TXT key */
617 _cupsLangPrintf(stderr
,
618 _("ippfind: Missing regular expression after %s."),
623 if ((temp
= new_expr(IPPFIND_OP_TXT_REGEX
, invert
, key
, argv
[i
],
625 return (IPPFIND_EXIT_MEMORY
);
627 else if (!strcmp(argv
[i
], "--uri"))
632 _cupsLangPrintf(stderr
,
633 _("ippfind: Missing regular expression after %s."),
638 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
, argv
[i
],
640 return (IPPFIND_EXIT_MEMORY
);
642 else if (!strcmp(argv
[i
], "--version"))
648 _cupsLangPrintf(stderr
, _("%s: Unknown option \"%s\"."),
656 * Add new expression...
659 if (logic
== IPPFIND_OP_AND
&&
660 current
&& current
->prev
&&
661 parent
&& parent
->op
!= IPPFIND_OP_AND
)
664 * Need to re-group "current" in a new AND node...
667 ippfind_expr_t
*tempand
; /* Temporary AND node */
669 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
671 return (IPPFIND_EXIT_MEMORY
);
674 * Replace "current" with new AND node at the end of this list...
677 current
->prev
->next
= tempand
;
678 tempand
->prev
= current
->prev
;
679 tempand
->parent
= parent
;
682 * Add "current to the new AND node...
685 tempand
->child
= current
;
686 current
->parent
= tempand
;
687 current
->prev
= NULL
;
692 * Add the new node at current level...
695 temp
->parent
= parent
;
696 temp
->prev
= current
;
699 current
->next
= temp
;
701 parent
->child
= temp
;
707 logic
= IPPFIND_OP_AND
;
717 for (opt
= argv
[i
] + 1; *opt
; opt
++)
722 address_family
= AF_INET
;
726 address_family
= AF_INET6
;
733 _cupsLangPrintf(stderr
,
734 _("ippfind: Expected port range after %s."),
739 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
],
740 NULL
, NULL
)) == NULL
)
741 return (IPPFIND_EXIT_MEMORY
);
748 _cupsLangPrintf(stderr
,
749 _("%s: Missing timeout for \"-T\"."),
754 bonjour_timeout
= atof(argv
[i
]);
761 _cupsLangPrintf(stderr
,
762 _("%s: Missing version for \"-V\"."),
767 if (!strcmp(argv
[i
], "1.1"))
769 else if (!strcmp(argv
[i
], "2.0"))
771 else if (!strcmp(argv
[i
], "2.1"))
773 else if (!strcmp(argv
[i
], "2.2"))
777 _cupsLangPrintf(stderr
, _("%s: Bad version %s for \"-V\"."),
787 _cupsLangPrintf(stderr
,
788 _("ippfind: Missing regular expression after "
793 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
,
794 argv
[i
], NULL
)) == NULL
)
795 return (IPPFIND_EXIT_MEMORY
);
802 _cupsLangPrintf(stderr
,
803 _("ippfind: Missing regular expression after "
808 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
,
809 argv
[i
], NULL
)) == NULL
)
810 return (IPPFIND_EXIT_MEMORY
);
814 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
816 return (IPPFIND_EXIT_MEMORY
);
825 _cupsLangPrintf(stderr
,
826 _("ippfind: Missing regular expression after "
831 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
,
832 argv
[i
], NULL
)) == NULL
)
833 return (IPPFIND_EXIT_MEMORY
);
837 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
839 return (IPPFIND_EXIT_MEMORY
);
845 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
847 return (IPPFIND_EXIT_MEMORY
);
853 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
855 return (IPPFIND_EXIT_MEMORY
);
859 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
861 return (IPPFIND_EXIT_MEMORY
);
870 _cupsLangPrintf(stderr
,
871 _("ippfind: Missing key name after %s."),
876 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
],
877 NULL
, NULL
)) == NULL
)
878 return (IPPFIND_EXIT_MEMORY
);
885 _cupsLangPrintf(stderr
,
886 _("ippfind: Missing regular expression after "
891 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
,
892 argv
[i
], NULL
)) == NULL
)
893 return (IPPFIND_EXIT_MEMORY
);
900 _cupsLangPrintf(stderr
,
901 _("ippfind: Missing program after %s."),
906 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
908 return (IPPFIND_EXIT_MEMORY
);
911 if (!strcmp(argv
[i
], ";"))
918 _cupsLangPrintf(stderr
,
919 _("ippfind: Missing semi-colon after %s."),
928 _cupsLangPrintf(stderr
, _("%s: Unknown option \"-%c\"."),
936 * Add new expression...
939 if (logic
== IPPFIND_OP_AND
&&
940 current
&& current
->prev
&&
941 parent
&& parent
->op
!= IPPFIND_OP_AND
)
944 * Need to re-group "current" in a new AND node...
947 ippfind_expr_t
*tempand
; /* Temporary AND node */
949 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
951 return (IPPFIND_EXIT_MEMORY
);
954 * Replace "current" with new AND node at the end of this list...
957 current
->prev
->next
= tempand
;
958 tempand
->prev
= current
->prev
;
959 tempand
->parent
= parent
;
962 * Add "current to the new AND node...
965 tempand
->child
= current
;
966 current
->parent
= tempand
;
967 current
->prev
= NULL
;
972 * Add the new node at current level...
975 temp
->parent
= parent
;
976 temp
->prev
= current
;
979 current
->next
= temp
;
981 parent
->child
= temp
;
987 logic
= IPPFIND_OP_AND
;
993 else if (!strcmp(argv
[i
], "("))
995 if (num_parens
>= 100)
997 _cupsLangPuts(stderr
, _("ippfind: Too many parenthesis."));
1001 if ((temp
= new_expr(IPPFIND_OP_AND
, invert
, NULL
, NULL
, NULL
)) == NULL
)
1002 return (IPPFIND_EXIT_MEMORY
);
1004 parens
[num_parens
++] = temp
;
1008 temp
->parent
= current
->parent
;
1009 current
->next
= temp
;
1010 temp
->prev
= current
;
1018 logic
= IPPFIND_OP_AND
;
1020 else if (!strcmp(argv
[i
], ")"))
1022 if (num_parens
<= 0)
1024 _cupsLangPuts(stderr
, _("ippfind: Missing open parenthesis."));
1028 current
= parens
[--num_parens
];
1029 parent
= current
->parent
;
1031 logic
= IPPFIND_OP_AND
;
1033 else if (!strcmp(argv
[i
], "!"))
1040 * _regtype._tcp[,subtype][.domain]
1044 * service-name[._regtype._tcp[.domain]]
1047 cupsArrayAdd(searches
, argv
[i
]);
1053 _cupsLangPuts(stderr
, _("ippfind: Missing close parenthesis."));
1060 * Add an implicit --print-uri to the end...
1063 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, 0, NULL
, NULL
, NULL
)) == NULL
)
1064 return (IPPFIND_EXIT_MEMORY
);
1068 while (current
->parent
)
1069 current
= current
->parent
;
1071 current
->next
= temp
;
1072 temp
->prev
= current
;
1078 if (cupsArrayCount(searches
) == 0)
1081 * Add an implicit browse for IPP printers ("_ipp._tcp")...
1084 cupsArrayAdd(searches
, "_ipp._tcp");
1087 if (getenv("IPPFIND_DEBUG"))
1089 int indent
= 4; /* Indentation */
1091 puts("Expression tree:");
1092 current
= expressions
;
1096 * Print the current node...
1099 printf("%*s%s%s\n", indent
, "", current
->invert
? "!" : "",
1103 * Advance to the next node...
1108 current
= current
->child
;
1111 else if (current
->next
)
1112 current
= current
->next
;
1113 else if (current
->parent
)
1115 while (current
->parent
)
1118 current
= current
->parent
;
1123 current
= current
->next
;
1129 puts("\nSearch items:");
1130 for (search
= (const char *)cupsArrayFirst(searches
);
1132 search
= (const char *)cupsArrayNext(searches
))
1133 printf(" %s\n", search
);
1137 * Start up browsing/resolving...
1141 if ((err
= DNSServiceCreateConnection(&dnssd_ref
)) != kDNSServiceErr_NoError
)
1143 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1144 dnssd_error_string(err
));
1145 return (IPPFIND_EXIT_BONJOUR
);
1148 #elif defined(HAVE_AVAHI)
1149 if ((avahi_poll
= avahi_simple_poll_new()) == NULL
)
1151 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1153 return (IPPFIND_EXIT_BONJOUR
);
1156 avahi_simple_poll_set_func(avahi_poll
, poll_callback
, NULL
);
1158 avahi_client
= avahi_client_new(avahi_simple_poll_get(avahi_poll
),
1159 0, client_callback
, avahi_poll
, &err
);
1162 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1163 dnssd_error_string(err
));
1164 return (IPPFIND_EXIT_BONJOUR
);
1166 #endif /* HAVE_DNSSD */
1168 for (search
= (const char *)cupsArrayFirst(searches
);
1170 search
= (const char *)cupsArrayNext(searches
))
1172 char buf
[1024], /* Full name string */
1173 *name
= NULL
, /* Service instance name */
1174 *regtype
, /* Registration type */
1175 *domain
; /* Domain, if any */
1177 strlcpy(buf
, search
, sizeof(buf
));
1182 else if ((regtype
= strstr(buf
, "._")) != NULL
)
1190 regtype
= "_ipp._tcp";
1193 for (domain
= regtype
; *domain
; domain
++)
1194 if (*domain
== '.' && domain
[1] != '_')
1206 * Resolve the given service instance name, regtype, and domain...
1212 service
= get_service(services
, name
, regtype
, domain
);
1215 service
->ref
= dnssd_ref
;
1216 err
= DNSServiceResolve(&(service
->ref
),
1217 kDNSServiceFlagsShareConnection
, 0, name
,
1218 regtype
, domain
, resolve_callback
,
1221 #elif defined(HAVE_AVAHI)
1222 service
->ref
= avahi_service_resolver_new(avahi_client
, AVAHI_IF_UNSPEC
,
1223 AVAHI_PROTO_UNSPEC
, name
,
1225 AVAHI_PROTO_UNSPEC
, 0,
1226 resolve_callback
, service
);
1230 err
= avahi_client_errno(avahi_client
);
1231 #endif /* HAVE_DNSSD */
1236 * Browse for services of the given type...
1240 DNSServiceRef ref
; /* Browse reference */
1243 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
, 0, regtype
,
1244 domain
, browse_callback
, services
);
1249 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
,
1250 kDNSServiceInterfaceIndexLocalOnly
, regtype
,
1251 domain
, browse_local_callback
, services
);
1254 #elif defined(HAVE_AVAHI)
1255 if (avahi_service_browser_new(avahi_client
, AVAHI_IF_UNSPEC
,
1256 AVAHI_PROTO_UNSPEC
, regtype
, domain
, 0,
1257 browse_callback
, services
))
1260 err
= avahi_client_errno(avahi_client
);
1261 #endif /* HAVE_DNSSD */
1266 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
1267 dnssd_error_string(err
));
1270 printf("name=\"%s\"\n", name
);
1272 printf("regtype=\"%s\"\n", regtype
);
1275 printf("domain=\"%s\"\n", domain
);
1277 return (IPPFIND_EXIT_BONJOUR
);
1282 * Process browse/resolve requests...
1285 if (bonjour_timeout
> 1.0)
1286 endtime
= get_time() + bonjour_timeout
;
1288 endtime
= get_time() + 300.0;
1290 while (get_time() < endtime
)
1292 int process
= 0; /* Process services? */
1295 int fd
= DNSServiceRefSockFD(dnssd_ref
);
1296 /* File descriptor for DNS-SD */
1299 FD_SET(fd
, &sinput
);
1301 stimeout
.tv_sec
= 0;
1302 stimeout
.tv_usec
= 500000;
1304 if (select(fd
+ 1, &sinput
, NULL
, NULL
, &stimeout
) < 0)
1307 if (FD_ISSET(fd
, &sinput
))
1310 * Process responses...
1313 DNSServiceProcessResult(dnssd_ref
);
1318 * Time to process services...
1324 #elif defined(HAVE_AVAHI)
1327 if (avahi_simple_poll_iterate(avahi_poll
, 500) > 0)
1330 * We've been told to exit the loop. Perhaps the connection to
1334 return (IPPFIND_EXIT_BONJOUR
);
1337 if (!avahi_got_data
)
1340 * Time to process services...
1345 #endif /* HAVE_DNSSD */
1350 * Process any services that we have found...
1353 int active
= 0, /* Number of active resolves */
1354 resolved
= 0, /* Number of resolved services */
1355 processed
= 0; /* Number of processed services */
1357 for (service
= (ippfind_srv_t
*)cupsArrayFirst(services
);
1359 service
= (ippfind_srv_t
*)cupsArrayNext(services
))
1361 if (service
->is_processed
)
1364 if (service
->is_resolved
)
1367 if (!service
->ref
&& !service
->is_resolved
)
1370 * Found a service, now resolve it (but limit to 50 active resolves...)
1376 service
->ref
= dnssd_ref
;
1377 err
= DNSServiceResolve(&(service
->ref
),
1378 kDNSServiceFlagsShareConnection
, 0,
1379 service
->name
, service
->regtype
,
1380 service
->domain
, resolve_callback
,
1383 #elif defined(HAVE_AVAHI)
1384 service
->ref
= avahi_service_resolver_new(avahi_client
,
1390 AVAHI_PROTO_UNSPEC
, 0,
1396 err
= avahi_client_errno(avahi_client
);
1397 #endif /* HAVE_DNSSD */
1401 _cupsLangPrintf(stderr
,
1402 _("ippfind: Unable to browse or resolve: %s"),
1403 dnssd_error_string(err
));
1404 return (IPPFIND_EXIT_BONJOUR
);
1410 else if (service
->is_resolved
&& !service
->is_processed
)
1413 * Resolved, not process this service against the expressions...
1419 DNSServiceRefDeallocate(service
->ref
);
1421 avahi_service_resolver_free(service
->ref
);
1422 #endif /* HAVE_DNSSD */
1424 service
->ref
= NULL
;
1427 if (eval_expr(service
, expressions
))
1428 status
= IPPFIND_EXIT_TRUE
;
1430 service
->is_processed
= 1;
1432 else if (service
->ref
)
1437 * If we have processed all services we have discovered, then we are done.
1440 if (processed
== cupsArrayCount(services
) && bonjour_timeout
<= 1.0)
1446 return (IPPFIND_EXIT_BONJOUR
);
1454 * 'browse_callback()' - Browse devices.
1457 static void DNSSD_API
1459 DNSServiceRef sdRef
, /* I - Service reference */
1460 DNSServiceFlags flags
, /* I - Option flags */
1461 uint32_t interfaceIndex
, /* I - Interface number */
1462 DNSServiceErrorType errorCode
, /* I - Error, if any */
1463 const char *serviceName
, /* I - Name of service/device */
1464 const char *regtype
, /* I - Type of service */
1465 const char *replyDomain
, /* I - Service domain */
1466 void *context
) /* I - Services array */
1469 * Only process "add" data...
1473 (void)interfaceIndex
;
1475 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1482 get_service((cups_array_t
*)context
, serviceName
, regtype
, replyDomain
);
1487 * 'browse_local_callback()' - Browse local devices.
1490 static void DNSSD_API
1491 browse_local_callback(
1492 DNSServiceRef sdRef
, /* I - Service reference */
1493 DNSServiceFlags flags
, /* I - Option flags */
1494 uint32_t interfaceIndex
, /* I - Interface number */
1495 DNSServiceErrorType errorCode
, /* I - Error, if any */
1496 const char *serviceName
, /* I - Name of service/device */
1497 const char *regtype
, /* I - Type of service */
1498 const char *replyDomain
, /* I - Service domain */
1499 void *context
) /* I - Services array */
1501 ippfind_srv_t
*service
; /* Service */
1505 * Only process "add" data...
1509 (void)interfaceIndex
;
1511 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1518 service
= get_service((cups_array_t
*)context
, serviceName
, regtype
,
1520 service
->is_local
= 1;
1522 #endif /* HAVE_DNSSD */
1527 * 'browse_callback()' - Browse devices.
1532 AvahiServiceBrowser
*browser
, /* I - Browser */
1533 AvahiIfIndex interface
, /* I - Interface index (unused) */
1534 AvahiProtocol protocol
, /* I - Network protocol (unused) */
1535 AvahiBrowserEvent event
, /* I - What happened */
1536 const char *name
, /* I - Service name */
1537 const char *type
, /* I - Registration type */
1538 const char *domain
, /* I - Domain */
1539 AvahiLookupResultFlags flags
, /* I - Flags */
1540 void *context
) /* I - Services array */
1542 AvahiClient
*client
= avahi_service_browser_get_client(browser
);
1543 /* Client information */
1544 ippfind_srv_t
*service
; /* Service information */
1553 case AVAHI_BROWSER_FAILURE
:
1554 fprintf(stderr
, "DEBUG: browse_callback: %s\n",
1555 avahi_strerror(avahi_client_errno(client
)));
1557 avahi_simple_poll_quit(avahi_poll
);
1560 case AVAHI_BROWSER_NEW
:
1562 * This object is new on the network. Create a device entry for it if
1563 * it doesn't yet exist.
1566 service
= get_service((cups_array_t
*)context
, name
, type
, domain
);
1568 if (flags
& AVAHI_LOOKUP_RESULT_LOCAL
)
1569 service
->is_local
= 1;
1572 case AVAHI_BROWSER_REMOVE
:
1573 case AVAHI_BROWSER_ALL_FOR_NOW
:
1574 case AVAHI_BROWSER_CACHE_EXHAUSTED
:
1581 * 'client_callback()' - Avahi client callback function.
1586 AvahiClient
*client
, /* I - Client information (unused) */
1587 AvahiClientState state
, /* I - Current state */
1588 void *context
) /* I - User data (unused) */
1594 * If the connection drops, quit.
1597 if (state
== AVAHI_CLIENT_FAILURE
)
1599 fputs("DEBUG: Avahi connection failed.\n", stderr
);
1601 avahi_simple_poll_quit(avahi_poll
);
1604 #endif /* HAVE_AVAHI */
1608 * 'compare_services()' - Compare two devices.
1611 static int /* O - Result of comparison */
1612 compare_services(ippfind_srv_t
*a
, /* I - First device */
1613 ippfind_srv_t
*b
) /* I - Second device */
1615 return (strcmp(a
->name
, b
->name
));
1620 * 'dnssd_error_string()' - Return an error string for an error code.
1623 static const char * /* O - Error message */
1624 dnssd_error_string(int error
) /* I - Error number */
1629 case kDNSServiceErr_NoError
:
1633 case kDNSServiceErr_Unknown
:
1634 return ("Unknown error.");
1636 case kDNSServiceErr_NoSuchName
:
1637 return ("Service not found.");
1639 case kDNSServiceErr_NoMemory
:
1640 return ("Out of memory.");
1642 case kDNSServiceErr_BadParam
:
1643 return ("Bad parameter.");
1645 case kDNSServiceErr_BadReference
:
1646 return ("Bad service reference.");
1648 case kDNSServiceErr_BadState
:
1649 return ("Bad state.");
1651 case kDNSServiceErr_BadFlags
:
1652 return ("Bad flags.");
1654 case kDNSServiceErr_Unsupported
:
1655 return ("Unsupported.");
1657 case kDNSServiceErr_NotInitialized
:
1658 return ("Not initialized.");
1660 case kDNSServiceErr_AlreadyRegistered
:
1661 return ("Already registered.");
1663 case kDNSServiceErr_NameConflict
:
1664 return ("Name conflict.");
1666 case kDNSServiceErr_Invalid
:
1667 return ("Invalid name.");
1669 case kDNSServiceErr_Firewall
:
1670 return ("Firewall prevents registration.");
1672 case kDNSServiceErr_Incompatible
:
1673 return ("Client library incompatible.");
1675 case kDNSServiceErr_BadInterfaceIndex
:
1676 return ("Bad interface index.");
1678 case kDNSServiceErr_Refused
:
1679 return ("Server prevents registration.");
1681 case kDNSServiceErr_NoSuchRecord
:
1682 return ("Record not found.");
1684 case kDNSServiceErr_NoAuth
:
1685 return ("Authentication required.");
1687 case kDNSServiceErr_NoSuchKey
:
1688 return ("Encryption key not found.");
1690 case kDNSServiceErr_NATTraversal
:
1691 return ("Unable to traverse NAT boundary.");
1693 case kDNSServiceErr_DoubleNAT
:
1694 return ("Unable to traverse double-NAT boundary.");
1696 case kDNSServiceErr_BadTime
:
1697 return ("Bad system time.");
1699 case kDNSServiceErr_BadSig
:
1700 return ("Bad signature.");
1702 case kDNSServiceErr_BadKey
:
1703 return ("Bad encryption key.");
1705 case kDNSServiceErr_Transient
:
1706 return ("Transient error occurred - please try again.");
1708 case kDNSServiceErr_ServiceNotRunning
:
1709 return ("Server not running.");
1711 case kDNSServiceErr_NATPortMappingUnsupported
:
1712 return ("NAT doesn't support NAT-PMP or UPnP.");
1714 case kDNSServiceErr_NATPortMappingDisabled
:
1715 return ("NAT supports NAT-PNP or UPnP but it is disabled.");
1717 case kDNSServiceErr_NoRouter
:
1718 return ("No Internet/default router configured.");
1720 case kDNSServiceErr_PollingMode
:
1721 return ("Service polling mode error.");
1724 case kDNSServiceErr_Timeout
:
1725 return ("Service timeout.");
1729 # elif defined(HAVE_AVAHI)
1730 return (avahi_strerror(error
));
1731 # endif /* HAVE_DNSSD */
1736 * 'eval_expr()' - Evaluate the expressions against the specified service.
1738 * Returns 1 for true and 0 for false.
1741 static int /* O - Result of evaluation */
1742 eval_expr(ippfind_srv_t
*service
, /* I - Service */
1743 ippfind_expr_t
*expressions
) /* I - Expressions */
1745 int logic
, /* Logical operation */
1746 result
; /* Result of current expression */
1747 ippfind_expr_t
*expression
; /* Current expression */
1748 const char *val
; /* TXT value */
1751 * Loop through the expressions...
1754 if (expressions
&& expressions
->parent
)
1755 logic
= expressions
->parent
->op
;
1757 logic
= IPPFIND_OP_AND
;
1759 for (expression
= expressions
; expression
; expression
= expression
->next
)
1761 switch (expression
->op
)
1764 case IPPFIND_OP_AND
:
1765 case IPPFIND_OP_OR
:
1766 if (expression
->child
)
1767 result
= eval_expr(service
, expression
->child
);
1769 result
= expression
->op
== IPPFIND_OP_AND
;
1771 case IPPFIND_OP_TRUE
:
1774 case IPPFIND_OP_FALSE
:
1777 case IPPFIND_OP_IS_LOCAL
:
1778 result
= service
->is_local
;
1780 case IPPFIND_OP_IS_REMOTE
:
1781 result
= !service
->is_local
;
1783 case IPPFIND_OP_DOMAIN_REGEX
:
1784 result
= !regexec(&(expression
->re
), service
->domain
, 0, NULL
, 0);
1786 case IPPFIND_OP_NAME_REGEX
:
1787 result
= !regexec(&(expression
->re
), service
->name
, 0, NULL
, 0);
1789 case IPPFIND_OP_HOST_REGEX
:
1790 result
= !regexec(&(expression
->re
), service
->host
, 0, NULL
, 0);
1792 case IPPFIND_OP_PORT_RANGE
:
1793 result
= service
->port
>= expression
->range
[0] &&
1794 service
->port
<= expression
->range
[1];
1796 case IPPFIND_OP_PATH_REGEX
:
1797 result
= !regexec(&(expression
->re
), service
->resource
, 0, NULL
, 0);
1799 case IPPFIND_OP_TXT_EXISTS
:
1800 result
= cupsGetOption(expression
->key
, service
->num_txt
,
1801 service
->txt
) != NULL
;
1803 case IPPFIND_OP_TXT_REGEX
:
1804 val
= cupsGetOption(expression
->key
, service
->num_txt
,
1807 result
= !regexec(&(expression
->re
), val
, 0, NULL
, 0);
1811 if (getenv("IPPFIND_DEBUG"))
1812 printf("TXT_REGEX of \"%s\": %d\n", val
, result
);
1814 case IPPFIND_OP_URI_REGEX
:
1815 result
= !regexec(&(expression
->re
), service
->uri
, 0, NULL
, 0);
1817 case IPPFIND_OP_EXEC
:
1818 result
= exec_program(service
, expression
->num_args
,
1821 case IPPFIND_OP_LIST
:
1822 result
= list_service(service
);
1824 case IPPFIND_OP_PRINT_NAME
:
1825 _cupsLangPuts(stdout
, service
->name
);
1828 case IPPFIND_OP_PRINT_URI
:
1829 _cupsLangPuts(stdout
, service
->uri
);
1832 case IPPFIND_OP_QUIET
:
1837 if (expression
->invert
)
1840 if (logic
== IPPFIND_OP_AND
&& !result
)
1842 else if (logic
== IPPFIND_OP_OR
&& result
)
1846 return (logic
== IPPFIND_OP_AND
);
1851 * 'exec_program()' - Execute a program for a service.
1854 static int /* O - 1 if program terminated
1855 successfully, 0 otherwise. */
1856 exec_program(ippfind_srv_t
*service
, /* I - Service */
1857 int num_args
, /* I - Number of command-line args */
1858 char **args
) /* I - Command-line arguments */
1860 char **myargv
, /* Command-line arguments */
1861 **myenvp
, /* Environment variables */
1862 *ptr
, /* Pointer into variable */
1863 domain
[1024], /* IPPFIND_SERVICE_DOMAIN */
1864 hostname
[1024], /* IPPFIND_SERVICE_HOSTNAME */
1865 name
[256], /* IPPFIND_SERVICE_NAME */
1866 port
[32], /* IPPFIND_SERVICE_PORT */
1867 regtype
[256], /* IPPFIND_SERVICE_REGTYPE */
1868 scheme
[128], /* IPPFIND_SERVICE_SCHEME */
1869 uri
[1024], /* IPPFIND_SERVICE_URI */
1870 txt
[100][256]; /* IPPFIND_TXT_foo */
1871 int i
, /* Looping var */
1872 myenvc
, /* Number of environment variables */
1873 status
; /* Exit status of program */
1875 char program
[1024]; /* Program to execute */
1876 int pid
; /* Process ID */
1881 * Environment variables...
1884 snprintf(domain
, sizeof(domain
), "IPPFIND_SERVICE_DOMAIN=%s",
1886 snprintf(hostname
, sizeof(hostname
), "IPPFIND_SERVICE_HOSTNAME=%s",
1888 snprintf(name
, sizeof(name
), "IPPFIND_SERVICE_NAME=%s", service
->name
);
1889 snprintf(port
, sizeof(port
), "IPPFIND_SERVICE_PORT=%d", service
->port
);
1890 snprintf(regtype
, sizeof(regtype
), "IPPFIND_SERVICE_REGTYPE=%s",
1892 snprintf(scheme
, sizeof(scheme
), "IPPFIND_SERVICE_SCHEME=%s",
1893 !strncmp(service
->regtype
, "_http._tcp", 10) ? "http" :
1894 !strncmp(service
->regtype
, "_https._tcp", 11) ? "https" :
1895 !strncmp(service
->regtype
, "_ipp._tcp", 9) ? "ipp" :
1896 !strncmp(service
->regtype
, "_ipps._tcp", 10) ? "ipps" : "lpd");
1897 snprintf(uri
, sizeof(uri
), "IPPFIND_SERVICE_URI=%s", service
->uri
);
1898 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1900 snprintf(txt
[i
], sizeof(txt
[i
]), "IPPFIND_TXT_%s=%s", service
->txt
[i
].name
,
1901 service
->txt
[i
].value
);
1902 for (ptr
= txt
[i
] + 12; *ptr
&& *ptr
!= '='; ptr
++)
1903 *ptr
= (char)_cups_toupper(*ptr
);
1906 for (i
= 0, myenvc
= 7 + service
->num_txt
; environ
[i
]; i
++)
1907 if (strncmp(environ
[i
], "IPPFIND_", 8))
1910 if ((myenvp
= calloc(sizeof(char *), (size_t)(myenvc
+ 1))) == NULL
)
1912 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1913 exit(IPPFIND_EXIT_MEMORY
);
1916 for (i
= 0, myenvc
= 0; environ
[i
]; i
++)
1917 if (strncmp(environ
[i
], "IPPFIND_", 8))
1918 myenvp
[myenvc
++] = environ
[i
];
1920 myenvp
[myenvc
++] = domain
;
1921 myenvp
[myenvc
++] = hostname
;
1922 myenvp
[myenvc
++] = name
;
1923 myenvp
[myenvc
++] = port
;
1924 myenvp
[myenvc
++] = regtype
;
1925 myenvp
[myenvc
++] = scheme
;
1926 myenvp
[myenvc
++] = uri
;
1928 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1929 myenvp
[myenvc
++] = txt
[i
];
1932 * Allocate and copy command-line arguments...
1935 if ((myargv
= calloc(sizeof(char *), (size_t)(num_args
+ 1))) == NULL
)
1937 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1938 exit(IPPFIND_EXIT_MEMORY
);
1941 for (i
= 0; i
< num_args
; i
++)
1943 if (strchr(args
[i
], '{'))
1945 char temp
[2048], /* Temporary string */
1946 *tptr
, /* Pointer into temporary string */
1947 keyword
[256], /* {keyword} */
1948 *kptr
; /* Pointer into keyword */
1950 for (ptr
= args
[i
], tptr
= temp
; *ptr
; ptr
++)
1955 * Do a {var} substitution...
1958 for (kptr
= keyword
, ptr
++; *ptr
&& *ptr
!= '}'; ptr
++)
1959 if (kptr
< (keyword
+ sizeof(keyword
) - 1))
1964 _cupsLangPuts(stderr
,
1965 _("ippfind: Missing close brace in substitution."));
1966 exit(IPPFIND_EXIT_SYNTAX
);
1970 if (!keyword
[0] || !strcmp(keyword
, "service_uri"))
1971 strlcpy(tptr
, service
->uri
, sizeof(temp
) - (size_t)(tptr
- temp
));
1972 else if (!strcmp(keyword
, "service_domain"))
1973 strlcpy(tptr
, service
->domain
, sizeof(temp
) - (size_t)(tptr
- temp
));
1974 else if (!strcmp(keyword
, "service_hostname"))
1975 strlcpy(tptr
, service
->host
, sizeof(temp
) - (size_t)(tptr
- temp
));
1976 else if (!strcmp(keyword
, "service_name"))
1977 strlcpy(tptr
, service
->name
, sizeof(temp
) - (size_t)(tptr
- temp
));
1978 else if (!strcmp(keyword
, "service_path"))
1979 strlcpy(tptr
, service
->resource
, sizeof(temp
) - (size_t)(tptr
- temp
));
1980 else if (!strcmp(keyword
, "service_port"))
1981 strlcpy(tptr
, port
+ 21, sizeof(temp
) - (size_t)(tptr
- temp
));
1982 else if (!strcmp(keyword
, "service_scheme"))
1983 strlcpy(tptr
, scheme
+ 22, sizeof(temp
) - (size_t)(tptr
- temp
));
1984 else if (!strncmp(keyword
, "txt_", 4))
1986 const char *txt
= cupsGetOption(keyword
+ 4, service
->num_txt
, service
->txt
);
1988 strlcpy(tptr
, txt
, sizeof(temp
) - (size_t)(tptr
- temp
));
1994 _cupsLangPrintf(stderr
, _("ippfind: Unknown variable \"{%s}\"."),
1996 exit(IPPFIND_EXIT_SYNTAX
);
1999 tptr
+= strlen(tptr
);
2001 else if (tptr
< (temp
+ sizeof(temp
) - 1))
2006 myargv
[i
] = strdup(temp
);
2009 myargv
[i
] = strdup(args
[i
]);
2013 if (getenv("IPPFIND_DEBUG"))
2015 printf("\nProgram:\n %s\n", args
[0]);
2016 puts("\nArguments:");
2017 for (i
= 0; i
< num_args
; i
++)
2018 printf(" %s\n", myargv
[i
]);
2019 puts("\nEnvironment:");
2020 for (i
= 0; i
< myenvc
; i
++)
2021 printf(" %s\n", myenvp
[i
]);
2024 status
= _spawnvpe(_P_WAIT
, args
[0], myargv
, myenvp
);
2028 * Execute the program...
2031 if (strchr(args
[0], '/') && !access(args
[0], X_OK
))
2032 strlcpy(program
, args
[0], sizeof(program
));
2033 else if (!cupsFileFind(args
[0], getenv("PATH"), 1, program
, sizeof(program
)))
2035 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2036 args
[0], strerror(ENOENT
));
2037 exit(IPPFIND_EXIT_SYNTAX
);
2040 if (getenv("IPPFIND_DEBUG"))
2042 printf("\nProgram:\n %s\n", program
);
2043 puts("\nArguments:");
2044 for (i
= 0; i
< num_args
; i
++)
2045 printf(" %s\n", myargv
[i
]);
2046 puts("\nEnvironment:");
2047 for (i
= 0; i
< myenvc
; i
++)
2048 printf(" %s\n", myenvp
[i
]);
2051 if ((pid
= fork()) == 0)
2054 * Child comes here...
2057 execve(program
, myargv
, myenvp
);
2062 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2063 args
[0], strerror(errno
));
2064 exit(IPPFIND_EXIT_SYNTAX
);
2069 * Wait for it to complete...
2072 while (wait(&status
) != pid
)
2081 for (i
= 0; i
< num_args
; i
++)
2088 * Return whether the program succeeded or crashed...
2091 if (getenv("IPPFIND_DEBUG"))
2094 printf("Exit Status: %d\n", status
);
2096 if (WIFEXITED(status
))
2097 printf("Exit Status: %d\n", WEXITSTATUS(status
));
2099 printf("Terminating Signal: %d\n", WTERMSIG(status
));
2103 return (status
== 0);
2108 * 'get_service()' - Create or update a device.
2111 static ippfind_srv_t
* /* O - Service */
2112 get_service(cups_array_t
*services
, /* I - Service array */
2113 const char *serviceName
, /* I - Name of service/device */
2114 const char *regtype
, /* I - Type of service */
2115 const char *replyDomain
) /* I - Service domain */
2117 ippfind_srv_t key
, /* Search key */
2118 *service
; /* Service */
2119 char fullName
[kDNSServiceMaxDomainName
];
2120 /* Full name for query */
2124 * See if this is a new device...
2127 key
.name
= (char *)serviceName
;
2128 key
.regtype
= (char *)regtype
;
2130 for (service
= cupsArrayFind(services
, &key
);
2132 service
= cupsArrayNext(services
))
2133 if (_cups_strcasecmp(service
->name
, key
.name
))
2135 else if (!strcmp(service
->regtype
, key
.regtype
))
2139 * Yes, add the service...
2142 service
= calloc(sizeof(ippfind_srv_t
), 1);
2143 service
->name
= strdup(serviceName
);
2144 service
->domain
= strdup(replyDomain
);
2145 service
->regtype
= strdup(regtype
);
2147 cupsArrayAdd(services
, service
);
2150 * Set the "full name" of this service, which is used for queries and
2155 DNSServiceConstructFullName(fullName
, serviceName
, regtype
, replyDomain
);
2156 #else /* HAVE_AVAHI */
2157 avahi_service_name_join(fullName
, kDNSServiceMaxDomainName
, serviceName
,
2158 regtype
, replyDomain
);
2159 #endif /* HAVE_DNSSD */
2161 service
->fullName
= strdup(fullName
);
2168 * 'get_time()' - Get the current time-of-day in seconds.
2175 struct _timeb curtime
; /* Current Windows time */
2179 return (curtime
.time
+ 0.001 * curtime
.millitm
);
2182 struct timeval curtime
; /* Current UNIX time */
2184 if (gettimeofday(&curtime
, NULL
))
2187 return (curtime
.tv_sec
+ 0.000001 * curtime
.tv_usec
);
2193 * 'list_service()' - List the contents of a service.
2196 static int /* O - 1 if successful, 0 otherwise */
2197 list_service(ippfind_srv_t
*service
) /* I - Service */
2199 http_addrlist_t
*addrlist
; /* Address(es) of service */
2200 char port
[10]; /* Port number of service */
2203 snprintf(port
, sizeof(port
), "%d", service
->port
);
2205 if ((addrlist
= httpAddrGetList(service
->host
, address_family
, port
)) == NULL
)
2207 _cupsLangPrintf(stdout
, "%s unreachable", service
->uri
);
2211 if (!strncmp(service
->regtype
, "_ipp._tcp", 9) ||
2212 !strncmp(service
->regtype
, "_ipps._tcp", 10))
2218 http_t
*http
; /* HTTP connection */
2219 ipp_t
*request
, /* IPP request */
2220 *response
; /* IPP response */
2221 ipp_attribute_t
*attr
; /* IPP attribute */
2222 int i
, /* Looping var */
2223 count
, /* Number of values */
2224 version
, /* IPP version */
2225 paccepting
; /* printer-is-accepting-jobs value */
2226 ipp_pstate_t pstate
; /* printer-state value */
2227 char preasons
[1024], /* Comma-delimited printer-state-reasons */
2228 *ptr
, /* Pointer into reasons */
2229 *end
; /* End of reasons buffer */
2230 static const char * const rattrs
[] =/* Requested attributes */
2232 "printer-is-accepting-jobs",
2234 "printer-state-reasons"
2238 * Connect to the printer...
2241 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2242 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2243 HTTP_ENCRYPTION_ALWAYS
:
2244 HTTP_ENCRYPTION_IF_REQUESTED
,
2247 httpAddrFreeList(addrlist
);
2251 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2256 * Get the current printer state...
2260 version
= ipp_version
;
2264 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
2265 ippSetVersion(request
, version
/ 10, version
% 10);
2266 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
2268 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
2269 "requesting-user-name", NULL
, cupsUser());
2270 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
2271 "requested-attributes",
2272 (int)(sizeof(rattrs
) / sizeof(rattrs
[0])), NULL
, rattrs
);
2274 response
= cupsDoRequest(http
, request
, service
->resource
);
2276 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
&& version
> 11)
2279 while (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
&& version
> 11);
2285 if (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
)
2287 _cupsLangPrintf(stdout
, "%s: unavailable", service
->uri
);
2291 if ((attr
= ippFindAttribute(response
, "printer-state",
2292 IPP_TAG_ENUM
)) != NULL
)
2293 pstate
= (ipp_pstate_t
)ippGetInteger(attr
, 0);
2295 pstate
= IPP_PSTATE_STOPPED
;
2297 if ((attr
= ippFindAttribute(response
, "printer-is-accepting-jobs",
2298 IPP_TAG_BOOLEAN
)) != NULL
)
2299 paccepting
= ippGetBoolean(attr
, 0);
2303 if ((attr
= ippFindAttribute(response
, "printer-state-reasons",
2304 IPP_TAG_KEYWORD
)) != NULL
)
2306 strlcpy(preasons
, ippGetString(attr
, 0, NULL
), sizeof(preasons
));
2308 for (i
= 1, count
= ippGetCount(attr
), ptr
= preasons
+ strlen(preasons
),
2309 end
= preasons
+ sizeof(preasons
) - 1;
2310 i
< count
&& ptr
< end
;
2311 i
++, ptr
+= strlen(ptr
))
2314 strlcpy(ptr
, ippGetString(attr
, i
, NULL
), (size_t)(end
- ptr
+ 1));
2318 strlcpy(preasons
, "none", sizeof(preasons
));
2320 ippDelete(response
);
2323 _cupsLangPrintf(stdout
, "%s %s %s %s", service
->uri
,
2324 ippEnumString("printer-state", pstate
),
2325 paccepting
? "accepting-jobs" : "not-accepting-jobs",
2328 else if (!strncmp(service
->regtype
, "_http._tcp", 10) ||
2329 !strncmp(service
->regtype
, "_https._tcp", 11))
2332 * HTTP/HTTPS web page
2335 http_t
*http
; /* HTTP connection */
2336 http_status_t status
; /* HEAD status */
2340 * Connect to the web server...
2343 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2344 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2345 HTTP_ENCRYPTION_ALWAYS
:
2346 HTTP_ENCRYPTION_IF_REQUESTED
,
2349 httpAddrFreeList(addrlist
);
2353 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2357 if (httpGet(http
, service
->resource
))
2359 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2365 status
= httpUpdate(http
);
2367 while (status
== HTTP_STATUS_CONTINUE
);
2372 if (status
>= HTTP_STATUS_BAD_REQUEST
)
2374 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2378 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2380 else if (!strncmp(service
->regtype
, "_printer._tcp", 13))
2386 int sock
; /* Socket */
2389 if (!httpAddrConnect(addrlist
, &sock
))
2391 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2392 httpAddrFreeList(addrlist
);
2396 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2397 httpAddrFreeList(addrlist
);
2399 httpAddrClose(NULL
, sock
);
2403 _cupsLangPrintf(stdout
, "%s unsupported", service
->uri
);
2404 httpAddrFreeList(addrlist
);
2413 * 'new_expr()' - Create a new expression.
2416 static ippfind_expr_t
* /* O - New expression */
2417 new_expr(ippfind_op_t op
, /* I - Operation */
2418 int invert
, /* I - Invert result? */
2419 const char *value
, /* I - TXT key or port range */
2420 const char *regex
, /* I - Regular expression */
2421 char **args
) /* I - Pointer to argument strings */
2423 ippfind_expr_t
*temp
; /* New expression */
2426 if ((temp
= calloc(1, sizeof(ippfind_expr_t
))) == NULL
)
2430 temp
->invert
= invert
;
2432 if (op
== IPPFIND_OP_TXT_EXISTS
|| op
== IPPFIND_OP_TXT_REGEX
)
2433 temp
->key
= (char *)value
;
2434 else if (op
== IPPFIND_OP_PORT_RANGE
)
2437 * Pull port number range of the form "number", "-number" (0-number),
2438 * "number-" (number-65535), and "number-number".
2443 temp
->range
[1] = atoi(value
+ 1);
2445 else if (strchr(value
, '-'))
2447 if (sscanf(value
, "%d-%d", temp
->range
, temp
->range
+ 1) == 1)
2448 temp
->range
[1] = 65535;
2452 temp
->range
[0] = temp
->range
[1] = atoi(value
);
2458 int err
= regcomp(&(temp
->re
), regex
, REG_NOSUB
| REG_ICASE
| REG_EXTENDED
);
2462 char message
[256]; /* Error message */
2464 regerror(err
, &(temp
->re
), message
, sizeof(message
));
2465 _cupsLangPrintf(stderr
, _("ippfind: Bad regular expression: %s"),
2467 exit(IPPFIND_EXIT_SYNTAX
);
2473 int num_args
; /* Number of arguments */
2475 for (num_args
= 1; args
[num_args
]; num_args
++)
2476 if (!strcmp(args
[num_args
], ";"))
2479 temp
->num_args
= num_args
;
2480 temp
->args
= malloc((size_t)num_args
* sizeof(char *));
2481 memcpy(temp
->args
, args
, (size_t)num_args
* sizeof(char *));
2490 * 'poll_callback()' - Wait for input on the specified file descriptors.
2492 * Note: This function is needed because avahi_simple_poll_iterate is broken
2493 * and always uses a timeout of 0 (!) milliseconds.
2494 * (Avahi Ticket #364)
2497 static int /* O - Number of file descriptors matching */
2499 struct pollfd
*pollfds
, /* I - File descriptors */
2500 unsigned int num_pollfds
, /* I - Number of file descriptors */
2501 int timeout
, /* I - Timeout in milliseconds (unused) */
2502 void *context
) /* I - User data (unused) */
2504 int val
; /* Return value */
2510 val
= poll(pollfds
, num_pollfds
, 500);
2517 #endif /* HAVE_AVAHI */
2521 * 'resolve_callback()' - Process resolve data.
2525 static void DNSSD_API
2527 DNSServiceRef sdRef
, /* I - Service reference */
2528 DNSServiceFlags flags
, /* I - Data flags */
2529 uint32_t interfaceIndex
, /* I - Interface */
2530 DNSServiceErrorType errorCode
, /* I - Error, if any */
2531 const char *fullName
, /* I - Full service name */
2532 const char *hostTarget
, /* I - Hostname */
2533 uint16_t port
, /* I - Port number (network byte order) */
2534 uint16_t txtLen
, /* I - Length of TXT record data */
2535 const unsigned char *txtRecord
, /* I - TXT record data */
2536 void *context
) /* I - Service */
2538 char key
[256], /* TXT key value */
2539 *value
; /* Value from TXT record */
2540 const unsigned char *txtEnd
; /* End of TXT record */
2541 uint8_t valueLen
; /* Length of value */
2542 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2547 * Only process "add" data...
2552 (void)interfaceIndex
;
2555 if (errorCode
!= kDNSServiceErr_NoError
)
2557 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
2558 dnssd_error_string(errorCode
));
2563 service
->is_resolved
= 1;
2564 service
->host
= strdup(hostTarget
);
2565 service
->port
= ntohs(port
);
2567 value
= service
->host
+ strlen(service
->host
) - 1;
2568 if (value
>= service
->host
&& *value
== '.')
2572 * Loop through the TXT key/value pairs and add them to an array...
2575 for (txtEnd
= txtRecord
+ txtLen
; txtRecord
< txtEnd
; txtRecord
+= valueLen
)
2578 * Ignore bogus strings...
2581 valueLen
= *txtRecord
++;
2583 memcpy(key
, txtRecord
, valueLen
);
2584 key
[valueLen
] = '\0';
2586 if ((value
= strchr(key
, '=')) == NULL
)
2592 * Add to array of TXT values...
2595 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2599 set_service_uri(service
);
2603 #elif defined(HAVE_AVAHI)
2606 AvahiServiceResolver
*resolver
, /* I - Resolver */
2607 AvahiIfIndex interface
, /* I - Interface */
2608 AvahiProtocol protocol
, /* I - Address protocol */
2609 AvahiResolverEvent event
, /* I - Event */
2610 const char *serviceName
,/* I - Service name */
2611 const char *regtype
, /* I - Registration type */
2612 const char *replyDomain
,/* I - Domain name */
2613 const char *hostTarget
, /* I - FQDN */
2614 const AvahiAddress
*address
, /* I - Address */
2615 uint16_t port
, /* I - Port number */
2616 AvahiStringList
*txt
, /* I - TXT records */
2617 AvahiLookupResultFlags flags
, /* I - Lookup flags */
2618 void *context
) /* I - Service */
2620 char key
[256], /* TXT key */
2621 *value
; /* TXT value */
2622 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2624 AvahiStringList
*current
; /* Current TXT key/value pair */
2629 if (event
!= AVAHI_RESOLVER_FOUND
)
2633 avahi_service_resolver_free(resolver
);
2634 avahi_simple_poll_quit(avahi_poll
);
2638 service
->is_resolved
= 1;
2639 service
->host
= strdup(hostTarget
);
2640 service
->port
= port
;
2642 value
= service
->host
+ strlen(service
->host
) - 1;
2643 if (value
>= service
->host
&& *value
== '.')
2647 * Loop through the TXT key/value pairs and add them to an array...
2650 for (current
= txt
; current
; current
= current
->next
)
2653 * Ignore bogus strings...
2656 if (current
->size
> (sizeof(key
) - 1))
2659 memcpy(key
, current
->text
, current
->size
);
2660 key
[current
->size
] = '\0';
2662 if ((value
= strchr(key
, '=')) == NULL
)
2668 * Add to array of TXT values...
2671 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2675 set_service_uri(service
);
2677 #endif /* HAVE_DNSSD */
2681 * 'set_service_uri()' - Set the URI of the service.
2685 set_service_uri(ippfind_srv_t
*service
) /* I - Service */
2687 char uri
[1024]; /* URI */
2688 const char *path
, /* Resource path */
2689 *scheme
; /* URI scheme */
2692 if (!strncmp(service
->regtype
, "_http.", 6))
2695 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2697 else if (!strncmp(service
->regtype
, "_https.", 7))
2700 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2702 else if (!strncmp(service
->regtype
, "_ipp.", 5))
2705 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2707 else if (!strncmp(service
->regtype
, "_ipps.", 6))
2710 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2712 else if (!strncmp(service
->regtype
, "_printer.", 9))
2715 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2720 if (!path
|| !*path
)
2725 service
->resource
= strdup(path
);
2729 snprintf(uri
, sizeof(uri
), "/%s", path
);
2730 service
->resource
= strdup(uri
);
2733 httpAssembleURI(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), scheme
, NULL
,
2734 service
->host
, service
->port
, service
->resource
);
2735 service
->uri
= strdup(uri
);
2740 * 'show_usage()' - Show program usage.
2746 _cupsLangPuts(stderr
, _("Usage: ippfind [options] regtype[,subtype]"
2747 "[.domain.] ... [expression]\n"
2748 " ippfind [options] name[.regtype[.domain.]] "
2749 "... [expression]\n"
2751 " ippfind --version"));
2752 _cupsLangPuts(stderr
, "");
2753 _cupsLangPuts(stderr
, _("Options:"));
2754 _cupsLangPuts(stderr
, _(" -4 Connect using IPv4."));
2755 _cupsLangPuts(stderr
, _(" -6 Connect using IPv6."));
2756 _cupsLangPuts(stderr
, _(" -T seconds Set the browse timeout in "
2758 _cupsLangPuts(stderr
, _(" -V version Set default IPP "
2760 _cupsLangPuts(stderr
, _(" --help Show this help."));
2761 _cupsLangPuts(stderr
, _(" --version Show program version."));
2762 _cupsLangPuts(stderr
, "");
2763 _cupsLangPuts(stderr
, _("Expressions:"));
2764 _cupsLangPuts(stderr
, _(" -P number[-number] Match port to number or range."));
2765 _cupsLangPuts(stderr
, _(" -d regex Match domain to regular expression."));
2766 _cupsLangPuts(stderr
, _(" -h regex Match hostname to regular expression."));
2767 _cupsLangPuts(stderr
, _(" -l List attributes."));
2768 _cupsLangPuts(stderr
, _(" -n regex Match service name to regular expression."));
2769 _cupsLangPuts(stderr
, _(" -p Print URI if true."));
2770 _cupsLangPuts(stderr
, _(" -q Quietly report match via exit code."));
2771 _cupsLangPuts(stderr
, _(" -r True if service is remote."));
2772 _cupsLangPuts(stderr
, _(" -s Print service name if true."));
2773 _cupsLangPuts(stderr
, _(" -t key True if the TXT record contains the key."));
2774 _cupsLangPuts(stderr
, _(" -u regex Match URI to regular expression."));
2775 _cupsLangPuts(stderr
, _(" -x utility [argument ...] ;\n"
2776 " Execute program if true."));
2777 _cupsLangPuts(stderr
, _(" --domain regex Match domain to regular expression."));
2778 _cupsLangPuts(stderr
, _(" --exec utility [argument ...] ;\n"
2779 " Execute program if true."));
2780 _cupsLangPuts(stderr
, _(" --host regex Match hostname to regular expression."));
2781 _cupsLangPuts(stderr
, _(" --ls List attributes."));
2782 _cupsLangPuts(stderr
, _(" --local True if service is local."));
2783 _cupsLangPuts(stderr
, _(" --name regex Match service name to regular expression."));
2784 _cupsLangPuts(stderr
, _(" --path regex Match resource path to regular expression."));
2785 _cupsLangPuts(stderr
, _(" --port number[-number] Match port to number or range."));
2786 _cupsLangPuts(stderr
, _(" --print Print URI if true."));
2787 _cupsLangPuts(stderr
, _(" --print-name Print service name if true."));
2788 _cupsLangPuts(stderr
, _(" --quiet Quietly report match via exit code."));
2789 _cupsLangPuts(stderr
, _(" --remote True if service is remote."));
2790 _cupsLangPuts(stderr
, _(" --txt key True if the TXT record contains the key."));
2791 _cupsLangPuts(stderr
, _(" --txt-* regex Match TXT record key to regular expression."));
2792 _cupsLangPuts(stderr
, _(" --uri regex Match URI to regular expression."));
2793 _cupsLangPuts(stderr
, "");
2794 _cupsLangPuts(stderr
, _("Modifiers:"));
2795 _cupsLangPuts(stderr
, _(" ( expressions ) Group expressions."));
2796 _cupsLangPuts(stderr
, _(" ! expression Unary NOT of expression."));
2797 _cupsLangPuts(stderr
, _(" --not expression Unary NOT of expression."));
2798 _cupsLangPuts(stderr
, _(" --false Always false."));
2799 _cupsLangPuts(stderr
, _(" --true Always true."));
2800 _cupsLangPuts(stderr
, _(" expression expression Logical AND."));
2801 _cupsLangPuts(stderr
, _(" expression --and expression\n"
2803 _cupsLangPuts(stderr
, _(" expression --or expression\n"
2805 _cupsLangPuts(stderr
, "");
2806 _cupsLangPuts(stderr
, _("Substitutions:"));
2807 _cupsLangPuts(stderr
, _(" {} URI"));
2808 _cupsLangPuts(stderr
, _(" {service_domain} Domain name"));
2809 _cupsLangPuts(stderr
, _(" {service_hostname} Fully-qualified domain name"));
2810 _cupsLangPuts(stderr
, _(" {service_name} Service instance name"));
2811 _cupsLangPuts(stderr
, _(" {service_port} Port number"));
2812 _cupsLangPuts(stderr
, _(" {service_regtype} DNS-SD registration type"));
2813 _cupsLangPuts(stderr
, _(" {service_scheme} URI scheme"));
2814 _cupsLangPuts(stderr
, _(" {service_uri} URI"));
2815 _cupsLangPuts(stderr
, _(" {txt_*} Value of TXT record key"));
2816 _cupsLangPuts(stderr
, "");
2817 _cupsLangPuts(stderr
, _("Environment Variables:"));
2818 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_DOMAIN Domain name"));
2819 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_HOSTNAME\n"
2820 " Fully-qualified domain name"));
2821 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_NAME Service instance name"));
2822 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_PORT Port number"));
2823 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_REGTYPE DNS-SD registration type"));
2824 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_SCHEME URI scheme"));
2825 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_URI URI"));
2826 _cupsLangPuts(stderr
, _(" IPPFIND_TXT_* Value of TXT record key"));
2828 exit(IPPFIND_EXIT_TRUE
);
2833 * 'show_version()' - Show program version.
2839 _cupsLangPuts(stderr
, CUPS_SVERSION
);
2841 exit(IPPFIND_EXIT_TRUE
);
2846 * End of "$Id: ippfind.c 12639 2015-05-19 02:36:30Z msweet $".