]>
Commit | Line | Data |
---|---|---|
bd0b97ff | 1 | /* |
8784b6a6 | 2 | * "$Id: lprm.c,v 1.3 1999/06/18 18:36:05 mike Exp $" |
bd0b97ff | 3 | * |
4 | * "lprm" 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 |
bd0b97ff | 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> | |
35 | #include <ctype.h> | |
36 | ||
37 | #include <cups/cups.h> | |
38 | #include <cups/language.h> | |
39 | ||
40 | ||
41 | /* | |
42 | * 'main()' - Parse options and cancel jobs. | |
43 | */ | |
44 | ||
45 | int /* O - Exit status */ | |
46 | main(int argc, /* I - Number of command-line arguments */ | |
47 | char *argv[]) /* I - Command-line arguments */ | |
48 | { | |
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 | char uri[1024]; /* Printer or job URI */ | |
54 | ipp_t *request; /* IPP request */ | |
55 | ipp_t *response; /* IPP response */ | |
56 | ipp_op_t op; /* Operation */ | |
57 | cups_lang_t *language; /* Language */ | |
58 | ||
59 | ||
60 | /* | |
61 | * Setup to cancel individual print jobs... | |
62 | */ | |
63 | ||
64 | op = IPP_CANCEL_JOB; | |
65 | job_id = 0; | |
66 | dest = cupsGetDefault(); | |
67 | response = NULL; | |
68 | ||
69 | /* | |
70 | * Open a connection to the server... | |
71 | */ | |
72 | ||
73 | if ((http = httpConnect("localhost", ippPort())) == NULL) | |
74 | { | |
75 | fputs("lprm: Unable to contact server!\n", stderr); | |
76 | return (1); | |
77 | } | |
78 | ||
79 | /* | |
80 | * Process command-line arguments... | |
81 | */ | |
82 | ||
83 | for (i = 1; i < argc; i ++) | |
84 | if (argv[i][0] == '-' && argv[i][1] != '\0') | |
85 | switch (argv[i][1]) | |
86 | { | |
87 | case 'P' : /* Cancel jobs on a printer */ | |
88 | if (argv[i][2]) | |
89 | dest = argv[i] + 2; | |
90 | else | |
91 | { | |
92 | i ++; | |
93 | dest = argv[i]; | |
94 | } | |
95 | break; | |
96 | ||
97 | default : | |
98 | fprintf(stderr, "lprm: Unknown option \'%c\'!\n", argv[i][1]); | |
99 | return (1); | |
100 | } | |
101 | else | |
102 | { | |
103 | /* | |
104 | * Cancel a job or printer... | |
105 | */ | |
106 | ||
107 | if (isdigit(argv[i][0])) | |
108 | { | |
109 | dest = NULL; | |
110 | op = IPP_CANCEL_JOB; | |
111 | job_id = atoi(argv[i]); | |
112 | } | |
113 | else if (strcmp(argv[i], "-") == 0) | |
114 | { | |
115 | /* | |
116 | * Cancel all jobs | |
117 | */ | |
118 | ||
119 | op = IPP_PURGE_JOBS; | |
120 | } | |
121 | else | |
122 | job_id = 0; | |
123 | ||
124 | /* | |
125 | * Build an IPP request, which requires the following | |
126 | * attributes: | |
127 | * | |
128 | * attributes-charset | |
129 | * attributes-natural-language | |
130 | * printer-uri + job-id *or* job-uri | |
131 | * [requesting-user-name] | |
132 | */ | |
133 | ||
134 | request = ippNew(); | |
135 | ||
136 | request->request.op.operation_id = op; | |
137 | request->request.op.request_id = 1; | |
138 | ||
139 | language = cupsLangDefault(); | |
140 | ||
141 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, | |
142 | "attributes-charset", NULL, cupsLangEncoding(language)); | |
143 | ||
144 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, | |
145 | "attributes-natural-language", NULL, language->language); | |
146 | ||
147 | if (dest) | |
148 | { | |
f8ab8b97 | 149 | sprintf(uri, "ipp://localhost/printers/%s", dest); |
bd0b97ff | 150 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, |
151 | "printer-uri", NULL, uri); | |
152 | ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", | |
153 | job_id); | |
154 | } | |
155 | else | |
156 | { | |
f8ab8b97 | 157 | sprintf(uri, "ipp://localhost/jobs/%d", job_id); |
bd0b97ff | 158 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, |
159 | uri); | |
160 | } | |
161 | ||
162 | /* | |
163 | * Do the request and get back a response... | |
164 | */ | |
165 | ||
166 | if (op == IPP_PURGE_JOBS) | |
167 | response = cupsDoRequest(http, request, "/admin/"); | |
168 | else | |
169 | response = cupsDoRequest(http, request, "/jobs/"); | |
170 | ||
171 | if (response != NULL) | |
172 | ippDelete(response); | |
173 | else | |
174 | { | |
175 | fputs("lprm: Unable to cancel job(s)!\n", stderr); | |
176 | return (1); | |
177 | } | |
178 | } | |
179 | ||
180 | /* | |
181 | * If nothing has been cancelled yet, cancel the current job on the specified | |
182 | * (or default) printer... | |
183 | */ | |
184 | ||
185 | if (response == NULL) | |
186 | if (!cupsCancelJob(dest, 0)) | |
187 | { | |
188 | fputs("lprm: Unable to cancel job(s)!\n", stderr); | |
189 | return (1); | |
190 | } | |
191 | ||
192 | return (0); | |
193 | } | |
194 | ||
195 | ||
196 | /* | |
8784b6a6 | 197 | * End of "$Id: lprm.c,v 1.3 1999/06/18 18:36:05 mike Exp $". |
bd0b97ff | 198 | */ |