]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cancel.c
2 * "$Id: cancel.c 5926 2006-09-05 20:45:47Z mike $"
4 * "cancel" command for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Parse options and cancel jobs.
30 * Include necessary headers...
35 #include <cups/string.h>
36 #include <cups/cups.h>
37 #include <cups/i18n.h>
41 * 'main()' - Parse options and cancel jobs.
44 int /* O - Exit status */
45 main(int argc
, /* I - Number of command-line arguments */
46 char *argv
[]) /* I - Command-line arguments */
48 http_t
*http
; /* HTTP connection to server */
49 int i
; /* Looping var */
50 int job_id
; /* Job ID */
51 int num_dests
; /* Number of destinations */
52 cups_dest_t
*dests
; /* Destinations */
53 char *dest
, /* Destination printer */
54 *job
, /* Job ID pointer */
55 *user
; /* Cancel jobs for a user */
56 int purge
; /* Purge or cancel jobs? */
57 char uri
[1024]; /* Printer or job URI */
58 ipp_t
*request
; /* IPP request */
59 ipp_t
*response
; /* IPP response */
60 ipp_op_t op
; /* Operation */
66 * Setup to cancel individual print jobs...
80 * Process command-line arguments...
83 for (i
= 1; i
< argc
; i
++)
84 if (argv
[i
][0] == '-' && argv
[i
][1])
87 case 'E' : /* Encrypt */
89 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
92 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
94 _cupsLangPrintf(stderr
,
95 _("%s: Sorry, no encryption support compiled in!\n"),
100 case 'U' : /* Username */
101 if (argv
[i
][2] != '\0')
102 cupsSetUser(argv
[i
] + 2);
108 _cupsLangPrintf(stderr
,
109 _("%s: Error - expected username after "
115 cupsSetUser(argv
[i
]);
119 case 'a' : /* Cancel all jobs */
124 case 'h' : /* Connect to host */
131 if (argv
[i
][2] != '\0')
132 cupsSetServer(argv
[i
] + 2);
139 _cupsLangPrintf(stderr
,
140 _("%s: Error - expected hostname after "
146 cupsSetServer(argv
[i
]);
150 case 'u' : /* Username */
153 if (argv
[i
][2] != '\0')
161 _cupsLangPrintf(stderr
,
162 _("%s: Error - expected username after "
173 _cupsLangPrintf(stderr
,
174 _("%s: Error - unknown option \'%c\'!\n"),
175 argv
[0], argv
[i
][1]);
181 * Cancel a job or printer...
185 num_dests
= cupsGetDests(&dests
);
187 if (!strcmp(argv
[i
], "-"))
190 * Delete the current job...
196 else if (cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) != NULL
)
199 * Delete the current job on the named destination...
205 else if ((job
= strrchr(argv
[i
], '-')) != NULL
&& isdigit(job
[1] & 255))
208 * Delete the specified job ID.
213 job_id
= atoi(job
+ 1);
215 else if (isdigit(argv
[i
][0] & 255))
218 * Delete the specified job ID.
223 job_id
= atoi(argv
[i
]);
231 _cupsLangPrintf(stderr
,
232 _("%s: Error - unknown destination \"%s\"!\n"),
238 * For Solaris LP compatibility, ignore a destination name after
239 * cancelling a specific job ID...
242 if (job_id
&& (i
+ 1) < argc
&&
243 cupsGetDest(argv
[i
+ 1], NULL
, num_dests
, dests
) != NULL
)
247 * Open a connection to the server...
251 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
252 cupsEncryption())) == NULL
)
254 _cupsLangPrintf(stderr
,
255 _("%s: Unable to contact server!\n"),
261 * Build an IPP request, which requires the following
265 * attributes-natural-language
266 * printer-uri + job-id *or* job-uri
267 * [requesting-user-name]
270 request
= ippNewRequest(op
);
274 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
275 "localhost", 0, "/printers/%s", dest
);
276 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
277 "printer-uri", NULL
, uri
);
278 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
283 sprintf(uri
, "ipp://localhost/jobs/%d", job_id
);
284 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
290 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
291 "requesting-user-name", NULL
, user
);
292 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
295 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
296 "requesting-user-name", NULL
, cupsUser());
298 if (op
== IPP_PURGE_JOBS
)
299 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
302 * Do the request and get back a response...
305 if (op
== IPP_PURGE_JOBS
&& (!user
|| strcasecmp(user
, cupsUser())))
306 response
= cupsDoRequest(http
, request
, "/admin/");
308 response
= cupsDoRequest(http
, request
, "/jobs/");
310 if (response
== NULL
||
311 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
313 _cupsLangPrintf(stderr
, _("%s: %s failed: %s\n"), argv
[0],
314 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
315 cupsLastErrorString());
326 if (num_dests
== 0 && op
== IPP_PURGE_JOBS
)
329 * Open a connection to the server...
333 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
334 cupsEncryption())) == NULL
)
336 _cupsLangPrintf(stderr
, _("%s: Unable to contact server!\n"),
342 * Build an IPP request, which requires the following
346 * attributes-natural-language
347 * printer-uri + job-id *or* job-uri
348 * [requesting-user-name]
351 request
= ippNewRequest(op
);
353 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
354 "printer-uri", NULL
, "ipp://localhost/printers/");
358 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
359 "requesting-user-name", NULL
, user
);
360 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
363 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
364 "requesting-user-name", NULL
, cupsUser());
366 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
369 * Do the request and get back a response...
372 response
= cupsDoRequest(http
, request
, "/admin/");
374 if (response
== NULL
||
375 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
377 _cupsLangPrintf(stderr
, _("%s: %s failed: %s\n"), argv
[0],
378 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
379 cupsLastErrorString());
395 * End of "$Id: cancel.c 5926 2006-09-05 20:45:47Z mike $".