]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cancel.c
2 * "$Id: cancel.c,v 1.14 2000/01/04 13:46:11 mike Exp $"
4 * "cancel" command for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2000 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-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Parse options and cancel jobs.
30 * Include necessary headers...
37 #include <cups/cups.h>
38 #include <cups/language.h>
42 * 'main()' - Parse options and cancel jobs.
45 int /* O - Exit status */
46 main(int argc
, /* I - Number of command-line arguments */
47 char *argv
[]) /* I - Command-line arguments */
49 http_t
*http
; /* HTTP connection to server */
50 int i
; /* Looping var */
51 int job_id
; /* Job ID */
52 char *dest
, /* Destination printer */
53 *host
; /* Host name */
54 char name
[255]; /* Printer name */
55 char uri
[1024]; /* Printer or job URI */
56 ipp_t
*request
; /* IPP request */
57 ipp_t
*response
; /* IPP response */
58 ipp_op_t op
; /* Operation */
59 cups_lang_t
*language
; /* Language */
63 * Setup to cancel individual print jobs...
72 * Process command-line arguments...
75 for (i
= 1; i
< argc
; i
++)
76 if (argv
[i
][0] == '-')
79 case 'a' : /* Cancel all jobs */
83 case 'h' : /* Connect to host */
87 if (argv
[i
][2] != '\0')
88 http
= httpConnect(argv
[i
] + 2, ippPort());
95 fputs("Error: need hostname after \'-h\' option!\n", stderr
);
99 http
= httpConnect(argv
[i
], ippPort());
104 perror("cancel: Unable to connect to server");
110 fprintf(stderr
, "cancel: Unknown option \'%c\'!\n", argv
[i
][1]);
116 * Cancel a job or printer...
119 if (isdigit(argv
[i
][0]))
123 job_id
= atoi(argv
[i
]);
129 sscanf(argv
[i
], "%254[^-]-%d", name
, &job_id
);
133 if ((host
= strchr(name
, '@')) != NULL
)
136 * Reconnect to the named host...
144 if ((http
= httpConnect(host
, ippPort())) == NULL
)
146 perror("cancel: Unable to connect to server");
153 * Open a connection to the server...
157 if ((http
= httpConnect(cupsServer(), ippPort())) == NULL
)
159 fputs("cancel: Unable to contact server!\n", stderr
);
164 * Build an IPP request, which requires the following
168 * attributes-natural-language
169 * printer-uri + job-id *or* job-uri
170 * [requesting-user-name]
175 request
->request
.op
.operation_id
= op
;
176 request
->request
.op
.request_id
= 1;
178 language
= cupsLangDefault();
180 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
181 "attributes-charset", NULL
, cupsLangEncoding(language
));
183 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
184 "attributes-natural-language", NULL
, language
->language
);
188 snprintf(uri
, sizeof(uri
), "ipp://localhost/printers/%s", dest
);
189 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
190 "printer-uri", NULL
, uri
);
191 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
196 sprintf(uri
, "ipp://localhost/jobs/%d", job_id
);
197 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
201 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
202 "requesting-user-name", NULL
, cupsUser());
205 * Do the request and get back a response...
208 if (op
== IPP_PURGE_JOBS
)
209 response
= cupsDoRequest(http
, request
, "/admin/");
211 response
= cupsDoRequest(http
, request
, "/jobs/");
213 if (response
!= NULL
)
215 switch (response
->request
.status
.status_code
)
218 fputs("cancel: Job or printer not found!\n", stderr
);
220 case IPP_NOT_AUTHORIZED
:
221 fputs("cancel: Not authorized to cancel job(s)!\n", stderr
);
224 fprintf(stderr
, "cancel: You don't own job ID %d!\n", job_id
);
227 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
228 fputs("cancel: Unable to cancel job(s)!\n", stderr
);
236 fputs("cancel: Unable to cancel job(s)!\n", stderr
);
246 * End of "$Id: cancel.c,v 1.14 2000/01/04 13:46:11 mike Exp $".