4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
26 /* $Id: lpmove.c 146 2006-03-24 00:26:54Z njacobs $ */
42 if ((name
= strrchr(program
, '/')) == NULL
)
48 gettext("Usage: %s [request-id] (destination)\n"
49 " %s (source) (destination)\n"), name
, name
);
54 move_job(papi_service_t svc
, char *src
, int32_t id
, char *dest
)
58 char *mesg
= gettext("moved");
60 status
= papiJobMove(svc
, src
, id
, dest
);
61 if (status
!= PAPI_OK
) {
62 mesg
= (char *)verbose_papi_message(svc
, status
);
65 fprintf(stderr
, gettext("%s-%d to %s: %s\n"), src
, id
, dest
, mesg
);
71 main(int ac
, char *av
[])
74 papi_encryption_t encryption
= PAPI_ENCRYPT_NEVER
;
75 char *destination
= NULL
;
78 (void) setlocale(LC_ALL
, "");
79 (void) textdomain("SUNW_OST_OSCMD");
81 while ((c
= getopt(ac
, av
, "E:")) != EOF
)
84 encryption
= PAPI_ENCRYPT_REQUIRED
;
93 destination
= av
[--ac
];
95 for (c
= optind
; c
< ac
; c
++) {
97 papi_service_t svc
= NULL
;
98 papi_job_t
*jobs
= NULL
;
102 (void) get_printer_id(av
[c
], &printer
, &id
);
104 status
= papiServiceCreate(&svc
, printer
, NULL
, NULL
,
105 cli_auth_callback
, encryption
, NULL
);
106 if (status
!= PAPI_OK
) {
107 fprintf(stderr
, gettext(
108 "Failed to contact service for %s: %s\n"),
109 printer
, verbose_papi_message(svc
, status
));
113 if (id
!= -1) { /* it's a job */
114 if (move_job(svc
, printer
, id
, destination
) < 0)
116 } else { /* it's a printer */
120 snprintf(message
, sizeof (message
), "moved jobs to %s",
122 status
= papiPrinterPause(svc
, printer
, message
);
123 if (status
!= PAPI_OK
) {
125 * If the user is denied the permission
126 * to disable then return appropriate msg
130 result
= papiServiceGetStatusMessage(svc
);
132 if (result
!= NULL
) {
134 * Check if user is denied
137 if (strstr(result
, "permission denied")
143 fprintf(stderr
, "UX:lpmove: ");
146 fprintf(stderr
, gettext("You "
147 "aren't allowed to do"
149 fprintf(stderr
, "\n\t");
152 fprintf(stderr
, ": ");
153 fprintf(stderr
, gettext("You "
154 "must be logged in as "
155 "\"lp\" or \"root\"."));
156 fprintf(stderr
, "\n");
159 fprintf(stderr
, gettext(
162 verbose_papi_message(
167 fprintf(stderr
, gettext(
170 verbose_papi_message(svc
, status
));
175 "destination %s is not accepting"\
176 " requests\n"), printer
);
178 status
= papiPrinterListJobs(svc
, printer
, NULL
,
180 if (status
!= PAPI_OK
) {
181 fprintf(stderr
, gettext("Jobs %s:"\
184 verbose_papi_message(svc
, status
));
188 printf(gettext("move in progress ...\n"));
189 while ((jobs
!= NULL
) && (*jobs
!= NULL
)) {
190 id
= papiJobGetId(*jobs
++);
191 if (move_job(svc
, printer
,
192 id
, destination
) < 0)
198 "total of %d requests moved"\
200 count
, printer
, destination
);
202 papiJobListFree(jobs
);
206 papiServiceDestroy(svc
);