5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License (the "License").
7 * You may not use this file except in compliance with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
29 /* $Id: disable.c 146 2006-03-24 00:26:54Z njacobs $ */
46 if ((name
= strrchr(program
, '/')) == NULL
)
52 gettext("Usage: %s [-c] [-W] [-r reason] destination ...\n"),
58 cancel_active_job(papi_service_t svc
, char *dest
)
62 char *req_attrs
[] = { "job-state", "job-id", NULL
};
64 status
= papiPrinterListJobs(svc
, dest
, req_attrs
, 0, 0, &j
);
65 if ((status
== PAPI_OK
) && (j
!= NULL
)) {
68 for (i
= 0; j
[i
] != NULL
; j
++) {
69 papi_attribute_t
**a
= papiJobGetAttributeList(j
[i
]);
75 (void) papiAttributeListGetInteger(a
, NULL
,
77 if (state
& 0x082A) { /* If state is RS_ACTIVE */
78 int32_t id
= papiJobGetId(j
[i
]);
80 (void) papiJobCancel(svc
, dest
, id
);
88 main(int ac
, char *av
[])
91 papi_service_t svc
= NULL
;
92 papi_encryption_t encryption
= PAPI_ENCRYPT_NEVER
;
95 int pending
= 0; /* not implemented */
99 (void) setlocale(LC_ALL
, "");
100 (void) textdomain("SUNW_OST_OSCMD");
102 while ((c
= getopt(ac
, av
, "EcWr:")) != EOF
)
104 case 'c': /* cancel active job first */
107 case 'W': /* wait for active request, not implemented */
110 case 'r': /* reason */
114 encryption
= PAPI_ENCRYPT_NEVER
;
123 while (optind
< ac
) {
124 char *printer
= av
[optind
++];
126 status
= papiServiceCreate(&svc
, printer
, NULL
, NULL
,
127 cli_auth_callback
, encryption
, NULL
);
128 if (status
!= PAPI_OK
) {
129 fprintf(stderr
, gettext(
130 "Failed to contact service for %s: %s\n"),
131 printer
, verbose_papi_message(svc
, status
));
135 status
= papiPrinterDisable(svc
, printer
, reason
);
136 if (status
== PAPI_OK
) {
137 printf(gettext("printer \"%s\" now disabled\n"),
139 } else if (status
== PAPI_NOT_ACCEPTING
) {
140 fprintf(stderr
, gettext(
141 "Destination \"%s\" was already disabled.\n"),
145 /* The operation is not supported in lpd protocol */
146 if (status
== PAPI_OPERATION_NOT_SUPPORTED
) {
148 verbose_papi_message(svc
, status
));
150 fprintf(stderr
, gettext("disable: %s: %s\n"),
151 printer
, verbose_papi_message(svc
, status
));
157 cancel_active_job(svc
, printer
);
159 papiServiceDestroy(svc
);
162 return (exit_status
);