10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
52264Sjacobs * Common Development and Distribution License (the "License").
62264Sjacobs * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*7253Sjacobs * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
232264Sjacobs * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <stdio.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <stdarg.h>
320Sstevel@tonic-gate #include <unistd.h>
330Sstevel@tonic-gate #include <string.h>
340Sstevel@tonic-gate #include <syslog.h>
350Sstevel@tonic-gate #include <locale.h>
360Sstevel@tonic-gate #ifndef SUNOS_4
370Sstevel@tonic-gate #include <libintl.h>
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate
402264Sjacobs #include <ns.h>
412264Sjacobs #include <list.h>
420Sstevel@tonic-gate
430Sstevel@tonic-gate extern char *optarg;
440Sstevel@tonic-gate extern int optind, opterr, optopt;
450Sstevel@tonic-gate extern char *getenv(const char *);
460Sstevel@tonic-gate
470Sstevel@tonic-gate
480Sstevel@tonic-gate static void
Usage(char * name)490Sstevel@tonic-gate Usage(char *name)
500Sstevel@tonic-gate {
510Sstevel@tonic-gate (void) fprintf(stderr,
520Sstevel@tonic-gate gettext("Usage: %s [-k key] [list|(printer) ...]\n"),
530Sstevel@tonic-gate name);
540Sstevel@tonic-gate exit(1);
550Sstevel@tonic-gate }
560Sstevel@tonic-gate
570Sstevel@tonic-gate static int
display_kvp(char * key,char * value)580Sstevel@tonic-gate display_kvp(char *key, char *value)
590Sstevel@tonic-gate {
600Sstevel@tonic-gate int rc = -1;
610Sstevel@tonic-gate
620Sstevel@tonic-gate if (value != NULL) {
630Sstevel@tonic-gate rc = 0;
640Sstevel@tonic-gate (void) printf("\n\t%s=%s", key, value);
650Sstevel@tonic-gate } else
660Sstevel@tonic-gate (void) printf(gettext("\n\t%s - undefined"), key);
670Sstevel@tonic-gate
680Sstevel@tonic-gate return (rc);
690Sstevel@tonic-gate }
700Sstevel@tonic-gate
710Sstevel@tonic-gate
720Sstevel@tonic-gate static int
display_value(ns_printer_t * printer,char * name,char ** keys)730Sstevel@tonic-gate display_value(ns_printer_t *printer, char *name, char **keys)
740Sstevel@tonic-gate {
750Sstevel@tonic-gate int rc = -1;
760Sstevel@tonic-gate
770Sstevel@tonic-gate if (printer != NULL) {
780Sstevel@tonic-gate rc = 0;
790Sstevel@tonic-gate (void) printf("%s:", name);
800Sstevel@tonic-gate if (keys != NULL) {
810Sstevel@tonic-gate while (*keys != NULL) {
820Sstevel@tonic-gate char *string = ns_get_value_string(*keys,
830Sstevel@tonic-gate printer);
840Sstevel@tonic-gate rc += display_kvp(*keys, string);
850Sstevel@tonic-gate keys++;
860Sstevel@tonic-gate }
870Sstevel@tonic-gate } else {
880Sstevel@tonic-gate ns_kvp_t **list = printer->attributes;
890Sstevel@tonic-gate
900Sstevel@tonic-gate for (list = printer->attributes;
910Sstevel@tonic-gate (list != NULL && *list != NULL); list++) {
920Sstevel@tonic-gate char *string;
930Sstevel@tonic-gate if (((*list)->key[0] == '\t') ||
940Sstevel@tonic-gate ((*list)->key[0] == ' '))
950Sstevel@tonic-gate continue;
960Sstevel@tonic-gate
970Sstevel@tonic-gate string = ns_get_value_string((*list)->key,
980Sstevel@tonic-gate printer);
990Sstevel@tonic-gate rc += display_kvp((*list)->key, string);
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate (void) printf("\n");
1030Sstevel@tonic-gate } else
1040Sstevel@tonic-gate (void) printf(gettext("%s: Not Found\n"), name);
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate return (rc);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate /*
1110Sstevel@tonic-gate * main() calls the appropriate routine to parse the command line arguments
1120Sstevel@tonic-gate * and then calls the local remove routine, followed by the remote remove
1130Sstevel@tonic-gate * routine to remove jobs.
1140Sstevel@tonic-gate */
1150Sstevel@tonic-gate int
main(int ac,char * av[])1160Sstevel@tonic-gate main(int ac, char *av[])
1170Sstevel@tonic-gate {
1180Sstevel@tonic-gate char *program;
1190Sstevel@tonic-gate int c;
1200Sstevel@tonic-gate char **keys = NULL;
1210Sstevel@tonic-gate char *ns = NULL;
1220Sstevel@tonic-gate int exit_code = 0;
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1270Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
1280Sstevel@tonic-gate #endif
1290Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate if ((program = strrchr(av[0], '/')) == NULL)
1320Sstevel@tonic-gate program = av[0];
1330Sstevel@tonic-gate else
1340Sstevel@tonic-gate program++;
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate openlog(program, LOG_PID, LOG_LPR);
1370Sstevel@tonic-gate while ((c = getopt(ac, av, "k:t:n:")) != EOF)
1380Sstevel@tonic-gate switch (c) {
1390Sstevel@tonic-gate case 'k':
1400Sstevel@tonic-gate case 't':
1410Sstevel@tonic-gate keys = (char **)list_append((void **)keys,
1420Sstevel@tonic-gate (void *)optarg);
1430Sstevel@tonic-gate break;
1440Sstevel@tonic-gate case 'n':
1450Sstevel@tonic-gate ns = optarg;
1460Sstevel@tonic-gate break;
1470Sstevel@tonic-gate default:
1480Sstevel@tonic-gate Usage(program);
1490Sstevel@tonic-gate }
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate if (optind >= ac)
1520Sstevel@tonic-gate Usage(program);
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate ns = normalize_ns_name(ns);
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate while (optind < ac) {
1570Sstevel@tonic-gate char *name = av[optind++];
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate if (strcmp(name, "list") == 0) {
1600Sstevel@tonic-gate ns_printer_t **printers = ns_printer_get_list(ns);
1610Sstevel@tonic-gate
1620Sstevel@tonic-gate while (printers != NULL && *printers != NULL) {
1630Sstevel@tonic-gate exit_code += display_value(*printers,
1640Sstevel@tonic-gate (*printers)->name, keys);
1650Sstevel@tonic-gate printers++;
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate } else
1680Sstevel@tonic-gate exit_code = display_value(ns_printer_get_name(name, ns),
1690Sstevel@tonic-gate name, keys);
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate }
1730Sstevel@tonic-gate return (exit_code);
1740Sstevel@tonic-gate }
175