]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cancel.c
2 * "$Id: cancel.c 5091 2006-02-08 18:39:56Z 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 */
64 * Setup to cancel individual print jobs...
78 * Process command-line arguments...
81 for (i
= 1; i
< argc
; i
++)
82 if (argv
[i
][0] == '-' && argv
[i
][1])
85 case 'E' : /* Encrypt */
87 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
90 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
92 _cupsLangPrintf(stderr
,
93 _("%s: Sorry, no encryption support compiled in!\n"),
98 case 'U' : /* Username */
99 if (argv
[i
][2] != '\0')
100 cupsSetUser(argv
[i
] + 2);
106 _cupsLangPrintf(stderr
,
107 _("%s: Error - expected username after "
113 cupsSetUser(argv
[i
]);
117 case 'a' : /* Cancel all jobs */
122 case 'h' : /* Connect to host */
126 if (argv
[i
][2] != '\0')
127 cupsSetServer(argv
[i
] + 2);
134 _cupsLangPrintf(stderr
,
135 _("%s: Error - expected hostname after "
141 cupsSetServer(argv
[i
]);
145 case 'u' : /* Username */
148 if (argv
[i
][2] != '\0')
156 _cupsLangPrintf(stderr
,
157 _("%s: Error - expected username after "
168 _cupsLangPrintf(stderr
,
169 _("%s: Error - unknown option \'%c\'!\n"),
170 argv
[0], argv
[i
][1]);
176 * Cancel a job or printer...
180 num_dests
= cupsGetDests(&dests
);
182 if (!strcmp(argv
[i
], "-"))
185 * Delete the current job...
191 else if (cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) != NULL
)
194 * Delete the current job on the named destination...
200 else if ((job
= strrchr(argv
[i
], '-')) != NULL
&& isdigit(job
[1] & 255))
203 * Delete the specified job ID.
208 job_id
= atoi(job
+ 1);
210 else if (isdigit(argv
[i
][0] & 255))
213 * Delete the specified job ID.
218 job_id
= atoi(argv
[i
]);
226 _cupsLangPrintf(stderr
,
227 _("%s: Error - unknown destination \"%s\"!\n"),
233 * For Solaris LP compatibility, ignore a destination name after
234 * cancelling a specific job ID...
237 if (job_id
&& (i
+ 1) < argc
&&
238 cupsGetDest(argv
[i
+ 1], NULL
, num_dests
, dests
) != NULL
)
242 * Open a connection to the server...
246 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
247 cupsEncryption())) == NULL
)
249 _cupsLangPrintf(stderr
,
250 _("%s: Unable to contact server!\n"),
256 * Build an IPP request, which requires the following
260 * attributes-natural-language
261 * printer-uri + job-id *or* job-uri
262 * [requesting-user-name]
265 request
= ippNewRequest(op
);
269 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
270 "localhost", 0, "/printers/%s", dest
);
271 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
272 "printer-uri", NULL
, uri
);
273 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
278 sprintf(uri
, "ipp://localhost/jobs/%d", job_id
);
279 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
285 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
286 "requesting-user-name", NULL
, user
);
287 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
290 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
291 "requesting-user-name", NULL
, cupsUser());
293 if (op
== IPP_PURGE_JOBS
)
294 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
297 * Do the request and get back a response...
300 if (op
== IPP_PURGE_JOBS
&& (!user
|| strcasecmp(user
, cupsUser())))
301 response
= cupsDoRequest(http
, request
, "/admin/");
303 response
= cupsDoRequest(http
, request
, "/jobs/");
305 if (response
== NULL
||
306 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
308 _cupsLangPrintf(stderr
, _("%s: %s failed: %s\n"), argv
[0],
309 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
310 cupsLastErrorString());
321 if (num_dests
== 0 && op
== IPP_PURGE_JOBS
)
324 * Open a connection to the server...
328 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
329 cupsEncryption())) == NULL
)
331 _cupsLangPrintf(stderr
, _("%s: Unable to contact server!\n"),
337 * Build an IPP request, which requires the following
341 * attributes-natural-language
342 * printer-uri + job-id *or* job-uri
343 * [requesting-user-name]
346 request
= ippNewRequest(op
);
348 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
349 "printer-uri", NULL
, "ipp://localhost/printers/");
353 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
354 "requesting-user-name", NULL
, user
);
355 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
358 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
359 "requesting-user-name", NULL
, cupsUser());
361 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
364 * Do the request and get back a response...
367 response
= cupsDoRequest(http
, request
, "/admin/");
369 if (response
== NULL
||
370 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
372 _cupsLangPrintf(stderr
, _("%s: %s failed: %s\n"), argv
[0],
373 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
374 cupsLastErrorString());
390 * End of "$Id: cancel.c 5091 2006-02-08 18:39:56Z mike $".