]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cancel.c
2 * "$Id: cancel.c 6649 2007-07-11 21:46:42Z mike $"
4 * "cancel" command for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * main() - Parse options and cancel jobs.
21 * Include necessary headers...
26 #include <cups/string.h>
27 #include <cups/cups.h>
28 #include <cups/i18n.h>
32 * 'main()' - Parse options and cancel jobs.
35 int /* O - Exit status */
36 main(int argc
, /* I - Number of command-line arguments */
37 char *argv
[]) /* I - Command-line arguments */
39 http_t
*http
; /* HTTP connection to server */
40 int i
; /* Looping var */
41 int job_id
; /* Job ID */
42 int num_dests
; /* Number of destinations */
43 cups_dest_t
*dests
; /* Destinations */
44 char *dest
, /* Destination printer */
45 *job
, /* Job ID pointer */
46 *user
; /* Cancel jobs for a user */
47 int purge
; /* Purge or cancel jobs? */
48 char uri
[1024]; /* Printer or job URI */
49 ipp_t
*request
; /* IPP request */
50 ipp_t
*response
; /* IPP response */
51 ipp_op_t op
; /* Operation */
57 * Setup to cancel individual print jobs...
71 * Process command-line arguments...
74 for (i
= 1; i
< argc
; i
++)
75 if (argv
[i
][0] == '-' && argv
[i
][1])
78 case 'E' : /* Encrypt */
80 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
83 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
85 _cupsLangPrintf(stderr
,
86 _("%s: Sorry, no encryption support compiled in!\n"),
91 case 'U' : /* Username */
92 if (argv
[i
][2] != '\0')
93 cupsSetUser(argv
[i
] + 2);
99 _cupsLangPrintf(stderr
,
100 _("%s: Error - expected username after "
106 cupsSetUser(argv
[i
]);
110 case 'a' : /* Cancel all jobs */
115 case 'h' : /* Connect to host */
122 if (argv
[i
][2] != '\0')
123 cupsSetServer(argv
[i
] + 2);
130 _cupsLangPrintf(stderr
,
131 _("%s: Error - expected hostname after "
137 cupsSetServer(argv
[i
]);
141 case 'u' : /* Username */
144 if (argv
[i
][2] != '\0')
152 _cupsLangPrintf(stderr
,
153 _("%s: Error - expected username after "
164 _cupsLangPrintf(stderr
,
165 _("%s: Error - unknown option \'%c\'!\n"),
166 argv
[0], argv
[i
][1]);
172 * Cancel a job or printer...
176 num_dests
= cupsGetDests(&dests
);
178 if (!strcmp(argv
[i
], "-"))
181 * Delete the current job...
187 else if (cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) != NULL
)
190 * Delete the current job on the named destination...
196 else if ((job
= strrchr(argv
[i
], '-')) != NULL
&& isdigit(job
[1] & 255))
199 * Delete the specified job ID.
204 job_id
= atoi(job
+ 1);
206 else if (isdigit(argv
[i
][0] & 255))
209 * Delete the specified job ID.
214 job_id
= atoi(argv
[i
]);
222 _cupsLangPrintf(stderr
,
223 _("%s: Error - unknown destination \"%s\"!\n"),
229 * For Solaris LP compatibility, ignore a destination name after
230 * cancelling a specific job ID...
233 if (job_id
&& (i
+ 1) < argc
&&
234 cupsGetDest(argv
[i
+ 1], NULL
, num_dests
, dests
) != NULL
)
238 * Open a connection to the server...
242 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
243 cupsEncryption())) == NULL
)
245 _cupsLangPrintf(stderr
,
246 _("%s: Unable to contact server!\n"),
252 * Build an IPP request, which requires the following
256 * attributes-natural-language
257 * printer-uri + job-id *or* job-uri
258 * [requesting-user-name]
261 request
= ippNewRequest(op
);
265 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
266 "localhost", 0, "/printers/%s", dest
);
267 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
268 "printer-uri", NULL
, uri
);
269 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
274 sprintf(uri
, "ipp://localhost/jobs/%d", job_id
);
275 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
281 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
282 "requesting-user-name", NULL
, user
);
283 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
286 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
287 "requesting-user-name", NULL
, cupsUser());
289 if (op
== IPP_PURGE_JOBS
)
290 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
293 * Do the request and get back a response...
296 if (op
== IPP_PURGE_JOBS
&& (!user
|| strcasecmp(user
, cupsUser())))
297 response
= cupsDoRequest(http
, request
, "/admin/");
299 response
= cupsDoRequest(http
, request
, "/jobs/");
301 if (response
== NULL
||
302 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
304 _cupsLangPrintf(stderr
, _("%s: %s failed: %s\n"), argv
[0],
305 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
306 cupsLastErrorString());
317 if (num_dests
== 0 && op
== IPP_PURGE_JOBS
)
320 * Open a connection to the server...
324 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
325 cupsEncryption())) == NULL
)
327 _cupsLangPrintf(stderr
, _("%s: Unable to contact server!\n"),
333 * Build an IPP request, which requires the following
337 * attributes-natural-language
338 * printer-uri + job-id *or* job-uri
339 * [requesting-user-name]
342 request
= ippNewRequest(op
);
344 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
345 "printer-uri", NULL
, "ipp://localhost/printers/");
349 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
350 "requesting-user-name", NULL
, user
);
351 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
354 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
355 "requesting-user-name", NULL
, cupsUser());
357 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
360 * Do the request and get back a response...
363 response
= cupsDoRequest(http
, request
, "/admin/");
365 if (response
== NULL
||
366 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
368 _cupsLangPrintf(stderr
, _("%s: %s failed: %s\n"), argv
[0],
369 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
370 cupsLastErrorString());
386 * End of "$Id: cancel.c 6649 2007-07-11 21:46:42Z mike $".