2 * Utility to find IPP printers via Bonjour/DNS-SD and optionally run
3 * commands such as IPP and Bonjour conformance tests. This tool is
4 * inspired by the UNIX "find" command, thus its name.
6 * Copyright 2008-2017 by Apple Inc.
8 * Licensed under Apache License v2.0. See the file "LICENSE" for more
13 * Include necessary headers.
16 #define _CUPS_NO_DEPRECATED
17 #include <cups/cups-private.h>
20 # include <sys/timeb.h>
22 # include <sys/wait.h>
27 #elif defined(HAVE_AVAHI)
28 # include <avahi-client/client.h>
29 # include <avahi-client/lookup.h>
30 # include <avahi-common/simple-watch.h>
31 # include <avahi-common/domain.h>
32 # include <avahi-common/error.h>
33 # include <avahi-common/malloc.h>
34 # define kDNSServiceMaxDomainName AVAHI_DOMAIN_NAME_MAX
35 #endif /* HAVE_DNSSD */
38 extern char **environ
; /* Process environment variables */
46 typedef enum ippfind_exit_e
/* Exit codes */
48 IPPFIND_EXIT_TRUE
= 0, /* OK and result is true */
49 IPPFIND_EXIT_FALSE
, /* OK but result is false*/
50 IPPFIND_EXIT_BONJOUR
, /* Browse/resolve failure */
51 IPPFIND_EXIT_SYNTAX
, /* Bad option or syntax error */
52 IPPFIND_EXIT_MEMORY
/* Out of memory */
55 typedef enum ippfind_op_e
/* Operations for expressions */
57 /* "Evaluation" operations */
58 IPPFIND_OP_NONE
, /* No operation */
59 IPPFIND_OP_AND
, /* Logical AND of all children */
60 IPPFIND_OP_OR
, /* Logical OR of all children */
61 IPPFIND_OP_TRUE
, /* Always true */
62 IPPFIND_OP_FALSE
, /* Always false */
63 IPPFIND_OP_IS_LOCAL
, /* Is a local service */
64 IPPFIND_OP_IS_REMOTE
, /* Is a remote service */
65 IPPFIND_OP_DOMAIN_REGEX
, /* Domain matches regular expression */
66 IPPFIND_OP_NAME_REGEX
, /* Name matches regular expression */
67 IPPFIND_OP_HOST_REGEX
, /* Hostname matches regular expression */
68 IPPFIND_OP_PORT_RANGE
, /* Port matches range */
69 IPPFIND_OP_PATH_REGEX
, /* Path matches regular expression */
70 IPPFIND_OP_TXT_EXISTS
, /* TXT record key exists */
71 IPPFIND_OP_TXT_REGEX
, /* TXT record key matches regular expression */
72 IPPFIND_OP_URI_REGEX
, /* URI matches regular expression */
74 /* "Output" operations */
75 IPPFIND_OP_EXEC
, /* Execute when true */
76 IPPFIND_OP_LIST
, /* List when true */
77 IPPFIND_OP_PRINT_NAME
, /* Print URI when true */
78 IPPFIND_OP_PRINT_URI
, /* Print name when true */
79 IPPFIND_OP_QUIET
/* No output when true */
82 typedef struct ippfind_expr_s
/* Expression */
85 *prev
, /* Previous expression */
86 *next
, /* Next expression */
87 *parent
, /* Parent expressions */
88 *child
; /* Child expressions */
89 ippfind_op_t op
; /* Operation code (see above) */
90 int invert
; /* Invert the result */
91 char *key
; /* TXT record key */
92 regex_t re
; /* Regular expression for matching */
93 int range
[2]; /* Port number range */
94 int num_args
; /* Number of arguments for exec */
95 char **args
; /* Arguments for exec */
98 typedef struct ippfind_srv_s
/* Service information */
101 DNSServiceRef ref
; /* Service reference for query */
102 #elif defined(HAVE_AVAHI)
103 AvahiServiceResolver
*ref
; /* Resolver */
104 #endif /* HAVE_DNSSD */
105 char *name
, /* Service name */
106 *domain
, /* Domain name */
107 *regtype
, /* Registration type */
108 *fullName
, /* Full name */
109 *host
, /* Hostname */
110 *resource
, /* Resource path */
112 int num_txt
; /* Number of TXT record keys */
113 cups_option_t
*txt
; /* TXT record keys */
114 int port
, /* Port number */
115 is_local
, /* Is a local service? */
116 is_processed
, /* Did we process the service? */
117 is_resolved
; /* Got the resolve data? */
126 static DNSServiceRef dnssd_ref
; /* Master service reference */
127 #elif defined(HAVE_AVAHI)
128 static AvahiClient
*avahi_client
= NULL
;/* Client information */
129 static int avahi_got_data
= 0; /* Got data from poll? */
130 static AvahiSimplePoll
*avahi_poll
= NULL
;
131 /* Poll information */
132 #endif /* HAVE_DNSSD */
134 static int address_family
= AF_UNSPEC
;
135 /* Address family for LIST */
136 static int bonjour_error
= 0; /* Error browsing/resolving? */
137 static double bonjour_timeout
= 1.0; /* Timeout in seconds */
138 static int ipp_version
= 20; /* IPP version for LIST */
146 static void DNSSD_API
browse_callback(DNSServiceRef sdRef
,
147 DNSServiceFlags flags
,
148 uint32_t interfaceIndex
,
149 DNSServiceErrorType errorCode
,
150 const char *serviceName
,
152 const char *replyDomain
, void *context
)
153 __attribute__((nonnull(1,5,6,7,8)));
154 static void DNSSD_API
browse_local_callback(DNSServiceRef sdRef
,
155 DNSServiceFlags flags
,
156 uint32_t interfaceIndex
,
157 DNSServiceErrorType errorCode
,
158 const char *serviceName
,
160 const char *replyDomain
,
162 __attribute__((nonnull(1,5,6,7,8)));
163 #elif defined(HAVE_AVAHI)
164 static void browse_callback(AvahiServiceBrowser
*browser
,
165 AvahiIfIndex interface
,
166 AvahiProtocol protocol
,
167 AvahiBrowserEvent event
,
168 const char *serviceName
,
170 const char *replyDomain
,
171 AvahiLookupResultFlags flags
,
173 static void client_callback(AvahiClient
*client
,
174 AvahiClientState state
,
176 #endif /* HAVE_AVAHI */
178 static int compare_services(ippfind_srv_t
*a
, ippfind_srv_t
*b
);
179 static const char *dnssd_error_string(int error
);
180 static int eval_expr(ippfind_srv_t
*service
,
181 ippfind_expr_t
*expressions
);
182 static int exec_program(ippfind_srv_t
*service
, int num_args
,
184 static ippfind_srv_t
*get_service(cups_array_t
*services
,
185 const char *serviceName
,
187 const char *replyDomain
)
188 __attribute__((nonnull(1,2,3,4)));
189 static double get_time(void);
190 static int list_service(ippfind_srv_t
*service
);
191 static ippfind_expr_t
*new_expr(ippfind_op_t op
, int invert
,
192 const char *value
, const char *regex
,
195 static void DNSSD_API
resolve_callback(DNSServiceRef sdRef
,
196 DNSServiceFlags flags
,
197 uint32_t interfaceIndex
,
198 DNSServiceErrorType errorCode
,
199 const char *fullName
,
200 const char *hostTarget
, uint16_t port
,
202 const unsigned char *txtRecord
,
204 __attribute__((nonnull(1,5,6,9, 10)));
205 #elif defined(HAVE_AVAHI)
206 static int poll_callback(struct pollfd
*pollfds
,
207 unsigned int num_pollfds
, int timeout
,
209 static void resolve_callback(AvahiServiceResolver
*res
,
210 AvahiIfIndex interface
,
211 AvahiProtocol protocol
,
212 AvahiResolverEvent event
,
213 const char *serviceName
,
215 const char *replyDomain
,
216 const char *host_name
,
217 const AvahiAddress
*address
,
219 AvahiStringList
*txt
,
220 AvahiLookupResultFlags flags
,
222 #endif /* HAVE_DNSSD */
223 static void set_service_uri(ippfind_srv_t
*service
);
224 static void show_usage(void) __attribute__((noreturn
));
225 static void show_version(void) __attribute__((noreturn
));
229 * 'main()' - Browse for printers.
232 int /* O - Exit status */
233 main(int argc
, /* I - Number of command-line args */
234 char *argv
[]) /* I - Command-line arguments */
236 int i
, /* Looping var */
237 have_output
= 0,/* Have output expression */
238 status
= IPPFIND_EXIT_FALSE
;
240 const char *opt
, /* Option character */
241 *search
; /* Current browse/resolve string */
242 cups_array_t
*searches
; /* Things to browse/resolve */
243 cups_array_t
*services
; /* Service array */
244 ippfind_srv_t
*service
; /* Current service */
245 ippfind_expr_t
*expressions
= NULL
,
246 /* Expression tree */
247 *temp
= NULL
, /* New expression */
248 *parent
= NULL
, /* Parent expression */
249 *current
= NULL
,/* Current expression */
250 *parens
[100]; /* Markers for parenthesis */
251 int num_parens
= 0; /* Number of parenthesis */
252 ippfind_op_t logic
= IPPFIND_OP_AND
;
253 /* Logic for next expression */
254 int invert
= 0; /* Invert expression? */
255 int err
; /* DNS-SD error */
257 fd_set sinput
; /* Input set for select() */
258 struct timeval stimeout
; /* Timeout for select() */
259 #endif /* HAVE_DNSSD */
260 double endtime
; /* End time */
261 static const char * const ops
[] = /* Node operation names */
287 * Initialize the locale...
290 _cupsSetLocale(argv
);
293 * Create arrays to track services and things we want to browse/resolve...
296 searches
= cupsArrayNew(NULL
, NULL
);
297 services
= cupsArrayNew((cups_array_func_t
)compare_services
, NULL
);
300 * Parse command-line...
303 if (getenv("IPPFIND_DEBUG"))
304 for (i
= 1; i
< argc
; i
++)
305 fprintf(stderr
, "argv[%d]=\"%s\"\n", i
, argv
[i
]);
307 for (i
= 1; i
< argc
; i
++)
309 if (argv
[i
][0] == '-')
311 if (argv
[i
][1] == '-')
314 * Parse --option options...
317 if (!strcmp(argv
[i
], "--and"))
319 if (logic
== IPPFIND_OP_OR
)
321 _cupsLangPuts(stderr
, _("ippfind: Cannot use --and after --or."));
327 _cupsLangPuts(stderr
,
328 _("ippfind: Missing expression before \"--and\"."));
334 else if (!strcmp(argv
[i
], "--domain"))
339 _cupsLangPrintf(stderr
,
340 _("ippfind: Missing regular expression after %s."),
345 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
, argv
[i
],
347 return (IPPFIND_EXIT_MEMORY
);
349 else if (!strcmp(argv
[i
], "--exec"))
354 _cupsLangPrintf(stderr
, _("ippfind: Expected program after %s."),
359 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
361 return (IPPFIND_EXIT_MEMORY
);
364 if (!strcmp(argv
[i
], ";"))
371 _cupsLangPrintf(stderr
, _("ippfind: Expected semi-colon after %s."),
378 else if (!strcmp(argv
[i
], "--false"))
380 if ((temp
= new_expr(IPPFIND_OP_FALSE
, invert
, NULL
, NULL
,
382 return (IPPFIND_EXIT_MEMORY
);
384 else if (!strcmp(argv
[i
], "--help"))
388 else if (!strcmp(argv
[i
], "--host"))
393 _cupsLangPrintf(stderr
,
394 _("ippfind: Missing regular expression after %s."),
399 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
, argv
[i
],
401 return (IPPFIND_EXIT_MEMORY
);
403 else if (!strcmp(argv
[i
], "--ls"))
405 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
407 return (IPPFIND_EXIT_MEMORY
);
411 else if (!strcmp(argv
[i
], "--local"))
413 if ((temp
= new_expr(IPPFIND_OP_IS_LOCAL
, invert
, NULL
, NULL
,
415 return (IPPFIND_EXIT_MEMORY
);
417 else if (!strcmp(argv
[i
], "--name"))
422 _cupsLangPrintf(stderr
,
423 _("ippfind: Missing regular expression after %s."),
428 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
, argv
[i
],
430 return (IPPFIND_EXIT_MEMORY
);
432 else if (!strcmp(argv
[i
], "--not"))
436 else if (!strcmp(argv
[i
], "--or"))
440 _cupsLangPuts(stderr
,
441 _("ippfind: Missing expression before \"--or\"."));
445 logic
= IPPFIND_OP_OR
;
447 if (parent
&& parent
->op
== IPPFIND_OP_OR
)
450 * Already setup to do "foo --or bar --or baz"...
455 else if (!current
->prev
&& parent
)
458 * Change parent node into an OR node...
461 parent
->op
= IPPFIND_OP_OR
;
464 else if (!current
->prev
)
467 * Need to group "current" in a new OR node...
470 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
472 return (IPPFIND_EXIT_MEMORY
);
474 temp
->parent
= parent
;
475 temp
->child
= current
;
476 current
->parent
= temp
;
479 parent
->child
= temp
;
489 * Need to group previous expressions in an AND node, and then
490 * put that in an OR node...
493 if ((temp
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
495 return (IPPFIND_EXIT_MEMORY
);
497 while (current
->prev
)
499 current
->parent
= temp
;
500 current
= current
->prev
;
503 current
->parent
= temp
;
504 temp
->child
= current
;
507 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
509 return (IPPFIND_EXIT_MEMORY
);
511 temp
->parent
= parent
;
512 current
->parent
= temp
;
515 parent
->child
= temp
;
523 else if (!strcmp(argv
[i
], "--path"))
528 _cupsLangPrintf(stderr
,
529 _("ippfind: Missing regular expression after %s."),
534 if ((temp
= new_expr(IPPFIND_OP_PATH_REGEX
, invert
, NULL
, argv
[i
],
536 return (IPPFIND_EXIT_MEMORY
);
538 else if (!strcmp(argv
[i
], "--port"))
543 _cupsLangPrintf(stderr
,
544 _("ippfind: Expected port range after %s."),
549 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
], NULL
,
551 return (IPPFIND_EXIT_MEMORY
);
553 else if (!strcmp(argv
[i
], "--print"))
555 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
557 return (IPPFIND_EXIT_MEMORY
);
561 else if (!strcmp(argv
[i
], "--print-name"))
563 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
565 return (IPPFIND_EXIT_MEMORY
);
569 else if (!strcmp(argv
[i
], "--quiet"))
571 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
573 return (IPPFIND_EXIT_MEMORY
);
577 else if (!strcmp(argv
[i
], "--remote"))
579 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
581 return (IPPFIND_EXIT_MEMORY
);
583 else if (!strcmp(argv
[i
], "--true"))
585 if ((temp
= new_expr(IPPFIND_OP_TRUE
, invert
, NULL
, argv
[i
],
587 return (IPPFIND_EXIT_MEMORY
);
589 else if (!strcmp(argv
[i
], "--txt"))
594 _cupsLangPrintf(stderr
, _("ippfind: Expected key name after %s."),
599 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
], NULL
,
601 return (IPPFIND_EXIT_MEMORY
);
603 else if (!strncmp(argv
[i
], "--txt-", 6))
605 const char *key
= argv
[i
] + 6;/* TXT key */
610 _cupsLangPrintf(stderr
,
611 _("ippfind: Missing regular expression after %s."),
616 if ((temp
= new_expr(IPPFIND_OP_TXT_REGEX
, invert
, key
, argv
[i
],
618 return (IPPFIND_EXIT_MEMORY
);
620 else if (!strcmp(argv
[i
], "--uri"))
625 _cupsLangPrintf(stderr
,
626 _("ippfind: Missing regular expression after %s."),
631 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
, argv
[i
],
633 return (IPPFIND_EXIT_MEMORY
);
635 else if (!strcmp(argv
[i
], "--version"))
641 _cupsLangPrintf(stderr
, _("%s: Unknown option \"%s\"."),
649 * Add new expression...
652 if (logic
== IPPFIND_OP_AND
&&
653 current
&& current
->prev
&&
654 parent
&& parent
->op
!= IPPFIND_OP_AND
)
657 * Need to re-group "current" in a new AND node...
660 ippfind_expr_t
*tempand
; /* Temporary AND node */
662 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
664 return (IPPFIND_EXIT_MEMORY
);
667 * Replace "current" with new AND node at the end of this list...
670 current
->prev
->next
= tempand
;
671 tempand
->prev
= current
->prev
;
672 tempand
->parent
= parent
;
675 * Add "current to the new AND node...
678 tempand
->child
= current
;
679 current
->parent
= tempand
;
680 current
->prev
= NULL
;
685 * Add the new node at current level...
688 temp
->parent
= parent
;
689 temp
->prev
= current
;
692 current
->next
= temp
;
694 parent
->child
= temp
;
700 logic
= IPPFIND_OP_AND
;
710 for (opt
= argv
[i
] + 1; *opt
; opt
++)
715 address_family
= AF_INET
;
719 address_family
= AF_INET6
;
726 _cupsLangPrintf(stderr
,
727 _("ippfind: Expected port range after %s."),
732 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
],
733 NULL
, NULL
)) == NULL
)
734 return (IPPFIND_EXIT_MEMORY
);
741 _cupsLangPrintf(stderr
,
742 _("%s: Missing timeout for \"-T\"."),
747 bonjour_timeout
= atof(argv
[i
]);
754 _cupsLangPrintf(stderr
,
755 _("%s: Missing version for \"-V\"."),
760 if (!strcmp(argv
[i
], "1.1"))
762 else if (!strcmp(argv
[i
], "2.0"))
764 else if (!strcmp(argv
[i
], "2.1"))
766 else if (!strcmp(argv
[i
], "2.2"))
770 _cupsLangPrintf(stderr
, _("%s: Bad version %s for \"-V\"."),
780 _cupsLangPrintf(stderr
,
781 _("ippfind: Missing regular expression after "
786 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
,
787 argv
[i
], NULL
)) == NULL
)
788 return (IPPFIND_EXIT_MEMORY
);
795 _cupsLangPrintf(stderr
,
796 _("ippfind: Missing regular expression after "
801 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
,
802 argv
[i
], NULL
)) == NULL
)
803 return (IPPFIND_EXIT_MEMORY
);
807 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
809 return (IPPFIND_EXIT_MEMORY
);
818 _cupsLangPrintf(stderr
,
819 _("ippfind: Missing regular expression after "
824 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
,
825 argv
[i
], NULL
)) == NULL
)
826 return (IPPFIND_EXIT_MEMORY
);
830 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
832 return (IPPFIND_EXIT_MEMORY
);
838 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
840 return (IPPFIND_EXIT_MEMORY
);
846 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
848 return (IPPFIND_EXIT_MEMORY
);
852 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
854 return (IPPFIND_EXIT_MEMORY
);
863 _cupsLangPrintf(stderr
,
864 _("ippfind: Missing key name after %s."),
869 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
],
870 NULL
, NULL
)) == NULL
)
871 return (IPPFIND_EXIT_MEMORY
);
878 _cupsLangPrintf(stderr
,
879 _("ippfind: Missing regular expression after "
884 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
,
885 argv
[i
], NULL
)) == NULL
)
886 return (IPPFIND_EXIT_MEMORY
);
893 _cupsLangPrintf(stderr
,
894 _("ippfind: Missing program after %s."),
899 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
901 return (IPPFIND_EXIT_MEMORY
);
904 if (!strcmp(argv
[i
], ";"))
911 _cupsLangPrintf(stderr
,
912 _("ippfind: Missing semi-colon after %s."),
921 _cupsLangPrintf(stderr
, _("%s: Unknown option \"-%c\"."),
929 * Add new expression...
932 if (logic
== IPPFIND_OP_AND
&&
933 current
&& current
->prev
&&
934 parent
&& parent
->op
!= IPPFIND_OP_AND
)
937 * Need to re-group "current" in a new AND node...
940 ippfind_expr_t
*tempand
; /* Temporary AND node */
942 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
944 return (IPPFIND_EXIT_MEMORY
);
947 * Replace "current" with new AND node at the end of this list...
950 current
->prev
->next
= tempand
;
951 tempand
->prev
= current
->prev
;
952 tempand
->parent
= parent
;
955 * Add "current to the new AND node...
958 tempand
->child
= current
;
959 current
->parent
= tempand
;
960 current
->prev
= NULL
;
965 * Add the new node at current level...
968 temp
->parent
= parent
;
969 temp
->prev
= current
;
972 current
->next
= temp
;
974 parent
->child
= temp
;
980 logic
= IPPFIND_OP_AND
;
986 else if (!strcmp(argv
[i
], "("))
988 if (num_parens
>= 100)
990 _cupsLangPuts(stderr
, _("ippfind: Too many parenthesis."));
994 if ((temp
= new_expr(IPPFIND_OP_AND
, invert
, NULL
, NULL
, NULL
)) == NULL
)
995 return (IPPFIND_EXIT_MEMORY
);
997 parens
[num_parens
++] = temp
;
1001 temp
->parent
= current
->parent
;
1002 current
->next
= temp
;
1003 temp
->prev
= current
;
1011 logic
= IPPFIND_OP_AND
;
1013 else if (!strcmp(argv
[i
], ")"))
1015 if (num_parens
<= 0)
1017 _cupsLangPuts(stderr
, _("ippfind: Missing open parenthesis."));
1021 current
= parens
[--num_parens
];
1022 parent
= current
->parent
;
1024 logic
= IPPFIND_OP_AND
;
1026 else if (!strcmp(argv
[i
], "!"))
1033 * _regtype._tcp[,subtype][.domain]
1037 * service-name[._regtype._tcp[.domain]]
1040 cupsArrayAdd(searches
, argv
[i
]);
1046 _cupsLangPuts(stderr
, _("ippfind: Missing close parenthesis."));
1053 * Add an implicit --print-uri to the end...
1056 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, 0, NULL
, NULL
, NULL
)) == NULL
)
1057 return (IPPFIND_EXIT_MEMORY
);
1061 while (current
->parent
)
1062 current
= current
->parent
;
1064 current
->next
= temp
;
1065 temp
->prev
= current
;
1071 if (cupsArrayCount(searches
) == 0)
1074 * Add an implicit browse for IPP printers ("_ipp._tcp")...
1077 cupsArrayAdd(searches
, "_ipp._tcp");
1080 if (getenv("IPPFIND_DEBUG"))
1082 int indent
= 4; /* Indentation */
1084 puts("Expression tree:");
1085 current
= expressions
;
1089 * Print the current node...
1092 printf("%*s%s%s\n", indent
, "", current
->invert
? "!" : "",
1096 * Advance to the next node...
1101 current
= current
->child
;
1104 else if (current
->next
)
1105 current
= current
->next
;
1106 else if (current
->parent
)
1108 while (current
->parent
)
1111 current
= current
->parent
;
1116 current
= current
->next
;
1122 puts("\nSearch items:");
1123 for (search
= (const char *)cupsArrayFirst(searches
);
1125 search
= (const char *)cupsArrayNext(searches
))
1126 printf(" %s\n", search
);
1130 * Start up browsing/resolving...
1134 if ((err
= DNSServiceCreateConnection(&dnssd_ref
)) != kDNSServiceErr_NoError
)
1136 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1137 dnssd_error_string(err
));
1138 return (IPPFIND_EXIT_BONJOUR
);
1141 #elif defined(HAVE_AVAHI)
1142 if ((avahi_poll
= avahi_simple_poll_new()) == NULL
)
1144 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1146 return (IPPFIND_EXIT_BONJOUR
);
1149 avahi_simple_poll_set_func(avahi_poll
, poll_callback
, NULL
);
1151 avahi_client
= avahi_client_new(avahi_simple_poll_get(avahi_poll
),
1152 0, client_callback
, avahi_poll
, &err
);
1155 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1156 dnssd_error_string(err
));
1157 return (IPPFIND_EXIT_BONJOUR
);
1159 #endif /* HAVE_DNSSD */
1161 for (search
= (const char *)cupsArrayFirst(searches
);
1163 search
= (const char *)cupsArrayNext(searches
))
1165 char buf
[1024], /* Full name string */
1166 *name
= NULL
, /* Service instance name */
1167 *regtype
, /* Registration type */
1168 *domain
; /* Domain, if any */
1170 strlcpy(buf
, search
, sizeof(buf
));
1171 if ((regtype
= strstr(buf
, "._")) != NULL
)
1173 if (strcmp(regtype
, "._tcp"))
1176 * "something._protocol._tcp" -> search for something with the given
1186 * "_protocol._tcp" -> search for everything with the given protocol...
1196 * "something" -> search for something with IPP protocol...
1200 regtype
= "_ipp._tcp";
1203 for (domain
= regtype
; *domain
; domain
++)
1205 if (*domain
== '.' && domain
[1] != '_')
1218 * Resolve the given service instance name, regtype, and domain...
1224 service
= get_service(services
, name
, regtype
, domain
);
1227 service
->ref
= dnssd_ref
;
1228 err
= DNSServiceResolve(&(service
->ref
),
1229 kDNSServiceFlagsShareConnection
, 0, name
,
1230 regtype
, domain
, resolve_callback
,
1233 #elif defined(HAVE_AVAHI)
1234 service
->ref
= avahi_service_resolver_new(avahi_client
, AVAHI_IF_UNSPEC
,
1235 AVAHI_PROTO_UNSPEC
, name
,
1237 AVAHI_PROTO_UNSPEC
, 0,
1238 resolve_callback
, service
);
1242 err
= avahi_client_errno(avahi_client
);
1243 #endif /* HAVE_DNSSD */
1248 * Browse for services of the given type...
1252 DNSServiceRef ref
; /* Browse reference */
1255 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
, 0, regtype
,
1256 domain
, browse_callback
, services
);
1261 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
,
1262 kDNSServiceInterfaceIndexLocalOnly
, regtype
,
1263 domain
, browse_local_callback
, services
);
1266 #elif defined(HAVE_AVAHI)
1267 if (avahi_service_browser_new(avahi_client
, AVAHI_IF_UNSPEC
,
1268 AVAHI_PROTO_UNSPEC
, regtype
, domain
, 0,
1269 browse_callback
, services
))
1272 err
= avahi_client_errno(avahi_client
);
1273 #endif /* HAVE_DNSSD */
1278 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
1279 dnssd_error_string(err
));
1281 return (IPPFIND_EXIT_BONJOUR
);
1286 * Process browse/resolve requests...
1289 if (bonjour_timeout
> 1.0)
1290 endtime
= get_time() + bonjour_timeout
;
1292 endtime
= get_time() + 300.0;
1294 while (get_time() < endtime
)
1296 int process
= 0; /* Process services? */
1299 int fd
= DNSServiceRefSockFD(dnssd_ref
);
1300 /* File descriptor for DNS-SD */
1303 FD_SET(fd
, &sinput
);
1305 stimeout
.tv_sec
= 0;
1306 stimeout
.tv_usec
= 500000;
1308 if (select(fd
+ 1, &sinput
, NULL
, NULL
, &stimeout
) < 0)
1311 if (FD_ISSET(fd
, &sinput
))
1314 * Process responses...
1317 DNSServiceProcessResult(dnssd_ref
);
1322 * Time to process services...
1328 #elif defined(HAVE_AVAHI)
1331 if (avahi_simple_poll_iterate(avahi_poll
, 500) > 0)
1334 * We've been told to exit the loop. Perhaps the connection to
1338 return (IPPFIND_EXIT_BONJOUR
);
1341 if (!avahi_got_data
)
1344 * Time to process services...
1349 #endif /* HAVE_DNSSD */
1354 * Process any services that we have found...
1357 int active
= 0, /* Number of active resolves */
1358 resolved
= 0, /* Number of resolved services */
1359 processed
= 0; /* Number of processed services */
1361 for (service
= (ippfind_srv_t
*)cupsArrayFirst(services
);
1363 service
= (ippfind_srv_t
*)cupsArrayNext(services
))
1365 if (service
->is_processed
)
1368 if (service
->is_resolved
)
1371 if (!service
->ref
&& !service
->is_resolved
)
1374 * Found a service, now resolve it (but limit to 50 active resolves...)
1380 service
->ref
= dnssd_ref
;
1381 err
= DNSServiceResolve(&(service
->ref
),
1382 kDNSServiceFlagsShareConnection
, 0,
1383 service
->name
, service
->regtype
,
1384 service
->domain
, resolve_callback
,
1387 #elif defined(HAVE_AVAHI)
1388 service
->ref
= avahi_service_resolver_new(avahi_client
,
1394 AVAHI_PROTO_UNSPEC
, 0,
1400 err
= avahi_client_errno(avahi_client
);
1401 #endif /* HAVE_DNSSD */
1405 _cupsLangPrintf(stderr
,
1406 _("ippfind: Unable to browse or resolve: %s"),
1407 dnssd_error_string(err
));
1408 return (IPPFIND_EXIT_BONJOUR
);
1414 else if (service
->is_resolved
&& !service
->is_processed
)
1417 * Resolved, not process this service against the expressions...
1423 DNSServiceRefDeallocate(service
->ref
);
1425 avahi_service_resolver_free(service
->ref
);
1426 #endif /* HAVE_DNSSD */
1428 service
->ref
= NULL
;
1431 if (eval_expr(service
, expressions
))
1432 status
= IPPFIND_EXIT_TRUE
;
1434 service
->is_processed
= 1;
1436 else if (service
->ref
)
1441 * If we have processed all services we have discovered, then we are done.
1444 if (processed
== cupsArrayCount(services
) && bonjour_timeout
<= 1.0)
1450 return (IPPFIND_EXIT_BONJOUR
);
1458 * 'browse_callback()' - Browse devices.
1461 static void DNSSD_API
1463 DNSServiceRef sdRef
, /* I - Service reference */
1464 DNSServiceFlags flags
, /* I - Option flags */
1465 uint32_t interfaceIndex
, /* I - Interface number */
1466 DNSServiceErrorType errorCode
, /* I - Error, if any */
1467 const char *serviceName
, /* I - Name of service/device */
1468 const char *regtype
, /* I - Type of service */
1469 const char *replyDomain
, /* I - Service domain */
1470 void *context
) /* I - Services array */
1473 * Only process "add" data...
1477 (void)interfaceIndex
;
1479 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1486 get_service((cups_array_t
*)context
, serviceName
, regtype
, replyDomain
);
1491 * 'browse_local_callback()' - Browse local devices.
1494 static void DNSSD_API
1495 browse_local_callback(
1496 DNSServiceRef sdRef
, /* I - Service reference */
1497 DNSServiceFlags flags
, /* I - Option flags */
1498 uint32_t interfaceIndex
, /* I - Interface number */
1499 DNSServiceErrorType errorCode
, /* I - Error, if any */
1500 const char *serviceName
, /* I - Name of service/device */
1501 const char *regtype
, /* I - Type of service */
1502 const char *replyDomain
, /* I - Service domain */
1503 void *context
) /* I - Services array */
1505 ippfind_srv_t
*service
; /* Service */
1509 * Only process "add" data...
1513 (void)interfaceIndex
;
1515 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1522 service
= get_service((cups_array_t
*)context
, serviceName
, regtype
,
1524 service
->is_local
= 1;
1526 #endif /* HAVE_DNSSD */
1531 * 'browse_callback()' - Browse devices.
1536 AvahiServiceBrowser
*browser
, /* I - Browser */
1537 AvahiIfIndex interface
, /* I - Interface index (unused) */
1538 AvahiProtocol protocol
, /* I - Network protocol (unused) */
1539 AvahiBrowserEvent event
, /* I - What happened */
1540 const char *name
, /* I - Service name */
1541 const char *type
, /* I - Registration type */
1542 const char *domain
, /* I - Domain */
1543 AvahiLookupResultFlags flags
, /* I - Flags */
1544 void *context
) /* I - Services array */
1546 AvahiClient
*client
= avahi_service_browser_get_client(browser
);
1547 /* Client information */
1548 ippfind_srv_t
*service
; /* Service information */
1557 case AVAHI_BROWSER_FAILURE
:
1558 fprintf(stderr
, "DEBUG: browse_callback: %s\n",
1559 avahi_strerror(avahi_client_errno(client
)));
1561 avahi_simple_poll_quit(avahi_poll
);
1564 case AVAHI_BROWSER_NEW
:
1566 * This object is new on the network. Create a device entry for it if
1567 * it doesn't yet exist.
1570 service
= get_service((cups_array_t
*)context
, name
, type
, domain
);
1572 if (flags
& AVAHI_LOOKUP_RESULT_LOCAL
)
1573 service
->is_local
= 1;
1576 case AVAHI_BROWSER_REMOVE
:
1577 case AVAHI_BROWSER_ALL_FOR_NOW
:
1578 case AVAHI_BROWSER_CACHE_EXHAUSTED
:
1585 * 'client_callback()' - Avahi client callback function.
1590 AvahiClient
*client
, /* I - Client information (unused) */
1591 AvahiClientState state
, /* I - Current state */
1592 void *context
) /* I - User data (unused) */
1598 * If the connection drops, quit.
1601 if (state
== AVAHI_CLIENT_FAILURE
)
1603 fputs("DEBUG: Avahi connection failed.\n", stderr
);
1605 avahi_simple_poll_quit(avahi_poll
);
1608 #endif /* HAVE_AVAHI */
1612 * 'compare_services()' - Compare two devices.
1615 static int /* O - Result of comparison */
1616 compare_services(ippfind_srv_t
*a
, /* I - First device */
1617 ippfind_srv_t
*b
) /* I - Second device */
1619 return (strcmp(a
->name
, b
->name
));
1624 * 'dnssd_error_string()' - Return an error string for an error code.
1627 static const char * /* O - Error message */
1628 dnssd_error_string(int error
) /* I - Error number */
1633 case kDNSServiceErr_NoError
:
1637 case kDNSServiceErr_Unknown
:
1638 return ("Unknown error.");
1640 case kDNSServiceErr_NoSuchName
:
1641 return ("Service not found.");
1643 case kDNSServiceErr_NoMemory
:
1644 return ("Out of memory.");
1646 case kDNSServiceErr_BadParam
:
1647 return ("Bad parameter.");
1649 case kDNSServiceErr_BadReference
:
1650 return ("Bad service reference.");
1652 case kDNSServiceErr_BadState
:
1653 return ("Bad state.");
1655 case kDNSServiceErr_BadFlags
:
1656 return ("Bad flags.");
1658 case kDNSServiceErr_Unsupported
:
1659 return ("Unsupported.");
1661 case kDNSServiceErr_NotInitialized
:
1662 return ("Not initialized.");
1664 case kDNSServiceErr_AlreadyRegistered
:
1665 return ("Already registered.");
1667 case kDNSServiceErr_NameConflict
:
1668 return ("Name conflict.");
1670 case kDNSServiceErr_Invalid
:
1671 return ("Invalid name.");
1673 case kDNSServiceErr_Firewall
:
1674 return ("Firewall prevents registration.");
1676 case kDNSServiceErr_Incompatible
:
1677 return ("Client library incompatible.");
1679 case kDNSServiceErr_BadInterfaceIndex
:
1680 return ("Bad interface index.");
1682 case kDNSServiceErr_Refused
:
1683 return ("Server prevents registration.");
1685 case kDNSServiceErr_NoSuchRecord
:
1686 return ("Record not found.");
1688 case kDNSServiceErr_NoAuth
:
1689 return ("Authentication required.");
1691 case kDNSServiceErr_NoSuchKey
:
1692 return ("Encryption key not found.");
1694 case kDNSServiceErr_NATTraversal
:
1695 return ("Unable to traverse NAT boundary.");
1697 case kDNSServiceErr_DoubleNAT
:
1698 return ("Unable to traverse double-NAT boundary.");
1700 case kDNSServiceErr_BadTime
:
1701 return ("Bad system time.");
1703 case kDNSServiceErr_BadSig
:
1704 return ("Bad signature.");
1706 case kDNSServiceErr_BadKey
:
1707 return ("Bad encryption key.");
1709 case kDNSServiceErr_Transient
:
1710 return ("Transient error occurred - please try again.");
1712 case kDNSServiceErr_ServiceNotRunning
:
1713 return ("Server not running.");
1715 case kDNSServiceErr_NATPortMappingUnsupported
:
1716 return ("NAT doesn't support NAT-PMP or UPnP.");
1718 case kDNSServiceErr_NATPortMappingDisabled
:
1719 return ("NAT supports NAT-PNP or UPnP but it is disabled.");
1721 case kDNSServiceErr_NoRouter
:
1722 return ("No Internet/default router configured.");
1724 case kDNSServiceErr_PollingMode
:
1725 return ("Service polling mode error.");
1728 case kDNSServiceErr_Timeout
:
1729 return ("Service timeout.");
1733 # elif defined(HAVE_AVAHI)
1734 return (avahi_strerror(error
));
1735 # endif /* HAVE_DNSSD */
1740 * 'eval_expr()' - Evaluate the expressions against the specified service.
1742 * Returns 1 for true and 0 for false.
1745 static int /* O - Result of evaluation */
1746 eval_expr(ippfind_srv_t
*service
, /* I - Service */
1747 ippfind_expr_t
*expressions
) /* I - Expressions */
1749 int logic
, /* Logical operation */
1750 result
; /* Result of current expression */
1751 ippfind_expr_t
*expression
; /* Current expression */
1752 const char *val
; /* TXT value */
1755 * Loop through the expressions...
1758 if (expressions
&& expressions
->parent
)
1759 logic
= expressions
->parent
->op
;
1761 logic
= IPPFIND_OP_AND
;
1763 for (expression
= expressions
; expression
; expression
= expression
->next
)
1765 switch (expression
->op
)
1768 case IPPFIND_OP_AND
:
1769 case IPPFIND_OP_OR
:
1770 if (expression
->child
)
1771 result
= eval_expr(service
, expression
->child
);
1773 result
= expression
->op
== IPPFIND_OP_AND
;
1775 case IPPFIND_OP_TRUE
:
1778 case IPPFIND_OP_FALSE
:
1781 case IPPFIND_OP_IS_LOCAL
:
1782 result
= service
->is_local
;
1784 case IPPFIND_OP_IS_REMOTE
:
1785 result
= !service
->is_local
;
1787 case IPPFIND_OP_DOMAIN_REGEX
:
1788 result
= !regexec(&(expression
->re
), service
->domain
, 0, NULL
, 0);
1790 case IPPFIND_OP_NAME_REGEX
:
1791 result
= !regexec(&(expression
->re
), service
->name
, 0, NULL
, 0);
1793 case IPPFIND_OP_HOST_REGEX
:
1794 result
= !regexec(&(expression
->re
), service
->host
, 0, NULL
, 0);
1796 case IPPFIND_OP_PORT_RANGE
:
1797 result
= service
->port
>= expression
->range
[0] &&
1798 service
->port
<= expression
->range
[1];
1800 case IPPFIND_OP_PATH_REGEX
:
1801 result
= !regexec(&(expression
->re
), service
->resource
, 0, NULL
, 0);
1803 case IPPFIND_OP_TXT_EXISTS
:
1804 result
= cupsGetOption(expression
->key
, service
->num_txt
,
1805 service
->txt
) != NULL
;
1807 case IPPFIND_OP_TXT_REGEX
:
1808 val
= cupsGetOption(expression
->key
, service
->num_txt
,
1811 result
= !regexec(&(expression
->re
), val
, 0, NULL
, 0);
1815 if (getenv("IPPFIND_DEBUG"))
1816 printf("TXT_REGEX of \"%s\": %d\n", val
, result
);
1818 case IPPFIND_OP_URI_REGEX
:
1819 result
= !regexec(&(expression
->re
), service
->uri
, 0, NULL
, 0);
1821 case IPPFIND_OP_EXEC
:
1822 result
= exec_program(service
, expression
->num_args
,
1825 case IPPFIND_OP_LIST
:
1826 result
= list_service(service
);
1828 case IPPFIND_OP_PRINT_NAME
:
1829 _cupsLangPuts(stdout
, service
->name
);
1832 case IPPFIND_OP_PRINT_URI
:
1833 _cupsLangPuts(stdout
, service
->uri
);
1836 case IPPFIND_OP_QUIET
:
1841 if (expression
->invert
)
1844 if (logic
== IPPFIND_OP_AND
&& !result
)
1846 else if (logic
== IPPFIND_OP_OR
&& result
)
1850 return (logic
== IPPFIND_OP_AND
);
1855 * 'exec_program()' - Execute a program for a service.
1858 static int /* O - 1 if program terminated
1859 successfully, 0 otherwise. */
1860 exec_program(ippfind_srv_t
*service
, /* I - Service */
1861 int num_args
, /* I - Number of command-line args */
1862 char **args
) /* I - Command-line arguments */
1864 char **myargv
, /* Command-line arguments */
1865 **myenvp
, /* Environment variables */
1866 *ptr
, /* Pointer into variable */
1867 domain
[1024], /* IPPFIND_SERVICE_DOMAIN */
1868 hostname
[1024], /* IPPFIND_SERVICE_HOSTNAME */
1869 name
[256], /* IPPFIND_SERVICE_NAME */
1870 port
[32], /* IPPFIND_SERVICE_PORT */
1871 regtype
[256], /* IPPFIND_SERVICE_REGTYPE */
1872 scheme
[128], /* IPPFIND_SERVICE_SCHEME */
1873 uri
[1024], /* IPPFIND_SERVICE_URI */
1874 txt
[100][256]; /* IPPFIND_TXT_foo */
1875 int i
, /* Looping var */
1876 myenvc
, /* Number of environment variables */
1877 status
; /* Exit status of program */
1879 char program
[1024]; /* Program to execute */
1880 int pid
; /* Process ID */
1885 * Environment variables...
1888 snprintf(domain
, sizeof(domain
), "IPPFIND_SERVICE_DOMAIN=%s",
1890 snprintf(hostname
, sizeof(hostname
), "IPPFIND_SERVICE_HOSTNAME=%s",
1892 snprintf(name
, sizeof(name
), "IPPFIND_SERVICE_NAME=%s", service
->name
);
1893 snprintf(port
, sizeof(port
), "IPPFIND_SERVICE_PORT=%d", service
->port
);
1894 snprintf(regtype
, sizeof(regtype
), "IPPFIND_SERVICE_REGTYPE=%s",
1896 snprintf(scheme
, sizeof(scheme
), "IPPFIND_SERVICE_SCHEME=%s",
1897 !strncmp(service
->regtype
, "_http._tcp", 10) ? "http" :
1898 !strncmp(service
->regtype
, "_https._tcp", 11) ? "https" :
1899 !strncmp(service
->regtype
, "_ipp._tcp", 9) ? "ipp" :
1900 !strncmp(service
->regtype
, "_ipps._tcp", 10) ? "ipps" : "lpd");
1901 snprintf(uri
, sizeof(uri
), "IPPFIND_SERVICE_URI=%s", service
->uri
);
1902 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1904 snprintf(txt
[i
], sizeof(txt
[i
]), "IPPFIND_TXT_%s=%s", service
->txt
[i
].name
,
1905 service
->txt
[i
].value
);
1906 for (ptr
= txt
[i
] + 12; *ptr
&& *ptr
!= '='; ptr
++)
1907 *ptr
= (char)_cups_toupper(*ptr
);
1910 for (i
= 0, myenvc
= 7 + service
->num_txt
; environ
[i
]; i
++)
1911 if (strncmp(environ
[i
], "IPPFIND_", 8))
1914 if ((myenvp
= calloc(sizeof(char *), (size_t)(myenvc
+ 1))) == NULL
)
1916 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1917 exit(IPPFIND_EXIT_MEMORY
);
1920 for (i
= 0, myenvc
= 0; environ
[i
]; i
++)
1921 if (strncmp(environ
[i
], "IPPFIND_", 8))
1922 myenvp
[myenvc
++] = environ
[i
];
1924 myenvp
[myenvc
++] = domain
;
1925 myenvp
[myenvc
++] = hostname
;
1926 myenvp
[myenvc
++] = name
;
1927 myenvp
[myenvc
++] = port
;
1928 myenvp
[myenvc
++] = regtype
;
1929 myenvp
[myenvc
++] = scheme
;
1930 myenvp
[myenvc
++] = uri
;
1932 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1933 myenvp
[myenvc
++] = txt
[i
];
1936 * Allocate and copy command-line arguments...
1939 if ((myargv
= calloc(sizeof(char *), (size_t)(num_args
+ 1))) == NULL
)
1941 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1942 exit(IPPFIND_EXIT_MEMORY
);
1945 for (i
= 0; i
< num_args
; i
++)
1947 if (strchr(args
[i
], '{'))
1949 char temp
[2048], /* Temporary string */
1950 *tptr
, /* Pointer into temporary string */
1951 keyword
[256], /* {keyword} */
1952 *kptr
; /* Pointer into keyword */
1954 for (ptr
= args
[i
], tptr
= temp
; *ptr
; ptr
++)
1959 * Do a {var} substitution...
1962 for (kptr
= keyword
, ptr
++; *ptr
&& *ptr
!= '}'; ptr
++)
1963 if (kptr
< (keyword
+ sizeof(keyword
) - 1))
1968 _cupsLangPuts(stderr
,
1969 _("ippfind: Missing close brace in substitution."));
1970 exit(IPPFIND_EXIT_SYNTAX
);
1974 if (!keyword
[0] || !strcmp(keyword
, "service_uri"))
1975 strlcpy(tptr
, service
->uri
, sizeof(temp
) - (size_t)(tptr
- temp
));
1976 else if (!strcmp(keyword
, "service_domain"))
1977 strlcpy(tptr
, service
->domain
, sizeof(temp
) - (size_t)(tptr
- temp
));
1978 else if (!strcmp(keyword
, "service_hostname"))
1979 strlcpy(tptr
, service
->host
, sizeof(temp
) - (size_t)(tptr
- temp
));
1980 else if (!strcmp(keyword
, "service_name"))
1981 strlcpy(tptr
, service
->name
, sizeof(temp
) - (size_t)(tptr
- temp
));
1982 else if (!strcmp(keyword
, "service_path"))
1983 strlcpy(tptr
, service
->resource
, sizeof(temp
) - (size_t)(tptr
- temp
));
1984 else if (!strcmp(keyword
, "service_port"))
1985 strlcpy(tptr
, port
+ 21, sizeof(temp
) - (size_t)(tptr
- temp
));
1986 else if (!strcmp(keyword
, "service_scheme"))
1987 strlcpy(tptr
, scheme
+ 22, sizeof(temp
) - (size_t)(tptr
- temp
));
1988 else if (!strncmp(keyword
, "txt_", 4))
1990 const char *val
= cupsGetOption(keyword
+ 4, service
->num_txt
, service
->txt
);
1992 strlcpy(tptr
, val
, sizeof(temp
) - (size_t)(tptr
- temp
));
1998 _cupsLangPrintf(stderr
, _("ippfind: Unknown variable \"{%s}\"."),
2000 exit(IPPFIND_EXIT_SYNTAX
);
2003 tptr
+= strlen(tptr
);
2005 else if (tptr
< (temp
+ sizeof(temp
) - 1))
2010 myargv
[i
] = strdup(temp
);
2013 myargv
[i
] = strdup(args
[i
]);
2017 if (getenv("IPPFIND_DEBUG"))
2019 printf("\nProgram:\n %s\n", args
[0]);
2020 puts("\nArguments:");
2021 for (i
= 0; i
< num_args
; i
++)
2022 printf(" %s\n", myargv
[i
]);
2023 puts("\nEnvironment:");
2024 for (i
= 0; i
< myenvc
; i
++)
2025 printf(" %s\n", myenvp
[i
]);
2028 status
= _spawnvpe(_P_WAIT
, args
[0], myargv
, myenvp
);
2032 * Execute the program...
2035 if (strchr(args
[0], '/') && !access(args
[0], X_OK
))
2036 strlcpy(program
, args
[0], sizeof(program
));
2037 else if (!cupsFileFind(args
[0], getenv("PATH"), 1, program
, sizeof(program
)))
2039 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2040 args
[0], strerror(ENOENT
));
2041 exit(IPPFIND_EXIT_SYNTAX
);
2044 if (getenv("IPPFIND_DEBUG"))
2046 printf("\nProgram:\n %s\n", program
);
2047 puts("\nArguments:");
2048 for (i
= 0; i
< num_args
; i
++)
2049 printf(" %s\n", myargv
[i
]);
2050 puts("\nEnvironment:");
2051 for (i
= 0; i
< myenvc
; i
++)
2052 printf(" %s\n", myenvp
[i
]);
2055 if ((pid
= fork()) == 0)
2058 * Child comes here...
2061 execve(program
, myargv
, myenvp
);
2066 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2067 args
[0], strerror(errno
));
2068 exit(IPPFIND_EXIT_SYNTAX
);
2073 * Wait for it to complete...
2076 while (wait(&status
) != pid
)
2085 for (i
= 0; i
< num_args
; i
++)
2092 * Return whether the program succeeded or crashed...
2095 if (getenv("IPPFIND_DEBUG"))
2098 printf("Exit Status: %d\n", status
);
2100 if (WIFEXITED(status
))
2101 printf("Exit Status: %d\n", WEXITSTATUS(status
));
2103 printf("Terminating Signal: %d\n", WTERMSIG(status
));
2107 return (status
== 0);
2112 * 'get_service()' - Create or update a device.
2115 static ippfind_srv_t
* /* O - Service */
2116 get_service(cups_array_t
*services
, /* I - Service array */
2117 const char *serviceName
, /* I - Name of service/device */
2118 const char *regtype
, /* I - Type of service */
2119 const char *replyDomain
) /* I - Service domain */
2121 ippfind_srv_t key
, /* Search key */
2122 *service
; /* Service */
2123 char fullName
[kDNSServiceMaxDomainName
];
2124 /* Full name for query */
2128 * See if this is a new device...
2131 key
.name
= (char *)serviceName
;
2132 key
.regtype
= (char *)regtype
;
2134 for (service
= cupsArrayFind(services
, &key
);
2136 service
= cupsArrayNext(services
))
2137 if (_cups_strcasecmp(service
->name
, key
.name
))
2139 else if (!strcmp(service
->regtype
, key
.regtype
))
2143 * Yes, add the service...
2146 service
= calloc(sizeof(ippfind_srv_t
), 1);
2147 service
->name
= strdup(serviceName
);
2148 service
->domain
= strdup(replyDomain
);
2149 service
->regtype
= strdup(regtype
);
2151 cupsArrayAdd(services
, service
);
2154 * Set the "full name" of this service, which is used for queries and
2159 DNSServiceConstructFullName(fullName
, serviceName
, regtype
, replyDomain
);
2160 #else /* HAVE_AVAHI */
2161 avahi_service_name_join(fullName
, kDNSServiceMaxDomainName
, serviceName
,
2162 regtype
, replyDomain
);
2163 #endif /* HAVE_DNSSD */
2165 service
->fullName
= strdup(fullName
);
2172 * 'get_time()' - Get the current time-of-day in seconds.
2179 struct _timeb curtime
; /* Current Windows time */
2183 return (curtime
.time
+ 0.001 * curtime
.millitm
);
2186 struct timeval curtime
; /* Current UNIX time */
2188 if (gettimeofday(&curtime
, NULL
))
2191 return (curtime
.tv_sec
+ 0.000001 * curtime
.tv_usec
);
2197 * 'list_service()' - List the contents of a service.
2200 static int /* O - 1 if successful, 0 otherwise */
2201 list_service(ippfind_srv_t
*service
) /* I - Service */
2203 http_addrlist_t
*addrlist
; /* Address(es) of service */
2204 char port
[10]; /* Port number of service */
2207 snprintf(port
, sizeof(port
), "%d", service
->port
);
2209 if ((addrlist
= httpAddrGetList(service
->host
, address_family
, port
)) == NULL
)
2211 _cupsLangPrintf(stdout
, "%s unreachable", service
->uri
);
2215 if (!strncmp(service
->regtype
, "_ipp._tcp", 9) ||
2216 !strncmp(service
->regtype
, "_ipps._tcp", 10))
2222 http_t
*http
; /* HTTP connection */
2223 ipp_t
*request
, /* IPP request */
2224 *response
; /* IPP response */
2225 ipp_attribute_t
*attr
; /* IPP attribute */
2226 int i
, /* Looping var */
2227 count
, /* Number of values */
2228 version
, /* IPP version */
2229 paccepting
; /* printer-is-accepting-jobs value */
2230 ipp_pstate_t pstate
; /* printer-state value */
2231 char preasons
[1024], /* Comma-delimited printer-state-reasons */
2232 *ptr
, /* Pointer into reasons */
2233 *end
; /* End of reasons buffer */
2234 static const char * const rattrs
[] =/* Requested attributes */
2236 "printer-is-accepting-jobs",
2238 "printer-state-reasons"
2242 * Connect to the printer...
2245 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2246 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2247 HTTP_ENCRYPTION_ALWAYS
:
2248 HTTP_ENCRYPTION_IF_REQUESTED
,
2251 httpAddrFreeList(addrlist
);
2255 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2260 * Get the current printer state...
2264 version
= ipp_version
;
2268 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
2269 ippSetVersion(request
, version
/ 10, version
% 10);
2270 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
2272 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
2273 "requesting-user-name", NULL
, cupsUser());
2274 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
2275 "requested-attributes",
2276 (int)(sizeof(rattrs
) / sizeof(rattrs
[0])), NULL
, rattrs
);
2278 response
= cupsDoRequest(http
, request
, service
->resource
);
2280 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
&& version
> 11)
2283 while (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
&& version
> 11);
2289 if (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
)
2291 _cupsLangPrintf(stdout
, "%s: unavailable", service
->uri
);
2295 if ((attr
= ippFindAttribute(response
, "printer-state",
2296 IPP_TAG_ENUM
)) != NULL
)
2297 pstate
= (ipp_pstate_t
)ippGetInteger(attr
, 0);
2299 pstate
= IPP_PSTATE_STOPPED
;
2301 if ((attr
= ippFindAttribute(response
, "printer-is-accepting-jobs",
2302 IPP_TAG_BOOLEAN
)) != NULL
)
2303 paccepting
= ippGetBoolean(attr
, 0);
2307 if ((attr
= ippFindAttribute(response
, "printer-state-reasons",
2308 IPP_TAG_KEYWORD
)) != NULL
)
2310 strlcpy(preasons
, ippGetString(attr
, 0, NULL
), sizeof(preasons
));
2312 for (i
= 1, count
= ippGetCount(attr
), ptr
= preasons
+ strlen(preasons
),
2313 end
= preasons
+ sizeof(preasons
) - 1;
2314 i
< count
&& ptr
< end
;
2315 i
++, ptr
+= strlen(ptr
))
2318 strlcpy(ptr
, ippGetString(attr
, i
, NULL
), (size_t)(end
- ptr
+ 1));
2322 strlcpy(preasons
, "none", sizeof(preasons
));
2324 ippDelete(response
);
2327 _cupsLangPrintf(stdout
, "%s %s %s %s", service
->uri
,
2328 ippEnumString("printer-state", pstate
),
2329 paccepting
? "accepting-jobs" : "not-accepting-jobs",
2332 else if (!strncmp(service
->regtype
, "_http._tcp", 10) ||
2333 !strncmp(service
->regtype
, "_https._tcp", 11))
2336 * HTTP/HTTPS web page
2339 http_t
*http
; /* HTTP connection */
2340 http_status_t status
; /* HEAD status */
2344 * Connect to the web server...
2347 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2348 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2349 HTTP_ENCRYPTION_ALWAYS
:
2350 HTTP_ENCRYPTION_IF_REQUESTED
,
2353 httpAddrFreeList(addrlist
);
2357 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2361 if (httpGet(http
, service
->resource
))
2363 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2369 status
= httpUpdate(http
);
2371 while (status
== HTTP_STATUS_CONTINUE
);
2376 if (status
>= HTTP_STATUS_BAD_REQUEST
)
2378 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2382 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2384 else if (!strncmp(service
->regtype
, "_printer._tcp", 13))
2390 int sock
; /* Socket */
2393 if (!httpAddrConnect(addrlist
, &sock
))
2395 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2396 httpAddrFreeList(addrlist
);
2400 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2401 httpAddrFreeList(addrlist
);
2403 httpAddrClose(NULL
, sock
);
2407 _cupsLangPrintf(stdout
, "%s unsupported", service
->uri
);
2408 httpAddrFreeList(addrlist
);
2417 * 'new_expr()' - Create a new expression.
2420 static ippfind_expr_t
* /* O - New expression */
2421 new_expr(ippfind_op_t op
, /* I - Operation */
2422 int invert
, /* I - Invert result? */
2423 const char *value
, /* I - TXT key or port range */
2424 const char *regex
, /* I - Regular expression */
2425 char **args
) /* I - Pointer to argument strings */
2427 ippfind_expr_t
*temp
; /* New expression */
2430 if ((temp
= calloc(1, sizeof(ippfind_expr_t
))) == NULL
)
2434 temp
->invert
= invert
;
2436 if (op
== IPPFIND_OP_TXT_EXISTS
|| op
== IPPFIND_OP_TXT_REGEX
)
2437 temp
->key
= (char *)value
;
2438 else if (op
== IPPFIND_OP_PORT_RANGE
)
2441 * Pull port number range of the form "number", "-number" (0-number),
2442 * "number-" (number-65535), and "number-number".
2447 temp
->range
[1] = atoi(value
+ 1);
2449 else if (strchr(value
, '-'))
2451 if (sscanf(value
, "%d-%d", temp
->range
, temp
->range
+ 1) == 1)
2452 temp
->range
[1] = 65535;
2456 temp
->range
[0] = temp
->range
[1] = atoi(value
);
2462 int err
= regcomp(&(temp
->re
), regex
, REG_NOSUB
| REG_ICASE
| REG_EXTENDED
);
2466 char message
[256]; /* Error message */
2468 regerror(err
, &(temp
->re
), message
, sizeof(message
));
2469 _cupsLangPrintf(stderr
, _("ippfind: Bad regular expression: %s"),
2471 exit(IPPFIND_EXIT_SYNTAX
);
2477 int num_args
; /* Number of arguments */
2479 for (num_args
= 1; args
[num_args
]; num_args
++)
2480 if (!strcmp(args
[num_args
], ";"))
2483 temp
->num_args
= num_args
;
2484 temp
->args
= malloc((size_t)num_args
* sizeof(char *));
2485 memcpy(temp
->args
, args
, (size_t)num_args
* sizeof(char *));
2494 * 'poll_callback()' - Wait for input on the specified file descriptors.
2496 * Note: This function is needed because avahi_simple_poll_iterate is broken
2497 * and always uses a timeout of 0 (!) milliseconds.
2498 * (Avahi Ticket #364)
2501 static int /* O - Number of file descriptors matching */
2503 struct pollfd
*pollfds
, /* I - File descriptors */
2504 unsigned int num_pollfds
, /* I - Number of file descriptors */
2505 int timeout
, /* I - Timeout in milliseconds (unused) */
2506 void *context
) /* I - User data (unused) */
2508 int val
; /* Return value */
2514 val
= poll(pollfds
, num_pollfds
, 500);
2521 #endif /* HAVE_AVAHI */
2525 * 'resolve_callback()' - Process resolve data.
2529 static void DNSSD_API
2531 DNSServiceRef sdRef
, /* I - Service reference */
2532 DNSServiceFlags flags
, /* I - Data flags */
2533 uint32_t interfaceIndex
, /* I - Interface */
2534 DNSServiceErrorType errorCode
, /* I - Error, if any */
2535 const char *fullName
, /* I - Full service name */
2536 const char *hostTarget
, /* I - Hostname */
2537 uint16_t port
, /* I - Port number (network byte order) */
2538 uint16_t txtLen
, /* I - Length of TXT record data */
2539 const unsigned char *txtRecord
, /* I - TXT record data */
2540 void *context
) /* I - Service */
2542 char key
[256], /* TXT key value */
2543 *value
; /* Value from TXT record */
2544 const unsigned char *txtEnd
; /* End of TXT record */
2545 uint8_t valueLen
; /* Length of value */
2546 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2551 * Only process "add" data...
2556 (void)interfaceIndex
;
2559 if (errorCode
!= kDNSServiceErr_NoError
)
2561 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
2562 dnssd_error_string(errorCode
));
2567 service
->is_resolved
= 1;
2568 service
->host
= strdup(hostTarget
);
2569 service
->port
= ntohs(port
);
2571 value
= service
->host
+ strlen(service
->host
) - 1;
2572 if (value
>= service
->host
&& *value
== '.')
2576 * Loop through the TXT key/value pairs and add them to an array...
2579 for (txtEnd
= txtRecord
+ txtLen
; txtRecord
< txtEnd
; txtRecord
+= valueLen
)
2582 * Ignore bogus strings...
2585 valueLen
= *txtRecord
++;
2587 memcpy(key
, txtRecord
, valueLen
);
2588 key
[valueLen
] = '\0';
2590 if ((value
= strchr(key
, '=')) == NULL
)
2596 * Add to array of TXT values...
2599 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2603 set_service_uri(service
);
2607 #elif defined(HAVE_AVAHI)
2610 AvahiServiceResolver
*resolver
, /* I - Resolver */
2611 AvahiIfIndex interface
, /* I - Interface */
2612 AvahiProtocol protocol
, /* I - Address protocol */
2613 AvahiResolverEvent event
, /* I - Event */
2614 const char *serviceName
,/* I - Service name */
2615 const char *regtype
, /* I - Registration type */
2616 const char *replyDomain
,/* I - Domain name */
2617 const char *hostTarget
, /* I - FQDN */
2618 const AvahiAddress
*address
, /* I - Address */
2619 uint16_t port
, /* I - Port number */
2620 AvahiStringList
*txt
, /* I - TXT records */
2621 AvahiLookupResultFlags flags
, /* I - Lookup flags */
2622 void *context
) /* I - Service */
2624 char key
[256], /* TXT key */
2625 *value
; /* TXT value */
2626 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2628 AvahiStringList
*current
; /* Current TXT key/value pair */
2633 if (event
!= AVAHI_RESOLVER_FOUND
)
2637 avahi_service_resolver_free(resolver
);
2638 avahi_simple_poll_quit(avahi_poll
);
2642 service
->is_resolved
= 1;
2643 service
->host
= strdup(hostTarget
);
2644 service
->port
= port
;
2646 value
= service
->host
+ strlen(service
->host
) - 1;
2647 if (value
>= service
->host
&& *value
== '.')
2651 * Loop through the TXT key/value pairs and add them to an array...
2654 for (current
= txt
; current
; current
= current
->next
)
2657 * Ignore bogus strings...
2660 if (current
->size
> (sizeof(key
) - 1))
2663 memcpy(key
, current
->text
, current
->size
);
2664 key
[current
->size
] = '\0';
2666 if ((value
= strchr(key
, '=')) == NULL
)
2672 * Add to array of TXT values...
2675 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2679 set_service_uri(service
);
2681 #endif /* HAVE_DNSSD */
2685 * 'set_service_uri()' - Set the URI of the service.
2689 set_service_uri(ippfind_srv_t
*service
) /* I - Service */
2691 char uri
[1024]; /* URI */
2692 const char *path
, /* Resource path */
2693 *scheme
; /* URI scheme */
2696 if (!strncmp(service
->regtype
, "_http.", 6))
2699 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2701 else if (!strncmp(service
->regtype
, "_https.", 7))
2704 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2706 else if (!strncmp(service
->regtype
, "_ipp.", 5))
2709 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2711 else if (!strncmp(service
->regtype
, "_ipps.", 6))
2714 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2716 else if (!strncmp(service
->regtype
, "_printer.", 9))
2719 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2724 if (!path
|| !*path
)
2729 service
->resource
= strdup(path
);
2733 snprintf(uri
, sizeof(uri
), "/%s", path
);
2734 service
->resource
= strdup(uri
);
2737 httpAssembleURI(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), scheme
, NULL
,
2738 service
->host
, service
->port
, service
->resource
);
2739 service
->uri
= strdup(uri
);
2744 * 'show_usage()' - Show program usage.
2750 _cupsLangPuts(stderr
, _("Usage: ippfind [options] regtype[,subtype]"
2751 "[.domain.] ... [expression]\n"
2752 " ippfind [options] name[.regtype[.domain.]] "
2753 "... [expression]\n"
2755 " ippfind --version"));
2756 _cupsLangPuts(stderr
, "");
2757 _cupsLangPuts(stderr
, _("Options:"));
2758 _cupsLangPuts(stderr
, _(" -4 Connect using IPv4."));
2759 _cupsLangPuts(stderr
, _(" -6 Connect using IPv6."));
2760 _cupsLangPuts(stderr
, _(" -T seconds Set the browse timeout in "
2762 _cupsLangPuts(stderr
, _(" -V version Set default IPP "
2764 _cupsLangPuts(stderr
, _(" --help Show this help."));
2765 _cupsLangPuts(stderr
, _(" --version Show program version."));
2766 _cupsLangPuts(stderr
, "");
2767 _cupsLangPuts(stderr
, _("Expressions:"));
2768 _cupsLangPuts(stderr
, _(" -P number[-number] Match port to number or range."));
2769 _cupsLangPuts(stderr
, _(" -d regex Match domain to regular expression."));
2770 _cupsLangPuts(stderr
, _(" -h regex Match hostname to regular expression."));
2771 _cupsLangPuts(stderr
, _(" -l List attributes."));
2772 _cupsLangPuts(stderr
, _(" -n regex Match service name to regular expression."));
2773 _cupsLangPuts(stderr
, _(" -p Print URI if true."));
2774 _cupsLangPuts(stderr
, _(" -q Quietly report match via exit code."));
2775 _cupsLangPuts(stderr
, _(" -r True if service is remote."));
2776 _cupsLangPuts(stderr
, _(" -s Print service name if true."));
2777 _cupsLangPuts(stderr
, _(" -t key True if the TXT record contains the key."));
2778 _cupsLangPuts(stderr
, _(" -u regex Match URI to regular expression."));
2779 _cupsLangPuts(stderr
, _(" -x utility [argument ...] ;\n"
2780 " Execute program if true."));
2781 _cupsLangPuts(stderr
, _(" --domain regex Match domain to regular expression."));
2782 _cupsLangPuts(stderr
, _(" --exec utility [argument ...] ;\n"
2783 " Execute program if true."));
2784 _cupsLangPuts(stderr
, _(" --host regex Match hostname to regular expression."));
2785 _cupsLangPuts(stderr
, _(" --ls List attributes."));
2786 _cupsLangPuts(stderr
, _(" --local True if service is local."));
2787 _cupsLangPuts(stderr
, _(" --name regex Match service name to regular expression."));
2788 _cupsLangPuts(stderr
, _(" --path regex Match resource path to regular expression."));
2789 _cupsLangPuts(stderr
, _(" --port number[-number] Match port to number or range."));
2790 _cupsLangPuts(stderr
, _(" --print Print URI if true."));
2791 _cupsLangPuts(stderr
, _(" --print-name Print service name if true."));
2792 _cupsLangPuts(stderr
, _(" --quiet Quietly report match via exit code."));
2793 _cupsLangPuts(stderr
, _(" --remote True if service is remote."));
2794 _cupsLangPuts(stderr
, _(" --txt key True if the TXT record contains the key."));
2795 _cupsLangPuts(stderr
, _(" --txt-* regex Match TXT record key to regular expression."));
2796 _cupsLangPuts(stderr
, _(" --uri regex Match URI to regular expression."));
2797 _cupsLangPuts(stderr
, "");
2798 _cupsLangPuts(stderr
, _("Modifiers:"));
2799 _cupsLangPuts(stderr
, _(" ( expressions ) Group expressions."));
2800 _cupsLangPuts(stderr
, _(" ! expression Unary NOT of expression."));
2801 _cupsLangPuts(stderr
, _(" --not expression Unary NOT of expression."));
2802 _cupsLangPuts(stderr
, _(" --false Always false."));
2803 _cupsLangPuts(stderr
, _(" --true Always true."));
2804 _cupsLangPuts(stderr
, _(" expression expression Logical AND."));
2805 _cupsLangPuts(stderr
, _(" expression --and expression\n"
2807 _cupsLangPuts(stderr
, _(" expression --or expression\n"
2809 _cupsLangPuts(stderr
, "");
2810 _cupsLangPuts(stderr
, _("Substitutions:"));
2811 _cupsLangPuts(stderr
, _(" {} URI"));
2812 _cupsLangPuts(stderr
, _(" {service_domain} Domain name"));
2813 _cupsLangPuts(stderr
, _(" {service_hostname} Fully-qualified domain name"));
2814 _cupsLangPuts(stderr
, _(" {service_name} Service instance name"));
2815 _cupsLangPuts(stderr
, _(" {service_port} Port number"));
2816 _cupsLangPuts(stderr
, _(" {service_regtype} DNS-SD registration type"));
2817 _cupsLangPuts(stderr
, _(" {service_scheme} URI scheme"));
2818 _cupsLangPuts(stderr
, _(" {service_uri} URI"));
2819 _cupsLangPuts(stderr
, _(" {txt_*} Value of TXT record key"));
2820 _cupsLangPuts(stderr
, "");
2821 _cupsLangPuts(stderr
, _("Environment Variables:"));
2822 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_DOMAIN Domain name"));
2823 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_HOSTNAME\n"
2824 " Fully-qualified domain name"));
2825 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_NAME Service instance name"));
2826 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_PORT Port number"));
2827 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_REGTYPE DNS-SD registration type"));
2828 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_SCHEME URI scheme"));
2829 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_URI URI"));
2830 _cupsLangPuts(stderr
, _(" IPPFIND_TXT_* Value of TXT record key"));
2832 exit(IPPFIND_EXIT_TRUE
);
2837 * 'show_version()' - Show program version.
2843 _cupsLangPuts(stderr
, CUPS_SVERSION
);
2845 exit(IPPFIND_EXIT_TRUE
);