]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cancel.c
2 * "$Id: cancel.c 7720 2008-07-11 22:46:21Z mike $"
4 * "cancel" command for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 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...
70 * Process command-line arguments...
73 for (i
= 1; i
< argc
; i
++)
74 if (argv
[i
][0] == '-' && argv
[i
][1])
77 case 'E' : /* Encrypt */
79 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
82 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
84 _cupsLangPrintf(stderr
,
85 _("%s: Sorry, no encryption support compiled in!\n"),
90 case 'U' : /* Username */
91 if (argv
[i
][2] != '\0')
92 cupsSetUser(argv
[i
] + 2);
98 _cupsLangPrintf(stderr
,
99 _("%s: Error - expected username after "
105 cupsSetUser(argv
[i
]);
109 case 'a' : /* Cancel all jobs */
114 case 'h' : /* Connect to host */
121 if (argv
[i
][2] != '\0')
122 cupsSetServer(argv
[i
] + 2);
129 _cupsLangPrintf(stderr
,
130 _("%s: Error - expected hostname after "
136 cupsSetServer(argv
[i
]);
140 case 'u' : /* Username */
143 if (argv
[i
][2] != '\0')
151 _cupsLangPrintf(stderr
,
152 _("%s: Error - expected username after "
163 _cupsLangPrintf(stderr
,
164 _("%s: Error - unknown option \'%c\'!\n"),
165 argv
[0], argv
[i
][1]);
171 * Cancel a job or printer...
175 num_dests
= cupsGetDests(&dests
);
177 if (!strcmp(argv
[i
], "-"))
180 * Delete the current job...
186 else if (cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) != NULL
)
189 * Delete the current job on the named destination...
195 else if ((job
= strrchr(argv
[i
], '-')) != NULL
&& isdigit(job
[1] & 255))
198 * Delete the specified job ID.
203 job_id
= atoi(job
+ 1);
205 else if (isdigit(argv
[i
][0] & 255))
208 * Delete the specified job ID.
213 job_id
= atoi(argv
[i
]);
221 _cupsLangPrintf(stderr
,
222 _("%s: Error - unknown destination \"%s\"!\n"),
228 * For Solaris LP compatibility, ignore a destination name after
229 * cancelling a specific job ID...
232 if (job_id
&& (i
+ 1) < argc
&&
233 cupsGetDest(argv
[i
+ 1], NULL
, num_dests
, dests
) != NULL
)
237 * Open a connection to the server...
241 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
242 cupsEncryption())) == NULL
)
244 _cupsLangPrintf(stderr
,
245 _("%s: Unable to contact server!\n"),
251 * Build an IPP request, which requires the following
255 * attributes-natural-language
256 * printer-uri + job-id *or* job-uri
257 * [requesting-user-name]
260 request
= ippNewRequest(op
);
264 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
265 "localhost", 0, "/printers/%s", dest
);
266 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
267 "printer-uri", NULL
, uri
);
268 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
273 sprintf(uri
, "ipp://localhost/jobs/%d", job_id
);
274 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
280 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
281 "requesting-user-name", NULL
, user
);
282 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
285 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
286 "requesting-user-name", NULL
, cupsUser());
288 if (op
== IPP_PURGE_JOBS
)
289 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
292 * Do the request and get back a response...
295 if (op
== IPP_PURGE_JOBS
&& (!user
|| strcasecmp(user
, cupsUser())))
296 response
= cupsDoRequest(http
, request
, "/admin/");
298 response
= cupsDoRequest(http
, request
, "/jobs/");
300 if (response
== NULL
||
301 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
303 _cupsLangPrintf(stderr
, _("%s: %s failed: %s\n"), argv
[0],
304 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
305 cupsLastErrorString());
316 if (num_dests
== 0 && op
== IPP_PURGE_JOBS
)
319 * Open a connection to the server...
323 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
324 cupsEncryption())) == NULL
)
326 _cupsLangPrintf(stderr
, _("%s: Unable to contact server!\n"),
332 * Build an IPP request, which requires the following
336 * attributes-natural-language
337 * printer-uri + job-id *or* job-uri
338 * [requesting-user-name]
341 request
= ippNewRequest(op
);
343 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
344 "printer-uri", NULL
, "ipp://localhost/printers/");
348 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
349 "requesting-user-name", NULL
, user
);
350 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
353 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
354 "requesting-user-name", NULL
, cupsUser());
356 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
359 * Do the request and get back a response...
362 response
= cupsDoRequest(http
, request
, "/admin/");
364 if (response
== NULL
||
365 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
367 _cupsLangPrintf(stderr
, _("%s: %s failed: %s\n"), argv
[0],
368 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
369 cupsLastErrorString());
385 * End of "$Id: cancel.c 7720 2008-07-11 22:46:21Z mike $".