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-2015 by Apple Inc.
8 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
12 * Include necessary headers.
15 #define _CUPS_NO_DEPRECATED
16 #include <cups/cups-private.h>
19 # include <sys/timeb.h>
21 # include <sys/wait.h>
26 #elif defined(HAVE_AVAHI)
27 # include <avahi-client/client.h>
28 # include <avahi-client/lookup.h>
29 # include <avahi-common/simple-watch.h>
30 # include <avahi-common/domain.h>
31 # include <avahi-common/error.h>
32 # include <avahi-common/malloc.h>
33 # define kDNSServiceMaxDomainName AVAHI_DOMAIN_NAME_MAX
34 #endif /* HAVE_DNSSD */
37 extern char **environ
; /* Process environment variables */
45 typedef enum ippfind_exit_e
/* Exit codes */
47 IPPFIND_EXIT_TRUE
= 0, /* OK and result is true */
48 IPPFIND_EXIT_FALSE
, /* OK but result is false*/
49 IPPFIND_EXIT_BONJOUR
, /* Browse/resolve failure */
50 IPPFIND_EXIT_SYNTAX
, /* Bad option or syntax error */
51 IPPFIND_EXIT_MEMORY
/* Out of memory */
54 typedef enum ippfind_op_e
/* Operations for expressions */
56 /* "Evaluation" operations */
57 IPPFIND_OP_NONE
, /* No operation */
58 IPPFIND_OP_AND
, /* Logical AND of all children */
59 IPPFIND_OP_OR
, /* Logical OR of all children */
60 IPPFIND_OP_TRUE
, /* Always true */
61 IPPFIND_OP_FALSE
, /* Always false */
62 IPPFIND_OP_IS_LOCAL
, /* Is a local service */
63 IPPFIND_OP_IS_REMOTE
, /* Is a remote service */
64 IPPFIND_OP_DOMAIN_REGEX
, /* Domain matches regular expression */
65 IPPFIND_OP_NAME_REGEX
, /* Name matches regular expression */
66 IPPFIND_OP_HOST_REGEX
, /* Hostname matches regular expression */
67 IPPFIND_OP_PORT_RANGE
, /* Port matches range */
68 IPPFIND_OP_PATH_REGEX
, /* Path matches regular expression */
69 IPPFIND_OP_TXT_EXISTS
, /* TXT record key exists */
70 IPPFIND_OP_TXT_REGEX
, /* TXT record key matches regular expression */
71 IPPFIND_OP_URI_REGEX
, /* URI matches regular expression */
73 /* "Output" operations */
74 IPPFIND_OP_EXEC
, /* Execute when true */
75 IPPFIND_OP_LIST
, /* List when true */
76 IPPFIND_OP_PRINT_NAME
, /* Print URI when true */
77 IPPFIND_OP_PRINT_URI
, /* Print name when true */
78 IPPFIND_OP_QUIET
/* No output when true */
81 typedef struct ippfind_expr_s
/* Expression */
84 *prev
, /* Previous expression */
85 *next
, /* Next expression */
86 *parent
, /* Parent expressions */
87 *child
; /* Child expressions */
88 ippfind_op_t op
; /* Operation code (see above) */
89 int invert
; /* Invert the result */
90 char *key
; /* TXT record key */
91 regex_t re
; /* Regular expression for matching */
92 int range
[2]; /* Port number range */
93 int num_args
; /* Number of arguments for exec */
94 char **args
; /* Arguments for exec */
97 typedef struct ippfind_srv_s
/* Service information */
100 DNSServiceRef ref
; /* Service reference for query */
101 #elif defined(HAVE_AVAHI)
102 AvahiServiceResolver
*ref
; /* Resolver */
103 #endif /* HAVE_DNSSD */
104 char *name
, /* Service name */
105 *domain
, /* Domain name */
106 *regtype
, /* Registration type */
107 *fullName
, /* Full name */
108 *host
, /* Hostname */
109 *resource
, /* Resource path */
111 int num_txt
; /* Number of TXT record keys */
112 cups_option_t
*txt
; /* TXT record keys */
113 int port
, /* Port number */
114 is_local
, /* Is a local service? */
115 is_processed
, /* Did we process the service? */
116 is_resolved
; /* Got the resolve data? */
125 static DNSServiceRef dnssd_ref
; /* Master service reference */
126 #elif defined(HAVE_AVAHI)
127 static AvahiClient
*avahi_client
= NULL
;/* Client information */
128 static int avahi_got_data
= 0; /* Got data from poll? */
129 static AvahiSimplePoll
*avahi_poll
= NULL
;
130 /* Poll information */
131 #endif /* HAVE_DNSSD */
133 static int address_family
= AF_UNSPEC
;
134 /* Address family for LIST */
135 static int bonjour_error
= 0; /* Error browsing/resolving? */
136 static double bonjour_timeout
= 1.0; /* Timeout in seconds */
137 static int ipp_version
= 20; /* IPP version for LIST */
145 static void DNSSD_API
browse_callback(DNSServiceRef sdRef
,
146 DNSServiceFlags flags
,
147 uint32_t interfaceIndex
,
148 DNSServiceErrorType errorCode
,
149 const char *serviceName
,
151 const char *replyDomain
, void *context
)
152 __attribute__((nonnull(1,5,6,7,8)));
153 static void DNSSD_API
browse_local_callback(DNSServiceRef sdRef
,
154 DNSServiceFlags flags
,
155 uint32_t interfaceIndex
,
156 DNSServiceErrorType errorCode
,
157 const char *serviceName
,
159 const char *replyDomain
,
161 __attribute__((nonnull(1,5,6,7,8)));
162 #elif defined(HAVE_AVAHI)
163 static void browse_callback(AvahiServiceBrowser
*browser
,
164 AvahiIfIndex interface
,
165 AvahiProtocol protocol
,
166 AvahiBrowserEvent event
,
167 const char *serviceName
,
169 const char *replyDomain
,
170 AvahiLookupResultFlags flags
,
172 static void client_callback(AvahiClient
*client
,
173 AvahiClientState state
,
175 #endif /* HAVE_AVAHI */
177 static int compare_services(ippfind_srv_t
*a
, ippfind_srv_t
*b
);
178 static const char *dnssd_error_string(int error
);
179 static int eval_expr(ippfind_srv_t
*service
,
180 ippfind_expr_t
*expressions
);
181 static int exec_program(ippfind_srv_t
*service
, int num_args
,
183 static ippfind_srv_t
*get_service(cups_array_t
*services
,
184 const char *serviceName
,
186 const char *replyDomain
)
187 __attribute__((nonnull(1,2,3,4)));
188 static double get_time(void);
189 static int list_service(ippfind_srv_t
*service
);
190 static ippfind_expr_t
*new_expr(ippfind_op_t op
, int invert
,
191 const char *value
, const char *regex
,
194 static void DNSSD_API
resolve_callback(DNSServiceRef sdRef
,
195 DNSServiceFlags flags
,
196 uint32_t interfaceIndex
,
197 DNSServiceErrorType errorCode
,
198 const char *fullName
,
199 const char *hostTarget
, uint16_t port
,
201 const unsigned char *txtRecord
,
203 __attribute__((nonnull(1,5,6,9, 10)));
204 #elif defined(HAVE_AVAHI)
205 static int poll_callback(struct pollfd
*pollfds
,
206 unsigned int num_pollfds
, int timeout
,
208 static void resolve_callback(AvahiServiceResolver
*res
,
209 AvahiIfIndex interface
,
210 AvahiProtocol protocol
,
211 AvahiResolverEvent event
,
212 const char *serviceName
,
214 const char *replyDomain
,
215 const char *host_name
,
216 const AvahiAddress
*address
,
218 AvahiStringList
*txt
,
219 AvahiLookupResultFlags flags
,
221 #endif /* HAVE_DNSSD */
222 static void set_service_uri(ippfind_srv_t
*service
);
223 static void show_usage(void) __attribute__((noreturn
));
224 static void show_version(void) __attribute__((noreturn
));
228 * 'main()' - Browse for printers.
231 int /* O - Exit status */
232 main(int argc
, /* I - Number of command-line args */
233 char *argv
[]) /* I - Command-line arguments */
235 int i
, /* Looping var */
236 have_output
= 0,/* Have output expression */
237 status
= IPPFIND_EXIT_FALSE
;
239 const char *opt
, /* Option character */
240 *search
; /* Current browse/resolve string */
241 cups_array_t
*searches
; /* Things to browse/resolve */
242 cups_array_t
*services
; /* Service array */
243 ippfind_srv_t
*service
; /* Current service */
244 ippfind_expr_t
*expressions
= NULL
,
245 /* Expression tree */
246 *temp
= NULL
, /* New expression */
247 *parent
= NULL
, /* Parent expression */
248 *current
= NULL
,/* Current expression */
249 *parens
[100]; /* Markers for parenthesis */
250 int num_parens
= 0; /* Number of parenthesis */
251 ippfind_op_t logic
= IPPFIND_OP_AND
;
252 /* Logic for next expression */
253 int invert
= 0; /* Invert expression? */
254 int err
; /* DNS-SD error */
256 fd_set sinput
; /* Input set for select() */
257 struct timeval stimeout
; /* Timeout for select() */
258 #endif /* HAVE_DNSSD */
259 double endtime
; /* End time */
260 static const char * const ops
[] = /* Node operation names */
286 * Initialize the locale...
289 _cupsSetLocale(argv
);
292 * Create arrays to track services and things we want to browse/resolve...
295 searches
= cupsArrayNew(NULL
, NULL
);
296 services
= cupsArrayNew((cups_array_func_t
)compare_services
, NULL
);
299 * Parse command-line...
302 if (getenv("IPPFIND_DEBUG"))
303 for (i
= 1; i
< argc
; i
++)
304 fprintf(stderr
, "argv[%d]=\"%s\"\n", i
, argv
[i
]);
306 for (i
= 1; i
< argc
; i
++)
308 if (argv
[i
][0] == '-')
310 if (argv
[i
][1] == '-')
313 * Parse --option options...
316 if (!strcmp(argv
[i
], "--and"))
318 if (logic
== IPPFIND_OP_OR
)
320 _cupsLangPuts(stderr
, _("ippfind: Cannot use --and after --or."));
326 _cupsLangPuts(stderr
,
327 _("ippfind: Missing expression before \"--and\"."));
333 else if (!strcmp(argv
[i
], "--domain"))
338 _cupsLangPrintf(stderr
,
339 _("ippfind: Missing regular expression after %s."),
344 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
, argv
[i
],
346 return (IPPFIND_EXIT_MEMORY
);
348 else if (!strcmp(argv
[i
], "--exec"))
353 _cupsLangPrintf(stderr
, _("ippfind: Expected program after %s."),
358 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
360 return (IPPFIND_EXIT_MEMORY
);
363 if (!strcmp(argv
[i
], ";"))
370 _cupsLangPrintf(stderr
, _("ippfind: Expected semi-colon after %s."),
377 else if (!strcmp(argv
[i
], "--false"))
379 if ((temp
= new_expr(IPPFIND_OP_FALSE
, invert
, NULL
, NULL
,
381 return (IPPFIND_EXIT_MEMORY
);
383 else if (!strcmp(argv
[i
], "--help"))
387 else if (!strcmp(argv
[i
], "--host"))
392 _cupsLangPrintf(stderr
,
393 _("ippfind: Missing regular expression after %s."),
398 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
, argv
[i
],
400 return (IPPFIND_EXIT_MEMORY
);
402 else if (!strcmp(argv
[i
], "--ls"))
404 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
406 return (IPPFIND_EXIT_MEMORY
);
410 else if (!strcmp(argv
[i
], "--local"))
412 if ((temp
= new_expr(IPPFIND_OP_IS_LOCAL
, invert
, NULL
, NULL
,
414 return (IPPFIND_EXIT_MEMORY
);
416 else if (!strcmp(argv
[i
], "--name"))
421 _cupsLangPrintf(stderr
,
422 _("ippfind: Missing regular expression after %s."),
427 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
, argv
[i
],
429 return (IPPFIND_EXIT_MEMORY
);
431 else if (!strcmp(argv
[i
], "--not"))
435 else if (!strcmp(argv
[i
], "--or"))
439 _cupsLangPuts(stderr
,
440 _("ippfind: Missing expression before \"--or\"."));
444 logic
= IPPFIND_OP_OR
;
446 if (parent
&& parent
->op
== IPPFIND_OP_OR
)
449 * Already setup to do "foo --or bar --or baz"...
454 else if (!current
->prev
&& parent
)
457 * Change parent node into an OR node...
460 parent
->op
= IPPFIND_OP_OR
;
463 else if (!current
->prev
)
466 * Need to group "current" in a new OR node...
469 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
471 return (IPPFIND_EXIT_MEMORY
);
473 temp
->parent
= parent
;
474 temp
->child
= current
;
475 current
->parent
= temp
;
478 parent
->child
= temp
;
488 * Need to group previous expressions in an AND node, and then
489 * put that in an OR node...
492 if ((temp
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
494 return (IPPFIND_EXIT_MEMORY
);
496 while (current
->prev
)
498 current
->parent
= temp
;
499 current
= current
->prev
;
502 current
->parent
= temp
;
503 temp
->child
= current
;
506 if ((temp
= new_expr(IPPFIND_OP_OR
, 0, NULL
, NULL
,
508 return (IPPFIND_EXIT_MEMORY
);
510 temp
->parent
= parent
;
511 current
->parent
= temp
;
514 parent
->child
= temp
;
522 else if (!strcmp(argv
[i
], "--path"))
527 _cupsLangPrintf(stderr
,
528 _("ippfind: Missing regular expression after %s."),
533 if ((temp
= new_expr(IPPFIND_OP_PATH_REGEX
, invert
, NULL
, argv
[i
],
535 return (IPPFIND_EXIT_MEMORY
);
537 else if (!strcmp(argv
[i
], "--port"))
542 _cupsLangPrintf(stderr
,
543 _("ippfind: Expected port range after %s."),
548 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
], NULL
,
550 return (IPPFIND_EXIT_MEMORY
);
552 else if (!strcmp(argv
[i
], "--print"))
554 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
556 return (IPPFIND_EXIT_MEMORY
);
560 else if (!strcmp(argv
[i
], "--print-name"))
562 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
564 return (IPPFIND_EXIT_MEMORY
);
568 else if (!strcmp(argv
[i
], "--quiet"))
570 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
572 return (IPPFIND_EXIT_MEMORY
);
576 else if (!strcmp(argv
[i
], "--remote"))
578 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
580 return (IPPFIND_EXIT_MEMORY
);
582 else if (!strcmp(argv
[i
], "--true"))
584 if ((temp
= new_expr(IPPFIND_OP_TRUE
, invert
, NULL
, argv
[i
],
586 return (IPPFIND_EXIT_MEMORY
);
588 else if (!strcmp(argv
[i
], "--txt"))
593 _cupsLangPrintf(stderr
, _("ippfind: Expected key name after %s."),
598 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
], NULL
,
600 return (IPPFIND_EXIT_MEMORY
);
602 else if (!strncmp(argv
[i
], "--txt-", 6))
604 const char *key
= argv
[i
] + 6;/* TXT key */
609 _cupsLangPrintf(stderr
,
610 _("ippfind: Missing regular expression after %s."),
615 if ((temp
= new_expr(IPPFIND_OP_TXT_REGEX
, invert
, key
, argv
[i
],
617 return (IPPFIND_EXIT_MEMORY
);
619 else if (!strcmp(argv
[i
], "--uri"))
624 _cupsLangPrintf(stderr
,
625 _("ippfind: Missing regular expression after %s."),
630 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
, argv
[i
],
632 return (IPPFIND_EXIT_MEMORY
);
634 else if (!strcmp(argv
[i
], "--version"))
640 _cupsLangPrintf(stderr
, _("%s: Unknown option \"%s\"."),
648 * Add new expression...
651 if (logic
== IPPFIND_OP_AND
&&
652 current
&& current
->prev
&&
653 parent
&& parent
->op
!= IPPFIND_OP_AND
)
656 * Need to re-group "current" in a new AND node...
659 ippfind_expr_t
*tempand
; /* Temporary AND node */
661 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
663 return (IPPFIND_EXIT_MEMORY
);
666 * Replace "current" with new AND node at the end of this list...
669 current
->prev
->next
= tempand
;
670 tempand
->prev
= current
->prev
;
671 tempand
->parent
= parent
;
674 * Add "current to the new AND node...
677 tempand
->child
= current
;
678 current
->parent
= tempand
;
679 current
->prev
= NULL
;
684 * Add the new node at current level...
687 temp
->parent
= parent
;
688 temp
->prev
= current
;
691 current
->next
= temp
;
693 parent
->child
= temp
;
699 logic
= IPPFIND_OP_AND
;
709 for (opt
= argv
[i
] + 1; *opt
; opt
++)
714 address_family
= AF_INET
;
718 address_family
= AF_INET6
;
725 _cupsLangPrintf(stderr
,
726 _("ippfind: Expected port range after %s."),
731 if ((temp
= new_expr(IPPFIND_OP_PORT_RANGE
, invert
, argv
[i
],
732 NULL
, NULL
)) == NULL
)
733 return (IPPFIND_EXIT_MEMORY
);
740 _cupsLangPrintf(stderr
,
741 _("%s: Missing timeout for \"-T\"."),
746 bonjour_timeout
= atof(argv
[i
]);
753 _cupsLangPrintf(stderr
,
754 _("%s: Missing version for \"-V\"."),
759 if (!strcmp(argv
[i
], "1.1"))
761 else if (!strcmp(argv
[i
], "2.0"))
763 else if (!strcmp(argv
[i
], "2.1"))
765 else if (!strcmp(argv
[i
], "2.2"))
769 _cupsLangPrintf(stderr
, _("%s: Bad version %s for \"-V\"."),
779 _cupsLangPrintf(stderr
,
780 _("ippfind: Missing regular expression after "
785 if ((temp
= new_expr(IPPFIND_OP_DOMAIN_REGEX
, invert
, NULL
,
786 argv
[i
], NULL
)) == NULL
)
787 return (IPPFIND_EXIT_MEMORY
);
794 _cupsLangPrintf(stderr
,
795 _("ippfind: Missing regular expression after "
800 if ((temp
= new_expr(IPPFIND_OP_HOST_REGEX
, invert
, NULL
,
801 argv
[i
], NULL
)) == NULL
)
802 return (IPPFIND_EXIT_MEMORY
);
806 if ((temp
= new_expr(IPPFIND_OP_LIST
, invert
, NULL
, NULL
,
808 return (IPPFIND_EXIT_MEMORY
);
817 _cupsLangPrintf(stderr
,
818 _("ippfind: Missing regular expression after "
823 if ((temp
= new_expr(IPPFIND_OP_NAME_REGEX
, invert
, NULL
,
824 argv
[i
], NULL
)) == NULL
)
825 return (IPPFIND_EXIT_MEMORY
);
829 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, invert
, NULL
, NULL
,
831 return (IPPFIND_EXIT_MEMORY
);
837 if ((temp
= new_expr(IPPFIND_OP_QUIET
, invert
, NULL
, NULL
,
839 return (IPPFIND_EXIT_MEMORY
);
845 if ((temp
= new_expr(IPPFIND_OP_IS_REMOTE
, invert
, NULL
, NULL
,
847 return (IPPFIND_EXIT_MEMORY
);
851 if ((temp
= new_expr(IPPFIND_OP_PRINT_NAME
, invert
, NULL
, NULL
,
853 return (IPPFIND_EXIT_MEMORY
);
862 _cupsLangPrintf(stderr
,
863 _("ippfind: Missing key name after %s."),
868 if ((temp
= new_expr(IPPFIND_OP_TXT_EXISTS
, invert
, argv
[i
],
869 NULL
, NULL
)) == NULL
)
870 return (IPPFIND_EXIT_MEMORY
);
877 _cupsLangPrintf(stderr
,
878 _("ippfind: Missing regular expression after "
883 if ((temp
= new_expr(IPPFIND_OP_URI_REGEX
, invert
, NULL
,
884 argv
[i
], NULL
)) == NULL
)
885 return (IPPFIND_EXIT_MEMORY
);
892 _cupsLangPrintf(stderr
,
893 _("ippfind: Missing program after %s."),
898 if ((temp
= new_expr(IPPFIND_OP_EXEC
, invert
, NULL
, NULL
,
900 return (IPPFIND_EXIT_MEMORY
);
903 if (!strcmp(argv
[i
], ";"))
910 _cupsLangPrintf(stderr
,
911 _("ippfind: Missing semi-colon after %s."),
920 _cupsLangPrintf(stderr
, _("%s: Unknown option \"-%c\"."),
928 * Add new expression...
931 if (logic
== IPPFIND_OP_AND
&&
932 current
&& current
->prev
&&
933 parent
&& parent
->op
!= IPPFIND_OP_AND
)
936 * Need to re-group "current" in a new AND node...
939 ippfind_expr_t
*tempand
; /* Temporary AND node */
941 if ((tempand
= new_expr(IPPFIND_OP_AND
, 0, NULL
, NULL
,
943 return (IPPFIND_EXIT_MEMORY
);
946 * Replace "current" with new AND node at the end of this list...
949 current
->prev
->next
= tempand
;
950 tempand
->prev
= current
->prev
;
951 tempand
->parent
= parent
;
954 * Add "current to the new AND node...
957 tempand
->child
= current
;
958 current
->parent
= tempand
;
959 current
->prev
= NULL
;
964 * Add the new node at current level...
967 temp
->parent
= parent
;
968 temp
->prev
= current
;
971 current
->next
= temp
;
973 parent
->child
= temp
;
979 logic
= IPPFIND_OP_AND
;
985 else if (!strcmp(argv
[i
], "("))
987 if (num_parens
>= 100)
989 _cupsLangPuts(stderr
, _("ippfind: Too many parenthesis."));
993 if ((temp
= new_expr(IPPFIND_OP_AND
, invert
, NULL
, NULL
, NULL
)) == NULL
)
994 return (IPPFIND_EXIT_MEMORY
);
996 parens
[num_parens
++] = temp
;
1000 temp
->parent
= current
->parent
;
1001 current
->next
= temp
;
1002 temp
->prev
= current
;
1010 logic
= IPPFIND_OP_AND
;
1012 else if (!strcmp(argv
[i
], ")"))
1014 if (num_parens
<= 0)
1016 _cupsLangPuts(stderr
, _("ippfind: Missing open parenthesis."));
1020 current
= parens
[--num_parens
];
1021 parent
= current
->parent
;
1023 logic
= IPPFIND_OP_AND
;
1025 else if (!strcmp(argv
[i
], "!"))
1032 * _regtype._tcp[,subtype][.domain]
1036 * service-name[._regtype._tcp[.domain]]
1039 cupsArrayAdd(searches
, argv
[i
]);
1045 _cupsLangPuts(stderr
, _("ippfind: Missing close parenthesis."));
1052 * Add an implicit --print-uri to the end...
1055 if ((temp
= new_expr(IPPFIND_OP_PRINT_URI
, 0, NULL
, NULL
, NULL
)) == NULL
)
1056 return (IPPFIND_EXIT_MEMORY
);
1060 while (current
->parent
)
1061 current
= current
->parent
;
1063 current
->next
= temp
;
1064 temp
->prev
= current
;
1070 if (cupsArrayCount(searches
) == 0)
1073 * Add an implicit browse for IPP printers ("_ipp._tcp")...
1076 cupsArrayAdd(searches
, "_ipp._tcp");
1079 if (getenv("IPPFIND_DEBUG"))
1081 int indent
= 4; /* Indentation */
1083 puts("Expression tree:");
1084 current
= expressions
;
1088 * Print the current node...
1091 printf("%*s%s%s\n", indent
, "", current
->invert
? "!" : "",
1095 * Advance to the next node...
1100 current
= current
->child
;
1103 else if (current
->next
)
1104 current
= current
->next
;
1105 else if (current
->parent
)
1107 while (current
->parent
)
1110 current
= current
->parent
;
1115 current
= current
->next
;
1121 puts("\nSearch items:");
1122 for (search
= (const char *)cupsArrayFirst(searches
);
1124 search
= (const char *)cupsArrayNext(searches
))
1125 printf(" %s\n", search
);
1129 * Start up browsing/resolving...
1133 if ((err
= DNSServiceCreateConnection(&dnssd_ref
)) != kDNSServiceErr_NoError
)
1135 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1136 dnssd_error_string(err
));
1137 return (IPPFIND_EXIT_BONJOUR
);
1140 #elif defined(HAVE_AVAHI)
1141 if ((avahi_poll
= avahi_simple_poll_new()) == NULL
)
1143 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1145 return (IPPFIND_EXIT_BONJOUR
);
1148 avahi_simple_poll_set_func(avahi_poll
, poll_callback
, NULL
);
1150 avahi_client
= avahi_client_new(avahi_simple_poll_get(avahi_poll
),
1151 0, client_callback
, avahi_poll
, &err
);
1154 _cupsLangPrintf(stderr
, _("ippfind: Unable to use Bonjour: %s"),
1155 dnssd_error_string(err
));
1156 return (IPPFIND_EXIT_BONJOUR
);
1158 #endif /* HAVE_DNSSD */
1160 for (search
= (const char *)cupsArrayFirst(searches
);
1162 search
= (const char *)cupsArrayNext(searches
))
1164 char buf
[1024], /* Full name string */
1165 *name
= NULL
, /* Service instance name */
1166 *regtype
, /* Registration type */
1167 *domain
; /* Domain, if any */
1169 strlcpy(buf
, search
, sizeof(buf
));
1174 else if ((regtype
= strstr(buf
, "._")) != NULL
)
1182 regtype
= "_ipp._tcp";
1185 for (domain
= regtype
; *domain
; domain
++)
1186 if (*domain
== '.' && domain
[1] != '_')
1198 * Resolve the given service instance name, regtype, and domain...
1204 service
= get_service(services
, name
, regtype
, domain
);
1207 service
->ref
= dnssd_ref
;
1208 err
= DNSServiceResolve(&(service
->ref
),
1209 kDNSServiceFlagsShareConnection
, 0, name
,
1210 regtype
, domain
, resolve_callback
,
1213 #elif defined(HAVE_AVAHI)
1214 service
->ref
= avahi_service_resolver_new(avahi_client
, AVAHI_IF_UNSPEC
,
1215 AVAHI_PROTO_UNSPEC
, name
,
1217 AVAHI_PROTO_UNSPEC
, 0,
1218 resolve_callback
, service
);
1222 err
= avahi_client_errno(avahi_client
);
1223 #endif /* HAVE_DNSSD */
1228 * Browse for services of the given type...
1232 DNSServiceRef ref
; /* Browse reference */
1235 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
, 0, regtype
,
1236 domain
, browse_callback
, services
);
1241 err
= DNSServiceBrowse(&ref
, kDNSServiceFlagsShareConnection
,
1242 kDNSServiceInterfaceIndexLocalOnly
, regtype
,
1243 domain
, browse_local_callback
, services
);
1246 #elif defined(HAVE_AVAHI)
1247 if (avahi_service_browser_new(avahi_client
, AVAHI_IF_UNSPEC
,
1248 AVAHI_PROTO_UNSPEC
, regtype
, domain
, 0,
1249 browse_callback
, services
))
1252 err
= avahi_client_errno(avahi_client
);
1253 #endif /* HAVE_DNSSD */
1258 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
1259 dnssd_error_string(err
));
1262 printf("name=\"%s\"\n", name
);
1264 printf("regtype=\"%s\"\n", regtype
);
1267 printf("domain=\"%s\"\n", domain
);
1269 return (IPPFIND_EXIT_BONJOUR
);
1274 * Process browse/resolve requests...
1277 if (bonjour_timeout
> 1.0)
1278 endtime
= get_time() + bonjour_timeout
;
1280 endtime
= get_time() + 300.0;
1282 while (get_time() < endtime
)
1284 int process
= 0; /* Process services? */
1287 int fd
= DNSServiceRefSockFD(dnssd_ref
);
1288 /* File descriptor for DNS-SD */
1291 FD_SET(fd
, &sinput
);
1293 stimeout
.tv_sec
= 0;
1294 stimeout
.tv_usec
= 500000;
1296 if (select(fd
+ 1, &sinput
, NULL
, NULL
, &stimeout
) < 0)
1299 if (FD_ISSET(fd
, &sinput
))
1302 * Process responses...
1305 DNSServiceProcessResult(dnssd_ref
);
1310 * Time to process services...
1316 #elif defined(HAVE_AVAHI)
1319 if (avahi_simple_poll_iterate(avahi_poll
, 500) > 0)
1322 * We've been told to exit the loop. Perhaps the connection to
1326 return (IPPFIND_EXIT_BONJOUR
);
1329 if (!avahi_got_data
)
1332 * Time to process services...
1337 #endif /* HAVE_DNSSD */
1342 * Process any services that we have found...
1345 int active
= 0, /* Number of active resolves */
1346 resolved
= 0, /* Number of resolved services */
1347 processed
= 0; /* Number of processed services */
1349 for (service
= (ippfind_srv_t
*)cupsArrayFirst(services
);
1351 service
= (ippfind_srv_t
*)cupsArrayNext(services
))
1353 if (service
->is_processed
)
1356 if (service
->is_resolved
)
1359 if (!service
->ref
&& !service
->is_resolved
)
1362 * Found a service, now resolve it (but limit to 50 active resolves...)
1368 service
->ref
= dnssd_ref
;
1369 err
= DNSServiceResolve(&(service
->ref
),
1370 kDNSServiceFlagsShareConnection
, 0,
1371 service
->name
, service
->regtype
,
1372 service
->domain
, resolve_callback
,
1375 #elif defined(HAVE_AVAHI)
1376 service
->ref
= avahi_service_resolver_new(avahi_client
,
1382 AVAHI_PROTO_UNSPEC
, 0,
1388 err
= avahi_client_errno(avahi_client
);
1389 #endif /* HAVE_DNSSD */
1393 _cupsLangPrintf(stderr
,
1394 _("ippfind: Unable to browse or resolve: %s"),
1395 dnssd_error_string(err
));
1396 return (IPPFIND_EXIT_BONJOUR
);
1402 else if (service
->is_resolved
&& !service
->is_processed
)
1405 * Resolved, not process this service against the expressions...
1411 DNSServiceRefDeallocate(service
->ref
);
1413 avahi_service_resolver_free(service
->ref
);
1414 #endif /* HAVE_DNSSD */
1416 service
->ref
= NULL
;
1419 if (eval_expr(service
, expressions
))
1420 status
= IPPFIND_EXIT_TRUE
;
1422 service
->is_processed
= 1;
1424 else if (service
->ref
)
1429 * If we have processed all services we have discovered, then we are done.
1432 if (processed
== cupsArrayCount(services
) && bonjour_timeout
<= 1.0)
1438 return (IPPFIND_EXIT_BONJOUR
);
1446 * 'browse_callback()' - Browse devices.
1449 static void DNSSD_API
1451 DNSServiceRef sdRef
, /* I - Service reference */
1452 DNSServiceFlags flags
, /* I - Option flags */
1453 uint32_t interfaceIndex
, /* I - Interface number */
1454 DNSServiceErrorType errorCode
, /* I - Error, if any */
1455 const char *serviceName
, /* I - Name of service/device */
1456 const char *regtype
, /* I - Type of service */
1457 const char *replyDomain
, /* I - Service domain */
1458 void *context
) /* I - Services array */
1461 * Only process "add" data...
1465 (void)interfaceIndex
;
1467 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1474 get_service((cups_array_t
*)context
, serviceName
, regtype
, replyDomain
);
1479 * 'browse_local_callback()' - Browse local devices.
1482 static void DNSSD_API
1483 browse_local_callback(
1484 DNSServiceRef sdRef
, /* I - Service reference */
1485 DNSServiceFlags flags
, /* I - Option flags */
1486 uint32_t interfaceIndex
, /* I - Interface number */
1487 DNSServiceErrorType errorCode
, /* I - Error, if any */
1488 const char *serviceName
, /* I - Name of service/device */
1489 const char *regtype
, /* I - Type of service */
1490 const char *replyDomain
, /* I - Service domain */
1491 void *context
) /* I - Services array */
1493 ippfind_srv_t
*service
; /* Service */
1497 * Only process "add" data...
1501 (void)interfaceIndex
;
1503 if (errorCode
!= kDNSServiceErr_NoError
|| !(flags
& kDNSServiceFlagsAdd
))
1510 service
= get_service((cups_array_t
*)context
, serviceName
, regtype
,
1512 service
->is_local
= 1;
1514 #endif /* HAVE_DNSSD */
1519 * 'browse_callback()' - Browse devices.
1524 AvahiServiceBrowser
*browser
, /* I - Browser */
1525 AvahiIfIndex interface
, /* I - Interface index (unused) */
1526 AvahiProtocol protocol
, /* I - Network protocol (unused) */
1527 AvahiBrowserEvent event
, /* I - What happened */
1528 const char *name
, /* I - Service name */
1529 const char *type
, /* I - Registration type */
1530 const char *domain
, /* I - Domain */
1531 AvahiLookupResultFlags flags
, /* I - Flags */
1532 void *context
) /* I - Services array */
1534 AvahiClient
*client
= avahi_service_browser_get_client(browser
);
1535 /* Client information */
1536 ippfind_srv_t
*service
; /* Service information */
1545 case AVAHI_BROWSER_FAILURE
:
1546 fprintf(stderr
, "DEBUG: browse_callback: %s\n",
1547 avahi_strerror(avahi_client_errno(client
)));
1549 avahi_simple_poll_quit(avahi_poll
);
1552 case AVAHI_BROWSER_NEW
:
1554 * This object is new on the network. Create a device entry for it if
1555 * it doesn't yet exist.
1558 service
= get_service((cups_array_t
*)context
, name
, type
, domain
);
1560 if (flags
& AVAHI_LOOKUP_RESULT_LOCAL
)
1561 service
->is_local
= 1;
1564 case AVAHI_BROWSER_REMOVE
:
1565 case AVAHI_BROWSER_ALL_FOR_NOW
:
1566 case AVAHI_BROWSER_CACHE_EXHAUSTED
:
1573 * 'client_callback()' - Avahi client callback function.
1578 AvahiClient
*client
, /* I - Client information (unused) */
1579 AvahiClientState state
, /* I - Current state */
1580 void *context
) /* I - User data (unused) */
1586 * If the connection drops, quit.
1589 if (state
== AVAHI_CLIENT_FAILURE
)
1591 fputs("DEBUG: Avahi connection failed.\n", stderr
);
1593 avahi_simple_poll_quit(avahi_poll
);
1596 #endif /* HAVE_AVAHI */
1600 * 'compare_services()' - Compare two devices.
1603 static int /* O - Result of comparison */
1604 compare_services(ippfind_srv_t
*a
, /* I - First device */
1605 ippfind_srv_t
*b
) /* I - Second device */
1607 return (strcmp(a
->name
, b
->name
));
1612 * 'dnssd_error_string()' - Return an error string for an error code.
1615 static const char * /* O - Error message */
1616 dnssd_error_string(int error
) /* I - Error number */
1621 case kDNSServiceErr_NoError
:
1625 case kDNSServiceErr_Unknown
:
1626 return ("Unknown error.");
1628 case kDNSServiceErr_NoSuchName
:
1629 return ("Service not found.");
1631 case kDNSServiceErr_NoMemory
:
1632 return ("Out of memory.");
1634 case kDNSServiceErr_BadParam
:
1635 return ("Bad parameter.");
1637 case kDNSServiceErr_BadReference
:
1638 return ("Bad service reference.");
1640 case kDNSServiceErr_BadState
:
1641 return ("Bad state.");
1643 case kDNSServiceErr_BadFlags
:
1644 return ("Bad flags.");
1646 case kDNSServiceErr_Unsupported
:
1647 return ("Unsupported.");
1649 case kDNSServiceErr_NotInitialized
:
1650 return ("Not initialized.");
1652 case kDNSServiceErr_AlreadyRegistered
:
1653 return ("Already registered.");
1655 case kDNSServiceErr_NameConflict
:
1656 return ("Name conflict.");
1658 case kDNSServiceErr_Invalid
:
1659 return ("Invalid name.");
1661 case kDNSServiceErr_Firewall
:
1662 return ("Firewall prevents registration.");
1664 case kDNSServiceErr_Incompatible
:
1665 return ("Client library incompatible.");
1667 case kDNSServiceErr_BadInterfaceIndex
:
1668 return ("Bad interface index.");
1670 case kDNSServiceErr_Refused
:
1671 return ("Server prevents registration.");
1673 case kDNSServiceErr_NoSuchRecord
:
1674 return ("Record not found.");
1676 case kDNSServiceErr_NoAuth
:
1677 return ("Authentication required.");
1679 case kDNSServiceErr_NoSuchKey
:
1680 return ("Encryption key not found.");
1682 case kDNSServiceErr_NATTraversal
:
1683 return ("Unable to traverse NAT boundary.");
1685 case kDNSServiceErr_DoubleNAT
:
1686 return ("Unable to traverse double-NAT boundary.");
1688 case kDNSServiceErr_BadTime
:
1689 return ("Bad system time.");
1691 case kDNSServiceErr_BadSig
:
1692 return ("Bad signature.");
1694 case kDNSServiceErr_BadKey
:
1695 return ("Bad encryption key.");
1697 case kDNSServiceErr_Transient
:
1698 return ("Transient error occurred - please try again.");
1700 case kDNSServiceErr_ServiceNotRunning
:
1701 return ("Server not running.");
1703 case kDNSServiceErr_NATPortMappingUnsupported
:
1704 return ("NAT doesn't support NAT-PMP or UPnP.");
1706 case kDNSServiceErr_NATPortMappingDisabled
:
1707 return ("NAT supports NAT-PNP or UPnP but it is disabled.");
1709 case kDNSServiceErr_NoRouter
:
1710 return ("No Internet/default router configured.");
1712 case kDNSServiceErr_PollingMode
:
1713 return ("Service polling mode error.");
1716 case kDNSServiceErr_Timeout
:
1717 return ("Service timeout.");
1721 # elif defined(HAVE_AVAHI)
1722 return (avahi_strerror(error
));
1723 # endif /* HAVE_DNSSD */
1728 * 'eval_expr()' - Evaluate the expressions against the specified service.
1730 * Returns 1 for true and 0 for false.
1733 static int /* O - Result of evaluation */
1734 eval_expr(ippfind_srv_t
*service
, /* I - Service */
1735 ippfind_expr_t
*expressions
) /* I - Expressions */
1737 int logic
, /* Logical operation */
1738 result
; /* Result of current expression */
1739 ippfind_expr_t
*expression
; /* Current expression */
1740 const char *val
; /* TXT value */
1743 * Loop through the expressions...
1746 if (expressions
&& expressions
->parent
)
1747 logic
= expressions
->parent
->op
;
1749 logic
= IPPFIND_OP_AND
;
1751 for (expression
= expressions
; expression
; expression
= expression
->next
)
1753 switch (expression
->op
)
1756 case IPPFIND_OP_AND
:
1757 case IPPFIND_OP_OR
:
1758 if (expression
->child
)
1759 result
= eval_expr(service
, expression
->child
);
1761 result
= expression
->op
== IPPFIND_OP_AND
;
1763 case IPPFIND_OP_TRUE
:
1766 case IPPFIND_OP_FALSE
:
1769 case IPPFIND_OP_IS_LOCAL
:
1770 result
= service
->is_local
;
1772 case IPPFIND_OP_IS_REMOTE
:
1773 result
= !service
->is_local
;
1775 case IPPFIND_OP_DOMAIN_REGEX
:
1776 result
= !regexec(&(expression
->re
), service
->domain
, 0, NULL
, 0);
1778 case IPPFIND_OP_NAME_REGEX
:
1779 result
= !regexec(&(expression
->re
), service
->name
, 0, NULL
, 0);
1781 case IPPFIND_OP_HOST_REGEX
:
1782 result
= !regexec(&(expression
->re
), service
->host
, 0, NULL
, 0);
1784 case IPPFIND_OP_PORT_RANGE
:
1785 result
= service
->port
>= expression
->range
[0] &&
1786 service
->port
<= expression
->range
[1];
1788 case IPPFIND_OP_PATH_REGEX
:
1789 result
= !regexec(&(expression
->re
), service
->resource
, 0, NULL
, 0);
1791 case IPPFIND_OP_TXT_EXISTS
:
1792 result
= cupsGetOption(expression
->key
, service
->num_txt
,
1793 service
->txt
) != NULL
;
1795 case IPPFIND_OP_TXT_REGEX
:
1796 val
= cupsGetOption(expression
->key
, service
->num_txt
,
1799 result
= !regexec(&(expression
->re
), val
, 0, NULL
, 0);
1803 if (getenv("IPPFIND_DEBUG"))
1804 printf("TXT_REGEX of \"%s\": %d\n", val
, result
);
1806 case IPPFIND_OP_URI_REGEX
:
1807 result
= !regexec(&(expression
->re
), service
->uri
, 0, NULL
, 0);
1809 case IPPFIND_OP_EXEC
:
1810 result
= exec_program(service
, expression
->num_args
,
1813 case IPPFIND_OP_LIST
:
1814 result
= list_service(service
);
1816 case IPPFIND_OP_PRINT_NAME
:
1817 _cupsLangPuts(stdout
, service
->name
);
1820 case IPPFIND_OP_PRINT_URI
:
1821 _cupsLangPuts(stdout
, service
->uri
);
1824 case IPPFIND_OP_QUIET
:
1829 if (expression
->invert
)
1832 if (logic
== IPPFIND_OP_AND
&& !result
)
1834 else if (logic
== IPPFIND_OP_OR
&& result
)
1838 return (logic
== IPPFIND_OP_AND
);
1843 * 'exec_program()' - Execute a program for a service.
1846 static int /* O - 1 if program terminated
1847 successfully, 0 otherwise. */
1848 exec_program(ippfind_srv_t
*service
, /* I - Service */
1849 int num_args
, /* I - Number of command-line args */
1850 char **args
) /* I - Command-line arguments */
1852 char **myargv
, /* Command-line arguments */
1853 **myenvp
, /* Environment variables */
1854 *ptr
, /* Pointer into variable */
1855 domain
[1024], /* IPPFIND_SERVICE_DOMAIN */
1856 hostname
[1024], /* IPPFIND_SERVICE_HOSTNAME */
1857 name
[256], /* IPPFIND_SERVICE_NAME */
1858 port
[32], /* IPPFIND_SERVICE_PORT */
1859 regtype
[256], /* IPPFIND_SERVICE_REGTYPE */
1860 scheme
[128], /* IPPFIND_SERVICE_SCHEME */
1861 uri
[1024], /* IPPFIND_SERVICE_URI */
1862 txt
[100][256]; /* IPPFIND_TXT_foo */
1863 int i
, /* Looping var */
1864 myenvc
, /* Number of environment variables */
1865 status
; /* Exit status of program */
1867 char program
[1024]; /* Program to execute */
1868 int pid
; /* Process ID */
1873 * Environment variables...
1876 snprintf(domain
, sizeof(domain
), "IPPFIND_SERVICE_DOMAIN=%s",
1878 snprintf(hostname
, sizeof(hostname
), "IPPFIND_SERVICE_HOSTNAME=%s",
1880 snprintf(name
, sizeof(name
), "IPPFIND_SERVICE_NAME=%s", service
->name
);
1881 snprintf(port
, sizeof(port
), "IPPFIND_SERVICE_PORT=%d", service
->port
);
1882 snprintf(regtype
, sizeof(regtype
), "IPPFIND_SERVICE_REGTYPE=%s",
1884 snprintf(scheme
, sizeof(scheme
), "IPPFIND_SERVICE_SCHEME=%s",
1885 !strncmp(service
->regtype
, "_http._tcp", 10) ? "http" :
1886 !strncmp(service
->regtype
, "_https._tcp", 11) ? "https" :
1887 !strncmp(service
->regtype
, "_ipp._tcp", 9) ? "ipp" :
1888 !strncmp(service
->regtype
, "_ipps._tcp", 10) ? "ipps" : "lpd");
1889 snprintf(uri
, sizeof(uri
), "IPPFIND_SERVICE_URI=%s", service
->uri
);
1890 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1892 snprintf(txt
[i
], sizeof(txt
[i
]), "IPPFIND_TXT_%s=%s", service
->txt
[i
].name
,
1893 service
->txt
[i
].value
);
1894 for (ptr
= txt
[i
] + 12; *ptr
&& *ptr
!= '='; ptr
++)
1895 *ptr
= (char)_cups_toupper(*ptr
);
1898 for (i
= 0, myenvc
= 7 + service
->num_txt
; environ
[i
]; i
++)
1899 if (strncmp(environ
[i
], "IPPFIND_", 8))
1902 if ((myenvp
= calloc(sizeof(char *), (size_t)(myenvc
+ 1))) == NULL
)
1904 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1905 exit(IPPFIND_EXIT_MEMORY
);
1908 for (i
= 0, myenvc
= 0; environ
[i
]; i
++)
1909 if (strncmp(environ
[i
], "IPPFIND_", 8))
1910 myenvp
[myenvc
++] = environ
[i
];
1912 myenvp
[myenvc
++] = domain
;
1913 myenvp
[myenvc
++] = hostname
;
1914 myenvp
[myenvc
++] = name
;
1915 myenvp
[myenvc
++] = port
;
1916 myenvp
[myenvc
++] = regtype
;
1917 myenvp
[myenvc
++] = scheme
;
1918 myenvp
[myenvc
++] = uri
;
1920 for (i
= 0; i
< service
->num_txt
&& i
< 100; i
++)
1921 myenvp
[myenvc
++] = txt
[i
];
1924 * Allocate and copy command-line arguments...
1927 if ((myargv
= calloc(sizeof(char *), (size_t)(num_args
+ 1))) == NULL
)
1929 _cupsLangPuts(stderr
, _("ippfind: Out of memory."));
1930 exit(IPPFIND_EXIT_MEMORY
);
1933 for (i
= 0; i
< num_args
; i
++)
1935 if (strchr(args
[i
], '{'))
1937 char temp
[2048], /* Temporary string */
1938 *tptr
, /* Pointer into temporary string */
1939 keyword
[256], /* {keyword} */
1940 *kptr
; /* Pointer into keyword */
1942 for (ptr
= args
[i
], tptr
= temp
; *ptr
; ptr
++)
1947 * Do a {var} substitution...
1950 for (kptr
= keyword
, ptr
++; *ptr
&& *ptr
!= '}'; ptr
++)
1951 if (kptr
< (keyword
+ sizeof(keyword
) - 1))
1956 _cupsLangPuts(stderr
,
1957 _("ippfind: Missing close brace in substitution."));
1958 exit(IPPFIND_EXIT_SYNTAX
);
1962 if (!keyword
[0] || !strcmp(keyword
, "service_uri"))
1963 strlcpy(tptr
, service
->uri
, sizeof(temp
) - (size_t)(tptr
- temp
));
1964 else if (!strcmp(keyword
, "service_domain"))
1965 strlcpy(tptr
, service
->domain
, sizeof(temp
) - (size_t)(tptr
- temp
));
1966 else if (!strcmp(keyword
, "service_hostname"))
1967 strlcpy(tptr
, service
->host
, sizeof(temp
) - (size_t)(tptr
- temp
));
1968 else if (!strcmp(keyword
, "service_name"))
1969 strlcpy(tptr
, service
->name
, sizeof(temp
) - (size_t)(tptr
- temp
));
1970 else if (!strcmp(keyword
, "service_path"))
1971 strlcpy(tptr
, service
->resource
, sizeof(temp
) - (size_t)(tptr
- temp
));
1972 else if (!strcmp(keyword
, "service_port"))
1973 strlcpy(tptr
, port
+ 21, sizeof(temp
) - (size_t)(tptr
- temp
));
1974 else if (!strcmp(keyword
, "service_scheme"))
1975 strlcpy(tptr
, scheme
+ 22, sizeof(temp
) - (size_t)(tptr
- temp
));
1976 else if (!strncmp(keyword
, "txt_", 4))
1978 const char *val
= cupsGetOption(keyword
+ 4, service
->num_txt
, service
->txt
);
1980 strlcpy(tptr
, val
, sizeof(temp
) - (size_t)(tptr
- temp
));
1986 _cupsLangPrintf(stderr
, _("ippfind: Unknown variable \"{%s}\"."),
1988 exit(IPPFIND_EXIT_SYNTAX
);
1991 tptr
+= strlen(tptr
);
1993 else if (tptr
< (temp
+ sizeof(temp
) - 1))
1998 myargv
[i
] = strdup(temp
);
2001 myargv
[i
] = strdup(args
[i
]);
2005 if (getenv("IPPFIND_DEBUG"))
2007 printf("\nProgram:\n %s\n", args
[0]);
2008 puts("\nArguments:");
2009 for (i
= 0; i
< num_args
; i
++)
2010 printf(" %s\n", myargv
[i
]);
2011 puts("\nEnvironment:");
2012 for (i
= 0; i
< myenvc
; i
++)
2013 printf(" %s\n", myenvp
[i
]);
2016 status
= _spawnvpe(_P_WAIT
, args
[0], myargv
, myenvp
);
2020 * Execute the program...
2023 if (strchr(args
[0], '/') && !access(args
[0], X_OK
))
2024 strlcpy(program
, args
[0], sizeof(program
));
2025 else if (!cupsFileFind(args
[0], getenv("PATH"), 1, program
, sizeof(program
)))
2027 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2028 args
[0], strerror(ENOENT
));
2029 exit(IPPFIND_EXIT_SYNTAX
);
2032 if (getenv("IPPFIND_DEBUG"))
2034 printf("\nProgram:\n %s\n", program
);
2035 puts("\nArguments:");
2036 for (i
= 0; i
< num_args
; i
++)
2037 printf(" %s\n", myargv
[i
]);
2038 puts("\nEnvironment:");
2039 for (i
= 0; i
< myenvc
; i
++)
2040 printf(" %s\n", myenvp
[i
]);
2043 if ((pid
= fork()) == 0)
2046 * Child comes here...
2049 execve(program
, myargv
, myenvp
);
2054 _cupsLangPrintf(stderr
, _("ippfind: Unable to execute \"%s\": %s"),
2055 args
[0], strerror(errno
));
2056 exit(IPPFIND_EXIT_SYNTAX
);
2061 * Wait for it to complete...
2064 while (wait(&status
) != pid
)
2073 for (i
= 0; i
< num_args
; i
++)
2080 * Return whether the program succeeded or crashed...
2083 if (getenv("IPPFIND_DEBUG"))
2086 printf("Exit Status: %d\n", status
);
2088 if (WIFEXITED(status
))
2089 printf("Exit Status: %d\n", WEXITSTATUS(status
));
2091 printf("Terminating Signal: %d\n", WTERMSIG(status
));
2095 return (status
== 0);
2100 * 'get_service()' - Create or update a device.
2103 static ippfind_srv_t
* /* O - Service */
2104 get_service(cups_array_t
*services
, /* I - Service array */
2105 const char *serviceName
, /* I - Name of service/device */
2106 const char *regtype
, /* I - Type of service */
2107 const char *replyDomain
) /* I - Service domain */
2109 ippfind_srv_t key
, /* Search key */
2110 *service
; /* Service */
2111 char fullName
[kDNSServiceMaxDomainName
];
2112 /* Full name for query */
2116 * See if this is a new device...
2119 key
.name
= (char *)serviceName
;
2120 key
.regtype
= (char *)regtype
;
2122 for (service
= cupsArrayFind(services
, &key
);
2124 service
= cupsArrayNext(services
))
2125 if (_cups_strcasecmp(service
->name
, key
.name
))
2127 else if (!strcmp(service
->regtype
, key
.regtype
))
2131 * Yes, add the service...
2134 service
= calloc(sizeof(ippfind_srv_t
), 1);
2135 service
->name
= strdup(serviceName
);
2136 service
->domain
= strdup(replyDomain
);
2137 service
->regtype
= strdup(regtype
);
2139 cupsArrayAdd(services
, service
);
2142 * Set the "full name" of this service, which is used for queries and
2147 DNSServiceConstructFullName(fullName
, serviceName
, regtype
, replyDomain
);
2148 #else /* HAVE_AVAHI */
2149 avahi_service_name_join(fullName
, kDNSServiceMaxDomainName
, serviceName
,
2150 regtype
, replyDomain
);
2151 #endif /* HAVE_DNSSD */
2153 service
->fullName
= strdup(fullName
);
2160 * 'get_time()' - Get the current time-of-day in seconds.
2167 struct _timeb curtime
; /* Current Windows time */
2171 return (curtime
.time
+ 0.001 * curtime
.millitm
);
2174 struct timeval curtime
; /* Current UNIX time */
2176 if (gettimeofday(&curtime
, NULL
))
2179 return (curtime
.tv_sec
+ 0.000001 * curtime
.tv_usec
);
2185 * 'list_service()' - List the contents of a service.
2188 static int /* O - 1 if successful, 0 otherwise */
2189 list_service(ippfind_srv_t
*service
) /* I - Service */
2191 http_addrlist_t
*addrlist
; /* Address(es) of service */
2192 char port
[10]; /* Port number of service */
2195 snprintf(port
, sizeof(port
), "%d", service
->port
);
2197 if ((addrlist
= httpAddrGetList(service
->host
, address_family
, port
)) == NULL
)
2199 _cupsLangPrintf(stdout
, "%s unreachable", service
->uri
);
2203 if (!strncmp(service
->regtype
, "_ipp._tcp", 9) ||
2204 !strncmp(service
->regtype
, "_ipps._tcp", 10))
2210 http_t
*http
; /* HTTP connection */
2211 ipp_t
*request
, /* IPP request */
2212 *response
; /* IPP response */
2213 ipp_attribute_t
*attr
; /* IPP attribute */
2214 int i
, /* Looping var */
2215 count
, /* Number of values */
2216 version
, /* IPP version */
2217 paccepting
; /* printer-is-accepting-jobs value */
2218 ipp_pstate_t pstate
; /* printer-state value */
2219 char preasons
[1024], /* Comma-delimited printer-state-reasons */
2220 *ptr
, /* Pointer into reasons */
2221 *end
; /* End of reasons buffer */
2222 static const char * const rattrs
[] =/* Requested attributes */
2224 "printer-is-accepting-jobs",
2226 "printer-state-reasons"
2230 * Connect to the printer...
2233 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2234 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2235 HTTP_ENCRYPTION_ALWAYS
:
2236 HTTP_ENCRYPTION_IF_REQUESTED
,
2239 httpAddrFreeList(addrlist
);
2243 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2248 * Get the current printer state...
2252 version
= ipp_version
;
2256 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
2257 ippSetVersion(request
, version
/ 10, version
% 10);
2258 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
2260 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
2261 "requesting-user-name", NULL
, cupsUser());
2262 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
2263 "requested-attributes",
2264 (int)(sizeof(rattrs
) / sizeof(rattrs
[0])), NULL
, rattrs
);
2266 response
= cupsDoRequest(http
, request
, service
->resource
);
2268 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
&& version
> 11)
2271 while (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
&& version
> 11);
2277 if (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE
)
2279 _cupsLangPrintf(stdout
, "%s: unavailable", service
->uri
);
2283 if ((attr
= ippFindAttribute(response
, "printer-state",
2284 IPP_TAG_ENUM
)) != NULL
)
2285 pstate
= (ipp_pstate_t
)ippGetInteger(attr
, 0);
2287 pstate
= IPP_PSTATE_STOPPED
;
2289 if ((attr
= ippFindAttribute(response
, "printer-is-accepting-jobs",
2290 IPP_TAG_BOOLEAN
)) != NULL
)
2291 paccepting
= ippGetBoolean(attr
, 0);
2295 if ((attr
= ippFindAttribute(response
, "printer-state-reasons",
2296 IPP_TAG_KEYWORD
)) != NULL
)
2298 strlcpy(preasons
, ippGetString(attr
, 0, NULL
), sizeof(preasons
));
2300 for (i
= 1, count
= ippGetCount(attr
), ptr
= preasons
+ strlen(preasons
),
2301 end
= preasons
+ sizeof(preasons
) - 1;
2302 i
< count
&& ptr
< end
;
2303 i
++, ptr
+= strlen(ptr
))
2306 strlcpy(ptr
, ippGetString(attr
, i
, NULL
), (size_t)(end
- ptr
+ 1));
2310 strlcpy(preasons
, "none", sizeof(preasons
));
2312 ippDelete(response
);
2315 _cupsLangPrintf(stdout
, "%s %s %s %s", service
->uri
,
2316 ippEnumString("printer-state", pstate
),
2317 paccepting
? "accepting-jobs" : "not-accepting-jobs",
2320 else if (!strncmp(service
->regtype
, "_http._tcp", 10) ||
2321 !strncmp(service
->regtype
, "_https._tcp", 11))
2324 * HTTP/HTTPS web page
2327 http_t
*http
; /* HTTP connection */
2328 http_status_t status
; /* HEAD status */
2332 * Connect to the web server...
2335 http
= httpConnect2(service
->host
, service
->port
, addrlist
, address_family
,
2336 !strncmp(service
->regtype
, "_ipps._tcp", 10) ?
2337 HTTP_ENCRYPTION_ALWAYS
:
2338 HTTP_ENCRYPTION_IF_REQUESTED
,
2341 httpAddrFreeList(addrlist
);
2345 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2349 if (httpGet(http
, service
->resource
))
2351 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2357 status
= httpUpdate(http
);
2359 while (status
== HTTP_STATUS_CONTINUE
);
2364 if (status
>= HTTP_STATUS_BAD_REQUEST
)
2366 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2370 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2372 else if (!strncmp(service
->regtype
, "_printer._tcp", 13))
2378 int sock
; /* Socket */
2381 if (!httpAddrConnect(addrlist
, &sock
))
2383 _cupsLangPrintf(stdout
, "%s unavailable", service
->uri
);
2384 httpAddrFreeList(addrlist
);
2388 _cupsLangPrintf(stdout
, "%s available", service
->uri
);
2389 httpAddrFreeList(addrlist
);
2391 httpAddrClose(NULL
, sock
);
2395 _cupsLangPrintf(stdout
, "%s unsupported", service
->uri
);
2396 httpAddrFreeList(addrlist
);
2405 * 'new_expr()' - Create a new expression.
2408 static ippfind_expr_t
* /* O - New expression */
2409 new_expr(ippfind_op_t op
, /* I - Operation */
2410 int invert
, /* I - Invert result? */
2411 const char *value
, /* I - TXT key or port range */
2412 const char *regex
, /* I - Regular expression */
2413 char **args
) /* I - Pointer to argument strings */
2415 ippfind_expr_t
*temp
; /* New expression */
2418 if ((temp
= calloc(1, sizeof(ippfind_expr_t
))) == NULL
)
2422 temp
->invert
= invert
;
2424 if (op
== IPPFIND_OP_TXT_EXISTS
|| op
== IPPFIND_OP_TXT_REGEX
)
2425 temp
->key
= (char *)value
;
2426 else if (op
== IPPFIND_OP_PORT_RANGE
)
2429 * Pull port number range of the form "number", "-number" (0-number),
2430 * "number-" (number-65535), and "number-number".
2435 temp
->range
[1] = atoi(value
+ 1);
2437 else if (strchr(value
, '-'))
2439 if (sscanf(value
, "%d-%d", temp
->range
, temp
->range
+ 1) == 1)
2440 temp
->range
[1] = 65535;
2444 temp
->range
[0] = temp
->range
[1] = atoi(value
);
2450 int err
= regcomp(&(temp
->re
), regex
, REG_NOSUB
| REG_ICASE
| REG_EXTENDED
);
2454 char message
[256]; /* Error message */
2456 regerror(err
, &(temp
->re
), message
, sizeof(message
));
2457 _cupsLangPrintf(stderr
, _("ippfind: Bad regular expression: %s"),
2459 exit(IPPFIND_EXIT_SYNTAX
);
2465 int num_args
; /* Number of arguments */
2467 for (num_args
= 1; args
[num_args
]; num_args
++)
2468 if (!strcmp(args
[num_args
], ";"))
2471 temp
->num_args
= num_args
;
2472 temp
->args
= malloc((size_t)num_args
* sizeof(char *));
2473 memcpy(temp
->args
, args
, (size_t)num_args
* sizeof(char *));
2482 * 'poll_callback()' - Wait for input on the specified file descriptors.
2484 * Note: This function is needed because avahi_simple_poll_iterate is broken
2485 * and always uses a timeout of 0 (!) milliseconds.
2486 * (Avahi Ticket #364)
2489 static int /* O - Number of file descriptors matching */
2491 struct pollfd
*pollfds
, /* I - File descriptors */
2492 unsigned int num_pollfds
, /* I - Number of file descriptors */
2493 int timeout
, /* I - Timeout in milliseconds (unused) */
2494 void *context
) /* I - User data (unused) */
2496 int val
; /* Return value */
2502 val
= poll(pollfds
, num_pollfds
, 500);
2509 #endif /* HAVE_AVAHI */
2513 * 'resolve_callback()' - Process resolve data.
2517 static void DNSSD_API
2519 DNSServiceRef sdRef
, /* I - Service reference */
2520 DNSServiceFlags flags
, /* I - Data flags */
2521 uint32_t interfaceIndex
, /* I - Interface */
2522 DNSServiceErrorType errorCode
, /* I - Error, if any */
2523 const char *fullName
, /* I - Full service name */
2524 const char *hostTarget
, /* I - Hostname */
2525 uint16_t port
, /* I - Port number (network byte order) */
2526 uint16_t txtLen
, /* I - Length of TXT record data */
2527 const unsigned char *txtRecord
, /* I - TXT record data */
2528 void *context
) /* I - Service */
2530 char key
[256], /* TXT key value */
2531 *value
; /* Value from TXT record */
2532 const unsigned char *txtEnd
; /* End of TXT record */
2533 uint8_t valueLen
; /* Length of value */
2534 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2539 * Only process "add" data...
2544 (void)interfaceIndex
;
2547 if (errorCode
!= kDNSServiceErr_NoError
)
2549 _cupsLangPrintf(stderr
, _("ippfind: Unable to browse or resolve: %s"),
2550 dnssd_error_string(errorCode
));
2555 service
->is_resolved
= 1;
2556 service
->host
= strdup(hostTarget
);
2557 service
->port
= ntohs(port
);
2559 value
= service
->host
+ strlen(service
->host
) - 1;
2560 if (value
>= service
->host
&& *value
== '.')
2564 * Loop through the TXT key/value pairs and add them to an array...
2567 for (txtEnd
= txtRecord
+ txtLen
; txtRecord
< txtEnd
; txtRecord
+= valueLen
)
2570 * Ignore bogus strings...
2573 valueLen
= *txtRecord
++;
2575 memcpy(key
, txtRecord
, valueLen
);
2576 key
[valueLen
] = '\0';
2578 if ((value
= strchr(key
, '=')) == NULL
)
2584 * Add to array of TXT values...
2587 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2591 set_service_uri(service
);
2595 #elif defined(HAVE_AVAHI)
2598 AvahiServiceResolver
*resolver
, /* I - Resolver */
2599 AvahiIfIndex interface
, /* I - Interface */
2600 AvahiProtocol protocol
, /* I - Address protocol */
2601 AvahiResolverEvent event
, /* I - Event */
2602 const char *serviceName
,/* I - Service name */
2603 const char *regtype
, /* I - Registration type */
2604 const char *replyDomain
,/* I - Domain name */
2605 const char *hostTarget
, /* I - FQDN */
2606 const AvahiAddress
*address
, /* I - Address */
2607 uint16_t port
, /* I - Port number */
2608 AvahiStringList
*txt
, /* I - TXT records */
2609 AvahiLookupResultFlags flags
, /* I - Lookup flags */
2610 void *context
) /* I - Service */
2612 char key
[256], /* TXT key */
2613 *value
; /* TXT value */
2614 ippfind_srv_t
*service
= (ippfind_srv_t
*)context
;
2616 AvahiStringList
*current
; /* Current TXT key/value pair */
2621 if (event
!= AVAHI_RESOLVER_FOUND
)
2625 avahi_service_resolver_free(resolver
);
2626 avahi_simple_poll_quit(avahi_poll
);
2630 service
->is_resolved
= 1;
2631 service
->host
= strdup(hostTarget
);
2632 service
->port
= port
;
2634 value
= service
->host
+ strlen(service
->host
) - 1;
2635 if (value
>= service
->host
&& *value
== '.')
2639 * Loop through the TXT key/value pairs and add them to an array...
2642 for (current
= txt
; current
; current
= current
->next
)
2645 * Ignore bogus strings...
2648 if (current
->size
> (sizeof(key
) - 1))
2651 memcpy(key
, current
->text
, current
->size
);
2652 key
[current
->size
] = '\0';
2654 if ((value
= strchr(key
, '=')) == NULL
)
2660 * Add to array of TXT values...
2663 service
->num_txt
= cupsAddOption(key
, value
, service
->num_txt
,
2667 set_service_uri(service
);
2669 #endif /* HAVE_DNSSD */
2673 * 'set_service_uri()' - Set the URI of the service.
2677 set_service_uri(ippfind_srv_t
*service
) /* I - Service */
2679 char uri
[1024]; /* URI */
2680 const char *path
, /* Resource path */
2681 *scheme
; /* URI scheme */
2684 if (!strncmp(service
->regtype
, "_http.", 6))
2687 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2689 else if (!strncmp(service
->regtype
, "_https.", 7))
2692 path
= cupsGetOption("path", service
->num_txt
, service
->txt
);
2694 else if (!strncmp(service
->regtype
, "_ipp.", 5))
2697 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2699 else if (!strncmp(service
->regtype
, "_ipps.", 6))
2702 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2704 else if (!strncmp(service
->regtype
, "_printer.", 9))
2707 path
= cupsGetOption("rp", service
->num_txt
, service
->txt
);
2712 if (!path
|| !*path
)
2717 service
->resource
= strdup(path
);
2721 snprintf(uri
, sizeof(uri
), "/%s", path
);
2722 service
->resource
= strdup(uri
);
2725 httpAssembleURI(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), scheme
, NULL
,
2726 service
->host
, service
->port
, service
->resource
);
2727 service
->uri
= strdup(uri
);
2732 * 'show_usage()' - Show program usage.
2738 _cupsLangPuts(stderr
, _("Usage: ippfind [options] regtype[,subtype]"
2739 "[.domain.] ... [expression]\n"
2740 " ippfind [options] name[.regtype[.domain.]] "
2741 "... [expression]\n"
2743 " ippfind --version"));
2744 _cupsLangPuts(stderr
, "");
2745 _cupsLangPuts(stderr
, _("Options:"));
2746 _cupsLangPuts(stderr
, _(" -4 Connect using IPv4."));
2747 _cupsLangPuts(stderr
, _(" -6 Connect using IPv6."));
2748 _cupsLangPuts(stderr
, _(" -T seconds Set the browse timeout in "
2750 _cupsLangPuts(stderr
, _(" -V version Set default IPP "
2752 _cupsLangPuts(stderr
, _(" --help Show this help."));
2753 _cupsLangPuts(stderr
, _(" --version Show program version."));
2754 _cupsLangPuts(stderr
, "");
2755 _cupsLangPuts(stderr
, _("Expressions:"));
2756 _cupsLangPuts(stderr
, _(" -P number[-number] Match port to number or range."));
2757 _cupsLangPuts(stderr
, _(" -d regex Match domain to regular expression."));
2758 _cupsLangPuts(stderr
, _(" -h regex Match hostname to regular expression."));
2759 _cupsLangPuts(stderr
, _(" -l List attributes."));
2760 _cupsLangPuts(stderr
, _(" -n regex Match service name to regular expression."));
2761 _cupsLangPuts(stderr
, _(" -p Print URI if true."));
2762 _cupsLangPuts(stderr
, _(" -q Quietly report match via exit code."));
2763 _cupsLangPuts(stderr
, _(" -r True if service is remote."));
2764 _cupsLangPuts(stderr
, _(" -s Print service name if true."));
2765 _cupsLangPuts(stderr
, _(" -t key True if the TXT record contains the key."));
2766 _cupsLangPuts(stderr
, _(" -u regex Match URI to regular expression."));
2767 _cupsLangPuts(stderr
, _(" -x utility [argument ...] ;\n"
2768 " Execute program if true."));
2769 _cupsLangPuts(stderr
, _(" --domain regex Match domain to regular expression."));
2770 _cupsLangPuts(stderr
, _(" --exec utility [argument ...] ;\n"
2771 " Execute program if true."));
2772 _cupsLangPuts(stderr
, _(" --host regex Match hostname to regular expression."));
2773 _cupsLangPuts(stderr
, _(" --ls List attributes."));
2774 _cupsLangPuts(stderr
, _(" --local True if service is local."));
2775 _cupsLangPuts(stderr
, _(" --name regex Match service name to regular expression."));
2776 _cupsLangPuts(stderr
, _(" --path regex Match resource path to regular expression."));
2777 _cupsLangPuts(stderr
, _(" --port number[-number] Match port to number or range."));
2778 _cupsLangPuts(stderr
, _(" --print Print URI if true."));
2779 _cupsLangPuts(stderr
, _(" --print-name Print service name if true."));
2780 _cupsLangPuts(stderr
, _(" --quiet Quietly report match via exit code."));
2781 _cupsLangPuts(stderr
, _(" --remote True if service is remote."));
2782 _cupsLangPuts(stderr
, _(" --txt key True if the TXT record contains the key."));
2783 _cupsLangPuts(stderr
, _(" --txt-* regex Match TXT record key to regular expression."));
2784 _cupsLangPuts(stderr
, _(" --uri regex Match URI to regular expression."));
2785 _cupsLangPuts(stderr
, "");
2786 _cupsLangPuts(stderr
, _("Modifiers:"));
2787 _cupsLangPuts(stderr
, _(" ( expressions ) Group expressions."));
2788 _cupsLangPuts(stderr
, _(" ! expression Unary NOT of expression."));
2789 _cupsLangPuts(stderr
, _(" --not expression Unary NOT of expression."));
2790 _cupsLangPuts(stderr
, _(" --false Always false."));
2791 _cupsLangPuts(stderr
, _(" --true Always true."));
2792 _cupsLangPuts(stderr
, _(" expression expression Logical AND."));
2793 _cupsLangPuts(stderr
, _(" expression --and expression\n"
2795 _cupsLangPuts(stderr
, _(" expression --or expression\n"
2797 _cupsLangPuts(stderr
, "");
2798 _cupsLangPuts(stderr
, _("Substitutions:"));
2799 _cupsLangPuts(stderr
, _(" {} URI"));
2800 _cupsLangPuts(stderr
, _(" {service_domain} Domain name"));
2801 _cupsLangPuts(stderr
, _(" {service_hostname} Fully-qualified domain name"));
2802 _cupsLangPuts(stderr
, _(" {service_name} Service instance name"));
2803 _cupsLangPuts(stderr
, _(" {service_port} Port number"));
2804 _cupsLangPuts(stderr
, _(" {service_regtype} DNS-SD registration type"));
2805 _cupsLangPuts(stderr
, _(" {service_scheme} URI scheme"));
2806 _cupsLangPuts(stderr
, _(" {service_uri} URI"));
2807 _cupsLangPuts(stderr
, _(" {txt_*} Value of TXT record key"));
2808 _cupsLangPuts(stderr
, "");
2809 _cupsLangPuts(stderr
, _("Environment Variables:"));
2810 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_DOMAIN Domain name"));
2811 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_HOSTNAME\n"
2812 " Fully-qualified domain name"));
2813 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_NAME Service instance name"));
2814 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_PORT Port number"));
2815 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_REGTYPE DNS-SD registration type"));
2816 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_SCHEME URI scheme"));
2817 _cupsLangPuts(stderr
, _(" IPPFIND_SERVICE_URI URI"));
2818 _cupsLangPuts(stderr
, _(" IPPFIND_TXT_* Value of TXT record key"));
2820 exit(IPPFIND_EXIT_TRUE
);
2825 * 'show_version()' - Show program version.
2831 _cupsLangPuts(stderr
, CUPS_SVERSION
);
2833 exit(IPPFIND_EXIT_TRUE
);