]>
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 CUPS.
6 * Copyright 2007-2010 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...
24 #include <cups/cups-private.h>
28 * 'main()' - Parse options and cancel jobs.
31 int /* O - Exit status */
32 main(int argc
, /* I - Number of command-line arguments */
33 char *argv
[]) /* I - Command-line arguments */
35 http_t
*http
; /* HTTP connection to server */
36 int i
; /* Looping var */
37 int job_id
; /* Job ID */
38 int num_dests
; /* Number of destinations */
39 cups_dest_t
*dests
; /* Destinations */
40 char *dest
, /* Destination printer */
41 *job
, /* Job ID pointer */
42 *user
; /* Cancel jobs for a user */
43 int purge
; /* Purge or cancel jobs? */
44 char uri
[1024]; /* Printer or job URI */
45 ipp_t
*request
; /* IPP request */
46 ipp_t
*response
; /* IPP response */
47 ipp_op_t op
; /* Operation */
53 * Setup to cancel individual print jobs...
66 * Process command-line arguments...
69 for (i
= 1; i
< argc
; i
++)
70 if (argv
[i
][0] == '-' && argv
[i
][1])
73 case 'E' : /* Encrypt */
75 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
78 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
80 _cupsLangPrintf(stderr
,
81 _("%s: Sorry, no encryption support."), argv
[0]);
85 case 'U' : /* Username */
86 if (argv
[i
][2] != '\0')
87 cupsSetUser(argv
[i
] + 2);
93 _cupsLangPrintf(stderr
,
94 _("%s: Error - expected username after "
95 "\"-U\" option."), argv
[0]);
103 case 'a' : /* Cancel all jobs */
108 case 'h' : /* Connect to host */
115 if (argv
[i
][2] != '\0')
116 cupsSetServer(argv
[i
] + 2);
123 _cupsLangPrintf(stderr
,
124 _("%s: Error - expected hostname after "
125 "\"-h\" option."), argv
[0]);
129 cupsSetServer(argv
[i
]);
133 case 'u' : /* Username */
136 if (argv
[i
][2] != '\0')
144 _cupsLangPrintf(stderr
,
145 _("%s: Error - expected username after "
146 "\"-u\" option."), argv
[0]);
155 _cupsLangPrintf(stderr
,
156 _("%s: Error - unknown option \"%c\"."),
157 argv
[0], argv
[i
][1]);
163 * Cancel a job or printer...
167 num_dests
= cupsGetDests(&dests
);
169 if (!strcmp(argv
[i
], "-"))
172 * Delete the current job...
178 else if (cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) != NULL
)
181 * Delete the current job on the named destination...
187 else if ((job
= strrchr(argv
[i
], '-')) != NULL
&& isdigit(job
[1] & 255))
190 * Delete the specified job ID.
195 job_id
= atoi(job
+ 1);
197 else if (isdigit(argv
[i
][0] & 255))
200 * Delete the specified job ID.
205 job_id
= atoi(argv
[i
]);
213 _cupsLangPrintf(stderr
,
214 _("%s: Error - unknown destination \"%s\"."),
220 * For Solaris LP compatibility, ignore a destination name after
221 * cancelling a specific job ID...
224 if (job_id
&& (i
+ 1) < argc
&&
225 cupsGetDest(argv
[i
+ 1], NULL
, num_dests
, dests
) != NULL
)
229 * Open a connection to the server...
233 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
234 cupsEncryption())) == NULL
)
236 _cupsLangPrintf(stderr
,
237 _("%s: Unable to contact server."), argv
[0]);
242 * Build an IPP request, which requires the following
246 * attributes-natural-language
247 * printer-uri + job-id *or* job-uri
248 * [requesting-user-name]
251 request
= ippNewRequest(op
);
255 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
256 "localhost", 0, "/printers/%s", dest
);
257 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
258 "printer-uri", NULL
, uri
);
259 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
264 sprintf(uri
, "ipp://localhost/jobs/%d", job_id
);
265 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
271 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
272 "requesting-user-name", NULL
, user
);
273 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
276 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
277 "requesting-user-name", NULL
, cupsUser());
279 if (op
== IPP_PURGE_JOBS
)
280 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
283 * Do the request and get back a response...
286 if (op
== IPP_PURGE_JOBS
&& (!user
|| strcasecmp(user
, cupsUser())))
287 response
= cupsDoRequest(http
, request
, "/admin/");
289 response
= cupsDoRequest(http
, request
, "/jobs/");
291 if (response
== NULL
||
292 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
294 _cupsLangPrintf(stderr
, _("%s: %s failed: %s"), argv
[0],
295 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
296 cupsLastErrorString());
307 if (num_dests
== 0 && op
== IPP_PURGE_JOBS
)
310 * Open a connection to the server...
314 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
315 cupsEncryption())) == NULL
)
317 _cupsLangPrintf(stderr
, _("%s: Unable to contact server."), argv
[0]);
322 * Build an IPP request, which requires the following
326 * attributes-natural-language
327 * printer-uri + job-id *or* job-uri
328 * [requesting-user-name]
331 request
= ippNewRequest(op
);
333 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
334 "printer-uri", NULL
, "ipp://localhost/printers/");
338 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
339 "requesting-user-name", NULL
, user
);
340 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
343 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
344 "requesting-user-name", NULL
, cupsUser());
346 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
349 * Do the request and get back a response...
352 response
= cupsDoRequest(http
, request
, "/admin/");
354 if (response
== NULL
||
355 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
357 _cupsLangPrintf(stderr
, _("%s: %s failed: %s"), argv
[0],
358 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
359 cupsLastErrorString());
375 * End of "$Id: cancel.c 7720 2008-07-11 22:46:21Z mike $".