]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cancel.c
2 * "$Id: cancel.c 4906 2006-01-10 20:53:28Z 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 */
61 cups_lang_t
*language
; /* Language */
65 * Setup to cancel individual print jobs...
76 language
= cupsLangDefault();
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
, language
,
95 _("%s: Sorry, no encryption support compiled in!\n"),
100 case 'a' : /* Cancel all jobs */
105 case 'h' : /* Connect to host */
109 if (argv
[i
][2] != '\0')
110 cupsSetServer(argv
[i
] + 2);
117 _cupsLangPuts(stderr
, language
,
118 _("cancel: Error - expected hostname after "
119 "\'-h\' option!\n"));
123 cupsSetServer(argv
[i
]);
127 case 'u' : /* Username */
130 if (argv
[i
][2] != '\0')
138 _cupsLangPuts(stderr
, language
,
139 _("cancel: Error - expected username after "
140 "\'-u\' option!\n"));
149 _cupsLangPrintf(stderr
, language
,
150 _("cancel: Unknown option \'%c\'!\n"), argv
[i
][1]);
156 * Cancel a job or printer...
160 num_dests
= cupsGetDests(&dests
);
162 if (strcmp(argv
[i
], "-") == 0)
165 * Delete the current job...
171 else if (cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) != NULL
)
174 * Delete the current job on the named destination...
180 else if ((job
= strrchr(argv
[i
], '-')) != NULL
&& isdigit(job
[1] & 255))
183 * Delete the specified job ID.
188 job_id
= atoi(job
+ 1);
190 else if (isdigit(argv
[i
][0] & 255))
193 * Delete the specified job ID.
198 job_id
= atoi(argv
[i
]);
206 _cupsLangPrintf(stderr
, language
,
207 _("cancel: Unknown destination \"%s\"!\n"), argv
[i
]);
212 * For Solaris LP compatibility, ignore a destination name after
213 * cancelling a specific job ID...
216 if (job_id
&& (i
+ 1) < argc
&&
217 cupsGetDest(argv
[i
+ 1], NULL
, num_dests
, dests
) != NULL
)
221 * Open a connection to the server...
225 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
226 cupsEncryption())) == NULL
)
228 _cupsLangPuts(stderr
, language
,
229 _("cancel: Unable to contact server!\n"));
234 * Build an IPP request, which requires the following
238 * attributes-natural-language
239 * printer-uri + job-id *or* job-uri
240 * [requesting-user-name]
245 request
->request
.op
.operation_id
= op
;
246 request
->request
.op
.request_id
= 1;
248 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
249 "attributes-charset", NULL
, cupsLangEncoding(language
));
251 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
252 "attributes-natural-language", NULL
, language
->language
);
256 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
257 "/printers/%s", dest
);
258 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
259 "printer-uri", NULL
, uri
);
260 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
265 sprintf(uri
, "ipp://localhost/jobs/%d", job_id
);
266 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
272 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
273 "requesting-user-name", NULL
, user
);
274 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
277 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
278 "requesting-user-name", NULL
, cupsUser());
280 if (op
== IPP_PURGE_JOBS
)
281 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
284 * Do the request and get back a response...
287 if (op
== IPP_PURGE_JOBS
&& (!user
|| strcasecmp(user
, cupsUser())))
288 response
= cupsDoRequest(http
, request
, "/admin/");
290 response
= cupsDoRequest(http
, request
, "/jobs/");
292 if (response
== NULL
||
293 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
295 _cupsLangPrintf(stderr
, language
, _("cancel: %s failed: %s\n"),
296 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
297 response
? ippErrorString(response
->request
.status
.status_code
) :
298 ippErrorString(cupsLastError()));
309 if (num_dests
== 0 && op
== IPP_PURGE_JOBS
)
312 * Open a connection to the server...
316 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
317 cupsEncryption())) == NULL
)
319 _cupsLangPuts(stderr
, language
, _("cancel: Unable to contact server!\n"));
324 * Build an IPP request, which requires the following
328 * attributes-natural-language
329 * printer-uri + job-id *or* job-uri
330 * [requesting-user-name]
335 request
->request
.op
.operation_id
= op
;
336 request
->request
.op
.request_id
= 1;
338 language
= cupsLangDefault();
340 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
341 "attributes-charset", NULL
, cupsLangEncoding(language
));
343 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
344 "attributes-natural-language", NULL
, language
->language
);
346 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
347 "printer-uri", NULL
, "ipp://localhost/printers/");
351 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
352 "requesting-user-name", NULL
, user
);
353 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
356 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
357 "requesting-user-name", NULL
, cupsUser());
359 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", purge
);
362 * Do the request and get back a response...
365 response
= cupsDoRequest(http
, request
, "/admin/");
367 if (response
== NULL
||
368 response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
370 _cupsLangPrintf(stderr
, language
, _("cancel: %s failed: %s\n"),
371 op
== IPP_PURGE_JOBS
? "purge-jobs" : "cancel-job",
372 response
? ippErrorString(response
->request
.status
.status_code
) :
373 ippErrorString(cupsLastError()));
389 * End of "$Id: cancel.c 4906 2006-01-10 20:53:28Z mike $".