]>
Commit | Line | Data |
---|---|---|
fc8c8467 | 1 | /* |
8784b6a6 | 2 | * "$Id: cancel.c,v 1.5 1999/06/18 18:36:52 mike Exp $" |
fc8c8467 | 3 | * |
4 | * "cancel" command for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 1997-1999 by Easy Software Products. | |
7 | * | |
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 | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
8784b6a6 | 17 | * 44141 Airport View Drive, Suite 204 |
fc8c8467 | 18 | * Hollywood, Maryland 20636-3111 USA |
19 | * | |
20 | * Voice: (301) 373-9603 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * Contents: | |
25 | * | |
26 | * main() - Parse options and cancel jobs. | |
27 | */ | |
28 | ||
29 | /* | |
30 | * Include necessary headers... | |
31 | */ | |
32 | ||
33 | #include <stdio.h> | |
34 | #include <stdlib.h> | |
b310a06a | 35 | #include <ctype.h> |
36 | ||
fc8c8467 | 37 | #include <cups/cups.h> |
b310a06a | 38 | #include <cups/language.h> |
fc8c8467 | 39 | |
40 | ||
41 | /* | |
42 | * 'main()' - Parse options and cancel jobs. | |
43 | */ | |
44 | ||
b310a06a | 45 | int /* O - Exit status */ |
46 | main(int argc, /* I - Number of command-line arguments */ | |
47 | char *argv[]) /* I - Command-line arguments */ | |
fc8c8467 | 48 | { |
b310a06a | 49 | http_t *http; /* HTTP connection to server */ |
fc8c8467 | 50 | int i; /* Looping var */ |
51 | int job_id; /* Job ID */ | |
808dd474 | 52 | char *dest, /* Destination printer */ |
53 | *host; /* Host name */ | |
b310a06a | 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 */ | |
fc8c8467 | 60 | |
fc8c8467 | 61 | |
b310a06a | 62 | /* |
63 | * Setup to cancel individual print jobs... | |
64 | */ | |
fc8c8467 | 65 | |
b310a06a | 66 | op = IPP_CANCEL_JOB; |
67 | job_id = 0; | |
68 | dest = NULL; | |
fc8c8467 | 69 | |
b310a06a | 70 | /* |
71 | * Open a connection to the server... | |
72 | */ | |
fc8c8467 | 73 | |
b310a06a | 74 | if ((http = httpConnect("localhost", ippPort())) == NULL) |
75 | { | |
76 | fputs("cancel: Unable to contact server!\n", stderr); | |
77 | return (1); | |
78 | } | |
fc8c8467 | 79 | |
b310a06a | 80 | /* |
81 | * Process command-line arguments... | |
82 | */ | |
fc8c8467 | 83 | |
b310a06a | 84 | for (i = 1; i < argc; i ++) |
85 | if (argv[i][0] == '-') | |
86 | switch (argv[i][1]) | |
87 | { | |
88 | case 'a' : /* Cancel all jobs */ | |
89 | op = IPP_PURGE_JOBS; | |
fc8c8467 | 90 | break; |
91 | ||
808dd474 | 92 | case 'h' : /* Connect to host */ |
93 | httpClose(http); | |
94 | ||
95 | if (argv[i][2] != '\0') | |
96 | http = httpConnect(argv[i] + 2, ippPort()); | |
97 | else | |
98 | { | |
99 | i ++; | |
100 | http = httpConnect(argv[i], ippPort()); | |
101 | } | |
102 | ||
103 | if (http == NULL) | |
104 | { | |
105 | perror("cancel: Unable to connect to server"); | |
106 | return (1); | |
107 | } | |
108 | break; | |
109 | ||
fc8c8467 | 110 | default : |
b310a06a | 111 | fprintf(stderr, "cancel: Unknown option \'%c\'!\n", argv[i][1]); |
fc8c8467 | 112 | return (1); |
113 | } | |
b310a06a | 114 | else |
fc8c8467 | 115 | { |
b310a06a | 116 | /* |
117 | * Cancel a job or printer... | |
118 | */ | |
fc8c8467 | 119 | |
b310a06a | 120 | if (isdigit(argv[i][0])) |
121 | { | |
122 | dest = NULL; | |
123 | op = IPP_CANCEL_JOB; | |
124 | job_id = atoi(argv[i]); | |
125 | } | |
126 | else | |
127 | { | |
128 | dest = name; | |
129 | job_id = 0; | |
130 | sscanf(argv[i], "%[^-]-%d", name, &job_id); | |
131 | if (job_id) | |
132 | op = IPP_CANCEL_JOB; | |
808dd474 | 133 | |
134 | if ((host = strchr(name, '@')) != NULL) | |
135 | { | |
136 | /* | |
137 | * Reconnect to the named host... | |
138 | */ | |
139 | ||
140 | httpClose(http); | |
141 | ||
142 | *host++ = '\0'; | |
143 | ||
144 | if ((http = httpConnect(host, ippPort())) == NULL) | |
145 | { | |
146 | perror("cancel: Unable to connect to server"); | |
147 | return (1); | |
148 | } | |
149 | } | |
b310a06a | 150 | } |
fc8c8467 | 151 | |
b310a06a | 152 | /* |
153 | * Build an IPP request, which requires the following | |
154 | * attributes: | |
155 | * | |
156 | * attributes-charset | |
157 | * attributes-natural-language | |
158 | * printer-uri + job-id *or* job-uri | |
159 | */ | |
fc8c8467 | 160 | |
b310a06a | 161 | request = ippNew(); |
fc8c8467 | 162 | |
b310a06a | 163 | request->request.op.operation_id = op; |
164 | request->request.op.request_id = 1; | |
fc8c8467 | 165 | |
b310a06a | 166 | language = cupsLangDefault(); |
fc8c8467 | 167 | |
b310a06a | 168 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, |
169 | "attributes-charset", NULL, cupsLangEncoding(language)); | |
fc8c8467 | 170 | |
b310a06a | 171 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, |
172 | "attributes-natural-language", NULL, language->language); | |
fc8c8467 | 173 | |
b310a06a | 174 | if (dest) |
175 | { | |
1fd07458 | 176 | sprintf(uri, "ipp://localhost/printers/%s", dest); |
b310a06a | 177 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, |
178 | "printer-uri", NULL, uri); | |
179 | ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", | |
180 | job_id); | |
181 | } | |
182 | else | |
183 | { | |
1fd07458 | 184 | sprintf(uri, "ipp://localhost/jobs/%d", job_id); |
b310a06a | 185 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, |
186 | uri); | |
187 | } | |
fc8c8467 | 188 | |
b310a06a | 189 | /* |
190 | * Do the request and get back a response... | |
191 | */ | |
fc8c8467 | 192 | |
b310a06a | 193 | if (op == IPP_PURGE_JOBS) |
194 | response = cupsDoRequest(http, request, "/admin/"); | |
195 | else | |
196 | response = cupsDoRequest(http, request, "/jobs/"); | |
fc8c8467 | 197 | |
b310a06a | 198 | if (response != NULL) |
199 | ippDelete(response); | |
200 | else | |
201 | { | |
202 | fputs("cancel: Unable to cancel job(s)!\n", stderr); | |
203 | return (1); | |
204 | } | |
fc8c8467 | 205 | } |
fc8c8467 | 206 | |
207 | return (0); | |
208 | } | |
209 | ||
210 | ||
211 | /* | |
8784b6a6 | 212 | * End of "$Id: cancel.c,v 1.5 1999/06/18 18:36:52 mike Exp $". |
fc8c8467 | 213 | */ |